Changeset 293506 in webkit
- Timestamp:
- Apr 27, 2022 6:12:28 AM (3 months ago)
- Location:
- trunk
- Files:
-
- 20 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/credentials.https-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/workers/service/SWClientConnection.cpp (modified) (1 diff)
-
Source/WebCore/workers/service/SWClientConnection.h (modified) (1 diff)
-
Source/WebCore/workers/service/ServiceWorkerContainer.h (modified) (1 diff)
-
Source/WebCore/workers/service/ServiceWorkerJob.cpp (modified) (2 diffs)
-
Source/WebCore/workers/service/ServiceWorkerJob.h (modified) (3 diffs)
-
Source/WebCore/workers/service/ServiceWorkerJobClient.h (modified) (2 diffs)
-
Source/WebCore/workers/service/server/SWServer.cpp (modified) (5 diffs)
-
Source/WebCore/workers/service/server/SWServer.h (modified) (7 diffs)
-
Source/WebCore/workers/service/server/SWServerJobQueue.cpp (modified) (2 diffs)
-
Source/WebCore/workers/service/server/SWServerJobQueue.h (modified) (5 diffs)
-
Source/WebCore/workers/service/server/SWServerWorker.cpp (modified) (1 diff)
-
Source/WebCore/workers/service/server/SWServerWorker.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (modified) (1 diff)
-
Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r293501 r293506 1 2022-04-27 Youenn Fablet <youenn@apple.com> 2 3 service worker update should refresh imported scripts in addition to the main script 4 https://bugs.webkit.org/show_bug.cgi?id=239657 5 6 Reviewed by Chris Dumez. 7 8 * web-platform-tests/service-workers/service-worker/credentials.https-expected.txt: 9 1 10 2022-04-27 Youenn Fablet <youenn@apple.com> 2 11 -
trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/credentials.https-expected.txt
r279389 r293506 2 2 PASS Set cookies as initialization 3 3 PASS Main script should have credentials 4 FAIL Imported script should have credentials promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'worker.postMessage')" 5 FAIL Module with an imported statement should not have credentials promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'worker.postMessage')" 4 PASS Imported script should have credentials 5 PASS Module with an imported statement should not have credentials 6 6 FAIL Script with service worker served as modules should not have credentials assert_equals: new module worker should not have credentials expected (undefined) undefined but got (string) "1" 7 7 -
trunk/Source/WebCore/ChangeLog
r293504 r293506 1 2022-04-27 Youenn Fablet <youenn@apple.com> 2 3 service worker update should refresh imported scripts in addition to the main script 4 https://bugs.webkit.org/show_bug.cgi?id=239657 5 6 Reviewed by Chris Dumez. 7 8 After checking main script, if matching, we refreach each identified imported script. 9 If matching, we reuse the same worker, otherwise we install a new one. 10 We reuse the soft update loader to fetch scripts in case of soft update. 11 Otherwise, we load scripts through the job's client. 12 13 Covered by rebased test. 14 15 * workers/service/SWClientConnection.cpp: 16 * workers/service/SWClientConnection.h: 17 * workers/service/ServiceWorkerContainer.cpp: 18 * workers/service/ServiceWorkerContainer.h: 19 * workers/service/ServiceWorkerJob.cpp: 20 * workers/service/ServiceWorkerJob.h: 21 * workers/service/ServiceWorkerJobClient.h: 22 * workers/service/server/SWServer.cpp: 23 * workers/service/server/SWServer.h: 24 * workers/service/server/SWServerJobQueue.cpp: 25 * workers/service/server/SWServerJobQueue.h: 26 * workers/service/server/SWServerWorker.cpp: 27 * workers/service/server/SWServerWorker.h: 28 1 29 2022-04-27 Nikolas Zimmermann <nzimmermann@igalia.com> 2 30 -
trunk/Source/WebCore/workers/service/SWClientConnection.cpp
r293501 r293506 116 116 } 117 117 118 class RefreshImportedScriptsCallbackHandler { 119 WTF_MAKE_FAST_ALLOCATED; 120 public: 121 explicit RefreshImportedScriptsCallbackHandler(ServiceWorkerJob::RefreshImportedScriptsCallback&& callback) 122 : m_callback(WTFMove(callback)) 123 { 124 } 125 126 ~RefreshImportedScriptsCallbackHandler() 127 { 128 if (!m_callback) 129 return; 130 131 callOnMainThread([callback = WTFMove(m_callback)] () mutable { 132 callback({ }); 133 }); 134 } 135 136 void call(Vector<std::pair<URL, ScriptBuffer>>&& scripts) 137 { 138 callOnMainThread([callback = WTFMove(m_callback), scripts = crossThreadCopy(WTFMove(scripts))] () mutable { 139 callback(WTFMove(scripts)); 140 }); 141 } 142 143 private: 144 ServiceWorkerJob::RefreshImportedScriptsCallback m_callback; 145 }; 146 147 void SWClientConnection::refreshImportedScripts(ServiceWorkerJobIdentifier jobIdentifier, FetchOptions::Cache cachePolicy, Vector<URL>&& urls, ServiceWorkerJob::RefreshImportedScriptsCallback&& callback) 148 { 149 ASSERT(isMainThread()); 150 auto handler = makeUnique<RefreshImportedScriptsCallbackHandler>(WTFMove(callback)); 151 postTaskForJob(jobIdentifier, IsJobComplete::No, [cachePolicy, urls = crossThreadCopy(WTFMove(urls)), handler = WTFMove(handler)] (auto& job) mutable { 152 job.refreshImportedScripts(urls, cachePolicy, [handler = WTFMove(handler)] (auto&& result) { 153 handler->call(WTFMove(result)); 154 }); 155 }); 156 } 118 157 119 158 static void postMessageToContainer(ScriptExecutionContext& context, MessageWithMessagePorts&& message, ServiceWorkerData&& sourceData, String&& sourceOrigin) -
trunk/Source/WebCore/workers/service/SWClientConnection.h
r292905 r293506 125 125 WEBCORE_EXPORT void registrationJobResolvedInServer(ServiceWorkerJobIdentifier, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved); 126 126 WEBCORE_EXPORT void startScriptFetchForServer(ServiceWorkerJobIdentifier, ServiceWorkerRegistrationKey&&, FetchOptions::Cache); 127 WEBCORE_EXPORT void refreshImportedScripts(ServiceWorkerJobIdentifier, FetchOptions::Cache, Vector<URL>&&, ServiceWorkerJob::RefreshImportedScriptsCallback&&); 127 128 WEBCORE_EXPORT void postMessageToServiceWorkerClient(ScriptExecutionContextIdentifier destinationContextIdentifier, MessageWithMessagePorts&&, ServiceWorkerData&& source, String&& sourceOrigin); 128 129 WEBCORE_EXPORT void updateRegistrationState(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerData>&); -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h
r292218 r293506 130 130 131 131 ServiceWorkerOrClientIdentifier contextIdentifier() final; 132 ScriptExecutionContext* context() final { return scriptExecutionContext(); } 132 133 133 134 SWClientConnection& ensureSWClientConnection(); -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp
r292857 r293506 96 96 } 97 97 98 void ServiceWorkerJob::fetchScriptWithContext(ScriptExecutionContext& context, FetchOptions::Cache cachePolicy) 99 { 100 ASSERT(m_creationThread.ptr() == &Thread::current()); 101 ASSERT(!m_completed); 102 103 // FIXME: WorkerScriptLoader is the wrong loader class to use here, but there's nothing else better right now. 104 m_scriptLoader = WorkerScriptLoader::create(); 105 106 ResourceRequest request { m_jobData.scriptURL }; 98 static ResourceRequest scriptResourceRequest(ScriptExecutionContext& context, const URL& url) 99 { 100 ResourceRequest request { url }; 107 101 request.setInitiatorIdentifier(context.resourceRequestIdentifier()); 108 102 request.addHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s); 109 103 return request; 104 } 105 106 static FetchOptions scriptFetchOptions(FetchOptions::Cache cachePolicy, FetchOptions::Destination destination) 107 { 110 108 FetchOptions options; 111 109 options.mode = FetchOptions::Mode::SameOrigin; 112 110 options.cache = cachePolicy; 113 111 options.redirect = FetchOptions::Redirect::Error; 114 options.destination = FetchOptions::Destination::Serviceworker;112 options.destination = destination; 115 113 options.credentials = FetchOptions::Credentials::SameOrigin; 114 return options; 115 } 116 117 ServiceWorkerJob::ImportedScriptsLoader::ImportedScriptsLoader(RefreshImportedScriptsCallback&& callback) 118 : m_callback(WTFMove(callback)) 119 { 120 } 121 122 ServiceWorkerJob::ImportedScriptsLoader::~ImportedScriptsLoader() 123 { 124 if (m_callback) 125 m_callback({ }); 126 } 127 128 void ServiceWorkerJob::ImportedScriptsLoader::load(ScriptExecutionContext& context, const Vector<URL>& urls, FetchOptions::Cache cachePolicy) 129 { 130 m_loaders.reserveCapacity(urls.size()); 131 for (auto& url : urls) { 132 auto scriptLoader = WorkerScriptLoader::create(); 133 scriptLoader->loadAsynchronously(context, scriptResourceRequest(context, url), WorkerScriptLoader::Source::ClassicWorkerScript, scriptFetchOptions(cachePolicy, FetchOptions::Destination::Script), ContentSecurityPolicyEnforcement::DoNotEnforce, ServiceWorkersMode::None, *this, WorkerRunLoop::defaultMode()); 134 if (scriptLoader->failed()) 135 continue; 136 m_loaders.uncheckedAppend(WTFMove(scriptLoader)); 137 } 138 m_remainingLoads = m_loaders.size(); 139 } 140 141 void ServiceWorkerJob::ImportedScriptsLoader::cancel() 142 { 143 auto loaders = WTFMove(m_loaders); 144 for (auto loader : loaders) 145 loader->cancel(); 146 } 147 148 void ServiceWorkerJob::ImportedScriptsLoader::notifyFinished() 149 { 150 if (--m_remainingLoads) 151 return; 152 153 Vector<std::pair<URL, ScriptBuffer>> results; 154 results.reserveInitialCapacity(m_loaders.size()); 155 156 auto loaders = WTFMove(m_loaders); 157 for (auto loader : loaders) { 158 if (!loader->failed()) 159 results.uncheckedAppend(std::make_pair(loader->url(), loader->script())); 160 } 161 162 m_callback(WTFMove(results)); 163 } 164 165 166 void ServiceWorkerJob::refreshImportedScripts(const Vector<URL>& urls, FetchOptions::Cache cachePolicy, RefreshImportedScriptsCallback&& callback) 167 { 168 ASSERT(m_creationThread.ptr() == &Thread::current()); 169 ASSERT(!m_completed); 170 171 auto* context = m_client.context(); 172 if (!context) { 173 callback({ }); 174 return; 175 } 176 177 m_importedScriptsLoader = makeUnique<ImportedScriptsLoader>(WTFMove(callback)); 178 m_importedScriptsLoader->load(*context, urls, cachePolicy); 179 } 180 181 void ServiceWorkerJob::fetchScriptWithContext(ScriptExecutionContext& context, FetchOptions::Cache cachePolicy) 182 { 183 ASSERT(m_creationThread.ptr() == &Thread::current()); 184 ASSERT(!m_completed); 116 185 117 186 auto source = m_jobData.workerType == WorkerType::Module ? WorkerScriptLoader::Source::ModuleScript : WorkerScriptLoader::Source::ClassicWorkerScript; 118 m_scriptLoader->loadAsynchronously(context, WTFMove(request), source, WTFMove(options), ContentSecurityPolicyEnforcement::DoNotEnforce, ServiceWorkersMode::None, *this, WorkerRunLoop::defaultMode()); 187 188 m_scriptLoader = WorkerScriptLoader::create(); 189 m_scriptLoader->loadAsynchronously(context, scriptResourceRequest(context, m_jobData.scriptURL), source, scriptFetchOptions(cachePolicy, FetchOptions::Destination::Serviceworker), ContentSecurityPolicyEnforcement::DoNotEnforce, ServiceWorkersMode::None, *this, WorkerRunLoop::defaultMode()); 119 190 } 120 191 … … 181 252 bool ServiceWorkerJob::cancelPendingLoad() 182 253 { 183 if (!m_scriptLoader) 184 return false; 185 186 m_scriptLoader->cancel(); 187 m_scriptLoader = nullptr; 188 return true; 254 if (auto importedScriptsLoader = WTFMove(m_importedScriptsLoader)) 255 importedScriptsLoader->cancel(); 256 257 if (auto loader = WTFMove(m_scriptLoader)) { 258 m_scriptLoader->cancel(); 259 return true; 260 } 261 return false; 189 262 } 190 263 -
trunk/Source/WebCore/workers/service/ServiceWorkerJob.h
r286012 r293506 35 35 #include "WorkerScriptLoader.h" 36 36 #include "WorkerScriptLoaderClient.h" 37 #include <wtf/CompletionHandler.h> 37 38 #include <wtf/RefPtr.h> 38 39 #include <wtf/RunLoop.h> … … 58 59 void resolvedWithUnregistrationResult(bool); 59 60 void startScriptFetch(FetchOptions::Cache); 61 62 using RefreshImportedScriptsCallback = CompletionHandler<void(Vector<std::pair<URL, ScriptBuffer>>&&)>; 63 void refreshImportedScripts(const Vector<URL>&, FetchOptions::Cache, RefreshImportedScriptsCallback&&); 60 64 61 65 using Identifier = ServiceWorkerJobIdentifier; … … 85 89 bool m_completed { false }; 86 90 91 class ImportedScriptsLoader : public WorkerScriptLoaderClient { 92 WTF_MAKE_FAST_ALLOCATED; 93 public: 94 explicit ImportedScriptsLoader(RefreshImportedScriptsCallback&&); 95 ~ImportedScriptsLoader(); 96 void load(ScriptExecutionContext&, const Vector<URL>&, FetchOptions::Cache); 97 void cancel(); 98 99 private: 100 void didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse&) final { } 101 void notifyFinished() final; 102 103 RefreshImportedScriptsCallback m_callback; 104 Vector<Ref<WorkerScriptLoader>> m_loaders; 105 size_t m_remainingLoads { 0 }; 106 }; 107 87 108 ServiceWorkerOrClientIdentifier m_contextIdentifier; 88 109 RefPtr<WorkerScriptLoader> m_scriptLoader; 110 std::unique_ptr<ImportedScriptsLoader> m_importedScriptsLoader; 89 111 90 112 #if ASSERT_ENABLED -
trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h
r291003 r293506 37 37 class ResourceError; 38 38 class ScriptBuffer; 39 class ScriptExecutionContext; 39 40 class ServiceWorkerJob; 40 41 struct CrossOriginEmbedderPolicy; … … 46 47 virtual ~ServiceWorkerJobClient() = default; 47 48 49 virtual ScriptExecutionContext* context() = 0; 48 50 virtual ServiceWorkerOrClientIdentifier contextIdentifier() = 0; 49 51 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r293501 r293506 346 346 } 347 347 348 void SWServer::Connection::finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, const WorkerFetchResult& result)349 { 350 m_server.scriptFetchFinished(jobDataIdentifier, registrationKey, result);348 void SWServer::Connection::finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, WorkerFetchResult&& result) 349 { 350 m_server.scriptFetchFinished(jobDataIdentifier, registrationKey, WTFMove(result)); 351 351 } 352 352 … … 508 508 } 509 509 510 ResourceRequest SWServer::createScriptRequest(const URL& url, const ServiceWorkerJobData& jobData, SWServerRegistration& registration) 511 { 512 ResourceRequest request { url }; 513 514 auto topOrigin = jobData.topOrigin.securityOrigin(); 515 auto origin = SecurityOrigin::create(jobData.scriptURL); 516 517 request.setDomainForCachePartition(jobData.domainForCachePartition); 518 request.setAllowCookies(true); 519 request.setFirstPartyForCookies(originURL(topOrigin)); 520 521 request.setHTTPHeaderField(HTTPHeaderName::Origin, origin->toString()); 522 request.setHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s); 523 request.setHTTPReferrer(originURL(origin).string()); 524 request.setHTTPUserAgent(serviceWorkerClientUserAgent(ClientOrigin { jobData.topOrigin, SecurityOrigin::create(jobData.scriptURL)->data() })); 525 request.setPriority(ResourceLoadPriority::Low); 526 request.setIsAppInitiated(registration.isAppInitiated()); 527 528 return request; 529 } 530 510 531 void SWServer::startScriptFetch(const ServiceWorkerJobData& jobData, SWServerRegistration& registration) 511 532 { … … 527 548 ASSERT(jobData.type == ServiceWorkerJobType::Update); 528 549 // This is a soft-update job, create directly a network load to fetch the script. 529 ResourceRequest request { jobData.scriptURL }; 530 531 auto topOrigin = jobData.topOrigin.securityOrigin(); 532 auto origin = SecurityOrigin::create(jobData.scriptURL); 533 534 request.setDomainForCachePartition(jobData.domainForCachePartition); 535 request.setAllowCookies(true); 536 request.setFirstPartyForCookies(originURL(topOrigin)); 537 538 request.setHTTPHeaderField(HTTPHeaderName::Origin, origin->toString()); 539 request.setHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s); 540 request.setHTTPReferrer(originURL(origin).string()); 541 request.setHTTPUserAgent(serviceWorkerClientUserAgent(ClientOrigin { jobData.topOrigin, SecurityOrigin::create(jobData.scriptURL)->data() })); 542 request.setPriority(ResourceLoadPriority::Low); 543 request.setIsAppInitiated(registration.isAppInitiated()); 544 545 m_softUpdateCallback(ServiceWorkerJobData { jobData }, shouldRefreshCache, WTFMove(request), [weakThis = WeakPtr { *this }, jobDataIdentifier = jobData.identifier(), registrationKey = jobData.registrationKey()](auto& result) { 550 m_softUpdateCallback(ServiceWorkerJobData { jobData }, shouldRefreshCache, createScriptRequest(jobData.scriptURL, jobData, registration), [weakThis = WeakPtr { *this }, jobDataIdentifier = jobData.identifier(), registrationKey = jobData.registrationKey()](auto&& result) { 546 551 if (weakThis) 547 weakThis->scriptFetchFinished(jobDataIdentifier, registrationKey, result);552 weakThis->scriptFetchFinished(jobDataIdentifier, registrationKey, WTFMove(result)); 548 553 }); 549 554 return; … … 552 557 } 553 558 554 void SWServer::scriptFetchFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, const WorkerFetchResult& result) 559 class RefreshImportedScriptsHandler : public RefCounted<RefreshImportedScriptsHandler> { 560 public: 561 using Callback = CompletionHandler<void(Vector<std::pair<URL, ScriptBuffer>>&&)>; 562 static Ref<RefreshImportedScriptsHandler> create(size_t expectedItems, Callback&& callback) { return adoptRef(*new RefreshImportedScriptsHandler(expectedItems, WTFMove(callback))); } 563 564 void add(const URL& url, WorkerFetchResult&& result) 565 { 566 if (result.error.isNull()) 567 m_scripts.append(std::make_pair(url, WTFMove(result.script))); 568 569 if (!--m_remainingItems) 570 m_callback(std::exchange(m_scripts, { })); 571 } 572 573 private: 574 RefreshImportedScriptsHandler(size_t expectedItems, Callback&& callback) 575 : m_remainingItems(expectedItems) 576 , m_callback(WTFMove(callback)) 577 { 578 } 579 580 size_t m_remainingItems; 581 Callback m_callback; 582 Vector<std::pair<URL, ScriptBuffer>> m_scripts; 583 }; 584 585 void SWServer::scriptFetchFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, WorkerFetchResult&& result) 555 586 { 556 587 LOG(ServiceWorker, "Server handling scriptFetchFinished for current job %s in client", jobDataIdentifier.loggingString().utf8().data()); … … 562 593 return; 563 594 564 jobQueue->scriptFetchFinished(jobDataIdentifier, result); 595 jobQueue->scriptFetchFinished(jobDataIdentifier, WTFMove(result)); 596 } 597 598 void SWServer::refreshImportedScripts(const ServiceWorkerJobData& jobData, SWServerRegistration& registration, const Vector<URL>& urls) 599 { 600 RefreshImportedScriptsHandler::Callback callback = [weakThis = WeakPtr { *this }, jobDataIdentifier = jobData.identifier(), registrationKey = jobData.registrationKey()](auto&& scripts) { 601 if (weakThis) 602 weakThis->refreshImportedScriptsFinished(jobDataIdentifier, registrationKey, scripts); 603 }; 604 bool shouldRefreshCache = registration.updateViaCache() == ServiceWorkerUpdateViaCache::None || (registration.getNewestWorker() && registration.isStale()); 605 606 auto* connection = m_connections.get(jobData.connectionIdentifier()); 607 if (connection) { 608 connection->refreshImportedScripts(jobData.identifier().jobIdentifier, shouldRefreshCache ? FetchOptions::Cache::NoCache : FetchOptions::Cache::Default, urls, WTFMove(callback)); 609 return; 610 } 611 612 ASSERT(jobData.connectionIdentifier() == Process::identifier()); 613 auto handler = RefreshImportedScriptsHandler::create(urls.size(), WTFMove(callback)); 614 for (auto& url : urls) { 615 m_softUpdateCallback(ServiceWorkerJobData { jobData }, shouldRefreshCache, createScriptRequest(url, jobData, registration), [handler, url, size = urls.size()](auto&& result) { 616 handler->add(url, WTFMove(result)); 617 }); 618 } 619 } 620 621 void SWServer::refreshImportedScriptsFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, const Vector<std::pair<URL, ScriptBuffer>>& scripts) 622 { 623 auto jobQueue = m_jobQueues.get(registrationKey); 624 if (!jobQueue) 625 return; 626 627 jobQueue->importedScriptsFetchFinished(jobDataIdentifier, scripts); 565 628 } 566 629 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r293501 r293506 106 106 WEBCORE_EXPORT Connection(SWServer&, Identifier); 107 107 108 WEBCORE_EXPORT void finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const WorkerFetchResult&);108 WEBCORE_EXPORT void finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, WorkerFetchResult&&); 109 109 WEBCORE_EXPORT void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier); 110 110 WEBCORE_EXPORT void removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier); … … 119 119 virtual void resolveUnregistrationJobInClient(ServiceWorkerJobIdentifier, const ServiceWorkerRegistrationKey&, bool registrationResult) = 0; 120 120 virtual void startScriptFetchInClient(ServiceWorkerJobIdentifier, const ServiceWorkerRegistrationKey&, FetchOptions::Cache) = 0; 121 virtual void refreshImportedScripts(ServiceWorkerJobIdentifier, FetchOptions::Cache, const Vector<URL>&, ServiceWorkerJob::RefreshImportedScriptsCallback&&) = 0; 121 122 122 123 struct RegistrationReadyRequest { … … 131 132 }; 132 133 133 using SoftUpdateCallback = Function<void(ServiceWorkerJobData&& jobData, bool shouldRefreshCache, ResourceRequest&&, CompletionHandler<void( const WorkerFetchResult&)>&&)>;134 using SoftUpdateCallback = Function<void(ServiceWorkerJobData&& jobData, bool shouldRefreshCache, ResourceRequest&&, CompletionHandler<void(WorkerFetchResult&&)>&&)>; 134 135 using CreateContextConnectionCallback = Function<void(const WebCore::RegistrableDomain&, std::optional<ProcessIdentifier> requestingProcessIdentifier, std::optional<ScriptExecutionContextIdentifier>, CompletionHandler<void()>&&)>; 135 136 using AppBoundDomainsCallback = Function<void(CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&)>; … … 157 158 void resolveUnregistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationKey&, bool unregistrationResult); 158 159 void startScriptFetch(const ServiceWorkerJobData&, SWServerRegistration&); 160 void refreshImportedScripts(const ServiceWorkerJobData&, SWServerRegistration&, const Vector<URL>&); 159 161 160 162 void updateWorker(const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const CrossOriginEmbedderPolicy&, const String& referrerPolicy, WorkerType, MemoryCompactRobinHoodHashMap<URL, ServiceWorkerContextData::ImportedScript>&&, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier); … … 179 181 SWOriginStore& originStore() { return m_originStore; } 180 182 183 void refreshImportedScriptsFinished(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const Vector<std::pair<URL, ScriptBuffer>>&); 181 184 void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&, const String& message); 182 185 void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&); … … 260 263 void validateRegistrationDomain(WebCore::RegistrableDomain, ServiceWorkerJobType, bool, CompletionHandler<void(bool)>&&); 261 264 262 void scriptFetchFinished(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const WorkerFetchResult&);265 void scriptFetchFinished(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, WorkerFetchResult&&); 263 266 264 267 void didResolveRegistrationPromise(Connection*, const ServiceWorkerRegistrationKey&); … … 283 286 void updateAppInitiatedValueForWorkers(const ClientOrigin&, LastNavigationWasAppInitiated); 284 287 void whenImportIsCompletedIfNeeded(CompletionHandler<void()>&&); 288 289 ResourceRequest createScriptRequest(const URL&, const ServiceWorkerJobData&, SWServerRegistration&); 285 290 286 291 HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>> m_connections; -
trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp
r288938 r293506 70 70 } 71 71 72 void SWServerJobQueue::scriptFetchFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const WorkerFetchResult& result)72 void SWServerJobQueue::scriptFetchFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, WorkerFetchResult&& result) 73 73 { 74 74 if (!isCurrentlyProcessingJob(jobDataIdentifier)) … … 102 102 // text, then: 103 103 if (newestWorker && equalIgnoringFragmentIdentifier(newestWorker->scriptURL(), job.scriptURL) && newestWorker->type() == job.workerType && result.script == newestWorker->script() && doCertificatesMatch(result.certificateInfo, newestWorker->certificateInfo())) { 104 RELEASE_LOG(ServiceWorker, "%p - SWServerJobQueue::scriptFetchFinished, script and certificate are matching for registrationID=%llu", this, registration->identifier().toUInt64()); 104 105 auto scriptURLs = newestWorker->importedScriptURLs(); 106 if (!scriptURLs.isEmpty()) { 107 m_workerFetchResult = WTFMove(result); 108 m_server.refreshImportedScripts(job, *registration, scriptURLs); 109 return; 110 } 111 105 112 // FIXME: for non classic scripts, check the script’s module record's [[ECMAScriptCode]]. 106 113 107 // Invoke Resolve Job Promise with job and registration. 108 m_server.resolveRegistrationJob(job, registration->data(), ShouldNotifyWhenResolved::No); 109 110 // Invoke Finish Job with job and abort these steps. 111 finishCurrentJob(); 112 return; 113 } 114 115 // FIXME: Update all the imported scripts as per spec. For now, we just do as if there is none. 114 RELEASE_LOG(ServiceWorker, "%p - SWServerJobQueue::scriptFetchFinished, script, certificate and imported scripts are matching for registrationID=%llu", this, registration->identifier().toUInt64()); 115 scriptAndImportedScriptsFetchFinished(job, *registration); 116 return; 117 } 116 118 117 119 m_server.updateWorker(job.identifier(), *registration, job.scriptURL, result.script, result.certificateInfo, result.contentSecurityPolicy, result.crossOriginEmbedderPolicy, result.referrerPolicy, job.workerType, { }, job.serviceWorkerPageIdentifier()); 120 } 121 122 void SWServerJobQueue::importedScriptsFetchFinished(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const Vector<std::pair<URL, ScriptBuffer>>& importedScripts) 123 { 124 if (!isCurrentlyProcessingJob(jobDataIdentifier)) 125 return; 126 127 auto& job = firstJob(); 128 129 auto* registration = m_server.getRegistration(m_registrationKey); 130 if (!registration) 131 return; 132 133 auto* newestWorker = registration->getNewestWorker(); 134 if (newestWorker && newestWorker->matchingImportedScripts(importedScripts)) { 135 RELEASE_LOG(ServiceWorker, "%p - SWServerJobQueue::importedScriptsFetchFinished, script, certificate and imported scripts are matching for registrationID=%llu", this, registration->identifier().toUInt64()); 136 scriptAndImportedScriptsFetchFinished(job, *registration); 137 return; 138 } 139 140 m_server.updateWorker(job.identifier(), *registration, job.scriptURL, m_workerFetchResult.script, m_workerFetchResult.certificateInfo, m_workerFetchResult.contentSecurityPolicy, m_workerFetchResult.crossOriginEmbedderPolicy, m_workerFetchResult.referrerPolicy, job.workerType, { }, job.serviceWorkerPageIdentifier()); 141 } 142 143 void SWServerJobQueue::scriptAndImportedScriptsFetchFinished(const ServiceWorkerJobData& job, SWServerRegistration& registration) 144 { 145 // Invoke Resolve Job Promise with job and registration. 146 m_server.resolveRegistrationJob(job, registration.data(), ShouldNotifyWhenResolved::No); 147 148 // Invoke Finish Job with job and abort these steps. 149 finishCurrentJob(); 118 150 } 119 151 -
trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h
r288938 r293506 31 31 #include "ServiceWorkerJobData.h" 32 32 #include "Timer.h" 33 #include "WorkerFetchResult.h" 33 34 #include <wtf/Deque.h> 34 35 … … 36 37 37 38 class SWServerWorker; 39 class ServiceWorkerJob; 38 40 struct WorkerFetchResult; 39 41 … … 52 54 void runNextJob(); 53 55 54 void scriptFetchFinished(const ServiceWorkerJobDataIdentifier&, const WorkerFetchResult&); 56 void scriptFetchFinished(const ServiceWorkerJobDataIdentifier&, WorkerFetchResult&&); 57 void importedScriptsFetchFinished(const ServiceWorkerJobDataIdentifier&, const Vector<std::pair<URL, ScriptBuffer>>&); 55 58 void scriptContextFailedToStart(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier, const String& message); 56 59 void scriptContextStarted(const ServiceWorkerJobDataIdentifier&, ServiceWorkerIdentifier); … … 75 78 76 79 void removeAllJobsMatching(const Function<bool(ServiceWorkerJobData&)>&); 80 void scriptAndImportedScriptsFetchFinished(const ServiceWorkerJobData&, SWServerRegistration&); 77 81 78 82 Deque<ServiceWorkerJobData> m_jobQueue; … … 81 85 SWServer& m_server; 82 86 ServiceWorkerRegistrationKey m_registrationKey; 87 WorkerFetchResult m_workerFetchResult; 83 88 }; 84 89 -
trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp
r293195 r293506 428 428 } 429 429 430 Vector<URL> SWServerWorker::importedScriptURLs() const 431 { 432 return copyToVector(m_scriptResourceMap.keys()); 433 } 434 435 bool SWServerWorker::matchingImportedScripts(const Vector<std::pair<URL, ScriptBuffer>>& scripts) const 436 { 437 for (auto& script : scripts) { 438 auto iterator = m_scriptResourceMap.find(script.first); 439 if (iterator == m_scriptResourceMap.end() || iterator->value.script != script.second) 440 return false; 441 } 442 return true; 443 } 444 430 445 } // namespace WebCore 431 446 -
trunk/Source/WebCore/workers/service/server/SWServerWorker.h
r293195 r293506 145 145 WEBCORE_EXPORT bool isClientActiveServiceWorker(ScriptExecutionContextIdentifier) const; 146 146 147 Vector<URL> importedScriptURLs() const; 148 const MemoryCompactRobinHoodHashMap<URL, ServiceWorkerContextData::ImportedScript>& scriptResourceMap() const { return m_scriptResourceMap; } 149 bool matchingImportedScripts(const Vector<std::pair<URL, ScriptBuffer>>&) const; 150 147 151 private: 148 152 SWServerWorker(SWServer&, SWServerRegistration&, const URL&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const CrossOriginEmbedderPolicy&, String&& referrerPolicy, WorkerType, ServiceWorkerIdentifier, MemoryCompactRobinHoodHashMap<URL, ServiceWorkerContextData::ImportedScript>&&); -
trunk/Source/WebKit/ChangeLog
r293502 r293506 1 2022-04-27 Youenn Fablet <youenn@apple.com> 2 3 service worker update should refresh imported scripts in addition to the main script 4 https://bugs.webkit.org/show_bug.cgi?id=239657 5 6 Reviewed by Chris Dumez. 7 8 * NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.h: 9 * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp: 10 * NetworkProcess/ServiceWorker/WebSWServerConnection.h: 11 * WebProcess/Storage/WebSWClientConnection.messages.in: 12 1 13 2022-04-27 Youenn Fablet <youenn@apple.com> 2 14 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.h
r289018 r293506 51 51 WTF_MAKE_FAST_ALLOCATED; 52 52 public: 53 using Handler = CompletionHandler<void( const WebCore::WorkerFetchResult&)>;53 using Handler = CompletionHandler<void(WebCore::WorkerFetchResult&&)>; 54 54 static void start(NetworkSession*, WebCore::ServiceWorkerJobData&&, bool shouldRefreshCache, WebCore::ResourceRequest&&, Handler&&); 55 55 -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
r293501 r293506 135 135 } 136 136 137 void WebSWServerConnection::refreshImportedScripts(ServiceWorkerJobIdentifier jobIdentifier, FetchOptions::Cache cachePolicy, const Vector<URL>& urls, ServiceWorkerJob::RefreshImportedScriptsCallback&& callback) 138 { 139 sendWithAsyncReply(Messages::WebSWClientConnection::RefreshImportedScripts(jobIdentifier, cachePolicy, urls), WTFMove(callback)); 140 } 141 137 142 void WebSWServerConnection::updateRegistrationStateInClient(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData) 138 143 { -
trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
r293501 r293506 97 97 void resolveUnregistrationJobInClient(WebCore::ServiceWorkerJobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, bool unregistrationResult) final; 98 98 void startScriptFetchInClient(WebCore::ServiceWorkerJobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::FetchOptions::Cache) final; 99 void refreshImportedScripts(WebCore::ServiceWorkerJobIdentifier, WebCore::FetchOptions::Cache, const Vector<URL>&, WebCore::ServiceWorkerJob::RefreshImportedScriptsCallback&&); 99 100 void updateRegistrationStateInClient(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::ServiceWorkerRegistrationState, const std::optional<WebCore::ServiceWorkerData>&) final; 100 101 void updateWorkerStateInClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerState) final; -
trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in
r292861 r293506 28 28 RegistrationJobResolvedInServer(WebCore::ServiceWorkerJobIdentifier jobDataIdentifier, struct WebCore::ServiceWorkerRegistrationData registration, enum:bool WebCore::ShouldNotifyWhenResolved shouldNotifyWhenResolved) 29 29 StartScriptFetchForServer(WebCore::ServiceWorkerJobIdentifier jobDataIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::FetchOptions::Cache cachePolicy) 30 RefreshImportedScripts(WebCore::ServiceWorkerJobIdentifier jobDataIdentifier, WebCore::FetchOptions::Cache cachePolicy, Vector<URL> urls) -> (Vector<std::pair<URL, WebCore::ScriptBuffer>> results); 30 31 UpdateRegistrationState(WebCore::ServiceWorkerRegistrationIdentifier identifier, enum:uint8_t WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerData> serviceWorkerIdentifier) 31 32 UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum:uint8_t WebCore::ServiceWorkerState state)
Note: See TracChangeset
for help on using the changeset viewer.