Title: [192319] trunk
Revision
192319
Author
ander...@apple.com
Date
2015-11-11 11:50:25 -0800 (Wed, 11 Nov 2015)

Log Message

_WKRemoteObjectInterface should handle specifying allowed classes for reply block arguments
https://bugs.webkit.org/show_bug.cgi?id=151144

Reviewed by Tim Horton.

Source/WebKit2:

* Shared/API/Cocoa/_WKRemoteObjectInterface.h:
* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(classesForSelectorArgument):
(-[_WKRemoteObjectInterface classesForSelector:argumentIndex:ofReply:]):
(-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:ofReply:]):
(-[_WKRemoteObjectInterface classesForSelector:argumentIndex:]):
(-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:]):

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.h:
(remoteObjectInterface):
* TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm:
(TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm:
(-[RemoteObjectRegistryPlugIn webProcessPlugIn:didCreateBrowserContextController:]):
(-[RemoteObjectRegistryPlugIn selectionAndClickInformationForClickAtPoint:completionHandler:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (192318 => 192319)


--- trunk/Source/WebKit2/ChangeLog	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Source/WebKit2/ChangeLog	2015-11-11 19:50:25 UTC (rev 192319)
@@ -1,3 +1,18 @@
+2015-11-11  Anders Carlsson  <ander...@apple.com>
+
+        _WKRemoteObjectInterface should handle specifying allowed classes for reply block arguments
+        https://bugs.webkit.org/show_bug.cgi?id=151144
+
+        Reviewed by Tim Horton.
+
+        * Shared/API/Cocoa/_WKRemoteObjectInterface.h:
+        * Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
+        (classesForSelectorArgument):
+        (-[_WKRemoteObjectInterface classesForSelector:argumentIndex:ofReply:]):
+        (-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:ofReply:]):
+        (-[_WKRemoteObjectInterface classesForSelector:argumentIndex:]):
+        (-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:]):
+
 2015-11-11  Tim Horton  <timothy_hor...@apple.com>
 
         Add some font-related preferences to the modern API

Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.h (192318 => 192319)


--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.h	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.h	2015-11-11 19:50:25 UTC (rev 192319)
@@ -39,6 +39,10 @@
 @property (readonly, nonatomic) Protocol *protocol;
 @property (readonly, nonatomic) NSString *identifier;
 
+- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply;
+- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply;
+
+// FIXME: Deprecate these.
 - (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex;
 - (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex;
 

Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm (192318 => 192319)


--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm	2015-11-11 19:50:25 UTC (rev 192319)
@@ -260,40 +260,58 @@
     return result.autorelease();
 }
 
-static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex)
+static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex, bool replyBlock)
 {
     auto it = interface->_methods.find(selector);
     if (it == interface->_methods.end())
         [NSException raise:NSInvalidArgumentException format:@"Interface does not contain selector \"%s\"", sel_getName(selector)];
 
     MethodInfo& methodInfo = it->value;
-    auto& allowedArgumentClasses = methodInfo.allowedArgumentClasses;
+    if (replyBlock) {
+        if (!methodInfo.replyInfo)
+            [NSException raise:NSInvalidArgumentException format:@"Selector \"%s\" does not have a reply block", sel_getName(selector)];
 
-    if (argumentIndex >= allowedArgumentClasses.size())
+        if (argumentIndex >= methodInfo.replyInfo->allowedReplyClasses.size())
+            [NSException raise:NSInvalidArgumentException format:@"Argument index %ld is out of range for reply block of selector \"%s\"", (unsigned long)argumentIndex, sel_getName(selector)];
+
+        return methodInfo.replyInfo->allowedReplyClasses[argumentIndex];
+    }
+
+    if (argumentIndex >= methodInfo.allowedArgumentClasses.size())
         [NSException raise:NSInvalidArgumentException format:@"Argument index %ld is out of range for selector \"%s\"", (unsigned long)argumentIndex, sel_getName(selector)];
 
-    return allowedArgumentClasses[argumentIndex];
+    return methodInfo.allowedArgumentClasses[argumentIndex];
 }
 
-- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply
 {
     auto result = adoptNS([[NSMutableSet alloc] init]);
 
-    for (auto allowedClass : classesForSelectorArgument(self, selector, argumentIndex))
+    for (auto allowedClass : classesForSelectorArgument(self, selector, argumentIndex, ofReply))
         [result addObject:allowedClass];
 
     return result.autorelease();
 }
 
-- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply
 {
     HashSet<Class> allowedClasses;
     for (Class allowedClass in classes)
         allowedClasses.add(allowedClass);
 
-    classesForSelectorArgument(self, selector, argumentIndex) = WTF::move(allowedClasses);
+    classesForSelectorArgument(self, selector, argumentIndex, ofReply) = WTF::move(allowedClasses);
 }
 
+- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+{
+    return [self classesForSelector:selector argumentIndex:argumentIndex ofReply:NO];
+}
+
+- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+{
+    [self setClasses:classes forSelector:selector argumentIndex:argumentIndex ofReply:NO];
+}
+
 static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL selector)
 {
     // First look at required methods.

Modified: trunk/Tools/ChangeLog (192318 => 192319)


--- trunk/Tools/ChangeLog	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Tools/ChangeLog	2015-11-11 19:50:25 UTC (rev 192319)
@@ -1,3 +1,18 @@
+2015-11-11  Anders Carlsson  <ander...@apple.com>
+
+        _WKRemoteObjectInterface should handle specifying allowed classes for reply block arguments
+        https://bugs.webkit.org/show_bug.cgi?id=151144
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.h:
+        (remoteObjectInterface):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm:
+        (-[RemoteObjectRegistryPlugIn webProcessPlugIn:didCreateBrowserContextController:]):
+        (-[RemoteObjectRegistryPlugIn selectionAndClickInformationForClickAtPoint:completionHandler:]):
+
 2015-11-10  Wenson Hsieh  <wenson_hs...@apple.com>
 
         UI-side scripts in WebKitTestRunner should wait until event handling completes before finishing

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.h (192318 => 192319)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.h	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.h	2015-11-11 19:50:25 UTC (rev 192319)
@@ -27,11 +27,22 @@
 
 #if WK_API_ENABLED
 
+#import <WebKit/_WKRemoteObjectInterface.h>
+
 @protocol RemoteObjectProtocol <NSObject>
 
 - (void)sayHello:(NSString *)hello;
 - (void)sayHello:(NSString *)hello completionHandler:(void (^)(NSString *))completionHandler;
+- (void)selectionAndClickInformationForClickAtPoint:(NSValue *)pointValue completionHandler:(void (^)(NSDictionary *))completionHandler;
 
 @end
 
+static inline _WKRemoteObjectInterface *remoteObjectInterface()
+{
+    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(RemoteObjectProtocol)];
+
+    [interface setClasses:[NSSet setWithObjects:[NSDictionary class], [NSURL class], nil] forSelector:@selector(selectionAndClickInformationForClickAtPoint:completionHandler:) argumentIndex:0 ofReply:YES];
+
+    return interface;
+}
 #endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm (192318 => 192319)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistry.mm	2015-11-11 19:50:25 UTC (rev 192319)
@@ -48,7 +48,7 @@
 
         isDone = false;
 
-        _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(RemoteObjectProtocol)];
+        _WKRemoteObjectInterface *interface = remoteObjectInterface();
         id <RemoteObjectProtocol> object = [[webView _remoteObjectRegistry] remoteObjectProxyWithInterface:interface];
 
         [object sayHello:@"Hello, World!"];
@@ -67,6 +67,10 @@
             isDone = true;
         }];
 
+        isDone = false;
+        [object selectionAndClickInformationForClickAtPoint:[NSValue valueWithPoint:NSMakePoint(12, 34)] completionHandler:^(NSDictionary *result) {
+            isDone = true;
+        }];
         TestWebKitAPI::Util::run(&isDone);
     }
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm (192318 => 192319)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm	2015-11-11 19:25:56 UTC (rev 192318)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RemoteObjectRegistryPlugIn.mm	2015-11-11 19:50:25 UTC (rev 192319)
@@ -52,7 +52,7 @@
     _browserContextController = browserContextController;
     _plugInController = plugInController;
 
-    _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(RemoteObjectProtocol)];
+    _WKRemoteObjectInterface *interface = remoteObjectInterface();
     [[_browserContextController _remoteObjectRegistry] registerExportedObject:self interface:interface];
 }
 
@@ -67,6 +67,15 @@
     completionHandler([NSString stringWithFormat:@"Your string was '%@'", hello]);
 }
 
+- (void)selectionAndClickInformationForClickAtPoint:(NSValue *)pointValue completionHandler:(void (^)(NSDictionary *))completionHandler
+{
+    NSDictionary *result = @{
+        @"URL" : [NSURL URLWithString:@"http://www.webkit.org/"],
+    };
+
+    completionHandler(result);
+}
+
 @end
 
 #endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to