Title: [158407] trunk
Revision
158407
Author
[email protected]
Date
2013-10-31 16:56:18 -0700 (Thu, 31 Oct 2013)

Log Message

Add a WKRemoteObject class
https://bugs.webkit.org/show_bug.cgi?id=123586

Reviewed by Dan Bernstein.

Source/WebKit2:

* Shared/API/Cocoa/WKRemoteObject.h: Added.
* Shared/API/Cocoa/WKRemoteObject.mm: Added.
(-[WKRemoteObject _initWithObjectRegistry:interface:]):
Add designated initializer.

(-[WKRemoteObject conformsToProtocol:]):
Check if the interface protocol conforms to our protocol.

(methodArgumentTypeEncodingForSelector):
Helper function that looks up a method in a given protocol and returns its type encoding.

(-[WKRemoteObject methodSignatureForSelector:]):
Try to find the method argument type encoding for the given selector and return its NSMethodSignature.

(-[WKRemoteObject forwardInvocation:]):
Add stub.

* Shared/API/Cocoa/WKRemoteObjectInterface.mm:
Remove a newline.

* Shared/API/Cocoa/WKRemoteObjectRegistry.mm:
(-[WKRemoteObjectRegistry remoteObjectProxyWithInterface:]):
Establish a mapping between interface identifiers and remote object proxies.

* WebKit2.xcodeproj/project.pbxproj:

Tools:

* TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm:
(TestWebKitAPI::TEST):
Add a conformsToProtocol: test.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (158406 => 158407)


--- trunk/Source/WebKit2/ChangeLog	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Source/WebKit2/ChangeLog	2013-10-31 23:56:18 UTC (rev 158407)
@@ -1,3 +1,36 @@
+2013-10-31  Anders Carlsson  <[email protected]>
+
+        Add a WKRemoteObject class
+        https://bugs.webkit.org/show_bug.cgi?id=123586
+
+        Reviewed by Dan Bernstein.
+
+        * Shared/API/Cocoa/WKRemoteObject.h: Added.
+        * Shared/API/Cocoa/WKRemoteObject.mm: Added.
+        (-[WKRemoteObject _initWithObjectRegistry:interface:]):
+        Add designated initializer.
+
+        (-[WKRemoteObject conformsToProtocol:]):
+        Check if the interface protocol conforms to our protocol.
+
+        (methodArgumentTypeEncodingForSelector):
+        Helper function that looks up a method in a given protocol and returns its type encoding.
+
+        (-[WKRemoteObject methodSignatureForSelector:]):
+        Try to find the method argument type encoding for the given selector and return its NSMethodSignature.
+
+        (-[WKRemoteObject forwardInvocation:]):
+        Add stub.
+
+        * Shared/API/Cocoa/WKRemoteObjectInterface.mm:
+        Remove a newline.
+
+        * Shared/API/Cocoa/WKRemoteObjectRegistry.mm:
+        (-[WKRemoteObjectRegistry remoteObjectProxyWithInterface:]):
+        Establish a mapping between interface identifiers and remote object proxies.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2013-10-31  Alexey Proskuryakov  <[email protected]>
 
         Enable WebCrypto on Mac

Copied: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.h (from rev 158405, trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm) (0 => 158407)


--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.h	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.h	2013-10-31 23:56:18 UTC (rev 158407)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import <WebKit2/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+@class WKRemoteObjectInterface;
+@class WKRemoteObjectRegistry;
+
+@interface WKRemoteObject : NSObject
+
+- (instancetype)_initWithObjectRegistry:(WKRemoteObjectRegistry *)objectRegistry interface:(WKRemoteObjectInterface *)interface;
+
+@end
+
+#endif // WK_API_ENABLED

Added: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.mm (0 => 158407)


--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.mm	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObject.mm	2013-10-31 23:56:18 UTC (rev 158407)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#import "config.h"
+#import "WKRemoteObject.h"
+
+#import "WKRemoteObjectInterface.h"
+#import <objc/runtime.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+@implementation WKRemoteObject {
+    RetainPtr<WKRemoteObjectRegistry> _objectRegistry;
+    RetainPtr<WKRemoteObjectInterface> _interface;
+}
+
+- (instancetype)_initWithObjectRegistry:(WKRemoteObjectRegistry *)objectRegistry interface:(WKRemoteObjectInterface *)interface
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _objectRegistry = objectRegistry;
+    _interface = interface;
+
+    return self;
+}
+
+- (BOOL)conformsToProtocol:(Protocol *)protocol
+{
+    if ([super conformsToProtocol:protocol])
+        return true;
+
+    return protocol_conformsToProtocol([_interface protocol], protocol);
+}
+
+static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL selector)
+{
+    // First look at required methods.
+    struct objc_method_description method = protocol_getMethodDescription(protocol, selector, YES, YES);
+    if (method.name)
+        return method.types;
+
+    // Then look at optional methods.
+    method = protocol_getMethodDescription(protocol, selector, NO, YES);
+    if (method.name)
+        return method.types;
+
+    return nullptr;
+}
+
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
+{
+    if (!selector)
+        return nil;
+
+    Protocol *protocol = [_interface protocol];
+
+    const char* types = methodArgumentTypeEncodingForSelector(protocol, selector);
+    if (!types) {
+        // We didn't find anything the protocol, fall back to the superclass.
+        return [super methodSignatureForSelector:selector];
+    }
+
+    return [NSMethodSignature signatureWithObjCTypes:types];
+}
+
+- (void)forwardInvocation:(NSInvocation *)invocation
+{
+    // FIXME: Implement.
+}
+
+@end
+
+#endif // WK_API_ENABLED
+

Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm (158406 => 158407)


--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm	2013-10-31 23:56:18 UTC (rev 158407)
@@ -41,7 +41,6 @@
     return self;
 }
 
-
 + (instancetype)remoteObjectInterfaceWithProtocol:(Protocol *)protocol
 {
     return [[[self alloc] initWithProtocol:protocol identifier:NSStringFromProtocol(protocol)] autorelease];

Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectRegistry.mm (158406 => 158407)


--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectRegistry.mm	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectRegistry.mm	2013-10-31 23:56:18 UTC (rev 158407)
@@ -29,8 +29,10 @@
 
 #import "Connection.h"
 #import "WKConnectionRef.h"
+#import "WKRemoteObjectInterface.h"
+#import "WKRemoteObject.h"
+#import "WKSharedAPICast.h"
 #import "WebConnection.h"
-#import "WKSharedAPICast.h"
 
 #if WK_API_ENABLED
 
@@ -38,6 +40,7 @@
 
 @implementation WKRemoteObjectRegistry {
     RefPtr<WebConnection> _connection;
+    RetainPtr<NSMapTable> _remoteObjectProxies;
 }
 
 - (void)registerExportedObject:(id)object interface:(WKRemoteObjectInterface *)interface
@@ -52,8 +55,17 @@
 
 - (id)remoteObjectProxyWithInterface:(WKRemoteObjectInterface *)interface
 {
-    // FIXME: Implement.
-    return nil;
+    if (!_remoteObjectProxies)
+        _remoteObjectProxies = [NSMapTable strongToWeakObjectsMapTable];
+
+    if (id remoteObjectProxy = [_remoteObjectProxies objectForKey:interface.identifier])
+        return remoteObjectProxy;
+
+    RetainPtr<NSString> identifier = adoptNS([interface.identifier copy]);
+    RetainPtr<WKRemoteObject> remoteObject = adoptNS([[WKRemoteObject alloc] _initWithObjectRegistry:self interface:interface]);
+    [_remoteObjectProxies setObject:remoteObject.get() forKey:identifier.get()];
+
+    return [remoteObject.leakRef() autorelease];
 }
 
 @end

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (158406 => 158407)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-10-31 23:56:18 UTC (rev 158407)
@@ -205,6 +205,8 @@
 		1A9E328D182165A900F5D04C /* WKRemoteObjectInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9E328B182165A900F5D04C /* WKRemoteObjectInterface.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A9E328E182165A900F5D04C /* WKRemoteObjectInterface.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A9E328C182165A900F5D04C /* WKRemoteObjectInterface.mm */; };
 		1A9E329718219BEA00F5D04C /* WKRemoteObjectRegistryPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9E329618219BEA00F5D04C /* WKRemoteObjectRegistryPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		1A9E329A1822E1CC00F5D04C /* WKRemoteObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A9E32981822E1CC00F5D04C /* WKRemoteObject.mm */; };
+		1A9E329B1822E1CC00F5D04C /* WKRemoteObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9E32991822E1CC00F5D04C /* WKRemoteObject.h */; };
 		1A9FBA8D13FF04E600DEED67 /* PluginComplexTextInputState.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9FBA8C13FF04E600DEED67 /* PluginComplexTextInputState.h */; };
 		1AA2E51D12E4C05E00BC4966 /* CGUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA2E51B12E4C05E00BC4966 /* CGUtilities.h */; };
 		1AA2E51E12E4C05E00BC4966 /* CGUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA2E51C12E4C05E00BC4966 /* CGUtilities.cpp */; };
@@ -1660,6 +1662,8 @@
 		1A9E328B182165A900F5D04C /* WKRemoteObjectInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKRemoteObjectInterface.h; sourceTree = "<group>"; };
 		1A9E328C182165A900F5D04C /* WKRemoteObjectInterface.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRemoteObjectInterface.mm; sourceTree = "<group>"; };
 		1A9E329618219BEA00F5D04C /* WKRemoteObjectRegistryPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKRemoteObjectRegistryPrivate.h; sourceTree = "<group>"; };
+		1A9E32981822E1CC00F5D04C /* WKRemoteObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRemoteObject.mm; sourceTree = "<group>"; };
+		1A9E32991822E1CC00F5D04C /* WKRemoteObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKRemoteObject.h; sourceTree = "<group>"; };
 		1A9FBA8C13FF04E600DEED67 /* PluginComplexTextInputState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginComplexTextInputState.h; sourceTree = "<group>"; };
 		1AA1C79A100E7FC50078DEBC /* WebCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		1AA1C7DE100E846E0078DEBC /* _javascript_Core.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = _javascript_Core.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -3691,6 +3695,8 @@
 			isa = PBXGroup;
 			children = (
 				37DFA6FF1810BB92001F4A9F /* WKFoundation.h */,
+				1A9E32991822E1CC00F5D04C /* WKRemoteObject.h */,
+				1A9E32981822E1CC00F5D04C /* WKRemoteObject.mm */,
 				1A9E328B182165A900F5D04C /* WKRemoteObjectInterface.h */,
 				1A9E328C182165A900F5D04C /* WKRemoteObjectInterface.mm */,
 				1A9E32871821636900F5D04C /* WKRemoteObjectRegistry.h */,
@@ -5575,6 +5581,7 @@
 				1A8EF4CB1252403700F7067F /* PluginControllerProxy.h in Headers */,
 				1A8EF96F1252AF6B00F7067F /* PluginControllerProxyMessages.h in Headers */,
 				1A179780137EE82C00F97D45 /* PluginCreationParameters.h in Headers */,
+				1A9E329B1822E1CC00F5D04C /* WKRemoteObject.h in Headers */,
 				7C3F8C91173AF52D007B7F39 /* PluginInformation.h in Headers */,
 				1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */,
 				1A3D610213A7CC2A00F95D4E /* PluginModuleInfo.h in Headers */,
@@ -6984,6 +6991,7 @@
 				51ACBBA1127A8F2C00D203B9 /* WebContextMenuProxyMac.mm in Sources */,
 				BCEE7D0D12846F69009827DA /* WebContextMessageReceiver.cpp in Sources */,
 				3309344F1315B94D0097A7BC /* WebCookieManager.cpp in Sources */,
+				1A9E329A1822E1CC00F5D04C /* WKRemoteObject.mm in Sources */,
 				51E35210180F63FB00E53BE9 /* DatabaseProcessIDBDatabaseBackendMessageReceiver.cpp in Sources */,
 				F6A90813133C20510082C3F4 /* WebCookieManagerMac.mm in Sources */,
 				330934471315B9220097A7BC /* WebCookieManagerMessageReceiver.cpp in Sources */,

Modified: trunk/Tools/ChangeLog (158406 => 158407)


--- trunk/Tools/ChangeLog	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Tools/ChangeLog	2013-10-31 23:56:18 UTC (rev 158407)
@@ -1,3 +1,14 @@
+2013-10-31  Anders Carlsson  <[email protected]>
+
+        Add a WKRemoteObject class
+        https://bugs.webkit.org/show_bug.cgi?id=123586
+
+        Reviewed by Dan Bernstein.
+
+        * TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm:
+        (TestWebKitAPI::TEST):
+        Add a conformsToProtocol: test.
+
 2013-10-30  Ryosuke Niwa  <[email protected]>
 
         build.webkit.org should have a clean build button

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm (158406 => 158407)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm	2013-10-31 23:30:08 UTC (rev 158406)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/WKRemoteObjectRegistry.mm	2013-10-31 23:56:18 UTC (rev 158407)
@@ -96,6 +96,8 @@
     WKRemoteObjectInterface *bundleInterface = [WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleInterface)];
 
     id <BundleInterface> remoteObjectProxy = [remoteObjectRegistry remoteObjectProxyWithInterface:bundleInterface];
+    EXPECT_TRUE([remoteObjectProxy conformsToProtocol:@protocol(BundleInterface)]);
+
     [remoteObjectProxy sayHello];
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to