Encode and decode WKTypeRefWrapper objects
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Dec 2014 20:25:10 +0000 (20:25 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Dec 2014 20:25:10 +0000 (20:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139966

Reviewed by Oliver Hunt.

* Shared/UserData.cpp:
(WebKit::UserData::encode):
* Shared/UserData.h:
* Shared/mac/ObjCObjectGraph.mm:
(WebKit::typeFromObject):
(WebKit::ObjCObjectGraph::encode):
(WebKit::ObjCObjectGraph::decode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/UserData.cpp
Source/WebKit2/Shared/UserData.h
Source/WebKit2/Shared/mac/ObjCObjectGraph.mm

index 4db203a..499fc4e 100644 (file)
@@ -1,5 +1,20 @@
 2014-12-27  Anders Carlsson  <andersca@apple.com>
 
+        Encode and decode WKTypeRefWrapper objects
+        https://bugs.webkit.org/show_bug.cgi?id=139966
+
+        Reviewed by Oliver Hunt.
+
+        * Shared/UserData.cpp:
+        (WebKit::UserData::encode):
+        * Shared/UserData.h:
+        * Shared/mac/ObjCObjectGraph.mm:
+        (WebKit::typeFromObject):
+        (WebKit::ObjCObjectGraph::encode):
+        (WebKit::ObjCObjectGraph::decode):
+
+2014-12-27  Anders Carlsson  <andersca@apple.com>
+
         Implement encoding and decoding of ObjCObjectGraph objects
         https://bugs.webkit.org/show_bug.cgi?id=139965
 
index b8f0a1f..e6ffb60 100644 (file)
@@ -151,7 +151,7 @@ bool UserData::decode(IPC::ArgumentDecoder& decoder, UserData& userData)
     return decode(decoder, userData.m_object);
 }
 
-void UserData::encode(IPC::ArgumentEncoder& encoder, const API::Object* object) const
+void UserData::encode(IPC::ArgumentEncoder& encoder, const API::Object* object)
 {
     if (!object) {
         encoder.encodeEnum(API::Object::Type::Null);
@@ -161,7 +161,7 @@ void UserData::encode(IPC::ArgumentEncoder& encoder, const API::Object* object)
     encode(encoder, *object);
 }
 
-void UserData::encode(IPC::ArgumentEncoder& encoder, const API::Object& object) const
+void UserData::encode(IPC::ArgumentEncoder& encoder, const API::Object& object)
 {
     API::Object::Type type = object.type();
     encoder.encodeEnum(type);
index eca5585..5d0a108 100644 (file)
@@ -54,12 +54,12 @@ public:
     void encode(IPC::ArgumentEncoder&) const;
     static bool decode(IPC::ArgumentDecoder&, UserData&);
 
-private:
-    void encode(IPC::ArgumentEncoder&, const API::Object*) const;
-    void encode(IPC::ArgumentEncoder&, const API::Object&) const;
-
+    static void encode(IPC::ArgumentEncoder&, const API::Object*);
     static bool decode(IPC::ArgumentDecoder&, RefPtr<API::Object>&);
 
+private:
+    static void encode(IPC::ArgumentEncoder&, const API::Object&);
+
     RefPtr<API::Object> m_object;
 };
 
index 635aca3..39eb476 100644 (file)
 #import <wtf/Optional.h>
 
 #if WK_API_ENABLED
+#import "UserData.h"
+#import "WKAPICast.h"
 #import "WKBrowsingContextHandleInternal.h"
+#import "WKTypeRefWrapper.h"
 #endif
 
 namespace WebKit {
@@ -106,6 +109,7 @@ enum class ObjCType {
 
 #if WK_API_ENABLED
     WKBrowsingContextHandle,
+    WKTypeRefWrapper,
 #endif
 };
 
@@ -129,6 +133,8 @@ static Optional<ObjCType> typeFromObject(id object)
 #if WK_API_ENABLED
     if (dynamic_objc_cast<WKBrowsingContextHandle>(object))
         return ObjCType::WKBrowsingContextHandle;
+    if (dynamic_objc_cast<WKTypeRefWrapper>(object))
+        return ObjCType::WKTypeRefWrapper;
 #endif
 
     return Nullopt;
@@ -188,6 +194,10 @@ void ObjCObjectGraph::encode(IPC::ArgumentEncoder& encoder, id object)
     case ObjCType::WKBrowsingContextHandle:
         encoder << static_cast<WKBrowsingContextHandle *>(object).pageID;
         break;
+
+    case ObjCType::WKTypeRefWrapper:
+        UserData::encode(encoder, toImpl(static_cast<WKTypeRefWrapper *>(object).object));
+        break;
 #endif
 
     default:
@@ -301,7 +311,16 @@ bool ObjCObjectGraph::decode(IPC::ArgumentDecoder& decoder, RetainPtr<id>& resul
         result = adoptNS([[WKBrowsingContextHandle alloc] _initWithPageID:pageID]);
         break;
     }
+
+    case ObjCType::WKTypeRefWrapper: {
+        RefPtr<API::Object> object;
+        if (!UserData::decode(decoder, object))
+            return false;
+
+        result = adoptNS([[WKTypeRefWrapper alloc] initWithObject:toAPI(object.get())]);
+    }
 #endif
+
     default:
         return false;
     }