Title: [158763] trunk/Source/WebKit2
- Revision
- 158763
- Author
- [email protected]
- Date
- 2013-11-06 11:23:20 -0800 (Wed, 06 Nov 2013)
Log Message
WKRemoteObjectInterface should keep track of allowed decodable classes
https://bugs.webkit.org/show_bug.cgi?id=123903
Reviewed by Sam Weinig.
* Shared/API/Cocoa/WKRemoteObjectInterface.mm:
(allowedArgumentClassesForMethod):
Helper function that returns a vector of sets of allowed classes for each method argument.
(initializeAllowedArgumentClasses):
Iterate over the methods in the protocol, get the extended method type encoding and create an
NSMethodSignature from it. Finally, pass the signature to allowedArgumentClassesForMethod.
(initializeAllowedArgumentClasses):
Call the other initializeAllowedArgumentClasses twice, once for required methods,
and once for optional methods.
(-[WKRemoteObjectInterface initWithProtocol:identifier:]):
Call initializeAllowedArgumentClasses.
(-[WKRemoteObjectInterface _allowedArgumentClassesForSelector:]):
Add new getter.
* Shared/API/Cocoa/WKRemoteObjectInterfaceInternal.h:
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (158762 => 158763)
--- trunk/Source/WebKit2/ChangeLog 2013-11-06 19:21:47 UTC (rev 158762)
+++ trunk/Source/WebKit2/ChangeLog 2013-11-06 19:23:20 UTC (rev 158763)
@@ -1,5 +1,32 @@
2013-11-06 Anders Carlsson <[email protected]>
+ WKRemoteObjectInterface should keep track of allowed decodable classes
+ https://bugs.webkit.org/show_bug.cgi?id=123903
+
+ Reviewed by Sam Weinig.
+
+ * Shared/API/Cocoa/WKRemoteObjectInterface.mm:
+ (allowedArgumentClassesForMethod):
+ Helper function that returns a vector of sets of allowed classes for each method argument.
+
+ (initializeAllowedArgumentClasses):
+ Iterate over the methods in the protocol, get the extended method type encoding and create an
+ NSMethodSignature from it. Finally, pass the signature to allowedArgumentClassesForMethod.
+
+ (initializeAllowedArgumentClasses):
+ Call the other initializeAllowedArgumentClasses twice, once for required methods,
+ and once for optional methods.
+
+ (-[WKRemoteObjectInterface initWithProtocol:identifier:]):
+ Call initializeAllowedArgumentClasses.
+
+ (-[WKRemoteObjectInterface _allowedArgumentClassesForSelector:]):
+ Add new getter.
+
+ * Shared/API/Cocoa/WKRemoteObjectInterfaceInternal.h:
+
+2013-11-06 Anders Carlsson <[email protected]>
+
Remove dead code
https://bugs.webkit.org/show_bug.cgi?id=123902
Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm (158762 => 158763)
--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm 2013-11-06 19:21:47 UTC (rev 158762)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterface.mm 2013-11-06 19:23:20 UTC (rev 158763)
@@ -27,11 +27,80 @@
#import "WKRemoteObjectInterface.h"
#import <objc/runtime.h>
+#import <wtf/HashMap.h>
+#import <wtf/Vector.h>
+#import <wtf/RetainPtr.h>
#if WK_API_ENABLED
-@implementation WKRemoteObjectInterface
+extern "C"
+const char *_protocol_getMethodTypeEncoding(Protocol *p, SEL sel, BOOL isRequiredMethod, BOOL isInstanceMethod);
+@interface NSMethodSignature (Details)
+- (Class)_classForObjectAtArgumentIndex:(NSInteger)idx;
+@end
+
+@implementation WKRemoteObjectInterface {
+ HashMap<SEL, Vector<RetainPtr<NSSet>>> _allowedArgumentClasses;
+}
+
+static Vector<RetainPtr<NSSet>> allowedArgumentClassesForMethod(NSMethodSignature *methodSignature)
+{
+ Vector<RetainPtr<NSSet>> result;
+
+ NSSet *emptySet = [NSSet set];
+
+ // We ignore self and _cmd.
+ NSUInteger argumentCount = methodSignature.numberOfArguments - 2;
+
+ result.reserveInitialCapacity(argumentCount);
+
+ for (NSUInteger i = 0; i < argumentCount; ++i) {
+ const char* type = [methodSignature getArgumentTypeAtIndex:i + 2];
+
+ if (*type != '@') {
+ // This is a non-object type; we won't allow any classes to be decoded for it.
+ result.uncheckedAppend(emptySet);
+ continue;
+ }
+
+ Class objectClass = [methodSignature _classForObjectAtArgumentIndex:i + 2];
+ if (!objectClass) {
+ result.uncheckedAppend(emptySet);
+ continue;
+ }
+
+ result.uncheckedAppend([NSSet setWithObject:objectClass]);
+ }
+
+ return result;
+}
+
+static void initializeAllowedArgumentClasses(WKRemoteObjectInterface *interface, bool requiredMethods)
+{
+ unsigned methodCount;
+ struct objc_method_description *methods = protocol_copyMethodDescriptionList(interface->_protocol, requiredMethods, true, &methodCount);
+
+ for (unsigned i = 0; i < methodCount; ++i) {
+ SEL selector = methods[i].name;
+
+ const char* types = _protocol_getMethodTypeEncoding(interface->_protocol, selector, requiredMethods, true);
+ if (!types)
+ [NSException raise:NSInvalidArgumentException format:@"Could not find method type encoding for method \"%s\"", sel_getName(selector)];
+
+ NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:types];
+ interface->_allowedArgumentClasses.set(selector, allowedArgumentClassesForMethod(methodSignature));
+ }
+
+ free(methods);
+}
+
+static void initializeAllowedArgumentClasses(WKRemoteObjectInterface *interface)
+{
+ initializeAllowedArgumentClasses(interface, true);
+ initializeAllowedArgumentClasses(interface, false);
+}
+
- (id)initWithProtocol:(Protocol *)protocol identifier:(NSString *)identifier
{
if (!(self = [super init]))
@@ -40,6 +109,8 @@
_protocol = protocol;
_identifier = [identifier copy];
+ initializeAllowedArgumentClasses(self);
+
return self;
}
@@ -72,6 +143,14 @@
return [NSMethodSignature signatureWithObjCTypes:types];
}
+- (const Vector<RetainPtr<NSSet>>&)_allowedArgumentClassesForSelector:(SEL)selector
+{
+ auto it = _allowedArgumentClasses.find(selector);
+ ASSERT(it != _allowedArgumentClasses.end());
+
+ return it->value;
+}
+
@end
#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterfaceInternal.h (158762 => 158763)
--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterfaceInternal.h 2013-11-06 19:21:47 UTC (rev 158762)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectInterfaceInternal.h 2013-11-06 19:23:20 UTC (rev 158763)
@@ -27,9 +27,13 @@
#if WK_API_ENABLED
+#import <wtf/Forward.h>
+#import <wtf/RetainPtr.h>
+
@interface WKRemoteObjectInterface ()
- (NSMethodSignature *)_methodSignatureForSelector:(SEL)selector;
+- (const Vector<RetainPtr<NSSet>>&)_allowedArgumentClassesForSelector:(SEL)selector;
@end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes