Title: [288093] trunk
Revision
288093
Author
[email protected]
Date
2022-01-17 02:49:40 -0800 (Mon, 17 Jan 2022)

Log Message

Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
https://bugs.webkit.org/show_bug.cgi?id=235070

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/fetch-event.https-expected.txt:

Source/WebCore:

Update ScriptExecutionContextIdentifier to be a process-scoped UUID.
This allows to identify the process running a process as well as exposing to _javascript_ context identifiers as UUIDs.
This is matching what Chrome and Firefox are doing.
Make SWServer store the maping from context UUID strings to the internal ScriptExecutionContextIdentifiers.
This allows to find a ServiceWorkerClient directly from its _javascript_ exposed identifier.
Rename reservedClientId in resultingClientId to match the spec.

Covered by existing tests.

* Modules/web-locks/WebLockRegistry.cpp:
* dom/ScriptExecutionContext.cpp:
* loader/DocumentLoader.cpp:
* page/mac/PageMac.mm:
* platform/ProcessQualified.h:
* platform/ScriptExecutionContextIdentifier.h:
* testing/Internals.cpp:
* testing/Internals.h:
* testing/Internals.idl:
* testing/ServiceWorkerInternals.cpp:
* testing/ServiceWorkerInternals.h:
* testing/ServiceWorkerInternals.idl:
* workers/service/FetchEvent.cpp:
* workers/service/FetchEvent.h:
* workers/service/FetchEvent.idl:
* workers/service/ServiceWorkerClient.cpp:
* workers/service/ServiceWorkerClient.idl:
* workers/service/ServiceWorkerClients.cpp:
* workers/service/context/SWContextManager.h:
* workers/service/context/ServiceWorkerFetch.cpp:
* workers/service/context/ServiceWorkerFetch.h:
* workers/service/context/ServiceWorkerThread.cpp:
* workers/service/context/ServiceWorkerThread.h:
* workers/service/context/ServiceWorkerThreadProxy.cpp:
* workers/service/context/ServiceWorkerThreadProxy.h:
* workers/service/server/SWServer.cpp:
* workers/service/server/SWServer.h:
* workers/service/server/SWServerToContextConnection.cpp:
* workers/service/server/SWServerToContextConnection.h:
* workers/service/server/SWServerWorker.cpp:
* workers/service/server/SWServerWorker.h:

Source/WebKit:

Change findByClientIdentifier into findByVisibleClientIdentifieran and make it asn async reply.
Update fetch event code path to send the visible IDs of the FetchEvent from network process to worker context process.
We store these IDs in NetworkResourceLoader so that we can change them in case of redirection for navigations.

* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
* NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
* WebProcess/InjectedBundle/InjectedBundle.h:
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

Source/WTF:

* wtf/UUID.cpp:
* wtf/UUID.h:
 Add routine to stringify a UUID.
 Add routine to parse a stringified UUID.
 We restrict UUID::create to values for which the version 4 UUID stringification is bijective.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/UUID.cpp:
* TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:

LayoutTests:

Updated tests to not rely on visible ID to be the serialization of a ScriptExecutionContextIdentifier.
For that reason, add internals API to get the internal ID from a ServiceWorkerClient.

* http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html:
* http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html:
* http/tests/workers/service/resources/getClientIds-worker.js:
* http/tests/workers/service/serviceworkerclients-matchAll-worker.js:
* http/tests/workers/service/serviceworkerclients-matchAll.https.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288092 => 288093)


--- trunk/LayoutTests/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,3 +1,19 @@
+2022-01-17  Youenn Fablet  <[email protected]>
+
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        Updated tests to not rely on visible ID to be the serialization of a ScriptExecutionContextIdentifier.
+        For that reason, add internals API to get the internal ID from a ServiceWorkerClient.
+
+        * http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html:
+        * http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html:
+        * http/tests/workers/service/resources/getClientIds-worker.js:
+        * http/tests/workers/service/serviceworkerclients-matchAll-worker.js:
+        * http/tests/workers/service/serviceworkerclients-matchAll.https.html:
+
 2022-01-17  Philippe Normand  <[email protected]>
 
         [GStreamer] tests media/track/audio-track-configuration.html and media/track/video-track-configuration.html fail

Modified: trunk/LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html (288092 => 288093)


--- trunk/LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html	2022-01-17 10:49:40 UTC (rev 288093)
@@ -70,12 +70,12 @@
 });
 
 navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then(function(registration) {
-    expectedClientIdentifiers.push(internals.serviceWorkerClientIdentifier(document));
+    expectedClientIdentifiers.push(internals.serviceWorkerClientInternalIdentifier(document));
 
     worker = registration.installing;
     otherWindow = open("other_resources/test.html");
     otherWindow._onload_ = function() {
-      expectedClientIdentifiers.push(internals.serviceWorkerClientIdentifier(otherWindow.document));
+      expectedClientIdentifiers.push(internals.serviceWorkerClientInternalIdentifier(otherWindow.document));
       step = "BothClientsInitiallyActive"
       worker.postMessage("getClientIds");
     };

Modified: trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html (288092 => 288093)


--- trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html	2022-01-17 10:49:40 UTC (rev 288093)
@@ -65,12 +65,14 @@
 });
 
 navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then(function(registration) {
-    topClientIdentifier = internals.serviceWorkerClientIdentifier(document);
+    if (!window.internals)
+        return;
+    topClientIdentifier = internals.serviceWorkerClientInternalIdentifier(document);
 
     worker = registration.installing;
     otherWindow = open("other_resources/test.html");
     otherWindow._onload_ = function() {
-      windowClientIdentifier = internals.serviceWorkerClientIdentifier(otherWindow.document);
+      windowClientIdentifier = internals.serviceWorkerClientInternalIdentifier(otherWindow.document);
       step = "BothClientsInitiallyActive"
       worker.postMessage("getClientIds");
     };

Modified: trunk/LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js (288092 => 288093)


--- trunk/LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js	2022-01-17 10:49:40 UTC (rev 288093)
@@ -3,7 +3,7 @@
     clients.matchAll({ includeUncontrolled : true }).then(function(clients) {
         let ids = [];
         for (let client of clients)
-            ids.push(client.id);
+            ids.push(self.internals.serviceWorkerClientInternalIdentifier(client));
         source.postMessage(ids);
     });
 });

Modified: trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll-worker.js (288092 => 288093)


--- trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll-worker.js	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll-worker.js	2022-01-17 10:49:40 UTC (rev 288093)
@@ -3,6 +3,15 @@
     return new Promise((resolve) => setTimeout(resolve, duration));
 }
 
+async function serviceWorkerClientIdentifierFromInternalIdentifier(internalIdentifier)
+{
+     const clients = await self.clients.matchAll({ includeUncontrolled : true });
+     for (let client of clients) {
+         if (internals.serviceWorkerClientInternalIdentifier(client) == internalIdentifier)
+            return client.id;
+     }
+}
+
 function checkClientNotInControlledClients(clientIdentifier)
 {
     return self.clients.matchAll().then((clients) => {
@@ -37,7 +46,7 @@
             return;
         }
 
-        const clientIdentifier = event.data.identifier;
+        const clientIdentifier = await serviceWorkerClientIdentifierFromInternalIdentifier(event.data.identifier);
 
         let result = await checkClientNotInControlledClients(clientIdentifier);
         if (result !== "PASS") {

Modified: trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll.https.html (288092 => 288093)


--- trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll.https.html	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll.https.html	2022-01-17 10:49:40 UTC (rev 288093)
@@ -27,7 +27,7 @@
 }, "Setup worker");
 
 promise_test(async (test) => {
-    const serviceWorkerClientIdentifier = internals.serviceWorkerClientIdentifier(document);
+    const serviceWorkerClientIdentifier = internals.serviceWorkerClientInternalIdentifier(document);
     var promise = new Promise((resolve, reject) => {
         navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
             assert_equals(event.data, "PASS");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288092 => 288093)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,5 +1,14 @@
 2022-01-17  Youenn Fablet  <[email protected]>
 
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/fetch-event.https-expected.txt:
+
+2022-01-17  Youenn Fablet  <[email protected]>
+
         Transmit network load metrics when service worker is using one of its network load to respond to FetchEvents
         https://bugs.webkit.org/show_bug.cgi?id=235179
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event.https-expected.txt (288092 => 288093)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event.https-expected.txt	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event.https-expected.txt	2022-01-17 10:49:40 UTC (rev 288093)
@@ -6,7 +6,7 @@
 PASS Service Worker responds to fetch event with blob body
 PASS Service Worker responds to fetch event with the referrer URL
 PASS Service Worker responds to fetch event with an existing client id
-FAIL Service Worker responds to fetch event with the correct resulting client id assert_equals: Service Worker should respond with an empty resulting client id for subresource requests expected "Resulting Client ID Not Found" but got "Resulting Client ID Found: undefined"
+PASS Service Worker responds to fetch event with the correct resulting client id
 PASS Service Worker does not respond to fetch event
 PASS Service Worker responds to fetch event with null response body
 PASS Service Worker fetches other file in fetch event

Modified: trunk/Source/WTF/ChangeLog (288092 => 288093)


--- trunk/Source/WTF/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WTF/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,3 +1,16 @@
+2022-01-17  Youenn Fablet  <[email protected]>
+
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        * wtf/UUID.cpp:
+        * wtf/UUID.h:
+         Add routine to stringify a UUID.
+         Add routine to parse a stringified UUID.
+         We restrict UUID::create to values for which the version 4 UUID stringification is bijective.
+
 2022-01-16  Youenn Fablet  <[email protected]>
 
         Enforce focus check for getUserMedia

Modified: trunk/Source/WTF/wtf/UUID.cpp (288092 => 288093)


--- trunk/Source/WTF/wtf/UUID.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WTF/wtf/UUID.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -35,6 +35,7 @@
 #include <wtf/ASCIICType.h>
 #include <wtf/CryptographicallyRandomNumber.h>
 #include <wtf/HexNumber.h>
+#include <wtf/text/StringToIntegerConversion.h>
 
 #if OS(DARWIN)
 #include <sys/sysctl.h>
@@ -45,9 +46,15 @@
 UUID::UUID()
 {
     static_assert(sizeof(m_data) == 16);
+    auto* data = "" char*>(&m_data);
+
     do {
-        cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(&m_data), 16);
+        cryptographicallyRandomValues(data, 16);
     } while (m_data == emptyValue || m_data == deletedValue);
+
+    // We sanitize the value so as not loosing any data when going to Version 4 UUIDs.
+    data[5] &= 0x0f;
+    data[11] &= 0xcf;
 }
 
 unsigned UUID::hash() const
@@ -55,10 +62,9 @@
     return StringHasher::hashMemory(reinterpret_cast<const unsigned char*>(&m_data), 16);
 }
 
-String createCanonicalUUIDString()
+String UUID::toString() const
 {
-    unsigned randomData[4];
-    cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(randomData), sizeof(randomData));
+    auto* randomData = reinterpret_cast<const unsigned*>(&m_data);
 
     // Format as Version 4 UUID.
     return makeString(
@@ -76,6 +82,65 @@
     );
 }
 
+std::optional<UUID> UUID::parse(StringView value)
+{
+    // Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with hexadecimal digits for x and one of 8, 9, A, or B for y.
+    if (value.length() != 36)
+        return { };
+
+    if (value[8] != '-' || value[13] != '-'  || value[14] != '4' || value[18] != '-' || value[23] != '-')
+        return { };
+
+    unsigned y = value[19];
+    if (y == '8' || y == '9')
+        y = y - '8';
+    else if (y == 'a' || y == 'A')
+        y = 2;
+    else if (y == 'b' || y == 'B')
+        y = 3;
+    else
+        return { };
+
+    auto firstValue = parseInteger<unsigned>(value.substring(0, 8), 16);
+    if (!firstValue)
+        return { };
+
+    auto secondValue = parseInteger<unsigned>(value.substring(9, 4), 16);
+    if (!secondValue)
+        return { };
+
+    auto thirdValue = parseInteger<unsigned>(value.substring(15, 3), 16);
+    if (!thirdValue)
+        return { };
+
+    auto fourthValue = parseInteger<unsigned>(value.substring(20, 3), 16);
+    if (!fourthValue)
+        return { };
+
+    auto fifthValue = parseInteger<unsigned>(value.substring(24, 4), 16);
+    if (!fifthValue)
+        return { };
+
+    auto sixthValue = parseInteger<unsigned>(value.substring(28, 8), 16);
+    if (!sixthValue)
+        return { };
+
+    UInt128 uuidValue;
+
+    auto* data = ""
+    data[0] = *firstValue;
+    data[1] = (*secondValue << 16) | *thirdValue;
+    data[2] = ((*fourthValue << 16) | *fifthValue) + (y << 30);
+    data[3] = *sixthValue;
+
+    return UUID(WTFMove(uuidValue));
+}
+
+String createCanonicalUUIDString()
+{
+    return UUID::create().toString();
+}
+
 String bootSessionUUIDString()
 {
 #if OS(DARWIN)
@@ -97,31 +162,7 @@
 
 bool isVersion4UUID(StringView value)
 {
-    // Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with hexadecimal digits for x and one of 8, 9, A, or B for y.
-    if (value.length() != 36)
-        return false;
-
-    for (auto cptr = 0; cptr < 36; ++cptr) {
-        if (cptr == 8 || cptr == 13 || cptr == 18 || cptr == 23) {
-            if (value[cptr] != '-')
-                return false;
-            continue;
-        }
-        if (cptr == 14) {
-            if (value[cptr] != '4')
-                return false;
-            continue;
-        }
-        if (cptr == 19) {
-            auto y = value[cptr];
-            if (y != '8' && y != '9' && y != 'a' && y != 'A' && y != 'b' && y != 'B')
-                return false;
-            continue;
-        }
-        if (!isASCIIHexDigit(value[cptr]))
-            return false;
-    }
-    return true;
+    return !!UUID::parse(value);
 }
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/UUID.h (288092 => 288093)


--- trunk/Source/WTF/wtf/UUID.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WTF/wtf/UUID.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -30,6 +30,7 @@
 
 #pragma once
 
+#include <wtf/Hasher.h>
 #include <wtf/Int128.h>
 #include <wtf/text/WTFString.h>
 
@@ -48,6 +49,8 @@
         return UUID { };
     }
 
+    WTF_EXPORT_PRIVATE static std::optional<UUID> parse(StringView);
+
     explicit UUID(Span<const uint8_t, 16> span)
     {
         memcpy(&m_data, span.data(), 16);
@@ -80,6 +83,7 @@
 
     bool isHashTableDeletedValue() const { return m_data == deletedValue; }
     WTF_EXPORT_PRIVATE unsigned hash() const;
+    WTF_EXPORT_PRIVATE String toString() const;
 
 private:
     WTF_EXPORT_PRIVATE UUID();
@@ -122,6 +126,11 @@
     return UUID { (static_cast<UInt128>(*high) << 64) | *low };
 }
 
+inline void add(Hasher& hasher, const UUID& uuid)
+{
+    add(hasher, uuid.hash());
+}
+
 // Creates a UUID that consists of 32 hexadecimal digits and returns its canonical form.
 // The canonical form is displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters.
 // The hexadecimal values "a" through "f" are output as lower case characters.

Modified: trunk/Source/WebCore/ChangeLog (288092 => 288093)


--- trunk/Source/WebCore/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,3 +1,51 @@
+2022-01-17  Youenn Fablet  <[email protected]>
+
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        Update ScriptExecutionContextIdentifier to be a process-scoped UUID.
+        This allows to identify the process running a process as well as exposing to _javascript_ context identifiers as UUIDs.
+        This is matching what Chrome and Firefox are doing.
+        Make SWServer store the maping from context UUID strings to the internal ScriptExecutionContextIdentifiers.
+        This allows to find a ServiceWorkerClient directly from its _javascript_ exposed identifier.
+        Rename reservedClientId in resultingClientId to match the spec.
+
+        Covered by existing tests.
+
+        * Modules/web-locks/WebLockRegistry.cpp:
+        * dom/ScriptExecutionContext.cpp:
+        * loader/DocumentLoader.cpp:
+        * page/mac/PageMac.mm:
+        * platform/ProcessQualified.h:
+        * platform/ScriptExecutionContextIdentifier.h:
+        * testing/Internals.cpp:
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        * testing/ServiceWorkerInternals.cpp:
+        * testing/ServiceWorkerInternals.h:
+        * testing/ServiceWorkerInternals.idl:
+        * workers/service/FetchEvent.cpp:
+        * workers/service/FetchEvent.h:
+        * workers/service/FetchEvent.idl:
+        * workers/service/ServiceWorkerClient.cpp:
+        * workers/service/ServiceWorkerClient.idl:
+        * workers/service/ServiceWorkerClients.cpp:
+        * workers/service/context/SWContextManager.h:
+        * workers/service/context/ServiceWorkerFetch.cpp:
+        * workers/service/context/ServiceWorkerFetch.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        * workers/service/context/ServiceWorkerThread.h:
+        * workers/service/context/ServiceWorkerThreadProxy.cpp:
+        * workers/service/context/ServiceWorkerThreadProxy.h:
+        * workers/service/server/SWServer.cpp:
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerToContextConnection.cpp:
+        * workers/service/server/SWServerToContextConnection.h:
+        * workers/service/server/SWServerWorker.cpp:
+        * workers/service/server/SWServerWorker.h:
+
 2022-01-17  Philippe Normand  <[email protected]>
 
         [GStreamer] tests media/track/audio-track-configuration.html and media/track/video-track-configuration.html fail

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (288092 => 288093)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -112,7 +112,7 @@
 };
 
 ScriptExecutionContext::ScriptExecutionContext()
-    : m_identifier(ScriptExecutionContextIdentifier::generateThreadSafe())
+    : m_identifier(ScriptExecutionContextIdentifier::generate())
 {
     Locker locker { allScriptExecutionContextsMapLock };
     allScriptExecutionContextsMap().add(m_identifier, this);

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (288092 => 288093)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -2095,7 +2095,7 @@
 #if ENABLE(SERVICE_WORKER)
     if (!m_temporaryServiceWorkerClient) {
         // The main navigation load will trigger the registration of the temp client.
-        m_temporaryServiceWorkerClient = ScriptExecutionContextIdentifier::generateThreadSafe();
+        m_temporaryServiceWorkerClient = ScriptExecutionContextIdentifier::generate();
         ASSERT(!temporaryIdentifierToLoaderMap().contains(*m_temporaryServiceWorkerClient));
         temporaryIdentifierToLoaderMap().add(*m_temporaryServiceWorkerClient, this);
     }

Modified: trunk/Source/WebCore/page/mac/PageMac.mm (288092 => 288093)


--- trunk/Source/WebCore/page/mac/PageMac.mm	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/page/mac/PageMac.mm	2022-01-17 10:49:40 UTC (rev 288093)
@@ -81,7 +81,7 @@
             WTFLogAlways("%u live documents:", Document::allDocuments().size());
             for (const auto* document : Document::allDocuments()) {
                 const char* documentType = is<SVGDocument>(document) ? "SVGDocument" : "Document";
-                WTFLogAlways("%s %p %s (refCount %d, referencingNodeCount %d) %s", documentType, document, document->identifier().toString().utf8().data(), document->refCount(), document->referencingNodeCount(), document->url().string().utf8().data());
+                WTFLogAlways("%s %p %" PRIu64 "-%s (refCount %d, referencingNodeCount %d) %s", documentType, document, document->identifier().processIdentifier().toUInt64(), document->identifier().toString().utf8().data(), document->refCount(), document->referencingNodeCount(), document->url().string().utf8().data());
             }
         });
     });

Modified: trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h (288092 => 288093)


--- trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -27,10 +27,79 @@
 
 #include "ProcessQualified.h"
 #include <wtf/Forward.h>
+#include <wtf/UUID.h>
 
 namespace WebCore {
 
-enum ScriptExecutionContextIdentifierType { };
-using ScriptExecutionContextIdentifier = ProcessQualified<ObjectIdentifier<ScriptExecutionContextIdentifierType>>;
+template <>
+class ProcessQualified<UUID> {
+public:
+    static ProcessQualified generate() { return { UUID::create(), Process::identifier() }; }
 
+    ProcessQualified()
+        : m_object(WTF::UInt128(0))
+    {
+    }
+
+    ProcessQualified(UUID&& object, ProcessIdentifier processIdentifier)
+        : m_object(WTFMove(object))
+        , m_processIdentifier(processIdentifier)
+    {
+    }
+
+    ProcessQualified(const UUID& object, ProcessIdentifier processIdentifier)
+        : m_object(object)
+        , m_processIdentifier(processIdentifier)
+    {
+    }
+
+    ProcessQualified(WTF::HashTableDeletedValueType)
+        : m_object(WTF::HashTableDeletedValue)
+        , m_processIdentifier(WTF::HashTableDeletedValue)
+    {
+    }
+
+    operator bool() const { return !!m_processIdentifier; }
+
+    const UUID& object() const { return m_object; }
+    ProcessIdentifier processIdentifier() const { return m_processIdentifier; }
+
+    unsigned hash() const { return m_object.hash(); }
+    bool isHashTableDeletedValue() const { return m_processIdentifier.isHashTableDeletedValue(); }
+
+    bool operator==(const ProcessQualified& other) const { return m_object == other.m_object && m_processIdentifier == other.m_processIdentifier; }
+    bool operator!=(const ProcessQualified& other) const { return !(*this == other); }
+
+    String toString() const { return m_object.toString(); }
+
+    template<typename Encoder> void encode(Encoder& encoder) const { encoder << m_object << m_processIdentifier; }
+    template<typename Decoder> static std::optional<ProcessQualified> decode(Decoder&);
+
+private:
+    UUID m_object;
+    ProcessIdentifier m_processIdentifier;
+};
+
+template<typename Decoder> std::optional<ProcessQualified<UUID>> ProcessQualified<UUID>::decode(Decoder& decoder)
+{
+    std::optional<UUID> object;
+    decoder >> object;
+    if (!object)
+        return std::nullopt;
+    std::optional<ProcessIdentifier> processIdentifier;
+    decoder >> processIdentifier;
+    if (!processIdentifier)
+        return std::nullopt;
+    return { { *object, *processIdentifier } };
 }
+
+template <>
+inline TextStream& operator<<(TextStream& ts, const ProcessQualified<UUID>& processQualified)
+{
+    ts << "ProcessQualified(" << processQualified.processIdentifier().toUInt64() << '-' << processQualified.object().toString() << ')';
+    return ts;
+}
+
+using ScriptExecutionContextIdentifier = ProcessQualified<UUID>;
+
+}

Modified: trunk/Source/WebCore/testing/Internals.cpp (288092 => 288093)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -2760,14 +2760,16 @@
     return document.numberOfResizeObservers();
 }
 
-uint64_t Internals::documentIdentifier(const Document& document) const
+String Internals::documentIdentifier(const Document& document) const
 {
-    return document.identifier().object().toUInt64();
+    return document.identifier().object().toString();
 }
 
-bool Internals::isDocumentAlive(uint64_t documentIdentifier) const
+bool Internals::isDocumentAlive(const String& documentIdentifier) const
 {
-    return Document::allDocumentsMap().contains({ makeObjectIdentifier<ScriptExecutionContextIdentifierType>(documentIdentifier), Process::identifier() });
+    auto uuid = UUID::parse(documentIdentifier);
+    ASSERT(uuid);
+    return uuid ? Document::allDocumentsMap().contains({ *uuid, Process::identifier() }) : false;
 }
 
 uint64_t Internals::storageAreaMapCount() const
@@ -2806,7 +2808,7 @@
     return WorkletGlobalScope::numberOfWorkletGlobalScopes();
 }
 
-String Internals::serviceWorkerClientIdentifier(const Document& document) const
+String Internals::serviceWorkerClientInternalIdentifier(const Document& document) const
 {
     return document.identifier().toString();
 }

Modified: trunk/Source/WebCore/testing/Internals.h (288092 => 288093)


--- trunk/Source/WebCore/testing/Internals.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/Internals.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -490,8 +490,8 @@
 
     unsigned numberOfResizeObservers(const Document&) const;
 
-    uint64_t documentIdentifier(const Document&) const;
-    bool isDocumentAlive(uint64_t documentIdentifier) const;
+    String documentIdentifier(const Document&) const;
+    bool isDocumentAlive(const String& documentIdentifier) const;
 
     uint64_t storageAreaMapCount() const;
 
@@ -503,7 +503,7 @@
 
     bool isAnyWorkletGlobalScopeAlive() const;
 
-    String serviceWorkerClientIdentifier(const Document&) const;
+    String serviceWorkerClientInternalIdentifier(const Document&) const;
 
     RefPtr<WindowProxy> openDummyInspectorFrontend(const String& url);
     void closeDummyInspectorFrontend();

Modified: trunk/Source/WebCore/testing/Internals.idl (288092 => 288093)


--- trunk/Source/WebCore/testing/Internals.idl	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/Internals.idl	2022-01-17 10:49:40 UTC (rev 288093)
@@ -920,8 +920,8 @@
     [Conditional=MEDIA_STREAM] boolean isMockRealtimeMediaSourceCenterEnabled();
     [Conditional=MEDIA_STREAM] boolean shouldAudioTrackPlay(AudioTrack track);
 
-    unsigned long long documentIdentifier(Document document);
-    boolean isDocumentAlive(unsigned long long documentIdentifier);
+    DOMString documentIdentifier(Document document);
+    boolean isDocumentAlive(DOMString documentIdentifier);
 
     readonly attribute unsigned long long storageAreaMapCount;
 
@@ -933,7 +933,7 @@
     boolean isAnyWorkletGlobalScopeAlive();
 
     readonly attribute long processIdentifier;
-    DOMString serviceWorkerClientIdentifier(Document document);
+    DOMString serviceWorkerClientInternalIdentifier(Document document);
     Promise<undefined> storeRegistrationsOnDisk();
     Promise<double> sendH2Ping(DOMString url);
 

Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp (288092 => 288093)


--- trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -33,6 +33,7 @@
 #include "PushSubscription.h"
 #include "PushSubscriptionData.h"
 #include "SWContextManager.h"
+#include "ServiceWorkerClient.h"
 #include "ServiceWorkerRegistration.h"
 #include <wtf/ProcessID.h>
 
@@ -193,6 +194,11 @@
     return event.request().internalRequest().isSameSite();
 }
 
+String ServiceWorkerInternals::serviceWorkerClientInternalIdentifier(const ServiceWorkerClient& client)
+{
+    return client.identifier().toString();
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.h (288092 => 288093)


--- trunk/Source/WebCore/testing/ServiceWorkerInternals.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -40,6 +40,7 @@
 class FetchResponse;
 class PushSubscription;
 class ScriptExecutionContext;
+class ServiceWorkerClient;
 
 template<typename IDLType> class DOMPromiseDeferred;
 
@@ -71,6 +72,8 @@
 
     bool fetchEventIsSameSite(FetchEvent&);
 
+    String serviceWorkerClientInternalIdentifier(const ServiceWorkerClient&);
+
 private:
     explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
 

Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.idl (288092 => 288093)


--- trunk/Source/WebCore/testing/ServiceWorkerInternals.idl	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.idl	2022-01-17 10:49:40 UTC (rev 288093)
@@ -51,4 +51,6 @@
     PushSubscription createPushSubscription(USVString endpoint, EpochTimeStamp? expirationTime, ArrayBuffer serverVAPIDPublicKey, ArrayBuffer clientECDHPublicKey, ArrayBuffer auth);
 
     boolean fetchEventIsSameSite(FetchEvent event);
+
+    DOMString serviceWorkerClientInternalIdentifier(ServiceWorkerClient client);
 };

Modified: trunk/Source/WebCore/workers/service/FetchEvent.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/FetchEvent.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/FetchEvent.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -61,7 +61,7 @@
     : ExtendableEvent(type, initializer, isTrusted)
     , m_request(initializer.request.releaseNonNull())
     , m_clientId(WTFMove(initializer.clientId))
-    , m_reservedClientId(WTFMove(initializer.reservedClientId))
+    , m_resultingClientId(WTFMove(initializer.resultingClientId))
     , m_targetClientId(WTFMove(initializer.targetClientId))
     , m_handled(retrieveHandledPromise(globalObject, WTFMove(initializer.handled)))
 {

Modified: trunk/Source/WebCore/workers/service/FetchEvent.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/FetchEvent.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/FetchEvent.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -49,7 +49,7 @@
     struct Init : ExtendableEventInit {
         RefPtr<FetchRequest> request;
         String clientId;
-        String reservedClientId;
+        String resultingClientId;
         String targetClientId;
         RefPtr<DOMPromise> handled;
     };
@@ -71,7 +71,7 @@
 
     FetchRequest& request() { return m_request.get(); }
     const String& clientId() const { return m_clientId; }
-    const String& reservedClientId() const { return m_reservedClientId; }
+    const String& resultingClientId() const { return m_resultingClientId; }
     const String& targetClientId() const { return m_targetClientId; }
     DOMPromise& handled() const { return m_handled.get(); }
 
@@ -93,7 +93,7 @@
 
     Ref<FetchRequest> m_request;
     String m_clientId;
-    String m_reservedClientId;
+    String m_resultingClientId;
     String m_targetClientId;
 
     bool m_respondWithEntered { false };

Modified: trunk/Source/WebCore/workers/service/FetchEvent.idl (288092 => 288093)


--- trunk/Source/WebCore/workers/service/FetchEvent.idl	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/FetchEvent.idl	2022-01-17 10:49:40 UTC (rev 288093)
@@ -35,7 +35,7 @@
     [SameObject] readonly attribute FetchRequest request;
     [CallWith=ScriptExecutionContext, EnabledBySetting=ServiceWorkerNavigationPreloadEnabled] readonly attribute Promise<any> preloadResponse;
     readonly attribute DOMString clientId;
-    readonly attribute DOMString reservedClientId;
+    readonly attribute DOMString resultingClientId;
     readonly attribute DOMString targetClientId;
     readonly attribute Promise<undefined> handled;
 
@@ -45,7 +45,7 @@
 dictionary FetchEventInit : ExtendableEventInit {
     required FetchRequest request;
     DOMString clientId = "";
-    DOMString reservedClientId = "";
+    DOMString resultingClientId = "";
     DOMString targetClientId = "";
     Promise<undefined> handled;
 };

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl (288092 => 288093)


--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl	2022-01-17 10:49:40 UTC (rev 288093)
@@ -27,6 +27,7 @@
     Conditional=SERVICE_WORKER,
     CustomToJSObject,
     EnabledAtRuntime=ServiceWorkerEnabled,
+    ExportMacro=WEBCORE_EXPORT,
     Exposed=ServiceWorker,
     InterfaceName=Client,
 ] interface ServiceWorkerClient {

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -38,55 +38,26 @@
 
 namespace WebCore {
 
-static inline void didFinishGetRequest(ServiceWorkerGlobalScope& scope, DeferredPromise& promise, ExceptionOr<std::optional<ServiceWorkerClientData>>&& clientData)
+static inline void didFinishGetRequest(ServiceWorkerGlobalScope& scope, DeferredPromise& promise, std::optional<ServiceWorkerClientData>&& clientData)
 {
-    if (clientData.hasException()) {
-        promise.reject(clientData.releaseException());
-        return;
-    }
-    auto data = ""
-    if (!data) {
+    if (!clientData) {
         promise.resolve();
         return;
     }
 
-    promise.resolve<IDLInterface<ServiceWorkerClient>>(ServiceWorkerClient::getOrCreate(scope, WTFMove(data.value())));
+    promise.resolve<IDLInterface<ServiceWorkerClient>>(ServiceWorkerClient::getOrCreate(scope, WTFMove(*clientData)));
 }
 
-static std::optional<ScriptExecutionContextIdentifier> scriptExecutionContextIdentifierFromString(StringView string)
-{
-    ProcessIdentifier processIdentifier;
-    ObjectIdentifier<ScriptExecutionContextIdentifierType> contextIdentifier;
-    unsigned counter = 0;
-    for (auto item : string.split('-')) {
-        auto identifier = parseInteger<uint64_t>(item);
-        if (!identifier || !*identifier)
-            return std::nullopt;
-        if (!counter++)
-            processIdentifier = makeObjectIdentifier<ProcessIdentifierType>(*identifier);
-        else if (counter == 2)
-            contextIdentifier = makeObjectIdentifier<ScriptExecutionContextIdentifierType>(*identifier);
-    }
-    return (processIdentifier && contextIdentifier) ? std::make_optional(ScriptExecutionContextIdentifier { contextIdentifier, processIdentifier }) : std::nullopt;
-}
-
 void ServiceWorkerClients::get(ScriptExecutionContext& context, const String& id, Ref<DeferredPromise>&& promise)
 {
-    auto identifier = scriptExecutionContextIdentifierFromString(id);
-    if (!identifier) {
-        promise->resolve();
-        return;
-    }
-    auto clientIdentifier = identifier.value();
-
     auto serviceWorkerIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
 
     auto promisePointer = promise.ptr();
     m_pendingPromises.add(promisePointer, WTFMove(promise));
 
-    callOnMainThread([promisePointer, serviceWorkerIdentifier, clientIdentifier] () {
+    callOnMainThread([promisePointer, serviceWorkerIdentifier, id = id.isolatedCopy()] () {
         auto connection = SWContextManager::singleton().connection();
-        connection->findClientByIdentifier(serviceWorkerIdentifier, clientIdentifier, [promisePointer, serviceWorkerIdentifier] (auto&& clientData) {
+        connection->findClientByVisibleIdentifier(serviceWorkerIdentifier, id, [promisePointer, serviceWorkerIdentifier] (auto&& clientData) {
             SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [promisePointer, data = "" (auto& context) mutable {
                 if (auto promise = context.clients().m_pendingPromises.take(promisePointer))
                     didFinishGetRequest(context, *promise, WTFMove(data));

Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/SWContextManager.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -62,8 +62,8 @@
         virtual void skipWaiting(ServiceWorkerIdentifier, CompletionHandler<void()>&&) = 0;
         virtual void setScriptResource(ServiceWorkerIdentifier, const URL&, const ServiceWorkerContextData::ImportedScript&) = 0;
 
-        using FindClientByIdentifierCallback = CompletionHandler<void(ExceptionOr<std::optional<ServiceWorkerClientData>>&&)>;
-        virtual void findClientByIdentifier(ServiceWorkerIdentifier, ScriptExecutionContextIdentifier, FindClientByIdentifierCallback&&) = 0;
+        using FindClientByIdentifierCallback = CompletionHandler<void(std::optional<ServiceWorkerClientData>&&)>;
+        virtual void findClientByVisibleIdentifier(ServiceWorkerIdentifier, const String&, FindClientByIdentifierCallback&&) = 0;
         virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0;
         virtual void claim(ServiceWorkerIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&) = 0;
 

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -146,7 +146,7 @@
     });
 }
 
-void dispatchFetchEvent(Ref<Client>&& client, ServiceWorkerGlobalScope& globalScope, std::optional<ScriptExecutionContextIdentifier> clientId, ResourceRequest&& request, String&& referrer, FetchOptions&& options, FetchIdentifier fetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled)
+void dispatchFetchEvent(Ref<Client>&& client, ServiceWorkerGlobalScope& globalScope, ResourceRequest&& request, String&& referrer, FetchOptions&& options, FetchIdentifier fetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier)
 {
     auto requestHeaders = FetchHeaders::create(FetchHeaders::Guard::Immutable, HTTPHeaderMap { request.httpHeaderFields() });
 
@@ -181,12 +181,8 @@
 
     FetchEvent::Init init;
     init.request = WTFMove(fetchRequest);
-    if (isNavigation) {
-        // FIXME: Set reservedClientId.
-        if (clientId)
-            init.targetClientId = clientId->toString();
-    } else if (clientId)
-        init.clientId = clientId->toString();
+    init.resultingClientId = WTFMove(resultingClientIdentifier);
+    init.clientId = WTFMove(clientIdentifier);
     init.cancelable = true;
 
     auto& jsDOMGlobalObject = *JSC::jsCast<JSDOMGlobalObject*>(globalScope.globalObject());

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerFetch.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -62,7 +62,7 @@
     virtual void convertFetchToDownload() = 0;
 };
 
-void dispatchFetchEvent(Ref<Client>&&, ServiceWorkerGlobalScope&, std::optional<ScriptExecutionContextIdentifier>, ResourceRequest&&, String&& referrer, FetchOptions&&, FetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled);
+void dispatchFetchEvent(Ref<Client>&&, ServiceWorkerGlobalScope&, ResourceRequest&&, String&& referrer, FetchOptions&&, FetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -124,11 +124,11 @@
     WorkerThread::runEventLoop();
 }
 
-void ServiceWorkerThread::queueTaskToFireFetchEvent(Ref<ServiceWorkerFetch::Client>&& client, std::optional<ScriptExecutionContextIdentifier>&& clientId, ResourceRequest&& request, String&& referrer, FetchOptions&& options, FetchIdentifier fetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled)
+void ServiceWorkerThread::queueTaskToFireFetchEvent(Ref<ServiceWorkerFetch::Client>&& client, ResourceRequest&& request, String&& referrer, FetchOptions&& options, FetchIdentifier fetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier)
 {
     Ref serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(*globalScope());
-    serviceWorkerGlobalScope->eventLoop().queueTask(TaskSource::DOMManipulation, [serviceWorkerGlobalScope, client = WTFMove(client), clientId, request = WTFMove(request), referrer = WTFMove(referrer), options = WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled]() mutable {
-        ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), serviceWorkerGlobalScope, clientId, WTFMove(request), WTFMove(referrer), WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled);
+    serviceWorkerGlobalScope->eventLoop().queueTask(TaskSource::DOMManipulation, [serviceWorkerGlobalScope, client = WTFMove(client), request = WTFMove(request), referrer = WTFMove(referrer), options = WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled, clientIdentifier = WTFMove(clientIdentifier), resultingClientIdentifier = WTFMove(resultingClientIdentifier)]() mutable {
+        ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), serviceWorkerGlobalScope, WTFMove(request), WTFMove(referrer), WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled, WTFMove(clientIdentifier), WTFMove(resultingClientIdentifier));
     });
 }
 

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -64,7 +64,7 @@
     void willPostTaskToFireMessageEvent();
     void willPostTaskToFirePushSubscriptionChangeEvent();
 
-    void queueTaskToFireFetchEvent(Ref<ServiceWorkerFetch::Client>&&, std::optional<ScriptExecutionContextIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&, FetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled);
+    void queueTaskToFireFetchEvent(Ref<ServiceWorkerFetch::Client>&&, ResourceRequest&&, String&& referrer, FetchOptions&&, FetchIdentifier, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier);
     void queueTaskToPostMessage(MessageWithMessagePorts&&, ServiceWorkerOrClientData&& sourceData);
     void queueTaskToFireInstallEvent();
     void queueTaskToFireActivateEvent();

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -210,7 +210,7 @@
     }, WorkerRunLoop::defaultMode());
 }
 
-void ServiceWorkerThreadProxy::startFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier, Ref<ServiceWorkerFetch::Client>&& client, std::optional<ScriptExecutionContextIdentifier>&& clientId, ResourceRequest&& request, String&& referrer, FetchOptions&& options, bool isServiceWorkerNavigationPreloadEnabled)
+void ServiceWorkerThreadProxy::startFetch(SWServerConnectionIdentifier connectionIdentifier, FetchIdentifier fetchIdentifier, Ref<ServiceWorkerFetch::Client>&& client, ResourceRequest&& request, String&& referrer, FetchOptions&& options, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier)
 {
     RELEASE_LOG(ServiceWorker, "ServiceWorkerThreadProxy::startFetch %llu", fetchIdentifier.toUInt64());
 
@@ -221,8 +221,8 @@
 
     ASSERT(!m_ongoingFetchTasks.contains(key));
     m_ongoingFetchTasks.add(key, client.copyRef());
-    postTaskForModeToWorkerOrWorkletGlobalScope([this, protectedThis = Ref { *this }, client = WTFMove(client), clientId, request = request.isolatedCopy(), referrer = referrer.isolatedCopy(), options = options.isolatedCopy(), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled](auto&) mutable {
-        thread().queueTaskToFireFetchEvent(WTFMove(client), WTFMove(clientId), WTFMove(request), WTFMove(referrer), WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled);
+    postTaskForModeToWorkerOrWorkletGlobalScope([this, protectedThis = Ref { *this }, client = WTFMove(client), request = request.isolatedCopy(), referrer = WTFMove(referrer).isolatedCopy(), options = options.isolatedCopy(), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled, clientIdentifier = WTFMove(clientIdentifier).isolatedCopy(), resultingClientIdentifier = WTFMove(resultingClientIdentifier).isolatedCopy()](auto&) mutable {
+        thread().queueTaskToFireFetchEvent(WTFMove(client), WTFMove(request), WTFMove(referrer), WTFMove(options), fetchIdentifier, isServiceWorkerNavigationPreloadEnabled, WTFMove(clientIdentifier), WTFMove(resultingClientIdentifier));
     }, WorkerRunLoop::defaultMode());
 }
 

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -75,7 +75,7 @@
 
     WEBCORE_EXPORT void notifyNetworkStateChange(bool isOnline);
 
-    WEBCORE_EXPORT void startFetch(SWServerConnectionIdentifier, FetchIdentifier, Ref<ServiceWorkerFetch::Client>&&, std::optional<ScriptExecutionContextIdentifier>&&, ResourceRequest&&, String&& referrer, FetchOptions&&, bool isServiceWorkerNavigationPreloadEnabled);
+    WEBCORE_EXPORT void startFetch(SWServerConnectionIdentifier, FetchIdentifier, Ref<ServiceWorkerFetch::Client>&&, ResourceRequest&&, String&& referrer, FetchOptions&&, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier);
     WEBCORE_EXPORT void cancelFetch(SWServerConnectionIdentifier, FetchIdentifier);
     WEBCORE_EXPORT void convertFetchToDownload(SWServerConnectionIdentifier, FetchIdentifier);
     WEBCORE_EXPORT void continueDidReceiveFetchResponse(SWServerConnectionIdentifier, FetchIdentifier);

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -942,6 +942,8 @@
             updateAppInitiatedValueForWorkers(clientOrigin, data.lastNavigationWasAppInitiated);
     }
 
+    m_visibleClientIdToInternalClientIdMap.add(data.identifier.object().toString(), clientIdentifier);
+
     ASSERT(!m_clientsById.contains(clientIdentifier));
     m_clientsById.add(clientIdentifier, WTFMove(data));
 
@@ -979,8 +981,8 @@
     auto clientRegistrableDomain = clientOrigin.clientRegistrableDomain();
     auto appInitiatedValueBefore = clientIsAppInitiatedForRegistrableDomain(clientOrigin.clientRegistrableDomain());
 
-    bool wasRemoved = m_clientsById.remove(clientIdentifier);
-    ASSERT_UNUSED(wasRemoved, wasRemoved);
+    m_clientsById.remove(clientIdentifier);
+    m_visibleClientIdToInternalClientIdMap.remove(clientIdentifier.toString());
 
     auto clientsByRegistrableDomainIterator = m_clientsByRegistrableDomain.find(clientRegistrableDomain);
     ASSERT(clientsByRegistrableDomainIterator != m_clientsByRegistrableDomain.end());

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -226,6 +226,8 @@
     enum class ShouldSkipEvent : bool { No, Yes };
     void fireFunctionalEvent(SWServerRegistration&, CompletionHandler<void(Expected<SWServerToContextConnection*, ShouldSkipEvent>)>&&);
 
+    ScriptExecutionContextIdentifier clientIdFromVisibleClientId(const String& visibleIdentifier) const { return m_visibleClientIdToInternalClientIdMap.get(visibleIdentifier); }
+
 private:
     void validateRegistrationDomain(WebCore::RegistrableDomain, ServiceWorkerJobType, CompletionHandler<void(bool)>&&);
 
@@ -271,6 +273,7 @@
     HashMap<ScriptExecutionContextIdentifier, WeakPtr<SWServerRegistration>> m_serviceWorkerPageIdentifierToRegistrationMap;
     HashMap<ScriptExecutionContextIdentifier, ServiceWorkerClientData> m_clientsById;
     HashMap<ScriptExecutionContextIdentifier, ServiceWorkerRegistrationIdentifier> m_clientToControllingRegistration;
+    HashMap<String, ScriptExecutionContextIdentifier> m_visibleClientIdToInternalClientIdMap;
 
     UniqueRef<SWOriginStore> m_originStore;
     std::unique_ptr<RegistrationStore> m_registrationStore;

Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -87,12 +87,6 @@
         worker->contextTerminated();
 }
 
-void SWServerToContextConnection::findClientByIdentifier(uint64_t requestIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, ScriptExecutionContextIdentifier clientId)
-{
-    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
-        worker->contextConnection()->findClientByIdentifierCompleted(requestIdentifier, worker->findClientByIdentifier(clientId), false);
-}
-
 void SWServerToContextConnection::matchAll(uint64_t requestIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const ServiceWorkerClientQueryOptions& options)
 {
     if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier)) {
@@ -102,6 +96,14 @@
     }
 }
 
+void SWServerToContextConnection::findClientByVisibleIdentifier(ServiceWorkerIdentifier serviceWorkerIdentifier, const String& clientIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&& callback)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->findClientByVisibleIdentifier(clientIdentifier, WTFMove(callback));
+    else
+        callback({ });
+}
+
 void SWServerToContextConnection::claim(ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void(std::optional<ExceptionData>&&)>&& callback)
 {
     auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier);

Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -58,7 +58,6 @@
     virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
     virtual void terminateWorker(ServiceWorkerIdentifier) = 0;
     virtual void didSaveScriptsToDisk(ServiceWorkerIdentifier, const ScriptBuffer&, const HashMap<URL, ScriptBuffer>& importedScripts) = 0;
-    virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0;
     virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>&) = 0;
     virtual void firePushEvent(ServiceWorkerIdentifier, const std::optional<Vector<uint8_t>>&, CompletionHandler<void(bool)>&& callback) = 0;
 
@@ -70,11 +69,11 @@
     WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
     WEBCORE_EXPORT void skipWaiting(ServiceWorkerIdentifier, CompletionHandler<void()>&&);
     WEBCORE_EXPORT void workerTerminated(ServiceWorkerIdentifier);
-    WEBCORE_EXPORT void findClientByIdentifier(uint64_t clientIdRequestIdentifier, ServiceWorkerIdentifier, ScriptExecutionContextIdentifier);
     WEBCORE_EXPORT void matchAll(uint64_t requestIdentifier, ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&);
     WEBCORE_EXPORT void claim(ServiceWorkerIdentifier, CompletionHandler<void(std::optional<ExceptionData>&&)>&&);
     WEBCORE_EXPORT void setScriptResource(ServiceWorkerIdentifier, URL&& scriptURL, ServiceWorkerContextData::ImportedScript&&);
     WEBCORE_EXPORT void didFailHeartBeatCheck(ServiceWorkerIdentifier);
+    WEBCORE_EXPORT void findClientByVisibleIdentifier(ServiceWorkerIdentifier, const String& clientIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&&);
 
     const RegistrableDomain& registrableDomain() const { return m_registrableDomain; }
     std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier() const { return m_serviceWorkerPageIdentifier; }

Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -231,6 +231,22 @@
     return m_server->serviceWorkerClientWithOriginByID(origin(), clientId);
 }
 
+void SWServerWorker::findClientByVisibleIdentifier(const String& clientIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&& callback)
+{
+    if (!m_server) {
+        callback({ });
+        return;
+    }
+
+    auto internalIdentifier = m_server->clientIdFromVisibleClientId(clientIdentifier);
+    if (!internalIdentifier) {
+        callback({ });
+        return;
+    }
+
+    callback(findClientByIdentifier(internalIdentifier));
+}
+
 void SWServerWorker::matchAll(const ServiceWorkerClientQueryOptions& options, ServiceWorkerClientsMatchAllCallback&& callback)
 {
     ASSERT(m_server);

Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (288092 => 288093)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -103,6 +103,7 @@
     void didFinishActivation();
     void contextTerminated();
     WEBCORE_EXPORT std::optional<ServiceWorkerClientData> findClientByIdentifier(const ScriptExecutionContextIdentifier&) const;
+    WEBCORE_EXPORT void findClientByVisibleIdentifier(const String& clientIdentifier, CompletionHandler<void(std::optional<WebCore::ServiceWorkerClientData>&&)>&&);
     void matchAll(const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&);
     void setScriptResource(URL&&, ServiceWorkerContextData::ImportedScript&&);
     void didSaveScriptsToDisk(ScriptBuffer&& mainScript, HashMap<URL, ScriptBuffer>&& importedScripts);

Modified: trunk/Source/WebKit/ChangeLog (288092 => 288093)


--- trunk/Source/WebKit/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,3 +1,27 @@
+2022-01-17  Youenn Fablet  <[email protected]>
+
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        Change findByClientIdentifier into findByVisibleClientIdentifieran and make it asn async reply.
+        Update fetch event code path to send the visible IDs of the FetchEvent from network process to worker context process.
+        We store these IDs in NetworkResourceLoader so that we can change them in case of redirection for navigations. 
+
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
+        * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
+        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
 2022-01-17  Kimmo Kinnunen  <[email protected]>
 
         Frequent GPU process jetsams due to RemoteRenderingBackendProxy not claiming ownership of SharedMemory buffers

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -145,6 +145,8 @@
 #if ENABLE(SERVICE_WORKER)
     void startWithServiceWorker();
     void serviceWorkerDidNotHandle(ServiceWorkerFetchTask*);
+    void setResultingClientIdentifier(String&& identifier) { m_resultingClientIdentifier = WTFMove(identifier); }
+    const String& resultingClientIdentifier() const { return m_resultingClientIdentifier; }
 #endif
 
     std::optional<WebCore::ResourceError> doCrossOriginOpenerHandlingOfResponse(const WebCore::ResourceResponse&);
@@ -255,6 +257,7 @@
     std::optional<NetworkActivityTracker> m_networkActivityTracker;
 #if ENABLE(SERVICE_WORKER)
     std::unique_ptr<ServiceWorkerFetchTask> m_serviceWorkerFetchTask;
+    String m_resultingClientIdentifier;
 #endif
     NetworkResourceLoadIdentifier m_resourceLoadID;
     WebCore::ResourceResponse m_redirectResponse;

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -151,7 +151,12 @@
     auto request = m_currentRequest;
     cleanHTTPRequestHeadersForAccessControl(request, m_loader.parameters().httpHeadersToKeep);
 
-    bool isSent = sendToServiceWorker(Messages::WebSWContextManagerConnection::StartFetch { m_serverConnectionIdentifier, m_serviceWorkerIdentifier, m_fetchIdentifier, request, options, IPC::FormDataReference { m_currentRequest.httpBody() }, referrer, m_preloader && m_preloader->isServiceWorkerNavigationPreloadEnabled() });
+    String clientIdentifier;
+    if (m_loader.parameters().options.mode != FetchOptions::Mode::Navigate) {
+        if (auto identifier = m_loader.parameters().options.clientIdentifier)
+            clientIdentifier = identifier->toString();
+    }
+    bool isSent = sendToServiceWorker(Messages::WebSWContextManagerConnection::StartFetch { m_serverConnectionIdentifier, m_serviceWorkerIdentifier, m_fetchIdentifier, request, options, IPC::FormDataReference { m_currentRequest.httpBody() }, referrer, m_preloader && m_preloader->isServiceWorkerNavigationPreloadEnabled(), clientIdentifier, m_loader.resultingClientIdentifier() });
     ASSERT_UNUSED(isSent, isSent);
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -175,6 +175,7 @@
 
         serviceWorkerRegistrationIdentifier = registration->identifier();
         controlClient(*loader.parameters().options.clientIdentifier, *registration, request);
+        loader.setResultingClientIdentifier(loader.parameters().options.clientIdentifier->toString());
     } else {
         if (!loader.parameters().serviceWorkerRegistrationIdentifier)
             return nullptr;

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -155,11 +155,6 @@
     m_connection.networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::TerminateUnresponsiveServiceWorkerProcesses { webProcessIdentifier() }, 0);
 }
 
-void WebSWServerToContextConnection::findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<ServiceWorkerClientData>& data, bool hasSecurityError)
-{
-    send(Messages::WebSWContextManagerConnection::FindClientByIdentifierCompleted { requestIdentifier, data, hasSecurityError });
-}
-
 void WebSWServerToContextConnection::matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>& clientsData)
 {
     send(Messages::WebSWContextManagerConnection::MatchAllCompleted { requestIdentifier, clientsData });

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -95,7 +95,6 @@
     void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
     void terminateWorker(WebCore::ServiceWorkerIdentifier) final;
     void didSaveScriptsToDisk(WebCore::ServiceWorkerIdentifier, const WebCore::ScriptBuffer&, const HashMap<URL, WebCore::ScriptBuffer>& importedScripts) final;
-    void findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final;
     void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientData>&) final;
     void firePushEvent(WebCore::ServiceWorkerIdentifier, const std::optional<Vector<uint8_t>>&, CompletionHandler<void(bool)>&&) final;
 

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in (288092 => 288093)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in	2022-01-17 10:49:40 UTC (rev 288093)
@@ -32,7 +32,7 @@
     SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier identifier, bool hasPendingEvents)
     SkipWaiting(WebCore::ServiceWorkerIdentifier identifier) -> () Async
     WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier)
-    FindClientByIdentifier(uint64_t requestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::ScriptExecutionContextIdentifier clientIdentifier)
+    FindClientByVisibleIdentifier(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String clientIdentifier) -> (std::optional<WebCore::ServiceWorkerClientData> data) Async
     MatchAll(uint64_t matchAllRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientQueryOptions options);
     Claim(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier) -> (std::optional<WebCore::ExceptionData> result) Async
     SetScriptResource(WebCore::ServiceWorkerIdentifier identifier, URL scriptURL, WebCore::ServiceWorkerContextData::ImportedScript script)

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h (288092 => 288093)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -81,7 +81,7 @@
 
 - (void)_doAfterReceivingEditDragSnapshotForTesting:(dispatch_block_t)action;
 
-- (void)_triggerSystemPreviewActionOnElement:(uint64_t)elementID document:(uint64_t)documentID page:(uint64_t)pageID;
+- (void)_triggerSystemPreviewActionOnElement:(uint64_t)elementID document:(NSString*)documentID page:(uint64_t)pageID;
 
 - (void)_setDeviceOrientationUserPermissionHandlerForTesting:(BOOL (^)(void))handler;
 

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm (288092 => 288093)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm	2022-01-17 10:49:40 UTC (rev 288093)
@@ -448,7 +448,7 @@
     [_contentView _simulateTextEntered:text];
 }
 
-- (void)_triggerSystemPreviewActionOnElement:(uint64_t)elementID document:(uint64_t)documentID page:(uint64_t)pageID
+- (void)_triggerSystemPreviewActionOnElement:(uint64_t)elementID document:(NSString*)documentID page:(uint64_t)pageID
 {
 #if USE(SYSTEM_PREVIEW)
     if (_page) {

Modified: trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm (288092 => 288093)


--- trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm	2022-01-17 10:49:40 UTC (rev 288093)
@@ -301,11 +301,16 @@
     page().systemPreviewActionTriggered(m_systemPreviewInfo, "_apple_ar_quicklook_button_tapped");
 }
 
-void SystemPreviewController::triggerSystemPreviewActionWithTargetForTesting(uint64_t elementID, uint64_t documentID, uint64_t pageID)
+void SystemPreviewController::triggerSystemPreviewActionWithTargetForTesting(uint64_t elementID, NSString* documentID, uint64_t pageID)
 {
+    auto uuid = UUID::parse(String(documentID));
+    ASSERT(uuid);
+    if (!uuid)
+        return;
+
     m_systemPreviewInfo.isPreview = true;
     m_systemPreviewInfo.element.elementIdentifier = makeObjectIdentifier<WebCore::ElementIdentifierType>(elementID);
-    m_systemPreviewInfo.element.documentIdentifier = WebCore::ScriptExecutionContextIdentifier { makeObjectIdentifier<WebCore::ScriptExecutionContextIdentifierType>(documentID), m_webPageProxy.process().coreProcessIdentifier() };
+    m_systemPreviewInfo.element.documentIdentifier = { *uuid, m_webPageProxy.process().coreProcessIdentifier() };
     m_systemPreviewInfo.element.webPageIdentifier = makeObjectIdentifier<WebCore::PageIdentifierType>(pageID);
     triggerSystemPreviewAction();
 }

Modified: trunk/Source/WebKit/UIProcess/SystemPreviewController.h (288092 => 288093)


--- trunk/Source/WebKit/UIProcess/SystemPreviewController.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/UIProcess/SystemPreviewController.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -61,7 +61,7 @@
 
     void triggerSystemPreviewAction();
 
-    void triggerSystemPreviewActionWithTargetForTesting(uint64_t elementID, uint64_t frameID, uint64_t pageID);
+    void triggerSystemPreviewActionWithTargetForTesting(uint64_t elementID, NSString* documentID, uint64_t pageID);
 
 private:
     WebPageProxy& m_webPageProxy;

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -129,7 +129,7 @@
         auto documentIDKey = adoptWK(WKStringCreateWithUTF8CString("id"));
         auto documentURLKey = adoptWK(WKStringCreateWithUTF8CString("url"));
 
-        auto documentIDValue = adoptWK(WKUInt64Create(it.key));
+        auto documentIDValue = adoptWK(WebKit::toCopiedAPI(it.key.toString()));
         auto documentURLValue = adoptWK(WebKit::toCopiedAPI(it.value));
 
         WKDictionarySetItem(urlInfo.get(), documentIDKey.get(), documentIDValue.get());

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -338,7 +338,7 @@
     DocumentIDToURLMap result;
 
     for (const auto* document : Document::allDocuments())
-        result.add(document->identifier().object().toUInt64(), document->url().string());
+        result.add(document->identifier().object(), document->url().string());
 
     if (excludeDocumentsInPageGroupPages) {
         Page::forEachPage([&](Page& page) {
@@ -345,7 +345,7 @@
             for (auto* frame = &page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
                 if (!frame->document())
                     continue;
-                result.remove(frame->document()->identifier().object().toUInt64());
+                result.remove(frame->document()->identifier().object());
             }
         });
     }

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -110,7 +110,7 @@
     std::optional<UUID> webNotificationID(JSContextRef, JSValueRef);
     Ref<API::Data> createWebDataFromUint8Array(JSContextRef, JSValueRef);
     
-    typedef HashMap<uint64_t, String> DocumentIDToURLMap;
+    typedef HashMap<UUID, String> DocumentIDToURLMap;
     DocumentIDToURLMap liveDocumentURLs(bool excludeDocumentsInPageGroupPages);
 
     // Garbage collection API

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -241,7 +241,7 @@
         serviceWorkerThreadProxy->continueDidReceiveFetchResponse(serverConnectionIdentifier, fetchIdentifier);
 }
 
-void WebSWContextManagerConnection::startFetch(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer, bool isServiceWorkerNavigationPreloadEnabled)
+void WebSWContextManagerConnection::startFetch(SWServerConnectionIdentifier serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, FetchIdentifier fetchIdentifier, ResourceRequest&& request, FetchOptions&& options, IPC::FormDataReference&& formData, String&& referrer, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier)
 {
     auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
     if (!serviceWorkerThreadProxy) {
@@ -257,10 +257,9 @@
     }
 
     auto client = WebServiceWorkerFetchTaskClient::create(m_connectionToNetworkProcess.copyRef(), serviceWorkerIdentifier, serverConnectionIdentifier, fetchIdentifier, request.requester() == ResourceRequest::Requester::Main);
-    std::optional<ScriptExecutionContextIdentifier> clientId = options.clientIdentifier;
 
     request.setHTTPBody(formData.takeData());
-    serviceWorkerThreadProxy->startFetch(serverConnectionIdentifier, fetchIdentifier, WTFMove(client), WTFMove(clientId), WTFMove(request), WTFMove(referrer), WTFMove(options), isServiceWorkerNavigationPreloadEnabled);
+    serviceWorkerThreadProxy->startFetch(serverConnectionIdentifier, fetchIdentifier, WTFMove(client), WTFMove(request), WTFMove(referrer), WTFMove(options), isServiceWorkerNavigationPreloadEnabled, WTFMove(clientIdentifier), WTFMove(resultingClientIdentifier));
 }
 
 void WebSWContextManagerConnection::postMessageToServiceWorker(ServiceWorkerIdentifier destinationIdentifier, MessageWithMessagePorts&& message, ServiceWorkerOrClientData&& sourceData)
@@ -333,24 +332,11 @@
     m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::WorkerTerminated(serviceWorkerIdentifier), 0);
 }
 
-void WebSWContextManagerConnection::findClientByIdentifier(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, ScriptExecutionContextIdentifier clientIdentifier, FindClientByIdentifierCallback&& callback)
+void WebSWContextManagerConnection::findClientByVisibleIdentifier(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, const String& clientIdentifier, FindClientByIdentifierCallback&& callback)
 {
-    auto requestIdentifier = ++m_previousRequestIdentifier;
-    m_findClientByIdentifierRequests.add(requestIdentifier, WTFMove(callback));
-    m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::FindClientByIdentifier { requestIdentifier, serviceWorkerIdentifier, clientIdentifier }, 0);
+    m_connectionToNetworkProcess->sendWithAsyncReply(Messages::WebSWServerToContextConnection::FindClientByVisibleIdentifier { serviceWorkerIdentifier, clientIdentifier }, WTFMove(callback));
 }
 
-void WebSWContextManagerConnection::findClientByIdentifierCompleted(uint64_t requestIdentifier, std::optional<ServiceWorkerClientData>&& clientData, bool hasSecurityError)
-{
-    if (auto callback = m_findClientByIdentifierRequests.take(requestIdentifier)) {
-        if (hasSecurityError) {
-            callback(Exception { SecurityError });
-            return;
-        }
-        callback(WTFMove(clientData));
-    }
-}
-
 void WebSWContextManagerConnection::matchAll(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, const ServiceWorkerClientQueryOptions& options, ServiceWorkerClientsMatchAllCallback&& callback)
 {
     auto requestIdentifier = ++m_previousRequestIdentifier;

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2022-01-17 10:49:40 UTC (rev 288093)
@@ -77,7 +77,7 @@
     void didFinishActivation(WebCore::ServiceWorkerIdentifier) final;
     void setServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier, bool) final;
     void workerTerminated(WebCore::ServiceWorkerIdentifier) final;
-    void findClientByIdentifier(WebCore::ServiceWorkerIdentifier, WebCore::ScriptExecutionContextIdentifier, FindClientByIdentifierCallback&&) final;
+    void findClientByVisibleIdentifier(WebCore::ServiceWorkerIdentifier, const String&, FindClientByIdentifierCallback&&) final;
     void matchAll(WebCore::ServiceWorkerIdentifier, const WebCore::ServiceWorkerClientQueryOptions&, WebCore::ServiceWorkerClientsMatchAllCallback&&) final;
     void claim(WebCore::ServiceWorkerIdentifier, CompletionHandler<void(WebCore::ExceptionOr<void>&&)>&&) final;
     void skipWaiting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&) final;
@@ -90,7 +90,7 @@
     void serviceWorkerFailedToStart(std::optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
     void installServiceWorker(WebCore::ServiceWorkerContextData&&, WebCore::ServiceWorkerData&&, String&& userAgent, WebCore::WorkerThreadMode);
     void updateAppInitiatedValue(WebCore::ServiceWorkerIdentifier, WebCore::LastNavigationWasAppInitiated);
-    void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer, bool isServiceWorkerNavigationPreloadEnabled);
+    void startFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&, String&& referrer, bool isServiceWorkerNavigationPreloadEnabled, String&& clientIdentifier, String&& resultingClientIdentifier);
     void cancelFetch(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier);
     void continueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::FetchIdentifier);
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerOrClientData&& sourceData);
@@ -101,7 +101,6 @@
 #if ENABLE(SHAREABLE_RESOURCE) && PLATFORM(COCOA)
     void didSaveScriptsToDisk(WebCore::ServiceWorkerIdentifier, WebCore::ScriptBuffer&&, HashMap<URL, WebCore::ScriptBuffer>&& importedScripts);
 #endif
-    void findClientByIdentifierCompleted(uint64_t requestIdentifier, std::optional<WebCore::ServiceWorkerClientData>&&, bool hasSecurityError);
     void matchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData>&&);
     void setUserAgent(String&& userAgent);
     void close();
@@ -117,7 +116,6 @@
     WebCore::PageIdentifier m_pageID;
 
     HashSet<std::unique_ptr<ServiceWorkerFrameLoaderClient>> m_loaders;
-    HashMap<uint64_t, FindClientByIdentifierCallback> m_findClientByIdentifierRequests;
     HashMap<uint64_t, WebCore::ServiceWorkerClientsMatchAllCallback> m_matchAllRequests;
     uint64_t m_previousRequestIdentifier { 0 };
     String m_userAgent;

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (288092 => 288093)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2022-01-17 10:49:40 UTC (rev 288093)
@@ -25,7 +25,7 @@
 messages -> WebSWContextManagerConnection NotRefCounted {
     InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData, struct WebCore::ServiceWorkerData workerData, String userAgent, enum:bool WebCore::WorkerThreadMode workerThreadMode)
     UpdateAppInitiatedValue(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum:bool WebCore::LastNavigationWasAppInitiated lastNavigationWasAppInitiated)
-    StartFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer, bool isServiceWorkerNavigationPreloadEnabled)
+    StartFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody, String referrer, bool isServiceWorkerNavigationPreloadEnabled, String clientIdentifer, String resutlingClientIdentifier)
     CancelFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier)
     ContinueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::FetchIdentifier fetchIdentifier)
     PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientData sourceData)
@@ -37,7 +37,6 @@
 #if ENABLE(SHAREABLE_RESOURCE) && PLATFORM(COCOA)
     DidSaveScriptsToDisk(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::ScriptBuffer script, HashMap<URL, WebCore::ScriptBuffer> importedScripts);
 #endif
-    FindClientByIdentifierCompleted(uint64_t clientIdRequestIdentifier, std::optional<WebCore::ServiceWorkerClientData> data, bool hasSecurityError)
     MatchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientData> clientsData)
     SetUserAgent(String userAgent)
     UpdatePreferencesStore(struct WebKit::WebPreferencesStore store)

Modified: trunk/Tools/ChangeLog (288092 => 288093)


--- trunk/Tools/ChangeLog	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Tools/ChangeLog	2022-01-17 10:49:40 UTC (rev 288093)
@@ -1,3 +1,14 @@
+2022-01-17  Youenn Fablet  <[email protected]>
+
+        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=235070
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/UUID.cpp:
+        * TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm:
+
 2022-01-17  Carlos Garcia Campos  <[email protected]>
 
         [GTK][a11y] Stop using isolated tree for the ATSPI implementation

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (288092 => 288093)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2022-01-17 10:49:40 UTC (rev 288093)
@@ -209,6 +209,7 @@
 		41661C662355E85E00D33C27 /* getUserMedia-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */; };
 		4181C62D255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4181C62C255A891100AEB0FF /* RTCRtpSFrameTransformerTests.cpp */; };
 		41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */; };
+		41D2A21F27906F9F0088FCCE /* UUID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144D40EC221B46A7004B474F /* UUID.cpp */; };
 		41E67A8525D16E83007B0A4C /* STUNMessageParsingTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E67A8425D16E83007B0A4C /* STUNMessageParsingTest.cpp */; };
 		44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */; };
 		4433A396208044140091ED57 /* SynchronousTimeoutTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */; };
@@ -5403,6 +5404,7 @@
 				E3C21A7C21B25CA2003B31A3 /* URLExtras.mm in Sources */,
 				E3A1E78521B25B91008C6007 /* URLParser.cpp in Sources */,
 				7C83E03B1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,
+				41D2A21F27906F9F0088FCCE /* UUID.cpp in Sources */,
 				7C83DF4C1D0A590C00FEBCF3 /* Vector.cpp in Sources */,
 				37C7CC2D1EA4146B007BD956 /* WeakLinking.cpp in Sources */,
 				57C3FA661F7C248F009D4B80 /* WeakPtr.cpp in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp (288092 => 288093)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp	2022-01-17 10:49:40 UTC (rev 288093)
@@ -31,3 +31,26 @@
 {
     EXPECT_EQ(bootSessionUUIDString(), bootSessionUUIDString());
 }
+
+TEST(WTF, TestUUIDParsing)
+{
+    auto created  = UUID::create();
+    auto value = UUID::parse(created.toString());
+    EXPECT_TRUE(!!value);
+    EXPECT_EQ(created, *value);
+
+    // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
+    value = UUID::parse("12345678-9abc-5de0-89AB-0123456789ab");
+    EXPECT_FALSE(!!value);
+
+    value = UUID::parse("12345678-9abc-4dea-79AB-0123456789ab");
+    EXPECT_FALSE(!!value);
+
+    value = UUID::parse("12345678-9abc-4de0-89ab-0123456789ab");
+    EXPECT_TRUE(!!value);
+    EXPECT_TRUE(value->toString() == "12345678-9abc-4de0-89ab-0123456789ab");
+
+    value = UUID::parse("6ef944c1-5cb8-48aa-Ad12-C5f823f005c3");
+    EXPECT_TRUE(!!value);
+    EXPECT_TRUE(value->toString() == "6ef944c1-5cb8-48aa-ad12-c5f823f005c3");
+}

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm (288092 => 288093)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm	2022-01-17 09:50:12 UTC (rev 288092)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreview.mm	2022-01-17 10:49:40 UTC (rev 288093)
@@ -37,7 +37,6 @@
 static bool hasTriggerInfo;
 static bool wasTriggered;
 static uint64_t elementID;
-static uint64_t documentID;
 static uint64_t pageID;
 
 @interface TestSystemPreviewTriggeredHandler : NSObject <WKScriptMessageHandler>
@@ -44,12 +43,13 @@
 @end
 
 @implementation TestSystemPreviewTriggeredHandler
+String documentID;
 
 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
 {
     if ([message.body[@"message"] isEqualToString:@"loaded"]) {
         elementID = [message.body[@"elementID"] unsignedIntValue];
-        documentID = [message.body[@"documentID"] unsignedIntValue];
+        documentID = message.body[@"documentID"];
         pageID = [message.body[@"pageID"] unsignedIntValue];
         hasTriggerInfo = true;
     } else if ([message.body[@"message"] isEqualToString:@"triggered"]) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to