Title: [287339] trunk
Revision
287339
Author
beid...@apple.com
Date
2021-12-21 18:31:40 -0800 (Tue, 21 Dec 2021)

Log Message

Make Notification identifiers be a UUID string instead of a uint64_t
https://bugs.webkit.org/show_bug.cgi?id=234534

Reviewed by Alex Christensen.
Source/WebCore:

No new tests (Refactor, covered by existing tests)

Before this patch, Notifications were tagged with an in-WebContent-process-unique identifier
and also tagged with a UIProcess-unique identifier.

There were maps between these two identifiers in WebKit, and both of them were exposed via API/SPI
(e.g. through the injected bundle), necessitating maps between them in WKTR as well.

This simplifies things by making a UUID identifier in the WebContent process that can be treated
as the One True Identifier within WebKit.

There's existing SPI clients that rely on the UIProcess-unique uin64_t identifier, so we sadly
couldn't get rid of that entirely. But this patch still puts us in a much better place.

* Modules/notifications/Notification.cpp:
(WebCore::Notification::show):
(WebCore::Notification::close):
(WebCore::Notification::stop):
(WebCore::Notification::data const):
(WebCore::Notification::dataWithoutNotificationID const): Deleted.
* Modules/notifications/Notification.h:

* Modules/notifications/NotificationClient.h:
(WebCore::NotificationClient::clearNotifications): Deleted.
* Modules/notifications/NotificationData.h:
(WebCore::NotificationData::decode):

Source/WebKit:

This is mostly changing a whole bunch of uint64_ts to Strings, but also gets rid of lots of weird
and fragile maps.

* NetworkProcess/Notifications/NetworkNotificationManager.cpp:
(WebKit::NetworkNotificationManager::cancelNotification):
(WebKit::NetworkNotificationManager::clearNotifications):
(WebKit::NetworkNotificationManager::didDestroyNotification):
* NetworkProcess/Notifications/NetworkNotificationManager.h:
* Shared/Notifications/NotificationManagerMessageHandler.h:
* Shared/Notifications/NotificationManagerMessageHandler.messages.in:

* UIProcess/API/C/WKNotification.cpp:
(WKNotificationCopyCoreIDForTesting):
* UIProcess/API/C/WKNotification.h:

* UIProcess/API/C/WKNotificationManager.cpp:
(WKNotificationManagerProviderDidClickNotification_b):
(WKNotificationManagerProviderDidRemoveNotificationPolicies):
(WKNotificationManagerGetLocalIDForTesting): Deleted.
* UIProcess/API/C/WKNotificationManager.h:

* UIProcess/Notifications/WebNotification.cpp:
(WebKit::WebNotification::WebNotification):
* UIProcess/Notifications/WebNotification.h:
(WebKit::WebNotification::create):
(WebKit::WebNotification::notificationID const):
(WebKit::WebNotification::coreNotificationID const):
(WebKit::WebNotification::pageIdentifier const):

* UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp:
(WebKit::WebNotificationManagerMessageHandler::cancelNotification):
(WebKit::WebNotificationManagerMessageHandler::clearNotifications):
(WebKit::WebNotificationManagerMessageHandler::didDestroyNotification):
* UIProcess/Notifications/WebNotificationManagerMessageHandler.h:

* UIProcess/Notifications/WebNotificationManagerProxy.cpp:
(WebKit::WebNotificationManagerProxy::show):
(WebKit::WebNotificationManagerProxy::cancel):
(WebKit::WebNotificationManagerProxy::didDestroyNotification):
(WebKit::pageIDsMatch):
(WebKit::pageAndNotificationIDsMatch):
(WebKit::WebNotificationManagerProxy::clearNotifications):
(WebKit::WebNotificationManagerProxy::providerDidShowNotification):
(WebKit::WebNotificationManagerProxy::providerDidClickNotification):
(WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
(WebKit::generateGlobalNotificationID): Deleted.
(WebKit::WebNotificationManagerProxy::notificationLocalIDForTesting): Deleted.
* UIProcess/Notifications/WebNotificationManagerProxy.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::cancelNotification):
(WebKit::WebPageProxy::clearNotifications):
(WebKit::WebPageProxy::didDestroyNotification):
* UIProcess/WebPageProxy.h:

* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
(WKBundleCopyWebNotificationID):
(WKBundleGetWebNotificationID): Deleted.
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::webNotificationID):
* WebProcess/InjectedBundle/InjectedBundle.h:

* WebProcess/Notifications/WebNotificationManager.cpp:
(WebKit::WebNotificationManager::show):
(WebKit::WebNotificationManager::cancel):
(WebKit::WebNotificationManager::didDestroyNotification):
(WebKit::WebNotificationManager::didShowNotification):
(WebKit::WebNotificationManager::didClickNotification):
(WebKit::WebNotificationManager::didCloseNotifications):
(WebKit::generateNotificationID): Deleted.
(WebKit::WebNotificationManager::notificationIDForTesting): Deleted.
(WebKit::WebNotificationManager::clearNotifications): Deleted.
(WebKit::WebNotificationManager::removeNotificationFromContextMap): Deleted.
* WebProcess/Notifications/WebNotificationManager.h:
* WebProcess/Notifications/WebNotificationManager.messages.in:

* WebProcess/WebCoreSupport/WebNotificationClient.cpp:
(WebKit::WebNotificationClient::show):
(WebKit::WebNotificationClient::cancel):
(WebKit::WebNotificationClient::notificationObjectDestroyed):
(WebKit::WebNotificationClient::clearNotifications): Deleted.
* WebProcess/WebCoreSupport/WebNotificationClient.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebNotificationClient.h:
* WebCoreSupport/WebNotificationClient.mm:
(WebNotificationClient::show):
(WebNotificationClient::cancel):
(WebNotificationClient::notificationObjectDestroyed):
(WebNotificationClient::clearNotifications): Deleted.

Source/WTF:

Add a new form of Identified that uses a UUID String as the identifier.

* wtf/Identified.h:
(WTF::UUIDIdentified::UUIDIdentified):

Tools:

Where possible, use the String UUID identifier.
This gets rid of lots of weird maps and cleans up flaky situations that could occasionally occur.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::postSimulateWebNotificationClick):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:

* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::simulateWebNotificationClick):

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::simulateWebNotificationClick):
* WebKitTestRunner/TestController.h:

* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):

* WebKitTestRunner/WebNotificationProvider.cpp:
(WTR::WebNotificationProvider::~WebNotificationProvider):
(WTR::WebNotificationProvider::showWebNotification):
(WTR::WebNotificationProvider::closeWebNotification):
(WTR::WebNotificationProvider::addNotificationManager):
(WTR::WebNotificationProvider::removeNotificationManager):
(WTR::WebNotificationProvider::simulateWebNotificationClick):
(WTR::WebNotificationProvider::reset):
(WTR::removeGlobalIDFromIDMap): Deleted.
* WebKitTestRunner/WebNotificationProvider.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (287338 => 287339)


--- trunk/Source/WTF/ChangeLog	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WTF/ChangeLog	2021-12-22 02:31:40 UTC (rev 287339)
@@ -1,3 +1,15 @@
+2021-12-21  Brady Eidson  <beid...@apple.com>
+
+        Make Notification identifiers be a UUID string instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=234534
+
+        Reviewed by Alex Christensen.
+
+        Add a new form of Identified that uses a UUID String as the identifier.
+        
+        * wtf/Identified.h:
+        (WTF::UUIDIdentified::UUIDIdentified):
+
 2021-12-21  Sam Weinig  <wei...@apple.com>
 
         Add support for premultiplied alpha interpolated gradients and defaulted off option to use them for CSS Gradients

Modified: trunk/Source/WTF/wtf/Identified.h (287338 => 287339)


--- trunk/Source/WTF/wtf/Identified.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WTF/wtf/Identified.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -27,6 +27,7 @@
 
 #include <atomic>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/UUID.h>
 
 namespace WTF {
 
@@ -104,7 +105,27 @@
     }
 };
 
+template <typename T>
+class UUIDIdentified : public IdentifiedBase<String, T> {
+protected:
+    UUIDIdentified()
+        : IdentifiedBase<String, T>(createCanonicalUUIDString())
+    {
+    }
+
+    UUIDIdentified(const UUIDIdentified& other)
+        : IdentifiedBase<String, T>(other.isolatedCopy())
+    {
+    }
+
+    explicit UUIDIdentified(const String& identifier)
+        : IdentifiedBase<String, T>(identifier.isolatedCopy())
+    {
+    }
+};
+
 } // namespace WTF
 
 using WTF::Identified;
 using WTF::ThreadSafeIdentified;
+using WTF::UUIDIdentified;

Modified: trunk/Source/WebCore/ChangeLog (287338 => 287339)


--- trunk/Source/WebCore/ChangeLog	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebCore/ChangeLog	2021-12-22 02:31:40 UTC (rev 287339)
@@ -1,3 +1,37 @@
+2021-12-21  Brady Eidson  <beid...@apple.com>
+
+        Make Notification identifiers be a UUID string instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=234534
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Refactor, covered by existing tests)
+
+        Before this patch, Notifications were tagged with an in-WebContent-process-unique identifier
+        and also tagged with a UIProcess-unique identifier.
+        
+        There were maps between these two identifiers in WebKit, and both of them were exposed via API/SPI
+        (e.g. through the injected bundle), necessitating maps between them in WKTR as well.
+        
+        This simplifies things by making a UUID identifier in the WebContent process that can be treated
+        as the One True Identifier within WebKit.
+        
+        There's existing SPI clients that rely on the UIProcess-unique uin64_t identifier, so we sadly
+        couldn't get rid of that entirely. But this patch still puts us in a much better place.
+
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::show):
+        (WebCore::Notification::close):
+        (WebCore::Notification::stop):
+        (WebCore::Notification::data const):
+        (WebCore::Notification::dataWithoutNotificationID const): Deleted.
+        * Modules/notifications/Notification.h:
+
+        * Modules/notifications/NotificationClient.h:
+        (WebCore::NotificationClient::clearNotifications): Deleted.
+        * Modules/notifications/NotificationData.h:
+        (WebCore::NotificationData::decode):
+
 2021-12-21  Alan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Compute visual geometry for InlineDisplay::Line

Modified: trunk/Source/WebCore/Modules/notifications/Notification.cpp (287338 => 287339)


--- trunk/Source/WebCore/Modules/notifications/Notification.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebCore/Modules/notifications/Notification.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -102,7 +102,7 @@
         dispatchErrorEvent();
         return;
     }
-    if (client.show(this))
+    if (client.show(*this))
         m_state = Showing;
 }
 
@@ -113,7 +113,7 @@
         break;
     case Showing: {
         if (auto* page = document()->page())
-            NotificationController::from(page)->client().cancel(this);
+            NotificationController::from(page)->client().cancel(*this);
         break;
     }
     case Closed:
@@ -136,7 +136,7 @@
     ActiveDOMObject::stop();
 
     if (auto* page = document()->page())
-        NotificationController::from(page)->client().notificationObjectDestroyed(this);
+        NotificationController::from(page)->client().notificationObjectDestroyed(*this);
 }
 
 void Notification::suspend(ReasonForSuspension)
@@ -225,7 +225,7 @@
     return m_state == Showing && m_hasRelevantEventListener;
 }
 
-NotificationData Notification::dataWithoutNotificationID() const
+NotificationData Notification::data() const
 {
     return {
         m_title,
@@ -235,7 +235,7 @@
         m_lang,
         m_direction,
         scriptExecutionContext()->securityOrigin()->toString(),
-        0
+        identifier(),
     };
 }
 

Modified: trunk/Source/WebCore/Modules/notifications/Notification.h (287338 => 287339)


--- trunk/Source/WebCore/Modules/notifications/Notification.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebCore/Modules/notifications/Notification.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -37,6 +37,7 @@
 #include "EventTarget.h"
 #include "NotificationDirection.h"
 #include "NotificationPermission.h"
+#include <wtf/Identified.h>
 #include <wtf/URL.h>
 #include "WritingMode.h"
 
@@ -48,7 +49,7 @@
 
 struct NotificationData;
 
-class Notification final : public ThreadSafeRefCounted<Notification>, public ActiveDOMObject, public EventTargetWithInlineData {
+class Notification final : public ThreadSafeRefCounted<Notification>, public ActiveDOMObject, public EventTargetWithInlineData, public UUIDIdentified<Notification> {
     WTF_MAKE_ISO_ALLOCATED_EXPORT(Notification, WEBCORE_EXPORT);
 public:
     using Permission = NotificationPermission;
@@ -89,7 +90,7 @@
 
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
 
-    WEBCORE_EXPORT NotificationData dataWithoutNotificationID() const;
+    WEBCORE_EXPORT NotificationData data() const;
 
     using ThreadSafeRefCounted::ref;
     using ThreadSafeRefCounted::deref;

Modified: trunk/Source/WebCore/Modules/notifications/NotificationClient.h (287338 => 287339)


--- trunk/Source/WebCore/Modules/notifications/NotificationClient.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebCore/Modules/notifications/NotificationClient.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -47,19 +47,15 @@
     using PermissionHandler = CompletionHandler<void(Permission)>;
 
     // Requests that a notification be shown.
-    virtual bool show(Notification*) = 0;
+    virtual bool show(Notification&) = 0;
 
     // Requests that a notification that has already been shown be canceled.
-    virtual void cancel(Notification*) = 0;
+    virtual void cancel(Notification&) = 0;
 
-    // When the user closes a page, or quits the client application, all of the page's
-    // associated notifications are cleared.
-    virtual void clearNotifications(ScriptExecutionContext*) { }
-    
     // Informs the presenter that a Notification object has been destroyed
     // (such as by a page transition). The presenter may continue showing
     // the notification, but must not attempt to call the event handlers.
-    virtual void notificationObjectDestroyed(Notification*) = 0;
+    virtual void notificationObjectDestroyed(Notification&) = 0;
 
     // Informs the presenter the controller attached to the page has been destroyed.
     virtual void notificationControllerDestroyed() = 0;

Modified: trunk/Source/WebCore/Modules/notifications/NotificationData.h (287338 => 287339)


--- trunk/Source/WebCore/Modules/notifications/NotificationData.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebCore/Modules/notifications/NotificationData.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -43,7 +43,7 @@
     String language;
     WebCore::NotificationDirection direction;
     String originString;
-    uint64_t notificationID;
+    String notificationID;
 };
 
 template<class Encoder>
@@ -90,7 +90,7 @@
     if (!originString)
         return std::nullopt;
 
-    std::optional<uint64_t> notificationID;
+    std::optional<String> notificationID;
     decoder >> notificationID;
     if (!notificationID)
         return std::nullopt;

Modified: trunk/Source/WebKit/ChangeLog (287338 => 287339)


--- trunk/Source/WebKit/ChangeLog	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/ChangeLog	2021-12-22 02:31:40 UTC (rev 287339)
@@ -1,3 +1,95 @@
+2021-12-21  Brady Eidson  <beid...@apple.com>
+
+        Make Notification identifiers be a UUID string instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=234534
+
+        Reviewed by Alex Christensen.
+        
+        This is mostly changing a whole bunch of uint64_ts to Strings, but also gets rid of lots of weird
+        and fragile maps.
+
+        * NetworkProcess/Notifications/NetworkNotificationManager.cpp:
+        (WebKit::NetworkNotificationManager::cancelNotification):
+        (WebKit::NetworkNotificationManager::clearNotifications):
+        (WebKit::NetworkNotificationManager::didDestroyNotification):
+        * NetworkProcess/Notifications/NetworkNotificationManager.h:
+        * Shared/Notifications/NotificationManagerMessageHandler.h:
+        * Shared/Notifications/NotificationManagerMessageHandler.messages.in:
+
+        * UIProcess/API/C/WKNotification.cpp:
+        (WKNotificationCopyCoreIDForTesting):
+        * UIProcess/API/C/WKNotification.h:
+
+        * UIProcess/API/C/WKNotificationManager.cpp:
+        (WKNotificationManagerProviderDidClickNotification_b):
+        (WKNotificationManagerProviderDidRemoveNotificationPolicies):
+        (WKNotificationManagerGetLocalIDForTesting): Deleted.
+        * UIProcess/API/C/WKNotificationManager.h:
+
+        * UIProcess/Notifications/WebNotification.cpp:
+        (WebKit::WebNotification::WebNotification):
+        * UIProcess/Notifications/WebNotification.h:
+        (WebKit::WebNotification::create):
+        (WebKit::WebNotification::notificationID const):
+        (WebKit::WebNotification::coreNotificationID const):
+        (WebKit::WebNotification::pageIdentifier const):
+
+        * UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp:
+        (WebKit::WebNotificationManagerMessageHandler::cancelNotification):
+        (WebKit::WebNotificationManagerMessageHandler::clearNotifications):
+        (WebKit::WebNotificationManagerMessageHandler::didDestroyNotification):
+        * UIProcess/Notifications/WebNotificationManagerMessageHandler.h:
+
+        * UIProcess/Notifications/WebNotificationManagerProxy.cpp:
+        (WebKit::WebNotificationManagerProxy::show):
+        (WebKit::WebNotificationManagerProxy::cancel):
+        (WebKit::WebNotificationManagerProxy::didDestroyNotification):
+        (WebKit::pageIDsMatch):
+        (WebKit::pageAndNotificationIDsMatch):
+        (WebKit::WebNotificationManagerProxy::clearNotifications):
+        (WebKit::WebNotificationManagerProxy::providerDidShowNotification):
+        (WebKit::WebNotificationManagerProxy::providerDidClickNotification):
+        (WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
+        (WebKit::generateGlobalNotificationID): Deleted.
+        (WebKit::WebNotificationManagerProxy::notificationLocalIDForTesting): Deleted.
+        * UIProcess/Notifications/WebNotificationManagerProxy.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::cancelNotification):
+        (WebKit::WebPageProxy::clearNotifications):
+        (WebKit::WebPageProxy::didDestroyNotification):
+        * UIProcess/WebPageProxy.h:
+
+        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+        (WKBundleCopyWebNotificationID):
+        (WKBundleGetWebNotificationID): Deleted.
+        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
+
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::webNotificationID):
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+
+        * WebProcess/Notifications/WebNotificationManager.cpp:
+        (WebKit::WebNotificationManager::show):
+        (WebKit::WebNotificationManager::cancel):
+        (WebKit::WebNotificationManager::didDestroyNotification):
+        (WebKit::WebNotificationManager::didShowNotification):
+        (WebKit::WebNotificationManager::didClickNotification):
+        (WebKit::WebNotificationManager::didCloseNotifications):
+        (WebKit::generateNotificationID): Deleted.
+        (WebKit::WebNotificationManager::notificationIDForTesting): Deleted.
+        (WebKit::WebNotificationManager::clearNotifications): Deleted.
+        (WebKit::WebNotificationManager::removeNotificationFromContextMap): Deleted.
+        * WebProcess/Notifications/WebNotificationManager.h:
+        * WebProcess/Notifications/WebNotificationManager.messages.in:
+
+        * WebProcess/WebCoreSupport/WebNotificationClient.cpp:
+        (WebKit::WebNotificationClient::show):
+        (WebKit::WebNotificationClient::cancel):
+        (WebKit::WebNotificationClient::notificationObjectDestroyed):
+        (WebKit::WebNotificationClient::clearNotifications): Deleted.
+        * WebProcess/WebCoreSupport/WebNotificationClient.h:
+
 2021-12-21  Eliot Hsu  <eliot_...@apple.com>
 
         Fix Safari-side SafeBrowsing telemetry

Modified: trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp (287338 => 287339)


--- trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -114,19 +114,19 @@
 //    sendMessageWithReply<WebPushD::MessageType::EchoTwice>(WTFMove(completionHandler), String("FIXME: Do useful work here"));
 }
 
-void NetworkNotificationManager::cancelNotification(uint64_t)
+void NetworkNotificationManager::cancelNotification(const String&)
 {
     if (!m_connection)
         return;
 }
 
-void NetworkNotificationManager::clearNotifications(const Vector<uint64_t>&)
+void NetworkNotificationManager::clearNotifications(const Vector<String>&)
 {
     if (!m_connection)
         return;
 }
 
-void NetworkNotificationManager::didDestroyNotification(uint64_t)
+void NetworkNotificationManager::didDestroyNotification(const String&)
 {
     if (!m_connection)
         return;

Modified: trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h (287338 => 287339)


--- trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -60,9 +60,9 @@
 
     void requestSystemNotificationPermission(const String& originString, CompletionHandler<void(bool)>&&) final;
     void showNotification(const WebCore::NotificationData&) final;
-    void cancelNotification(uint64_t notificationID) final;
-    void clearNotifications(const Vector<uint64_t>& notificationIDs) final;
-    void didDestroyNotification(uint64_t notificationID) final;
+    void cancelNotification(const String& notificationID) final;
+    void clearNotifications(const Vector<String>& notificationIDs) final;
+    void didDestroyNotification(const String& notificationID) final;
 
     void maybeSendConnectionConfiguration() const;
 

Modified: trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.h (287338 => 287339)


--- trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -41,9 +41,9 @@
 
     virtual void requestSystemNotificationPermission(const String& securityOrigin, CompletionHandler<void(bool)>&&) = 0;
     virtual void showNotification(const WebCore::NotificationData&) = 0;
-    virtual void cancelNotification(uint64_t notificationID) = 0;
-    virtual void clearNotifications(const Vector<uint64_t>& notificationIDs) = 0;
-    virtual void didDestroyNotification(uint64_t notificationID) = 0;
+    virtual void cancelNotification(const String& notificationID) = 0;
+    virtual void clearNotifications(const Vector<String>& notificationIDs) = 0;
+    virtual void didDestroyNotification(const String& notificationID) = 0;
 
 private:
     // IPC::MessageReceiver

Modified: trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.messages.in (287338 => 287339)


--- trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.messages.in	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.messages.in	2021-12-22 02:31:40 UTC (rev 287339)
@@ -23,7 +23,7 @@
 messages -> NotificationManagerMessageHandler NotRefCounted {
     RequestSystemNotificationPermission(String originIdentifier) -> (bool allowed) Async
     ShowNotification(struct WebCore::NotificationData notificationData)
-    CancelNotification(uint64_t notificationID)
-    ClearNotifications(Vector<uint64_t> notificationIDs)
-    DidDestroyNotification(uint64_t notificationID)
+    CancelNotification(String notificationID)
+    ClearNotifications(Vector<String> notificationIDs)
+    DidDestroyNotification(String notificationID)
 }

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -87,3 +87,8 @@
 {
     return toImpl(notification)->notificationID();
 }
+
+WKStringRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification)
+{
+    return toCopiedAPI(toImpl(notification)->coreNotificationID());
+}

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotification.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotification.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotification.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -42,6 +42,7 @@
 WK_EXPORT WKStringRef WKNotificationCopyDir(WKNotificationRef notification);
 WK_EXPORT WKSecurityOriginRef WKNotificationGetSecurityOrigin(WKNotificationRef notification);
 WK_EXPORT uint64_t WKNotificationGetID(WKNotificationRef notification);
+WK_EXPORT WKStringRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification);
 
 #ifdef __cplusplus
 }

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -54,6 +54,11 @@
     toImpl(managerRef)->providerDidClickNotification(notificationID);
 }
 
+void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKStringRef notificationID)
+{
+    toImpl(managerRef)->providerDidClickNotification(toWTFString(notificationID));
+}
+
 void WKNotificationManagerProviderDidCloseNotifications(WKNotificationManagerRef managerRef, WKArrayRef notificationIDs)
 {
     toImpl(managerRef)->providerDidCloseNotifications(toImpl(notificationIDs));
@@ -68,8 +73,3 @@
 {
     toImpl(managerRef)->providerDidRemoveNotificationPolicies(toImpl(origins));
 }
-
-uint64_t WKNotificationManagerGetLocalIDForTesting(WKNotificationManagerRef manager, WKNotificationRef notification)
-{
-    return toImpl(manager)->notificationLocalIDForTesting(toImpl(notification));
-}

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotificationManager.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -38,10 +38,10 @@
 
 WK_EXPORT void WKNotificationManagerProviderDidShowNotification(WKNotificationManagerRef managerRef, uint64_t notificationID);
 WK_EXPORT void WKNotificationManagerProviderDidClickNotification(WKNotificationManagerRef managerRef, uint64_t notificationID);
+WK_EXPORT void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKStringRef notificationID);
 WK_EXPORT void WKNotificationManagerProviderDidCloseNotifications(WKNotificationManagerRef managerRef, WKArrayRef notificationIDs);
 WK_EXPORT void WKNotificationManagerProviderDidUpdateNotificationPolicy(WKNotificationManagerRef managerRef, WKSecurityOriginRef origin, bool allowed);
 WK_EXPORT void WKNotificationManagerProviderDidRemoveNotificationPolicies(WKNotificationManagerRef managerRef, WKArrayRef origins);
-WK_EXPORT uint64_t WKNotificationManagerGetLocalIDForTesting(WKNotificationManagerRef managerRef, WKNotificationRef notification);
 
 #ifdef __cplusplus
 }

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -30,7 +30,7 @@
 
 namespace WebKit {
 
-WebNotification::WebNotification(const WebCore::NotificationData& data)
+WebNotification::WebNotification(const WebCore::NotificationData& data, WebPageProxyIdentifier pageIdentifier)
     : m_title(data.title)
     , m_body(data.body)
     , m_iconURL(data.iconURL)
@@ -38,7 +38,8 @@
     , m_lang(data.language)
     , m_dir(data.direction)
     , m_origin(API::SecurityOrigin::createFromString(data.originString))
-    , m_notificationID(data.notificationID)
+    , m_coreNotificationID(data.notificationID)
+    , m_pageIdentifier(pageIdentifier)
 {
 }
 

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -27,6 +27,8 @@
 
 #include "APIObject.h"
 #include "APISecurityOrigin.h"
+#include "WebPageProxyIdentifier.h"
+#include <wtf/Identified.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
 
@@ -37,11 +39,11 @@
 
 namespace WebKit {
 
-class WebNotification : public API::ObjectImpl<API::Object::Type::Notification> {
+class WebNotification : public API::ObjectImpl<API::Object::Type::Notification>, public Identified<WebNotification> {
 public:
-    static Ref<WebNotification> create(const WebCore::NotificationData& data)
+    static Ref<WebNotification> create(const WebCore::NotificationData& data, WebPageProxyIdentifier pageIdentifier)
     {
-        return adoptRef(*new WebNotification(data));
+        return adoptRef(*new WebNotification(data, pageIdentifier));
     }
 
     const String& title() const { return m_title; }
@@ -52,10 +54,13 @@
     WebCore::NotificationDirection dir() const { return m_dir; }
     API::SecurityOrigin* origin() const { return m_origin.get(); }
     
-    uint64_t notificationID() const { return m_notificationID; }
+    uint64_t notificationID() const { return identifier(); }
+    const String& coreNotificationID() const { return m_coreNotificationID; }
 
+    WebPageProxyIdentifier pageIdentifier() const { return m_pageIdentifier; }
+
 private:
-    WebNotification(const WebCore::NotificationData&);
+    WebNotification(const WebCore::NotificationData&, WebPageProxyIdentifier);
 
     String m_title;
     String m_body;
@@ -64,7 +69,9 @@
     String m_lang;
     WebCore::NotificationDirection m_dir;
     RefPtr<API::SecurityOrigin> m_origin;
-    uint64_t m_notificationID;
+    String m_coreNotificationID;
+
+    WebPageProxyIdentifier m_pageIdentifier;
 };
 
 inline bool isNotificationIDValid(uint64_t id)

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -45,17 +45,17 @@
     m_webPageProxy.showNotification(data);
 }
 
-void WebNotificationManagerMessageHandler::cancelNotification(uint64_t notificationID)
+void WebNotificationManagerMessageHandler::cancelNotification(const String& notificationID)
 {
     m_webPageProxy.cancelNotification(notificationID);
 }
 
-void WebNotificationManagerMessageHandler::clearNotifications(const Vector<uint64_t>& notificationIDs)
+void WebNotificationManagerMessageHandler::clearNotifications(const Vector<String>& notificationIDs)
 {
     m_webPageProxy.clearNotifications(notificationIDs);
 }
 
-void WebNotificationManagerMessageHandler::didDestroyNotification(uint64_t notificationID)
+void WebNotificationManagerMessageHandler::didDestroyNotification(const String& notificationID)
 {
     m_webPageProxy.didDestroyNotification(notificationID);
 }

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -38,9 +38,9 @@
 
     void requestSystemNotificationPermission(const String&, CompletionHandler<void(bool)>&&) final;
     void showNotification(const WebCore::NotificationData&) final;
-    void cancelNotification(uint64_t notificationID) final;
-    void clearNotifications(const Vector<uint64_t>& notificationIDs) final;
-    void didDestroyNotification(uint64_t notificationID) final;
+    void cancelNotification(const String& notificationID) final;
+    void clearNotifications(const Vector<String>& notificationIDs) final;
+    void didDestroyNotification(const String& notificationID) final;
 
     WebPageProxy& m_webPageProxy;
 };

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -39,12 +39,6 @@
 namespace WebKit {
 using namespace WebCore;
 
-static uint64_t generateGlobalNotificationID()
-{
-    static uint64_t uniqueGlobalNotificationID = 1;
-    return uniqueGlobalNotificationID++;
-}
-
 const char* WebNotificationManagerProxy::supplementName()
 {
     return "WebNotificationManagerProxy";
@@ -96,36 +90,32 @@
 
 void WebNotificationManagerProxy::show(WebPageProxy* webPage, const WebCore::NotificationData& notificationData)
 {
-    uint64_t globalNotificationID = generateGlobalNotificationID();
-    auto notification = WebNotification::create(notificationData);
-    auto notificationIDPair = std::make_pair(webPage->identifier(), notificationData.notificationID);
-    m_globalNotificationMap.set(globalNotificationID, notificationIDPair);
-    m_notifications.set(notificationIDPair, std::make_pair(globalNotificationID, notification.copyRef()));
+    auto notification = WebNotification::create(notificationData, webPage->identifier());
+    m_globalNotificationMap.set(notification->notificationID(), notification->coreNotificationID());
+    m_notifications.set(notification->coreNotificationID(), notification);
     m_provider->show(*webPage, notification.get());
 }
 
-void WebNotificationManagerProxy::cancel(WebPageProxy* webPage, uint64_t pageNotificationID)
+void WebNotificationManagerProxy::cancel(WebPageProxy* webPage, const String& pageNotificationID)
 {
-    if (WebNotification* notification = m_notifications.get(std::make_pair(webPage->identifier(), pageNotificationID)).second.get())
-        m_provider->cancel(*notification);
+    if (auto webNotification = m_notifications.get(pageNotificationID))
+        m_provider->cancel(*webNotification);
 }
     
-void WebNotificationManagerProxy::didDestroyNotification(WebPageProxy* webPage, uint64_t pageNotificationID)
+void WebNotificationManagerProxy::didDestroyNotification(WebPageProxy* webPage, const String& pageNotificationID)
 {
-    auto globalIDNotificationPair = m_notifications.take(std::make_pair(webPage->identifier(), pageNotificationID));
-    if (uint64_t globalNotificationID = globalIDNotificationPair.first) {
-        WebNotification* notification = globalIDNotificationPair.second.get();
-        m_globalNotificationMap.remove(globalNotificationID);
-        m_provider->didDestroyNotification(*notification);
+    if (auto webNotification = m_notifications.take(pageNotificationID)) {
+        m_globalNotificationMap.remove(webNotification->notificationID());
+        m_provider->didDestroyNotification(*webNotification);
     }
 }
 
-static bool pageIDsMatch(WebPageProxyIdentifier pageID, uint64_t, WebPageProxyIdentifier desiredPageID, const Vector<uint64_t>&)
+static bool pageIDsMatch(WebPageProxyIdentifier pageID, const String&, WebPageProxyIdentifier desiredPageID, const Vector<String>&)
 {
     return pageID == desiredPageID;
 }
 
-static bool pageAndNotificationIDsMatch(WebPageProxyIdentifier pageID, uint64_t pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<uint64_t>& desiredPageNotificationIDs)
+static bool pageAndNotificationIDsMatch(WebPageProxyIdentifier pageID, const String& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<String>& desiredPageNotificationIDs)
 {
     return pageID == desiredPageID && desiredPageNotificationIDs.contains(pageNotificationID);
 }
@@ -132,15 +122,15 @@
 
 void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage)
 {
-    clearNotifications(webPage, Vector<uint64_t>(), pageIDsMatch);
+    clearNotifications(webPage, Vector<String>(), pageIDsMatch);
 }
 
-void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<uint64_t>& pageNotificationIDs)
+void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<String>& pageNotificationIDs)
 {
     clearNotifications(webPage, pageNotificationIDs, pageAndNotificationIDsMatch);
 }
 
-void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<uint64_t>& pageNotificationIDs, NotificationFilterFunction filterFunction)
+void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<String>& pageNotificationIDs, NotificationFilterFunction filterFunction)
 {
     auto targetPageProxyID = webPage->identifier();
 
@@ -147,13 +137,13 @@
     Vector<uint64_t> globalNotificationIDs;
     globalNotificationIDs.reserveCapacity(m_globalNotificationMap.size());
 
-    for (auto it = m_notifications.begin(), end = m_notifications.end(); it != end; ++it) {
-        auto pageProxyID = it->key.first;
-        uint64_t pageNotificationID = it->key.second;
-        if (!filterFunction(pageProxyID, pageNotificationID, targetPageProxyID, pageNotificationIDs))
+    for (auto notification : m_notifications.values()) {
+        auto pageProxyID = notification->pageIdentifier();
+        String coreNotificationID = notification->coreNotificationID();
+        if (!filterFunction(pageProxyID, coreNotificationID, targetPageProxyID, pageNotificationIDs))
             continue;
 
-        uint64_t globalNotificationID = it->value.first;
+        uint64_t globalNotificationID = notification->notificationID();
         globalNotificationIDs.append(globalNotificationID);
     }
 
@@ -171,12 +161,17 @@
     if (it == m_globalNotificationMap.end())
         return;
 
-    auto* webPage = WebProcessProxy::webPage(it->value.first);
+    auto notification = m_notifications.get(it->value);
+    if (!notification) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    auto* webPage = WebProcessProxy::webPage(notification->pageIdentifier());
     if (!webPage)
         return;
 
-    uint64_t pageNotificationID = it->value.second;
-    webPage->process().send(Messages::WebNotificationManager::DidShowNotification(pageNotificationID), 0);
+    webPage->process().send(Messages::WebNotificationManager::DidShowNotification(it->value), 0);
 }
 
 void WebNotificationManagerProxy::providerDidClickNotification(uint64_t globalNotificationID)
@@ -184,40 +179,76 @@
     auto it = m_globalNotificationMap.find(globalNotificationID);
     if (it == m_globalNotificationMap.end())
         return;
-    
-    auto* webPage = WebProcessProxy::webPage(it->value.first);
+
+    auto notification = m_notifications.get(it->value);
+    if (!notification) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    auto* webPage = WebProcessProxy::webPage(notification->pageIdentifier());
     if (!webPage)
         return;
 
-    uint64_t pageNotificationID = it->value.second;
-    webPage->process().send(Messages::WebNotificationManager::DidClickNotification(pageNotificationID), 0);
+    webPage->process().send(Messages::WebNotificationManager::DidClickNotification(it->value), 0);
 }
 
+void WebNotificationManagerProxy::providerDidClickNotification(const String& coreNotificationID)
+{
+    auto notification = m_notifications.get(coreNotificationID);
+    if (!notification)
+        return;
 
+    auto* webPage = WebProcessProxy::webPage(notification->pageIdentifier());
+    if (!webPage)
+        return;
+
+    webPage->process().send(Messages::WebNotificationManager::DidClickNotification(coreNotificationID), 0);
+}
+
 void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* globalNotificationIDs)
 {
-    HashMap<WebPageProxy*, Vector<uint64_t>> pageNotificationIDs;
-    
+    HashMap<WebPageProxy*, Vector<String>> pageNotificationIDs;
+
     size_t size = globalNotificationIDs->size();
     for (size_t i = 0; i < size; ++i) {
-        auto it = m_globalNotificationMap.find(globalNotificationIDs->at<API::UInt64>(i)->value());
-        if (it == m_globalNotificationMap.end())
+        // The passed array might have uint64_t identifiers or String identifiers.
+        // Handle both.
+
+        String coreNotificationID;
+        auto* intValue = globalNotificationIDs->at<API::UInt64>(i);
+        if (intValue) {
+            auto it = m_globalNotificationMap.find(intValue->value());
+            if (it == m_globalNotificationMap.end())
+                continue;
+
+            coreNotificationID = it->value;
+        } else {
+            auto* stringValue = globalNotificationIDs->at<API::String>(i);
+            if (!stringValue)
+                continue;
+
+            coreNotificationID = stringValue->string();
+        }
+
+        ASSERT(!coreNotificationID.isEmpty());
+
+        auto notification = m_notifications.take(coreNotificationID);
+        if (!notification)
             continue;
 
-        if (WebPageProxy* webPage = WebProcessProxy::webPage(it->value.first)) {
+        if (WebPageProxy* webPage = WebProcessProxy::webPage(notification->pageIdentifier())) {
             auto pageIt = pageNotificationIDs.find(webPage);
             if (pageIt == pageNotificationIDs.end()) {
-                Vector<uint64_t> newVector;
+                Vector<String> newVector;
                 newVector.reserveInitialCapacity(size);
                 pageIt = pageNotificationIDs.add(webPage, WTFMove(newVector)).iterator;
             }
 
-            uint64_t pageNotificationID = it->value.second;
-            pageIt->value.append(pageNotificationID);
+            pageIt->value.append(notification->coreNotificationID());
         }
 
-        m_notifications.remove(it->value);
-        m_globalNotificationMap.remove(it);
+        m_globalNotificationMap.remove(notification->notificationID());
     }
 
     for (auto it = pageNotificationIDs.begin(), end = pageNotificationIDs.end(); it != end; ++it)
@@ -250,16 +281,4 @@
     processPool()->sendToAllProcesses(Messages::WebNotificationManager::DidRemoveNotificationDecisions(originStrings));
 }
 
-uint64_t WebNotificationManagerProxy::notificationLocalIDForTesting(WebNotification* notification)
-{
-    if (!notification)
-        return 0;
-
-    auto it = m_globalNotificationMap.find(notification->notificationID());
-    if (it == m_globalNotificationMap.end())
-        return 0;
-
-    return it->value.second;
-}
-
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -60,19 +60,18 @@
     HashMap<String, bool> notificationPermissions();
 
     void show(WebPageProxy*, const WebCore::NotificationData&);
-    void cancel(WebPageProxy*, uint64_t pageNotificationID);
+    void cancel(WebPageProxy*, const String& pageNotificationID);
     void clearNotifications(WebPageProxy*);
-    void clearNotifications(WebPageProxy*, const Vector<uint64_t>& pageNotificationIDs);
-    void didDestroyNotification(WebPageProxy*, uint64_t pageNotificationID);
+    void clearNotifications(WebPageProxy*, const Vector<String>& pageNotificationIDs);
+    void didDestroyNotification(WebPageProxy*, const String& pageNotificationID);
 
     void providerDidShowNotification(uint64_t notificationID);
     void providerDidClickNotification(uint64_t notificationID);
+    void providerDidClickNotification(const String& notificationID);
     void providerDidCloseNotifications(API::Array* notificationIDs);
     void providerDidUpdateNotificationPolicy(const API::SecurityOrigin*, bool allowed);
     void providerDidRemoveNotificationPolicies(API::Array* origins);
 
-    uint64_t notificationLocalIDForTesting(WebNotification*);
-
     using API::Object::ref;
     using API::Object::deref;
 
@@ -79,8 +78,8 @@
 private:
     explicit WebNotificationManagerProxy(WebProcessPool*);
 
-    typedef bool (*NotificationFilterFunction)(WebPageProxyIdentifier pageID, uint64_t pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<uint64_t>& desiredPageNotificationIDs);
-    void clearNotifications(WebPageProxy*, const Vector<uint64_t>& pageNotificationIDs, NotificationFilterFunction);
+    typedef bool (*NotificationFilterFunction)(WebPageProxyIdentifier pageID, const String& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<String>& desiredPageNotificationIDs);
+    void clearNotifications(WebPageProxy*, const Vector<String>& pageNotificationIDs, NotificationFilterFunction);
 
     // WebContextSupplement
     void processPoolDestroyed() override;
@@ -88,10 +87,9 @@
     void derefWebContextSupplement() override;
 
     std::unique_ptr<API::NotificationProvider> m_provider;
-    // Pair comprised of web page ID and the web process's notification ID
-    HashMap<uint64_t, std::pair<WebPageProxyIdentifier, uint64_t>> m_globalNotificationMap;
-    // Key pair comprised of web page ID and the web process's notification ID; value pair comprised of global notification ID, and notification object
-    HashMap<std::pair<WebPageProxyIdentifier, uint64_t>, std::pair<uint64_t, RefPtr<WebNotification>>> m_notifications;
+
+    HashMap<uint64_t, String> m_globalNotificationMap;
+    HashMap<String, Ref<WebNotification>> m_notifications;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -8742,17 +8742,17 @@
     m_process->processPool().supplement<WebNotificationManagerProxy>()->show(this, notificationData);
 }
 
-void WebPageProxy::cancelNotification(uint64_t notificationID)
+void WebPageProxy::cancelNotification(const String& notificationID)
 {
     m_process->processPool().supplement<WebNotificationManagerProxy>()->cancel(this, notificationID);
 }
 
-void WebPageProxy::clearNotifications(const Vector<uint64_t>& notificationIDs)
+void WebPageProxy::clearNotifications(const Vector<String>& notificationIDs)
 {
     m_process->processPool().supplement<WebNotificationManagerProxy>()->clearNotifications(this, notificationIDs);
 }
 
-void WebPageProxy::didDestroyNotification(uint64_t notificationID)
+void WebPageProxy::didDestroyNotification(const String& notificationID)
 {
     m_process->processPool().supplement<WebNotificationManagerProxy>()->didDestroyNotification(this, notificationID);
 }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (287338 => 287339)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -2033,9 +2033,9 @@
 #endif
 
     void showNotification(const WebCore::NotificationData&);
-    void cancelNotification(uint64_t notificationID);
-    void clearNotifications(const Vector<uint64_t>& notificationIDs);
-    void didDestroyNotification(uint64_t notificationID);
+    void cancelNotification(const String& notificationID);
+    void clearNotifications(const Vector<String>& notificationIDs);
+    void didDestroyNotification(const String& notificationID);
 
     void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&);
     void classifyModalContainerControls(Vector<String>&& texts, CompletionHandler<void(Vector<WebCore::ModalContainerControlType>&&)>&&);

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


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -206,9 +206,13 @@
     WebKit::toImpl(bundleRef)->removeAllWebNotificationPermissions(WebKit::toImpl(pageRef));
 }
 
-uint64_t WKBundleGetWebNotificationID(WKBundleRef bundleRef, JSContextRef context, JSValueRef notification)
+WKStringRef WKBundleCopyWebNotificationID(WKBundleRef bundleRef, JSContextRef context, JSValueRef notification)
 {
-    return WebKit::toImpl(bundleRef)->webNotificationID(context, notification);
+    auto identifier = WebKit::toImpl(bundleRef)->webNotificationID(context, notification);
+    if (!identifier)
+        return nullptr;
+
+    return WebKit::toCopiedAPI(*identifier);
 }
 
 void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundleRef, WKBundlePageRef pageRef, bool enabled)

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -52,7 +52,7 @@
 WK_EXPORT void WKBundleSetUserStyleSheetLocationForTesting(WKBundleRef bundle, WKStringRef location);
 WK_EXPORT void WKBundleSetWebNotificationPermission(WKBundleRef bundle, WKBundlePageRef page, WKStringRef originStringRef, bool allowed);
 WK_EXPORT void WKBundleRemoveAllWebNotificationPermissions(WKBundleRef bundle, WKBundlePageRef page);
-WK_EXPORT uint64_t WKBundleGetWebNotificationID(WKBundleRef bundle, JSContextRef context, JSValueRef notification);
+WK_EXPORT WKStringRef WKBundleCopyWebNotificationID(WKBundleRef bundle, JSContextRef context, JSValueRef notification);
 WK_EXPORT WKDataRef WKBundleCreateWKDataFromUInt8Array(WKBundleRef bundle, JSContextRef context, JSValueRef data);
 WK_EXPORT void WKBundleSetAsynchronousSpellCheckingEnabledForTesting(WKBundleRef bundleRef, bool enabled);
 // Returns array of dictionaries. Dictionary keys are document identifiers, values are document URLs.

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -310,17 +310,17 @@
 #endif
 }
 
-uint64_t InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
+std::optional<String> InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
 {
 #if ENABLE(NOTIFICATIONS)
     WebCore::Notification* notification = JSNotification::toWrapped(toJS(jsContext)->vm(), toJS(toJS(jsContext), jsNotification));
     if (!notification)
-        return 0;
-    return WebProcess::singleton().supplement<WebNotificationManager>()->notificationIDForTesting(notification);
+        return std::nullopt;
+    return notification->identifier();
 #else
     UNUSED_PARAM(jsContext);
     UNUSED_PARAM(jsNotification);
-    return 0;
+    return std::nullopt;
 #endif
 }
 

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -106,7 +106,7 @@
     void setUserStyleSheetLocation(const String&);
     void setWebNotificationPermission(WebPage*, const String& originString, bool allowed);
     void removeAllWebNotificationPermissions(WebPage*);
-    uint64_t webNotificationID(JSContextRef, JSValueRef);
+    std::optional<String> webNotificationID(JSContextRef, JSValueRef);
     Ref<API::Data> createWebDataFromUint8Array(JSContextRef, JSValueRef);
     
     typedef HashMap<uint64_t, String> DocumentIDToURLMap;

Modified: trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -51,14 +51,6 @@
 namespace WebKit {
 using namespace WebCore;
 
-#if ENABLE(NOTIFICATIONS)
-static uint64_t generateNotificationID()
-{
-    static uint64_t uniqueNotificationID = 1;
-    return uniqueNotificationID++;
-}
-#endif
-
 const char* WebNotificationManager::supplementName()
 {
     return "WebNotificationManager";
@@ -128,19 +120,7 @@
 #endif
 }
 
-uint64_t WebNotificationManager::notificationIDForTesting(Notification* notification)
-{
 #if ENABLE(NOTIFICATIONS)
-    if (!notification)
-        return 0;
-    return m_notificationMap.get(notification);
-#else
-    UNUSED_PARAM(notification);
-    return 0;
-#endif
-}
-
-#if ENABLE(NOTIFICATIONS)
 template<typename U> bool sendNotificationMessage(WebProcess& process, U&& message, WebPage& page)
 {
 #if ENABLE(BUILT_IN_NOTIFICATIONS)
@@ -151,22 +131,15 @@
 }
 #endif // ENABLE(NOTIFICATIONS)
 
-bool WebNotificationManager::show(Notification* notification, WebPage* page)
+bool WebNotificationManager::show(Notification& notification, WebPage* page)
 {
 #if ENABLE(NOTIFICATIONS)
-    if (!notification || !page->corePage()->settings().notificationsEnabled())
+    if (!page->corePage()->settings().notificationsEnabled())
         return false;
-    
-    uint64_t notificationID = generateNotificationID();
-    m_notificationMap.set(notification, notificationID);
-    m_notificationIDMap.set(notificationID, notification);
-    
-    auto it = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<uint64_t>()).iterator;
-    it->value.append(notificationID);
 
-    auto notificationData = notification->dataWithoutNotificationID();
-    notificationData.notificationID = notificationID;
-    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::ShowNotification(WTFMove(notificationData)), *page);
+    m_notificationIDMap.set(notification.identifier(), &notification);
+
+    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::ShowNotification(notification.data()), *page);
     return true;
 #else
     UNUSED_PARAM(notification);
@@ -175,60 +148,35 @@
 #endif
 }
 
-void WebNotificationManager::cancel(Notification* notification, WebPage* page)
+void WebNotificationManager::cancel(Notification& notification, WebPage* page)
 {
 #if ENABLE(NOTIFICATIONS)
-    if (!notification || !page->corePage()->settings().notificationsEnabled())
+    if (!page->corePage()->settings().notificationsEnabled())
         return;
-    
-    uint64_t notificationID = m_notificationMap.get(notification);
-    if (!notificationID)
-        return;
-    
-    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::CancelNotification(notificationID), *page);
-#else
-    UNUSED_PARAM(notification);
-    UNUSED_PARAM(page);
-#endif
-}
 
-void WebNotificationManager::clearNotifications(WebCore::ScriptExecutionContext* context, WebPage* page)
-{
-#if ENABLE(NOTIFICATIONS)
-    NotificationContextMap::iterator it = m_notificationContextMap.find(context);
-    if (it == m_notificationContextMap.end())
+    auto mappedNotification = m_notificationIDMap.get(notification.identifier());
+    if (!mappedNotification)
         return;
+    ASSERT(mappedNotification == &notification);
 
-    Vector<uint64_t>& notificationIDs = it->value;
-    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::ClearNotifications(notificationIDs), *page);
-    size_t count = notificationIDs.size();
-    for (size_t i = 0; i < count; ++i) {
-        RefPtr<Notification> notification = m_notificationIDMap.take(notificationIDs[i]);
-        if (!notification)
-            continue;
-        notification->finalize();
-        m_notificationMap.remove(notification);
-    }
-    
-    m_notificationContextMap.remove(it);
+    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::CancelNotification(notification.identifier()), *page);
 #else
-    UNUSED_PARAM(context);
+    UNUSED_PARAM(notification);
     UNUSED_PARAM(page);
 #endif
 }
 
-void WebNotificationManager::didDestroyNotification(Notification* notification, WebPage* page)
+void WebNotificationManager::didDestroyNotification(Notification& notification, WebPage* page)
 {
 #if ENABLE(NOTIFICATIONS)
-    RefPtr protectedNotification { notification };
+    Ref protectedNotification { notification };
 
-    uint64_t notificationID = m_notificationMap.take(notification);
-    if (!notificationID)
+    auto takenNotification = m_notificationIDMap.take(notification.identifier());
+    if (!takenNotification)
         return;
+    ASSERT(takenNotification == &notification);
 
-    m_notificationIDMap.remove(notificationID);
-    removeNotificationFromContextMap(notificationID, notification);
-    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::DidDestroyNotification(notificationID), *page);
+    sendNotificationMessage(m_process, Messages::NotificationManagerMessageHandler::DidDestroyNotification(notification.identifier()), *page);
 #else
     UNUSED_PARAM(notification);
     UNUSED_PARAM(page);
@@ -235,12 +183,9 @@
 #endif
 }
 
-void WebNotificationManager::didShowNotification(uint64_t notificationID)
+void WebNotificationManager::didShowNotification(const String& notificationID)
 {
 #if ENABLE(NOTIFICATIONS)
-    if (!isNotificationIDValid(notificationID))
-        return;
-    
     RefPtr<Notification> notification = m_notificationIDMap.get(notificationID);
     if (!notification)
         return;
@@ -251,12 +196,9 @@
 #endif
 }
 
-void WebNotificationManager::didClickNotification(uint64_t notificationID)
+void WebNotificationManager::didClickNotification(const String& notificationID)
 {
 #if ENABLE(NOTIFICATIONS)
-    if (!isNotificationIDValid(notificationID))
-        return;
-
     RefPtr<Notification> notification = m_notificationIDMap.get(notificationID);
     if (!notification)
         return;
@@ -269,22 +211,17 @@
 #endif
 }
 
-void WebNotificationManager::didCloseNotifications(const Vector<uint64_t>& notificationIDs)
+void WebNotificationManager::didCloseNotifications(const Vector<String>& notificationIDs)
 {
 #if ENABLE(NOTIFICATIONS)
     size_t count = notificationIDs.size();
     for (size_t i = 0; i < count; ++i) {
-        uint64_t notificationID = notificationIDs[i];
-        if (!isNotificationIDValid(notificationID))
-            continue;
+        auto notificationID = notificationIDs[i];
 
         RefPtr<Notification> notification = m_notificationIDMap.take(notificationID);
         if (!notification)
             continue;
 
-        m_notificationMap.remove(notification);
-        removeNotificationFromContextMap(notificationID, notification.get());
-
         notification->dispatchCloseEvent();
     }
 #else
@@ -292,18 +229,4 @@
 #endif
 }
 
-#if ENABLE(NOTIFICATIONS)
-void WebNotificationManager::removeNotificationFromContextMap(uint64_t notificationID, Notification* notification)
-{
-    // This is a helper function for managing the hash maps.
-    NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
-    ASSERT(it != m_notificationContextMap.end());
-    size_t index = it->value.find(notificationID);
-    ASSERT(index != notFound);
-    it->value.remove(index);
-    if (it->value.isEmpty())
-        m_notificationContextMap.remove(it);
-}
-#endif
-
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.h (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -28,6 +28,7 @@
 #include "MessageReceiver.h"
 #include "WebProcessSupplement.h"
 #include <WebCore/NotificationClient.h>
+#include <optional>
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RefPtr.h>
@@ -53,11 +54,11 @@
 
     static const char* supplementName();
     
-    bool show(WebCore::Notification*, WebPage*);
-    void cancel(WebCore::Notification*, WebPage*);
-    void clearNotifications(WebCore::ScriptExecutionContext*, WebPage*);
+    bool show(WebCore::Notification&, WebPage*);
+    void cancel(WebCore::Notification&, WebPage*);
+
     // This callback comes from WebCore, not messaged from the UI process.
-    void didDestroyNotification(WebCore::Notification*, WebPage*);
+    void didDestroyNotification(WebCore::Notification&, WebPage*);
 
     void didUpdateNotificationDecision(const String& originString, bool allowed);
 
@@ -65,7 +66,6 @@
     WebCore::NotificationClient::Permission policyForOrigin(const String& originString) const;
 
     void removeAllPermissionsForTesting();
-    uint64_t notificationIDForTesting(WebCore::Notification*);
 
 private:
     // WebProcessSupplement
@@ -75,27 +75,17 @@
     // Implemented in generated WebNotificationManagerMessageReceiver.cpp
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
     
-    void didShowNotification(uint64_t notificationID);
-    void didClickNotification(uint64_t notificationID);
-    void didCloseNotifications(const Vector<uint64_t>& notificationIDs);
+    void didShowNotification(const String& notificationID);
+    void didClickNotification(const String& notificationID);
+    void didCloseNotifications(const Vector<String>& notificationIDs);
     void didRemoveNotificationDecisions(const Vector<String>& originStrings);
-    
-#if ENABLE(NOTIFICATIONS)
-    void removeNotificationFromContextMap(uint64_t notificationID, WebCore::Notification*);
-#endif
 
     WebProcess& m_process;
 
 #if ENABLE(NOTIFICATIONS)
-    typedef HashMap<RefPtr<WebCore::Notification>, uint64_t> NotificationMap;
-    NotificationMap m_notificationMap;
-    
-    typedef HashMap<uint64_t, RefPtr<WebCore::Notification>> NotificationIDMap;
+    typedef HashMap<String, RefPtr<WebCore::Notification>> NotificationIDMap;
     NotificationIDMap m_notificationIDMap;
     
-    typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<uint64_t>> NotificationContextMap;
-    NotificationContextMap m_notificationContextMap;
-    
     HashMap<String, bool> m_permissionsMap;
 #endif
 };

Modified: trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.messages.in (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.messages.in	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/Notifications/WebNotificationManager.messages.in	2021-12-22 02:31:40 UTC (rev 287339)
@@ -21,9 +21,9 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebNotificationManager NotRefCounted {
-    DidShowNotification(uint64_t notificationID);
-    DidClickNotification(uint64_t notificationID);
-    DidCloseNotifications(Vector<uint64_t> notificationIDs);
+    DidShowNotification(String notificationID);
+    DidClickNotification(String notificationID);
+    DidCloseNotifications(Vector<String> notificationIDs);
     DidUpdateNotificationDecision(String originString, bool allowed);
     DidRemoveNotificationDecisions(Vector<String> originStrings);
 }

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.cpp (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -46,23 +46,18 @@
 {
 }
 
-bool WebNotificationClient::show(Notification* notification)
+bool WebNotificationClient::show(Notification& notification)
 {
     return WebProcess::singleton().supplement<WebNotificationManager>()->show(notification, m_page);
 }
 
-void WebNotificationClient::cancel(Notification* notification)
+void WebNotificationClient::cancel(Notification& notification)
 {
     WebProcess::singleton().supplement<WebNotificationManager>()->cancel(notification, m_page);
 }
 
-void WebNotificationClient::clearNotifications(ScriptExecutionContext* context)
+void WebNotificationClient::notificationObjectDestroyed(Notification& notification)
 {
-    WebProcess::singleton().supplement<WebNotificationManager>()->clearNotifications(context, m_page);
-}
-
-void WebNotificationClient::notificationObjectDestroyed(Notification* notification)
-{
     WebProcess::singleton().supplement<WebNotificationManager>()->didDestroyNotification(notification, m_page);
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.h (287338 => 287339)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebNotificationClient.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -45,10 +45,9 @@
     virtual ~WebNotificationClient();
 
 private:
-    bool show(WebCore::Notification*) override;
-    void cancel(WebCore::Notification*) override;
-    void clearNotifications(WebCore::ScriptExecutionContext*) override;
-    void notificationObjectDestroyed(WebCore::Notification*) override;
+    bool show(WebCore::Notification&) override;
+    void cancel(WebCore::Notification&) override;
+    void notificationObjectDestroyed(WebCore::Notification&) override;
     void notificationControllerDestroyed() override;
     void requestPermission(WebCore::ScriptExecutionContext&, PermissionHandler&&) override;
     WebCore::NotificationClient::Permission checkPermission(WebCore::ScriptExecutionContext*) override;

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (287338 => 287339)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-22 02:31:40 UTC (rev 287339)
@@ -1,3 +1,17 @@
+2021-12-21  Brady Eidson  <beid...@apple.com>
+
+        Make Notification identifiers be a UUID string instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=234534
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebNotificationClient.h:
+        * WebCoreSupport/WebNotificationClient.mm:
+        (WebNotificationClient::show):
+        (WebNotificationClient::cancel):
+        (WebNotificationClient::notificationObjectDestroyed):
+        (WebNotificationClient::clearNotifications): Deleted.
+
 2021-12-21  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Add support for a UI delegate method to decide how to handle detected modal containers

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.h (287338 => 287339)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -45,10 +45,9 @@
     uint64_t notificationIDForTesting(WebCore::Notification*);
 
 private:
-    bool show(WebCore::Notification*) override;
-    void cancel(WebCore::Notification*) override;
-    void clearNotifications(WebCore::ScriptExecutionContext*) override;
-    void notificationObjectDestroyed(WebCore::Notification*) override;
+    bool show(WebCore::Notification&) override;
+    void cancel(WebCore::Notification&) override;
+    void notificationObjectDestroyed(WebCore::Notification&) override;
     void notificationControllerDestroyed() override;
     void requestPermission(WebCore::ScriptExecutionContext&, PermissionHandler&&) override;
     WebCore::NotificationClient::Permission checkPermission(WebCore::ScriptExecutionContext*) override;
@@ -57,9 +56,6 @@
 
     WebView *m_webView;
     HashMap<RefPtr<WebCore::Notification>, RetainPtr<WebNotification>> m_notificationMap;
-    
-    typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<RetainPtr<WebNotification>>> NotificationContextMap;
-    NotificationContextMap m_notificationContextMap;
 
     bool m_everRequestedPermission { false };
 };

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.mm (287338 => 287339)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.mm	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebNotificationClient.mm	2021-12-22 02:31:40 UTC (rev 287339)
@@ -58,25 +58,22 @@
 {
 }
 
-bool WebNotificationClient::show(Notification* notification)
+bool WebNotificationClient::show(Notification& notification)
 {
     if (![m_webView _notificationProvider])
         return false;
 
     uint64_t notificationID = generateNotificationID();
-    RetainPtr<WebNotification> webNotification = adoptNS([[WebNotification alloc] initWithCoreNotification:notification notificationID:notificationID]);
-    m_notificationMap.set(notification, webNotification);
+    RetainPtr<WebNotification> webNotification = adoptNS([[WebNotification alloc] initWithCoreNotification:&notification notificationID:notificationID]);
+    m_notificationMap.set(&notification, webNotification);
 
-    auto it = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<RetainPtr<WebNotification>>()).iterator;
-    it->value.append(webNotification);
-
     [[m_webView _notificationProvider] showNotification:webNotification.get() fromWebView:m_webView];
     return true;
 }
 
-void WebNotificationClient::cancel(Notification* notification)
+void WebNotificationClient::cancel(Notification& notification)
 {
-    WebNotification *webNotification = m_notificationMap.get(notification).get();
+    WebNotification *webNotification = m_notificationMap.get(&notification).get();
     if (!webNotification)
         return;
 
@@ -83,37 +80,12 @@
     [[m_webView _notificationProvider] cancelNotification:webNotification];
 }
 
-void WebNotificationClient::clearNotifications(ScriptExecutionContext* context)
+void WebNotificationClient::notificationObjectDestroyed(Notification& notification)
 {
-    auto it = m_notificationContextMap.find(context);
-    if (it == m_notificationContextMap.end())
-        return;
-    
-    auto finalizedNotificationIDs = createNSArray(it->value, [&] (auto& notification) {
-        auto& coreNotification = *core(notification.get());
-        coreNotification.finalize();
-        m_notificationMap.remove(&coreNotification);
-        return @([notification notificationID]);
-    });
-
-    [[m_webView _notificationProvider] clearNotifications:finalizedNotificationIDs.get()];
-    m_notificationContextMap.remove(it);
-}
-
-void WebNotificationClient::notificationObjectDestroyed(Notification* notification)
-{
-    RetainPtr<WebNotification> webNotification = m_notificationMap.take(notification);
+    RetainPtr<WebNotification> webNotification = m_notificationMap.take(&notification);
     if (!webNotification)
         return;
 
-    auto it = m_notificationContextMap.find(notification->scriptExecutionContext());
-    ASSERT(it != m_notificationContextMap.end());
-    size_t index = it->value.find(webNotification);
-    ASSERT(index != notFound);
-    it->value.remove(index);
-    if (it->value.isEmpty())
-        m_notificationContextMap.remove(it);
-
     [[m_webView _notificationProvider] notificationDestroyed:webNotification.get()];
 }
 

Modified: trunk/Tools/ChangeLog (287338 => 287339)


--- trunk/Tools/ChangeLog	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/ChangeLog	2021-12-22 02:31:40 UTC (rev 287339)
@@ -1,3 +1,38 @@
+2021-12-21  Brady Eidson  <beid...@apple.com>
+
+        Make Notification identifiers be a UUID string instead of a uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=234534
+
+        Reviewed by Alex Christensen.
+        
+        Where possible, use the String UUID identifier.
+        This gets rid of lots of weird maps and cleans up flaky situations that could occasionally occur.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::postSimulateWebNotificationClick):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::simulateWebNotificationClick):
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::simulateWebNotificationClick):
+        * WebKitTestRunner/TestController.h:
+
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
+
+        * WebKitTestRunner/WebNotificationProvider.cpp:
+        (WTR::WebNotificationProvider::~WebNotificationProvider):
+        (WTR::WebNotificationProvider::showWebNotification):
+        (WTR::WebNotificationProvider::closeWebNotification):
+        (WTR::WebNotificationProvider::addNotificationManager):
+        (WTR::WebNotificationProvider::removeNotificationManager):
+        (WTR::WebNotificationProvider::simulateWebNotificationClick):
+        (WTR::WebNotificationProvider::reset):
+        (WTR::removeGlobalIDFromIDMap): Deleted.
+        * WebKitTestRunner/WebNotificationProvider.h:
+
 2021-12-21  Simon Fraser  <simon.fra...@apple.com>
 
         Allow a way to specify a custom pixel tolerance in a ref test

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -663,9 +663,9 @@
     WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("SetViewSize").get(), body.get(), 0);
 }
 
-void InjectedBundle::postSimulateWebNotificationClick(uint64_t notificationID)
+void InjectedBundle::postSimulateWebNotificationClick(WKStringRef notificationID)
 {
-    postPageMessage("SimulateWebNotificationClick", adoptWK(WKUInt64Create(notificationID)));
+    postPageMessage("SimulateWebNotificationClick", notificationID);
 }
 
 void InjectedBundle::postSetAddsVisitedLinks(bool addsVisitedLinks)

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -94,7 +94,7 @@
     void postSetBackingScaleFactor(double);
     void postSetWindowIsKey(bool);
     void postSetViewSize(double width, double height);
-    void postSimulateWebNotificationClick(uint64_t notificationID);
+    void postSimulateWebNotificationClick(WKStringRef notificationID);
     void postSetAddsVisitedLinks(bool);
 
     // Geolocation.

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -881,7 +881,9 @@
 void TestRunner::simulateWebNotificationClick(JSValueRef notification)
 {
     auto& injectedBundle = InjectedBundle::singleton();
-    injectedBundle.postSimulateWebNotificationClick(WKBundleGetWebNotificationID(injectedBundle.bundle(), mainFrameJSContext(), notification));
+
+    auto notificationID = adoptWK(WKBundleCopyWebNotificationID(injectedBundle.bundle(), mainFrameJSContext(), notification));
+    injectedBundle.postSimulateWebNotificationClick(notificationID.get());
 }
 
 void TestRunner::setGeolocationPermission(bool enabled)

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -2346,7 +2346,7 @@
     m_currentInvocation->didRemoveSwipeSnapshot();
 }
 
-void TestController::simulateWebNotificationClick(uint64_t notificationID)
+void TestController::simulateWebNotificationClick(WKStringRef notificationID)
 {
     m_webNotificationProvider.simulateWebNotificationClick(mainWebView()->page(), notificationID);
 }

Modified: trunk/Tools/WebKitTestRunner/TestController.h (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/TestController.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -125,7 +125,7 @@
     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
     void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
 
-    void simulateWebNotificationClick(uint64_t notificationID);
+    void simulateWebNotificationClick(WKStringRef notificationID);
 
     // Geolocation.
     void setGeolocationPermission(bool);

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -390,7 +390,7 @@
     }
 
     if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
-        uint64_t notificationID = uint64Value(messageBody);
+        WKStringRef notificationID = stringValue(messageBody);
         TestController::singleton().simulateWebNotificationClick(notificationID);
         return;
     }

Modified: trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp	2021-12-22 02:31:40 UTC (rev 287339)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WebNotificationProvider.h"
 
+#include "StringFunctions.h"
 #include <WebKit/WKMutableArray.h>
 #include <WebKit/WKNotification.h>
 #include <WebKit/WKNotificationManager.h>
@@ -66,8 +67,8 @@
 
 WebNotificationProvider::~WebNotificationProvider()
 {
-    for (auto& manager : m_ownedNotifications)
-        WKNotificationManagerSetProvider(manager.key.get(), nullptr);
+    for (auto& manager : m_knownManagers)
+        WKNotificationManagerSetProvider(manager.get(), nullptr);
 }
 
 WKNotificationProviderV0 WebNotificationProvider::provider()
@@ -89,44 +90,26 @@
 {
     auto context = WKPageGetContext(page);
     auto notificationManager = WKContextGetNotificationManager(context);
-    uint64_t id = WKNotificationGetID(notification);
+    ASSERT(m_knownManagers.contains(notificationManager));
 
-    ASSERT(m_ownedNotifications.contains(notificationManager));
-    auto addResult = m_ownedNotifications.find(notificationManager)->value.add(id);
+    uint64_t identifier = WKNotificationGetID(notification);
+    auto coreIdentifier = adoptWK(WKNotificationCopyCoreIDForTesting(notification));
+
+    auto addResult = m_owningManager.set(toWTFString(coreIdentifier.get()), notificationManager);
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
-    auto addResult2 = m_owningManager.set(id, notificationManager);
-    ASSERT_UNUSED(addResult2, addResult2.isNewEntry);
-    auto addResult3 = m_localToGlobalNotificationIDMap.add(std::make_pair(page, WKNotificationManagerGetLocalIDForTesting(notificationManager, notification)), id);
-    ASSERT_UNUSED(addResult3, addResult3.isNewEntry);
 
-    WKNotificationManagerProviderDidShowNotification(notificationManager, id);
+    WKNotificationManagerProviderDidShowNotification(notificationManager, identifier);
 }
 
-static void removeGlobalIDFromIDMap(HashMap<std::pair<WKPageRef, uint64_t>, uint64_t>& map, uint64_t id)
-{
-    for (auto iter = map.begin(); iter != map.end(); ++iter) {
-        if (iter->value == id) {
-            map.remove(iter);
-            return;
-        }
-    }
-    ASSERT_NOT_REACHED();
-}
-
 void WebNotificationProvider::closeWebNotification(WKNotificationRef notification)
 {
-    uint64_t id = WKNotificationGetID(notification);
-    ASSERT(m_owningManager.contains(id));
-    auto notificationManager = m_owningManager.get(id);
+    auto identifier = toWTFString(adoptWK(WKNotificationCopyCoreIDForTesting(notification)).get());
 
-    ASSERT(m_ownedNotifications.contains(notificationManager));
-    bool success = m_ownedNotifications.find(notificationManager)->value.remove(id);
-    ASSERT_UNUSED(success, success);
-    m_owningManager.remove(id);
+    auto notificationManager = m_owningManager.take(identifier);
+    ASSERT(notificationManager);
+    ASSERT(m_knownManagers.contains(notificationManager));
 
-    removeGlobalIDFromIDMap(m_localToGlobalNotificationIDMap, id);
-
-    auto wkID = adoptWK(WKUInt64Create(id));
+    auto wkID = adoptWK(WKUInt64Create(WKNotificationGetID(notification)));
     auto array = adoptWK(WKMutableArrayCreate());
     WKArrayAppendItem(array.get(), wkID.get());
     WKNotificationManagerProviderDidCloseNotifications(notificationManager, array.get());
@@ -134,23 +117,28 @@
 
 void WebNotificationProvider::addNotificationManager(WKNotificationManagerRef manager)
 {
-    m_ownedNotifications.add(manager, HashSet<uint64_t>());
+    ASSERT(!m_knownManagers.contains(manager));
+    m_knownManagers.add(manager);
 }
 
 void WebNotificationProvider::removeNotificationManager(WKNotificationManagerRef manager)
 {
-    auto iterator = m_ownedNotifications.find(manager);
-    ASSERT(iterator != m_ownedNotifications.end());
-    auto toRemove = iterator->value;
-    WKRetainPtr<WKNotificationManagerRef> guard(manager);
-    m_ownedNotifications.remove(iterator);
+    auto protectedManager = m_knownManagers.take(manager);
+    ASSERT(protectedManager);
+
+    auto toRemove = Vector<String> { };
+    for (auto& iterator : m_owningManager) {
+        if (iterator.value != manager)
+            continue;
+        toRemove.append(iterator.key);
+    }
+
     auto array = adoptWK(WKMutableArrayCreate());
-    for (uint64_t notificationID : toRemove) {
-        bool success = m_owningManager.remove(notificationID);
-        ASSERT_UNUSED(success, success);
-        removeGlobalIDFromIDMap(m_localToGlobalNotificationIDMap, notificationID);
-        WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get());
+    for (auto& identifier : toRemove) {
+        WKArrayAppendItem(array.get(), toWK(identifier).get());
+        m_owningManager.remove(identifier);
     }
+
     WKNotificationManagerProviderDidCloseNotifications(manager, array.get());
 }
 
@@ -160,28 +148,23 @@
     return WKMutableDictionaryCreate();
 }
 
-void WebNotificationProvider::simulateWebNotificationClick(WKPageRef page, uint64_t notificationID)
+void WebNotificationProvider::simulateWebNotificationClick(WKPageRef, WKStringRef notificationID)
 {
-    ASSERT(m_localToGlobalNotificationIDMap.contains(std::make_pair(page, notificationID)));
-    auto globalID = m_localToGlobalNotificationIDMap.get(std::make_pair(page, notificationID));
-    ASSERT(m_owningManager.contains(globalID));
-    WKNotificationManagerProviderDidClickNotification(m_owningManager.get(globalID), globalID);
+    auto identifier = toWTFString(notificationID);
+    ASSERT(m_owningManager.contains(identifier));
+
+    WKNotificationManagerProviderDidClickNotification_b(m_owningManager.get(identifier), notificationID);
 }
 
 void WebNotificationProvider::reset()
 {
-    for (auto& notificationPair : m_ownedNotifications) {
-        if (notificationPair.value.isEmpty())
-            continue;
+    for (auto iterator : m_owningManager) {
         auto array = adoptWK(WKMutableArrayCreate());
-        for (uint64_t notificationID : notificationPair.value)
-            WKArrayAppendItem(array.get(), adoptWK(WKUInt64Create(notificationID)).get());
+        WKArrayAppendItem(array.get(), toWK(iterator.key).get());
+        WKNotificationManagerProviderDidCloseNotifications(iterator.value, array.get());
+    }
 
-        notificationPair.value.clear();
-        WKNotificationManagerProviderDidCloseNotifications(notificationPair.key.get(), array.get());
-    }
     m_owningManager.clear();
-    m_localToGlobalNotificationIDMap.clear();
 }
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/WebNotificationProvider.h (287338 => 287339)


--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.h	2021-12-22 01:39:27 UTC (rev 287338)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.h	2021-12-22 02:31:40 UTC (rev 287339)
@@ -31,6 +31,7 @@
 #include <WebKit/WKRetainPtr.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/text/StringHash.h>
 
 namespace WTR {
 
@@ -46,15 +47,12 @@
     void removeNotificationManager(WKNotificationManagerRef);
     WKDictionaryRef notificationPermissions();
 
-    void simulateWebNotificationClick(WKPageRef, uint64_t notificationID);
+    void simulateWebNotificationClick(WKPageRef, WKStringRef notificationID);
     void reset();
 
 private:
-    // Inverses of each other.
-    HashMap<WKRetainPtr<WKNotificationManagerRef>, HashSet<uint64_t>> m_ownedNotifications;
-    HashMap<uint64_t, WKNotificationManagerRef> m_owningManager;
-
-    HashMap<std::pair<WKPageRef, uint64_t>, uint64_t> m_localToGlobalNotificationIDMap;
+    HashSet<WKRetainPtr<WKNotificationManagerRef>> m_knownManagers;
+    HashMap<String, WKNotificationManagerRef> m_owningManager;
 };
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to