1 | /* |
2 | * Copyright (C) 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 "LoadParameters.h" |
28 | |
29 | #include "FormDataReference.h" |
30 | #include "WebCoreArgumentCoders.h" |
31 | |
32 | namespace WebKit { |
33 | |
34 | void LoadParameters::encode(IPC::Encoder& encoder) const |
35 | { |
36 | encoder << navigationID; |
37 | encoder << request; |
38 | |
39 | encoder << static_cast<bool>(request.httpBody()); |
40 | if (request.httpBody()) { |
41 | // FormDataReference encoder / decoder takes care of passing and consuming the needed sandbox extensions. |
42 | encoder << IPC::FormDataReference { request.httpBody() }; |
43 | } |
44 | |
45 | encoder << sandboxExtensionHandle; |
46 | encoder << data; |
47 | encoder << MIMEType; |
48 | encoder << encodingName; |
49 | encoder << baseURLString; |
50 | encoder << unreachableURLString; |
51 | encoder << provisionalLoadErrorURLString; |
52 | encoder << websitePolicies; |
53 | encoder << shouldOpenExternalURLsPolicy; |
54 | encoder << shouldTreatAsContinuingLoad; |
55 | encoder << userData; |
56 | encoder.encodeEnum(lockHistory); |
57 | encoder.encodeEnum(lockBackForwardList); |
58 | encoder << clientRedirectSourceForHistory; |
59 | |
60 | platformEncode(encoder); |
61 | } |
62 | |
63 | bool LoadParameters::decode(IPC::Decoder& decoder, LoadParameters& data) |
64 | { |
65 | if (!decoder.decode(data.navigationID)) |
66 | return false; |
67 | |
68 | if (!decoder.decode(data.request)) |
69 | return false; |
70 | |
71 | bool hasHTTPBody; |
72 | if (!decoder.decode(hasHTTPBody)) |
73 | return false; |
74 | |
75 | if (hasHTTPBody) { |
76 | // FormDataReference encoder / decoder takes care of passing and consuming the needed sandbox extensions. |
77 | Optional<IPC::FormDataReference> formDataReference; |
78 | decoder >> formDataReference; |
79 | if (!formDataReference) |
80 | return false; |
81 | |
82 | data.request.setHTTPBody(formDataReference->takeData()); |
83 | } |
84 | |
85 | Optional<SandboxExtension::Handle> sandboxExtensionHandle; |
86 | decoder >> sandboxExtensionHandle; |
87 | if (!sandboxExtensionHandle) |
88 | return false; |
89 | data.sandboxExtensionHandle = WTFMove(*sandboxExtensionHandle); |
90 | |
91 | if (!decoder.decode(data.data)) |
92 | return false; |
93 | |
94 | if (!decoder.decode(data.MIMEType)) |
95 | return false; |
96 | |
97 | if (!decoder.decode(data.encodingName)) |
98 | return false; |
99 | |
100 | if (!decoder.decode(data.baseURLString)) |
101 | return false; |
102 | |
103 | if (!decoder.decode(data.unreachableURLString)) |
104 | return false; |
105 | |
106 | if (!decoder.decode(data.provisionalLoadErrorURLString)) |
107 | return false; |
108 | |
109 | Optional<Optional<WebsitePoliciesData>> websitePolicies; |
110 | decoder >> websitePolicies; |
111 | if (!websitePolicies) |
112 | return false; |
113 | data.websitePolicies = WTFMove(*websitePolicies); |
114 | |
115 | if (!decoder.decode(data.shouldOpenExternalURLsPolicy)) |
116 | return false; |
117 | |
118 | if (!decoder.decode(data.shouldTreatAsContinuingLoad)) |
119 | return false; |
120 | |
121 | if (!decoder.decode(data.userData)) |
122 | return false; |
123 | |
124 | if (!decoder.decodeEnum(data.lockHistory)) |
125 | return false; |
126 | |
127 | if (!decoder.decodeEnum(data.lockBackForwardList)) |
128 | return false; |
129 | |
130 | Optional<String> clientRedirectSourceForHistory; |
131 | decoder >> clientRedirectSourceForHistory; |
132 | if (!clientRedirectSourceForHistory) |
133 | return false; |
134 | data.clientRedirectSourceForHistory = WTFMove(*clientRedirectSourceForHistory); |
135 | |
136 | if (!platformDecode(decoder, data)) |
137 | return false; |
138 | |
139 | return true; |
140 | } |
141 | |
142 | #if !PLATFORM(COCOA) |
143 | |
144 | void LoadParameters::platformEncode(IPC::Encoder&) const |
145 | { |
146 | } |
147 | |
148 | bool LoadParameters::platformDecode(IPC::Decoder&, LoadParameters&) |
149 | { |
150 | return true; |
151 | } |
152 | |
153 | #endif // !PLATFORM(COCOA) |
154 | |
155 | |
156 | } // namespace WebKit |
157 | |