Add WK api to get capture attribute for supporting HTML media capture
[profile/ivi/webkit-efl.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/Credential.h>
32 #include <WebCore/Cursor.h>
33 #include <WebCore/DatabaseDetails.h>
34 #include <WebCore/DragSession.h>
35 #include <WebCore/Editor.h>
36 #include <WebCore/FileChooser.h>
37 #include <WebCore/GraphicsContext.h>
38 #include <WebCore/GraphicsLayer.h>
39 #include <WebCore/Image.h>
40 #include <WebCore/KURL.h>
41 #include <WebCore/PluginData.h>
42 #include <WebCore/ProtectionSpace.h>
43 #include <WebCore/TextCheckerClient.h>
44 #include <WebCore/ViewportArguments.h>
45 #include <WebCore/WindowFeatures.h>
46 #include <wtf/text/StringHash.h>
47
48 #if USE(UI_SIDE_COMPOSITING)
49 #include <WebCore/Animation.h>
50 #include <WebCore/FloatPoint3D.h>
51 #include <WebCore/TransformationMatrix.h>
52
53 #if ENABLE(CSS_FILTERS)
54 #include <WebCore/FilterOperations.h>
55 #endif
56 #endif
57
58 using namespace WebCore;
59 using namespace WebKit;
60
61 namespace CoreIPC {
62
63 void ArgumentCoder<AffineTransform>::encode(ArgumentEncoder* encoder, const AffineTransform& affineTransform)
64 {
65     SimpleArgumentCoder<AffineTransform>::encode(encoder, affineTransform);
66 }
67
68 bool ArgumentCoder<AffineTransform>::decode(ArgumentDecoder* decoder, AffineTransform& affineTransform)
69 {
70     return SimpleArgumentCoder<AffineTransform>::decode(decoder, affineTransform);
71 }
72
73
74 void ArgumentCoder<FloatPoint>::encode(ArgumentEncoder* encoder, const FloatPoint& floatPoint)
75 {
76     SimpleArgumentCoder<FloatPoint>::encode(encoder, floatPoint);
77 }
78
79 bool ArgumentCoder<FloatPoint>::decode(ArgumentDecoder* decoder, FloatPoint& floatPoint)
80 {
81     return SimpleArgumentCoder<FloatPoint>::decode(decoder, floatPoint);
82 }
83
84
85 void ArgumentCoder<FloatRect>::encode(ArgumentEncoder* encoder, const FloatRect& floatRect)
86 {
87     SimpleArgumentCoder<FloatRect>::encode(encoder, floatRect);
88 }
89
90 bool ArgumentCoder<FloatRect>::decode(ArgumentDecoder* decoder, FloatRect& floatRect)
91 {
92     return SimpleArgumentCoder<FloatRect>::decode(decoder, floatRect);
93 }
94
95
96 void ArgumentCoder<FloatSize>::encode(ArgumentEncoder* encoder, const FloatSize& floatSize)
97 {
98     SimpleArgumentCoder<FloatSize>::encode(encoder, floatSize);
99 }
100
101 bool ArgumentCoder<FloatSize>::decode(ArgumentDecoder* decoder, FloatSize& floatSize)
102 {
103     return SimpleArgumentCoder<FloatSize>::decode(decoder, floatSize);
104 }
105
106
107 void ArgumentCoder<IntPoint>::encode(ArgumentEncoder* encoder, const IntPoint& intPoint)
108 {
109     SimpleArgumentCoder<IntPoint>::encode(encoder, intPoint);
110 }
111
112 bool ArgumentCoder<IntPoint>::decode(ArgumentDecoder* decoder, IntPoint& intPoint)
113 {
114     return SimpleArgumentCoder<IntPoint>::decode(decoder, intPoint);
115 }
116
117
118 void ArgumentCoder<IntRect>::encode(ArgumentEncoder* encoder, const IntRect& intRect)
119 {
120     SimpleArgumentCoder<IntRect>::encode(encoder, intRect);
121 }
122
123 bool ArgumentCoder<IntRect>::decode(ArgumentDecoder* decoder, IntRect& intRect)
124 {
125     return SimpleArgumentCoder<IntRect>::decode(decoder, intRect);
126 }
127
128
129 void ArgumentCoder<IntSize>::encode(ArgumentEncoder* encoder, const IntSize& intSize)
130 {
131     SimpleArgumentCoder<IntSize>::encode(encoder, intSize);
132 }
133
134 bool ArgumentCoder<IntSize>::decode(ArgumentDecoder* decoder, IntSize& intSize)
135 {
136     return SimpleArgumentCoder<IntSize>::decode(decoder, intSize);
137 }
138
139 void ArgumentCoder<ViewportAttributes>::encode(ArgumentEncoder* encoder, const ViewportAttributes& viewportAttributes)
140 {
141     SimpleArgumentCoder<ViewportAttributes>::encode(encoder, viewportAttributes);
142 }
143
144 bool ArgumentCoder<ViewportAttributes>::decode(ArgumentDecoder* decoder, ViewportAttributes& viewportAttributes)
145 {
146     return SimpleArgumentCoder<ViewportAttributes>::decode(decoder, viewportAttributes);
147 }
148
149 void ArgumentCoder<MimeClassInfo>::encode(ArgumentEncoder* encoder, const MimeClassInfo& mimeClassInfo)
150 {
151     encoder->encode(mimeClassInfo.type);
152     encoder->encode(mimeClassInfo.desc);
153     encoder->encode(mimeClassInfo.extensions);
154 }
155
156 bool ArgumentCoder<MimeClassInfo>::decode(ArgumentDecoder* decoder, MimeClassInfo& mimeClassInfo)
157 {
158     if (!decoder->decode(mimeClassInfo.type))
159         return false;
160     if (!decoder->decode(mimeClassInfo.desc))
161         return false;
162     if (!decoder->decode(mimeClassInfo.extensions))
163         return false;
164
165     return true;
166 }
167
168
169 void ArgumentCoder<PluginInfo>::encode(ArgumentEncoder* encoder, const PluginInfo& pluginInfo)
170 {
171     encoder->encode(pluginInfo.name);
172     encoder->encode(pluginInfo.file);
173     encoder->encode(pluginInfo.desc);
174     encoder->encode(pluginInfo.mimes);
175 }
176     
177 bool ArgumentCoder<PluginInfo>::decode(ArgumentDecoder* decoder, PluginInfo& pluginInfo)
178 {
179     if (!decoder->decode(pluginInfo.name))
180         return false;
181     if (!decoder->decode(pluginInfo.file))
182         return false;
183     if (!decoder->decode(pluginInfo.desc))
184         return false;
185     if (!decoder->decode(pluginInfo.mimes))
186         return false;
187
188     return true;
189 }
190
191
192 void ArgumentCoder<HTTPHeaderMap>::encode(ArgumentEncoder* encoder, const HTTPHeaderMap& headerMap)
193 {
194     encoder->encode(static_cast<const HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap));
195 }
196
197 bool ArgumentCoder<HTTPHeaderMap>::decode(ArgumentDecoder* decoder, HTTPHeaderMap& headerMap)
198 {
199     return decoder->decode(static_cast<HashMap<AtomicString, String, CaseFoldingHash>&>(headerMap));
200 }
201
202
203 void ArgumentCoder<AuthenticationChallenge>::encode(ArgumentEncoder* encoder, const AuthenticationChallenge& challenge)
204 {
205     encoder->encode(challenge.protectionSpace());
206     encoder->encode(challenge.proposedCredential());
207     encoder->encode(challenge.previousFailureCount());
208     encoder->encode(challenge.failureResponse());
209     encoder->encode(challenge.error());
210 }
211
212 bool ArgumentCoder<AuthenticationChallenge>::decode(ArgumentDecoder* decoder, AuthenticationChallenge& challenge)
213 {    
214     ProtectionSpace protectionSpace;
215     if (!decoder->decode(protectionSpace))
216         return false;
217
218     Credential proposedCredential;
219     if (!decoder->decode(proposedCredential))
220         return false;
221
222     unsigned previousFailureCount;    
223     if (!decoder->decode(previousFailureCount))
224         return false;
225
226     ResourceResponse failureResponse;
227     if (!decoder->decode(failureResponse))
228         return false;
229
230     ResourceError error;
231     if (!decoder->decode(error))
232         return false;
233     
234     challenge = AuthenticationChallenge(protectionSpace, proposedCredential, previousFailureCount, failureResponse, error);
235     return true;
236 }
237
238
239 void ArgumentCoder<ProtectionSpace>::encode(ArgumentEncoder* encoder, const ProtectionSpace& space)
240 {
241     encoder->encode(space.host());
242     encoder->encode(space.port());
243     encoder->encodeEnum(space.serverType());
244     encoder->encode(space.realm());
245     encoder->encodeEnum(space.authenticationScheme());
246 }
247
248 bool ArgumentCoder<ProtectionSpace>::decode(ArgumentDecoder* decoder, ProtectionSpace& space)
249 {
250     String host;
251     if (!decoder->decode(host))
252         return false;
253
254     int port;
255     if (!decoder->decode(port))
256         return false;
257
258     ProtectionSpaceServerType serverType;
259     if (!decoder->decodeEnum(serverType))
260         return false;
261
262     String realm;
263     if (!decoder->decode(realm))
264         return false;
265     
266     ProtectionSpaceAuthenticationScheme authenticationScheme;
267     if (!decoder->decodeEnum(authenticationScheme))
268         return false;
269
270     space = ProtectionSpace(host, port, serverType, realm, authenticationScheme);
271     return true;
272 }
273
274 void ArgumentCoder<Credential>::encode(ArgumentEncoder* encoder, const Credential& credential)
275 {
276     encoder->encode(credential.user());
277     encoder->encode(credential.password());
278     encoder->encodeEnum(credential.persistence());
279 }
280
281 bool ArgumentCoder<Credential>::decode(ArgumentDecoder* decoder, Credential& credential)
282 {
283     String user;
284     if (!decoder->decode(user))
285         return false;
286
287     String password;
288     if (!decoder->decode(password))
289         return false;
290
291     CredentialPersistence persistence;
292     if (!decoder->decodeEnum(persistence))
293         return false;
294     
295     credential = Credential(user, password, persistence);
296     return true;
297 }
298
299 static void encodeImage(ArgumentEncoder* encoder, Image* image)
300 {
301     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), ShareableBitmap::SupportsAlpha);
302     bitmap->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
303
304     ShareableBitmap::Handle handle;
305     bitmap->createHandle(handle);
306
307     encoder->encode(handle);
308 }
309
310 static bool decodeImage(ArgumentDecoder* decoder, RefPtr<Image>& image)
311 {
312     ShareableBitmap::Handle handle;
313     if (!decoder->decode(handle))
314         return false;
315     
316     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
317     if (!bitmap)
318         return false;
319     image = bitmap->createImage();
320     if (!image)
321         return false;
322     return true;
323 }
324
325 void ArgumentCoder<Cursor>::encode(ArgumentEncoder* encoder, const Cursor& cursor)
326 {
327     encoder->encodeEnum(cursor.type());
328         
329     if (cursor.type() != Cursor::Custom)
330         return;
331
332     if (cursor.image()->isNull()) {
333         encoder->encodeBool(false); // There is no valid image being encoded.
334         return;
335     }
336
337     encoder->encodeBool(true);
338     encodeImage(encoder, cursor.image());
339     encoder->encode(cursor.hotSpot());
340 }
341
342 bool ArgumentCoder<Cursor>::decode(ArgumentDecoder* decoder, Cursor& cursor)
343 {
344     Cursor::Type type;
345     if (!decoder->decodeEnum(type))
346         return false;
347
348     if (type > Cursor::Custom)
349         return false;
350
351     if (type != Cursor::Custom) {
352         const Cursor& cursorReference = Cursor::fromType(type);
353         // Calling platformCursor here will eagerly create the platform cursor for the cursor singletons inside WebCore.
354         // This will avoid having to re-create the platform cursors over and over.
355         (void)cursorReference.platformCursor();
356
357         cursor = cursorReference;
358         return true;
359     }
360
361     bool isValidImagePresent;
362     if (!decoder->decode(isValidImagePresent))
363         return false;
364
365     if (!isValidImagePresent) {
366         cursor = Cursor(Image::nullImage(), IntPoint());
367         return true;
368     }
369
370     RefPtr<Image> image;
371     if (!decodeImage(decoder, image))
372         return false;
373
374     IntPoint hotSpot;
375     if (!decoder->decode(hotSpot))
376         return false;
377
378     if (!image->rect().contains(hotSpot))
379         return false;
380
381     cursor = Cursor(image.get(), hotSpot);
382     return true;
383 }
384
385
386 void ArgumentCoder<WindowFeatures>::encode(ArgumentEncoder* encoder, const WindowFeatures& windowFeatures)
387 {
388     encoder->encode(windowFeatures.x);
389     encoder->encode(windowFeatures.y);
390     encoder->encode(windowFeatures.width);
391     encoder->encode(windowFeatures.height);
392     encoder->encode(windowFeatures.xSet);
393     encoder->encode(windowFeatures.ySet);
394     encoder->encode(windowFeatures.widthSet);
395     encoder->encode(windowFeatures.heightSet);
396     encoder->encode(windowFeatures.menuBarVisible);
397     encoder->encode(windowFeatures.statusBarVisible);
398     encoder->encode(windowFeatures.toolBarVisible);
399     encoder->encode(windowFeatures.locationBarVisible);
400     encoder->encode(windowFeatures.scrollbarsVisible);
401     encoder->encode(windowFeatures.resizable);
402     encoder->encode(windowFeatures.fullscreen);
403     encoder->encode(windowFeatures.dialog);
404 }
405
406 bool ArgumentCoder<WindowFeatures>::decode(ArgumentDecoder* decoder, WindowFeatures& windowFeatures)
407 {
408     if (!decoder->decode(windowFeatures.x))
409         return false;
410     if (!decoder->decode(windowFeatures.y))
411         return false;
412     if (!decoder->decode(windowFeatures.width))
413         return false;
414     if (!decoder->decode(windowFeatures.height))
415         return false;
416     if (!decoder->decode(windowFeatures.xSet))
417         return false;
418     if (!decoder->decode(windowFeatures.ySet))
419         return false;
420     if (!decoder->decode(windowFeatures.widthSet))
421         return false;
422     if (!decoder->decode(windowFeatures.heightSet))
423         return false;
424     if (!decoder->decode(windowFeatures.menuBarVisible))
425         return false;
426     if (!decoder->decode(windowFeatures.statusBarVisible))
427         return false;
428     if (!decoder->decode(windowFeatures.toolBarVisible))
429         return false;
430     if (!decoder->decode(windowFeatures.locationBarVisible))
431         return false;
432     if (!decoder->decode(windowFeatures.scrollbarsVisible))
433         return false;
434     if (!decoder->decode(windowFeatures.resizable))
435         return false;
436     if (!decoder->decode(windowFeatures.fullscreen))
437         return false;
438     if (!decoder->decode(windowFeatures.dialog))
439         return false;
440     return true;
441 }
442
443
444 void ArgumentCoder<Color>::encode(ArgumentEncoder* encoder, const Color& color)
445 {
446     if (!color.isValid()) {
447         encoder->encodeBool(false);
448         return;
449     }
450
451     encoder->encodeBool(true);
452     encoder->encode(color.rgb());
453 }
454
455 bool ArgumentCoder<Color>::decode(ArgumentDecoder* decoder, Color& color)
456 {
457     bool isValid;
458     if (!decoder->decode(isValid))
459         return false;
460
461     if (!isValid) {
462         color = Color();
463         return true;
464     }
465
466     RGBA32 rgba;
467     if (!decoder->decode(rgba))
468         return false;
469
470     color = Color(rgba);
471     return true;
472 }
473
474
475 void ArgumentCoder<CompositionUnderline>::encode(ArgumentEncoder* encoder, const CompositionUnderline& underline)
476 {
477     encoder->encode(underline.startOffset);
478     encoder->encode(underline.endOffset);
479     encoder->encode(underline.thick);
480     encoder->encode(underline.color);
481 }
482
483 bool ArgumentCoder<CompositionUnderline>::decode(ArgumentDecoder* decoder, CompositionUnderline& underline)
484 {
485     if (!decoder->decode(underline.startOffset))
486         return false;
487     if (!decoder->decode(underline.endOffset))
488         return false;
489     if (!decoder->decode(underline.thick))
490         return false;
491     if (!decoder->decode(underline.color))
492         return false;
493
494     return true;
495 }
496
497
498 void ArgumentCoder<DatabaseDetails>::encode(ArgumentEncoder* encoder, const DatabaseDetails& details)
499 {
500     encoder->encode(details.name());
501     encoder->encode(details.displayName());
502     encoder->encode(details.expectedUsage());
503     encoder->encode(details.currentUsage());
504 }
505     
506 bool ArgumentCoder<DatabaseDetails>::decode(ArgumentDecoder* decoder, DatabaseDetails& details)
507 {
508     String name;
509     if (!decoder->decode(name))
510         return false;
511
512     String displayName;
513     if (!decoder->decode(displayName))
514         return false;
515
516     uint64_t expectedUsage;
517     if (!decoder->decode(expectedUsage))
518         return false;
519
520     uint64_t currentUsage;
521     if (!decoder->decode(currentUsage))
522         return false;
523     
524     details = DatabaseDetails(name, displayName, expectedUsage, currentUsage);
525     return true;
526 }
527
528
529 void ArgumentCoder<FileChooserSettings>::encode(ArgumentEncoder* encoder, const FileChooserSettings& settings)
530 {
531     encoder->encode(settings.allowsMultipleFiles);
532 #if ENABLE(DIRECTORY_UPLOAD)
533     encoder->encode(settings.allowsDirectoryUpload);
534 #endif
535     encoder->encode(settings.acceptMIMETypes);
536     encoder->encode(settings.selectedFiles);
537 #if ENABLE(MEDIA_CAPTURE)
538     encoder->encode(settings.capture);
539 #endif
540 }
541
542 bool ArgumentCoder<FileChooserSettings>::decode(ArgumentDecoder* decoder, FileChooserSettings& settings)
543 {
544     if (!decoder->decode(settings.allowsMultipleFiles))
545         return false;
546 #if ENABLE(DIRECTORY_UPLOAD)
547     if (!decoder->decode(settings.allowsDirectoryUpload))
548         return false;
549 #endif
550     if (!decoder->decode(settings.acceptMIMETypes))
551         return false;
552     if (!decoder->decode(settings.selectedFiles))
553         return false;
554 #if ENABLE(MEDIA_CAPTURE)
555     if (!decoder->decode(settings.capture))
556         return false;
557 #endif
558
559     return true;
560 }
561
562
563 void ArgumentCoder<GrammarDetail>::encode(ArgumentEncoder* encoder, const GrammarDetail& detail)
564 {
565     encoder->encode(detail.location);
566     encoder->encode(detail.length);
567     encoder->encode(detail.guesses);
568     encoder->encode(detail.userDescription);
569 }
570
571 bool ArgumentCoder<GrammarDetail>::decode(ArgumentDecoder* decoder, GrammarDetail& detail)
572 {
573     if (!decoder->decode(detail.location))
574         return false;
575     if (!decoder->decode(detail.length))
576         return false;
577     if (!decoder->decode(detail.guesses))
578         return false;
579     if (!decoder->decode(detail.userDescription))
580         return false;
581
582     return true;
583 }
584
585
586 void ArgumentCoder<TextCheckingResult>::encode(ArgumentEncoder* encoder, const TextCheckingResult& result)
587 {
588     encoder->encodeEnum(result.type);
589     encoder->encode(result.location);
590     encoder->encode(result.length);
591     encoder->encode(result.details);
592     encoder->encode(result.replacement);
593 }
594
595 bool ArgumentCoder<TextCheckingResult>::decode(ArgumentDecoder* decoder, TextCheckingResult& result)
596 {
597     if (!decoder->decodeEnum(result.type))
598         return false;
599     if (!decoder->decode(result.location))
600         return false;
601     if (!decoder->decode(result.length))
602         return false;
603     if (!decoder->decode(result.details))
604         return false;
605     if (!decoder->decode(result.replacement))
606         return false;
607     return true;
608 }
609
610 void ArgumentCoder<DragSession>::encode(ArgumentEncoder* encoder, const DragSession& result)
611 {
612     encoder->encodeEnum(result.operation);
613     encoder->encode(result.mouseIsOverFileInput);
614     encoder->encode(result.numberOfItemsToBeAccepted);
615 }
616
617 bool ArgumentCoder<DragSession>::decode(ArgumentDecoder* decoder, DragSession& result)
618 {
619     if (!decoder->decodeEnum(result.operation))
620         return false;
621     if (!decoder->decode(result.mouseIsOverFileInput))
622         return false;
623     if (!decoder->decode(result.numberOfItemsToBeAccepted))
624         return false;
625     return true;
626 }
627
628 void ArgumentCoder<KURL>::encode(ArgumentEncoder* encoder, const KURL& result)
629 {
630     encoder->encode(result.string());
631 }
632     
633 bool ArgumentCoder<KURL>::decode(ArgumentDecoder* decoder, KURL& result)
634 {
635     String urlAsString;
636     if (!decoder->decode(urlAsString))
637         return false;
638     result = KURL(WebCore::ParsedURLString, urlAsString);
639     return true;
640 }
641
642 #if USE(UI_SIDE_COMPOSITING)
643 void ArgumentCoder<FloatPoint3D>::encode(ArgumentEncoder* encoder, const FloatPoint3D& floatPoint3D)
644 {
645     SimpleArgumentCoder<FloatPoint3D>::encode(encoder, floatPoint3D);
646 }
647
648 bool ArgumentCoder<FloatPoint3D>::decode(ArgumentDecoder* decoder, FloatPoint3D& floatPoint3D)
649 {
650     return SimpleArgumentCoder<FloatPoint3D>::decode(decoder, floatPoint3D);
651 }
652
653 void ArgumentCoder<Length>::encode(ArgumentEncoder* encoder, const Length& length)
654 {
655     SimpleArgumentCoder<Length>::encode(encoder, length);
656 }
657
658 bool ArgumentCoder<Length>::decode(ArgumentDecoder* decoder, Length& length)
659 {
660     return SimpleArgumentCoder<Length>::decode(decoder, length);
661 }
662
663 void ArgumentCoder<TransformationMatrix>::encode(ArgumentEncoder* encoder, const TransformationMatrix& transformationMatrix)
664 {
665     SimpleArgumentCoder<TransformationMatrix>::encode(encoder, transformationMatrix);
666 }
667
668 bool ArgumentCoder<TransformationMatrix>::decode(ArgumentDecoder* decoder, TransformationMatrix& transformationMatrix)
669 {
670     return SimpleArgumentCoder<TransformationMatrix>::decode(decoder, transformationMatrix);
671 }
672
673 #if ENABLE(CSS_FILTERS)
674 void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder* encoder, const WebCore::FilterOperations& filters)
675 {
676     encoder->encodeUInt32(filters.size());
677     for (size_t i = 0; i < filters.size(); ++i) {
678         const FilterOperation* filter = filters.at(i);
679         FilterOperation::OperationType type = filter->getOperationType();
680         encoder->encodeEnum(type);
681         switch (type) {
682         case FilterOperation::GRAYSCALE:
683         case FilterOperation::SEPIA:
684         case FilterOperation::SATURATE:
685         case FilterOperation::HUE_ROTATE:
686             encoder->encodeDouble(static_cast<const BasicColorMatrixFilterOperation*>(filter)->amount());
687             break;
688         case FilterOperation::INVERT:
689         case FilterOperation::BRIGHTNESS:
690         case FilterOperation::CONTRAST:
691         case FilterOperation::OPACITY:
692             encoder->encodeDouble(static_cast<const BasicComponentTransferFilterOperation*>(filter)->amount());
693             break;
694         case FilterOperation::BLUR:
695             ArgumentCoder<Length>::encode(encoder, static_cast<const BlurFilterOperation*>(filter)->stdDeviation());
696             break;
697         case FilterOperation::DROP_SHADOW: {
698             const DropShadowFilterOperation* shadow = static_cast<const DropShadowFilterOperation*>(filter);
699             ArgumentCoder<IntPoint>::encode(encoder, shadow->location());
700             encoder->encodeInt32(shadow->stdDeviation());
701             ArgumentCoder<Color>::encode(encoder, shadow->color());
702             break;
703         }
704         default:
705             break;
706         }
707     }
708 }
709
710 bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder, WebCore::FilterOperations& filters)
711 {
712     uint32_t size;
713     if (!decoder->decodeUInt32(size))
714         return false;
715
716     Vector<RefPtr<FilterOperation> >& operations = filters.operations();
717
718     for (size_t i = 0; i < size; ++i) {
719         FilterOperation::OperationType type;
720         RefPtr<FilterOperation> filter;
721         if (!decoder->decodeEnum(type))
722             return false;
723
724         switch (type) {
725         case FilterOperation::GRAYSCALE:
726         case FilterOperation::SEPIA:
727         case FilterOperation::SATURATE:
728         case FilterOperation::HUE_ROTATE: {
729             double value;
730             if (!decoder->decodeDouble(value))
731                 return false;
732             filter = BasicColorMatrixFilterOperation::create(value, type);
733             break;
734         }
735         case FilterOperation::INVERT:
736         case FilterOperation::BRIGHTNESS:
737         case FilterOperation::CONTRAST:
738         case FilterOperation::OPACITY: {
739             double value;
740             if (!decoder->decodeDouble(value))
741                 return false;
742             filter = BasicComponentTransferFilterOperation::create(value, type);
743             break;
744         }
745         case FilterOperation::BLUR: {
746             Length length;
747             if (!ArgumentCoder<Length>::decode(decoder, length))
748                 return false;
749             filter = BlurFilterOperation::create(length, type);
750             break;
751         }
752         case FilterOperation::DROP_SHADOW: {
753             IntPoint location;
754             int32_t stdDeviation;
755             Color color;
756             if (!ArgumentCoder<IntPoint>::decode(decoder, location))
757                 return false;
758             if (!decoder->decodeInt32(stdDeviation))
759                 return false;
760             if (!ArgumentCoder<Color>::decode(decoder, color))
761                 return false;
762             filter = DropShadowFilterOperation::create(location, stdDeviation, color, type);
763             break;
764         }
765         default:
766             break;
767         }
768
769         if (filter)
770             operations.append(filter);
771     }
772
773     return true;
774 }
775 #endif
776
777 #endif
778
779 } // namespace CoreIPC