<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[192162] trunk/Source/WebKit2</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/192162">192162</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-11-09 10:35:19 -0800 (Mon, 09 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Rework the way allowed argument classes are stored
https://bugs.webkit.org/show_bug.cgi?id=150992
Reviewed by Darin Adler.
Add a separate MethodInfo class so we have someplace to store the reply block arguments.
Use HashSet<Class> instead of NSSet. No functionality change intended.
* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(-[WKRemoteObjectDecoder decodeValueOfObjCType:at:]):
(decodeObjectFromObjectStream):
(checkIfClassIsAllowed):
(decodeInvocationArguments):
(decodeObject):
(-[WKRemoteObjectDecoder decodeObjectOfClasses:forKey:]):
(-[WKRemoteObjectDecoder allowedClasses]):
* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(isContainerClass):
(propertyListClasses):
(initializeMethod):
(initializeMethods):
(-[_WKRemoteObjectInterface initWithProtocol:identifier:]):
(classesForSelectorArgument):
(-[_WKRemoteObjectInterface classesForSelector:argumentIndex:]):
(-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:]):
(-[_WKRemoteObjectInterface _allowedArgumentClassesForSelector:]):
(allowedArgumentClassesForMethod): Deleted.
(initializeAllowedArgumentClasses): Deleted.
* Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCodermm">trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfacemm">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfaceInternalh">trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (192161 => 192162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-11-09 18:10:29 UTC (rev 192161)
+++ trunk/Source/WebKit2/ChangeLog        2015-11-09 18:35:19 UTC (rev 192162)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-11-06 Anders Carlsson <andersca@apple.com>
+
+ Rework the way allowed argument classes are stored
+ https://bugs.webkit.org/show_bug.cgi?id=150992
+
+ Reviewed by Darin Adler.
+
+ Add a separate MethodInfo class so we have someplace to store the reply block arguments.
+ Use HashSet<Class> instead of NSSet. No functionality change intended.
+
+ * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+ (-[WKRemoteObjectDecoder decodeValueOfObjCType:at:]):
+ (decodeObjectFromObjectStream):
+ (checkIfClassIsAllowed):
+ (decodeInvocationArguments):
+ (decodeObject):
+ (-[WKRemoteObjectDecoder decodeObjectOfClasses:forKey:]):
+ (-[WKRemoteObjectDecoder allowedClasses]):
+ * Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
+ (isContainerClass):
+ (propertyListClasses):
+ (initializeMethod):
+ (initializeMethods):
+ (-[_WKRemoteObjectInterface initWithProtocol:identifier:]):
+ (classesForSelectorArgument):
+ (-[_WKRemoteObjectInterface classesForSelector:argumentIndex:]):
+ (-[_WKRemoteObjectInterface setClasses:forSelector:argumentIndex:]):
+ (-[_WKRemoteObjectInterface _allowedArgumentClassesForSelector:]):
+ (allowedArgumentClassesForMethod): Deleted.
+ (initializeAllowedArgumentClasses): Deleted.
+ * Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h:
+
</ins><span class="cx"> 2015-11-09 Csaba Osztrogonác <ossy@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed CMake buildfix after r192113.
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoaWKRemoteObjectCodermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm (192161 => 192162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm        2015-11-09 18:10:29 UTC (rev 192161)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm        2015-11-09 18:35:19 UTC (rev 192162)
</span><span class="lines">@@ -358,7 +358,7 @@
</span><span class="cx"> const API::Array* _objectStream;
</span><span class="cx"> size_t _objectStreamPosition;
</span><span class="cx">
</span><del>- NSSet *_allowedClasses;
</del><ins>+ const HashSet<Class>* _allowedClasses;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary
</span><span class="lines">@@ -381,7 +381,7 @@
</span><span class="cx"> switch (*type) {
</span><span class="cx"> // int
</span><span class="cx"> case 'i':
</span><del>- *static_cast<int*>(data) = [decodeObjectFromObjectStream(self, [NSSet setWithObject:[NSNumber class]]) intValue];
</del><ins>+ *static_cast<int*>(data) = [decodeObjectFromObjectStream(self, { [NSNumber class] }) intValue];
</ins><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> default:
</span><span class="lines">@@ -404,9 +404,9 @@
</span><span class="cx"> return [self decodeObjectOfClasses:nil forKey:key];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static id decodeObject(WKRemoteObjectDecoder *, const API::Dictionary*, NSSet *allowedClasses);
</del><ins>+static id decodeObject(WKRemoteObjectDecoder *, const API::Dictionary*, const HashSet<Class>& allowedClasses);
</ins><span class="cx">
</span><del>-static id decodeObjectFromObjectStream(WKRemoteObjectDecoder *decoder, NSSet *allowedClasses)
</del><ins>+static id decodeObjectFromObjectStream(WKRemoteObjectDecoder *decoder, const HashSet<Class>& allowedClasses)
</ins><span class="cx"> {
</span><span class="cx"> if (!decoder->_objectStream)
</span><span class="cx"> return nil;
</span><span class="lines">@@ -421,15 +421,19 @@
</span><span class="cx">
</span><span class="cx"> static void checkIfClassIsAllowed(WKRemoteObjectDecoder *decoder, Class objectClass)
</span><span class="cx"> {
</span><del>- NSSet *allowedClasses = decoder->_allowedClasses;
</del><ins>+ auto* allowedClasses = decoder->_allowedClasses;
+ if (!allowedClasses)
+ return;
</ins><span class="cx">
</span><del>- // Check if the class or any of its superclasses are in the allowed classes set.
- for (Class cls = objectClass; cls; cls = class_getSuperclass(cls)) {
- if ([allowedClasses containsObject:cls])
</del><ins>+ if (allowedClasses->contains(objectClass))
+ return;
+
+ for (Class superclass = class_getSuperclass(objectClass); superclass; superclass = class_getSuperclass(superclass)) {
+ if (allowedClasses->contains(superclass))
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- [NSException raise:NSInvalidUnarchiveOperationException format:@"Object of class \"%@\" is not allowed. Allowed classes are \"%@\"", objectClass, allowedClasses];
</del><ins>+ [NSException raise:NSInvalidUnarchiveOperationException format:@"Object of class \"%@\" is not allowed. Allowed classes are \"%@\"", objectClass, decoder.allowedClasses];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static void validateClass(WKRemoteObjectDecoder *decoder, Class objectClass)
</span><span class="lines">@@ -445,7 +449,7 @@
</span><span class="cx"> [decoder validateClassSupportsSecureCoding:objectClass];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocation *invocation, const Vector<RetainPtr<NSSet>>& allowedArgumentClasses)
</del><ins>+static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocation *invocation, const Vector<HashSet<Class>>& allowedArgumentClasses)
</ins><span class="cx"> {
</span><span class="cx"> NSMethodSignature *methodSignature = invocation.methodSignature;
</span><span class="cx"> NSUInteger argumentCount = methodSignature.numberOfArguments;
</span><span class="lines">@@ -460,63 +464,63 @@
</span><span class="cx"> switch (*type) {
</span><span class="cx"> // double
</span><span class="cx"> case 'd': {
</span><del>- double value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) doubleValue];
</del><ins>+ double value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) doubleValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // float
</span><span class="cx"> case 'f': {
</span><del>- float value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) floatValue];
</del><ins>+ float value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) floatValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // int
</span><span class="cx"> case 'i': {
</span><del>- int value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) intValue];
</del><ins>+ int value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) intValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // unsigned
</span><span class="cx"> case 'I': {
</span><del>- unsigned value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) unsignedIntValue];
</del><ins>+ unsigned value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) unsignedIntValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // char
</span><span class="cx"> case 'c': {
</span><del>- char value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) charValue];
</del><ins>+ char value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) charValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // bool
</span><span class="cx"> case 'B': {
</span><del>- bool value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) boolValue];
</del><ins>+ bool value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) boolValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // long
</span><span class="cx"> case 'q': {
</span><del>- long value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) longValue];
</del><ins>+ long value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) longValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // unsigned long
</span><span class="cx"> case 'Q': {
</span><del>- unsigned long value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) unsignedLongValue];
</del><ins>+ unsigned long value = [decodeObjectFromObjectStream(decoder, { [NSNumber class] }) unsignedLongValue];
</ins><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Objective-C object
</span><span class="cx"> case '@': {
</span><del>- NSSet *allowedClasses = allowedArgumentClasses[i - 2].get();
</del><ins>+ auto& allowedClasses = allowedArgumentClasses[i - 2];
</ins><span class="cx">
</span><span class="cx"> id value = decodeObjectFromObjectStream(decoder, allowedClasses);
</span><span class="cx"> [invocation setArgument:&value atIndex:i];
</span><span class="lines">@@ -608,7 +612,7 @@
</span><span class="cx"> return [result autorelease];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static id decodeObject(WKRemoteObjectDecoder *decoder, const API::Dictionary* dictionary, NSSet *allowedClasses)
</del><ins>+static id decodeObject(WKRemoteObjectDecoder *decoder, const API::Dictionary* dictionary, const HashSet<Class>& allowedClasses)
</ins><span class="cx"> {
</span><span class="cx"> if (!dictionary)
</span><span class="cx"> return nil;
</span><span class="lines">@@ -616,10 +620,10 @@
</span><span class="cx"> TemporaryChange<const API::Dictionary*> dictionaryChange(decoder->_currentDictionary, dictionary);
</span><span class="cx">
</span><span class="cx"> // If no allowed classes were listed, just use the currently allowed classes.
</span><del>- if (!allowedClasses)
</del><ins>+ if (allowedClasses.isEmpty())
</ins><span class="cx"> return decodeObject(decoder);
</span><span class="cx">
</span><del>- TemporaryChange<NSSet *> allowedClassesChange(decoder->_allowedClasses, allowedClasses);
</del><ins>+ TemporaryChange<const HashSet<Class>*> allowedClassesChange(decoder->_allowedClasses, &allowedClasses);
</ins><span class="cx"> return decodeObject(decoder);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -695,12 +699,23 @@
</span><span class="cx">
</span><span class="cx"> - (id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key
</span><span class="cx"> {
</span><del>- return decodeObject(self, _currentDictionary->get<API::Dictionary>(escapeKey(key)), classes);
</del><ins>+ HashSet<Class> allowedClasses;
+ for (Class allowedClass in classes)
+ allowedClasses.add(allowedClass);
+
+ return decodeObject(self, _currentDictionary->get<API::Dictionary>(escapeKey(key)), allowedClasses);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSSet *)allowedClasses
</span><span class="cx"> {
</span><del>- return _allowedClasses;
</del><ins>+ if (!_allowedClasses)
+ return [NSSet set];
+
+ auto result = adoptNS([[NSMutableSet alloc] init]);
+ for (Class allowedClass : *_allowedClasses)
+ [result addObject:allowedClass];
+
+ return result.autorelease();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm (192161 => 192162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm        2015-11-09 18:10:29 UTC (rev 192161)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm        2015-11-09 18:35:19 UTC (rev 192162)
</span><span class="lines">@@ -24,14 +24,15 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "config.h"
</span><del>-#import "_WKRemoteObjectInterface.h"
</del><ins>+#import "_WKRemoteObjectInterfaceInternal.h"
</ins><span class="cx">
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><span class="cx"> #import <objc/runtime.h>
</span><span class="cx"> #import <wtf/HashMap.h>
</span><ins>+#import <wtf/NeverDestroyed.h>
+#import <wtf/RetainPtr.h>
</ins><span class="cx"> #import <wtf/Vector.h>
</span><del>-#import <wtf/RetainPtr.h>
</del><span class="cx">
</span><span class="cx"> extern "C"
</span><span class="cx"> const char *_protocol_getMethodTypeEncoding(Protocol *p, SEL sel, BOOL isRequiredMethod, BOOL isInstanceMethod);
</span><span class="lines">@@ -40,88 +41,116 @@
</span><span class="cx"> - (Class)_classForObjectAtArgumentIndex:(NSInteger)idx;
</span><span class="cx"> @end
</span><span class="cx">
</span><ins>+struct MethodInfo {
+ Vector<HashSet<Class>> allowedArgumentClasses;
+
+ // FIXME: This should have allowed reply argument classes too.
+};
+
</ins><span class="cx"> @implementation _WKRemoteObjectInterface {
</span><del>- HashMap<SEL, Vector<RetainPtr<NSSet>>> _allowedArgumentClasses;
</del><span class="cx"> RetainPtr<NSString> _identifier;
</span><ins>+
+ HashMap<SEL, MethodInfo> _methods;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static bool isContainerClass(Class objectClass)
</span><span class="cx"> {
</span><span class="cx"> // FIXME: Add more classes here if needed.
</span><del>- static NSSet *containerClasses = [[NSSet alloc] initWithObjects:[NSArray class], [NSDictionary class], nil];
</del><ins>+ static LazyNeverDestroyed<HashSet<Class>> containerClasses;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ containerClasses.construct(std::initializer_list<Class> { [NSArray class], [NSDictionary class] });
+ });
</ins><span class="cx">
</span><del>- return [containerClasses containsObject:objectClass];
</del><ins>+ return containerClasses->contains(objectClass);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static NSSet *propertyListClasses()
</del><ins>+static HashSet<Class>& propertyListClasses()
</ins><span class="cx"> {
</span><del>- // FIXME: Add more property list classes if needed.
- static NSSet *propertyListClasses = [[NSSet alloc] initWithObjects:[NSArray class], [NSDictionary class], [NSNumber class], [NSString class], nil];
</del><ins>+ static LazyNeverDestroyed<HashSet<Class>> propertyListClasses;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ propertyListClasses.construct(std::initializer_list<Class> { [NSArray class], [NSDictionary class], [NSNumber class], [NSString class] });
+ });
</ins><span class="cx">
</span><span class="cx"> return propertyListClasses;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static Vector<RetainPtr<NSSet>> allowedArgumentClassesForMethod(NSMethodSignature *methodSignature)
</del><ins>+static void initializeMethod(MethodInfo& methodInfo, NSMethodSignature *methodSignature, bool forReplyBlock)
</ins><span class="cx"> {
</span><del>- Vector<RetainPtr<NSSet>> result;
</del><ins>+ Vector<HashSet<Class>> allowedClasses;
</ins><span class="cx">
</span><del>- NSSet *emptySet = [NSSet set];
</del><ins>+ NSUInteger firstArgument = forReplyBlock ? 1 : 2;
+ NSUInteger argumentCount = methodSignature.numberOfArguments;
</ins><span class="cx">
</span><del>- // We ignore self and _cmd.
- NSUInteger argumentCount = methodSignature.numberOfArguments - 2;
</del><ins>+ for (NSUInteger i = firstArgument; i < argumentCount; ++i) {
+ const char* argumentType = [methodSignature getArgumentTypeAtIndex:i];
</ins><span class="cx">
</span><del>- result.reserveInitialCapacity(argumentCount);
-
- for (NSUInteger i = 0; i < argumentCount; ++i) {
- const char* type = [methodSignature getArgumentTypeAtIndex:i + 2];
-
- if (*type != '@') {
</del><ins>+ if (*argumentType != '@') {
</ins><span class="cx"> // This is a non-object type; we won't allow any classes to be decoded for it.
</span><del>- result.uncheckedAppend(emptySet);
</del><ins>+ allowedClasses.uncheckedAppend({ });
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- Class objectClass = [methodSignature _classForObjectAtArgumentIndex:i + 2];
</del><ins>+ Class objectClass = [methodSignature _classForObjectAtArgumentIndex:i];
</ins><span class="cx"> if (!objectClass) {
</span><del>- result.uncheckedAppend(emptySet);
</del><ins>+ allowedClasses.append({ });
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (isContainerClass(objectClass)) {
</span><span class="cx"> // For container classes, we allow all simple property list classes.
</span><del>- result.uncheckedAppend(propertyListClasses());
</del><ins>+ allowedClasses.append(propertyListClasses());
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- result.uncheckedAppend([NSSet setWithObject:objectClass]);
</del><ins>+ allowedClasses.append({ objectClass });
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- return result;
</del><ins>+ methodInfo.allowedArgumentClasses = WTF::move(allowedClasses);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static void initializeAllowedArgumentClasses(_WKRemoteObjectInterface *interface, bool requiredMethods)
</del><ins>+static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *protocol, bool requiredMethods)
</ins><span class="cx"> {
</span><span class="cx"> unsigned methodCount;
</span><del>- struct objc_method_description *methods = protocol_copyMethodDescriptionList(interface->_protocol, requiredMethods, true, &methodCount);
</del><ins>+ struct objc_method_description *methods = protocol_copyMethodDescriptionList(protocol, requiredMethods, true, &methodCount);
</ins><span class="cx">
</span><span class="cx"> for (unsigned i = 0; i < methodCount; ++i) {
</span><span class="cx"> SEL selector = methods[i].name;
</span><span class="cx">
</span><del>- const char* types = _protocol_getMethodTypeEncoding(interface->_protocol, selector, requiredMethods, true);
- if (!types)
</del><ins>+ ASSERT(!interface->_methods.contains(selector));
+ MethodInfo& methodInfo = interface->_methods.add(selector, MethodInfo()).iterator->value;
+
+ const char* methodTypeEncoding = _protocol_getMethodTypeEncoding(protocol, selector, requiredMethods, true);
+ if (!methodTypeEncoding)
</ins><span class="cx"> [NSException raise:NSInvalidArgumentException format:@"Could not find method type encoding for method \"%s\"", sel_getName(selector)];
</span><span class="cx">
</span><del>- NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:types];
- interface->_allowedArgumentClasses.set(selector, allowedArgumentClassesForMethod(methodSignature));
</del><ins>+ NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:methodTypeEncoding];
+
+ initializeMethod(methodInfo, methodSignature, false);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> free(methods);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void initializeAllowedArgumentClasses(_WKRemoteObjectInterface *interface)
</del><ins>+static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *protocol)
</ins><span class="cx"> {
</span><del>- initializeAllowedArgumentClasses(interface, true);
- initializeAllowedArgumentClasses(interface, false);
</del><ins>+ unsigned conformingProtocolCount;
+ Protocol** conformingProtocols = protocol_copyProtocolList(interface->_protocol, &conformingProtocolCount);
+
+ for (unsigned i = 0; i < conformingProtocolCount; ++i) {
+ Protocol* conformingProtocol = conformingProtocols[i];
+
+ if (conformingProtocol == @protocol(NSObject))
+ continue;
+
+ initializeMethods(interface, conformingProtocol);
+ }
+
+ free(conformingProtocols);
+
+ initializeMethods(interface, protocol, true);
+ initializeMethods(interface, protocol, false);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (id)initWithProtocol:(Protocol *)protocol identifier:(NSString *)identifier
</span><span class="lines">@@ -132,7 +161,7 @@
</span><span class="cx"> _protocol = protocol;
</span><span class="cx"> _identifier = adoptNS([identifier copy]);
</span><span class="cx">
</span><del>- initializeAllowedArgumentClasses(self);
</del><ins>+ initializeMethods(self, _protocol);
</ins><span class="cx">
</span><span class="cx"> return self;
</span><span class="cx"> }
</span><span class="lines">@@ -152,26 +181,38 @@
</span><span class="cx"> return [NSString stringWithFormat:@"<%@: %p; protocol = \"%@\"; identifier = \"%@\">", NSStringFromClass(self.class), self, _identifier.get(), NSStringFromProtocol(_protocol)];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static RetainPtr<NSSet>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex)
</del><ins>+static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex)
</ins><span class="cx"> {
</span><del>- auto it = interface->_allowedArgumentClasses.find(selector);
- if (it == interface->_allowedArgumentClasses.end())
</del><ins>+ auto it = interface->_methods.find(selector);
+ if (it == interface->_methods.end())
</ins><span class="cx"> [NSException raise:NSInvalidArgumentException format:@"Interface does not contain selector \"%s\"", sel_getName(selector)];
</span><span class="cx">
</span><del>- if (argumentIndex >= it->value.size())
</del><ins>+ MethodInfo& methodInfo = it->value;
+ auto& allowedArgumentClasses = methodInfo.allowedArgumentClasses;
+
+ if (argumentIndex >= allowedArgumentClasses.size())
</ins><span class="cx"> [NSException raise:NSInvalidArgumentException format:@"Argument index %ld is out of range for selector \"%s\"", (unsigned long)argumentIndex, sel_getName(selector)];
</span><span class="cx">
</span><del>- return it->value[argumentIndex];
</del><ins>+ return allowedArgumentClasses[argumentIndex];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
</span><span class="cx"> {
</span><del>- return [[classesForSelectorArgument(self, selector, argumentIndex).get() retain] autorelease];
</del><ins>+ auto result = adoptNS([[NSMutableSet alloc] init]);
+
+ for (auto allowedClass : classesForSelectorArgument(self, selector, argumentIndex))
+ [result addObject:allowedClass];
+
+ return result.autorelease();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
</span><span class="cx"> {
</span><del>- classesForSelectorArgument(self, selector, argumentIndex) = adoptNS([classes copy]);
</del><ins>+ HashSet<Class> allowedClasses;
+ for (Class allowedClass in classes)
+ allowedClasses.add(allowedClass);
+
+ classesForSelectorArgument(self, selector, argumentIndex) = WTF::move(allowedClasses);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL selector)
</span><span class="lines">@@ -198,12 +239,11 @@
</span><span class="cx"> return [NSMethodSignature signatureWithObjCTypes:types];
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (const Vector<RetainPtr<NSSet>>&)_allowedArgumentClassesForSelector:(SEL)selector
</del><ins>+- (const Vector<HashSet<Class>>&)_allowedArgumentClassesForSelector:(SEL)selector
</ins><span class="cx"> {
</span><del>- auto it = _allowedArgumentClasses.find(selector);
- ASSERT(it != _allowedArgumentClasses.end());
</del><ins>+ ASSERT(_methods.contains(selector));
</ins><span class="cx">
</span><del>- return it->value;
</del><ins>+ return _methods.find(selector)->value.allowedArgumentClasses;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPICocoa_WKRemoteObjectInterfaceInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h (192161 => 192162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h        2015-11-09 18:10:29 UTC (rev 192161)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterfaceInternal.h        2015-11-09 18:35:19 UTC (rev 192162)
</span><span class="lines">@@ -28,12 +28,14 @@
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><span class="cx"> #import <wtf/Forward.h>
</span><ins>+#import <wtf/HashSet.h>
</ins><span class="cx"> #import <wtf/RetainPtr.h>
</span><ins>+#import <wtf/Vector.h>
</ins><span class="cx">
</span><span class="cx"> @interface _WKRemoteObjectInterface ()
</span><span class="cx">
</span><span class="cx"> - (NSMethodSignature *)_methodSignatureForSelector:(SEL)selector;
</span><del>-- (const Vector<RetainPtr<NSSet>>&)_allowedArgumentClassesForSelector:(SEL)selector;
</del><ins>+- (const Vector<HashSet<Class>>&)_allowedArgumentClassesForSelector:(SEL)selector;
</ins><span class="cx">
</span><span class="cx"> @end
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>