969308abd7192eb96b2aea70ff416223506233a1
[WebKit-https.git] / Source / WebKit / Shared / NavigationActionData.cpp
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.encodeEnum(lockHistory);
54     encoder.encodeEnum(lockBackForwardList);
55     encoder << clientRedirectSourceForHistory;
56     encoder << adClickAttribution;
57 }
58
59 Optional<NavigationActionData> NavigationActionData::decode(IPC::Decoder& decoder)
60 {
61     WebCore::NavigationType navigationType;
62     if (!decoder.decodeEnum(navigationType))
63         return WTF::nullopt;
64     
65     OptionSet<WebEvent::Modifier> modifiers;
66     if (!decoder.decode(modifiers))
67         return WTF::nullopt;
68
69     WebMouseEvent::Button mouseButton;
70     if (!decoder.decodeEnum(mouseButton))
71         return WTF::nullopt;
72     
73     WebMouseEvent::SyntheticClickType syntheticClickType;
74     if (!decoder.decodeEnum(syntheticClickType))
75         return WTF::nullopt;
76     
77     Optional<uint64_t> userGestureTokenIdentifier;
78     decoder >> userGestureTokenIdentifier;
79     if (!userGestureTokenIdentifier)
80         return WTF::nullopt;
81     
82     Optional<bool> canHandleRequest;
83     decoder >> canHandleRequest;
84     if (!canHandleRequest)
85         return WTF::nullopt;
86     
87     WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy;
88     if (!decoder.decodeEnum(shouldOpenExternalURLsPolicy))
89         return WTF::nullopt;
90     
91     Optional<String> downloadAttribute;
92     decoder >> downloadAttribute;
93     if (!downloadAttribute)
94         return WTF::nullopt;
95     
96     WebCore::FloatPoint clickLocationInRootViewCoordinates;
97     if (!decoder.decode(clickLocationInRootViewCoordinates))
98         return WTF::nullopt;
99     
100     Optional<bool> isRedirect;
101     decoder >> isRedirect;
102     if (!isRedirect)
103         return WTF::nullopt;
104
105     Optional<bool> treatAsSameOriginNavigation;
106     decoder >> treatAsSameOriginNavigation;
107     if (!treatAsSameOriginNavigation)
108         return WTF::nullopt;
109
110     Optional<bool> hasOpenedFrames;
111     decoder >> hasOpenedFrames;
112     if (!hasOpenedFrames)
113         return WTF::nullopt;
114
115     Optional<bool> openedByDOMWithOpener;
116     decoder >> openedByDOMWithOpener;
117     if (!openedByDOMWithOpener)
118         return WTF::nullopt;
119
120     Optional<WebCore::SecurityOriginData> requesterOrigin;
121     decoder >> requesterOrigin;
122     if (!requesterOrigin)
123         return WTF::nullopt;
124
125     Optional<Optional<WebCore::BackForwardItemIdentifier>> targetBackForwardItemIdentifier;
126     decoder >> targetBackForwardItemIdentifier;
127     if (!targetBackForwardItemIdentifier)
128         return WTF::nullopt;
129
130     WebCore::LockHistory lockHistory;
131     if (!decoder.decodeEnum(lockHistory))
132         return WTF::nullopt;
133
134     WebCore::LockBackForwardList lockBackForwardList;
135     if (!decoder.decodeEnum(lockBackForwardList))
136         return WTF::nullopt;
137
138     Optional<String> clientRedirectSourceForHistory;
139     decoder >> clientRedirectSourceForHistory;
140     if (!clientRedirectSourceForHistory)
141         return WTF::nullopt;
142
143     Optional<Optional<WebCore::AdClickAttribution>> adClickAttribution;
144     decoder >> adClickAttribution;
145     if (!adClickAttribution)
146         return WTF::nullopt;
147
148     return {{ WTFMove(navigationType), modifiers, WTFMove(mouseButton), WTFMove(syntheticClickType), WTFMove(*userGestureTokenIdentifier),
149         WTFMove(*canHandleRequest), WTFMove(shouldOpenExternalURLsPolicy), WTFMove(*downloadAttribute), WTFMove(clickLocationInRootViewCoordinates),
150         WTFMove(*isRedirect), *treatAsSameOriginNavigation, *hasOpenedFrames, *openedByDOMWithOpener, WTFMove(*requesterOrigin),
151         WTFMove(*targetBackForwardItemIdentifier), lockHistory, lockBackForwardList, WTFMove(*clientRedirectSourceForHistory), WTFMove(*adClickAttribution) }};
152 }
153
154 } // namespace WebKit