Title: [256749] trunk/Source
Revision
256749
Author
[email protected]
Date
2020-02-17 11:23:56 -0800 (Mon, 17 Feb 2020)

Log Message

Do not send the client URL to network process
https://bugs.webkit.org/show_bug.cgi?id=207803

Reviewed by Darin Adler.

Source/WebCore:

Instead of sending the client URL through threads and IPC, we can retrieve it in NetworkProcess from the client identifier.
Implement this, as this is more efficient and safer.
No change of behavior.

* workers/service/SWClientConnection.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::unregisterRegistration):
* workers/service/WorkerSWClientConnection.cpp:
(WebCore::WorkerSWClientConnection::scheduleUnregisterJobInServer):
* workers/service/WorkerSWClientConnection.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::scheduleUnregisterJob):
* workers/service/server/SWServer.h:

Source/WebKit:

* NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::scheduleUnregisterJobInServer):
* NetworkProcess/ServiceWorker/WebSWServerConnection.h:
* NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::scheduleUnregisterJobInServer):
* WebProcess/Storage/WebSWClientConnection.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (256748 => 256749)


--- trunk/Source/WebCore/ChangeLog	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/ChangeLog	2020-02-17 19:23:56 UTC (rev 256749)
@@ -1,3 +1,24 @@
+2020-02-17  Youenn Fablet  <[email protected]>
+
+        Do not send the client URL to network process
+        https://bugs.webkit.org/show_bug.cgi?id=207803
+
+        Reviewed by Darin Adler.
+
+        Instead of sending the client URL through threads and IPC, we can retrieve it in NetworkProcess from the client identifier.
+        Implement this, as this is more efficient and safer.
+        No change of behavior.
+
+        * workers/service/SWClientConnection.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::unregisterRegistration):
+        * workers/service/WorkerSWClientConnection.cpp:
+        (WebCore::WorkerSWClientConnection::scheduleUnregisterJobInServer):
+        * workers/service/WorkerSWClientConnection.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::scheduleUnregisterJob):
+        * workers/service/server/SWServer.h:
+
 2020-02-17  Víctor Manuel Jáquez Leal  <[email protected]>
 
         a lot gcc warnings because of %{public}s format specifier

Modified: trunk/Source/WebCore/workers/service/SWClientConnection.h (256748 => 256749)


--- trunk/Source/WebCore/workers/service/SWClientConnection.h	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/workers/service/SWClientConnection.h	2020-02-17 19:23:56 UTC (rev 256749)
@@ -69,7 +69,7 @@
 
     virtual void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier) = 0;
     virtual void removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier) = 0;
-    virtual void scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier, DocumentOrWorkerIdentifier, const URL& /* clientCreationURL */, CompletionHandler<void(ExceptionOr<bool>&&)>&&) = 0;
+    virtual void scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier, DocumentOrWorkerIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&&) = 0;
 
     WEBCORE_EXPORT virtual void scheduleJob(DocumentOrWorkerIdentifier, const ServiceWorkerJobData&);
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (256748 => 256749)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2020-02-17 19:23:56 UTC (rev 256749)
@@ -189,13 +189,7 @@
 
 void ServiceWorkerContainer::unregisterRegistration(ServiceWorkerRegistrationIdentifier registrationIdentifier, DOMPromiseDeferred<IDLBoolean>&& promise)
 {
-    auto* context = scriptExecutionContext();
-    if (!context) {
-        ASSERT_NOT_REACHED();
-        promise.reject(Exception(InvalidStateError));
-        return;
-    }
-
+    ASSERT(!m_isStopped);
     if (!m_swConnection) {
         ASSERT_NOT_REACHED();
         promise.reject(Exception(InvalidStateError));
@@ -203,7 +197,7 @@
     }
 
     CONTAINER_RELEASE_LOG_IF_ALLOWED("unregisterRegistration: Unregistering service worker.");
-    m_swConnection->scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier(), context->url(), [promise = WTFMove(promise)](auto&& result) mutable {
+    m_swConnection->scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier(), [promise = WTFMove(promise)](auto&& result) mutable {
         promise.settle(WTFMove(result));
     });
 }

Modified: trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp (256748 => 256749)


--- trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp	2020-02-17 19:23:56 UTC (rev 256749)
@@ -196,14 +196,14 @@
     });
 }
 
-void WorkerSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentOrWorkerIdentifier contextIdentifier, const URL& clientCreationURL, CompletionHandler<void(ExceptionOr<bool>&&)>&& callback)
+void WorkerSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentOrWorkerIdentifier contextIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&& callback)
 {
     uint64_t requestIdentifier = ++m_lastRequestIdentifier;
     m_unregisterRequests.add(requestIdentifier, WTFMove(callback));
 
-    callOnMainThread([thread = m_thread.copyRef(), requestIdentifier, registrationIdentifier, contextIdentifier, clientCreationURL = crossThreadCopy(clientCreationURL)]() mutable {
+    callOnMainThread([thread = m_thread.copyRef(), requestIdentifier, registrationIdentifier, contextIdentifier]() mutable {
         auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
-        connection.scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier, clientCreationURL, [thread = WTFMove(thread), requestIdentifier](auto&& result) {
+        connection.scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier, [thread = WTFMove(thread), requestIdentifier](auto&& result) {
             thread->runLoop().postTaskForMode([requestIdentifier, result = crossThreadCopy(result)](auto& scope) mutable {
                 auto callback = downcast<WorkerGlobalScope>(scope).swClientConnection().m_unregisterRequests.take(requestIdentifier);
                 callback(WTFMove(result));

Modified: trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h (256748 => 256749)


--- trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h	2020-02-17 19:23:56 UTC (rev 256749)
@@ -57,7 +57,7 @@
     void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) final;
     void scheduleJobInServer(const ServiceWorkerJobData&) final;
     void scheduleJob(DocumentOrWorkerIdentifier, const ServiceWorkerJobData&) final;
-    void scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier, DocumentOrWorkerIdentifier, const URL& /* clientCreationURL */, CompletionHandler<void(ExceptionOr<bool>&&)>&&) final;
+    void scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier, DocumentOrWorkerIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&&) final;
 
     Ref<WorkerThread> m_thread;
 

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


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2020-02-17 19:23:56 UTC (rev 256749)
@@ -143,7 +143,7 @@
     WEBCORE_EXPORT Vector<ServiceWorkerRegistrationData> getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL);
 
     WEBCORE_EXPORT void scheduleJob(ServiceWorkerJobData&&);
-    WEBCORE_EXPORT void scheduleUnregisterJob(ServiceWorkerJobDataIdentifier, SWServerRegistration&, DocumentOrWorkerIdentifier, URL&& /* clientCreationURL */);
+    WEBCORE_EXPORT void scheduleUnregisterJob(ServiceWorkerJobDataIdentifier, SWServerRegistration&, DocumentOrWorkerIdentifier, URL&&);
 
     void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
     void resolveRegistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationData&, ShouldNotifyWhenResolved);
@@ -157,7 +157,7 @@
     void fireActivateEvent(SWServerWorker&);
 
     WEBCORE_EXPORT SWServerWorker* workerByID(ServiceWorkerIdentifier) const;
-    Optional<ServiceWorkerClientData> serviceWorkerClientWithOriginByID(const ClientOrigin&, const ServiceWorkerClientIdentifier&) const;
+    WEBCORE_EXPORT Optional<ServiceWorkerClientData> serviceWorkerClientWithOriginByID(const ClientOrigin&, const ServiceWorkerClientIdentifier&) const;
     String serviceWorkerClientUserAgent(const ClientOrigin&) const;
     WEBCORE_EXPORT SWServerWorker* activeWorkerFromRegistrationID(ServiceWorkerRegistrationIdentifier);
 

Modified: trunk/Source/WebKit/ChangeLog (256748 => 256749)


--- trunk/Source/WebKit/ChangeLog	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/ChangeLog	2020-02-17 19:23:56 UTC (rev 256749)
@@ -1,3 +1,18 @@
+2020-02-17  Youenn Fablet  <[email protected]>
+
+        Do not send the client URL to network process
+        https://bugs.webkit.org/show_bug.cgi?id=207803
+
+        Reviewed by Darin Adler.
+
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::scheduleUnregisterJobInServer):
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
+        * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::scheduleUnregisterJobInServer):
+        * WebProcess/Storage/WebSWClientConnection.h:
+
 2020-02-17  Víctor Manuel Jáquez Leal  <[email protected]>
 
         a lot gcc warnings because of %{public}s format specifier

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (256748 => 256749)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2020-02-17 19:23:56 UTC (rev 256749)
@@ -288,8 +288,30 @@
     server().scheduleJob(WTFMove(jobData));
 }
 
-void WebSWServerConnection::scheduleUnregisterJobInServer(WebCore::ServiceWorkerJobIdentifier jobIdentifier, WebCore::ServiceWorkerRegistrationIdentifier registrationIdentifier, WebCore::DocumentOrWorkerIdentifier contextIdentifier, URL&& clientCreationURL, CompletionHandler<void(UnregisterJobResult&&)>&& completionHandler)
+URL WebSWServerConnection::clientURLFromIdentifier(DocumentOrWorkerIdentifier contextIdentifier)
 {
+    return WTF::switchOn(contextIdentifier, [&](DocumentIdentifier documentIdentifier) -> URL {
+        ServiceWorkerClientIdentifier clientIdentifier { identifier(), documentIdentifier };
+
+        auto iterator = m_clientOrigins.find(clientIdentifier);
+        if (iterator == m_clientOrigins.end())
+            return { };
+
+        auto clientData = server().serviceWorkerClientWithOriginByID(iterator->value, clientIdentifier);
+        if (!clientData)
+            return { };
+
+        return clientData->url;
+    }, [&](ServiceWorkerIdentifier serviceWorkerIdentifier) -> URL {
+        auto* worker = server().workerByID(serviceWorkerIdentifier);
+        if (!worker)
+            return { };
+        return worker->data().scriptURL;
+    });
+}
+
+void WebSWServerConnection::scheduleUnregisterJobInServer(ServiceWorkerJobIdentifier jobIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentOrWorkerIdentifier contextIdentifier, CompletionHandler<void(UnregisterJobResult&&)>&& completionHandler)
+{
     SWSERVERCONNECTION_RELEASE_LOG_IF_ALLOWED("Scheduling unregister ServiceWorker job in server");
 
     auto* registration = server().getRegistration(registrationIdentifier);
@@ -296,10 +318,14 @@
     if (!registration)
         return completionHandler(false);
 
+    auto clientURL = clientURLFromIdentifier(contextIdentifier);
+    if (!clientURL.isValid())
+        return completionHandler(makeUnexpected(ExceptionData { InvalidStateError, "Client is unknown"_s }));
+
     ASSERT(!m_unregisterJobs.contains(jobIdentifier));
     m_unregisterJobs.add(jobIdentifier, WTFMove(completionHandler));
 
-    server().scheduleUnregisterJob(ServiceWorkerJobDataIdentifier { identifier(), jobIdentifier }, *registration, contextIdentifier, WTFMove(clientCreationURL));
+    server().scheduleUnregisterJob(ServiceWorkerJobDataIdentifier { identifier(), jobIdentifier }, *registration, contextIdentifier, WTFMove(clientURL));
 }
 
 void WebSWServerConnection::postMessageToServiceWorkerClient(DocumentIdentifier destinationContextIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (256748 => 256749)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2020-02-17 19:23:56 UTC (rev 256749)
@@ -94,7 +94,7 @@
     void scheduleJobInServer(WebCore::ServiceWorkerJobData&&);
 
     using UnregisterJobResult = Expected<bool, WebCore::ExceptionData>;
-    void scheduleUnregisterJobInServer(WebCore::ServiceWorkerJobIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentOrWorkerIdentifier, URL&&, CompletionHandler<void(UnregisterJobResult&&)>&&);
+    void scheduleUnregisterJobInServer(WebCore::ServiceWorkerJobIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentOrWorkerIdentifier, CompletionHandler<void(UnregisterJobResult&&)>&&);
 
     void startFetch(ServiceWorkerFetchTask&, WebCore::SWServerWorker&);
 
@@ -119,6 +119,8 @@
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source);
     void controlClient(WebCore::ServiceWorkerClientIdentifier, WebCore::SWServerRegistration&, const WebCore::ResourceRequest&);
 
+    URL clientURLFromIdentifier(WebCore::DocumentOrWorkerIdentifier);
+
     IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
     uint64_t messageSenderDestinationID() const final { return 0; }
     

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in (256748 => 256749)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in	2020-02-17 19:23:56 UTC (rev 256749)
@@ -25,7 +25,7 @@
 messages -> WebSWServerConnection NotRefCounted {
     # When possible, these messages can be implemented directly by WebCore::SWClientConnection
     ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData)
-    ScheduleUnregisterJobInServer(WebCore::ServiceWorkerJobIdentifier jobIdentifier, WebCore::ServiceWorkerRegistrationIdentifier identifier, WebCore::DocumentOrWorkerIdentifier documentIdentifier, URL clientCreationURL) -> (Expected<bool, WebCore::ExceptionData> result) Async
+    ScheduleUnregisterJobInServer(WebCore::ServiceWorkerJobIdentifier jobIdentifier, WebCore::ServiceWorkerRegistrationIdentifier identifier, WebCore::DocumentOrWorkerIdentifier documentIdentifier) -> (Expected<bool, WebCore::ExceptionData> result) Async
 
     FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
     AddServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier identifier)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (256748 => 256749)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2020-02-17 19:23:56 UTC (rev 256749)
@@ -96,9 +96,9 @@
         send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer { identifier });
 }
 
-void WebSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, WebCore::DocumentOrWorkerIdentifier documentIdentifier, const URL& clientCreationURL, CompletionHandler<void(ExceptionOr<bool>&&)>&& completionHandler)
+void WebSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, WebCore::DocumentOrWorkerIdentifier documentIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&& completionHandler)
 {
-    sendWithAsyncReply(Messages::WebSWServerConnection::ScheduleUnregisterJobInServer { ServiceWorkerJobIdentifier::generateThreadSafe(), registrationIdentifier, documentIdentifier, clientCreationURL }, [completionHandler = WTFMove(completionHandler)](auto&& result) mutable {
+    sendWithAsyncReply(Messages::WebSWServerConnection::ScheduleUnregisterJobInServer { ServiceWorkerJobIdentifier::generateThreadSafe(), registrationIdentifier, documentIdentifier }, [completionHandler = WTFMove(completionHandler)](auto&& result) mutable {
         if (!result.has_value())
             return completionHandler(result.error().toException());
         completionHandler(result.value());

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (256748 => 256749)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2020-02-17 19:17:44 UTC (rev 256748)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2020-02-17 19:23:56 UTC (rev 256749)
@@ -75,7 +75,7 @@
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source) final;
     void registerServiceWorkerClient(const WebCore::SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, const String& userAgent) final;
     void unregisterServiceWorkerClient(WebCore::DocumentIdentifier) final;
-    void scheduleUnregisterJobInServer(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentOrWorkerIdentifier, const URL& /* clientCreationURL */, CompletionHandler<void(WebCore::ExceptionOr<bool>&&)>&&) final;
+    void scheduleUnregisterJobInServer(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentOrWorkerIdentifier, CompletionHandler<void(WebCore::ExceptionOr<bool>&&)>&&) final;
 
     void matchRegistration(WebCore::SecurityOriginData&& topOrigin, const URL& clientURL, RegistrationCallback&&) final;
     void didMatchRegistration(uint64_t matchRequestIdentifier, Optional<WebCore::ServiceWorkerRegistrationData>&&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to