Changeset 292905 in webkit
- Timestamp:
- Apr 15, 2022 6:15:30 AM (3 months ago)
- Location:
- trunk
- Files:
-
- 4 added
- 26 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html (modified) (2 diffs)
-
LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache-expected.txt (modified) (1 diff)
-
LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html (modified) (5 diffs)
-
LayoutTests/http/tests/workers/service/other_resources/dummy.js (added)
-
LayoutTests/http/tests/workers/service/other_resources/test.html (modified) (1 diff)
-
LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js (modified) (1 diff)
-
LayoutTests/http/wpt/service-workers/about-blank-iframe-expected.txt (added)
-
LayoutTests/http/wpt/service-workers/about-blank-iframe-worker.js (added)
-
LayoutTests/http/wpt/service-workers/about-blank-iframe.html (added)
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/about-blank-replacement.https-expected.txt (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/client-url-of-blob-url-worker.https-expected.txt (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-blob-url-worker.https-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/Document.cpp (modified) (1 diff)
-
Source/WebCore/loader/DocumentLoader.cpp (modified) (1 diff)
-
Source/WebCore/workers/DedicatedWorkerThread.cpp (modified) (1 diff)
-
Source/WebCore/workers/WorkerGlobalScope.cpp (modified) (3 diffs)
-
Source/WebCore/workers/WorkerGlobalScope.h (modified) (2 diffs)
-
Source/WebCore/workers/WorkerScriptLoader.cpp (modified) (3 diffs)
-
Source/WebCore/workers/service/SWClientConnection.h (modified) (2 diffs)
-
Source/WebCore/workers/service/WorkerSWClientConnection.cpp (modified) (1 diff)
-
Source/WebCore/workers/service/WorkerSWClientConnection.h (modified) (2 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r292904 r292905 1 2022-04-15 Youenn Fablet <youenn@apple.com> 2 3 ServiceWorker.postMessage() doesn't work from inside iframe 4 https://bugs.webkit.org/show_bug.cgi?id=213984 5 <rdar://problem/65203340> 6 7 Reviewed by Chris Dumez. 8 9 * http/wpt/service-workers/about-blank-iframe-expected.txt: Added. 10 * http/wpt/service-workers/about-blank-iframe-worker.js: Added. 11 * http/wpt/service-workers/about-blank-iframe.html: Added. 12 * http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html: 13 * http/tests/workers/service/client-removed-from-clients-while-in-page-cache-expected.txt: 14 * http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html: 15 * http/tests/workers/service/other_resources/test.html: 16 * http/tests/workers/service/resources/getClientIds-worker.js: 17 1 18 2022-04-14 Claudio Saavedra <csaavedra@igalia.com> 2 19 -
trunk/LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html
r288093 r292905 23 23 navigator.serviceWorker.addEventListener("message", function(event) { 24 24 if (step == "BothClientsInitiallyActive") { 25 if (!containsExpectedClients(event.data )) {25 if (!containsExpectedClients(event.data.ids)) { 26 26 if (++tries > 20) { 27 27 log("FAIL: Wrong initial number of clients"); … … 60 60 61 61 if (step == "SecondClientRestoredFromPageCache") { 62 if (!containsExpectedClients(event.data )) {62 if (!containsExpectedClients(event.data.ids)) { 63 63 log("FAIL: Wrong number of clients after one client was restored from page cache"); 64 64 finishSWTest(); -
trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache-expected.txt
r226677 r292905 1 1 * Tests that a client is removed from the list of service worker clients while it is in the page cache 2 2 3 PASS: service worker has initially 2 clients 3 PASS: service worker has initially 2 window clients 4 PASS: service worker has initially 2 worker clients 4 5 PASS: page is about to enter page cache 5 PASS: service worker has only 1 client after 1 entered page cache 6 PASS: service worker has only 1 window client after 1 entered page cache 7 PASS: service worker has only 1 worker client after 1 entered page cache 6 8 -
trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html
r288093 r292905 10 10 let topClientIdentifier = null; 11 11 let windowClientIdentifier = null; 12 12 let dedicatedWorker = null; 13 13 let tries = 0; 14 14 … … 24 24 25 25 navigator.serviceWorker.addEventListener("message", function(event) { 26 if (step == " BothClientsInitiallyActive") {27 if (!containsBothClients(event.data )) {26 if (step == "AllClientsInitiallyActive") { 27 if (!containsBothClients(event.data.ids) && event.data.workersCount !== 2) { 28 28 if (++tries > 20) { 29 29 log("FAIL: Wrong initial number of clients"); … … 34 34 return; 35 35 } 36 log("PASS: service worker has initially 2 clients"); 36 log("PASS: service worker has initially 2 window clients"); 37 log("PASS: service worker has initially 2 worker clients"); 37 38 38 39 otherWindow.addEventListener("pagehide", function(event) { … … 55 56 56 57 if (step == "OnlyOneClientRemainsActive") { 57 if (!containsOnlyTopClient(event.data )) {58 if (!containsOnlyTopClient(event.data.ids) && event.data.workersCount !== 1) { 58 59 log("FAIL: Wrong number of clients after one client entered page cache"); 59 60 finishSWTest(); 60 61 } 61 62 62 log("PASS: service worker has only 1 client after 1 entered page cache"); 63 log("PASS: service worker has only 1 window client after 1 entered page cache"); 64 log("PASS: service worker has only 1 worker client after 1 entered page cache"); 63 65 finishSWTest(); 64 66 } 65 67 }); 66 68 67 navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then( function(registration){69 navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then(async (registration) => { 68 70 if (!window.internals) 69 71 return; … … 71 73 72 74 worker = registration.installing; 75 76 dedicatedWorker = new Worker("other_resources/dummy.js"); 77 73 78 otherWindow = open("other_resources/test.html"); 74 otherWindow.onload = function() { 75 windowClientIdentifier = internals.serviceWorkerClientInternalIdentifier(otherWindow.document); 76 step = "BothClientsInitiallyActive" 77 worker.postMessage("getClientIds"); 78 }; 79 await new Promise(resolve => otherWindow.onload = resolve); 80 windowClientIdentifier = internals.serviceWorkerClientInternalIdentifier(otherWindow.document); 81 step = "AllClientsInitiallyActive" 82 worker.postMessage("getClientIds"); 79 83 }); 80 84 </script> -
trunk/LayoutTests/http/tests/workers/service/other_resources/test.html
r226677 r292905 1 <!DOCTYPE html> 2 <html> 3 <body> 4 <script src="resources/sw-test-pre.js"></script> 5 <script> 6 var dedicatedWorker = new Worker("dummy.js"); 7 </script> 1 8 TEST 9 </body> -
trunk/LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js
r288093 r292905 1 self.addEventListener("message", (event) => {1 self.addEventListener("message", async (event) => { 2 2 source = event.source; 3 clients.matchAll({ includeUncontrolled : true }).then(function(clients) { 4 let ids = []; 5 for (let client of clients) 6 ids.push(self.internals.serviceWorkerClientInternalIdentifier(client)); 7 source.postMessage(ids); 8 }); 3 const matchedClients = await clients.matchAll({ includeUncontrolled : true, type: 'all' }) 4 let data = { ids: [], workerCount: 0 }; 5 for (let client of matchedClients) { 6 if (client.type === 'worker') 7 data.workerCount++; 8 else 9 data.ids.push(self.internals.serviceWorkerClientInternalIdentifier(client)); 10 } 11 source.postMessage(data); 9 12 }); -
trunk/LayoutTests/imported/w3c/ChangeLog
r292893 r292905 1 2022-04-15 Youenn Fablet <youenn@apple.com> 2 3 ServiceWorker.postMessage() doesn't work from inside iframe 4 https://bugs.webkit.org/show_bug.cgi?id=213984 5 <rdar://problem/65203340> 6 7 Reviewed by Chris Dumez. 8 9 * web-platform-tests/service-workers/service-worker/about-blank-replacement.https-expected.txt: 10 * web-platform-tests/service-workers/service-worker/client-url-of-blob-url-worker.https-expected.txt: 11 * web-platform-tests/service-workers/service-worker/clients-matchall-blob-url-worker.https-expected.txt: 12 1 13 2022-04-14 Nikolaos Mouchtaris <nmouchtaris@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/about-blank-replacement.https-expected.txt
r267647 r292905 6 6 FAIL Popup initial about:blank is controlled, exposed to clients.matchAll(), and matches final Client. assert_false: result: failure: could not find about:blank client expected false got true 7 7 PASS Initial about:blank is controlled, exposed to clients.matchAll(), and final Client is not controlled by a service worker. 8 FAIL Simple about:blank is controlled and is exposed to clients.matchAll(). assert_false: result: failure: could not find about:blank client expected false got true 9 FAIL Nested about:srcdoc is controlled and is exposed to clients.matchAll(). assert_false: result: failure: could not find about:srcdoc client expected false got true 10 FAIL Dynamic about:blank is controlled and is exposed to clients.matchAll(). assert_false: result: failure: could not find about:blank client expected false got true 8 PASS Simple about:blank is controlled and is exposed to clients.matchAll(). 9 PASS Nested about:srcdoc is controlled and is exposed to clients.matchAll(). 10 PASS Dynamic about:blank is controlled and is exposed to clients.matchAll(). 11 11 -
trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/client-url-of-blob-url-worker.https-expected.txt
r279389 r292905 1 1 2 FAIL Client.url of a blob URL worker should be a blob URL. assert_not_equals: worker client should exist got disallowed value "one worker client should exist" 2 PASS Client.url of a blob URL worker should be a blob URL. 3 3 -
trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-blob-url-worker.https-expected.txt
r279389 r292905 1 1 2 FAIL Test Clients.matchAll() with a blob URL worker client. assert_equals: expected 1 but got 0 3 FAIL Test Clients.matchAll() with an uncontrolled blob URL worker client. assert_equals: expected 1 but got 0 2 PASS Test Clients.matchAll() with a blob URL worker client. 3 PASS Test Clients.matchAll() with an uncontrolled blob URL worker client. 4 4 -
trunk/Source/WebCore/ChangeLog
r292902 r292905 1 2022-04-15 Youenn Fablet <youenn@apple.com> 2 3 ServiceWorker.postMessage() doesn't work from inside iframe 4 https://bugs.webkit.org/show_bug.cgi?id=213984 5 <rdar://problem/65203340> 6 7 Reviewed by Chris Dumez. 8 9 postMessage was not working as we do not postMessage to a service worker if the source is not registered. 10 We now register service worker clients more aggresively and pass the client origin to better handle blob and about:blank clients. 11 We also add support for registering/unregistering worker clients when they get suspended/resumed. 12 To make sure a worker client is removed in failure case, WorkerScriptLoader is unregistering the service worker client if 13 the service worker data was not taken by its Worker. 14 15 Test: http/wpt/service-workers/about-blank-iframe.html 16 17 * dom/Document.cpp: 18 * loader/DocumentLoader.cpp: 19 * workers/DedicatedWorkerThread.cpp: 20 * workers/WorkerGlobalScope.cpp: 21 * workers/WorkerGlobalScope.h: 22 * workers/WorkerScriptLoader.cpp: 23 * workers/service/SWClientConnection.h: 24 * workers/service/WorkerSWClientConnection.cpp: 25 * workers/service/WorkerSWClientConnection.h: 26 1 27 2022-04-14 Antoine Quint <graouts@apple.com> 2 28 -
trunk/Source/WebCore/dom/Document.cpp
r292857 r292905 8779 8779 8780 8780 auto controllingServiceWorkerRegistrationIdentifier = activeServiceWorker() ? std::make_optional<ServiceWorkerRegistrationIdentifier>(activeServiceWorker()->registrationIdentifier()) : std::nullopt; 8781 m_serviceWorkerConnection->registerServiceWorkerClient( topOrigin(), ServiceWorkerClientData::from(*this), controllingServiceWorkerRegistrationIdentifier, userAgent(url()));8781 m_serviceWorkerConnection->registerServiceWorkerClient(clientOrigin(), ServiceWorkerClientData::from(*this), controllingServiceWorkerRegistrationIdentifier, userAgent(url())); 8782 8782 } 8783 8783 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r292861 r292905 1260 1260 } 1261 1261 1262 if (m_frame->document()->activeServiceWorker() || document.url().protocolIsInHTTPFamily() || (document.page() && document.page()->isServiceWorkerPage()) )1262 if (m_frame->document()->activeServiceWorker() || document.url().protocolIsInHTTPFamily() || (document.page() && document.page()->isServiceWorkerPage()) || (document.parentDocument() && shouldUseActiveServiceWorkerFromParent(document, *document.parentDocument()))) 1263 1263 document.setServiceWorkerConnection(&ServiceWorkerProvider::singleton().serviceWorkerConnection()); 1264 1264 -
trunk/Source/WebCore/workers/DedicatedWorkerThread.cpp
r292861 r292905 53 53 if (params.serviceWorkerData) 54 54 scope->setActiveServiceWorker(ServiceWorker::getOrCreate(scope.get(), ServiceWorkerData { *params.serviceWorkerData })); 55 scope->updateServiceWorkerClientData(); 55 56 #endif 56 57 return scope; -
trunk/Source/WebCore/workers/WorkerGlobalScope.cpp
r292861 r292905 152 152 WorkerOrWorkletGlobalScope::prepareForDestruction(); 153 153 154 #if ENABLE(SERVICE_WORKER) 155 if (settingsValues().serviceWorkersEnabled) 156 swClientConnection().unregisterServiceWorkerClient(identifier()); 157 #endif 158 154 159 stopIndexedDatabase(); 155 160 … … 230 235 if (m_connectionProxy) 231 236 m_connectionProxy->setContextSuspended(*this, true); 237 238 #if ENABLE(SERVICE_WORKER) 239 if (settingsValues().serviceWorkersEnabled) 240 swClientConnection().unregisterServiceWorkerClient(identifier()); 241 #endif 232 242 } 233 243 234 244 void WorkerGlobalScope::resume() 235 245 { 246 #if ENABLE(SERVICE_WORKER) 247 if (settingsValues().serviceWorkersEnabled) 248 updateServiceWorkerClientData(); 249 #endif 250 236 251 if (m_connectionProxy) 237 252 m_connectionProxy->setContextSuspended(*this, false); … … 658 673 void WorkerGlobalScope::updateServiceWorkerClientData() 659 674 { 660 ASSERT(type() == WebCore::WorkerGlobalScope::Type::DedicatedWorker); 675 if (!settingsValues().serviceWorkersEnabled) 676 return; 677 678 ASSERT(type() == WebCore::WorkerGlobalScope::Type::DedicatedWorker || type() == WebCore::WorkerGlobalScope::Type::SharedWorker); 661 679 auto controllingServiceWorkerRegistrationIdentifier = activeServiceWorker() ? std::make_optional<ServiceWorkerRegistrationIdentifier>(activeServiceWorker()->registrationIdentifier()) : std::nullopt; 662 SWClientConnection& connection = swClientConnection(); 663 connection.registerServiceWorkerClient(topOrigin(), ServiceWorkerClientData::from(*this), controllingServiceWorkerRegistrationIdentifier, String { m_userAgent }); 680 swClientConnection().registerServiceWorkerClient(clientOrigin(), ServiceWorkerClientData::from(*this), controllingServiceWorkerRegistrationIdentifier, String { m_userAgent }); 664 681 } 665 682 #endif -
trunk/Source/WebCore/workers/WorkerGlobalScope.h
r292861 r292905 98 98 WorkerCacheStorageConnection& cacheStorageConnection(); 99 99 MessagePortChannelProvider& messagePortChannelProvider(); 100 100 101 #if ENABLE(SERVICE_WORKER) 101 102 WorkerSWClientConnection& swClientConnection(); 103 void updateServiceWorkerClientData() final; 102 104 #endif 103 105 … … 192 194 bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) final; 193 195 bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) final; 194 #endif195 #if ENABLE(SERVICE_WORKER)196 void updateServiceWorkerClientData() final;197 196 #endif 198 197 -
trunk/Source/WebCore/workers/WorkerScriptLoader.cpp
r292861 r292905 37 37 #include "ServiceWorkerContextData.h" 38 38 #include "ServiceWorkerGlobalScope.h" 39 #include "ServiceWorkerProvider.h" 39 40 #include "TextResourceDecoder.h" 40 41 #include "WorkerFetchResult.h" … … 59 60 WorkerScriptLoader::~WorkerScriptLoader() 60 61 { 61 if (m_clientIdentifier) 62 scriptExecutionContextIdentifierToWorkerScriptLoaderMap().remove(m_clientIdentifier); 62 if (!m_clientIdentifier) 63 return; 64 65 scriptExecutionContextIdentifierToWorkerScriptLoaderMap().remove(m_clientIdentifier); 66 #if ENABLE(SERVICE_WORKER) 67 if (m_activeServiceWorkerData) 68 ServiceWorkerProvider::singleton().serviceWorkerConnection().unregisterServiceWorkerClient(m_clientIdentifier); 69 #endif 63 70 } 64 71 … … 152 159 if (m_destination == FetchOptions::Destination::Worker && is<Document>(scriptExecutionContext)) { 153 160 ASSERT(clientIdentifier); 161 options.clientIdentifier = m_clientIdentifier = clientIdentifier; 154 162 // In case of blob URLs, we reuse the document controlling service worker. 155 163 if (request->url().protocolIsBlob() && scriptExecutionContext.activeServiceWorker()) 156 164 setControllingServiceWorker(ServiceWorkerData { scriptExecutionContext.activeServiceWorker()->data() }); 157 else { 158 options.clientIdentifier = m_clientIdentifier = clientIdentifier; 165 else 159 166 scriptExecutionContextIdentifierToWorkerScriptLoaderMap().add(m_clientIdentifier, this); 160 }161 167 } else if (auto* activeServiceWorker = scriptExecutionContext.activeServiceWorker()) 162 168 options.serviceWorkerRegistrationIdentifier = activeServiceWorker->registrationIdentifier(); -
trunk/Source/WebCore/workers/service/SWClientConnection.h
r292218 r292905 51 51 enum class ServiceWorkerState : uint8_t; 52 52 enum class ShouldNotifyWhenResolved : bool; 53 struct ClientOrigin; 53 54 struct ExceptionData; 54 55 struct MessageWithMessagePorts; … … 85 86 virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const = 0; 86 87 87 virtual void registerServiceWorkerClient(const SecurityOrigin& topOrigin, ServiceWorkerClientData&&, const std::optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent) = 0;88 virtual void registerServiceWorkerClient(const ClientOrigin&, ServiceWorkerClientData&&, const std::optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent) = 0; 88 89 virtual void unregisterServiceWorkerClient(ScriptExecutionContextIdentifier) = 0; 89 90 -
trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp
r292218 r292905 185 185 } 186 186 187 void WorkerSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& identifier, String&& userAgent) 188 { 189 callOnMainThread([topOrigin = topOrigin.isolatedCopy(), data = crossThreadCopy(WTFMove(data)), identifier, userAgent = crossThreadCopy(WTFMove(userAgent))]() mutable { 190 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 191 connection.registerServiceWorkerClient(topOrigin, WTFMove(data), identifier, WTFMove(userAgent)); 192 }); 193 } 194 195 void WorkerSWClientConnection::unregisterServiceWorkerClient(ScriptExecutionContextIdentifier) 187 void WorkerSWClientConnection::registerServiceWorkerClient(const ClientOrigin& clientOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& identifier, String&& userAgent) 188 { 189 callOnMainThread([clientOrigin = clientOrigin.isolatedCopy(), data = crossThreadCopy(WTFMove(data)), identifier, userAgent = crossThreadCopy(WTFMove(userAgent))]() mutable { 190 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 191 connection.registerServiceWorkerClient(clientOrigin, WTFMove(data), identifier, WTFMove(userAgent)); 192 }); 193 } 194 195 void WorkerSWClientConnection::unregisterServiceWorkerClient(ScriptExecutionContextIdentifier identifier) 196 { 197 callOnMainThread([identifier] { 198 ServiceWorkerProvider::singleton().serviceWorkerConnection().unregisterServiceWorkerClient(identifier); 199 }); 200 } 201 202 void WorkerSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerRegistrationKey&& registrationKey, WorkerFetchResult&& result) 203 { 204 callOnMainThread([jobDataIdentifier, registrationKey = crossThreadCopy(WTFMove(registrationKey)), result = crossThreadCopy(WTFMove(result))]() mutable { 205 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 206 connection.finishFetchingScriptInServer(jobDataIdentifier, WTFMove(registrationKey), WTFMove(result)); 207 }); 208 } 209 210 void WorkerSWClientConnection::scheduleJob(ServiceWorkerOrClientIdentifier identifier, const ServiceWorkerJobData& data) 211 { 212 callOnMainThread([identifier, data = crossThreadCopy(data)]() mutable { 213 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 214 connection.scheduleJob(identifier, data); 215 }); 216 } 217 218 void WorkerSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, ServiceWorkerOrClientIdentifier contextIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&& callback) 219 { 220 uint64_t requestIdentifier = ++m_lastRequestIdentifier; 221 m_unregisterRequests.add(requestIdentifier, WTFMove(callback)); 222 223 callOnMainThread([thread = m_thread, requestIdentifier, registrationIdentifier, contextIdentifier]() mutable { 224 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection(); 225 connection.scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier, [thread = WTFMove(thread), requestIdentifier](auto&& result) { 226 thread->runLoop().postTaskForMode([requestIdentifier, result = crossThreadCopy(WTFMove(result))](auto& scope) mutable { 227 auto callback = downcast<WorkerGlobalScope>(scope).swClientConnection().m_unregisterRequests.take(requestIdentifier); 228 callback(WTFMove(result)); 229 }, WorkerRunLoop::defaultMode()); 230 }); 231 }); 232 } 233 234 void WorkerSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData&) 196 235 { 197 236 ASSERT_NOT_REACHED(); 198 237 } 199 238 200 void WorkerSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerRegistrationKey&& registrationKey, WorkerFetchResult&& result)201 {202 callOnMainThread([jobDataIdentifier, registrationKey = crossThreadCopy(WTFMove(registrationKey)), result = crossThreadCopy(WTFMove(result))]() mutable {203 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();204 connection.finishFetchingScriptInServer(jobDataIdentifier, WTFMove(registrationKey), WTFMove(result));205 });206 }207 208 void WorkerSWClientConnection::scheduleJob(ServiceWorkerOrClientIdentifier identifier, const ServiceWorkerJobData& data)209 {210 callOnMainThread([identifier, data = crossThreadCopy(data)]() mutable {211 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();212 connection.scheduleJob(identifier, data);213 });214 }215 216 void WorkerSWClientConnection::scheduleUnregisterJobInServer(ServiceWorkerRegistrationIdentifier registrationIdentifier, ServiceWorkerOrClientIdentifier contextIdentifier, CompletionHandler<void(ExceptionOr<bool>&&)>&& callback)217 {218 uint64_t requestIdentifier = ++m_lastRequestIdentifier;219 m_unregisterRequests.add(requestIdentifier, WTFMove(callback));220 221 callOnMainThread([thread = m_thread, requestIdentifier, registrationIdentifier, contextIdentifier]() mutable {222 auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();223 connection.scheduleUnregisterJobInServer(registrationIdentifier, contextIdentifier, [thread = WTFMove(thread), requestIdentifier](auto&& result) {224 thread->runLoop().postTaskForMode([requestIdentifier, result = crossThreadCopy(WTFMove(result))](auto& scope) mutable {225 auto callback = downcast<WorkerGlobalScope>(scope).swClientConnection().m_unregisterRequests.take(requestIdentifier);226 callback(WTFMove(result));227 }, WorkerRunLoop::defaultMode());228 });229 });230 }231 232 void WorkerSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData&)233 {234 ASSERT_NOT_REACHED();235 }236 237 239 void WorkerSWClientConnection::subscribeToPushService(ServiceWorkerRegistrationIdentifier registrationIdentifier, const Vector<uint8_t>& applicationServerKey, SubscribeToPushServiceCallback&& callback) 238 240 { -
trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h
r292218 r292905 40 40 ~WorkerSWClientConnection(); 41 41 42 void registerServiceWorkerClient(const ClientOrigin&, ServiceWorkerClientData&&, const std::optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent) final; 43 void unregisterServiceWorkerClient(ScriptExecutionContextIdentifier) final; 44 42 45 private: 43 46 explicit WorkerSWClientConnection(WorkerGlobalScope&); … … 52 55 SWServerConnectionIdentifier serverConnectionIdentifier() const final; 53 56 bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const final; 54 void registerServiceWorkerClient(const SecurityOrigin& topOrigin, ServiceWorkerClientData&&, const std::optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent) final;55 void unregisterServiceWorkerClient(ScriptExecutionContextIdentifier) final;56 57 void finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier&, ServiceWorkerRegistrationKey&&, WorkerFetchResult&&) final; 57 58 void scheduleJobInServer(const ServiceWorkerJobData&) final; -
trunk/Source/WebKit/ChangeLog
r292904 r292905 1 2022-04-15 Youenn Fablet <youenn@apple.com> 2 3 ServiceWorker.postMessage() doesn't work from inside iframe 4 https://bugs.webkit.org/show_bug.cgi?id=213984 5 <rdar://problem/65203340> 6 7 Reviewed by Chris Dumez. 8 9 Pass the full ClientOrigin when registering a service worker client. 10 Filter out clients that cannot be matched: 11 - non HTTP/blob/about:blank clients 12 - sandboxed HTTP clients 13 14 * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: 15 * NetworkProcess/ServiceWorker/WebSWServerConnection.h: 16 * NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in: 17 * WebProcess/Storage/WebSWClientConnection.cpp: 18 * WebProcess/Storage/WebSWClientConnection.h: 19 1 20 2022-04-14 Claudio Saavedra <csaavedra@igalia.com> 2 21 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
r292861 r292905 185 185 auto ancestorOrigins = map(parameters.frameAncestorOrigins, [](auto& origin) { return origin->toString(); }); 186 186 ServiceWorkerClientData data { clientIdentifier, clientType, ServiceWorkerClientFrameType::None, request.url(), parameters.webPageID, parameters.webFrameID, request.isAppInitiated() ? WebCore::LastNavigationWasAppInitiated::Yes : WebCore::LastNavigationWasAppInitiated::No, false, false, 0, WTFMove(ancestorOrigins) }; 187 registerServiceWorkerClient( SecurityOriginData { registration.key().topOrigin() }, WTFMove(data), registration.identifier(), request.httpUserAgent());187 registerServiceWorkerClient(ClientOrigin { registration.key().topOrigin(), SecurityOriginData::fromURL(request.url()) }, WTFMove(data), registration.identifier(), request.httpUserAgent()); 188 188 } 189 189 … … 396 396 } 397 397 398 void WebSWServerConnection::registerServiceWorkerClient( SecurityOriginData&& topOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent)398 void WebSWServerConnection::registerServiceWorkerClient(WebCore::ClientOrigin&& clientOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent) 399 399 { 400 400 CONNECTION_MESSAGE_CHECK(data.identifier.processIdentifier() == identifier()); 401 CONNECTION_MESSAGE_CHECK(!topOrigin.isEmpty()); 402 403 auto contextOrigin = SecurityOriginData::fromURL(data.url); 401 CONNECTION_MESSAGE_CHECK(!clientOrigin.topOrigin.isEmpty()); 402 403 auto& contextOrigin = clientOrigin.clientOrigin; 404 if (data.url.protocolIsInHTTPFamily()) { 405 // We do not register any sandbox document. 406 if (contextOrigin != SecurityOriginData::fromURL(data.url)) 407 return; 408 } 409 404 410 CONNECTION_MESSAGE_CHECK(!contextOrigin.isEmpty()); 405 411 … … 409 415 auto* contextConnection = isNewOrigin ? server().contextConnectionForRegistrableDomain(RegistrableDomain { contextOrigin }) : nullptr; 410 416 411 auto clientOrigin = ClientOrigin { WTFMove(topOrigin), WTFMove(contextOrigin) };412 417 m_clientOrigins.add(data.identifier, clientOrigin); 413 418 server().registerServiceWorkerClient(WTFMove(clientOrigin), WTFMove(data), controllingServiceWorkerRegistrationIdentifier, WTFMove(userAgent)); -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
r292468 r292905 111 111 void getRegistrations(const WebCore::SecurityOriginData& topOrigin, const URL& clientURL, CompletionHandler<void(const Vector<WebCore::ServiceWorkerRegistrationData>&)>&&); 112 112 113 void registerServiceWorkerClient(WebCore:: SecurityOriginData&& topOrigin, WebCore::ServiceWorkerClientData&&, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent);113 void registerServiceWorkerClient(WebCore::ClientOrigin&&, WebCore::ServiceWorkerClientData&&, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent); 114 114 void unregisterServiceWorkerClient(const WebCore::ScriptExecutionContextIdentifier&); 115 115 void terminateWorkerFromClient(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&); -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in
r290903 r292905 39 39 WhenRegistrationReady(struct WebCore::SecurityOriginData topOrigin, URL clientURL) -> (std::optional<WebCore::ServiceWorkerRegistrationData> registration) 40 40 GetRegistrations(struct WebCore::SecurityOriginData topOrigin, URL clientURL) -> (Vector<WebCore::ServiceWorkerRegistrationData> registrations) 41 RegisterServiceWorkerClient(struct WebCore:: SecurityOriginData topOrigin, struct WebCore::ServiceWorkerClientData data, std::optional<WebCore::ServiceWorkerRegistrationIdentifier> controllingServiceWorkerRegistrationIdentifier, String userAgent)41 RegisterServiceWorkerClient(struct WebCore::ClientOrigin clientOrigin, struct WebCore::ServiceWorkerClientData data, std::optional<WebCore::ServiceWorkerRegistrationIdentifier> controllingServiceWorkerRegistrationIdentifier, String userAgent) 42 42 UnregisterServiceWorkerClient(WebCore::ScriptExecutionContextIdentifier identifier) 43 43 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
r292861 r292905 116 116 } 117 117 118 void WebSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, WebCore::ServiceWorkerClientData&& data, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent)119 { 120 send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent });118 void WebSWClientConnection::registerServiceWorkerClient(const ClientOrigin& clientOrigin, WebCore::ServiceWorkerClientData&& data, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent) 119 { 120 send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { clientOrigin, data, controllingServiceWorkerRegistrationIdentifier, userAgent }); 121 121 } 122 122 -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
r292861 r292905 74 74 void finishFetchingScriptInServer(const WebCore::ServiceWorkerJobDataIdentifier&, WebCore::ServiceWorkerRegistrationKey&&, WebCore::WorkerFetchResult&&) final; 75 75 void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source) final; 76 void registerServiceWorkerClient(const WebCore:: SecurityOrigin& topOrigin, WebCore::ServiceWorkerClientData&&, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent) final;76 void registerServiceWorkerClient(const WebCore::ClientOrigin&, WebCore::ServiceWorkerClientData&&, const std::optional<WebCore::ServiceWorkerRegistrationIdentifier>&, String&& userAgent) final; 77 77 void unregisterServiceWorkerClient(WebCore::ScriptExecutionContextIdentifier) final; 78 78 void scheduleUnregisterJobInServer(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::ServiceWorkerOrClientIdentifier, CompletionHandler<void(WebCore::ExceptionOr<bool>&&)>&&) final;
Note: See TracChangeset
for help on using the changeset viewer.