Changeset 160148 in webkit


Ignore:
Timestamp:
Dec 4, 2013 5:43:49 PM (10 years ago)
Author:
weinig@apple.com
Message:

[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]):

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r160146 r160148  
     12013-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
    1272013-12-04  Anders Carlsson  <andersca@apple.com>
    228
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnection.mm

    r160104 r160148  
    3030
    3131#import "ObjCObjectGraph.h"
    32 #import "WKConnectionRef.h"
    33 #import "WKData.h"
     32#import "WKRemoteObjectRegistryInternal.h"
    3433#import "WKRetainPtr.h"
     34#import "WKSharedAPICast.h"
    3535#import "WKStringCF.h"
    36 #import "WKRemoteObjectRegistryInternal.h"
    3736#import <wtf/RetainPtr.h>
     37#import <wtf/text/WTFString.h>
    3838
    3939using namespace WebKit;
    4040
    4141@implementation WKConnection {
    42     // Underlying connection object.
    43     WKRetainPtr<WKConnectionRef> _connectionRef;
    44 
     42    API::ObjectStorage<WebConnection> _connection;
    4543    RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry;
    4644}
    4745
     46@synthesize delegate = _delegate;
     47
    4848- (void)dealloc
    4949{
    50     WKConnectionSetConnectionClient(_connectionRef.get(), 0);
     50    _connection->~WebConnection();
    5151
    5252    [super dealloc];
    53 }
    54 
    55 - (void)sendMessageWithName:(NSString *)messageName body:(id)messageBody
    56 {
    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 *)remoteObjectRegistry
    64 {
    65     if (!_remoteObjectRegistry)
    66         _remoteObjectRegistry = adoptNS([[WKRemoteObjectRegistry alloc] _initWithConnectionRef:_connectionRef.get()]);
    67 
    68     return _remoteObjectRegistry.get();
    6953}
    7054
     
    7256{
    7357    WKConnection *connection = (WKConnection *)clientInfo;
    74 
    7558    if ([connection->_remoteObjectRegistry _handleMessageWithName:messageName body:messageBody])
    7659        return;
     
    7962        RetainPtr<CFStringRef> nsMessageName = adoptCF(WKStringCopyCFString(kCFAllocatorDefault, messageName));
    8063        RetainPtr<id> nsMessageBody = ((ObjCObjectGraph*)messageBody)->rootObject();
    81 
    8264        [connection.delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()];
    8365    }
     
    8769{
    8870    WKConnection *connection = (WKConnection *)clientInfo;
    89     if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)]) {
     71    if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)])
    9072        [connection.delegate connectionDidClose:connection];
    91     }
    9273}
    9374
    94 static void setUpClient(WKConnection *connection, WKConnectionRef connectionRef)
     75static void setUpClient(WKConnection *wrapper, WebConnection& connection)
    9576{
    9677    WKConnectionClientV0 client;
     
    9879
    9980    client.base.version = 0;
    100     client.base.clientInfo = connection;
     81    client.base.clientInfo = wrapper;
    10182    client.didReceiveMessage = didReceiveMessage;
    10283    client.didClose = didClose;
    10384
    104     WKConnectionSetConnectionClient(connectionRef, &client.base);
     85    connection.initializeConnectionClient(&client.base);
    10586}
    10687
    107 - (id)_initWithConnectionRef:(WKConnectionRef)connectionRef
     88- (id <WKConnectionDelegate>)delegate
    10889{
    109     self = [super init];
    110     if (!self)
    111         return nil;
     90    return _delegate;
     91}
    11292
    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}
    114101
    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}
    116107
    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;
    118121}
    119122
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKConnectionInternal.h

    r159874 r160148  
    2828#if WK_API_ENABLED
    2929
    30 #import <WebKit2/WKBase.h>
     30#import "WKObject.h"
     31#import "WebConnection.h"
    3132
    32 @interface WKConnection ()
     33namespace WebKit {
    3334
    34 - (id)_initWithConnectionRef:(WKConnectionRef)connectionRef;
     35inline WKConnection *wrapper(WebConnection& connection)
     36{
     37    ASSERT([connection.wrapper() isKindOfClass:[WKConnection class]]);
     38    return (WKConnection *)connection.wrapper();
     39}
    3540
     41}
     42
     43@interface WKConnection () <WKObject>
    3644@end
    3745
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessGroup.mm

    r160104 r160148  
    7070{
    7171    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))];
    7674}
    7775
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm

    r160104 r160148  
    3737#import <wtf/RetainPtr.h>
    3838
     39using namespace WebKit;
     40
    3941typedef HashMap<WKBundlePageRef, RetainPtr<WKWebProcessPlugInBrowserContextController *>> BundlePageWrapperCache;
    4042
    4143@interface WKWebProcessPlugInController () {
    42     RetainPtr<id <WKWebProcessPlugIn> > _principalClassInstance;
    43     WKRetainPtr<WKBundleRef> _bundleRef;
     44    RetainPtr<id <WKWebProcessPlugIn>> _principalClassInstance;
     45    RefPtr<InjectedBundle> _bundle;
    4446    BundlePageWrapperCache _bundlePageWrapperCache;
    4547    RetainPtr<WKConnection *> _connectionWrapper;
     
    111113
    112114    _principalClassInstance = principalClassInstance;
    113     _bundleRef = bundleRef;
    114     _connectionWrapper = adoptNS([[WKConnection alloc] _initWithConnectionRef:WKBundleGetApplicationConnection(_bundleRef.get())]);
     115    _bundle = toImpl(bundleRef);
    115116
    116117    ASSERT_WITH_MESSAGE(!sharedInstance, "WKWebProcessPlugInController initialized multiple times.");
     
    130131- (WKConnection *)connection
    131132{
    132     return _connectionWrapper.get();
     133    return wrapper(*_bundle->webConnectionToUIProcess());
    133134}
    134135
     
    139140- (WKBundleRef)_bundleRef
    140141{
    141     return _bundleRef.get();
     142    return toAPI(_bundle.get());
    142143}
    143144
Note: See TracChangeset for help on using the changeset viewer.