Title: [255127] trunk/Source
Revision
255127
Author
beid...@apple.com
Date
2020-01-25 21:43:29 -0800 (Sat, 25 Jan 2020)

Log Message

Make ContentWorlds be identified by an ObjectIdentifier instead of a uint64_t
https://bugs.webkit.org/show_bug.cgi?id=206784

Reviewed by Alex Christensen.

Source/WebKit:

Refactor: No behavior change.

* Scripts/webkit/messages.py:

* Shared/AuxiliaryProcess.cpp:
(WebKit::AuxiliaryProcess::initialize):

* Shared/ContentWorldShared.h:
(WebKit::pageContentWorldIdentifier):

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

* Shared/WebUserContentControllerDataTypes.cpp:
(WebKit::WebUserScriptData::decode):
(WebKit::WebUserStyleSheetData::decode):
(WebKit::WebScriptMessageHandlerData::decode):
* Shared/WebUserContentControllerDataTypes.h:

* UIProcess/API/APIContentWorld.cpp:
(API::ContentWorld::pageContentWorld):
(API::ContentWorld::defaultClientWorld):
(API::ContentWorld::ContentWorld):
(API::ContentWorldBase::generateIdentifier): Deleted.

* UIProcess/API/APIContentWorld.h:
(API::ContentWorldBase::identifier const):
(API::ContentWorldBase::worldData const):
(API::ContentWorldBase::ContentWorldBase):
* UIProcess/API/APIUserContentWorld.cpp:
(API::UserContentWorld::UserContentWorld):

* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::removeUserContentWorldUses):
(WebKit::WebUserContentControllerProxy::removeAllUserScripts):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):

* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::worldMap):
(WebKit::WebUserContentController::worldForIdentifier):
(WebKit::WebUserContentController::addUserContentWorld):
(WebKit::WebUserContentController::addUserContentWorlds):
(WebKit::WebUserContentController::removeUserContentWorlds):
(WebKit::WebUserContentController::addUserScripts):
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeAllUserScripts):
(WebKit::WebUserContentController::addUserStyleSheets):
(WebKit::WebUserContentController::removeUserStyleSheet):
(WebKit::WebUserContentController::removeAllUserStyleSheets):
(WebKit::WebUserContentController::addUserScriptMessageHandlers):
(WebKit::WebUserContentController::removeUserScriptMessageHandler):
(WebKit::WebUserContentController::removeAllUserScriptMessageHandlers):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::runJavaScript):
(WebKit::WebPage::runJavaScriptInMainFrameScriptWorld):
(WebKit::WebPage::runJavaScriptInFrame):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WTF:

* wtf/ObjectIdentifier.h:
(WTF::ObjectIdentifier::generate):
(WTF::ObjectIdentifier::generateThreadSafe):
(WTF::ObjectIdentifier::enableGenerationProtection): To allow restricting generating an identifier to the UIProcess.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (255126 => 255127)


--- trunk/Source/WTF/ChangeLog	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WTF/ChangeLog	2020-01-26 05:43:29 UTC (rev 255127)
@@ -1,3 +1,15 @@
+2020-01-25  Brady Eidson  <beid...@apple.com>
+
+        Make ContentWorlds be identified by an ObjectIdentifier instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=206784
+
+        Reviewed by Alex Christensen.
+
+        * wtf/ObjectIdentifier.h:
+        (WTF::ObjectIdentifier::generate):
+        (WTF::ObjectIdentifier::generateThreadSafe):
+        (WTF::ObjectIdentifier::enableGenerationProtection): To allow restricting generating an identifier to the UIProcess.
+
 2020-01-25  Mark Lam  <mark....@apple.com>
 
         Introduce a getVTablePointer() utility function.

Modified: trunk/Source/WTF/wtf/ObjectIdentifier.h (255126 => 255127)


--- trunk/Source/WTF/wtf/ObjectIdentifier.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WTF/wtf/ObjectIdentifier.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -44,14 +44,21 @@
 public:
     static ObjectIdentifier generate()
     {
+        RELEASE_ASSERT(!m_generationProtected);
         return ObjectIdentifier { generateIdentifierInternal() };
     }
 
     static ObjectIdentifier generateThreadSafe()
     {
+        RELEASE_ASSERT(!m_generationProtected);
         return ObjectIdentifier { generateThreadSafeIdentifierInternal() };
     }
 
+    static void enableGenerationProtection()
+    {
+        m_generationProtected = true;
+    }
+
     ObjectIdentifier() = default;
 
     ObjectIdentifier(HashTableDeletedValueType) : m_identifier(hashTableDeletedValue()) { }
@@ -103,6 +110,7 @@
     }
 
     uint64_t m_identifier { 0 };
+    inline static bool m_generationProtected { false };
 };
 
 template<typename T> inline ObjectIdentifier<T> makeObjectIdentifier(uint64_t identifier)

Modified: trunk/Source/WebKit/ChangeLog (255126 => 255127)


--- trunk/Source/WebKit/ChangeLog	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/ChangeLog	2020-01-26 05:43:29 UTC (rev 255127)
@@ -1,3 +1,73 @@
+2020-01-25  Brady Eidson  <beid...@apple.com>
+
+        Make ContentWorlds be identified by an ObjectIdentifier instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=206784
+
+        Reviewed by Alex Christensen.
+
+        Refactor: No behavior change.
+
+        * Scripts/webkit/messages.py:
+
+        * Shared/AuxiliaryProcess.cpp:
+        (WebKit::AuxiliaryProcess::initialize):
+
+        * Shared/ContentWorldShared.h:
+        (WebKit::pageContentWorldIdentifier):
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+
+        * Shared/WebUserContentControllerDataTypes.cpp:
+        (WebKit::WebUserScriptData::decode):
+        (WebKit::WebUserStyleSheetData::decode):
+        (WebKit::WebScriptMessageHandlerData::decode):
+        * Shared/WebUserContentControllerDataTypes.h:
+
+        * UIProcess/API/APIContentWorld.cpp:
+        (API::ContentWorld::pageContentWorld):
+        (API::ContentWorld::defaultClientWorld):
+        (API::ContentWorld::ContentWorld):
+        (API::ContentWorldBase::generateIdentifier): Deleted.
+
+        * UIProcess/API/APIContentWorld.h:
+        (API::ContentWorldBase::identifier const):
+        (API::ContentWorldBase::worldData const):
+        (API::ContentWorldBase::ContentWorldBase):
+        * UIProcess/API/APIUserContentWorld.cpp:
+        (API::UserContentWorld::UserContentWorld):
+
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+        (WebKit::WebUserContentControllerProxy::removeUserContentWorldUses):
+        (WebKit::WebUserContentControllerProxy::removeAllUserScripts):
+        (WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):
+
+        * WebProcess/UserContent/WebUserContentController.cpp:
+        (WebKit::worldMap):
+        (WebKit::WebUserContentController::worldForIdentifier):
+        (WebKit::WebUserContentController::addUserContentWorld):
+        (WebKit::WebUserContentController::addUserContentWorlds):
+        (WebKit::WebUserContentController::removeUserContentWorlds):
+        (WebKit::WebUserContentController::addUserScripts):
+        (WebKit::WebUserContentController::removeUserScript):
+        (WebKit::WebUserContentController::removeAllUserScripts):
+        (WebKit::WebUserContentController::addUserStyleSheets):
+        (WebKit::WebUserContentController::removeUserStyleSheet):
+        (WebKit::WebUserContentController::removeAllUserStyleSheets):
+        (WebKit::WebUserContentController::addUserScriptMessageHandlers):
+        (WebKit::WebUserContentController::removeUserScriptMessageHandler):
+        (WebKit::WebUserContentController::removeAllUserScriptMessageHandlers):
+        * WebProcess/UserContent/WebUserContentController.h:
+        * WebProcess/UserContent/WebUserContentController.messages.in:
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::runJavaScript):
+        (WebKit::WebPage::runJavaScriptInMainFrameScriptWorld):
+        (WebKit::WebPage::runJavaScriptInFrame):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2020-01-25  Per Arne Vollan  <pvol...@apple.com>
 
         [Cocoa] Media mime types map should be created in the UI process

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (255126 => 255127)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2020-01-26 05:43:29 UTC (rev 255127)
@@ -219,6 +219,7 @@
         'WebCore::SWServerConnectionIdentifier',
         'WebKit::ActivityStateChangeID',
         'WebKit::AudioMediaStreamTrackRendererIdentifier',
+        'WebKit::ContentWorldIdentifier',
         'WebKit::LayerHostingContextID',
         'WebKit::MediaPlayerPrivateRemoteIdentifier',
         'WebKit::MediaRecorderIdentifier',
@@ -605,6 +606,7 @@
         'WebCore::SelectionRect': ['"EditorState.h"'],
         'WebKit::ActivityStateChangeID': ['"DrawingAreaInfo.h"'],
         'WebKit::BackForwardListItemState': ['"SessionState.h"'],
+        'WebKit::ContentWorldIdentifier' : ['"ContentWorldShared.h"'],
         'WebKit::LayerHostingContextID': ['"LayerHostingContext.h"'],
         'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'],
         'WebKit::PageState': ['"SessionState.h"'],

Modified: trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp (255126 => 255127)


--- trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "AuxiliaryProcess.h"
 
+#include "ContentWorldShared.h"
 #include "DependencyProcessAssertion.h"
 #include "Logging.h"
 #include "SandboxInitializationParameters.h"
@@ -78,8 +79,9 @@
 
     initializeProcessName(parameters);
 
-    // In WebKit2, only the UI process should ever be generating non-default PAL::SessionIDs.
+    // In WebKit2, only the UI process should ever be generating certain identifiers.
     PAL::SessionID::enableGenerationProtection();
+    ContentWorldIdentifier::enableGenerationProtection();
 
     m_connection = IPC::Connection::createClientConnection(parameters.connectionIdentifier, *this);
     initializeConnection(m_connection.get());

Modified: trunk/Source/WebKit/Shared/ContentWorldShared.h (255126 => 255127)


--- trunk/Source/WebKit/Shared/ContentWorldShared.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/ContentWorldShared.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -25,8 +25,17 @@
 
 #pragma once
 
+#include <wtf/ObjectIdentifier.h>
+
 namespace WebKit {
 
-static const uint64_t pageContentWorldIdentifier = 1;
+enum ContentWorldIdentifierType { };
+using ContentWorldIdentifier = ObjectIdentifier<ContentWorldIdentifierType>;
 
+inline ContentWorldIdentifier pageContentWorldIdentifier()
+{
+    static NeverDestroyed<ContentWorldIdentifier> identifier(makeObjectIdentifier<ContentWorldIdentifierType>(1));
+    return identifier;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp (255126 => 255127)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -370,7 +370,7 @@
     if (!decoder.decode(parameters.enumeratingAllNetworkInterfacesEnabled))
         return WTF::nullopt;
 
-    Optional<Vector<std::pair<uint64_t, String>>> userContentWorlds;
+    Optional<Vector<std::pair<ContentWorldIdentifier, String>>> userContentWorlds;
     decoder >> userContentWorlds;
     if (!userContentWorlds)
         return WTF::nullopt;

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.h (255126 => 255127)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -193,7 +193,7 @@
     bool enumeratingAllNetworkInterfacesEnabled { false };
 
     // UserContentController members
-    Vector<std::pair<uint64_t, String>> userContentWorlds;
+    Vector<std::pair<ContentWorldIdentifier, String>> userContentWorlds;
     Vector<WebUserScriptData> userScripts;
     Vector<WebUserStyleSheetData> userStyleSheets;
     Vector<WebScriptMessageHandlerData> messageHandlers;

Modified: trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.cpp (255126 => 255127)


--- trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -44,7 +44,7 @@
     if (!identifier)
         return WTF::nullopt;
     
-    Optional<uint64_t> worldIdentifier;
+    Optional<ContentWorldIdentifier> worldIdentifier;
     decoder >> worldIdentifier;
     if (!worldIdentifier)
         return WTF::nullopt;
@@ -70,7 +70,7 @@
     if (!identifier)
         return WTF::nullopt;
     
-    Optional<uint64_t> worldIdentifier;
+    Optional<ContentWorldIdentifier> worldIdentifier;
     decoder >> worldIdentifier;
     if (!worldIdentifier)
         return WTF::nullopt;
@@ -97,7 +97,7 @@
     if (!identifier)
         return WTF::nullopt;
     
-    Optional<uint64_t> worldIdentifier;
+    Optional<ContentWorldIdentifier> worldIdentifier;
     decoder >> worldIdentifier;
     if (!worldIdentifier)
         return WTF::nullopt;

Modified: trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.h (255126 => 255127)


--- trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/Shared/WebUserContentControllerDataTypes.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "ContentWorldShared.h"
 #include <WebCore/UserScript.h>
 #include <WebCore/UserStyleSheet.h>
 
@@ -40,7 +41,7 @@
     static Optional<WebUserScriptData> decode(IPC::Decoder&);
 
     uint64_t identifier;
-    uint64_t worldIdentifier;
+    ContentWorldIdentifier worldIdentifier;
     WebCore::UserScript userScript;
 };
 
@@ -49,7 +50,7 @@
     static Optional<WebUserStyleSheetData> decode(IPC::Decoder&);
 
     uint64_t identifier;
-    uint64_t worldIdentifier;
+    ContentWorldIdentifier worldIdentifier;
     WebCore::UserStyleSheet userStyleSheet;
 };
 
@@ -58,7 +59,7 @@
     static Optional<WebScriptMessageHandlerData> decode(IPC::Decoder&);
 
     uint64_t identifier;
-    uint64_t worldIdentifier;
+    ContentWorldIdentifier worldIdentifier;
     String name;
 };
 

Modified: trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp (255126 => 255127)


--- trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/UIProcess/API/APIContentWorld.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -33,11 +33,18 @@
 
 namespace API {
 
-uint64_t ContentWorldBase::generateIdentifier()
+ContentWorldBase::ContentWorldBase(const WTF::String& name)
+    : m_name(name)
 {
-    static uint64_t identifier = WebKit::pageContentWorldIdentifier;
+    static std::once_flag once;
+    std::call_once(once, [] {
+        // To make sure we don't use our shared pageContentWorld identifier for this
+        // content world we're about to make, burn through one identifier.
+        auto identifier = WebKit::ContentWorldIdentifier::generate();
+        ASSERT_UNUSED(identifier, identifier.toUInt64() >= WebKit::pageContentWorldIdentifier().toUInt64());
+    });
 
-    return ++identifier;
+    m_identifier = WebKit::ContentWorldIdentifier::generate();
 }
 
 static HashMap<WTF::String, ContentWorld*>& sharedWorldMap()
@@ -59,13 +66,13 @@
 
 ContentWorld& ContentWorld::pageContentWorld()
 {
-    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(WebKit::pageContentWorldIdentifier)));
+    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(WebKit::pageContentWorldIdentifier())));
     return *world.get();
 }
 
 ContentWorld& ContentWorld::defaultClientWorld()
 {
-    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(generateIdentifier())));
+    static NeverDestroyed<RefPtr<ContentWorld>> world(adoptRef(new ContentWorld(WTF::String { })));
     return *world.get();
 }
 
@@ -74,7 +81,7 @@
 {
 }
 
-ContentWorld::ContentWorld(uint64_t identifier)
+ContentWorld::ContentWorld(WebKit::ContentWorldIdentifier identifier)
     : ContentWorldBase(identifier)
 {
 }

Modified: trunk/Source/WebKit/UIProcess/API/APIContentWorld.h (255126 => 255127)


--- trunk/Source/WebKit/UIProcess/API/APIContentWorld.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/UIProcess/API/APIContentWorld.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIObject.h"
+#include "ContentWorldShared.h"
 #include <wtf/text/WTFString.h>
 
 namespace API {
@@ -34,30 +35,22 @@
 public:
     virtual ~ContentWorldBase() = default;
 
-    uint64_t identifier() const { return m_identifier; }
+    WebKit::ContentWorldIdentifier identifier() const { return m_identifier; }
     const WTF::String& name() const { return m_name; }
-    std::pair<uint64_t, WTF::String> worldData() const { return { identifier(), name() }; }
+    std::pair<WebKit::ContentWorldIdentifier, WTF::String> worldData() const { 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)
+    ContentWorldBase(const WTF::String& name);
+    ContentWorldBase(WebKit::ContentWorldIdentifier identifier)
         : m_identifier(identifier)
     {
     }
 
 private:
-    // FIXME: This should be an ObjectIdentifier once we can get all ScriptWorld related classes to use ObjectIdentifier.
-    uint64_t m_identifier;
+    WebKit::ContentWorldIdentifier m_identifier;
     WTF::String m_name;
 };
 
@@ -74,7 +67,7 @@
 
 private:
     explicit ContentWorld(const WTF::String&);
-    explicit ContentWorld(uint64_t identifier);
+    explicit ContentWorld(WebKit::ContentWorldIdentifier);
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp (255126 => 255127)


--- trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/UIProcess/API/APIUserContentWorld.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -47,7 +47,7 @@
 }
 
 UserContentWorld::UserContentWorld(ForNormalWorldOnly)
-    : ContentWorldBase(WebKit::pageContentWorldIdentifier)
+    : ContentWorldBase(WebKit::pageContentWorldIdentifier())
 {
 }
 

Modified: trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp (255126 => 255127)


--- trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/UIProcess/UserContent/WebUserContentControllerProxy.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -184,7 +184,7 @@
 
 void WebUserContentControllerProxy::removeUserContentWorldUses(HashCountedSet<RefPtr<API::UserContentWorld>>& worlds)
 {
-    Vector<uint64_t> worldsToRemove;
+    Vector<ContentWorldIdentifier> worldsToRemove;
     for (auto& worldUsePair : worlds) {
         if (shouldSendRemoveUserContentWorldsMessage(*worldUsePair.key.get(), worldUsePair.value))
             worldsToRemove.append(worldUsePair.key->identifier());
@@ -236,7 +236,7 @@
     for (auto userScript : m_userScripts->elementsOfType<API::UserScript>())
         worlds.add(const_cast<API::UserContentWorld*>(&userScript->userContentWorld()));
 
-    Vector<uint64_t> worldIdentifiers;
+    Vector<ContentWorldIdentifier> worldIdentifiers;
     worldIdentifiers.reserveInitialCapacity(worlds.size());
     for (const auto& worldCountPair : worlds)
         worldIdentifiers.uncheckedAppend(worldCountPair.key->identifier());
@@ -291,7 +291,7 @@
     for (auto userStyleSheet : m_userStyleSheets->elementsOfType<API::UserStyleSheet>())
         worlds.add(const_cast<API::UserContentWorld*>(&userStyleSheet->userContentWorld()));
 
-    Vector<uint64_t> worldIdentifiers;
+    Vector<ContentWorldIdentifier> worldIdentifiers;
     worldIdentifiers.reserveInitialCapacity(worlds.size());
     for (const auto& worldCountPair : worlds)
         worldIdentifiers.uncheckedAppend(worldCountPair.key->identifier());

Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -59,11 +59,11 @@
     return userContentControllers;
 }
 
-typedef HashMap<uint64_t, std::pair<RefPtr<InjectedBundleScriptWorld>, unsigned>> WorldMap;
+typedef HashMap<ContentWorldIdentifier, std::pair<RefPtr<InjectedBundleScriptWorld>, unsigned>> WorldMap;
 
 static WorldMap& worldMap()
 {
-    static NeverDestroyed<WorldMap> map(std::initializer_list<WorldMap::KeyValuePairType> { { WebUserContentController::identifierForNormalWorld(), std::make_pair(&InjectedBundleScriptWorld::normalWorld(), 1) } });
+    static NeverDestroyed<WorldMap> map(std::initializer_list<WorldMap::KeyValuePairType> { { pageContentWorldIdentifier(), std::make_pair(&InjectedBundleScriptWorld::normalWorld(), 1) } });
 
     return map;
 }
@@ -95,16 +95,16 @@
     userContentControllers().remove(m_identifier);
 }
 
-InjectedBundleScriptWorld* WebUserContentController::worldForIdentifier(uint64_t identifier)
+InjectedBundleScriptWorld* WebUserContentController::worldForIdentifier(ContentWorldIdentifier identifier)
 {
     auto iterator = worldMap().find(identifier);
     return iterator == worldMap().end() ? nullptr : iterator->value.first.get();
 }
 
-void WebUserContentController::addUserContentWorld(const std::pair<uint64_t, String>& world)
+void WebUserContentController::addUserContentWorld(const std::pair<ContentWorldIdentifier, String>& world)
 {
     ASSERT(world.first);
-    if (world.first == pageContentWorldIdentifier)
+    if (world.first == pageContentWorldIdentifier())
         return;
 
     worldMap().ensure(world.first, [&] {
@@ -113,27 +113,27 @@
         // use the existing world created by the web extension if any. The world name is used
         // as the identifier.
         if (auto* existingWorld = InjectedBundleScriptWorld::find(world.second))
-            return std::make_pair(Ref<InjectedBundleScriptWorld>(*existingWorld), pageContentWorldIdentifier);
+            return std::make_pair(Ref<InjectedBundleScriptWorld>(*existingWorld), 1);
 #endif
-        return std::make_pair(InjectedBundleScriptWorld::create(world.second), pageContentWorldIdentifier);
+        return std::make_pair(InjectedBundleScriptWorld::create(world.second), 1);
     });
 }
 
-void WebUserContentController::addUserContentWorlds(const Vector<std::pair<uint64_t, String>>& worlds)
+void WebUserContentController::addUserContentWorlds(const Vector<std::pair<ContentWorldIdentifier, String>>& worlds)
 {
     for (auto& world : worlds)
         addUserContentWorld(world);
 }
 
-void WebUserContentController::removeUserContentWorlds(const Vector<uint64_t>& worldIdentifiers)
+void WebUserContentController::removeUserContentWorlds(const Vector<ContentWorldIdentifier>& worldIdentifiers)
 {
     for (auto& worldIdentifier : worldIdentifiers) {
         ASSERT(worldIdentifier);
-        ASSERT(worldIdentifier != 1);
+        ASSERT(worldIdentifier != pageContentWorldIdentifier());
 
         auto it = worldMap().find(worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to remove a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+            WTFLogAlways("Trying to remove a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
             return;
         }
 
@@ -149,7 +149,7 @@
     for (const auto& userScriptData : userScripts) {
         auto it = worldMap().find(userScriptData.worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to add a UserScript to a UserContentWorld (id=%" PRIu64 ") that does not exist.", userScriptData.worldIdentifier);
+            WTFLogAlways("Trying to add a UserScript to a UserContentWorld (id=%" PRIu64 ") that does not exist.", userScriptData.worldIdentifier.toUInt64());
             continue;
         }
 
@@ -158,11 +158,11 @@
     }
 }
 
-void WebUserContentController::removeUserScript(uint64_t worldIdentifier, uint64_t userScriptIdentifier)
+void WebUserContentController::removeUserScript(ContentWorldIdentifier worldIdentifier, uint64_t userScriptIdentifier)
 {
     auto it = worldMap().find(worldIdentifier);
     if (it == worldMap().end()) {
-        WTFLogAlways("Trying to remove a UserScript from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+        WTFLogAlways("Trying to remove a UserScript from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
         return;
     }
 
@@ -169,12 +169,12 @@
     removeUserScriptInternal(*it->value.first, userScriptIdentifier);
 }
 
-void WebUserContentController::removeAllUserScripts(const Vector<uint64_t>& worldIdentifiers)
+void WebUserContentController::removeAllUserScripts(const Vector<ContentWorldIdentifier>& worldIdentifiers)
 {
     for (auto& worldIdentifier : worldIdentifiers) {
         auto it = worldMap().find(worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to remove all UserScripts from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+            WTFLogAlways("Trying to remove all UserScripts from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
             return;
         }
 
@@ -187,7 +187,7 @@
     for (const auto& userStyleSheetData : userStyleSheets) {
         auto it = worldMap().find(userStyleSheetData.worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to add a UserStyleSheet to a UserContentWorld (id=%" PRIu64 ") that does not exist.", userStyleSheetData.worldIdentifier);
+            WTFLogAlways("Trying to add a UserStyleSheet to a UserContentWorld (id=%" PRIu64 ") that does not exist.", userStyleSheetData.worldIdentifier.toUInt64());
             continue;
         }
         
@@ -198,11 +198,11 @@
     invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
 }
 
-void WebUserContentController::removeUserStyleSheet(uint64_t worldIdentifier, uint64_t userStyleSheetIdentifier)
+void WebUserContentController::removeUserStyleSheet(ContentWorldIdentifier worldIdentifier, uint64_t userStyleSheetIdentifier)
 {
     auto it = worldMap().find(worldIdentifier);
     if (it == worldMap().end()) {
-        WTFLogAlways("Trying to remove a UserStyleSheet from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+        WTFLogAlways("Trying to remove a UserStyleSheet from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
         return;
     }
 
@@ -209,13 +209,13 @@
     removeUserStyleSheetInternal(*it->value.first, userStyleSheetIdentifier);
 }
 
-void WebUserContentController::removeAllUserStyleSheets(const Vector<uint64_t>& worldIdentifiers)
+void WebUserContentController::removeAllUserStyleSheets(const Vector<ContentWorldIdentifier>& worldIdentifiers)
 {
     bool sheetsChanged = false;
     for (auto& worldIdentifier : worldIdentifiers) {
         auto it = worldMap().find(worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to remove all UserStyleSheets from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+            WTFLogAlways("Trying to remove all UserStyleSheets from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
             return;
         }
 
@@ -278,7 +278,7 @@
     for (auto& handler : scriptMessageHandlers) {
         auto it = worldMap().find(handler.worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to add a UserScriptMessageHandler to a UserContentWorld (id=%" PRIu64 ") that does not exist.", handler.worldIdentifier);
+            WTFLogAlways("Trying to add a UserScriptMessageHandler to a UserContentWorld (id=%" PRIu64 ") that does not exist.", handler.worldIdentifier.toUInt64());
             continue;
         }
 
@@ -289,12 +289,12 @@
 #endif
 }
 
-void WebUserContentController::removeUserScriptMessageHandler(uint64_t worldIdentifier, uint64_t userScriptMessageHandlerIdentifier)
+void WebUserContentController::removeUserScriptMessageHandler(ContentWorldIdentifier worldIdentifier, uint64_t userScriptMessageHandlerIdentifier)
 {
 #if ENABLE(USER_MESSAGE_HANDLERS)
     auto it = worldMap().find(worldIdentifier);
     if (it == worldMap().end()) {
-        WTFLogAlways("Trying to remove a UserScriptMessageHandler from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+        WTFLogAlways("Trying to remove a UserScriptMessageHandler from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
         return;
     }
 
@@ -305,7 +305,7 @@
 #endif
 }
 
-void WebUserContentController::removeAllUserScriptMessageHandlers(const Vector<uint64_t>& worldIdentifiers)
+void WebUserContentController::removeAllUserScriptMessageHandlers(const Vector<ContentWorldIdentifier>& worldIdentifiers)
 {
 #if ENABLE(USER_MESSAGE_HANDLERS)
     bool userMessageHandlersChanged = false;
@@ -312,7 +312,7 @@
     for (auto& worldIdentifier : worldIdentifiers) {
         auto it = worldMap().find(worldIdentifier);
         if (it == worldMap().end()) {
-            WTFLogAlways("Trying to remove all UserScriptMessageHandler from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier);
+            WTFLogAlways("Trying to remove all UserScriptMessageHandler from a UserContentWorld (id=%" PRIu64 ") that does not exist.", worldIdentifier.toUInt64());
             return;
         }
 

Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -64,11 +64,10 @@
     void removeUserStyleSheets(InjectedBundleScriptWorld&);
     void removeAllUserContent();
 
-    static uint64_t identifierForNormalWorld() { return 1; }
-    InjectedBundleScriptWorld* worldForIdentifier(uint64_t);
+    InjectedBundleScriptWorld* worldForIdentifier(ContentWorldIdentifier);
 
-    void addUserContentWorlds(const Vector<std::pair<uint64_t, String>>&);
-    void addUserContentWorld(const std::pair<uint64_t, String>&);
+    void addUserContentWorlds(const Vector<std::pair<ContentWorldIdentifier, String>>&);
+    void addUserContentWorld(const std::pair<ContentWorldIdentifier, String>&);
     void addUserScripts(Vector<WebUserScriptData>&&, InjectUserScriptImmediately);
     void addUserStyleSheets(const Vector<WebUserStyleSheetData>&);
     void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerData>&);
@@ -92,16 +91,16 @@
     // IPC::MessageReceiver.
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
-    void removeUserContentWorlds(const Vector<uint64_t>&);
+    void removeUserContentWorlds(const Vector<ContentWorldIdentifier>&);
 
-    void removeUserScript(uint64_t worldIdentifier, uint64_t userScriptIdentifier);
-    void removeAllUserScripts(const Vector<uint64_t>&);
+    void removeUserScript(ContentWorldIdentifier, uint64_t userScriptIdentifier);
+    void removeAllUserScripts(const Vector<ContentWorldIdentifier>&);
 
-    void removeUserStyleSheet(uint64_t worldIdentifier, uint64_t userScriptIdentifier);
-    void removeAllUserStyleSheets(const Vector<uint64_t>&);
+    void removeUserStyleSheet(ContentWorldIdentifier, uint64_t userScriptIdentifier);
+    void removeAllUserStyleSheets(const Vector<ContentWorldIdentifier>&);
 
-    void removeUserScriptMessageHandler(uint64_t worldIdentifier, uint64_t userScriptIdentifier);
-    void removeAllUserScriptMessageHandlers(const Vector<uint64_t>&);
+    void removeUserScriptMessageHandler(ContentWorldIdentifier, uint64_t userScriptIdentifier);
+    void removeAllUserScriptMessageHandlers(const Vector<ContentWorldIdentifier>&);
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void removeContentRuleList(const String& name);

Modified: trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.messages.in	2020-01-26 05:43:29 UTC (rev 255127)
@@ -24,20 +24,20 @@
  */
 
 messages -> WebUserContentController {
-    AddUserContentWorlds(Vector<std::pair<uint64_t, String>> worlds);
-    RemoveUserContentWorlds(Vector<uint64_t> worldIdentifiers);
+    AddUserContentWorlds(Vector<std::pair<WebKit::ContentWorldIdentifier, String>> worlds);
+    RemoveUserContentWorlds(Vector<WebKit::ContentWorldIdentifier> worldIdentifiers);
 
     AddUserScripts(Vector<struct WebKit::WebUserScriptData> userScripts, enum:bool WebKit::InjectUserScriptImmediately immediately);
-    RemoveUserScript(uint64_t worldIdentifier, uint64_t identifier);
-    RemoveAllUserScripts(Vector<uint64_t> worldIdentifiers);
+    RemoveUserScript(WebKit::ContentWorldIdentifier worldIdentifier, uint64_t identifier);
+    RemoveAllUserScripts(Vector<WebKit::ContentWorldIdentifier> worldIdentifiers);
 
     AddUserStyleSheets(Vector<struct WebKit::WebUserStyleSheetData> userStyleSheets);
-    RemoveUserStyleSheet(uint64_t worldIdentifier, uint64_t identifier);
-    RemoveAllUserStyleSheets(Vector<uint64_t> worldIdentifiers);
+    RemoveUserStyleSheet(WebKit::ContentWorldIdentifier worldIdentifier, uint64_t identifier);
+    RemoveAllUserStyleSheets(Vector<WebKit::ContentWorldIdentifier> worldIdentifiers);
 
     AddUserScriptMessageHandlers(Vector<struct WebKit::WebScriptMessageHandlerData> scriptMessageHandlers);
-    RemoveUserScriptMessageHandler(uint64_t worldIdentifier, uint64_t identifier);
-    RemoveAllUserScriptMessageHandlers(Vector<uint64_t> worldIdentifiers);
+    RemoveUserScriptMessageHandler(WebKit::ContentWorldIdentifier worldIdentifier, uint64_t identifier);
+    RemoveAllUserScriptMessageHandlers(Vector<WebKit::ContentWorldIdentifier> worldIdentifiers);
 
 #if ENABLE(CONTENT_EXTENSIONS)
     AddContentRuleLists(Vector<std::pair<String, WebKit::WebCompiledContentRuleListData>> contentFilters);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-01-26 05:43:29 UTC (rev 255127)
@@ -3380,7 +3380,7 @@
     return static_cast<KeyboardUIMode>((fullKeyboardAccessEnabled ? KeyboardAccessFull : KeyboardAccessDefault) | (m_tabToLinks ? KeyboardAccessTabsToLinks : 0));
 }
 
-void WebPage::runJavaScript(WebFrame* frame, RunJavaScriptParameters&& parameters, uint64_t worldIdentifier, CallbackID callbackID)
+void WebPage::runJavaScript(WebFrame* frame, RunJavaScriptParameters&& parameters, ContentWorldIdentifier worldIdentifier, CallbackID callbackID)
 {
     // NOTE: We need to be careful when running scripts that the objects we depend on don't
     // disappear during script execution.
@@ -3390,7 +3390,6 @@
         return;
     }
 
-    ASSERT(worldIdentifier);
     auto* world = m_userContentController->worldForIdentifier(worldIdentifier);
     if (!world) {
         send(Messages::WebPageProxy::ScriptValueCallback({ }, ExceptionDetails { "Unable to execute _javascript_: Cannot find specified content world"_s }, callbackID));
@@ -3419,7 +3418,7 @@
     frame->coreFrame()->script().executeAsynchronousUserAgentScriptInWorld(world->coreWorld(), WTFMove(parameters), WTFMove(resolveFunction));
 }
 
-void WebPage::runJavaScriptInMainFrameScriptWorld(RunJavaScriptParameters&& parameters, const std::pair<uint64_t, String>& worldData, CallbackID callbackID)
+void WebPage::runJavaScriptInMainFrameScriptWorld(RunJavaScriptParameters&& parameters, const std::pair<ContentWorldIdentifier, String>& worldData, CallbackID callbackID)
 {
     m_userContentController->addUserContentWorld(worldData);
     runJavaScript(mainWebFrame(), WTFMove(parameters), worldData.first, callbackID);
@@ -3429,7 +3428,7 @@
 {
     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     ASSERT(mainWebFrame() != frame);
-    runJavaScript(frame, { script, false, WTF::nullopt, forceUserGesture }, WebUserContentController::identifierForNormalWorld(), callbackID);
+    runJavaScript(frame, { script, false, WTF::nullopt, forceUserGesture }, pageContentWorldIdentifier(), callbackID);
 }
 
 void WebPage::getContentsAsString(CallbackID callbackID)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-01-26 05:43:29 UTC (rev 255127)
@@ -1462,8 +1462,8 @@
     void getSelectionAsWebArchiveData(CallbackID);
     void getSourceForFrame(WebCore::FrameIdentifier, CallbackID);
     void getWebArchiveOfFrame(WebCore::FrameIdentifier, CallbackID);
-    void runJavaScript(WebFrame*, WebCore::RunJavaScriptParameters&&, uint64_t worldIdentifier, CallbackID);
-    void runJavaScriptInMainFrameScriptWorld(WebCore::RunJavaScriptParameters&&, const std::pair<uint64_t, String>& worldData, CallbackID);
+    void runJavaScript(WebFrame*, WebCore::RunJavaScriptParameters&&, ContentWorldIdentifier, CallbackID);
+    void runJavaScriptInMainFrameScriptWorld(WebCore::RunJavaScriptParameters&&, const std::pair<ContentWorldIdentifier, String>& worldData, CallbackID);
     void runJavaScriptInFrame(WebCore::FrameIdentifier, const String&, bool forceUserGesture, CallbackID);
     void forceRepaint(CallbackID);
     void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CallbackID);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (255126 => 255127)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-01-25 22:34:00 UTC (rev 255126)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-01-26 05:43:29 UTC (rev 255127)
@@ -208,7 +208,7 @@
     GetWebArchiveOfFrame(WebCore::FrameIdentifier frameID, WebKit::CallbackID callbackID)
 
     // FIXME: These should use sendWithAsyncReply instead of callbackIDs
-    RunJavaScriptInMainFrameScriptWorld(struct WebCore::RunJavaScriptParameters parameters, std::pair<uint64_t, String> world, WebKit::CallbackID callbackID)
+    RunJavaScriptInMainFrameScriptWorld(struct WebCore::RunJavaScriptParameters parameters, std::pair<WebKit::ContentWorldIdentifier, String> world, WebKit::CallbackID callbackID)
     RunJavaScriptInFrame(WebCore::FrameIdentifier frameID, String script, bool forceUserGesture, WebKit::CallbackID callbackID)
 
     ForceRepaint(WebKit::CallbackID callbackID)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to