Title: [225703] trunk
Revision
225703
Author
commit-qu...@webkit.org
Date
2017-12-08 14:44:26 -0800 (Fri, 08 Dec 2017)

Log Message

Service Worker should use a correct SessionID
https://bugs.webkit.org/show_bug.cgi?id=180585

Patch by Youenn Fablet <you...@apple.com> on 2017-12-08
Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/workers/service/serviceworker-private-browsing.https.html

Store SessionID in SWServer and send it as part of service worker instantiation.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::SWServer):
(WebCore::SWServer::installContextData):
(WebCore::SWServer::runServiceWorker):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerToContextConnection.h:

Source/WebKit:

Store SessionID in SWServer and send it as part of service worker instantiation.
Use it when creating service worker thread in service worker process.

* StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::installServiceWorkerContext):
* StorageProcess/ServiceWorker/WebSWServerToContextConnection.h:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::swServerForSession):
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::installServiceWorker):
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

LayoutTests:

* http/tests/workers/service/serviceworker-private-browsing-worker.js: Added.
(async):
* http/tests/workers/service/serviceworker-private-browsing.https-expected.txt: Added.
* http/tests/workers/service/serviceworker-private-browsing.https.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225702 => 225703)


--- trunk/LayoutTests/ChangeLog	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/LayoutTests/ChangeLog	2017-12-08 22:44:26 UTC (rev 225703)
@@ -1,5 +1,17 @@
 2017-12-08  Youenn Fablet  <you...@apple.com>
 
+        Service Worker should use a correct SessionID
+        https://bugs.webkit.org/show_bug.cgi?id=180585
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/workers/service/serviceworker-private-browsing-worker.js: Added.
+        (async):
+        * http/tests/workers/service/serviceworker-private-browsing.https-expected.txt: Added.
+        * http/tests/workers/service/serviceworker-private-browsing.https.html: Added.
+
+2017-12-08  Youenn Fablet  <you...@apple.com>
+
         FetchResponse should keep unfiltered ResourceResponse so that it can be used in Service Worker
         https://bugs.webkit.org/show_bug.cgi?id=179641
         <rdar://problem/35923570>

Added: trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing-worker.js (0 => 225703)


--- trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing-worker.js	2017-12-08 22:44:26 UTC (rev 225703)
@@ -0,0 +1,12 @@
+self.addEventListener("message", async (event) => {
+    try { 
+        if (event.data !== "TESTCACHE") {
+             event.source.postMessage("FAIL: Unknown message");
+        }
+        var keys = await self.caches.keys();
+        event.source.postMessage(keys.length === 0 ? "PASS" : "FAIL: caches is not empty, got: " + JSON.stringify(keys));
+    } catch (e) {
+        event.source.postMessage("FAIL: received exception " + e);
+    }
+});
+

Added: trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https-expected.txt (0 => 225703)


--- trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https-expected.txt	2017-12-08 22:44:26 UTC (rev 225703)
@@ -0,0 +1,4 @@
+
+PASS Setup cache in regular session and service worker in private browsing session 
+PASS Test private browsing service worker has not access to regular cache storage 
+

Added: trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https.html (0 => 225703)


--- trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworker-private-browsing.https.html	2017-12-08 22:44:26 UTC (rev 225703)
@@ -0,0 +1,53 @@
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "my private backyard";
+var activeWorker;
+
+promise_test(async (test) => {
+    // Opening a cache and check that private browsing service worker does not have access to it.
+    self.caches.open("test");
+
+    if (!window.testRunner)
+       return Promise.reject("test requires internals API");
+    testRunner.setPrivateBrowsingEnabled(true);
+
+    var registration = await navigator.serviceWorker.getRegistration(scope);
+    if (registration && registration.scope === scope)
+        await registration.unregister();
+
+    var registration = await navigator.serviceWorker.register("serviceworker-private-browsing-worker.js", { scope : scope });
+    activeWorker = registration.active;
+    if (activeWorker)
+        return;
+    activeWorker = registration.installing;
+    return new Promise(resolve => {
+        activeWorker.addEventListener('statechange', () => {
+            if (activeWorker.state === "activated")
+                resolve();
+        });
+    });
+}, "Setup cache in regular session and service worker in private browsing session");
+
+promise_test(async (test) => {
+    var promise = new Promise((resolve, reject) => {
+        navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
+            if (event.data ="" "PASS") {
+                resolve();
+                return;
+            }
+            reject(event.data);
+        }));
+    });
+
+    activeWorker.postMessage("TESTCACHE");
+    await promise;
+
+}, "Test private browsing service worker has not access to regular cache storage");
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (225702 => 225703)


--- trunk/Source/WebCore/ChangeLog	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebCore/ChangeLog	2017-12-08 22:44:26 UTC (rev 225703)
@@ -1,5 +1,23 @@
 2017-12-08  Youenn Fablet  <you...@apple.com>
 
+        Service Worker should use a correct SessionID
+        https://bugs.webkit.org/show_bug.cgi?id=180585
+
+        Reviewed by Alex Christensen.
+
+        Test: http/tests/workers/service/serviceworker-private-browsing.https.html
+
+        Store SessionID in SWServer and send it as part of service worker instantiation.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::SWServer):
+        (WebCore::SWServer::installContextData):
+        (WebCore::SWServer::runServiceWorker):
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerToContextConnection.h:
+
+2017-12-08  Youenn Fablet  <you...@apple.com>
+
         FetchResponse should keep unfiltered ResourceResponse so that it can be used in Service Worker
         https://bugs.webkit.org/show_bug.cgi?id=179641
         <rdar://problem/35923570>

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


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-12-08 22:44:26 UTC (rev 225703)
@@ -197,9 +197,10 @@
         m_server.syncTerminateWorker(*worker);
 }
 
-SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, const String& registrationDatabaseDirectory)
+    SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, String&& registrationDatabaseDirectory, PAL::SessionID sessionID)
     : m_originStore(WTFMove(originStore))
-    , m_registrationStore(*this, registrationDatabaseDirectory)
+    , m_registrationStore(*this, WTFMove(registrationDatabaseDirectory))
+    , m_sessionID(sessionID)
 {
     UNUSED_PARAM(registrationDatabaseDirectory);
     allServers().add(this);
@@ -463,7 +464,7 @@
     auto result = m_runningOrTerminatingWorkers.add(data.serviceWorkerIdentifier, WTFMove(worker));
     ASSERT_UNUSED(result, result.isNewEntry);
 
-    connection->installServiceWorkerContext(data);
+    connection->installServiceWorkerContext(data, m_sessionID);
 }
 
 void SWServer::runServiceWorkerIfNecessary(ServiceWorkerIdentifier identifier, RunServiceWorkerCallback&& callback)
@@ -505,7 +506,7 @@
 
     auto* connection = SWServerToContextConnection::globalServerToContextConnection();
     ASSERT(connection);
-    connection->installServiceWorkerContext(worker->contextData());
+    connection->installServiceWorkerContext(worker->contextData(), m_sessionID);
 
     return true;
 }

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


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-12-08 22:44:26 UTC (rev 225703)
@@ -114,7 +114,7 @@
         Vector<RegistrationReadyRequest> m_registrationReadyRequests;
     };
 
-    WEBCORE_EXPORT explicit SWServer(UniqueRef<SWOriginStore>&&, const String& registrationDatabaseDirectory);
+    WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, String&& registrationDatabaseDirectory, PAL::SessionID);
     WEBCORE_EXPORT ~SWServer();
 
     WEBCORE_EXPORT void clearAll();
@@ -224,6 +224,7 @@
     RegistrationStore m_registrationStore;
     Deque<ServiceWorkerContextData> m_pendingContextDatas;
     HashMap<ServiceWorkerIdentifier, Vector<RunServiceWorkerCallback>> m_serviceWorkerRunRequests;
+    PAL::SessionID m_sessionID;
 };
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h	2017-12-08 22:44:26 UTC (rev 225703)
@@ -32,6 +32,10 @@
 #include "ServiceWorkerTypes.h"
 #include <wtf/RefCounted.h>
 
+namespace PAL {
+class SessionID;
+}
+
 namespace WebCore {
 
 class SWServer;
@@ -48,7 +52,7 @@
     SWServerToContextConnectionIdentifier identifier() const { return m_identifier; }
 
     // Messages to the SW host process
-    virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
+    virtual void installServiceWorkerContext(const ServiceWorkerContextData&, PAL::SessionID) = 0;
     virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
     virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
     virtual void terminateWorker(ServiceWorkerIdentifier) = 0;

Modified: trunk/Source/WebKit/ChangeLog (225702 => 225703)


--- trunk/Source/WebKit/ChangeLog	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/ChangeLog	2017-12-08 22:44:26 UTC (rev 225703)
@@ -1,5 +1,25 @@
 2017-12-08  Youenn Fablet  <you...@apple.com>
 
+        Service Worker should use a correct SessionID
+        https://bugs.webkit.org/show_bug.cgi?id=180585
+
+        Reviewed by Alex Christensen.
+
+        Store SessionID in SWServer and send it as part of service worker instantiation.
+        Use it when creating service worker thread in service worker process.
+
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+        (WebKit::WebSWServerToContextConnection::installServiceWorkerContext):
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.h:
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::swServerForSession):
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::installServiceWorker):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
+2017-12-08  Youenn Fablet  <you...@apple.com>
+
         FetchResponse should keep unfiltered ResourceResponse so that it can be used in Service Worker
         https://bugs.webkit.org/show_bug.cgi?id=179641
         <rdar://problem/35923570>

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp (225702 => 225703)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp	2017-12-08 22:44:26 UTC (rev 225703)
@@ -56,9 +56,9 @@
     // FIXME: Do what here...?
 }
 
-void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& data)
+void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& data, PAL::SessionID sessionID)
 {
-    send(Messages::WebSWContextManagerConnection::InstallServiceWorker(data));
+    send(Messages::WebSWContextManagerConnection::InstallServiceWorker { data, sessionID });
 }
 
 void WebSWServerToContextConnection::fireInstallEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h (225702 => 225703)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h	2017-12-08 22:44:26 UTC (rev 225703)
@@ -55,7 +55,7 @@
     uint64_t messageSenderDestinationID() final;
 
     // Messages to the SW host WebProcess
-    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
+    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&, PAL::SessionID) final;
     void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
     void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
     void terminateWorker(WebCore::ServiceWorkerIdentifier) final;

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.cpp (225702 => 225703)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-12-08 22:44:26 UTC (rev 225703)
@@ -420,7 +420,7 @@
     // If there's not, then where did this PAL::SessionID come from?
     ASSERT(sessionID.isEphemeral() || !path.isEmpty());
 
-    result.iterator->value = std::make_unique<SWServer>(makeUniqueRef<WebSWOriginStore>(), path);
+    result.iterator->value = std::make_unique<SWServer>(makeUniqueRef<WebSWOriginStore>(), WTFMove(path), sessionID);
     return *result.iterator->value;
 }
 

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (225702 => 225703)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp	2017-12-08 22:44:26 UTC (rev 225703)
@@ -99,13 +99,10 @@
     RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
 }
 
-void WebSWContextManagerConnection::installServiceWorker(const ServiceWorkerContextData& data)
+void WebSWContextManagerConnection::installServiceWorker(const ServiceWorkerContextData& data, SessionID sessionID)
 {
     LOG(ServiceWorker, "WebSWContextManagerConnection::installServiceWorker for worker %s", data.serviceWorkerIdentifier.loggingString().utf8().data());
 
-    // FIXME: Provide a sensical session ID.
-    auto sessionID = PAL::SessionID::defaultSessionID();
-
     PageConfiguration pageConfiguration {
         createEmptyEditorClient(),
         WebSocketProvider::create(),

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (225702 => 225703)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h	2017-12-08 22:44:26 UTC (rev 225703)
@@ -71,7 +71,7 @@
 
     // IPC messages.
     void serviceWorkerStartedWithMessage(std::optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
-    void installServiceWorker(const WebCore::ServiceWorkerContextData&);
+    void installServiceWorker(const WebCore::ServiceWorkerContextData&, PAL::SessionID);
     void startFetch(WebCore::SWServerConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ServiceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&, IPC::FormDataReference&&);
     void postMessageToServiceWorkerFromClient(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientIdentifier sourceIdentifier, WebCore::ServiceWorkerClientData&& sourceData);
     void postMessageToServiceWorkerFromServiceWorker(WebCore::ServiceWorkerIdentifier destination, const IPC::DataReference& message, WebCore::ServiceWorkerData&& sourceData);

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


--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2017-12-08 22:41:48 UTC (rev 225702)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in	2017-12-08 22:44:26 UTC (rev 225703)
@@ -23,7 +23,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 messages -> WebSWContextManagerConnection {
-    InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData)
+    InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData, PAL::SessionID sessionID)
     StartFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody)
     PostMessageToServiceWorkerFromClient(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, struct WebCore::ServiceWorkerClientData sourceData)
     PostMessageToServiceWorkerFromServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData sourceData)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to