Title: [158780] trunk/Source/WebKit2
- Revision
- 158780
- Author
- [email protected]
- Date
- 2013-11-06 13:17:47 -0800 (Wed, 06 Nov 2013)
Log Message
Decode invocation arguments
https://bugs.webkit.org/show_bug.cgi?id=123917
Reviewed by Sam Weinig.
* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(-[WKRemoteObjectDecoder initWithInterface:rootObjectDictionary:WebKit::]):
Initialize the object stream.
(decodeObjectFromObjectStream):
Check that we're not reading past the end of the stream, then decode the object.
(decodeInvocationArguments):
Decode arguments from the object stream.
(decodeInvocation):
Call decodeInvocationArguments and set up the selector argument.
* Shared/ImmutableArray.h:
(WebKit::ImmutableArray::at):
(WebKit::ImmutableArray::size):
(WebKit::ImmutableArray::entries):
Constify.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (158779 => 158780)
--- trunk/Source/WebKit2/ChangeLog 2013-11-06 20:56:52 UTC (rev 158779)
+++ trunk/Source/WebKit2/ChangeLog 2013-11-06 21:17:47 UTC (rev 158780)
@@ -1,3 +1,29 @@
+2013-11-06 Anders Carlsson <[email protected]>
+
+ Decode invocation arguments
+ https://bugs.webkit.org/show_bug.cgi?id=123917
+
+ Reviewed by Sam Weinig.
+
+ * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+ (-[WKRemoteObjectDecoder initWithInterface:rootObjectDictionary:WebKit::]):
+ Initialize the object stream.
+
+ (decodeObjectFromObjectStream):
+ Check that we're not reading past the end of the stream, then decode the object.
+
+ (decodeInvocationArguments):
+ Decode arguments from the object stream.
+
+ (decodeInvocation):
+ Call decodeInvocationArguments and set up the selector argument.
+
+ * Shared/ImmutableArray.h:
+ (WebKit::ImmutableArray::at):
+ (WebKit::ImmutableArray::size):
+ (WebKit::ImmutableArray::entries):
+ Constify.
+
2013-11-06 Dan Bernstein <[email protected]>
[Cocoa] Add -[WKNavigationData response]
Modified: trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm (158779 => 158780)
--- trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm 2013-11-06 20:56:52 UTC (rev 158779)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm 2013-11-06 21:17:47 UTC (rev 158780)
@@ -258,6 +258,9 @@
const ImmutableDictionary* _rootDictionary;
const ImmutableDictionary* _currentDictionary;
+ const ImmutableArray* _objectStream;
+ size_t _objectStreamPosition;
+
NSSet *_allowedClasses;
}
@@ -271,6 +274,8 @@
_rootDictionary = rootObjectDictionary;
_currentDictionary = _rootDictionary;
+ _objectStream = _rootDictionary->get<ImmutableArray>(objectStreamKey);
+
return self;
}
@@ -299,6 +304,23 @@
return YES;
}
+static id decodeObject(WKRemoteObjectDecoder *decoder, const ImmutableDictionary*);
+
+static id decodeObjectFromObjectStream(WKRemoteObjectDecoder *decoder, NSSet *allowedClasses)
+{
+ if (!decoder->_objectStream)
+ return nil;
+
+ if (decoder->_objectStreamPosition == decoder->_objectStream->size())
+ return nil;
+
+ TemporaryChange<NSSet *> allowedClassesChange(decoder->_allowedClasses, allowedClasses);
+
+ const ImmutableDictionary* dictionary = decoder->_objectStream->at<ImmutableDictionary>(decoder->_objectStreamPosition++);
+
+ return decodeObject(decoder, dictionary);
+}
+
static void checkIfClassIsAllowed(WKRemoteObjectDecoder *decoder, Class objectClass)
{
NSSet *allowedClasses = decoder->_allowedClasses;
@@ -325,6 +347,50 @@
[decoder validateClassSupportsSecureCoding:objectClass];
}
+static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocation *invocation, const Vector<RetainPtr<NSSet>>& allowedArgumentClasses)
+{
+ NSMethodSignature *methodSignature = invocation.methodSignature;
+ NSUInteger argumentCount = methodSignature.numberOfArguments;
+
+ // The invocation should always have have self and _cmd arguments.
+ ASSERT(argumentCount >= 2);
+
+ // We ignore self and _cmd.
+ for (NSUInteger i = 2; i < argumentCount; ++i) {
+ const char* type = [methodSignature getArgumentTypeAtIndex:i];
+
+ switch (*type) {
+ // double
+ case 'd': {
+ double value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) doubleValue];
+ [invocation setArgument:&value atIndex:i];
+ break;
+ }
+
+ // int
+ case 'i': {
+ int value = [decodeObjectFromObjectStream(decoder, [NSSet setWithObject:[NSNumber class]]) intValue];
+ [invocation setArgument:&value atIndex:i];
+ break;
+ }
+
+ // Objective-C object
+ case '@': {
+ NSSet *allowedClasses = allowedArgumentClasses[i - 2].get();
+
+ id value = decodeObjectFromObjectStream(decoder, allowedClasses);
+ [invocation setArgument:&value atIndex:i];
+
+ // FIXME: Make sure the invocation doesn't outlive the value.
+ break;
+ }
+
+ default:
+ [NSException raise:NSInvalidArgumentException format:@"Unsupported invocation argument type '%s' for argument %zu", type, i];
+ }
+ }
+}
+
static NSInvocation *decodeInvocation(WKRemoteObjectDecoder *decoder)
{
NSString *selectorString = [decoder decodeObjectOfClass:[NSString class] forKey:selectorKey];
@@ -346,8 +412,13 @@
if (![localMethodSignature isEqualTo:remoteMethodSignature])
[NSException raise:NSInvalidUnarchiveOperationException format:@"Local and remote method signatures are not equal for method \"%@\"", selectorString];
- // FIXME: Handle arguments.
- return nil;
+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:localMethodSignature];
+
+ const auto& allowedClasses = [decoder->_interface _allowedArgumentClassesForSelector:selector];
+ decodeInvocationArguments(decoder, invocation, allowedClasses);
+
+ [invocation setArgument:&selector atIndex:1];
+ return invocation;
}
static id decodeObject(WKRemoteObjectDecoder *decoder)
Modified: trunk/Source/WebKit2/Shared/ImmutableArray.h (158779 => 158780)
--- trunk/Source/WebKit2/Shared/ImmutableArray.h 2013-11-06 20:56:52 UTC (rev 158779)
+++ trunk/Source/WebKit2/Shared/ImmutableArray.h 2013-11-06 21:17:47 UTC (rev 158780)
@@ -58,14 +58,20 @@
virtual ~ImmutableArray();
template<typename T>
- T* at(size_t i) { if (m_entries[i]->type() != T::APIType) return 0; return static_cast<T*>(m_entries[i].get()); }
+ T* at(size_t i) const
+ {
+ if (m_entries[i]->type() != T::APIType)
+ return nullptr;
- APIObject* at(size_t i) { return m_entries[i].get(); }
- size_t size() { return m_entries.size(); }
+ return static_cast<T*>(m_entries[i].get());
+ }
+ APIObject* at(size_t i) const { return m_entries[i].get(); }
+ size_t size() const { return m_entries.size(); }
+
virtual bool isMutable() { return false; }
- const Vector<RefPtr<APIObject>>& entries() { return m_entries; }
+ const Vector<RefPtr<APIObject>>& entries() const { return m_entries; }
protected:
ImmutableArray();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes