1 | /* |
2 | * Copyright (C) 2014-2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "NavigationActionData.h" |
28 | |
29 | #include "ArgumentCoders.h" |
30 | #include "Decoder.h" |
31 | #include "Encoder.h" |
32 | #include "WebCoreArgumentCoders.h" |
33 | |
34 | namespace WebKit { |
35 | |
36 | void NavigationActionData::encode(IPC::Encoder& encoder) const |
37 | { |
38 | encoder.encodeEnum(navigationType); |
39 | encoder << modifiers; |
40 | encoder.encodeEnum(mouseButton); |
41 | encoder.encodeEnum(syntheticClickType); |
42 | encoder << userGestureTokenIdentifier; |
43 | encoder << canHandleRequest; |
44 | encoder.encodeEnum(shouldOpenExternalURLsPolicy); |
45 | encoder << downloadAttribute; |
46 | encoder << clickLocationInRootViewCoordinates; |
47 | encoder << isRedirect; |
48 | encoder << treatAsSameOriginNavigation; |
49 | encoder << hasOpenedFrames; |
50 | encoder << openedByDOMWithOpener; |
51 | encoder << requesterOrigin; |
52 | encoder << targetBackForwardItemIdentifier; |
53 | encoder << sourceBackForwardItemIdentifier; |
54 | encoder.encodeEnum(lockHistory); |
55 | encoder.encodeEnum(lockBackForwardList); |
56 | encoder << clientRedirectSourceForHistory; |
57 | encoder << adClickAttribution; |
58 | } |
59 | |
60 | Optional<NavigationActionData> NavigationActionData::decode(IPC::Decoder& decoder) |
61 | { |
62 | WebCore::NavigationType navigationType; |
63 | if (!decoder.decodeEnum(navigationType)) |
64 | return WTF::nullopt; |
65 | |
66 | OptionSet<WebEvent::Modifier> modifiers; |
67 | if (!decoder.decode(modifiers)) |
68 | return WTF::nullopt; |
69 | |
70 | WebMouseEvent::Button mouseButton; |
71 | if (!decoder.decodeEnum(mouseButton)) |
72 | return WTF::nullopt; |
73 | |
74 | WebMouseEvent::SyntheticClickType syntheticClickType; |
75 | if (!decoder.decodeEnum(syntheticClickType)) |
76 | return WTF::nullopt; |
77 | |
78 | Optional<uint64_t> userGestureTokenIdentifier; |
79 | decoder >> userGestureTokenIdentifier; |
80 | if (!userGestureTokenIdentifier) |
81 | return WTF::nullopt; |
82 | |
83 | Optional<bool> canHandleRequest; |
84 | decoder >> canHandleRequest; |
85 | if (!canHandleRequest) |
86 | return WTF::nullopt; |
87 | |
88 | WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy; |
89 | if (!decoder.decodeEnum(shouldOpenExternalURLsPolicy)) |
90 | return WTF::nullopt; |
91 | |
92 | Optional<String> downloadAttribute; |
93 | decoder >> downloadAttribute; |
94 | if (!downloadAttribute) |
95 | return WTF::nullopt; |
96 | |
97 | WebCore::FloatPoint clickLocationInRootViewCoordinates; |
98 | if (!decoder.decode(clickLocationInRootViewCoordinates)) |
99 | return WTF::nullopt; |
100 | |
101 | Optional<bool> isRedirect; |
102 | decoder >> isRedirect; |
103 | if (!isRedirect) |
104 | return WTF::nullopt; |
105 | |
106 | Optional<bool> treatAsSameOriginNavigation; |
107 | decoder >> treatAsSameOriginNavigation; |
108 | if (!treatAsSameOriginNavigation) |
109 | return WTF::nullopt; |
110 | |
111 | Optional<bool> hasOpenedFrames; |
112 | decoder >> hasOpenedFrames; |
113 | if (!hasOpenedFrames) |
114 | return WTF::nullopt; |
115 | |
116 | Optional<bool> openedByDOMWithOpener; |
117 | decoder >> openedByDOMWithOpener; |
118 | if (!openedByDOMWithOpener) |
119 | return WTF::nullopt; |
120 | |
121 | Optional<WebCore::SecurityOriginData> requesterOrigin; |
122 | decoder >> requesterOrigin; |
123 | if (!requesterOrigin) |
124 | return WTF::nullopt; |
125 | |
126 | Optional<Optional<WebCore::BackForwardItemIdentifier>> targetBackForwardItemIdentifier; |
127 | decoder >> targetBackForwardItemIdentifier; |
128 | if (!targetBackForwardItemIdentifier) |
129 | return WTF::nullopt; |
130 | |
131 | Optional<Optional<WebCore::BackForwardItemIdentifier>> sourceBackForwardItemIdentifier; |
132 | decoder >> sourceBackForwardItemIdentifier; |
133 | if (!sourceBackForwardItemIdentifier) |
134 | return WTF::nullopt; |
135 | |
136 | WebCore::LockHistory lockHistory; |
137 | if (!decoder.decodeEnum(lockHistory)) |
138 | return WTF::nullopt; |
139 | |
140 | WebCore::LockBackForwardList lockBackForwardList; |
141 | if (!decoder.decodeEnum(lockBackForwardList)) |
142 | return WTF::nullopt; |
143 | |
144 | Optional<String> clientRedirectSourceForHistory; |
145 | decoder >> clientRedirectSourceForHistory; |
146 | if (!clientRedirectSourceForHistory) |
147 | return WTF::nullopt; |
148 | |
149 | Optional<Optional<WebCore::AdClickAttribution>> adClickAttribution; |
150 | decoder >> adClickAttribution; |
151 | if (!adClickAttribution) |
152 | return WTF::nullopt; |
153 | |
154 | return {{ WTFMove(navigationType), modifiers, WTFMove(mouseButton), WTFMove(syntheticClickType), WTFMove(*userGestureTokenIdentifier), |
155 | WTFMove(*canHandleRequest), WTFMove(shouldOpenExternalURLsPolicy), WTFMove(*downloadAttribute), WTFMove(clickLocationInRootViewCoordinates), |
156 | WTFMove(*isRedirect), *treatAsSameOriginNavigation, *hasOpenedFrames, *openedByDOMWithOpener, WTFMove(*requesterOrigin), |
157 | WTFMove(*targetBackForwardItemIdentifier), WTFMove(*sourceBackForwardItemIdentifier), lockHistory, lockBackForwardList, WTFMove(*clientRedirectSourceForHistory), WTFMove(*adClickAttribution) }}; |
158 | } |
159 | |
160 | } // namespace WebKit |
161 | |