Convert WebPreferences and VisitedLinkProvider to be bridged API::Objects
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 21:16:56 +0000 (21:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 21:16:56 +0000 (21:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141002

Patch by Sam Weinig <sam@webkit.org> on 2015-01-28
Reviewed by Tim Horton.

* Shared/API/APIObject.h:
Add VisitedLinkProvider type.

* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
Allocate WebPreferences and VisitedLinkProvider as their Objective-C counterpart.

* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences init]):
Switch to constructInWrapper.

(-[WKPreferences dealloc]):
Call the WebPreferences destructor.

(-[WKPreferences _apiObject]):
Add implementation of the WKObject protocol.

* UIProcess/API/Cocoa/WKPreferencesInternal.h:
Convert to using ObjectStorage.

* UIProcess/API/Cocoa/_WKVisitedLinkProvider.mm:
(-[_WKVisitedLinkProvider init]):
Switch to constructInWrapper.

(-[_WKVisitedLinkProvider dealloc]):
Call the VisitedLinkProvider destructor.

(-[_WKVisitedLinkProvider _apiObject]):
Add implementation of the WKObject protocol.

* UIProcess/API/Cocoa/_WKVisitedLinkProviderInternal.h:
Convert to using ObjectStorage.

* UIProcess/VisitedLinkProvider.cpp:
(WebKit::VisitedLinkProvider::create):
* UIProcess/VisitedLinkProvider.h:
Switch create() to return a Ref.

* UIProcess/WebPreferences.h:
Make the constructor public for use by constructInWrapper.

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::createWebPage):
* UIProcess/WebProcessPool.h:
Store the VisitedLinkProvider in a Ref.

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/APIObject.h
Source/WebKit2/Shared/Cocoa/APIObject.mm
Source/WebKit2/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit2/UIProcess/API/Cocoa/WKPreferencesInternal.h
Source/WebKit2/UIProcess/API/Cocoa/_WKVisitedLinkProvider.mm
Source/WebKit2/UIProcess/API/Cocoa/_WKVisitedLinkProviderInternal.h
Source/WebKit2/UIProcess/VisitedLinkProvider.cpp
Source/WebKit2/UIProcess/VisitedLinkProvider.h
Source/WebKit2/UIProcess/WebPreferences.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebProcessPool.h

index b86781a..8af3797 100644 (file)
@@ -1,3 +1,56 @@
+2015-01-28  Sam Weinig  <sam@webkit.org>
+
+        Convert WebPreferences and VisitedLinkProvider to be bridged API::Objects
+        https://bugs.webkit.org/show_bug.cgi?id=141002
+
+        Reviewed by Tim Horton.
+
+        * Shared/API/APIObject.h:
+        Add VisitedLinkProvider type.
+        
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+        Allocate WebPreferences and VisitedLinkProvider as their Objective-C counterpart.
+        
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences init]):
+        Switch to constructInWrapper.
+
+        (-[WKPreferences dealloc]):
+        Call the WebPreferences destructor.
+        
+        (-[WKPreferences _apiObject]):
+        Add implementation of the WKObject protocol.
+
+        * UIProcess/API/Cocoa/WKPreferencesInternal.h:
+        Convert to using ObjectStorage.
+
+        * UIProcess/API/Cocoa/_WKVisitedLinkProvider.mm:
+        (-[_WKVisitedLinkProvider init]):
+        Switch to constructInWrapper.
+
+        (-[_WKVisitedLinkProvider dealloc]):
+        Call the VisitedLinkProvider destructor.
+
+        (-[_WKVisitedLinkProvider _apiObject]):
+        Add implementation of the WKObject protocol.
+
+        * UIProcess/API/Cocoa/_WKVisitedLinkProviderInternal.h:
+        Convert to using ObjectStorage.
+
+        * UIProcess/VisitedLinkProvider.cpp:
+        (WebKit::VisitedLinkProvider::create):
+        * UIProcess/VisitedLinkProvider.h:
+        Switch create() to return a Ref.
+
+        * UIProcess/WebPreferences.h:
+        Make the constructor public for use by constructInWrapper.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::createWebPage):
+        * UIProcess/WebProcessPool.h:
+        Store the VisitedLinkProvider in a Ref.
+
 2015-01-28  Dana Burkart  <dburkart@apple.com>
 
         Move ASan flag settings from DebugRelease.xcconfig to Base.xcconfig
index c5dfd34..63448ca 100644 (file)
@@ -141,6 +141,7 @@ public:
         UserMediaPermissionRequest,
         Vibration,
         ViewportAttributes,
+        VisitedLinkProvider,
         WebsiteDataStore,
 
         // Bundle types
index 81f6892..ed55065 100644 (file)
@@ -43,6 +43,7 @@
 #import "WKNSURLRequest.h"
 #import "WKNavigationDataInternal.h"
 #import "WKNavigationInternal.h"
+#import "WKPreferencesInternal.h"
 #import "WKProcessPoolInternal.h"
 #import "WKUserContentControllerInternal.h"
 #import "WKUserScriptInternal.h"
@@ -56,6 +57,7 @@
 #import "_WKDownloadInternal.h"
 #import "_WKFrameHandleInternal.h"
 #import "_WKProcessPoolConfigurationInternal.h"
+#import "_WKVisitedLinkProviderInternal.h"
 #import "_WKWebsiteDataStoreInternal.h"
 #import <objc/objc-auto.h>
 
@@ -108,6 +110,10 @@ void* Object::newObject(size_t size, Type type)
         wrapper = NSAllocateObject([WKConnection self], size, nullptr);
         break;
 
+    case Type::Preferences:
+        wrapper = [WKPreferences alloc];
+        break;
+
     case Type::ProcessPool:
         wrapper = [WKProcessPool alloc];
         break;
@@ -168,6 +174,10 @@ void* Object::newObject(size_t size, Type type)
         wrapper = [WKUserScript alloc];
         break;
 
+    case Type::VisitedLinkProvider:
+        wrapper = [_WKVisitedLinkProvider alloc];
+        break;
+
     case Type::WebsiteDataStore:
         wrapper = [_WKWebsiteDataStore alloc];
         break;
index ebe098b..6f4cf78 100644 (file)
     if (!(self = [super init]))
         return nil;
 
-    _preferences = WebKit::WebPreferences::create(String(), "WebKit", "WebKit");
+    API::Object::constructInWrapper<WebKit::WebPreferences>(self, String(), "WebKit", "WebKit");
     return self;
 }
 
+- (void)dealloc
+{
+    _preferences->~WebPreferences();
+
+    [super dealloc];
+}
+
 - (CGFloat)minimumFontSize
 {
     return _preferences->minimumFontSize();
 
 #endif
 
+#pragma mark WKObject protocol implementation
+
+- (API::Object&)_apiObject
+{
+    return *_preferences;
+}
+
 @end
 
 @implementation WKPreferences (WKPrivate)
index 0c804e7..20733f4 100644 (file)
 
 #if WK_API_ENABLED
 
-#import <wtf/RefPtr.h>
+#import "WKObject.h"
+#import "WebPreferences.h"
 
 namespace WebKit {
-class WebPreferences;
+
+inline WKPreferences *wrapper(WebPreferences& preferences)
+{
+    ASSERT([preferences.wrapper() isKindOfClass:[WKPreferences class]]);
+    return (WKPreferences *)preferences.wrapper();
+}
+
 }
 
-@interface WKPreferences () {
+@interface WKPreferences () <WKObject> {
 @package
-    RefPtr<WebKit::WebPreferences> _preferences;
+    API::ObjectStorage<WebKit::WebPreferences> _preferences;
 }
 
 @end
index e65c9ac..dd6a791 100644 (file)
     if (!(self = [super init]))
         return nil;
 
-    _visitedLinkProvider = WebKit::VisitedLinkProvider::create();
+    API::Object::constructInWrapper<WebKit::VisitedLinkProvider>(self);
 
     return self;
 }
 
+- (void)dealloc
+{
+    _visitedLinkProvider->~VisitedLinkProvider();
+
+    [super dealloc];
+}
+
 - (void)addVisitedLinkWithURL:(NSURL *)URL
 {
     auto linkHash = WebCore::visitedLinkHash(URL.absoluteString);
     _visitedLinkProvider->removeAll();
 }
 
+#pragma mark WKObject protocol implementation
+
+- (API::Object&)_apiObject
+{
+    return *_visitedLinkProvider;
+}
+
 @end
 
 #endif
index 001072b..693610c 100644 (file)
 
 #if WK_API_ENABLED
 
-#import <wtf/RefPtr.h>
+#import "VisitedLinkProvider.h"
+#import "WKObject.h"
 
 namespace WebKit {
-class VisitedLinkProvider;
+
+inline _WKVisitedLinkProvider *wrapper(VisitedLinkProvider& visitedLinkProvider)
+{
+    ASSERT([visitedLinkProvider.wrapper() isKindOfClass:[_WKVisitedLinkProvider class]]);
+    return (_WKVisitedLinkProvider *)visitedLinkProvider.wrapper();
+}
+
 }
 
-@interface _WKVisitedLinkProvider () {
+@interface _WKVisitedLinkProvider () <WKObject> {
 @package
-    RefPtr<WebKit::VisitedLinkProvider> _visitedLinkProvider;
+    API::ObjectStorage<WebKit::VisitedLinkProvider> _visitedLinkProvider;
 }
 
 @end
index 6675295..f8ce9c3 100644 (file)
@@ -47,9 +47,9 @@ static uint64_t generateIdentifier()
     return ++identifier;
 }
 
-PassRefPtr<VisitedLinkProvider> VisitedLinkProvider::create()
+Ref<VisitedLinkProvider> VisitedLinkProvider::create()
 {
-    return adoptRef(new VisitedLinkProvider);
+    return adoptRef(*new VisitedLinkProvider);
 }
 
 VisitedLinkProvider::~VisitedLinkProvider()
index d1a9356..9bf5669 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef VisitedLinkProvider_h
 #define VisitedLinkProvider_h
 
+#include "APIObject.h"
 #include "MessageReceiver.h"
 #include "VisitedLinkTable.h"
 #include "WebProcessLifetimeObserver.h"
@@ -40,10 +41,12 @@ namespace WebKit {
 class WebPageProxy;
 class WebProcessProxy;
     
-class VisitedLinkProvider : public RefCounted<VisitedLinkProvider>, private IPC::MessageReceiver, public WebProcessLifetimeObserver {
+class VisitedLinkProvider final : public API::ObjectImpl<API::Object::Type::VisitedLinkProvider>, private IPC::MessageReceiver, public WebProcessLifetimeObserver {
 public:
-    static PassRefPtr<VisitedLinkProvider> create();
-    ~VisitedLinkProvider();
+    static Ref<VisitedLinkProvider> create();
+
+    explicit VisitedLinkProvider();
+    virtual ~VisitedLinkProvider();
 
     uint64_t identifier() const { return m_identifier; }
 
@@ -54,8 +57,6 @@ public:
     void removeAll();
 
 private:
-    VisitedLinkProvider();
-
     // IPC::MessageReceiver
     virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
 
index 90aa579..e95ef82 100644 (file)
@@ -47,6 +47,9 @@ public:
     static PassRefPtr<WebPreferences> create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
     static PassRefPtr<WebPreferences> createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
 
+    explicit WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
+    WebPreferences(const WebPreferences&);
+
     virtual ~WebPreferences();
 
     PassRefPtr<WebPreferences> copy() const;
@@ -71,9 +74,6 @@ public:
     static bool anyPagesAreUsingPrivateBrowsing();
 
 private:
-    explicit WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix);
-    WebPreferences(const WebPreferences&);
-
     void platformInitializeStore();
 
     void update();
index ccc99d7..86a6e20 100644 (file)
@@ -842,7 +842,7 @@ PassRefPtr<WebPageProxy> WebProcessPool::createWebPage(PageClient& pageClient, W
     if (!configuration.preferences)
         configuration.preferences = &configuration.pageGroup->preferences();
     if (!configuration.visitedLinkProvider)
-        configuration.visitedLinkProvider = m_visitedLinkProvider.get();
+        configuration.visitedLinkProvider = m_visitedLinkProvider.ptr();
     if (!configuration.websiteDataStore) {
         ASSERT(!configuration.sessionID.isValid());
         configuration.websiteDataStore = m_websiteDataStore.get();
index fe7f04e..a226c32 100644 (file)
@@ -202,7 +202,7 @@ public:
     void registerURLSchemeAsCachePartitioned(const String&);
 #endif
 
-    VisitedLinkProvider& visitedLinkProvider() { return *m_visitedLinkProvider; }
+    VisitedLinkProvider& visitedLinkProvider() { return m_visitedLinkProvider.get(); }
 
     void setCacheModel(CacheModel);
     CacheModel cacheModel() const { return m_cacheModel; }
@@ -442,7 +442,7 @@ private:
 #if ENABLE(NETSCAPE_PLUGIN_API)
     PluginInfoStore m_pluginInfoStore;
 #endif
-    RefPtr<VisitedLinkProvider> m_visitedLinkProvider;
+    Ref<VisitedLinkProvider> m_visitedLinkProvider;
     bool m_visitedLinksPopulated;
 
     PlugInAutoStartProvider m_plugInAutoStartProvider;