Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Unified Diff: content/browser/service_worker/link_header_support.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/link_header_support.cc
diff --git a/content/browser/service_worker/link_header_support.cc b/content/browser/service_worker/link_header_support.cc
index 9f1fe47107a138bb8a724b1df0842c6fec8e6b50..dbfa83892917cf24eb01e3a959f5c8a537b21370 100644
--- a/content/browser/service_worker/link_header_support.cc
+++ b/content/browser/service_worker/link_header_support.cc
@@ -34,6 +34,24 @@ void RegisterServiceWorkerFinished(int64_t trace_id, bool result) {
trace_id, "Success", result);
}
+blink::WebServiceWorkerUpdateViaCache ParseUpdateViaCache(
+ const std::unordered_map<std::string, base::Optional<std::string>>&
+ params) {
+ // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-updateviacache
+ auto cache_param = params.find("updateviacache");
+ if (cache_param == params.end())
+ return blink::WebServiceWorkerUpdateViaCache::kImports;
+ const std::string& cache = cache_param->second.value_or("");
+ if (base::EqualsCaseInsensitiveASCII(cache, "imports"))
+ return blink::WebServiceWorkerUpdateViaCache::kImports;
+ if (base::EqualsCaseInsensitiveASCII(cache, "all"))
+ return blink::WebServiceWorkerUpdateViaCache::kAll;
+ if (base::EqualsCaseInsensitiveASCII(cache, "none"))
+ return blink::WebServiceWorkerUpdateViaCache::kNone;
+ // Default value
+ return blink::WebServiceWorkerUpdateViaCache::kImports;
+}
+
void HandleServiceWorkerLink(
net::URLRequest* request,
const std::string& url,
@@ -97,6 +115,11 @@ void HandleServiceWorkerLink(
GURL scope_url = scope_param == params.end()
? script_url.Resolve("./")
: context_url.Resolve(scope_param->second.value_or(""));
+ blink::WebServiceWorkerUpdateViaCache update_via_cache =
+ ParseUpdateViaCache(params);
+ if (update_via_cache == blink::WebServiceWorkerUpdateViaCache::kUnknown) {
+ return;
+ }
if (!context_url.is_valid() || !script_url.is_valid() ||
!scope_url.is_valid())
@@ -121,7 +144,7 @@ void HandleServiceWorkerLink(
"ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink",
++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec());
service_worker_context->RegisterServiceWorker(
- scope_url, script_url,
+ scope_url, script_url, update_via_cache,
base::Bind(&RegisterServiceWorkerFinished, trace_id));
}

Powered by Google App Engine
This is Rietveld 408576698