Title: [254862] trunk/Source/WebKit
Revision
254862
Author
[email protected]
Date
2020-01-21 10:42:40 -0800 (Tue, 21 Jan 2020)

Log Message

API::(User)ContentWorld cleanup
https://bugs.webkit.org/show_bug.cgi?id=206509

Reviewed by Darin Adler.

No behavior change.

- Give (User)ContentWorld a shared base class for upcoming work.
- Reference them by identifier instead of object instance whenever possible.
- Other shared class cleanup.

* UIProcess/API/APIContentWorld.cpp:
(API::ContentWorldBase::generateIdentifier):
(API::ContentWorld::ContentWorld):
(API::ContentWorld::~ContentWorld):
* UIProcess/API/APIContentWorld.h:
(API::ContentWorldBase::identifier const):
(API::ContentWorldBase::name const):
(API::ContentWorldBase::worldData const):
(API::ContentWorldBase::ContentWorldBase):
* UIProcess/API/APIUserContentWorld.cpp:
(API::UserContentWorld::UserContentWorld):
(API::UserContentWorld::generateIdentifier): Deleted.
* UIProcess/API/APIUserContentWorld.h:
* UIProcess/UserContent/WebScriptMessageHandler.h:
(WebKit::WebScriptMessageHandler::world):
(WebKit::WebScriptMessageHandler::userContentWorld const): Deleted.
(WebKit::WebScriptMessageHandler::userContentWorld): Deleted.
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserContentWorldUse):
(WebKit::WebUserContentControllerProxy::shouldSendRemoveUserContentWorldsMessage):
(WebKit::WebUserContentControllerProxy::addUserScriptMessageHandler):
(WebKit::WebUserContentControllerProxy::removeUserMessageHandlerForName):
(WebKit::WebUserContentControllerProxy::removeAllUserMessageHandlers):
* UIProcess/UserContent/WebUserContentControllerProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (254861 => 254862)


--- trunk/Source/WebKit/ChangeLog	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/ChangeLog	2020-01-21 18:42:40 UTC (rev 254862)
@@ -1,3 +1,42 @@
+2020-01-21  Brady Eidson  <[email protected]>
+
+        API::(User)ContentWorld cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=206509
+
+        Reviewed by Darin Adler.
+
+        No behavior change.
+        
+        - Give (User)ContentWorld a shared base class for upcoming work.
+        - Reference them by identifier instead of object instance whenever possible.
+        - Other shared class cleanup.
+
+        * UIProcess/API/APIContentWorld.cpp:
+        (API::ContentWorldBase::generateIdentifier):
+        (API::ContentWorld::ContentWorld):
+        (API::ContentWorld::~ContentWorld):
+        * UIProcess/API/APIContentWorld.h:
+        (API::ContentWorldBase::identifier const):
+        (API::ContentWorldBase::name const):
+        (API::ContentWorldBase::worldData const):
+        (API::ContentWorldBase::ContentWorldBase):
+        * UIProcess/API/APIUserContentWorld.cpp:
+        (API::UserContentWorld::UserContentWorld):
+        (API::UserContentWorld::generateIdentifier): Deleted.
+        * UIProcess/API/APIUserContentWorld.h:
+        * UIProcess/UserContent/WebScriptMessageHandler.h:
+        (WebKit::WebScriptMessageHandler::world):
+        (WebKit::WebScriptMessageHandler::userContentWorld const): Deleted.
+        (WebKit::WebScriptMessageHandler::userContentWorld): Deleted.
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+        (WebKit::WebUserContentControllerProxy::addProcess):
+        (WebKit::WebUserContentControllerProxy::addUserContentWorldUse):
+        (WebKit::WebUserContentControllerProxy::shouldSendRemoveUserContentWorldsMessage):
+        (WebKit::WebUserContentControllerProxy::addUserScriptMessageHandler):
+        (WebKit::WebUserContentControllerProxy::removeUserMessageHandlerForName):
+        (WebKit::WebUserContentControllerProxy::removeAllUserMessageHandlers):
+        * UIProcess/UserContent/WebUserContentControllerProxy.h:
+
 2020-01-21  Chris Dumez  <[email protected]>
 
         Minor improvements to StorageAreaMap

Modified: trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp	2020-01-21 18:42:40 UTC (rev 254862)
@@ -33,6 +33,13 @@
 
 namespace API {
 
+uint64_t ContentWorldBase::generateIdentifier()
+{
+    static uint64_t identifier = WebKit::pageContentWorldIdentifier;
+
+    return ++identifier;
+}
+
 static HashMap<WTF::String, ContentWorld*>& sharedWorldMap()
 {
     static HashMap<WTF::String, ContentWorld*>* sharedMap = new HashMap<WTF::String, ContentWorld*>;
@@ -58,27 +65,26 @@
 
 ContentWorld& ContentWorld::defaultClientWorld()
 {
-    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(API::UserContentWorld::generateIdentifier())));
+    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(generateIdentifier())));
     return *world.get();
 }
 
 ContentWorld::ContentWorld(const WTF::String& name)
-    : m_identifier(API::UserContentWorld::generateIdentifier())
-    , m_name(name)
+    : ContentWorldBase(name)
 {
 }
 
 ContentWorld::ContentWorld(uint64_t identifier)
-    : m_identifier(identifier)
+    : ContentWorldBase(identifier)
 {
 }
 
 ContentWorld::~ContentWorld()
 {
-    if (m_name.isNull())
+    if (name().isNull())
         return;
 
-    auto taken = sharedWorldMap().take(m_name);
+    auto taken = sharedWorldMap().take(name());
     ASSERT_UNUSED(taken, taken == this);
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/APIContentWorld.h (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/API/APIContentWorld.h	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/API/APIContentWorld.h	2020-01-21 18:42:40 UTC (rev 254862)
@@ -30,26 +30,51 @@
 
 namespace API {
 
-class ContentWorld final : public API::ObjectImpl<API::Object::Type::ContentWorld> {
+class ContentWorldBase {
 public:
-    static Ref<ContentWorld> sharedWorldWithName(const WTF::String&);
-    static ContentWorld& pageContentWorld();
-    static ContentWorld& defaultClientWorld();
+    virtual ~ContentWorldBase() = default;
 
-    virtual ~ContentWorld();
-
+    uint64_t identifier() const { return m_identifier; }
     const WTF::String& name() const { return m_name; }
-    uint64_t identifier() const { return m_identifier; }
+    std::pair<uint64_t, WTF::String> worldData() const { return { identifier(), name() }; }
 
-    std::pair<uint64_t, WTF::String> worldData() { return { m_identifier, m_name }; }
+    virtual void ref() const = 0;
+    virtual void deref() const = 0;
 
+    static uint64_t generateIdentifier();
+
+protected:
+    ContentWorldBase(const WTF::String& name)
+        : m_identifier(generateIdentifier())
+        , m_name(name)
+    {
+    }
+
+    ContentWorldBase(uint64_t identifier)
+        : m_identifier(identifier)
+    {
+    }
+
 private:
-    ContentWorld(const WTF::String&);
-    ContentWorld(uint64_t identifier);
-
     // FIXME: This should be an ObjectIdentifier once we can get all ScriptWorld related classes to use ObjectIdentifier.
     uint64_t m_identifier;
     WTF::String m_name;
 };
 
+class ContentWorld final : public API::ObjectImpl<API::Object::Type::ContentWorld>, public ContentWorldBase {
+public:
+    static Ref<ContentWorld> sharedWorldWithName(const WTF::String&);
+    static ContentWorld& pageContentWorld();
+    static ContentWorld& defaultClientWorld();
+
+    virtual ~ContentWorld();
+
+    void ref() const final { ObjectImpl::ref(); }
+    void deref() const final { ObjectImpl::deref(); }
+
+private:
+    explicit ContentWorld(const WTF::String&);
+    explicit ContentWorld(uint64_t identifier);
+};
+
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp	2020-01-21 18:42:40 UTC (rev 254862)
@@ -30,13 +30,6 @@
 
 namespace API {
 
-uint64_t UserContentWorld::generateIdentifier()
-{
-    static uint64_t identifier = WebKit::pageContentWorldIdentifier;
-
-    return ++identifier;
-}
-
 Ref<UserContentWorld> UserContentWorld::worldWithName(const WTF::String& name)
 {
     return adoptRef(*new UserContentWorld(name));
@@ -49,13 +42,12 @@
 }
 
 UserContentWorld::UserContentWorld(const WTF::String& name)
-    : m_identifier(generateIdentifier())
-    , m_name(name)
+    : ContentWorldBase(name)
 {
 }
 
 UserContentWorld::UserContentWorld(ForNormalWorldOnly)
-    : m_identifier(WebKit::pageContentWorldIdentifier)
+    : ContentWorldBase(WebKit::pageContentWorldIdentifier)
 {
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.h (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.h	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.h	2020-01-21 18:42:40 UTC (rev 254862)
@@ -23,17 +23,14 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef APIUserContentWorld_h
-#define APIUserContentWorld_h
+#pragma once
 
-#include "APIObject.h"
+#include "APIContentWorld.h"
 #include <wtf/text/WTFString.h>
 
 namespace API {
 
-class ContentWorld;
-
-class UserContentWorld final : public API::ObjectImpl<API::Object::Type::UserContentWorld> {
+class UserContentWorld final : public API::ObjectImpl<API::Object::Type::UserContentWorld>, public ContentWorldBase {
 public:
     static Ref<UserContentWorld> worldWithName(const WTF::String&);
     static UserContentWorld& normalWorld();
@@ -40,23 +37,15 @@
 
     virtual ~UserContentWorld();
 
-    const WTF::String& name() const { return m_name; }
-    uint64_t identifier() const { return m_identifier; }
+    void ref() const final { ObjectImpl::ref(); }
+    void deref() const final { ObjectImpl::deref(); }
 
 private:
-    friend class ContentWorld;
+    explicit UserContentWorld(const WTF::String&);
 
-    UserContentWorld(const WTF::String&);
-
     enum class ForNormalWorldOnly { NormalWorld };
-    UserContentWorld(ForNormalWorldOnly);
+    explicit UserContentWorld(ForNormalWorldOnly);
 
-    static uint64_t generateIdentifier();
-
-    uint64_t m_identifier;
-    WTF::String m_name;
 };
 
 } // namespace API
-
-#endif // APIUserContentWorld_h

Modified: trunk/Source/WebKit/UIProcess/UserContent/WebScriptMessageHandler.h (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/UserContent/WebScriptMessageHandler.h	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebScriptMessageHandler.h	2020-01-21 18:42:40 UTC (rev 254862)
@@ -23,9 +23,9 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebScriptMessageHandler_h
-#define WebScriptMessageHandler_h
+#pragma once
 
+#include "APIUserContentWorld.h"
 #include "WebUserContentControllerDataTypes.h"
 #include <wtf/Identified.h>
 #include <wtf/Ref.h>
@@ -60,8 +60,7 @@
 
     String name() const { return m_name; }
 
-    const API::UserContentWorld& userContentWorld() const { return m_world; }
-    API::UserContentWorld& userContentWorld() { return m_world; }
+    API::ContentWorldBase& world() { return m_world.get(); }
 
     Client& client() const { return *m_client; }
 
@@ -74,5 +73,3 @@
 };
 
 } // namespace API
-    
-#endif // WebScriptMessageHandler_h

Modified: trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp	2020-01-21 18:42:40 UTC (rev 254862)
@@ -105,8 +105,8 @@
         webProcessProxy.addMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier(), *this);
 
     ASSERT(parameters.userContentWorlds.isEmpty());
-    for (const auto& world : m_userContentWorlds)
-        parameters.userContentWorlds.append(std::make_pair(world.key->identifier(), world.key->name()));
+    for (const auto& world : m_contentWorlds)
+        parameters.userContentWorlds.append(world.key->worldData());
 
     ASSERT(parameters.userScripts.isEmpty());
     for (auto userScript : m_userScripts->elementsOfType<API::UserScript>())
@@ -118,7 +118,7 @@
 
     ASSERT(parameters.messageHandlers.isEmpty());
     for (auto& handler : m_scriptMessageHandlers.values())
-        parameters.messageHandlers.append({ handler->identifier(), handler->userContentWorld().identifier(), handler->name() });
+        parameters.messageHandlers.append({ handler->identifier(), handler->world().identifier(), handler->name() });
 
 #if ENABLE(CONTENT_EXTENSIONS)
     ASSERT(parameters.contentRuleLists.isEmpty());
@@ -146,15 +146,15 @@
     webProcessProxy.removeMessageReceiver(Messages::WebUserContentControllerProxy::messageReceiverName(), identifier());
 }
 
-void WebUserContentControllerProxy::addUserContentWorldUse(API::UserContentWorld& world)
+void WebUserContentControllerProxy::addUserContentWorldUse(API::ContentWorldBase& world)
 {
     if (&world == &API::UserContentWorld::normalWorld())
         return;
 
-    auto addResult = m_userContentWorlds.add(&world);
+    auto addResult = m_contentWorlds.add(&world);
     if (addResult.isNewEntry) {
         for (auto& process : m_processes)
-            process.send(Messages::WebUserContentController::AddUserContentWorlds({ std::make_pair(world.identifier(), world.name()) }), identifier());
+            process.send(Messages::WebUserContentController::AddUserContentWorlds({ world.worldData() }), identifier());
     }
 }
 
@@ -163,9 +163,9 @@
     if (&world == &API::UserContentWorld::normalWorld())
         return false;
 
-    auto it = m_userContentWorlds.find(&world);
+    auto it = m_contentWorlds.find(&world);
     for (unsigned i = 0; i < numberOfUsesToRemove; ++i) {
-        if (m_userContentWorlds.remove(it)) {
+        if (m_contentWorlds.remove(it)) {
             ASSERT(i == (numberOfUsesToRemove - 1));
             return true;
         }
@@ -306,19 +306,19 @@
 
 bool WebUserContentControllerProxy::addUserScriptMessageHandler(WebScriptMessageHandler& handler)
 {
-    Ref<API::UserContentWorld> world = handler.userContentWorld();
+    auto& world = handler.world();
 
     for (auto& existingHandler : m_scriptMessageHandlers.values()) {
-        if (existingHandler->name() == handler.name() && &existingHandler->userContentWorld() == world.ptr())
+        if (existingHandler->name() == handler.name() && existingHandler->world().identifier() == world.identifier())
             return false;
     }
 
-    addUserContentWorldUse(world.get());
+    addUserContentWorldUse(world);
 
     m_scriptMessageHandlers.add(handler.identifier(), &handler);
 
     for (auto& process : m_processes)
-        process.send(Messages::WebUserContentController::AddUserScriptMessageHandlers({ { handler.identifier(), world->identifier(), handler.name() } }), identifier());
+        process.send(Messages::WebUserContentController::AddUserScriptMessageHandlers({ { handler.identifier(), world.identifier(), handler.name() } }), identifier());
     
     return true;
 }
@@ -326,7 +326,7 @@
 void WebUserContentControllerProxy::removeUserMessageHandlerForName(const String& name, API::UserContentWorld& world)
 {
     for (auto it = m_scriptMessageHandlers.begin(), end = m_scriptMessageHandlers.end(); it != end; ++it) {
-        if (it->value->name() == name && &it->value->userContentWorld() == &world) {
+        if (it->value->name() == name && it->value->world().identifier() == world.identifier()) {
             for (auto& process : m_processes)
                 process.send(Messages::WebUserContentController::RemoveUserScriptMessageHandler(world.identifier(), it->value->identifier()), identifier());
 
@@ -345,7 +345,7 @@
 
     unsigned numberRemoved = 0;
     m_scriptMessageHandlers.removeIf([&](auto& entry) {
-        if (&entry.value->userContentWorld() == &world) {
+        if (entry.value->world().identifier() == world.identifier()) {
             ++numberRemoved;
             return true;
         }

Modified: trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h (254861 => 254862)


--- trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h	2020-01-21 18:28:17 UTC (rev 254861)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.h	2020-01-21 18:42:40 UTC (rev 254862)
@@ -41,7 +41,7 @@
 namespace API {
 class Array;
 class ContentRuleList;
-class ContentWorld;
+class ContentWorldBase;
 class UserContentWorld;
 class UserScript;
 class UserStyleSheet;
@@ -117,7 +117,7 @@
 
     void didPostMessage(IPC::Connection&, WebPageProxyIdentifier, FrameInfoData&&, uint64_t messageHandlerID, const IPC::DataReference&);
 
-    void addUserContentWorldUse(API::UserContentWorld&);
+    void addUserContentWorldUse(API::ContentWorldBase&);
     void removeUserContentWorldUses(API::UserContentWorld&, unsigned numberOfUsesToRemove);
     void removeUserContentWorldUses(HashCountedSet<RefPtr<API::UserContentWorld>>&);
     bool shouldSendRemoveUserContentWorldsMessage(API::UserContentWorld&, unsigned numberOfUsesToRemove);
@@ -127,7 +127,7 @@
     Ref<API::Array> m_userScripts;
     Ref<API::Array> m_userStyleSheets;
     HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers;
-    HashCountedSet<RefPtr<API::UserContentWorld>> m_userContentWorlds;
+    HashCountedSet<RefPtr<API::ContentWorldBase>> m_contentWorlds;
 
 #if ENABLE(CONTENT_EXTENSIONS)
     WeakHashSet<NetworkProcessProxy> m_networkProcesses;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to