6fbf8440da1fab473f6908a39ac01754fc5ed2b0
[WebKit-https.git] / Source / WebKit2 / Shared / WebCoreArgumentCoders.cpp
1 /*
2  * Copyright (C) 2011 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 "WebCoreArgumentCoders.h"
28
29 #include "ShareableBitmap.h"
30 #include <WebCore/AuthenticationChallenge.h>
31 #include <WebCore/CertificateInfo.h>
32 #include <WebCore/Cookie.h>
33 #include <WebCore/Credential.h>
34 #include <WebCore/Cursor.h>
35 #include <WebCore/DatabaseDetails.h>
36 #include <WebCore/DictationAlternative.h>
37 #include <WebCore/DragSession.h>
38 #include <WebCore/Editor.h>
39 #include <WebCore/FileChooser.h>
40 #include <WebCore/FilterOperation.h>
41 #include <WebCore/FilterOperations.h>
42 #include <WebCore/GraphicsContext.h>
43 #include <WebCore/GraphicsLayer.h>
44 #include <WebCore/IDBDatabaseMetadata.h>
45 #include <WebCore/IDBKeyData.h>
46 #include <WebCore/IDBKeyPath.h>
47 #include <WebCore/Image.h>
48 #include <WebCore/Length.h>
49 #include <WebCore/PluginData.h>
50 #include <WebCore/ProtectionSpace.h>
51 #include <WebCore/ResourceError.h>
52 #include <WebCore/ResourceRequest.h>
53 #include <WebCore/ResourceResponse.h>
54 #include <WebCore/ScrollingConstraints.h>
55 #include <WebCore/ScrollingCoordinator.h>
56 #include <WebCore/TextCheckerClient.h>
57 #include <WebCore/TransformationMatrix.h>
58 #include <WebCore/URL.h>
59 #include <WebCore/UserScript.h>
60 #include <WebCore/UserStyleSheet.h>
61 #include <WebCore/ViewportArguments.h>
62 #include <WebCore/WindowFeatures.h>
63 #include <wtf/text/CString.h>
64 #include <wtf/text/StringHash.h>
65
66 #if PLATFORM(IOS)
67 #include <WebCore/FloatQuad.h>
68 #include <WebCore/Pasteboard.h>
69 #include <WebCore/SelectionRect.h>
70 #include <WebCore/SharedBuffer.h>
71 #endif // PLATFORM(IOS)
72
73 using namespace WebCore;
74 using namespace WebKit;
75
76 namespace IPC {
77
78 void ArgumentCoder<AffineTransform>::encode(ArgumentEncoder& encoder, const AffineTransform& affineTransform)
79 {
80     SimpleArgumentCoder<AffineTransform>::encode(encoder, affineTransform);
81 }
82
83 bool ArgumentCoder<AffineTransform>::decode(ArgumentDecoder& decoder, AffineTransform& affineTransform)
84 {
85     return SimpleArgumentCoder<AffineTransform>::decode(decoder, affineTransform);
86 }
87
88
89 void ArgumentCoder<TransformationMatrix>::encode(ArgumentEncoder& encoder, const TransformationMatrix& transformationMatrix)
90 {
91     SimpleArgumentCoder<TransformationMatrix>::encode(encoder, transformationMatrix);
92 }
93
94 bool ArgumentCoder<TransformationMatrix>::decode(ArgumentDecoder& decoder, TransformationMatrix& transformationMatrix)
95 {
96     return SimpleArgumentCoder<TransformationMatrix>::decode(decoder, transformationMatrix);
97 }
98
99 void ArgumentCoder<FloatPoint>::encode(ArgumentEncoder& encoder, const FloatPoint& floatPoint)
100 {
101     SimpleArgumentCoder<FloatPoint>::encode(encoder, floatPoint);
102 }
103
104 bool ArgumentCoder<FloatPoint>::decode(ArgumentDecoder& decoder, FloatPoint& floatPoint)
105 {
106     return SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint);
107 }
108
109
110 void ArgumentCoder<FloatPoint3D>::encode(ArgumentEncoder& encoder, const FloatPoint3D& floatPoint)
111 {
112     SimpleArgumentCoder<FloatPoint3D>::encode(encoder, floatPoint);
113 }
114
115 bool ArgumentCoder<FloatPoint3D>::decode(ArgumentDecoder& decoder, FloatPoint3D& floatPoint)
116 {
117     return SimpleArgumentCoder<FloatPoint3D>::decode(decoder, floatPoint);
118 }
119
120
121 void ArgumentCoder<FloatRect>::encode(ArgumentEncoder& encoder, const FloatRect& floatRect)
122 {
123     SimpleArgumentCoder<FloatRect>::encode(encoder, floatRect);
124 }
125
126 bool ArgumentCoder<FloatRect>::decode(ArgumentDecoder& decoder, FloatRect& floatRect)
127 {
128     return SimpleArgumentCoder<FloatRect>::decode(decoder, floatRect);
129 }
130
131
132 void ArgumentCoder<FloatSize>::encode(ArgumentEncoder& encoder, const FloatSize& floatSize)
133 {
134     SimpleArgumentCoder<FloatSize>::encode(encoder, floatSize);
135 }
136
137 bool ArgumentCoder<FloatSize>::decode(ArgumentDecoder& decoder, FloatSize& floatSize)
138 {
139     return SimpleArgumentCoder<FloatSize>::decode(decoder, floatSize);
140 }
141
142
143 #if PLATFORM(IOS)
144 void ArgumentCoder<FloatQuad>::encode(ArgumentEncoder& encoder, const FloatQuad& floatQuad)
145 {
146     SimpleArgumentCoder<FloatQuad>::encode(encoder, floatQuad);
147 }
148
149 bool ArgumentCoder<FloatQuad>::decode(ArgumentDecoder& decoder, FloatQuad& floatQuad)
150 {
151     return SimpleArgumentCoder<FloatQuad>::decode(decoder, floatQuad);
152 }
153
154 void ArgumentCoder<ViewportArguments>::encode(ArgumentEncoder& encoder, const ViewportArguments& viewportArguments)
155 {
156     SimpleArgumentCoder<ViewportArguments>::encode(encoder, viewportArguments);
157 }
158
159 bool ArgumentCoder<ViewportArguments>::decode(ArgumentDecoder& decoder, ViewportArguments& viewportArguments)
160 {
161     return SimpleArgumentCoder<ViewportArguments>::decode(decoder, viewportArguments);
162 }
163 #endif // PLATFORM(IOS)
164
165
166 void ArgumentCoder<IntPoint>::encode(ArgumentEncoder& encoder, const IntPoint& intPoint)
167 {
168     SimpleArgumentCoder<IntPoint>::encode(encoder, intPoint);
169 }
170
171 bool ArgumentCoder<IntPoint>::decode(ArgumentDecoder& decoder, IntPoint& intPoint)
172 {
173     return SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint);
174 }
175
176
177 void ArgumentCoder<IntRect>::encode(ArgumentEncoder& encoder, const IntRect& intRect)
178 {
179     SimpleArgumentCoder<IntRect>::encode(encoder, intRect);
180 }
181
182 bool ArgumentCoder<IntRect>::decode(ArgumentDecoder& decoder, IntRect& intRect)
183 {
184     return SimpleArgumentCoder<IntRect>::decode(decoder, intRect);
185 }
186
187
188 void ArgumentCoder<IntSize>::encode(ArgumentEncoder& encoder, const IntSize& intSize)
189 {
190     SimpleArgumentCoder<IntSize>::encode(encoder, intSize);
191 }
192
193 bool ArgumentCoder<IntSize>::decode(ArgumentDecoder& decoder, IntSize& intSize)
194 {
195     return SimpleArgumentCoder<IntSize>::decode(decoder, intSize);
196 }
197
198
199 void ArgumentCoder<Length>::encode(ArgumentEncoder& encoder, const Length& length)
200 {
201     SimpleArgumentCoder<Length>::encode(encoder, length);
202 }
203
204 bool ArgumentCoder<Length>::decode(ArgumentDecoder& decoder, Length& length)
205 {
206     return SimpleArgumentCoder<Length>::decode(decoder, length);
207 }
208
209
210 void ArgumentCoder<ViewportAttributes>::encode(ArgumentEncoder& encoder, const ViewportAttributes& viewportAttributes)
211 {
212     SimpleArgumentCoder<ViewportAttributes>::encode(encoder, viewportAttributes);
213 }
214
215 bool ArgumentCoder<ViewportAttributes>::decode(ArgumentDecoder& decoder, ViewportAttributes& viewportAttributes)
216 {
217     return SimpleArgumentCoder<ViewportAttributes>::decode(decoder, viewportAttributes);
218 }
219
220
221 void ArgumentCoder<MimeClassInfo>::encode(ArgumentEncoder& encoder, const MimeClassInfo& mimeClassInfo)
222 {
223     encoder << mimeClassInfo.type << mimeClassInfo.desc << mimeClassInfo.extensions;
224 }
225
226 bool ArgumentCoder<MimeClassInfo>::decode(ArgumentDecoder& decoder, MimeClassInfo& mimeClassInfo)
227 {
228     if (!decoder.decode(mimeClassInfo.type))
229         return false;
230     if (!decoder.decode(mimeClassInfo.desc))
231         return false;
232     if (!decoder.decode(mimeClassInfo.extensions))
233         return false;
234
235     return true;
236 }
237
238
239 void ArgumentCoder<PluginInfo>::encode(ArgumentEncoder& encoder, const PluginInfo& pluginInfo)
240 {
241     encoder << pluginInfo.name << pluginInfo.file << pluginInfo.desc << pluginInfo.mimes << pluginInfo.isApplicationPlugin;
242 }
243     
244 bool ArgumentCoder<PluginInfo>::decode(ArgumentDecoder& decoder, PluginInfo& pluginInfo)
245 {
246     if (!decoder.decode(pluginInfo.name))
247         return false;
248     if (!decoder.decode(pluginInfo.file))
249         return false;
250     if (!decoder.decode(pluginInfo.desc))
251         return false;
252     if (!decoder.decode(pluginInfo.mimes))
253         return false;
254     if (!decoder.decode(pluginInfo.isApplicationPlugin))
255         return false;
256
257     return true;
258 }
259
260
261 void ArgumentCoder<HTTPHeaderMap>::encode(ArgumentEncoder& encoder, const HTTPHeaderMap& headerMap)
262 {
263     encoder << static_cast<const HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap);
264 }
265
266 bool ArgumentCoder<HTTPHeaderMap>::decode(ArgumentDecoder& decoder, HTTPHeaderMap& headerMap)
267 {
268     return decoder.decode(static_cast<HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap));
269 }
270
271
272 void ArgumentCoder<AuthenticationChallenge>::encode(ArgumentEncoder& encoder, const AuthenticationChallenge& challenge)
273 {
274     encoder << challenge.protectionSpace() << challenge.proposedCredential() << challenge.previousFailureCount() << challenge.failureResponse() << challenge.error();
275 }
276
277 bool ArgumentCoder<AuthenticationChallenge>::decode(ArgumentDecoder& decoder, AuthenticationChallenge& challenge)
278 {    
279     ProtectionSpace protectionSpace;
280     if (!decoder.decode(protectionSpace))
281         return false;
282
283     Credential proposedCredential;
284     if (!decoder.decode(proposedCredential))
285         return false;
286
287     unsigned previousFailureCount;    
288     if (!decoder.decode(previousFailureCount))
289         return false;
290
291     ResourceResponse failureResponse;
292     if (!decoder.decode(failureResponse))
293         return false;
294
295     ResourceError error;
296     if (!decoder.decode(error))
297         return false;
298     
299     challenge = AuthenticationChallenge(protectionSpace, proposedCredential, previousFailureCount, failureResponse, error);
300     return true;
301 }
302
303
304 void ArgumentCoder<ProtectionSpace>::encode(ArgumentEncoder& encoder, const ProtectionSpace& space)
305 {
306     encoder << space.host() << space.port() << space.realm();
307     encoder.encodeEnum(space.authenticationScheme());
308     encoder.encodeEnum(space.serverType());
309 }
310
311 bool ArgumentCoder<ProtectionSpace>::decode(ArgumentDecoder& decoder, ProtectionSpace& space)
312 {
313     String host;
314     if (!decoder.decode(host))
315         return false;
316
317     int port;
318     if (!decoder.decode(port))
319         return false;
320
321     String realm;
322     if (!decoder.decode(realm))
323         return false;
324     
325     ProtectionSpaceAuthenticationScheme authenticationScheme;
326     if (!decoder.decodeEnum(authenticationScheme))
327         return false;
328
329     ProtectionSpaceServerType serverType;
330     if (!decoder.decodeEnum(serverType))
331         return false;
332
333     space = ProtectionSpace(host, port, serverType, realm, authenticationScheme);
334     return true;
335 }
336
337 void ArgumentCoder<Credential>::encode(ArgumentEncoder& encoder, const Credential& credential)
338 {
339     encoder << credential.user() << credential.password();
340     encoder.encodeEnum(credential.persistence());
341 }
342
343 bool ArgumentCoder<Credential>::decode(ArgumentDecoder& decoder, Credential& credential)
344 {
345     String user;
346     if (!decoder.decode(user))
347         return false;
348
349     String password;
350     if (!decoder.decode(password))
351         return false;
352
353     CredentialPersistence persistence;
354     if (!decoder.decodeEnum(persistence))
355         return false;
356     
357     credential = Credential(user, password, persistence);
358     return true;
359 }
360
361 static void encodeImage(ArgumentEncoder& encoder, Image* image)
362 {
363     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), ShareableBitmap::SupportsAlpha);
364     bitmap->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
365
366     ShareableBitmap::Handle handle;
367     bitmap->createHandle(handle);
368
369     encoder << handle;
370 }
371
372 static bool decodeImage(ArgumentDecoder& decoder, RefPtr<Image>& image)
373 {
374     ShareableBitmap::Handle handle;
375     if (!decoder.decode(handle))
376         return false;
377     
378     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
379     if (!bitmap)
380         return false;
381     image = bitmap->createImage();
382     if (!image)
383         return false;
384     return true;
385 }
386
387 #if !PLATFORM(IOS)
388 void ArgumentCoder<Cursor>::encode(ArgumentEncoder& encoder, const Cursor& cursor)
389 {
390     encoder.encodeEnum(cursor.type());
391         
392     if (cursor.type() != Cursor::Custom)
393         return;
394
395     if (cursor.image()->isNull()) {
396         encoder << false; // There is no valid image being encoded.
397         return;
398     }
399
400     encoder << true;
401     encodeImage(encoder, cursor.image());
402     encoder << cursor.hotSpot();
403 }
404
405 bool ArgumentCoder<Cursor>::decode(ArgumentDecoder& decoder, Cursor& cursor)
406 {
407     Cursor::Type type;
408     if (!decoder.decodeEnum(type))
409         return false;
410
411     if (type > Cursor::Custom)
412         return false;
413
414     if (type != Cursor::Custom) {
415         const Cursor& cursorReference = Cursor::fromType(type);
416         // Calling platformCursor here will eagerly create the platform cursor for the cursor singletons inside WebCore.
417         // This will avoid having to re-create the platform cursors over and over.
418         (void)cursorReference.platformCursor();
419
420         cursor = cursorReference;
421         return true;
422     }
423
424     bool isValidImagePresent;
425     if (!decoder.decode(isValidImagePresent))
426         return false;
427
428     if (!isValidImagePresent) {
429         cursor = Cursor(Image::nullImage(), IntPoint());
430         return true;
431     }
432
433     RefPtr<Image> image;
434     if (!decodeImage(decoder, image))
435         return false;
436
437     IntPoint hotSpot;
438     if (!decoder.decode(hotSpot))
439         return false;
440
441     if (!image->rect().contains(hotSpot))
442         return false;
443
444     cursor = Cursor(image.get(), hotSpot);
445     return true;
446 }
447 #endif
448
449 void ArgumentCoder<ResourceRequest>::encode(ArgumentEncoder& encoder, const ResourceRequest& resourceRequest)
450 {
451     if (kShouldSerializeWebCoreData) {
452         encoder << resourceRequest.url().string();
453         encoder << resourceRequest.httpMethod();
454         encoder << resourceRequest.httpHeaderFields();
455
456         // FIXME: Do not encode HTTP message body.
457         // 1. It can be large and thus costly to send across.
458         // 2. It is misleading to provide a body with some requests, while others use body streams, which cannot be serialized at all.
459         FormData* httpBody = resourceRequest.httpBody();
460         encoder << static_cast<bool>(httpBody);
461         if (httpBody)
462             encoder << httpBody->flattenToString();
463
464         encoder << resourceRequest.firstPartyForCookies().string();
465     }
466
467 #if ENABLE(CACHE_PARTITIONING)
468     encoder << resourceRequest.cachePartition();
469 #endif
470
471     encodePlatformData(encoder, resourceRequest);
472 }
473
474 bool ArgumentCoder<ResourceRequest>::decode(ArgumentDecoder& decoder, ResourceRequest& resourceRequest)
475 {
476     if (kShouldSerializeWebCoreData) {
477         ResourceRequest request;
478
479         String url;
480         if (!decoder.decode(url))
481             return false;
482         request.setURL(URL(URL(), url));
483
484         String httpMethod;
485         if (!decoder.decode(httpMethod))
486             return false;
487         request.setHTTPMethod(httpMethod);
488
489         HTTPHeaderMap headers;
490         if (!decoder.decode(headers))
491             return false;
492         request.addHTTPHeaderFields(headers);
493
494         bool hasHTTPBody;
495         if (!decoder.decode(hasHTTPBody))
496             return false;
497         if (hasHTTPBody) {
498             String httpBody;
499             if (!decoder.decode(httpBody))
500                 return false;
501             request.setHTTPBody(FormData::create(httpBody.utf8()));
502         }
503
504         String firstPartyForCookies;
505         if (!decoder.decode(firstPartyForCookies))
506             return false;
507         request.setFirstPartyForCookies(URL(URL(), firstPartyForCookies));
508
509         resourceRequest = request;
510     }
511
512 #if ENABLE(CACHE_PARTITIONING)
513     String cachePartition;
514     if (!decoder.decode(cachePartition))
515         return false;
516     resourceRequest.setCachePartition(cachePartition);
517 #endif
518
519     return decodePlatformData(decoder, resourceRequest);
520 }
521
522 void ArgumentCoder<ResourceResponse>::encode(ArgumentEncoder& encoder, const ResourceResponse& resourceResponse)
523 {
524 #if PLATFORM(MAC)
525     bool shouldSerializeWebCoreData = !resourceResponse.platformResponseIsUpToDate();
526     encoder << shouldSerializeWebCoreData;
527 #else
528     bool shouldSerializeWebCoreData = true;
529 #endif
530
531     encodePlatformData(encoder, resourceResponse);
532
533     if (shouldSerializeWebCoreData) {
534         bool responseIsNull = resourceResponse.isNull();
535         encoder << responseIsNull;
536         if (responseIsNull)
537             return;
538
539         encoder << resourceResponse.url().string();
540         encoder << static_cast<int32_t>(resourceResponse.httpStatusCode());
541         encoder << resourceResponse.httpHeaderFields();
542
543         encoder << resourceResponse.mimeType();
544         encoder << resourceResponse.textEncodingName();
545         encoder << static_cast<int64_t>(resourceResponse.expectedContentLength());
546         encoder << resourceResponse.httpStatusText();
547         encoder << resourceResponse.suggestedFilename();
548     }
549 }
550
551 bool ArgumentCoder<ResourceResponse>::decode(ArgumentDecoder& decoder, ResourceResponse& resourceResponse)
552 {
553 #if PLATFORM(MAC)
554     bool hasSerializedWebCoreData;
555     if (!decoder.decode(hasSerializedWebCoreData))
556         return false;
557 #else
558     bool hasSerializedWebCoreData = true;
559 #endif
560
561     ResourceResponse response;
562
563     if (!decodePlatformData(decoder, response))
564         return false;
565
566     if (hasSerializedWebCoreData) {
567         bool responseIsNull;
568         if (!decoder.decode(responseIsNull))
569             return false;
570         if (responseIsNull) {
571             resourceResponse = ResourceResponse();
572             return true;
573         }
574
575         String url;
576         if (!decoder.decode(url))
577             return false;
578         response.setURL(URL(URL(), url));
579
580         int32_t httpStatusCode;
581         if (!decoder.decode(httpStatusCode))
582             return false;
583         response.setHTTPStatusCode(httpStatusCode);
584
585         HTTPHeaderMap headers;
586         if (!decoder.decode(headers))
587             return false;
588         for (HTTPHeaderMap::const_iterator it = headers.begin(), end = headers.end(); it != end; ++it)
589             response.setHTTPHeaderField(it->key, it->value);
590
591         String mimeType;
592         if (!decoder.decode(mimeType))
593             return false;
594         response.setMimeType(mimeType);
595
596         String textEncodingName;
597         if (!decoder.decode(textEncodingName))
598             return false;
599         response.setTextEncodingName(textEncodingName);
600
601         int64_t contentLength;
602         if (!decoder.decode(contentLength))
603             return false;
604         response.setExpectedContentLength(contentLength);
605
606         String httpStatusText;
607         if (!decoder.decode(httpStatusText))
608             return false;
609         response.setHTTPStatusText(httpStatusText);
610
611         String suggestedFilename;
612         if (!decoder.decode(suggestedFilename))
613             return false;
614         response.setSuggestedFilename(suggestedFilename);
615     }
616
617     resourceResponse = response;
618
619     return true;
620 }
621
622 void ArgumentCoder<ResourceError>::encode(ArgumentEncoder& encoder, const ResourceError& resourceError)
623 {
624     if (kShouldSerializeWebCoreData) {
625         bool errorIsNull = resourceError.isNull();
626         encoder << errorIsNull;
627         if (errorIsNull)
628             return;
629
630         encoder << resourceError.domain();
631         encoder << resourceError.errorCode();
632         encoder << resourceError.failingURL();
633         encoder << resourceError.localizedDescription();
634         encoder << resourceError.isCancellation();
635         encoder << resourceError.isTimeout();
636     }
637
638     encodePlatformData(encoder, resourceError);
639 }
640
641 bool ArgumentCoder<ResourceError>::decode(ArgumentDecoder& decoder, ResourceError& resourceError)
642 {
643     if (kShouldSerializeWebCoreData) {
644         bool errorIsNull;
645         if (!decoder.decode(errorIsNull))
646             return false;
647         if (errorIsNull) {
648             resourceError = ResourceError();
649             return true;
650         }
651
652         String domain;
653         if (!decoder.decode(domain))
654             return false;
655
656         int errorCode;
657         if (!decoder.decode(errorCode))
658             return false;
659
660         String failingURL;
661         if (!decoder.decode(failingURL))
662             return false;
663
664         String localizedDescription;
665         if (!decoder.decode(localizedDescription))
666             return false;
667
668         bool isCancellation;
669         if (!decoder.decode(isCancellation))
670             return false;
671
672         bool isTimeout;
673         if (!decoder.decode(isTimeout))
674             return false;
675
676         resourceError = ResourceError(domain, errorCode, failingURL, localizedDescription);
677         resourceError.setIsCancellation(isCancellation);
678         resourceError.setIsTimeout(isTimeout);
679     }
680
681     return decodePlatformData(decoder, resourceError);
682 }
683
684 #if PLATFORM(IOS)
685
686 void ArgumentCoder<SelectionRect>::encode(ArgumentEncoder& encoder, const SelectionRect& selectionRect)
687 {
688     encoder << selectionRect.rect();
689     encoder << static_cast<uint32_t>(selectionRect.direction());
690     encoder << selectionRect.minX();
691     encoder << selectionRect.maxX();
692     encoder << selectionRect.maxY();
693     encoder << selectionRect.lineNumber();
694     encoder << selectionRect.isLineBreak();
695     encoder << selectionRect.isFirstOnLine();
696     encoder << selectionRect.isLastOnLine();
697     encoder << selectionRect.containsStart();
698     encoder << selectionRect.containsEnd();
699     encoder << selectionRect.isHorizontal();
700 }
701
702 bool ArgumentCoder<SelectionRect>::decode(ArgumentDecoder& decoder, SelectionRect& selectionRect)
703 {
704     WebCore::IntRect rect;
705     if (!decoder.decode(rect))
706         return false;
707     selectionRect.setRect(rect);
708
709     uint32_t direction;
710     if (!decoder.decode(direction))
711         return false;
712     selectionRect.setDirection((WebCore::TextDirection)direction);
713
714     int intValue;
715     if (!decoder.decode(intValue))
716         return false;
717     selectionRect.setMinX(intValue);
718
719     if (!decoder.decode(intValue))
720         return false;
721     selectionRect.setMaxX(intValue);
722
723     if (!decoder.decode(intValue))
724         return false;
725     selectionRect.setMaxY(intValue);
726
727     if (!decoder.decode(intValue))
728         return false;
729     selectionRect.setLineNumber(intValue);
730
731     bool boolValue;
732     if (!decoder.decode(boolValue))
733         return false;
734     selectionRect.setIsLineBreak(boolValue);
735
736     if (!decoder.decode(boolValue))
737         return false;
738     selectionRect.setIsFirstOnLine(boolValue);
739
740     if (!decoder.decode(boolValue))
741         return false;
742     selectionRect.setIsLastOnLine(boolValue);
743
744     if (!decoder.decode(boolValue))
745         return false;
746     selectionRect.setContainsStart(boolValue);
747
748     if (!decoder.decode(boolValue))
749         return false;
750     selectionRect.setContainsEnd(boolValue);
751
752     if (!decoder.decode(boolValue))
753         return false;
754     selectionRect.setIsHorizontal(boolValue);
755
756     return true;
757 }
758
759 #endif
760
761 void ArgumentCoder<WindowFeatures>::encode(ArgumentEncoder& encoder, const WindowFeatures& windowFeatures)
762 {
763     encoder << windowFeatures.x;
764     encoder << windowFeatures.y;
765     encoder << windowFeatures.width;
766     encoder << windowFeatures.height;
767     encoder << windowFeatures.xSet;
768     encoder << windowFeatures.ySet;
769     encoder << windowFeatures.widthSet;
770     encoder << windowFeatures.heightSet;
771     encoder << windowFeatures.menuBarVisible;
772     encoder << windowFeatures.statusBarVisible;
773     encoder << windowFeatures.toolBarVisible;
774     encoder << windowFeatures.locationBarVisible;
775     encoder << windowFeatures.scrollbarsVisible;
776     encoder << windowFeatures.resizable;
777     encoder << windowFeatures.fullscreen;
778     encoder << windowFeatures.dialog;
779 }
780
781 bool ArgumentCoder<WindowFeatures>::decode(ArgumentDecoder& decoder, WindowFeatures& windowFeatures)
782 {
783     if (!decoder.decode(windowFeatures.x))
784         return false;
785     if (!decoder.decode(windowFeatures.y))
786         return false;
787     if (!decoder.decode(windowFeatures.width))
788         return false;
789     if (!decoder.decode(windowFeatures.height))
790         return false;
791     if (!decoder.decode(windowFeatures.xSet))
792         return false;
793     if (!decoder.decode(windowFeatures.ySet))
794         return false;
795     if (!decoder.decode(windowFeatures.widthSet))
796         return false;
797     if (!decoder.decode(windowFeatures.heightSet))
798         return false;
799     if (!decoder.decode(windowFeatures.menuBarVisible))
800         return false;
801     if (!decoder.decode(windowFeatures.statusBarVisible))
802         return false;
803     if (!decoder.decode(windowFeatures.toolBarVisible))
804         return false;
805     if (!decoder.decode(windowFeatures.locationBarVisible))
806         return false;
807     if (!decoder.decode(windowFeatures.scrollbarsVisible))
808         return false;
809     if (!decoder.decode(windowFeatures.resizable))
810         return false;
811     if (!decoder.decode(windowFeatures.fullscreen))
812         return false;
813     if (!decoder.decode(windowFeatures.dialog))
814         return false;
815     return true;
816 }
817
818
819 void ArgumentCoder<Color>::encode(ArgumentEncoder& encoder, const Color& color)
820 {
821     if (!color.isValid()) {
822         encoder << false;
823         return;
824     }
825
826     encoder << true;
827     encoder << color.rgb();
828 }
829
830 bool ArgumentCoder<Color>::decode(ArgumentDecoder& decoder, Color& color)
831 {
832     bool isValid;
833     if (!decoder.decode(isValid))
834         return false;
835
836     if (!isValid) {
837         color = Color();
838         return true;
839     }
840
841     RGBA32 rgba;
842     if (!decoder.decode(rgba))
843         return false;
844
845     color = Color(rgba);
846     return true;
847 }
848
849
850 void ArgumentCoder<CompositionUnderline>::encode(ArgumentEncoder& encoder, const CompositionUnderline& underline)
851 {
852     encoder << underline.startOffset;
853     encoder << underline.endOffset;
854     encoder << underline.thick;
855     encoder << underline.color;
856 }
857
858 bool ArgumentCoder<CompositionUnderline>::decode(ArgumentDecoder& decoder, CompositionUnderline& underline)
859 {
860     if (!decoder.decode(underline.startOffset))
861         return false;
862     if (!decoder.decode(underline.endOffset))
863         return false;
864     if (!decoder.decode(underline.thick))
865         return false;
866     if (!decoder.decode(underline.color))
867         return false;
868
869     return true;
870 }
871
872
873 void ArgumentCoder<Cookie>::encode(ArgumentEncoder& encoder, const Cookie& cookie)
874 {
875     encoder << cookie.name;
876     encoder << cookie.value;
877     encoder << cookie.domain;
878     encoder << cookie.path;
879     encoder << cookie.expires;
880     encoder << cookie.httpOnly;
881     encoder << cookie.secure;
882     encoder << cookie.session;
883 }
884
885 bool ArgumentCoder<Cookie>::decode(ArgumentDecoder& decoder, Cookie& cookie)
886 {
887     if (!decoder.decode(cookie.name))
888         return false;
889     if (!decoder.decode(cookie.value))
890         return false;
891     if (!decoder.decode(cookie.domain))
892         return false;
893     if (!decoder.decode(cookie.path))
894         return false;
895     if (!decoder.decode(cookie.expires))
896         return false;
897     if (!decoder.decode(cookie.httpOnly))
898         return false;
899     if (!decoder.decode(cookie.secure))
900         return false;
901     if (!decoder.decode(cookie.session))
902         return false;
903
904     return true;
905 }
906
907
908 #if ENABLE(SQL_DATABASE)
909 void ArgumentCoder<DatabaseDetails>::encode(ArgumentEncoder& encoder, const DatabaseDetails& details)
910 {
911     encoder << details.name();
912     encoder << details.displayName();
913     encoder << details.expectedUsage();
914     encoder << details.currentUsage();
915 }
916     
917 bool ArgumentCoder<DatabaseDetails>::decode(ArgumentDecoder& decoder, DatabaseDetails& details)
918 {
919     String name;
920     if (!decoder.decode(name))
921         return false;
922
923     String displayName;
924     if (!decoder.decode(displayName))
925         return false;
926
927     uint64_t expectedUsage;
928     if (!decoder.decode(expectedUsage))
929         return false;
930
931     uint64_t currentUsage;
932     if (!decoder.decode(currentUsage))
933         return false;
934     
935     details = DatabaseDetails(name, displayName, expectedUsage, currentUsage);
936     return true;
937 }
938
939 #endif
940
941 #if PLATFORM(IOS)
942
943 static void encodeSharedBuffer(ArgumentEncoder& encoder, SharedBuffer* buffer)
944 {
945     SharedMemory::Handle handle;
946     encoder << (buffer ? static_cast<uint64_t>(buffer->size()): 0);
947     if (buffer) {
948         RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(buffer->size());
949         memcpy(sharedMemoryBuffer->data(), buffer->data(), buffer->size());
950         sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
951         encoder << handle;
952     }
953 }
954
955 static bool decodeSharedBuffer(ArgumentDecoder& decoder, RefPtr<SharedBuffer>& buffer)
956 {
957     uint64_t bufferSize = 0;
958     if (!decoder.decode(bufferSize))
959         return false;
960
961     if (bufferSize) {
962         SharedMemory::Handle handle;
963         if (!decoder.decode(handle))
964             return false;
965
966         RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly);
967         buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), bufferSize);
968     }
969
970     return true;
971 }
972
973 void ArgumentCoder<PasteboardWebContent>::encode(ArgumentEncoder& encoder, const WebCore::PasteboardWebContent& content)
974 {
975     encoder << content.canSmartCopyOrDelete;
976     encoder << content.dataInStringFormat;
977
978     encodeSharedBuffer(encoder, content.dataInWebArchiveFormat.get());
979     encodeSharedBuffer(encoder, content.dataInRTFDFormat.get());
980     encodeSharedBuffer(encoder, content.dataInRTFFormat.get());
981
982     encoder << content.clientTypes;
983     encoder << static_cast<uint64_t>(content.clientData.size());
984     for (size_t i = 0; i < content.clientData.size(); i++)
985         encodeSharedBuffer(encoder, content.clientData[i].get());
986 }
987
988 bool ArgumentCoder<PasteboardWebContent>::decode(ArgumentDecoder& decoder, WebCore::PasteboardWebContent& content)
989 {
990     if (!decoder.decode(content.canSmartCopyOrDelete))
991         return false;
992     if (!decoder.decode(content.dataInStringFormat))
993         return false;
994     if (!decodeSharedBuffer(decoder, content.dataInWebArchiveFormat))
995         return false;
996     if (!decodeSharedBuffer(decoder, content.dataInRTFDFormat))
997         return false;
998     if (!decodeSharedBuffer(decoder, content.dataInRTFFormat))
999         return false;
1000     if (!decoder.decode(content.clientTypes))
1001         return false;
1002     uint64_t clientDataSize;
1003     if (!decoder.decode(clientDataSize))
1004         return false;
1005     if (clientDataSize)
1006         content.clientData.resize(clientDataSize);
1007     for (size_t i = 0; i < clientDataSize; i++)
1008         decodeSharedBuffer(decoder, content.clientData[i]);
1009     return true;
1010 }
1011
1012 void ArgumentCoder<PasteboardImage>::encode(ArgumentEncoder& encoder, const WebCore::PasteboardImage& pasteboardImage)
1013 {
1014     encodeImage(encoder, pasteboardImage.image.get());
1015     encoder << pasteboardImage.url.url;
1016     encoder << pasteboardImage.url.title;
1017     encoder << pasteboardImage.resourceMIMEType;
1018     if (pasteboardImage.resourceData)
1019         encodeSharedBuffer(encoder, pasteboardImage.resourceData.get());
1020 }
1021
1022 bool ArgumentCoder<PasteboardImage>::decode(ArgumentDecoder& decoder, WebCore::PasteboardImage& pasteboardImage)
1023 {
1024     if (!decodeImage(decoder, pasteboardImage.image))
1025         return false;
1026     if (!decoder.decode(pasteboardImage.url.url))
1027         return false;
1028     if (!decoder.decode(pasteboardImage.url.title))
1029         return false;
1030     if (!decoder.decode(pasteboardImage.resourceMIMEType))
1031         return false;
1032     if (!decodeSharedBuffer(decoder, pasteboardImage.resourceData))
1033         return false;
1034     return true;
1035 }
1036
1037 #endif
1038
1039 void ArgumentCoder<DictationAlternative>::encode(ArgumentEncoder& encoder, const DictationAlternative& dictationAlternative)
1040 {
1041     encoder << dictationAlternative.rangeStart;
1042     encoder << dictationAlternative.rangeLength;
1043     encoder << dictationAlternative.dictationContext;
1044 }
1045
1046 bool ArgumentCoder<DictationAlternative>::decode(ArgumentDecoder& decoder, DictationAlternative& dictationAlternative)
1047 {
1048     if (!decoder.decode(dictationAlternative.rangeStart))
1049         return false;
1050     if (!decoder.decode(dictationAlternative.rangeLength))
1051         return false;
1052     if (!decoder.decode(dictationAlternative.dictationContext))
1053         return false;
1054     return true;
1055 }
1056
1057
1058 void ArgumentCoder<FileChooserSettings>::encode(ArgumentEncoder& encoder, const FileChooserSettings& settings)
1059 {
1060     encoder << settings.allowsMultipleFiles;
1061 #if ENABLE(DIRECTORY_UPLOAD)
1062     encoder << settings.allowsDirectoryUpload;
1063 #endif
1064     encoder << settings.acceptMIMETypes;
1065     encoder << settings.selectedFiles;
1066 #if ENABLE(MEDIA_CAPTURE)
1067     encoder << settings.capture;
1068 #endif
1069 }
1070
1071 bool ArgumentCoder<FileChooserSettings>::decode(ArgumentDecoder& decoder, FileChooserSettings& settings)
1072 {
1073     if (!decoder.decode(settings.allowsMultipleFiles))
1074         return false;
1075 #if ENABLE(DIRECTORY_UPLOAD)
1076     if (!decoder.decode(settings.allowsDirectoryUpload))
1077         return false;
1078 #endif
1079     if (!decoder.decode(settings.acceptMIMETypes))
1080         return false;
1081     if (!decoder.decode(settings.selectedFiles))
1082         return false;
1083 #if ENABLE(MEDIA_CAPTURE)
1084     if (!decoder.decode(settings.capture))
1085         return false;
1086 #endif
1087
1088     return true;
1089 }
1090
1091
1092 void ArgumentCoder<GrammarDetail>::encode(ArgumentEncoder& encoder, const GrammarDetail& detail)
1093 {
1094     encoder << detail.location;
1095     encoder << detail.length;
1096     encoder << detail.guesses;
1097     encoder << detail.userDescription;
1098 }
1099
1100 bool ArgumentCoder<GrammarDetail>::decode(ArgumentDecoder& decoder, GrammarDetail& detail)
1101 {
1102     if (!decoder.decode(detail.location))
1103         return false;
1104     if (!decoder.decode(detail.length))
1105         return false;
1106     if (!decoder.decode(detail.guesses))
1107         return false;
1108     if (!decoder.decode(detail.userDescription))
1109         return false;
1110
1111     return true;
1112 }
1113
1114 void ArgumentCoder<TextCheckingRequestData>::encode(ArgumentEncoder& encoder, const TextCheckingRequestData& request)
1115 {
1116     encoder << request.sequence();
1117     encoder << request.text();
1118     encoder << request.mask();
1119     encoder.encodeEnum(request.processType());
1120 }
1121
1122 bool ArgumentCoder<TextCheckingRequestData>::decode(ArgumentDecoder& decoder, TextCheckingRequestData& request)
1123 {
1124     int sequence;
1125     if (!decoder.decode(sequence))
1126         return false;
1127
1128     String text;
1129     if (!decoder.decode(text))
1130         return false;
1131
1132     TextCheckingTypeMask mask;
1133     if (!decoder.decode(mask))
1134         return false;
1135
1136     TextCheckingProcessType processType;
1137     if (!decoder.decodeEnum(processType))
1138         return false;
1139
1140     request = TextCheckingRequestData(sequence, text, mask, processType);
1141     return true;
1142 }
1143
1144 void ArgumentCoder<TextCheckingResult>::encode(ArgumentEncoder& encoder, const TextCheckingResult& result)
1145 {
1146     encoder.encodeEnum(result.type);
1147     encoder << result.location;
1148     encoder << result.length;
1149     encoder << result.details;
1150     encoder << result.replacement;
1151 }
1152
1153 bool ArgumentCoder<TextCheckingResult>::decode(ArgumentDecoder& decoder, TextCheckingResult& result)
1154 {
1155     if (!decoder.decodeEnum(result.type))
1156         return false;
1157     if (!decoder.decode(result.location))
1158         return false;
1159     if (!decoder.decode(result.length))
1160         return false;
1161     if (!decoder.decode(result.details))
1162         return false;
1163     if (!decoder.decode(result.replacement))
1164         return false;
1165     return true;
1166 }
1167
1168 void ArgumentCoder<DragSession>::encode(ArgumentEncoder& encoder, const DragSession& result)
1169 {
1170     encoder.encodeEnum(result.operation);
1171     encoder << result.mouseIsOverFileInput;
1172     encoder << result.numberOfItemsToBeAccepted;
1173 }
1174
1175 bool ArgumentCoder<DragSession>::decode(ArgumentDecoder& decoder, DragSession& result)
1176 {
1177     if (!decoder.decodeEnum(result.operation))
1178         return false;
1179     if (!decoder.decode(result.mouseIsOverFileInput))
1180         return false;
1181     if (!decoder.decode(result.numberOfItemsToBeAccepted))
1182         return false;
1183     return true;
1184 }
1185
1186 void ArgumentCoder<URL>::encode(ArgumentEncoder& encoder, const URL& result)
1187 {
1188     encoder << result.string();
1189 }
1190     
1191 bool ArgumentCoder<URL>::decode(ArgumentDecoder& decoder, URL& result)
1192 {
1193     String urlAsString;
1194     if (!decoder.decode(urlAsString))
1195         return false;
1196     result = URL(WebCore::ParsedURLString, urlAsString);
1197     return true;
1198 }
1199
1200 void ArgumentCoder<WebCore::UserStyleSheet>::encode(ArgumentEncoder& encoder, const WebCore::UserStyleSheet& userStyleSheet)
1201 {
1202     encoder << userStyleSheet.source();
1203     encoder << userStyleSheet.url();
1204     encoder << userStyleSheet.whitelist();
1205     encoder << userStyleSheet.blacklist();
1206     encoder.encodeEnum(userStyleSheet.injectedFrames());
1207     encoder.encodeEnum(userStyleSheet.level());
1208 }
1209
1210 bool ArgumentCoder<WebCore::UserStyleSheet>::decode(ArgumentDecoder& decoder, WebCore::UserStyleSheet& userStyleSheet)
1211 {
1212     String source;
1213     if (!decoder.decode(source))
1214         return false;
1215
1216     URL url;
1217     if (!decoder.decode(url))
1218         return false;
1219
1220     Vector<String> whitelist;
1221     if (!decoder.decode(whitelist))
1222         return false;
1223
1224     Vector<String> blacklist;
1225     if (!decoder.decode(blacklist))
1226         return false;
1227
1228     WebCore::UserContentInjectedFrames injectedFrames;
1229     if (!decoder.decodeEnum(injectedFrames))
1230         return false;
1231
1232     WebCore::UserStyleLevel level;
1233     if (!decoder.decodeEnum(level))
1234         return false;
1235
1236     userStyleSheet = WebCore::UserStyleSheet(source, url, whitelist, blacklist, injectedFrames, level);
1237     return true;
1238 }
1239
1240 void ArgumentCoder<WebCore::UserScript>::encode(ArgumentEncoder& encoder, const WebCore::UserScript& userScript)
1241 {
1242     encoder << userScript.source();
1243     encoder << userScript.url();
1244     encoder << userScript.whitelist();
1245     encoder << userScript.blacklist();
1246     encoder.encodeEnum(userScript.injectionTime());
1247     encoder.encodeEnum(userScript.injectedFrames());
1248 }
1249
1250 bool ArgumentCoder<WebCore::UserScript>::decode(ArgumentDecoder& decoder, WebCore::UserScript& userScript)
1251 {
1252     String source;
1253     if (!decoder.decode(source))
1254         return false;
1255
1256     URL url;
1257     if (!decoder.decode(url))
1258         return false;
1259
1260     Vector<String> whitelist;
1261     if (!decoder.decode(whitelist))
1262         return false;
1263
1264     Vector<String> blacklist;
1265     if (!decoder.decode(blacklist))
1266         return false;
1267
1268     WebCore::UserScriptInjectionTime injectionTime;
1269     if (!decoder.decodeEnum(injectionTime))
1270         return false;
1271
1272     WebCore::UserContentInjectedFrames injectedFrames;
1273     if (!decoder.decodeEnum(injectedFrames))
1274         return false;
1275
1276     userScript = WebCore::UserScript(source, url, whitelist, blacklist, injectionTime, injectedFrames);
1277     return true;
1278 }
1279
1280 void ArgumentCoder<WebCore::ScrollableAreaParameters>::encode(ArgumentEncoder& encoder, const WebCore::ScrollableAreaParameters& parameters)
1281 {
1282     encoder.encodeEnum(parameters.horizontalScrollElasticity);
1283     encoder.encodeEnum(parameters.verticalScrollElasticity);
1284
1285     encoder.encodeEnum(parameters.horizontalScrollbarMode);
1286     encoder.encodeEnum(parameters.verticalScrollbarMode);
1287
1288     encoder << parameters.hasEnabledHorizontalScrollbar;
1289     encoder << parameters.hasEnabledVerticalScrollbar;
1290 }
1291
1292 bool ArgumentCoder<WebCore::ScrollableAreaParameters>::decode(ArgumentDecoder& decoder, WebCore::ScrollableAreaParameters& params)
1293 {
1294     if (!decoder.decodeEnum(params.horizontalScrollElasticity))
1295         return false;
1296     if (!decoder.decodeEnum(params.verticalScrollElasticity))
1297         return false;
1298
1299     if (!decoder.decodeEnum(params.horizontalScrollbarMode))
1300         return false;
1301     if (!decoder.decodeEnum(params.verticalScrollbarMode))
1302         return false;
1303
1304     if (!decoder.decode(params.hasEnabledHorizontalScrollbar))
1305         return false;
1306     if (!decoder.decode(params.hasEnabledVerticalScrollbar))
1307         return false;
1308     
1309     return true;
1310 }
1311
1312 void ArgumentCoder<WebCore::FixedPositionViewportConstraints>::encode(ArgumentEncoder& encoder, const WebCore::FixedPositionViewportConstraints& viewportConstraints)
1313 {
1314     encoder << viewportConstraints.alignmentOffset();
1315     encoder << viewportConstraints.anchorEdges();
1316
1317     encoder << viewportConstraints.viewportRectAtLastLayout();
1318     encoder << viewportConstraints.layerPositionAtLastLayout();
1319 }
1320
1321 bool ArgumentCoder<WebCore::FixedPositionViewportConstraints>::decode(ArgumentDecoder& decoder, WebCore::FixedPositionViewportConstraints& viewportConstraints)
1322 {
1323     FloatSize alignmentOffset;
1324     if (!decoder.decode(alignmentOffset))
1325         return false;
1326     
1327     ViewportConstraints::AnchorEdges anchorEdges;
1328     if (!decoder.decode(anchorEdges))
1329         return false;
1330
1331     FloatRect viewportRectAtLastLayout;
1332     if (!decoder.decode(viewportRectAtLastLayout))
1333         return false;
1334
1335     FloatPoint layerPositionAtLastLayout;
1336     if (!decoder.decode(layerPositionAtLastLayout))
1337         return false;
1338
1339     viewportConstraints = WebCore::FixedPositionViewportConstraints();
1340     viewportConstraints.setAlignmentOffset(alignmentOffset);
1341     viewportConstraints.setAnchorEdges(anchorEdges);
1342
1343     viewportConstraints.setViewportRectAtLastLayout(viewportRectAtLastLayout);
1344     viewportConstraints.setLayerPositionAtLastLayout(layerPositionAtLastLayout);
1345     
1346     return true;
1347 }
1348
1349 void ArgumentCoder<WebCore::StickyPositionViewportConstraints>::encode(ArgumentEncoder& encoder, const WebCore::StickyPositionViewportConstraints& viewportConstraints)
1350 {
1351     encoder << viewportConstraints.alignmentOffset();
1352     encoder << viewportConstraints.anchorEdges();
1353
1354     encoder << viewportConstraints.leftOffset();
1355     encoder << viewportConstraints.rightOffset();
1356     encoder << viewportConstraints.topOffset();
1357     encoder << viewportConstraints.bottomOffset();
1358
1359     encoder << viewportConstraints.constrainingRectAtLastLayout();
1360     encoder << viewportConstraints.containingBlockRect();
1361     encoder << viewportConstraints.stickyBoxRect();
1362
1363     encoder << viewportConstraints.stickyOffsetAtLastLayout();
1364     encoder << viewportConstraints.layerPositionAtLastLayout();
1365 }
1366
1367 bool ArgumentCoder<WebCore::StickyPositionViewportConstraints>::decode(ArgumentDecoder& decoder, WebCore::StickyPositionViewportConstraints& viewportConstraints)
1368 {
1369     FloatSize alignmentOffset;
1370     if (!decoder.decode(alignmentOffset))
1371         return false;
1372     
1373     ViewportConstraints::AnchorEdges anchorEdges;
1374     if (!decoder.decode(anchorEdges))
1375         return false;
1376     
1377     float leftOffset;
1378     if (!decoder.decode(leftOffset))
1379         return false;
1380
1381     float rightOffset;
1382     if (!decoder.decode(rightOffset))
1383         return false;
1384
1385     float topOffset;
1386     if (!decoder.decode(topOffset))
1387         return false;
1388
1389     float bottomOffset;
1390     if (!decoder.decode(bottomOffset))
1391         return false;
1392     
1393     FloatRect constrainingRectAtLastLayout;
1394     if (!decoder.decode(constrainingRectAtLastLayout))
1395         return false;
1396
1397     FloatRect containingBlockRect;
1398     if (!decoder.decode(containingBlockRect))
1399         return false;
1400
1401     FloatRect stickyBoxRect;
1402     if (!decoder.decode(stickyBoxRect))
1403         return false;
1404
1405     FloatSize stickyOffsetAtLastLayout;
1406     if (!decoder.decode(stickyOffsetAtLastLayout))
1407         return false;
1408     
1409     FloatPoint layerPositionAtLastLayout;
1410     if (!decoder.decode(layerPositionAtLastLayout))
1411         return false;
1412     
1413     viewportConstraints = WebCore::StickyPositionViewportConstraints();
1414     viewportConstraints.setAlignmentOffset(alignmentOffset);
1415     viewportConstraints.setAnchorEdges(anchorEdges);
1416
1417     viewportConstraints.setLeftOffset(leftOffset);
1418     viewportConstraints.setRightOffset(rightOffset);
1419     viewportConstraints.setTopOffset(topOffset);
1420     viewportConstraints.setBottomOffset(bottomOffset);
1421     
1422     viewportConstraints.setConstrainingRectAtLastLayout(constrainingRectAtLastLayout);
1423     viewportConstraints.setContainingBlockRect(containingBlockRect);
1424     viewportConstraints.setStickyBoxRect(stickyBoxRect);
1425
1426     viewportConstraints.setStickyOffsetAtLastLayout(stickyOffsetAtLastLayout);
1427     viewportConstraints.setLayerPositionAtLastLayout(layerPositionAtLastLayout);
1428
1429     return true;
1430 }
1431
1432 #if ENABLE(CSS_FILTERS) && !USE(COORDINATED_GRAPHICS)
1433 static void encodeFilterOperation(ArgumentEncoder& encoder, const FilterOperation& filter)
1434 {
1435     encoder.encodeEnum(filter.type());
1436
1437     switch (filter.type()) {
1438     case FilterOperation::REFERENCE: {
1439         const auto& referenceFilter = static_cast<const ReferenceFilterOperation&>(filter);
1440         encoder << referenceFilter.url();
1441         encoder << referenceFilter.fragment();
1442         break;
1443     }
1444     case FilterOperation::GRAYSCALE:
1445     case FilterOperation::SEPIA:
1446     case FilterOperation::SATURATE:
1447     case FilterOperation::HUE_ROTATE:
1448         encoder << static_cast<const BasicColorMatrixFilterOperation&>(filter).amount();
1449         break;
1450     case FilterOperation::INVERT:
1451     case FilterOperation::OPACITY:
1452     case FilterOperation::BRIGHTNESS:
1453     case FilterOperation::CONTRAST:
1454         encoder << static_cast<const BasicComponentTransferFilterOperation&>(filter).amount();
1455         break;
1456     case FilterOperation::BLUR:
1457         encoder << static_cast<const BlurFilterOperation&>(filter).stdDeviation();
1458         break;
1459     case FilterOperation::DROP_SHADOW: {
1460         const auto& dropShadowFilter = static_cast<const DropShadowFilterOperation&>(filter);
1461         encoder << dropShadowFilter.location();
1462         encoder << dropShadowFilter.stdDeviation();
1463         encoder << dropShadowFilter.color();
1464         break;
1465     }
1466 #if ENABLE(CSS_SHADERS)
1467     case FilterOperation::CUSTOM:
1468     case FilterOperation::VALIDATED_CUSTOM:
1469         ASSERT_NOT_REACHED();
1470         break;
1471 #endif
1472     case FilterOperation::PASSTHROUGH:
1473     case FilterOperation::NONE:
1474         break;
1475     };
1476 }
1477
1478 static bool decodeFilterOperation(ArgumentDecoder& decoder, RefPtr<FilterOperation>& filter)
1479 {
1480     FilterOperation::OperationType type;
1481     if (!decoder.decodeEnum(type))
1482         return false;
1483
1484     switch (type) {
1485     case FilterOperation::REFERENCE: {
1486         String url;
1487         String fragment;
1488         if (!decoder.decode(url))
1489             return false;
1490         if (!decoder.decode(fragment))
1491             return false;
1492         filter = ReferenceFilterOperation::create(url, fragment, type);
1493         break;
1494     }
1495     case FilterOperation::GRAYSCALE:
1496     case FilterOperation::SEPIA:
1497     case FilterOperation::SATURATE:
1498     case FilterOperation::HUE_ROTATE: {
1499         double amount;
1500         if (!decoder.decode(amount))
1501             return false;
1502         filter = BasicColorMatrixFilterOperation::create(amount, type);
1503         break;
1504     }
1505     case FilterOperation::INVERT:
1506     case FilterOperation::OPACITY:
1507     case FilterOperation::BRIGHTNESS:
1508     case FilterOperation::CONTRAST: {
1509         double amount;
1510         if (!decoder.decode(amount))
1511             return false;
1512         filter = BasicComponentTransferFilterOperation::create(amount, type);
1513         break;
1514     }
1515     case FilterOperation::BLUR: {
1516         Length stdDeviation;
1517         if (!decoder.decode(stdDeviation))
1518             return false;
1519         filter = BlurFilterOperation::create(stdDeviation, type);
1520         break;
1521     }
1522     case FilterOperation::DROP_SHADOW: {
1523         IntPoint location;
1524         int stdDeviation;
1525         Color color;
1526         if (!decoder.decode(location))
1527             return false;
1528         if (!decoder.decode(stdDeviation))
1529             return false;
1530         if (!decoder.decode(color))
1531             return false;
1532         filter = DropShadowFilterOperation::create(location, stdDeviation, color, type);
1533         break;
1534     }
1535 #if ENABLE(CSS_SHADERS)
1536     case FilterOperation::CUSTOM:
1537     case FilterOperation::VALIDATED_CUSTOM:
1538         ASSERT_NOT_REACHED();
1539         break;
1540 #endif
1541     case FilterOperation::PASSTHROUGH:
1542     case FilterOperation::NONE:
1543         break;
1544     };
1545
1546     return true;
1547 }
1548
1549
1550 void ArgumentCoder<FilterOperations>::encode(ArgumentEncoder& encoder, const FilterOperations& filters)
1551 {
1552     encoder << static_cast<uint64_t>(filters.size());
1553
1554     for (const auto& filter : filters.operations())
1555         encodeFilterOperation(encoder, *filter);
1556 }
1557
1558 bool ArgumentCoder<FilterOperations>::decode(ArgumentDecoder& decoder, FilterOperations& filters)
1559 {
1560     uint64_t filterCount;
1561     if (!decoder.decode(filterCount))
1562         return false;
1563
1564     for (uint64_t i = 0; i < filterCount; ++i) {
1565         RefPtr<FilterOperation> filter;
1566         if (!decodeFilterOperation(decoder, filter))
1567             return false;
1568         filters.operations().append(std::move(filter));
1569     }
1570
1571     return true;
1572 }
1573 #endif // ENABLE(CSS_FILTERS) && !USE(COORDINATED_GRAPHICS)
1574
1575 #if ENABLE(INDEXED_DATABASE)
1576 void ArgumentCoder<IDBDatabaseMetadata>::encode(ArgumentEncoder& encoder, const IDBDatabaseMetadata& metadata)
1577 {
1578     encoder << metadata.name << metadata.id << metadata.version << metadata.maxObjectStoreId << metadata.objectStores;
1579 }
1580
1581 bool ArgumentCoder<IDBDatabaseMetadata>::decode(ArgumentDecoder& decoder, IDBDatabaseMetadata& metadata)
1582 {
1583     if (!decoder.decode(metadata.name))
1584         return false;
1585
1586     if (!decoder.decode(metadata.id))
1587         return false;
1588
1589     if (!decoder.decode(metadata.version))
1590         return false;
1591
1592     if (!decoder.decode(metadata.maxObjectStoreId))
1593         return false;
1594
1595     if (!decoder.decode(metadata.objectStores))
1596         return false;
1597
1598     return true;
1599 }
1600
1601 void ArgumentCoder<IDBIndexMetadata>::encode(ArgumentEncoder& encoder, const IDBIndexMetadata& metadata)
1602 {
1603     encoder << metadata.name << metadata.id << metadata.keyPath << metadata.unique << metadata.multiEntry;
1604 }
1605
1606 bool ArgumentCoder<IDBIndexMetadata>::decode(ArgumentDecoder& decoder, IDBIndexMetadata& metadata)
1607 {
1608     if (!decoder.decode(metadata.name))
1609         return false;
1610
1611     if (!decoder.decode(metadata.id))
1612         return false;
1613
1614     if (!decoder.decode(metadata.keyPath))
1615         return false;
1616
1617     if (!decoder.decode(metadata.unique))
1618         return false;
1619
1620     if (!decoder.decode(metadata.multiEntry))
1621         return false;
1622
1623     return true;
1624 }
1625
1626 void ArgumentCoder<IDBKeyData>::encode(ArgumentEncoder& encoder, const IDBKeyData& keyData)
1627 {
1628     encoder << keyData.isNull;
1629     if (keyData.isNull)
1630         return;
1631
1632     encoder.encodeEnum(keyData.type);
1633
1634     switch (keyData.type) {
1635     case IDBKey::InvalidType:
1636         break;
1637     case IDBKey::ArrayType:
1638         encoder << keyData.arrayValue;
1639         break;
1640     case IDBKey::StringType:
1641         encoder << keyData.stringValue;
1642         break;
1643     case IDBKey::DateType:
1644     case IDBKey::NumberType:
1645         encoder << keyData.numberValue;
1646         break;
1647     case IDBKey::MinType:
1648         ASSERT_NOT_REACHED();
1649         break;
1650     }
1651 }
1652
1653 bool ArgumentCoder<IDBKeyData>::decode(ArgumentDecoder& decoder, IDBKeyData& keyData)
1654 {
1655     if (!decoder.decode(keyData.isNull))
1656         return false;
1657
1658     if (keyData.isNull)
1659         return true;
1660
1661     if (!decoder.decodeEnum(keyData.type))
1662         return false;
1663
1664     switch (keyData.type) {
1665     case IDBKey::InvalidType:
1666         break;
1667     case IDBKey::ArrayType:
1668         if (!decoder.decode(keyData.arrayValue))
1669             return false;
1670         break;
1671     case IDBKey::StringType:
1672         if (!decoder.decode(keyData.stringValue))
1673             return false;
1674         break;
1675     case IDBKey::DateType:
1676     case IDBKey::NumberType:
1677         if (!decoder.decode(keyData.numberValue))
1678             return false;
1679         break;
1680     case IDBKey::MinType:
1681         ASSERT_NOT_REACHED();
1682         return false;
1683     }
1684
1685     return true;
1686 }
1687
1688 void ArgumentCoder<IDBKeyPath>::encode(ArgumentEncoder& encoder, const IDBKeyPath& keyPath)
1689 {
1690     encoder.encodeEnum(keyPath.type());
1691
1692     switch (keyPath.type()) {
1693     case IDBKeyPath::NullType:
1694         break;
1695     case IDBKeyPath::StringType:
1696         encoder << keyPath.string();
1697         break;
1698     case IDBKeyPath::ArrayType:
1699         encoder << keyPath.array();
1700         break;
1701     default:
1702         ASSERT_NOT_REACHED();
1703     }
1704 }
1705
1706 bool ArgumentCoder<IDBKeyPath>::decode(ArgumentDecoder& decoder, IDBKeyPath& keyPath)
1707 {
1708     IDBKeyPath::Type type;
1709     if (!decoder.decodeEnum(type))
1710         return false;
1711
1712     switch (type) {
1713     case IDBKeyPath::NullType:
1714         keyPath = IDBKeyPath();
1715         return true;
1716
1717     case IDBKeyPath::StringType: {
1718         String string;
1719         if (!decoder.decode(string))
1720             return false;
1721
1722         keyPath = IDBKeyPath(string);
1723         return true;
1724     }
1725     case IDBKeyPath::ArrayType: {
1726         Vector<String> array;
1727         if (!decoder.decode(array))
1728             return false;
1729
1730         keyPath = IDBKeyPath(array);
1731         return true;
1732     }
1733     default:
1734         return false;
1735     }
1736 }
1737
1738 void ArgumentCoder<IDBObjectStoreMetadata>::encode(ArgumentEncoder& encoder, const IDBObjectStoreMetadata& metadata)
1739 {
1740     encoder << metadata.name << metadata.id << metadata.keyPath << metadata.autoIncrement << metadata.maxIndexId << metadata.indexes;
1741 }
1742
1743 bool ArgumentCoder<IDBObjectStoreMetadata>::decode(ArgumentDecoder& decoder, IDBObjectStoreMetadata& metadata)
1744 {
1745     if (!decoder.decode(metadata.name))
1746         return false;
1747
1748     if (!decoder.decode(metadata.id))
1749         return false;
1750
1751     if (!decoder.decode(metadata.keyPath))
1752         return false;
1753
1754     if (!decoder.decode(metadata.autoIncrement))
1755         return false;
1756
1757     if (!decoder.decode(metadata.maxIndexId))
1758         return false;
1759
1760     if (!decoder.decode(metadata.indexes))
1761         return false;
1762
1763     return true;
1764 }
1765 #endif
1766
1767 } // namespace IPC