1/*
2 * Copyright (C) 2010-2018 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 "WebPageCreationParameters.h"
28
29#include "WebCoreArgumentCoders.h"
30
31namespace WebKit {
32
33void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
34{
35 encoder << viewSize;
36 encoder << activityState;
37
38 encoder << store;
39 encoder.encodeEnum(drawingAreaType);
40 encoder << drawingAreaIdentifier;
41 encoder << pageGroupData;
42 encoder << isEditable;
43 encoder << underlayColor;
44 encoder << useFixedLayout;
45 encoder << fixedLayoutSize;
46 encoder << alwaysShowsHorizontalScroller;
47 encoder << alwaysShowsVerticalScroller;
48 encoder.encodeEnum(paginationMode);
49 encoder << paginationBehavesLikeColumns;
50 encoder << pageLength;
51 encoder << gapBetweenPages;
52 encoder << paginationLineGridEnabled;
53 encoder << userAgent;
54 encoder << itemStates;
55 encoder << sessionID;
56 encoder << userContentControllerID;
57 encoder << visitedLinkTableID;
58 encoder << websiteDataStoreID;
59 encoder << canRunBeforeUnloadConfirmPanel;
60 encoder << canRunModal;
61 encoder << deviceScaleFactor;
62 encoder << viewScaleFactor;
63 encoder << textZoomFactor;
64 encoder << pageZoomFactor;
65 encoder << topContentInset;
66 encoder << mediaVolume;
67 encoder << muted;
68 encoder << mayStartMediaWhenInWindow;
69 encoder << mediaPlaybackIsSuspended;
70 encoder << viewLayoutSize;
71 encoder << autoSizingShouldExpandToViewHeight;
72 encoder << viewportSizeForCSSViewportUnits;
73 encoder.encodeEnum(scrollPinningBehavior);
74 encoder << scrollbarOverlayStyle;
75 encoder << backgroundExtendsBeyondPage;
76 encoder.encodeEnum(layerHostingMode);
77 encoder << mimeTypesWithCustomContentProviders;
78 encoder << controlledByAutomation;
79 encoder << isProcessSwap;
80 encoder << useDarkAppearance;
81 encoder << useInactiveAppearance;
82
83#if PLATFORM(MAC)
84 encoder << colorSpace;
85 encoder << useSystemAppearance;
86#endif
87#if PLATFORM(IOS_FAMILY)
88 encoder << screenSize;
89 encoder << availableScreenSize;
90 encoder << overrideScreenSize;
91 encoder << textAutosizingWidth;
92 encoder << ignoresViewportScaleLimits;
93 encoder << viewportConfigurationViewLayoutSize;
94 encoder << viewportConfigurationLayoutSizeScaleFactor;
95 encoder << viewportConfigurationMinimumEffectiveDeviceWidth;
96 encoder << viewportConfigurationViewSize;
97 encoder << maximumUnobscuredSize;
98 encoder << deviceOrientation;
99 encoder << keyboardIsAttached;
100 encoder << canShowWhileLocked;
101 encoder << doubleTapForDoubleClickDelay;
102 encoder << doubleTapForDoubleClickRadius;
103 encoder << overrideViewportArguments;
104#endif
105#if PLATFORM(COCOA)
106 encoder << smartInsertDeleteEnabled;
107 encoder << additionalSupportedImageTypes;
108#endif
109#if USE(WPE_RENDERER)
110 encoder << hostFileDescriptor;
111#endif
112 encoder << appleMailPaginationQuirkEnabled;
113 encoder << appleMailLinesClampEnabled;
114 encoder << shouldScaleViewToFitDocument;
115 encoder.encodeEnum(userInterfaceLayoutDirection);
116 encoder << observedLayoutMilestones;
117 encoder << overrideContentSecurityPolicy;
118 encoder << cpuLimit;
119 encoder << urlSchemeHandlers;
120#if ENABLE(APPLICATION_MANIFEST)
121 encoder << applicationManifest;
122#endif
123#if ENABLE(SERVICE_WORKER)
124 encoder << hasRegisteredServiceWorkers;
125#endif
126 encoder << needsFontAttributes;
127 encoder << iceCandidateFilteringEnabled;
128 encoder << enumeratingAllNetworkInterfacesEnabled;
129 encoder << userContentWorlds;
130 encoder << userScripts;
131 encoder << userStyleSheets;
132 encoder << messageHandlers;
133#if ENABLE(CONTENT_EXTENSIONS)
134 encoder << contentRuleLists;
135#endif
136 encoder << backgroundColor;
137 encoder << oldPageID;
138}
139
140Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
141{
142 WebPageCreationParameters parameters;
143 if (!decoder.decode(parameters.viewSize))
144 return WTF::nullopt;
145 if (!decoder.decode(parameters.activityState))
146 return WTF::nullopt;
147 if (!decoder.decode(parameters.store))
148 return WTF::nullopt;
149 if (!decoder.decodeEnum(parameters.drawingAreaType))
150 return WTF::nullopt;
151 Optional<DrawingAreaIdentifier> drawingAreaIdentifier;
152 decoder >> drawingAreaIdentifier;
153 if (!drawingAreaIdentifier)
154 return WTF::nullopt;
155 parameters.drawingAreaIdentifier = *drawingAreaIdentifier;
156 Optional<WebPageGroupData> pageGroupData;
157 decoder >> pageGroupData;
158 if (!pageGroupData)
159 return WTF::nullopt;
160 parameters.pageGroupData = WTFMove(*pageGroupData);
161 if (!decoder.decode(parameters.isEditable))
162 return WTF::nullopt;
163 if (!decoder.decode(parameters.underlayColor))
164 return WTF::nullopt;
165 if (!decoder.decode(parameters.useFixedLayout))
166 return WTF::nullopt;
167 if (!decoder.decode(parameters.fixedLayoutSize))
168 return WTF::nullopt;
169 if (!decoder.decode(parameters.alwaysShowsHorizontalScroller))
170 return WTF::nullopt;
171 if (!decoder.decode(parameters.alwaysShowsVerticalScroller))
172 return WTF::nullopt;
173 if (!decoder.decodeEnum(parameters.paginationMode))
174 return WTF::nullopt;
175 if (!decoder.decode(parameters.paginationBehavesLikeColumns))
176 return WTF::nullopt;
177 if (!decoder.decode(parameters.pageLength))
178 return WTF::nullopt;
179 if (!decoder.decode(parameters.gapBetweenPages))
180 return WTF::nullopt;
181 if (!decoder.decode(parameters.paginationLineGridEnabled))
182 return WTF::nullopt;
183
184 Optional<String> userAgent;
185 decoder >> userAgent;
186 if (!userAgent)
187 return WTF::nullopt;
188 parameters.userAgent = WTFMove(*userAgent);
189
190 Optional<Vector<BackForwardListItemState>> itemStates;
191 decoder >> itemStates;
192 if (!itemStates)
193 return WTF::nullopt;
194 parameters.itemStates = WTFMove(*itemStates);
195
196 if (!decoder.decode(parameters.sessionID))
197 return WTF::nullopt;
198
199 Optional<UserContentControllerIdentifier> userContentControllerIdentifier;
200 decoder >> userContentControllerIdentifier;
201 if (!userContentControllerIdentifier)
202 return WTF::nullopt;
203 parameters.userContentControllerID = *userContentControllerIdentifier;
204
205 if (!decoder.decode(parameters.visitedLinkTableID))
206 return WTF::nullopt;
207 if (!decoder.decode(parameters.websiteDataStoreID))
208 return WTF::nullopt;
209 if (!decoder.decode(parameters.canRunBeforeUnloadConfirmPanel))
210 return WTF::nullopt;
211 if (!decoder.decode(parameters.canRunModal))
212 return WTF::nullopt;
213 if (!decoder.decode(parameters.deviceScaleFactor))
214 return WTF::nullopt;
215 if (!decoder.decode(parameters.viewScaleFactor))
216 return WTF::nullopt;
217 if (!decoder.decode(parameters.textZoomFactor))
218 return WTF::nullopt;
219 if (!decoder.decode(parameters.pageZoomFactor))
220 return WTF::nullopt;
221 if (!decoder.decode(parameters.topContentInset))
222 return WTF::nullopt;
223 if (!decoder.decode(parameters.mediaVolume))
224 return WTF::nullopt;
225 if (!decoder.decode(parameters.muted))
226 return WTF::nullopt;
227 if (!decoder.decode(parameters.mayStartMediaWhenInWindow))
228 return WTF::nullopt;
229 if (!decoder.decode(parameters.mediaPlaybackIsSuspended))
230 return WTF::nullopt;
231 if (!decoder.decode(parameters.viewLayoutSize))
232 return WTF::nullopt;
233 if (!decoder.decode(parameters.autoSizingShouldExpandToViewHeight))
234 return WTF::nullopt;
235 if (!decoder.decode(parameters.viewportSizeForCSSViewportUnits))
236 return WTF::nullopt;
237 if (!decoder.decodeEnum(parameters.scrollPinningBehavior))
238 return WTF::nullopt;
239
240 Optional<Optional<uint32_t>> scrollbarOverlayStyle;
241 decoder >> scrollbarOverlayStyle;
242 if (!scrollbarOverlayStyle)
243 return WTF::nullopt;
244 parameters.scrollbarOverlayStyle = WTFMove(*scrollbarOverlayStyle);
245
246 if (!decoder.decode(parameters.backgroundExtendsBeyondPage))
247 return WTF::nullopt;
248 if (!decoder.decodeEnum(parameters.layerHostingMode))
249 return WTF::nullopt;
250 if (!decoder.decode(parameters.mimeTypesWithCustomContentProviders))
251 return WTF::nullopt;
252 if (!decoder.decode(parameters.controlledByAutomation))
253 return WTF::nullopt;
254 if (!decoder.decode(parameters.isProcessSwap))
255 return WTF::nullopt;
256 if (!decoder.decode(parameters.useDarkAppearance))
257 return WTF::nullopt;
258 if (!decoder.decode(parameters.useInactiveAppearance))
259 return WTF::nullopt;
260
261#if PLATFORM(MAC)
262 if (!decoder.decode(parameters.colorSpace))
263 return WTF::nullopt;
264 if (!decoder.decode(parameters.useSystemAppearance))
265 return WTF::nullopt;
266#endif
267
268#if PLATFORM(IOS_FAMILY)
269 if (!decoder.decode(parameters.screenSize))
270 return WTF::nullopt;
271 if (!decoder.decode(parameters.availableScreenSize))
272 return WTF::nullopt;
273 if (!decoder.decode(parameters.overrideScreenSize))
274 return WTF::nullopt;
275 if (!decoder.decode(parameters.textAutosizingWidth))
276 return WTF::nullopt;
277 if (!decoder.decode(parameters.ignoresViewportScaleLimits))
278 return WTF::nullopt;
279 if (!decoder.decode(parameters.viewportConfigurationViewLayoutSize))
280 return WTF::nullopt;
281 if (!decoder.decode(parameters.viewportConfigurationLayoutSizeScaleFactor))
282 return WTF::nullopt;
283 if (!decoder.decode(parameters.viewportConfigurationMinimumEffectiveDeviceWidth))
284 return WTF::nullopt;
285 if (!decoder.decode(parameters.viewportConfigurationViewSize))
286 return WTF::nullopt;
287 if (!decoder.decode(parameters.maximumUnobscuredSize))
288 return WTF::nullopt;
289 if (!decoder.decode(parameters.deviceOrientation))
290 return WTF::nullopt;
291 if (!decoder.decode(parameters.keyboardIsAttached))
292 return WTF::nullopt;
293 if (!decoder.decode(parameters.canShowWhileLocked))
294 return WTF::nullopt;
295 if (!decoder.decode(parameters.doubleTapForDoubleClickDelay))
296 return WTF::nullopt;
297 if (!decoder.decode(parameters.doubleTapForDoubleClickRadius))
298 return WTF::nullopt;
299
300 Optional<Optional<WebCore::ViewportArguments>> overrideViewportArguments;
301 decoder >> overrideViewportArguments;
302 if (!overrideViewportArguments)
303 return WTF::nullopt;
304 parameters.overrideViewportArguments = WTFMove(*overrideViewportArguments);
305#endif
306
307#if PLATFORM(COCOA)
308 if (!decoder.decode(parameters.smartInsertDeleteEnabled))
309 return WTF::nullopt;
310 if (!decoder.decode(parameters.additionalSupportedImageTypes))
311 return WTF::nullopt;
312#endif
313
314#if USE(WPE_RENDERER)
315 if (!decoder.decode(parameters.hostFileDescriptor))
316 return WTF::nullopt;
317#endif
318
319 if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
320 return WTF::nullopt;
321
322 if (!decoder.decode(parameters.appleMailLinesClampEnabled))
323 return WTF::nullopt;
324
325 if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
326 return WTF::nullopt;
327
328 if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection))
329 return WTF::nullopt;
330 if (!decoder.decode(parameters.observedLayoutMilestones))
331 return WTF::nullopt;
332
333 if (!decoder.decode(parameters.overrideContentSecurityPolicy))
334 return WTF::nullopt;
335
336 Optional<Optional<double>> cpuLimit;
337 decoder >> cpuLimit;
338 if (!cpuLimit)
339 return WTF::nullopt;
340 parameters.cpuLimit = WTFMove(*cpuLimit);
341
342 if (!decoder.decode(parameters.urlSchemeHandlers))
343 return WTF::nullopt;
344
345#if ENABLE(APPLICATION_MANIFEST)
346 Optional<Optional<WebCore::ApplicationManifest>> applicationManifest;
347 decoder >> applicationManifest;
348 if (!applicationManifest)
349 return WTF::nullopt;
350 parameters.applicationManifest = WTFMove(*applicationManifest);
351#endif
352#if ENABLE(SERVICE_WORKER)
353 if (!decoder.decode(parameters.hasRegisteredServiceWorkers))
354 return WTF::nullopt;
355#endif
356
357 if (!decoder.decode(parameters.needsFontAttributes))
358 return WTF::nullopt;
359
360 if (!decoder.decode(parameters.iceCandidateFilteringEnabled))
361 return WTF::nullopt;
362
363 if (!decoder.decode(parameters.enumeratingAllNetworkInterfacesEnabled))
364 return WTF::nullopt;
365
366 Optional<Vector<std::pair<uint64_t, String>>> userContentWorlds;
367 decoder >> userContentWorlds;
368 if (!userContentWorlds)
369 return WTF::nullopt;
370 parameters.userContentWorlds = WTFMove(*userContentWorlds);
371
372 Optional<Vector<WebUserScriptData>> userScripts;
373 decoder >> userScripts;
374 if (!userScripts)
375 return WTF::nullopt;
376 parameters.userScripts = WTFMove(*userScripts);
377
378 Optional<Vector<WebUserStyleSheetData>> userStyleSheets;
379 decoder >> userStyleSheets;
380 if (!userStyleSheets)
381 return WTF::nullopt;
382 parameters.userStyleSheets = WTFMove(*userStyleSheets);
383
384 Optional<Vector<WebScriptMessageHandlerData>> messageHandlers;
385 decoder >> messageHandlers;
386 if (!messageHandlers)
387 return WTF::nullopt;
388 parameters.messageHandlers = WTFMove(*messageHandlers);
389
390#if ENABLE(CONTENT_EXTENSIONS)
391 Optional<Vector<std::pair<String, WebCompiledContentRuleListData>>> contentRuleLists;
392 decoder >> contentRuleLists;
393 if (!contentRuleLists)
394 return WTF::nullopt;
395 parameters.contentRuleLists = WTFMove(*contentRuleLists);
396#endif
397
398 Optional<Optional<WebCore::Color>> backgroundColor;
399 decoder >> backgroundColor;
400 if (!backgroundColor)
401 return WTF::nullopt;
402 parameters.backgroundColor = WTFMove(*backgroundColor);
403
404 Optional<Optional<WebCore::PageIdentifier>> oldPageID;
405 decoder >> oldPageID;
406 if (!oldPageID)
407 return WTF::nullopt;
408 parameters.oldPageID = WTFMove(*oldPageID);
409
410 return parameters;
411}
412
413} // namespace WebKit
414