Title: [289153] trunk/Source
Revision
289153
Author
beid...@apple.com
Date
2022-02-05 00:10:36 -0800 (Sat, 05 Feb 2022)

Log Message

Notification refactoring
https://bugs.webkit.org/show_bug.cgi?id=236169

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (No behavior change)

Some "no behavior change" refactors broken out from an upcoming larger patch, including:
- Make Notification objects reliant on ScriptExecutionContext instead of Document
- Give them a direct path to a NotificationClient instead of having to go through a Page's NotificationController
- Give ScriptExecutionContext's a sessionID() accessor for future use
- Some Notification object threading hardening

* Modules/notifications/Notification.cpp:
(WebCore::Notification::create):
(WebCore::Notification::Notification):
(WebCore::Notification::show):
(WebCore::Notification::close):
(WebCore::Notification::clientFromContext):
(WebCore::Notification::stop):
(WebCore::Notification::dispatchErrorEvent):
(WebCore::Notification::permission):
(WebCore::Notification::requestPermission):
(WebCore::Notification::data const):
(WebCore::Notification::document const): Deleted.
* Modules/notifications/Notification.h:

* Modules/notifications/NotificationClient.h:

* Modules/notifications/NotificationData.h:
(WebCore::NotificationData::encode const):
(WebCore::NotificationData::decode):

* dom/Document.cpp:
(WebCore::Document::notificationClient):
(WebCore::Document::sessionID const):
* dom/Document.h:

* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::isServiceWorkerGlobalScope const):
(WebCore::ScriptExecutionContext::notificationClient):
(WebCore::ScriptExecutionContext::sessionID const):

* workers/WorkerThread.h:

* workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::create):
(WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
* workers/service/ServiceWorkerGlobalScope.h:

* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::generateWorkerParameters):
(WebCore::ServiceWorkerThread::ServiceWorkerThread):
(WebCore::m_notificationClient):
(WebCore::ServiceWorkerThread::createWorkerGlobalScope):
* workers/service/context/ServiceWorkerThread.h:

* workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
* workers/service/context/ServiceWorkerThreadProxy.h:

Source/WebKit:

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::installServiceWorker):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289152 => 289153)


--- trunk/Source/WebCore/ChangeLog	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/ChangeLog	2022-02-05 08:10:36 UTC (rev 289153)
@@ -1,3 +1,66 @@
+2022-02-05  Brady Eidson  <beid...@apple.com>
+
+        Notification refactoring
+        https://bugs.webkit.org/show_bug.cgi?id=236169
+
+        Reviewed by Alex Christensen.
+
+        No new tests (No behavior change)
+        
+        Some "no behavior change" refactors broken out from an upcoming larger patch, including:
+        - Make Notification objects reliant on ScriptExecutionContext instead of Document
+        - Give them a direct path to a NotificationClient instead of having to go through a Page's NotificationController
+        - Give ScriptExecutionContext's a sessionID() accessor for future use
+        - Some Notification object threading hardening
+
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::create):
+        (WebCore::Notification::Notification):
+        (WebCore::Notification::show):
+        (WebCore::Notification::close):
+        (WebCore::Notification::clientFromContext):
+        (WebCore::Notification::stop):
+        (WebCore::Notification::dispatchErrorEvent):
+        (WebCore::Notification::permission):
+        (WebCore::Notification::requestPermission):
+        (WebCore::Notification::data const):
+        (WebCore::Notification::document const): Deleted.
+        * Modules/notifications/Notification.h:
+        
+        * Modules/notifications/NotificationClient.h:
+        
+        * Modules/notifications/NotificationData.h:
+        (WebCore::NotificationData::encode const):
+        (WebCore::NotificationData::decode):
+        
+        * dom/Document.cpp:
+        (WebCore::Document::notificationClient):
+        (WebCore::Document::sessionID const):
+        * dom/Document.h:
+        
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::isServiceWorkerGlobalScope const):
+        (WebCore::ScriptExecutionContext::notificationClient):
+        (WebCore::ScriptExecutionContext::sessionID const):
+        
+        * workers/WorkerThread.h:
+        
+        * workers/service/ServiceWorkerGlobalScope.cpp:
+        (WebCore::ServiceWorkerGlobalScope::create):
+        (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
+        * workers/service/ServiceWorkerGlobalScope.h:
+        
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::generateWorkerParameters):
+        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
+        (WebCore::m_notificationClient):
+        (WebCore::ServiceWorkerThread::createWorkerGlobalScope):
+        * workers/service/context/ServiceWorkerThread.h:
+        
+        * workers/service/context/ServiceWorkerThreadProxy.cpp:
+        (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
+        * workers/service/context/ServiceWorkerThreadProxy.h:
+
 2022-02-04  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         ch unit fallback size doesn't match the spec

Modified: trunk/Source/WebCore/Modules/notifications/Notification.cpp (289152 => 289153)


--- trunk/Source/WebCore/Modules/notifications/Notification.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/Modules/notifications/Notification.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2009, 2011, 2012, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011, 2012, 2016, 2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -35,12 +35,10 @@
 
 #include "Notification.h"
 
-#include "Document.h"
 #include "Event.h"
 #include "EventNames.h"
 #include "JSDOMPromiseDeferred.h"
 #include "NotificationClient.h"
-#include "NotificationController.h"
 #include "NotificationData.h"
 #include "NotificationPermissionCallback.h"
 #include "WindowEventLoop.h"
@@ -52,7 +50,7 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Notification);
 
-Ref<Notification> Notification::create(Document& context, const String& title, const Options& options)
+Ref<Notification> Notification::create(ScriptExecutionContext& context, const String& title, const Options& options)
 {
     auto notification = adoptRef(*new Notification(context, title, options));
     notification->suspendIfNeeded();
@@ -60,17 +58,24 @@
     return notification;
 }
 
-Notification::Notification(Document& document, const String& title, const Options& options)
-    : ActiveDOMObject(document)
-    , m_title(title)
+Notification::Notification(ScriptExecutionContext& context, const String& title, const Options& options)
+    : ActiveDOMObject(&context)
+    , m_title(title.isolatedCopy())
     , m_direction(options.dir)
-    , m_lang(options.lang)
-    , m_body(options.body)
-    , m_tag(options.tag)
+    , m_lang(options.lang.isolatedCopy())
+    , m_body(options.body.isolatedCopy())
+    , m_tag(options.tag.isolatedCopy())
     , m_state(Idle)
 {
+    if (context.isDocument())
+        m_notificationSource = NotificationSource::Document;
+    else if (context.isServiceWorkerGlobalScope())
+        m_notificationSource = NotificationSource::ServiceWorker;
+    else
+        RELEASE_ASSERT_NOT_REACHED();
+
     if (!options.icon.isEmpty()) {
-        auto iconURL = document.completeURL(options.icon);
+        auto iconURL = context.completeURL(options.icon);
         if (iconURL.isValid())
             m_icon = iconURL;
     }
@@ -92,17 +97,15 @@
     if (m_state != Idle)
         return;
 
-    auto* page = document()->page();
-    if (!page)
+    auto* client = clientFromContext();
+    if (!client)
         return;
 
-    auto& client = NotificationController::from(page)->client();
-
-    if (client.checkPermission(scriptExecutionContext()) != Permission::Granted) {
+    if (client->checkPermission(scriptExecutionContext()) != Permission::Granted) {
         dispatchErrorEvent();
         return;
     }
-    if (client.show(*this))
+    if (client->show(*this))
         m_state = Showing;
 }
 
@@ -112,8 +115,8 @@
     case Idle:
         break;
     case Showing: {
-        if (auto* page = document()->page())
-            NotificationController::from(page)->client().cancel(*this);
+        if (auto* client = clientFromContext())
+            client->cancel(*this);
         break;
     }
     case Closed:
@@ -121,9 +124,11 @@
     }
 }
 
-Document* Notification::document() const
+NotificationClient* Notification::clientFromContext()
 {
-    return downcast<Document>(scriptExecutionContext());
+    if (auto* context = scriptExecutionContext())
+        return context->notificationClient();
+    return nullptr;
 }
 
 const char* Notification::activeDOMObjectName() const
@@ -135,8 +140,8 @@
 {
     ActiveDOMObject::stop();
 
-    if (auto* page = document()->page())
-        NotificationController::from(page)->client().notificationObjectDestroyed(*this);
+    if (auto* client = clientFromContext())
+        client->notificationObjectDestroyed(*this);
 }
 
 void Notification::suspend(ReasonForSuspension)
@@ -172,19 +177,22 @@
 
 void Notification::dispatchErrorEvent()
 {
+    ASSERT(isMainThread());
+    ASSERT(m_notificationSource == NotificationSource::Document);
+
     queueTaskToDispatchEvent(*this, TaskSource::UserInteraction, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
 
-auto Notification::permission(Document& document) -> Permission
+auto Notification::permission(ScriptExecutionContext& context) -> Permission
 {
-    auto* page = document.page();
-    if (!page)
+    auto* client = context.notificationClient();
+    if (!client)
         return Permission::Default;
 
-    if (!document.isSecureContext())
+    if (!context.isSecureContext())
         return Permission::Denied;
 
-    return NotificationController::from(document.page())->client().checkPermission(&document);
+    return client->checkPermission(&context);
 }
 
 void Notification::requestPermission(Document& document, RefPtr<NotificationPermissionCallback>&& callback, Ref<DeferredPromise>&& promise)
@@ -197,8 +205,8 @@
         });
     };
 
-    auto* page = document.page();
-    if (!page)
+    auto* client = static_cast<ScriptExecutionContext&>(document).notificationClient();
+    if (!client)
         return resolvePromiseAndCallback(Permission::Denied);
 
     if (!document.isSecureContext()) {
@@ -206,7 +214,7 @@
         return resolvePromiseAndCallback(Permission::Denied);
     }
 
-    NotificationController::from(page)->client().requestPermission(document, WTFMove(resolvePromiseAndCallback));
+    client->requestPermission(document, WTFMove(resolvePromiseAndCallback));
 }
 
 void Notification::eventListenersDidChange()
@@ -227,15 +235,19 @@
 
 NotificationData Notification::data() const
 {
+    auto sessionID = scriptExecutionContext()->sessionID();
+    RELEASE_ASSERT(sessionID);
+
     return {
-        m_title,
-        m_body,
-        m_icon.string(),
+        m_title.isolatedCopy(),
+        m_body.isolatedCopy(),
+        m_icon.string().isolatedCopy(),
         m_tag,
         m_lang,
         m_direction,
-        scriptExecutionContext()->securityOrigin()->toString(),
+        scriptExecutionContext()->securityOrigin()->toString().isolatedCopy(),
         identifier(),
+        *sessionID,
     };
 }
 

Modified: trunk/Source/WebCore/Modules/notifications/Notification.h (289152 => 289153)


--- trunk/Source/WebCore/Modules/notifications/Notification.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/Modules/notifications/Notification.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2009, 2011, 2012, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011, 2012, 2016, 2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -45,6 +45,7 @@
 
 class DeferredPromise;
 class Document;
+class NotificationClient;
 class NotificationPermissionCallback;
 
 struct NotificationData;
@@ -62,7 +63,7 @@
         String tag;
         String icon;
     };
-    static Ref<Notification> create(Document&, const String& title, const Options&);
+    static Ref<Notification> create(ScriptExecutionContext&, const String& title, const Options&);
     
     WEBCORE_EXPORT virtual ~Notification();
 
@@ -85,7 +86,7 @@
 
     WEBCORE_EXPORT void finalize();
 
-    static Permission permission(Document&);
+    static Permission permission(ScriptExecutionContext&);
     static void requestPermission(Document&, RefPtr<NotificationPermissionCallback>&&, Ref<DeferredPromise>&&);
 
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
@@ -96,9 +97,9 @@
     using ThreadSafeRefCounted::deref;
 
 private:
-    Notification(Document&, const String& title, const Options&);
+    Notification(ScriptExecutionContext&, const String& title, const Options&);
 
-    Document* document() const;
+    NotificationClient* clientFromContext();
     EventTargetInterface eventTargetInterface() const final { return NotificationEventTargetInterfaceType; }
 
     void showSoon();
@@ -124,6 +125,12 @@
     enum State { Idle, Showing, Closed };
     State m_state { Idle };
     bool m_hasRelevantEventListener { false };
+
+    enum class NotificationSource : bool {
+        Document,
+        ServiceWorker,
+    };
+    NotificationSource m_notificationSource;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/notifications/NotificationClient.h (289152 => 289153)


--- trunk/Source/WebCore/Modules/notifications/NotificationClient.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/Modules/notifications/NotificationClient.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -68,7 +68,6 @@
     // Checks the current level of permission.
     virtual Permission checkPermission(ScriptExecutionContext*) = 0;
 
-protected:
     virtual ~NotificationClient() = default;
 };
 

Modified: trunk/Source/WebCore/Modules/notifications/NotificationData.h (289152 => 289153)


--- trunk/Source/WebCore/Modules/notifications/NotificationData.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/Modules/notifications/NotificationData.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <optional>
+#include <pal/SessionID.h>
 #include <wtf/UUID.h>
 #include <wtf/text/WTFString.h>
 
@@ -45,12 +46,13 @@
     WebCore::NotificationDirection direction;
     String originString;
     UUID notificationID;
+    PAL::SessionID sourceSession;
 };
 
 template<class Encoder>
 void NotificationData::encode(Encoder& encoder) const
 {
-    encoder << title << body << iconURL << tag << language << direction << originString << notificationID;
+    encoder << title << body << iconURL << tag << language << direction << originString << notificationID << sourceSession;
 }
 
 template<class Decoder>
@@ -96,6 +98,11 @@
     if (!notificationID)
         return std::nullopt;
 
+    std::optional<PAL::SessionID> sourceSession;
+    decoder >> sourceSession;
+    if (!sourceSession)
+        return std::nullopt;
+
     return { {
         WTFMove(*title),
         WTFMove(*body),
@@ -105,6 +112,7 @@
         WTFMove(*direction),
         WTFMove(*originString),
         WTFMove(*notificationID),
+        WTFMove(*sourceSession),
     } };
 }
 

Modified: trunk/Source/WebCore/dom/Document.cpp (289152 => 289153)


--- trunk/Source/WebCore/dom/Document.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -160,6 +160,7 @@
 #include "NodeIterator.h"
 #include "NodeRareData.h"
 #include "NodeWithIndex.h"
+#include "NotificationController.h"
 #include "OverflowEvent.h"
 #include "PageConsoleClient.h"
 #include "PageGroup.h"
@@ -9064,6 +9065,27 @@
     callback();
 }
 
+NotificationClient* Document::notificationClient()
+{
+#if ENABLE(NOTIFICATIONS)
+    auto* page = this->page();
+    if (!page)
+        return nullptr;
+
+    return &NotificationController::from(page)->client();
+#else
+    return nullptr;
+#endif
+}
+
+std::optional<PAL::SessionID> Document::sessionID() const
+{
+    if (auto* page = this->page())
+        return page->sessionID();
+
+    return std::nullopt;
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG

Modified: trunk/Source/WebCore/dom/Document.h (289152 => 289153)


--- trunk/Source/WebCore/dom/Document.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/dom/Document.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -1796,6 +1796,9 @@
     void addToDocumentsMap();
     void removeFromDocumentsMap();
 
+    NotificationClient* notificationClient() final;
+    std::optional<PAL::SessionID> sessionID() const final;
+
     const Ref<const Settings> m_settings;
 
     UniqueRef<Quirks> m_quirks;

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (289152 => 289153)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -36,6 +36,7 @@
 #include "Settings.h"
 #include <_javascript_Core/ConsoleTypes.h>
 #include <_javascript_Core/HandleTypes.h>
+#include <pal/SessionID.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/Function.h>
 #include <wtf/HashSet.h>
@@ -68,6 +69,7 @@
 class EventTarget;
 class FontLoadRequest;
 class MessagePort;
+class NotificationClient;
 class PermissionController;
 class PublicURLManager;
 class RejectedPromiseTracker;
@@ -94,6 +96,7 @@
 
     virtual bool isDocument() const { return false; }
     virtual bool isWorkerGlobalScope() const { return false; }
+    virtual bool isServiceWorkerGlobalScope() const { return false; }
     virtual bool isShadowRealmGlobalScope() const { return false; }
     virtual bool isWorkletGlobalScope() const { return false; }
 
@@ -112,6 +115,9 @@
 
     virtual const Settings::Values& settingsValues() const = 0;
 
+    virtual NotificationClient* notificationClient() { return nullptr; }
+    virtual std::optional<PAL::SessionID> sessionID() const { return std::nullopt; }
+
     virtual void disableEval(const String& errorMessage) = 0;
     virtual void disableWebAssembly(const String& errorMessage) = 0;
 

Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (289152 => 289153)


--- trunk/Source/WebCore/workers/WorkerThread.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -61,7 +61,8 @@
         workerType,
         credentials,
         settingsValues.isolatedCopy(),
-        workerThreadMode
+        workerThreadMode,
+        sessionID,
     };
 }
 

Modified: trunk/Source/WebCore/workers/WorkerThread.h (289152 => 289153)


--- trunk/Source/WebCore/workers/WorkerThread.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/WorkerThread.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -33,6 +33,7 @@
 #include "WorkerType.h"
 #include <_javascript_Core/RuntimeFlags.h>
 #include <memory>
+#include <pal/SessionID.h>
 #include <wtf/URL.h>
 
 namespace WebCore {
@@ -73,6 +74,7 @@
     FetchRequestCredentials credentials;
     Settings::Values settingsValues;
     WorkerThreadMode workerThreadMode { WorkerThreadMode::CreateNewThread };
+    std::optional<PAL::SessionID> sessionID { std::nullopt };
 
     WorkerParameters isolatedCopy() const;
 };

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp (289152 => 289153)


--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -50,20 +50,22 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(ServiceWorkerGlobalScope);
 
-Ref<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::create(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, ServiceWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
+Ref<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::create(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, ServiceWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, std::unique_ptr<NotificationClient>&& notificationClient, PAL::SessionID sessionID)
 {
-    auto scope = adoptRef(*new ServiceWorkerGlobalScope { WTFMove(contextData), WTFMove(workerData), params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider });
+    auto scope = adoptRef(*new ServiceWorkerGlobalScope { WTFMove(contextData), WTFMove(workerData), params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider, WTFMove(notificationClient), sessionID });
     scope->applyContentSecurityPolicyResponseHeaders(params.contentSecurityPolicyResponseHeaders);
     scope->notifyServiceWorkerPageOfCreationIfNecessary();
     return scope;
 }
 
-ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, ServiceWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
+ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, ServiceWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, std::unique_ptr<NotificationClient>&& notificationClient, PAL::SessionID sessionID)
     : WorkerGlobalScope(WorkerThreadType::ServiceWorker, params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider)
     , m_contextData(WTFMove(contextData))
     , m_registration(ServiceWorkerRegistration::getOrCreate(*this, navigator().serviceWorker(), WTFMove(m_contextData.registration)))
     , m_serviceWorker(ServiceWorker::getOrCreate(*this, WTFMove(workerData)))
     , m_clients(ServiceWorkerClients::create())
+    , m_sessionID(sessionID)
+    , m_notificationClient(WTFMove(notificationClient))
 {
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h (289152 => 289153)


--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "NotificationClient.h"
 #include "ScriptExecutionContextIdentifier.h"
 #include "ServiceWorkerContextData.h"
 #include "ServiceWorkerRegistration.h"
@@ -46,10 +47,12 @@
 class ServiceWorkerGlobalScope final : public WorkerGlobalScope {
     WTF_MAKE_ISO_ALLOCATED(ServiceWorkerGlobalScope);
 public:
-    static Ref<ServiceWorkerGlobalScope> create(ServiceWorkerContextData&&, ServiceWorkerData&&, const WorkerParameters&, Ref<SecurityOrigin>&&, ServiceWorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
+    static Ref<ServiceWorkerGlobalScope> create(ServiceWorkerContextData&&, ServiceWorkerData&&, const WorkerParameters&, Ref<SecurityOrigin>&&, ServiceWorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, std::unique_ptr<NotificationClient>&&, PAL::SessionID);
 
     ~ServiceWorkerGlobalScope();
 
+    bool isServiceWorkerGlobalScope() const final { return true; }
+
     ServiceWorkerClients& clients() { return m_clients.get(); }
     ServiceWorkerRegistration& registration() { return m_registration.get(); }
     ServiceWorker& serviceWorker() { return m_serviceWorker.get(); }
@@ -79,12 +82,15 @@
     WEBCORE_EXPORT Page* serviceWorkerPage();
     
 private:
-    ServiceWorkerGlobalScope(ServiceWorkerContextData&&, ServiceWorkerData&&, const WorkerParameters&, Ref<SecurityOrigin>&&, ServiceWorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
+    ServiceWorkerGlobalScope(ServiceWorkerContextData&&, ServiceWorkerData&&, const WorkerParameters&, Ref<SecurityOrigin>&&, ServiceWorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, std::unique_ptr<NotificationClient>&&, PAL::SessionID);
     void notifyServiceWorkerPageOfCreationIfNecessary();
 
     Type type() const final { return Type::ServiceWorker; }
     bool hasPendingEvents() const { return !m_extendedEvents.isEmpty(); }
 
+    NotificationClient* notificationClient() final { return m_notificationClient.get(); }
+    std::optional<PAL::SessionID> sessionID() const final { return m_sessionID; }
+
     ServiceWorkerContextData m_contextData;
     Ref<ServiceWorkerRegistration> m_registration;
     Ref<ServiceWorker> m_serviceWorker;
@@ -94,6 +100,8 @@
 
     uint64_t m_lastRequestIdentifier { 0 };
     HashMap<uint64_t, RefPtr<DeferredPromise>> m_pendingSkipWaitingPromises;
+    PAL::SessionID m_sessionID;
+    std::unique_ptr<NotificationClient> m_notificationClient;
 };
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -76,7 +76,7 @@
 // FIXME: Use a valid WorkerObjectProxy
 // FIXME: Use valid runtime flags
 
-static WorkerParameters generateWorkerParameters(const ServiceWorkerContextData& contextData, String&& userAgent, WorkerThreadMode workerThreadMode, const Settings::Values& settingsValues)
+static WorkerParameters generateWorkerParameters(const ServiceWorkerContextData& contextData, String&& userAgent, WorkerThreadMode workerThreadMode, const Settings::Values& settingsValues, PAL::SessionID sessionID)
 {
     return {
         contextData.scriptURL,
@@ -92,12 +92,13 @@
         contextData.workerType,
         FetchRequestCredentials::Omit,
         settingsValues,
-        workerThreadMode
+        workerThreadMode,
+        sessionID
     };
 }
 
-ServiceWorkerThread::ServiceWorkerThread(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, String&& userAgent, WorkerThreadMode workerThreadMode, const Settings::Values& settingsValues, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider)
-    : WorkerThread(generateWorkerParameters(contextData, WTFMove(userAgent), workerThreadMode, settingsValues), contextData.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, contextData.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
+ServiceWorkerThread::ServiceWorkerThread(ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, String&& userAgent, WorkerThreadMode workerThreadMode, const Settings::Values& settingsValues, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider, std::unique_ptr<NotificationClient>&& notificationClient, PAL::SessionID sessionID)
+    : WorkerThread(generateWorkerParameters(contextData, WTFMove(userAgent), workerThreadMode, settingsValues, sessionID), contextData.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, contextData.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())
     , m_serviceWorkerIdentifier(contextData.serviceWorkerIdentifier)
     , m_jobDataIdentifier(contextData.jobDataIdentifier)
     , m_contextData(crossThreadCopy(WTFMove(contextData)))
@@ -105,6 +106,7 @@
     , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
     , m_heartBeatTimeout(settingsValues.shouldUseServiceWorkerShortTimeout ? heartBeatTimeoutForTest : heartBeatTimeout)
     , m_heartBeatTimer { *this, &ServiceWorkerThread::heartBeatTimerFired }
+    , m_notificationClient(WTFMove(notificationClient))
 {
     ASSERT(isMainThread());
     AtomString::init();
@@ -115,7 +117,8 @@
 Ref<WorkerGlobalScope> ServiceWorkerThread::createWorkerGlobalScope(const WorkerParameters& params, Ref<SecurityOrigin>&& origin, Ref<SecurityOrigin>&& topOrigin)
 {
     RELEASE_ASSERT(m_contextData);
-    return ServiceWorkerGlobalScope::create(*std::exchange(m_contextData, std::nullopt), *std::exchange(m_workerData, std::nullopt), params, WTFMove(origin), *this, WTFMove(topOrigin), idbConnectionProxy(), socketProvider());
+    RELEASE_ASSERT(params.sessionID);
+    return ServiceWorkerGlobalScope::create(*std::exchange(m_contextData, std::nullopt), *std::exchange(m_workerData, std::nullopt), params, WTFMove(origin), *this, WTFMove(topOrigin), idbConnectionProxy(), socketProvider(), WTFMove(m_notificationClient), *params.sessionID);
 }
 
 void ServiceWorkerThread::runEventLoop()

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


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "NotificationClient.h"
 #include "PushSubscriptionData.h"
 #include "ScriptExecutionContextIdentifier.h"
 #include "ServiceWorkerContextData.h"
@@ -85,7 +86,7 @@
     void runEventLoop() override;
 
 private:
-    WEBCORE_EXPORT ServiceWorkerThread(ServiceWorkerContextData&&, ServiceWorkerData&&, String&& userAgent, WorkerThreadMode, const Settings::Values&, WorkerLoaderProxy&, WorkerDebuggerProxy&, IDBClient::IDBConnectionProxy*, SocketProvider*);
+    WEBCORE_EXPORT ServiceWorkerThread(ServiceWorkerContextData&&, ServiceWorkerData&&, String&& userAgent, WorkerThreadMode, const Settings::Values&, WorkerLoaderProxy&, WorkerDebuggerProxy&, IDBClient::IDBConnectionProxy*, SocketProvider*, std::unique_ptr<NotificationClient>&&, PAL::SessionID);
 
     ASCIILiteral threadName() const final { return "WebCore: ServiceWorker"_s; }
     void finishedEvaluatingScript() final;
@@ -119,6 +120,7 @@
     static constexpr Seconds heartBeatTimeoutForTest { 1_s };
     Seconds m_heartBeatTimeout { heartBeatTimeout };
     Timer m_heartBeatTimer;
+    std::unique_ptr<NotificationClient> m_notificationClient;
 };
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -62,13 +62,13 @@
     return set;
 }
 
-ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(UniqueRef<Page>&& page, ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, String&& userAgent, WorkerThreadMode workerThreadMode, CacheStorageProvider& cacheStorageProvider)
+ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(UniqueRef<Page>&& page, ServiceWorkerContextData&& contextData, ServiceWorkerData&& workerData, String&& userAgent, WorkerThreadMode workerThreadMode, CacheStorageProvider& cacheStorageProvider, std::unique_ptr<NotificationClient>&& notificationClient)
     : m_page(WTFMove(page))
     , m_document(*m_page->mainFrame().document())
 #if ENABLE(REMOTE_INSPECTOR)
     , m_remoteDebuggable(makeUnique<ServiceWorkerDebuggable>(*this, contextData))
 #endif
-    , m_serviceWorkerThread(ServiceWorkerThread::create(WTFMove(contextData), WTFMove(workerData), WTFMove(userAgent), workerThreadMode, m_document->settingsValues(), *this, *this, idbConnectionProxy(m_document), m_document->socketProvider()))
+    , m_serviceWorkerThread(ServiceWorkerThread::create(WTFMove(contextData), WTFMove(workerData), WTFMove(userAgent), workerThreadMode, m_document->settingsValues(), *this, *this, idbConnectionProxy(m_document), m_document->socketProvider(), WTFMove(notificationClient), m_page->sessionID()))
     , m_cacheStorageProvider(cacheStorageProvider)
     , m_inspectorProxy(*this)
 {

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


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h	2022-02-05 08:10:36 UTC (rev 289153)
@@ -91,7 +91,7 @@
     WEBCORE_EXPORT bool lastNavigationWasAppInitiated();
 
 private:
-    WEBCORE_EXPORT ServiceWorkerThreadProxy(UniqueRef<Page>&&, ServiceWorkerContextData&&, ServiceWorkerData&&, String&& userAgent, WorkerThreadMode, CacheStorageProvider&);
+    WEBCORE_EXPORT ServiceWorkerThreadProxy(UniqueRef<Page>&&, ServiceWorkerContextData&&, ServiceWorkerData&&, String&& userAgent, WorkerThreadMode, CacheStorageProvider&, std::unique_ptr<NotificationClient>&&);
 
     WEBCORE_EXPORT static void networkStateChanged(bool isOnLine);
 

Modified: trunk/Source/WebKit/ChangeLog (289152 => 289153)


--- trunk/Source/WebKit/ChangeLog	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebKit/ChangeLog	2022-02-05 08:10:36 UTC (rev 289153)
@@ -1,3 +1,13 @@
+2022-02-05  Brady Eidson  <beid...@apple.com>
+
+        Notification refactoring
+        https://bugs.webkit.org/show_bug.cgi?id=236169
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::installServiceWorker):
+
 2022-02-04  Alex Christensen  <achristen...@webkit.org>
 
         Don't use adattributiond on iOS

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (289152 => 289153)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2022-02-05 07:26:52 UTC (rev 289152)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2022-02-05 08:10:36 UTC (rev 289153)
@@ -45,6 +45,7 @@
 #include "WebDatabaseProvider.h"
 #include "WebDocumentLoader.h"
 #include "WebFrameLoaderClient.h"
+#include "WebNotificationClient.h"
 #include "WebPage.h"
 #include "WebPreferencesKeys.h"
 #include "WebPreferencesStore.h"
@@ -147,8 +148,14 @@
         page->settings().setStorageBlockingPolicy(static_cast<StorageBlockingPolicy>(m_preferencesStore->getUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey())));
     }
     page->setupForRemoteWorker(contextData.scriptURL, contextData.registration.key.topOrigin(), contextData.referrerPolicy);
-    auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(page), WTFMove(contextData), WTFMove(workerData), WTFMove(effectiveUserAgent), workerThreadMode, WebProcess::singleton().cacheStorageProvider());
 
+    std::unique_ptr<WebCore::NotificationClient> notificationClient;
+#if ENABLE(NOTIFICATIONS)
+    notificationClient = makeUnique<WebNotificationClient>(nullptr);
+#endif
+
+    auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(page), WTFMove(contextData), WTFMove(workerData), WTFMove(effectiveUserAgent), workerThreadMode, WebProcess::singleton().cacheStorageProvider(), WTFMove(notificationClient));
+
     if (lastNavigationWasAppInitiated)
         serviceWorkerThreadProxy->setLastNavigationWasAppInitiated(lastNavigationWasAppInitiated == WebCore::LastNavigationWasAppInitiated::Yes);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to