diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp index 7acb71c74c3..267d1a178cc 100644 --- a/Libraries/LibWeb/ServiceWorker/Job.cpp +++ b/Libraries/LibWeb/ServiceWorker/Job.cpp @@ -349,7 +349,31 @@ static void update(JS::VM& vm, GC::Ref job) state->set_has_updated_resources(true); } - // FIXME: 21. If hasUpdatedResources is false and newestWorker’s classic scripts imported flag is set, then: + // 21. If hasUpdatedResources is false and newestWorker’s classic scripts imported flag is set, then: + if (!state->has_updated_resources()) { + VERIFY(newest_worker); + if (newest_worker->classic_scripts_imported) { + // 1. For each importUrl → storedResponse of newestWorker’s script resource map: + if (false) { + // FIXME: 1. If importUrl is url, then continue. + // FIXME 2. Let importRequest be a new request whose url is importUrl, client is job’s client, destination is "script", parser metadata + // is "not parser-inserted", and whose use-URL-credentials flag is set. + // FIXME: 3. Set importRequest’s cache mode to "no-cache" if any of the following are true: + // * registration’s update via cache mode is "none". + // * job’s force bypass cache flag is set. + // * registration is stale. + // FIXME: 4. Let fetchedResponse be the result of fetching importRequest. + // FIXME: 5. Set updatedResourceMap[importRequest’s url] to fetchedResponse. + // FIXME: 6. Set fetchedResponse to fetchedResponse’s unsafe response. + // FIXME: 7. If fetchedResponse’s cache state is not "local", set registration’s last update check time to the current time. + // FIXME: 8. If fetchedResponse is a bad import script response, continue. + // NOTE: Bad responses for importScripts() are ignored for the purpose of the byte-to-byte check. Only good responses for the incumbent worker + // and good responses for the potential update worker are considered. See issue #1374 for some rationale + // FIXME: 9. If fetchedResponse’s body is not byte-for-byte identical with storedResponse’s unsafe response’s body, set hasUpdatedResources to true. + // NOTE: The control does not break the loop in this step to continue with all the imported scripts to populate the cache. + } + } + } // 22. Asynchronously complete these steps with response. process_response_completion_result = WebIDL::ExceptionOr {}; diff --git a/Libraries/LibWeb/ServiceWorker/Registration.h b/Libraries/LibWeb/ServiceWorker/Registration.h index ce4c4c6ed17..fd48e7e4ab2 100644 --- a/Libraries/LibWeb/ServiceWorker/Registration.h +++ b/Libraries/LibWeb/ServiceWorker/Registration.h @@ -41,7 +41,7 @@ public: StorageAPI::StorageKey const& storage_key() const { return m_storage_key; } URL::URL const& scope_url() const { return m_scope_url; } Bindings::ServiceWorkerUpdateViaCache update_via_cache() const { return m_update_via_cache_mode; } - void set_update_via_cache(Bindings::ServiceWorkerUpdateViaCache update_visa_cache_mode) { m_update_via_cache_mode = update_visa_cache_mode; } + void set_update_via_cache(Bindings::ServiceWorkerUpdateViaCache update_via_cache_mode) { m_update_via_cache_mode = update_via_cache_mode; } void set_last_update_check_time(MonotonicTime time) { m_last_update_check_time = time; } diff --git a/Libraries/LibWeb/ServiceWorker/ServiceWorkerRecord.h b/Libraries/LibWeb/ServiceWorker/ServiceWorkerRecord.h index c8e88aefcca..be1e16a20c7 100644 --- a/Libraries/LibWeb/ServiceWorker/ServiceWorkerRecord.h +++ b/Libraries/LibWeb/ServiceWorker/ServiceWorkerRecord.h @@ -29,6 +29,10 @@ struct ServiceWorkerRecord { // A service worker has an associated type which is either "classic" or "module". Unless stated otherwise, it is "classic". Bindings::WorkerType worker_type = Bindings::WorkerType::Classic; + // https://w3c.github.io/ServiceWorker/#dfn-classic-scripts-imported-flag + // A service worker has an associated classic scripts imported flag. It is initially unset. + bool classic_scripts_imported { false }; + // FIXME: A lot more fields after this... };