Changeset 160148 in webkit
- Timestamp:
- Dec 4, 2013 5:43:49 PM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r160146 r160148 1 2013-12-04 Sam Weinig <sam@webkit.org> 2 3 [Cocoa] Make WKConnection work with WKObject wrapping 4 https://bugs.webkit.org/show_bug.cgi?id=125266 5 6 Reviewed by Dan Bernstein. 7 8 * UIProcess/API/Cocoa/WKConnection.mm: 9 (-[WKConnection dealloc]): 10 (didReceiveMessage): 11 (didClose): 12 (setUpClient): 13 (-[WKConnection delegate]): 14 (-[WKConnection setDelegate:]): 15 (-[WKConnection sendMessageWithName:body:]): 16 (-[WKConnection remoteObjectRegistry]): 17 (-[WKConnection API::]): 18 * UIProcess/API/Cocoa/WKConnectionInternal.h: 19 (WebKit::wrapper): 20 * UIProcess/API/Cocoa/WKProcessGroup.mm: 21 (didCreateConnection): 22 * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm: 23 (-[WKWebProcessPlugInController _initWithPrincipalClassInstance:bundleRef:]): 24 (-[WKWebProcessPlugInController connection]): 25 (-[WKWebProcessPlugInController _bundleRef]): 26 1 27 2013-12-04 Anders Carlsson <andersca@apple.com> 2 28 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm
r160104 r160148 30 30 31 31 #import "ObjCObjectGraph.h" 32 #import "WKConnectionRef.h" 33 #import "WKData.h" 32 #import "WKRemoteObjectRegistryInternal.h" 34 33 #import "WKRetainPtr.h" 34 #import "WKSharedAPICast.h" 35 35 #import "WKStringCF.h" 36 #import "WKRemoteObjectRegistryInternal.h"37 36 #import <wtf/RetainPtr.h> 37 #import <wtf/text/WTFString.h> 38 38 39 39 using namespace WebKit; 40 40 41 41 @implementation WKConnection { 42 // Underlying connection object. 43 WKRetainPtr<WKConnectionRef> _connectionRef; 44 42 API::ObjectStorage<WebConnection> _connection; 45 43 RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry; 46 44 } 47 45 46 @synthesize delegate = _delegate; 47 48 48 - (void)dealloc 49 49 { 50 WKConnectionSetConnectionClient(_connectionRef.get(), 0);50 _connection->~WebConnection(); 51 51 52 52 [super dealloc]; 53 }54 55 - (void)sendMessageWithName:(NSString *)messageName body:(id)messageBody56 {57 WKRetainPtr<WKStringRef> wkMessageName = adoptWK(WKStringCreateWithCFString((CFStringRef)messageName));58 RefPtr<ObjCObjectGraph> wkMessageBody = ObjCObjectGraph::create(messageBody);59 60 WKConnectionPostMessage(_connectionRef.get(), wkMessageName.get(), (WKTypeRef)wkMessageBody.get());61 }62 63 - (WKRemoteObjectRegistry *)remoteObjectRegistry64 {65 if (!_remoteObjectRegistry)66 _remoteObjectRegistry = adoptNS([[WKRemoteObjectRegistry alloc] _initWithConnectionRef:_connectionRef.get()]);67 68 return _remoteObjectRegistry.get();69 53 } 70 54 … … 72 56 { 73 57 WKConnection *connection = (WKConnection *)clientInfo; 74 75 58 if ([connection->_remoteObjectRegistry _handleMessageWithName:messageName body:messageBody]) 76 59 return; … … 79 62 RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName)); 80 63 RetainPtr<id> nsMessageBody = ((ObjCObjectGraph*)messageBody)->rootObject(); 81 82 64 [connection.delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()]; 83 65 } … … 87 69 { 88 70 WKConnection *connection = (WKConnection *)clientInfo; 89 if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)]) {71 if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)]) 90 72 [connection.delegate connectionDidClose:connection]; 91 }92 73 } 93 74 94 static void setUpClient(WKConnection * connection, WKConnectionRef connectionRef)75 static void setUpClient(WKConnection *wrapper, WebConnection& connection) 95 76 { 96 77 WKConnectionClientV0 client; … … 98 79 99 80 client.base.version = 0; 100 client.base.clientInfo = connection;81 client.base.clientInfo = wrapper; 101 82 client.didReceiveMessage = didReceiveMessage; 102 83 client.didClose = didClose; 103 84 104 WKConnectionSetConnectionClient(connectionRef,&client.base);85 connection.initializeConnectionClient(&client.base); 105 86 } 106 87 107 - (id )_initWithConnectionRef:(WKConnectionRef)connectionRef88 - (id <WKConnectionDelegate>)delegate 108 89 { 109 self = [super init]; 110 if (!self) 111 return nil; 90 return _delegate; 91 } 112 92 113 _connectionRef = connectionRef; 93 - (void)setDelegate:(id <WKConnectionDelegate>)delegate 94 { 95 _delegate = delegate; 96 if (_delegate) 97 setUpClient(self, *_connection); 98 else 99 _connection->initializeConnectionClient(nullptr); 100 } 114 101 115 setUpClient(self, _connectionRef.get()); 102 - (void)sendMessageWithName:(NSString *)messageName body:(id)messageBody 103 { 104 RefPtr<ObjCObjectGraph> wkMessageBody = ObjCObjectGraph::create(messageBody); 105 _connection->postMessage(messageName, wkMessageBody.get()); 106 } 116 107 117 return self; 108 - (WKRemoteObjectRegistry *)remoteObjectRegistry 109 { 110 if (!_remoteObjectRegistry) 111 _remoteObjectRegistry = adoptNS([[WKRemoteObjectRegistry alloc] _initWithConnectionRef:toAPI(_connection.get())]); 112 113 return _remoteObjectRegistry.get(); 114 } 115 116 #pragma mark WKObject protocol implementation 117 118 - (API::Object&)_apiObject 119 { 120 return *_connection; 118 121 } 119 122 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnectionInternal.h
r159874 r160148 28 28 #if WK_API_ENABLED 29 29 30 #import <WebKit2/WKBase.h> 30 #import "WKObject.h" 31 #import "WebConnection.h" 31 32 32 @interface WKConnection () 33 namespace WebKit { 33 34 34 - (id)_initWithConnectionRef:(WKConnectionRef)connectionRef; 35 inline WKConnection *wrapper(WebConnection& connection) 36 { 37 ASSERT([connection.wrapper() isKindOfClass:[WKConnection class]]); 38 return (WKConnection *)connection.wrapper(); 39 } 35 40 41 } 42 43 @interface WKConnection () <WKObject> 36 44 @end 37 45 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm
r160104 r160148 70 70 { 71 71 WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo; 72 if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)]) { 73 RetainPtr<WKConnection> connection = adoptNS([[WKConnection alloc] _initWithConnectionRef:connectionRef]); 74 [processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:connection.get()]; 75 } 72 if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)]) 73 [processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))]; 76 74 } 77 75 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm
r160104 r160148 37 37 #import <wtf/RetainPtr.h> 38 38 39 using namespace WebKit; 40 39 41 typedef HashMap<WKBundlePageRef, RetainPtr<WKWebProcessPlugInBrowserContextController *>> BundlePageWrapperCache; 40 42 41 43 @interface WKWebProcessPlugInController () { 42 RetainPtr<id <WKWebProcessPlugIn> 43 WKRetainPtr<WKBundleRef> _bundleRef;44 RetainPtr<id <WKWebProcessPlugIn>> _principalClassInstance; 45 RefPtr<InjectedBundle> _bundle; 44 46 BundlePageWrapperCache _bundlePageWrapperCache; 45 47 RetainPtr<WKConnection *> _connectionWrapper; … … 111 113 112 114 _principalClassInstance = principalClassInstance; 113 _bundleRef = bundleRef; 114 _connectionWrapper = adoptNS([[WKConnection alloc] _initWithConnectionRef:WKBundleGetApplicationConnection(_bundleRef.get())]); 115 _bundle = toImpl(bundleRef); 115 116 116 117 ASSERT_WITH_MESSAGE(!sharedInstance, "WKWebProcessPlugInController initialized multiple times."); … … 130 131 - (WKConnection *)connection 131 132 { 132 return _connectionWrapper.get();133 return wrapper(*_bundle->webConnectionToUIProcess()); 133 134 } 134 135 … … 139 140 - (WKBundleRef)_bundleRef 140 141 { 141 return _bundleRef.get();142 return toAPI(_bundle.get()); 142 143 } 143 144
Note: See TracChangeset
for help on using the changeset viewer.