Diff
Modified: trunk/Source/WebKit2/ChangeLog (160147 => 160148)
--- trunk/Source/WebKit2/ChangeLog 2013-12-05 01:30:00 UTC (rev 160147)
+++ trunk/Source/WebKit2/ChangeLog 2013-12-05 01:43:49 UTC (rev 160148)
@@ -1,3 +1,29 @@
+2013-12-04 Sam Weinig <[email protected]>
+
+ [Cocoa] Make WKConnection work with WKObject wrapping
+ https://bugs.webkit.org/show_bug.cgi?id=125266
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/API/Cocoa/WKConnection.mm:
+ (-[WKConnection dealloc]):
+ (didReceiveMessage):
+ (didClose):
+ (setUpClient):
+ (-[WKConnection delegate]):
+ (-[WKConnection setDelegate:]):
+ (-[WKConnection sendMessageWithName:body:]):
+ (-[WKConnection remoteObjectRegistry]):
+ (-[WKConnection API::]):
+ * UIProcess/API/Cocoa/WKConnectionInternal.h:
+ (WebKit::wrapper):
+ * UIProcess/API/Cocoa/WKProcessGroup.mm:
+ (didCreateConnection):
+ * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm:
+ (-[WKWebProcessPlugInController _initWithPrincipalClassInstance:bundleRef:]):
+ (-[WKWebProcessPlugInController connection]):
+ (-[WKWebProcessPlugInController _bundleRef]):
+
2013-12-04 Anders Carlsson <[email protected]>
Add a WeakObjCPtr class
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm (160147 => 160148)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm 2013-12-05 01:30:00 UTC (rev 160147)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm 2013-12-05 01:43:49 UTC (rev 160148)
@@ -29,56 +29,38 @@
#if WK_API_ENABLED
#import "ObjCObjectGraph.h"
-#import "WKConnectionRef.h"
-#import "WKData.h"
+#import "WKRemoteObjectRegistryInternal.h"
#import "WKRetainPtr.h"
+#import "WKSharedAPICast.h"
#import "WKStringCF.h"
-#import "WKRemoteObjectRegistryInternal.h"
#import <wtf/RetainPtr.h>
+#import <wtf/text/WTFString.h>
using namespace WebKit;
@implementation WKConnection {
- // Underlying connection object.
- WKRetainPtr<WKConnectionRef> _connectionRef;
-
+ API::ObjectStorage<WebConnection> _connection;
RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry;
}
+@synthesize delegate = _delegate;
+
- (void)dealloc
{
- WKConnectionSetConnectionClient(_connectionRef.get(), 0);
+ _connection->~WebConnection();
[super dealloc];
}
-- (void)sendMessageWithName:(NSString *)messageName body:(id)messageBody
-{
- WKRetainPtr<WKStringRef> wkMessageName = adoptWK(WKStringCreateWithCFString((CFStringRef)messageName));
- RefPtr<ObjCObjectGraph> wkMessageBody = ObjCObjectGraph::create(messageBody);
-
- WKConnectionPostMessage(_connectionRef.get(), wkMessageName.get(), (WKTypeRef)wkMessageBody.get());
-}
-
-- (WKRemoteObjectRegistry *)remoteObjectRegistry
-{
- if (!_remoteObjectRegistry)
- _remoteObjectRegistry = adoptNS([[WKRemoteObjectRegistry alloc] _initWithConnectionRef:_connectionRef.get()]);
-
- return _remoteObjectRegistry.get();
-}
-
static void didReceiveMessage(WKConnectionRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
{
WKConnection *connection = (WKConnection *)clientInfo;
-
if ([connection->_remoteObjectRegistry _handleMessageWithName:messageName body:messageBody])
return;
if ([connection.delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) {
RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName));
RetainPtr<id> nsMessageBody = ((ObjCObjectGraph*)messageBody)->rootObject();
-
[connection.delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()];
}
}
@@ -86,37 +68,58 @@
static void didClose(WKConnectionRef, const void* clientInfo)
{
WKConnection *connection = (WKConnection *)clientInfo;
- if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)]) {
+ if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)])
[connection.delegate connectionDidClose:connection];
- }
}
-static void setUpClient(WKConnection *connection, WKConnectionRef connectionRef)
+static void setUpClient(WKConnection *wrapper, WebConnection& connection)
{
WKConnectionClientV0 client;
memset(&client, 0, sizeof(client));
client.base.version = 0;
- client.base.clientInfo = connection;
+ client.base.clientInfo = wrapper;
client.didReceiveMessage = didReceiveMessage;
client.didClose = didClose;
- WKConnectionSetConnectionClient(connectionRef, &client.base);
+ connection.initializeConnectionClient(&client.base);
}
-- (id)_initWithConnectionRef:(WKConnectionRef)connectionRef
+- (id <WKConnectionDelegate>)delegate
{
- self = [super init];
- if (!self)
- return nil;
+ return _delegate;
+}
- _connectionRef = connectionRef;
+- (void)setDelegate:(id <WKConnectionDelegate>)delegate
+{
+ _delegate = delegate;
+ if (_delegate)
+ setUpClient(self, *_connection);
+ else
+ _connection->initializeConnectionClient(nullptr);
+}
- setUpClient(self, _connectionRef.get());
+- (void)sendMessageWithName:(NSString *)messageName body:(id)messageBody
+{
+ RefPtr<ObjCObjectGraph> wkMessageBody = ObjCObjectGraph::create(messageBody);
+ _connection->postMessage(messageName, wkMessageBody.get());
+}
- return self;
+- (WKRemoteObjectRegistry *)remoteObjectRegistry
+{
+ if (!_remoteObjectRegistry)
+ _remoteObjectRegistry = adoptNS([[WKRemoteObjectRegistry alloc] _initWithConnectionRef:toAPI(_connection.get())]);
+
+ return _remoteObjectRegistry.get();
}
+#pragma mark WKObject protocol implementation
+
+- (API::Object&)_apiObject
+{
+ return *_connection;
+}
+
@end
#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnectionInternal.h (160147 => 160148)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnectionInternal.h 2013-12-05 01:30:00 UTC (rev 160147)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnectionInternal.h 2013-12-05 01:43:49 UTC (rev 160148)
@@ -27,12 +27,20 @@
#if WK_API_ENABLED
-#import <WebKit2/WKBase.h>
+#import "WKObject.h"
+#import "WebConnection.h"
-@interface WKConnection ()
+namespace WebKit {
-- (id)_initWithConnectionRef:(WKConnectionRef)connectionRef;
+inline WKConnection *wrapper(WebConnection& connection)
+{
+ ASSERT([connection.wrapper() isKindOfClass:[WKConnection class]]);
+ return (WKConnection *)connection.wrapper();
+}
+}
+
+@interface WKConnection () <WKObject>
@end
#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm (160147 => 160148)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm 2013-12-05 01:30:00 UTC (rev 160147)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm 2013-12-05 01:43:49 UTC (rev 160148)
@@ -69,10 +69,8 @@
static void didCreateConnection(WKContextRef, WKConnectionRef connectionRef, const void* clientInfo)
{
WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo;
- if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)]) {
- RetainPtr<WKConnection> connection = adoptNS([[WKConnection alloc] _initWithConnectionRef:connectionRef]);
- [processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:connection.get()];
- }
+ if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)])
+ [processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))];
}
static void setUpConnectionClient(WKProcessGroup *processGroup, WKContextRef contextRef)
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm (160147 => 160148)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm 2013-12-05 01:30:00 UTC (rev 160147)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm 2013-12-05 01:43:49 UTC (rev 160148)
@@ -36,11 +36,13 @@
#import "WKWebProcessPlugInBrowserContextControllerInternal.h"
#import <wtf/RetainPtr.h>
+using namespace WebKit;
+
typedef HashMap<WKBundlePageRef, RetainPtr<WKWebProcessPlugInBrowserContextController *>> BundlePageWrapperCache;
@interface WKWebProcessPlugInController () {
- RetainPtr<id <WKWebProcessPlugIn> > _principalClassInstance;
- WKRetainPtr<WKBundleRef> _bundleRef;
+ RetainPtr<id <WKWebProcessPlugIn>> _principalClassInstance;
+ RefPtr<InjectedBundle> _bundle;
BundlePageWrapperCache _bundlePageWrapperCache;
RetainPtr<WKConnection *> _connectionWrapper;
}
@@ -110,8 +112,7 @@
return nil;
_principalClassInstance = principalClassInstance;
- _bundleRef = bundleRef;
- _connectionWrapper = adoptNS([[WKConnection alloc] _initWithConnectionRef:WKBundleGetApplicationConnection(_bundleRef.get())]);
+ _bundle = toImpl(bundleRef);
ASSERT_WITH_MESSAGE(!sharedInstance, "WKWebProcessPlugInController initialized multiple times.");
sharedInstance = self;
@@ -129,7 +130,7 @@
- (WKConnection *)connection
{
- return _connectionWrapper.get();
+ return wrapper(*_bundle->webConnectionToUIProcess());
}
@end
@@ -138,7 +139,7 @@
- (WKBundleRef)_bundleRef
{
- return _bundleRef.get();
+ return toAPI(_bundle.get());
}
@end