Add a separate object that represents a remote object invocation
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 20:38:12 +0000 (20:38 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 20:38:12 +0000 (20:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150639

Reviewed by Tim Horton.

* Shared/API/Cocoa/RemoteObjectInvocation.h: Copied from Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h.
(WebKit::RemoteObjectInvocation::interfaceIdentifier):
(WebKit::RemoteObjectInvocation::encodedInvocation):
* Shared/API/Cocoa/RemoteObjectInvocation.mm: Copied from Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm.
(WebKit::RemoteObjectInvocation::RemoteObjectInvocation):
(WebKit::RemoteObjectInvocation::encode):
(WebKit::RemoteObjectInvocation::decode):
* Shared/API/Cocoa/RemoteObjectRegistry.h:
* Shared/API/Cocoa/RemoteObjectRegistry.messages.in:
* Shared/API/Cocoa/RemoteObjectRegistry.mm:
(WebKit::RemoteObjectRegistry::sendInvocation):
(WebKit::RemoteObjectRegistry::invokeMethod):
* Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
(-[_WKRemoteObjectRegistry _sendInvocation:interface:]):
(-[_WKRemoteObjectRegistry _invokeMethod:]):
* Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h:
* WebKit2.xcodeproj/project.pbxproj:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.h [new file with mode: 0644]
Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm [new file with mode: 0644]
Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h
Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.messages.in
Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm
Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm
Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 321d1eb..7f52384 100644 (file)
@@ -1,3 +1,28 @@
+2015-10-30  Anders Carlsson  <andersca@apple.com>
+
+        Add a separate object that represents a remote object invocation
+        https://bugs.webkit.org/show_bug.cgi?id=150639
+
+        Reviewed by Tim Horton.
+
+        * Shared/API/Cocoa/RemoteObjectInvocation.h: Copied from Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.h.
+        (WebKit::RemoteObjectInvocation::interfaceIdentifier):
+        (WebKit::RemoteObjectInvocation::encodedInvocation):
+        * Shared/API/Cocoa/RemoteObjectInvocation.mm: Copied from Source/WebKit2/Shared/API/Cocoa/RemoteObjectRegistry.mm.
+        (WebKit::RemoteObjectInvocation::RemoteObjectInvocation):
+        (WebKit::RemoteObjectInvocation::encode):
+        (WebKit::RemoteObjectInvocation::decode):
+        * Shared/API/Cocoa/RemoteObjectRegistry.h:
+        * Shared/API/Cocoa/RemoteObjectRegistry.messages.in:
+        * Shared/API/Cocoa/RemoteObjectRegistry.mm:
+        (WebKit::RemoteObjectRegistry::sendInvocation):
+        (WebKit::RemoteObjectRegistry::invokeMethod):
+        * Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
+        (-[_WKRemoteObjectRegistry _sendInvocation:interface:]):
+        (-[_WKRemoteObjectRegistry _invokeMethod:]):
+        * Shared/API/Cocoa/_WKRemoteObjectRegistryInternal.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2015-10-30  Beth Dakin  <bdakin@apple.com>
 
         Another speculative build fix.
diff --git a/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.h b/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.h
new file mode 100644 (file)
index 0000000..123a610
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RemoteObjectInvocation_h
+#define RemoteObjectInvocation_h
+
+#include "APIDictionary.h"
+#include <wtf/text/WTFString.h>
+
+namespace IPC {
+class ArgumentEncoder;
+class ArgumentDecoder;
+}
+
+namespace WebKit {
+
+class RemoteObjectInvocation {
+public:
+    RemoteObjectInvocation();
+    RemoteObjectInvocation(const String& interfaceIdentifier, RefPtr<API::Dictionary>&& encodedInvocation);
+
+    const String& interfaceIdentifier() const { return m_interfaceIdentifier; }
+    const API::Dictionary* encodedInvocation() const { return m_encodedInvocation.get(); }
+
+    void encode(IPC::ArgumentEncoder&) const;
+    static bool decode(IPC::ArgumentDecoder&, RemoteObjectInvocation&);
+
+private:
+    String m_interfaceIdentifier;
+    RefPtr<API::Dictionary> m_encodedInvocation;
+};
+
+}
+
+#endif // RemoteObjectInvocation_h
diff --git a/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm b/Source/WebKit2/Shared/API/Cocoa/RemoteObjectInvocation.mm
new file mode 100644 (file)
index 0000000..2c4a528
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteObjectInvocation.h"
+
+#include "ArgumentCoders.h"
+#include "UserData.h"
+
+namespace WebKit {
+
+RemoteObjectInvocation::RemoteObjectInvocation()
+{
+}
+
+RemoteObjectInvocation::RemoteObjectInvocation(const String& interfaceIdentifier, RefPtr<API::Dictionary>&& encodedInvocation)
+    : m_interfaceIdentifier(interfaceIdentifier)
+    , m_encodedInvocation(WTF::move(encodedInvocation))
+{
+}
+
+void RemoteObjectInvocation::encode(IPC::ArgumentEncoder& encoder) const
+{
+    encoder << m_interfaceIdentifier;
+    UserData::encode(encoder, m_encodedInvocation.get());
+}
+
+bool RemoteObjectInvocation::decode(IPC::ArgumentDecoder& decoder, RemoteObjectInvocation& result)
+{
+    if (!decoder.decode(result.m_interfaceIdentifier))
+        return false;
+
+    RefPtr<API::Object> encodedInvocation;
+    if (!UserData::decode(decoder, encodedInvocation))
+        return false;
+
+    if (!encodedInvocation || encodedInvocation->type() != API::Object::Type::Dictionary)
+        return false;
+
+    result.m_encodedInvocation = static_cast<API::Dictionary*>(encodedInvocation.get());
+
+    return true;
+}
+
+}
index 10c7c65..6528c0c 100644 (file)
@@ -36,21 +36,21 @@ class MessageSender;
 
 namespace WebKit {
 
-class UserData;
+class RemoteObjectInvocation;
 
 class RemoteObjectRegistry final : public IPC::MessageReceiver {
 public:
     RemoteObjectRegistry(_WKRemoteObjectRegistry *, IPC::MessageSender&);
     ~RemoteObjectRegistry();
 
-    void sendInvocation(const UserData&);
+    void sendInvocation(const RemoteObjectInvocation&);
 
 private:
     // IPC::MessageReceiver
     virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
 
     // Message handlers
-    void invokeMethod(const UserData&);
+    void invokeMethod(const RemoteObjectInvocation&);
 
     _WKRemoteObjectRegistry *m_remoteObjectRegistry;
     IPC::MessageSender& m_messageSender;
index c352024..3220e4c 100644 (file)
@@ -21,5 +21,5 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> RemoteObjectRegistry {
-    InvokeMethod(WebKit::UserData invocation)
+    InvokeMethod(WebKit::RemoteObjectInvocation invocation)
 }
index 6f7fdab..a1c3f78 100644 (file)
@@ -27,8 +27,8 @@
 #import "RemoteObjectRegistry.h"
 
 #import "MessageSender.h"
+#import "RemoteObjectInvocation.h"
 #import "RemoteObjectRegistryMessages.h"
-#import "UserData.h"
 #import "_WKRemoteObjectRegistryInternal.h"
 
 namespace WebKit {
@@ -43,12 +43,12 @@ RemoteObjectRegistry::~RemoteObjectRegistry()
 {
 }
 
-void RemoteObjectRegistry::sendInvocation(const UserData& userData)
+void RemoteObjectRegistry::sendInvocation(const RemoteObjectInvocation& invocation)
 {
-    m_messageSender.send(Messages::RemoteObjectRegistry::InvokeMethod(userData));
+    m_messageSender.send(Messages::RemoteObjectRegistry::InvokeMethod(invocation));
 }
 
-void RemoteObjectRegistry::invokeMethod(const UserData& invocation)
+void RemoteObjectRegistry::invokeMethod(const RemoteObjectInvocation& invocation)
 {
 #if WK_API_ENABLED
     [m_remoteObjectRegistry _invokeMethod:invocation];
index 2e14aee..34e8ff0 100644 (file)
@@ -30,8 +30,8 @@
 
 #import "APIDictionary.h"
 #import "Connection.h"
+#import "RemoteObjectInvocation.h"
 #import "RemoteObjectRegistry.h"
-#import "UserData.h"
 #import "WKConnectionRef.h"
 #import "WKRemoteObject.h"
 #import "WKRemoteObjectCoder.h"
@@ -39,9 +39,6 @@
 #import "WebConnection.h"
 #import "_WKRemoteObjectInterface.h"
 
-const char* const encodedInvocationKey = "encodedInvocation";
-const char* const interfaceIdentifierKey = "interfaceIdentifier";
-
 NSString * const invocationKey = @"invocation";
 
 using namespace WebKit;
@@ -99,17 +96,13 @@ using namespace WebKit;
 
 - (void)_sendInvocation:(NSInvocation *)invocation interface:(_WKRemoteObjectInterface *)interface
 {
-    RetainPtr<WKRemoteObjectEncoder> encoder = adoptNS([[WKRemoteObjectEncoder alloc] init]);
+    auto encoder = adoptNS([[WKRemoteObjectEncoder alloc] init]);
     [encoder encodeObject:invocation forKey:invocationKey];
 
-    Ref<API::Dictionary> body = API::Dictionary::create();
-    body->set(interfaceIdentifierKey, API::String::create(interface.identifier));
-    body->set(encodedInvocationKey, [encoder rootObjectDictionary]);
-
     if (!_remoteObjectRegistry)
         return;
 
-    _remoteObjectRegistry->sendInvocation(UserData(body.ptr()));
+    _remoteObjectRegistry->sendInvocation(RemoteObjectInvocation(interface.identifier, [encoder rootObjectDictionary]));
 }
 
 - (WebKit::RemoteObjectRegistry&)remoteObjectRegistry
@@ -117,22 +110,9 @@ using namespace WebKit;
     return *_remoteObjectRegistry;
 }
 
-- (BOOL)_invokeMethod:(const UserData&)invocation
+- (BOOL)_invokeMethod:(const RemoteObjectInvocation&)invocation
 {
-    if (!invocation.object() || invocation.object()->type() != API::Object::Type::Dictionary)
-        return NO;
-    
-    const API::Dictionary& dictionary = static_cast<const API::Dictionary&>(*invocation.object());
-
-    API::String* interfaceIdentifier = dictionary.get<API::String>(interfaceIdentifierKey);
-    if (!interfaceIdentifier)
-        return NO;
-
-    const API::Dictionary* encodedInvocation = dictionary.get<API::Dictionary>(encodedInvocationKey);
-    if (!encodedInvocationKey)
-        return NO;
-
-    [self _invokeMessageWithInterfaceIdentifier:interfaceIdentifier->string() encodedInvocation:encodedInvocation];
+    [self _invokeMessageWithInterfaceIdentifier:invocation.interfaceIdentifier() encodedInvocation:invocation.encodedInvocation()];
 
     return YES;
 }
index 6a89cd8..3921d4a 100644 (file)
@@ -32,8 +32,8 @@ class MessageSender;
 }
 
 namespace WebKit {
+class RemoteObjectInvocation;
 class RemoteObjectRegistry;
-class UserData;
 }
 
 @interface _WKRemoteObjectRegistry ()
@@ -44,7 +44,7 @@ class UserData;
 - (void)_invalidate;
 
 - (void)_sendInvocation:(NSInvocation *)invocation interface:(_WKRemoteObjectInterface *)interface;
-- (BOOL)_invokeMethod:(const WebKit::UserData&)invocation;
+- (BOOL)_invokeMethod:(const WebKit::RemoteObjectInvocation&)invocation;
 
 @end
 
index 70f78dc..0aaa6f6 100644 (file)
                1A5704F21BE0174000874AF1 /* _WKElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5704F01BE0173F00874AF1 /* _WKElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A5704F71BE01FF400874AF1 /* _WKContextMenuElementInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A5704F51BE01FF400874AF1 /* _WKContextMenuElementInfo.mm */; };
                1A5704F81BE01FF400874AF1 /* _WKContextMenuElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5704F61BE01FF400874AF1 /* _WKContextMenuElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1A5704FB1BE1751100874AF1 /* RemoteObjectInvocation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A5704F91BE1751100874AF1 /* RemoteObjectInvocation.mm */; };
+               1A5704FC1BE1751100874AF1 /* RemoteObjectInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5704FA1BE1751100874AF1 /* RemoteObjectInvocation.h */; };
                1A57109E1ABA0027002FABBE /* WKWebsiteDataStoreRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A57109C1ABA0027002FABBE /* WKWebsiteDataStoreRef.cpp */; };
                1A57109F1ABA0027002FABBE /* WKWebsiteDataStoreRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A57109D1ABA0027002FABBE /* WKWebsiteDataStoreRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1A5B1C501898606F004FCF9B /* WKNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A5B1C4E1898606F004FCF9B /* WKNavigation.mm */; };
                1A5704F01BE0173F00874AF1 /* _WKElementInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKElementInfo.h; sourceTree = "<group>"; };
                1A5704F51BE01FF400874AF1 /* _WKContextMenuElementInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKContextMenuElementInfo.mm; sourceTree = "<group>"; };
                1A5704F61BE01FF400874AF1 /* _WKContextMenuElementInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKContextMenuElementInfo.h; sourceTree = "<group>"; };
+               1A5704F91BE1751100874AF1 /* RemoteObjectInvocation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteObjectInvocation.mm; sourceTree = "<group>"; };
+               1A5704FA1BE1751100874AF1 /* RemoteObjectInvocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteObjectInvocation.h; sourceTree = "<group>"; };
                1A57109C1ABA0027002FABBE /* WKWebsiteDataStoreRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKWebsiteDataStoreRef.cpp; sourceTree = "<group>"; };
                1A57109D1ABA0027002FABBE /* WKWebsiteDataStoreRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsiteDataStoreRef.h; sourceTree = "<group>"; };
                1A5B1C4E1898606F004FCF9B /* WKNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNavigation.mm; sourceTree = "<group>"; };
                                1F604BA71889FA7400EE0395 /* _WKRenderingProgressEventsInternal.h */,
                                376311F81A3FB30B005A2E51 /* _WKSameDocumentNavigationType.h */,
                                376311FA1A3FB38B005A2E51 /* _WKSameDocumentNavigationTypeInternal.h */,
+                               1A5704FA1BE1751100874AF1 /* RemoteObjectInvocation.h */,
+                               1A5704F91BE1751100874AF1 /* RemoteObjectInvocation.mm */,
                                1AC1337E18590AE400F3EC05 /* RemoteObjectRegistry.h */,
                                1AC1338118590B0500F3EC05 /* RemoteObjectRegistry.messages.in */,
                                1AC1337D18590AE400F3EC05 /* RemoteObjectRegistry.mm */,
                                BC0E607312D6BC200012A72A /* WebGeolocationPosition.h in Headers */,
                                BC1BE1F212D54DBD0004A228 /* WebGeolocationProvider.h in Headers */,
                                2D5036761BCED19F00E20BB3 /* WebGestureEvent.h in Headers */,
+                               1A5704FC1BE1751100874AF1 /* RemoteObjectInvocation.h in Headers */,
                                93A88B331BC6E9CD00ABA5C2 /* WebHitTestResultData.h in Headers */,
                                511B24AB132E097200065A0C /* WebIconDatabase.h in Headers */,
                                51834593134532E90092B696 /* WebIconDatabaseClient.h in Headers */,
                                1ACECD2417162DB1001FC9EF /* StorageAreaMap.cpp in Sources */,
                                1A334DED16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp in Sources */,
                                1A44B95B16B73F9F00B7BBD8 /* StorageManager.cpp in Sources */,
+                               1A5704FB1BE1751100874AF1 /* RemoteObjectInvocation.mm in Sources */,
                                1AB31A9616BC688100F6DBC9 /* StorageManagerMessageReceiver.cpp in Sources */,
                                1A44B95716B737AA00B7BBD8 /* StorageNamespaceImpl.cpp in Sources */,
                                1AE00D6B18327C1200087DD7 /* StringReference.cpp in Sources */,