Use a side table to map WebPageProxy objects to WKBrowsingContextController objects
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jan 2014 21:25:23 +0000 (21:25 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jan 2014 21:25:23 +0000 (21:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127577

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(browsingContextControllerMap):
(-[WKBrowsingContextController dealloc]):
(-[WKBrowsingContextController _initWithPageRef:]):
(+[WKBrowsingContextController _browsingContextControllerForPageRef:]):
* UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h:
* UIProcess/WebPageProxy.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162719 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h
Source/WebKit2/UIProcess/WebPageProxy.h

index e2564a1..1f8111a 100644 (file)
@@ -1,3 +1,18 @@
+2014-01-24  Anders Carlsson  <andersca@apple.com>
+
+        Use a side table to map WebPageProxy objects to WKBrowsingContextController objects
+        https://bugs.webkit.org/show_bug.cgi?id=127577
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (browsingContextControllerMap):
+        (-[WKBrowsingContextController dealloc]):
+        (-[WKBrowsingContextController _initWithPageRef:]):
+        (+[WKBrowsingContextController _browsingContextControllerForPageRef:]):
+        * UIProcess/API/Cocoa/WKBrowsingContextControllerInternal.h:
+        * UIProcess/WebPageProxy.h:
+
 2014-01-24  Tim Horton  <timothy_horton@apple.com>
 
         iOS build fix after r162710.
index ce251e2..616bdca 100644 (file)
@@ -58,6 +58,7 @@
 #import "WebCertificateInfo.h"
 #import "WebContext.h"
 #import "WebPageProxy.h"
+#import <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 using namespace WebKit;
@@ -149,10 +150,18 @@ static NSString * const frameErrorKey = @"WKBrowsingContextFrameErrorKey";
     RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry;
 }
 
+static HashMap<WebPageProxy*, WKBrowsingContextController *>& browsingContextControllerMap()
+{
+    static NeverDestroyed<HashMap<WebPageProxy*, WKBrowsingContextController *>> browsingContextControllerMap;
+    return browsingContextControllerMap;
+}
+
 - (void)dealloc
 {
+    ASSERT(browsingContextControllerMap().get(_page.get()) == self);
+    browsingContextControllerMap().remove(_page.get());
+
     _page->pageLoadState().removeObserver(*_pageLoadStateObserver);
-    _page->~WebPageProxy();
 
     [_remoteObjectRegistry _invalidate];
 
@@ -785,12 +794,6 @@ static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext,
     return YES;
 }
 
-#pragma mark WKObject protocol implementation
-
-- (API::Object&)_apiObject
-{
-    return *reinterpret_cast<API::Object*>(&_page);
-}
 
 - (instancetype)_initWithPageRef:(WKPageRef)pageRef
 {
@@ -802,12 +805,15 @@ static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext,
     _pageLoadStateObserver = std::make_unique<PageLoadStateObserver>(self);
     _page->pageLoadState().addObserver(*_pageLoadStateObserver);
 
+    ASSERT(!browsingContextControllerMap().contains(_page.get()));
+    browsingContextControllerMap().set(_page.get(), self);
+
     return self;
 }
 
 + (WKBrowsingContextController *)_browsingContextControllerForPageRef:(WKPageRef)pageRef
 {
-    return (WKBrowsingContextController *)static_cast<const WebLoaderClient*>(WebKit::toImpl(pageRef)->loaderClient())->client().base.clientInfo;
+    return browsingContextControllerMap().get(toImpl(pageRef));
 }
 
 @end
index cb36164..0271f5c 100644 (file)
 
 #if WK_API_ENABLED
 
-#import "WKObject.h"
 #import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
 
-@interface WKBrowsingContextController () <WKObject> {
+@interface WKBrowsingContextController () {
 @package
     WebKit::WeakObjCPtr<id <WKBrowsingContextHistoryDelegate>> _historyDelegate;
 }
index 0fab646..7abb26f 100644 (file)
@@ -834,8 +834,6 @@ public:
     void endColorPicker();
 #endif
 
-    const API::LoaderClient* loaderClient() { return m_loaderClient.get(); }
-
     WebCore::IntSize minimumLayoutSize() const { return m_minimumLayoutSize; }
     void setMinimumLayoutSize(const WebCore::IntSize&);