Commit cd451e75 authored by andersca@apple.com's avatar andersca@apple.com

WebKit2 API should use weak ownership for delegate properties rather than assign

https://bugs.webkit.org/show_bug.cgi?id=125316
<rdar://problem/15560614>

Reviewed by Dan Bernstein.

Use WeakObjCPtr for the delegates.

* UIProcess/API/Cocoa/WKBrowsingContextController.h:
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(didStartProvisionalLoadForFrame):
(didReceiveServerRedirectForProvisionalLoadForFrame):
(didFailProvisionalLoadWithErrorForFrame):
(didCommitLoadForFrame):
(didFinishLoadForFrame):
(didFailLoadWithErrorForFrame):
(didStartProgress):
(didChangeProgress):
(didFinishProgress):
(didChangeBackForwardList):
(setUpPagePolicyClient):
(-[WKBrowsingContextController loadDelegate]):
(-[WKBrowsingContextController setLoadDelegate:]):
(-[WKBrowsingContextController policyDelegate]):
(-[WKBrowsingContextController setPolicyDelegate:]):
(-[WKBrowsingContextController historyDelegate]):
(-[WKBrowsingContextController setHistoryDelegate:]):
* UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h:
* UIProcess/API/Cocoa/WKConnection.mm:
(didReceiveMessage):
(didClose):
(-[WKConnection delegate]):
(-[WKConnection setDelegate:]):
* UIProcess/API/Cocoa/WKProcessGroup.mm:
(didCreateConnection):
(getInjectedBundleInitializationUserData):
(didNavigateWithNavigationData):
(didPerformClientRedirect):
(didPerformServerRedirect):
(didUpdateHistoryTitle):
(-[WKProcessGroup delegate]):
(-[WKProcessGroup setDelegate:]):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160191 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0a6174a7
2013-12-05 Anders Carlsson <andersca@apple.com>
WebKit2 API should use weak ownership for delegate properties rather than assign
https://bugs.webkit.org/show_bug.cgi?id=125316
<rdar://problem/15560614>
Reviewed by Dan Bernstein.
Use WeakObjCPtr for the delegates.
* UIProcess/API/Cocoa/WKBrowsingContextController.h:
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(didStartProvisionalLoadForFrame):
(didReceiveServerRedirectForProvisionalLoadForFrame):
(didFailProvisionalLoadWithErrorForFrame):
(didCommitLoadForFrame):
(didFinishLoadForFrame):
(didFailLoadWithErrorForFrame):
(didStartProgress):
(didChangeProgress):
(didFinishProgress):
(didChangeBackForwardList):
(setUpPagePolicyClient):
(-[WKBrowsingContextController loadDelegate]):
(-[WKBrowsingContextController setLoadDelegate:]):
(-[WKBrowsingContextController policyDelegate]):
(-[WKBrowsingContextController setPolicyDelegate:]):
(-[WKBrowsingContextController historyDelegate]):
(-[WKBrowsingContextController setHistoryDelegate:]):
* UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h:
* UIProcess/API/Cocoa/WKConnection.mm:
(didReceiveMessage):
(didClose):
(-[WKConnection delegate]):
(-[WKConnection setDelegate:]):
* UIProcess/API/Cocoa/WKProcessGroup.mm:
(didCreateConnection):
(getInjectedBundleInitializationUserData):
(didNavigateWithNavigationData):
(didPerformClientRedirect):
(didPerformServerRedirect):
(didUpdateHistoryTitle):
(-[WKProcessGroup delegate]):
(-[WKProcessGroup setDelegate:]):
2013-12-05 Anders Carlsson <andersca@apple.com>
Tweak WeakObjCPtr
......
......@@ -44,9 +44,9 @@ WK_API_CLASS
#pragma mark Delegates
@property (assign) id <WKBrowsingContextLoadDelegate> loadDelegate;
@property (assign) id <WKBrowsingContextPolicyDelegate> policyDelegate;
@property (assign) id <WKBrowsingContextHistoryDelegate> historyDelegate;
@property (weak) id <WKBrowsingContextLoadDelegate> loadDelegate;
@property (weak) id <WKBrowsingContextPolicyDelegate> policyDelegate;
@property (weak) id <WKBrowsingContextHistoryDelegate> historyDelegate;
#pragma mark Loading
......
......@@ -28,6 +28,7 @@
#if WK_API_ENABLED
#import "WKObject.h"
#import "WeakObjCPtr.h"
#import "WebPageProxy.h"
namespace WebKit {
......@@ -40,7 +41,10 @@ inline WKBrowsingContextController *wrapper(WebPageProxy& page)
}
@interface WKBrowsingContextController () <WKObject>
@interface WKBrowsingContextController () <WKObject> {
@package
WebKit::WeakObjCPtr<id <WKBrowsingContextHistoryDelegate>> _historyDelegate;
}
- (void)_finishInitialization;
+ (NSMutableSet *)customSchemes;
......
......@@ -33,6 +33,7 @@
#import "WKRetainPtr.h"
#import "WKSharedAPICast.h"
#import "WKStringCF.h"
#import "WeakObjCPtr.h"
#import <wtf/RetainPtr.h>
#import <wtf/text/WTFString.h>
......@@ -41,9 +42,9 @@ using namespace WebKit;
@implementation WKConnection {
API::ObjectStorage<WebConnection> _connection;
RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry;
}
@synthesize delegate = _delegate;
WeakObjCPtr<id <WKConnectionDelegate>> _delegate;
}
- (void)dealloc
{
......@@ -58,18 +59,21 @@ static void didReceiveMessage(WKConnectionRef, WKStringRef messageName, WKTypeRe
if ([connection->_remoteObjectRegistry _handleMessageWithName:messageName body:messageBody])
return;
if ([connection.delegate respondsToSelector:@selector(connection:didReceiveMessageWithName:body:)]) {
auto delegate = connection->_delegate.get();
if ([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()];
[delegate connection:connection didReceiveMessageWithName:(NSString *)nsMessageName.get() body:nsMessageBody.get()];
}
}
static void didClose(WKConnectionRef, const void* clientInfo)
{
WKConnection *connection = (WKConnection *)clientInfo;
if ([connection.delegate respondsToSelector:@selector(connectionDidClose:)])
[connection.delegate connectionDidClose:connection];
auto delegate = connection->_delegate.get();
if ([delegate respondsToSelector:@selector(connectionDidClose:)])
[delegate connectionDidClose:connection];
}
static void setUpClient(WKConnection *wrapper, WebConnection& connection)
......@@ -87,13 +91,13 @@ static void setUpClient(WKConnection *wrapper, WebConnection& connection)
- (id <WKConnectionDelegate>)delegate
{
return _delegate;
return _delegate.getAutoreleased();
}
- (void)setDelegate:(id <WKConnectionDelegate>)delegate
{
_delegate = delegate;
if (_delegate)
if (delegate)
setUpClient(self, *_connection);
else
_connection->initializeConnectionClient(nullptr);
......
......@@ -40,6 +40,7 @@
#import "WKNavigationDataInternal.h"
#import "WKRetainPtr.h"
#import "WKStringCF.h"
#import "WeakObjCPtr.h"
#import "WebFrameProxy.h"
#import <wtf/RetainPtr.h>
......@@ -54,6 +55,8 @@ using namespace WebKit;
@implementation WKProcessGroup {
API::ObjectStorage<WebContext> _context;
WeakObjCPtr<id <WKProcessGroupDelegate>> _delegate;
#if PLATFORM(IOS)
RetainPtr<WKGeolocationProviderIOS> _geolocationProvider;
#endif // PLATFORM(IOS)
......@@ -69,8 +72,10 @@ using namespace WebKit;
static void didCreateConnection(WKContextRef, WKConnectionRef connectionRef, const void* clientInfo)
{
WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo;
if ([processGroup.delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)])
[processGroup.delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))];
auto delegate = processGroup->_delegate.get();
if ([delegate respondsToSelector:@selector(processGroup:didCreateConnectionToWebProcessPlugIn:)])
[delegate processGroup:processGroup didCreateConnectionToWebProcessPlugIn:wrapper(*toImpl(connectionRef))];
}
static void setUpConnectionClient(WKProcessGroup *processGroup, WKContextRef contextRef)
......@@ -88,8 +93,10 @@ static void setUpConnectionClient(WKProcessGroup *processGroup, WKContextRef con
static WKTypeRef getInjectedBundleInitializationUserData(WKContextRef, const void* clientInfo)
{
WKProcessGroup *processGroup = (WKProcessGroup *)clientInfo;
if ([processGroup.delegate respondsToSelector:@selector(processGroupWillCreateConnectionToWebProcessPlugIn:)]) {
RetainPtr<id> initializationUserData = [processGroup.delegate processGroupWillCreateConnectionToWebProcessPlugIn:processGroup];
auto delegate = processGroup->_delegate.get();
if ([delegate respondsToSelector:@selector(processGroupWillCreateConnectionToWebProcessPlugIn:)]) {
RetainPtr<id> initializationUserData = [delegate processGroupWillCreateConnectionToWebProcessPlugIn:processGroup];
RefPtr<WebKit::ObjCObjectGraph> wkMessageBody = WebKit::ObjCObjectGraph::create(initializationUserData.get());
return (WKTypeRef)wkMessageBody.release().leakRef();
}
......@@ -115,8 +122,10 @@ static void didNavigateWithNavigationData(WKContextRef, WKPageRef pageRef, WKNav
return;
WKBrowsingContextController *controller = wrapper(*toImpl(pageRef));
if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didNavigateWithNavigationData:)])
[controller.historyDelegate browsingContextController:controller didNavigateWithNavigationData:wrapper(*toImpl(navigationDataRef))];
auto historyDelegate = controller->_historyDelegate.get();
if ([historyDelegate respondsToSelector:@selector(browsingContextController:didNavigateWithNavigationData:)])
[historyDelegate browsingContextController:controller didNavigateWithNavigationData:wrapper(*toImpl(navigationDataRef))];
}
static void didPerformClientRedirect(WKContextRef, WKPageRef pageRef, WKURLRef sourceURLRef, WKURLRef destinationURLRef, WKFrameRef frameRef, const void*)
......@@ -125,8 +134,10 @@ static void didPerformClientRedirect(WKContextRef, WKPageRef pageRef, WKURLRef s
return;
WKBrowsingContextController *controller = wrapper(*toImpl(pageRef));
if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didPerformClientRedirectFromURL:toURL:)])
[controller.historyDelegate browsingContextController:controller didPerformClientRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))];
auto historyDelegate = controller->_historyDelegate.get();
if ([historyDelegate respondsToSelector:@selector(browsingContextController:didPerformClientRedirectFromURL:toURL:)])
[historyDelegate browsingContextController:controller didPerformClientRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))];
}
static void didPerformServerRedirect(WKContextRef, WKPageRef pageRef, WKURLRef sourceURLRef, WKURLRef destinationURLRef, WKFrameRef frameRef, const void*)
......@@ -135,8 +146,10 @@ static void didPerformServerRedirect(WKContextRef, WKPageRef pageRef, WKURLRef s
return;
WKBrowsingContextController *controller = wrapper(*toImpl(pageRef));
if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didPerformServerRedirectFromURL:toURL:)])
[controller.historyDelegate browsingContextController:controller didPerformServerRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))];
auto historyDelegate = controller->_historyDelegate.get();
if ([historyDelegate respondsToSelector:@selector(browsingContextController:didPerformServerRedirectFromURL:toURL:)])
[historyDelegate browsingContextController:controller didPerformServerRedirectFromURL:wrapper(*toImpl(sourceURLRef)) toURL:wrapper(*toImpl(destinationURLRef))];
}
static void didUpdateHistoryTitle(WKContextRef, WKPageRef pageRef, WKStringRef titleRef, WKURLRef urlRef, WKFrameRef frameRef, const void*)
......@@ -145,8 +158,10 @@ static void didUpdateHistoryTitle(WKContextRef, WKPageRef pageRef, WKStringRef t
return;
WKBrowsingContextController *controller = wrapper(*toImpl(pageRef));
if ([controller.historyDelegate respondsToSelector:@selector(browsingContextController:didUpdateHistoryTitle:forURL:)])
[controller.historyDelegate browsingContextController:controller didUpdateHistoryTitle:wrapper(*toImpl(titleRef)) forURL:wrapper(*toImpl(urlRef))];
auto historyDelegate = controller->_historyDelegate.get();
if ([historyDelegate respondsToSelector:@selector(browsingContextController:didUpdateHistoryTitle:forURL:)])
[historyDelegate browsingContextController:controller didUpdateHistoryTitle:wrapper(*toImpl(titleRef)) forURL:wrapper(*toImpl(urlRef))];
}
static void setUpHistoryClient(WKProcessGroup *processGroup, WKContextRef contextRef)
......@@ -189,6 +204,16 @@ static void setUpHistoryClient(WKProcessGroup *processGroup, WKContextRef contex
return self;
}
- (id <WKProcessGroupDelegate>)delegate
{
return _delegate.getAutoreleased();
}
- (void)setDelegate:(id <WKProcessGroupDelegate>)delegate
{
_delegate = delegate;
}
#pragma mark WKObject protocol implementation
- (API::Object&)_apiObject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment