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

Side by Side 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 tests Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/link_header_support.h" 5 #include "content/browser/service_worker/link_header_support.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "components/link_header_util/link_header_util.h" 10 #include "components/link_header_util/link_header_util.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // should share logic with ServiceWorkerRequestHandler and 88 // should share logic with ServiceWorkerRequestHandler and
89 // ForeignFetchRequestHandler to limit the requests for which serviceworker 89 // ForeignFetchRequestHandler to limit the requests for which serviceworker
90 // links are processed. 90 // links are processed.
91 91
92 GURL context_url = request->url(); 92 GURL context_url = request->url();
93 GURL script_url = context_url.Resolve(url); 93 GURL script_url = context_url.Resolve(url);
94 auto scope_param = params.find("scope"); 94 auto scope_param = params.find("scope");
95 GURL scope_url = scope_param == params.end() 95 GURL scope_url = scope_param == params.end()
96 ? script_url.Resolve("./") 96 ? script_url.Resolve("./")
97 : context_url.Resolve(scope_param->second.value_or("")); 97 : context_url.Resolve(scope_param->second.value_or(""));
98 bool use_cache = params.find("usecache") != params.end();
98 99
99 if (!context_url.is_valid() || !script_url.is_valid() || 100 if (!context_url.is_valid() || !script_url.is_valid() ||
100 !scope_url.is_valid()) 101 !scope_url.is_valid())
101 return; 102 return;
102 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers( 103 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(
103 {context_url, scope_url, script_url})) { 104 {context_url, scope_url, script_url})) {
104 return; 105 return;
105 } 106 }
106 std::string error; 107 std::string error;
107 if (ServiceWorkerUtils::ContainsDisallowedCharacter(scope_url, script_url, 108 if (ServiceWorkerUtils::ContainsDisallowedCharacter(scope_url, script_url,
108 &error)) 109 &error))
109 return; 110 return;
110 111
111 if (!GetContentClient()->browser()->AllowServiceWorker( 112 if (!GetContentClient()->browser()->AllowServiceWorker(
112 scope_url, request->first_party_for_cookies(), 113 scope_url, request->first_party_for_cookies(),
113 request_info->GetContext(), 114 request_info->GetContext(),
114 request_info->GetWebContentsGetterForRequest())) 115 request_info->GetWebContentsGetterForRequest()))
115 return; 116 return;
116 117
117 static int64_t trace_id = 0; 118 static int64_t trace_id = 0;
118 TRACE_EVENT_ASYNC_BEGIN2( 119 TRACE_EVENT_ASYNC_BEGIN2(
119 "ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink", 120 "ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink",
120 ++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec()); 121 ++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec());
121 service_worker_context->RegisterServiceWorker( 122 service_worker_context->RegisterServiceWorker(
122 scope_url, script_url, 123 scope_url, script_url, use_cache,
123 base::Bind(&RegisterServiceWorkerFinished, trace_id)); 124 base::Bind(&RegisterServiceWorkerFinished, trace_id));
124 } 125 }
125 126
126 void ProcessLinkHeaderValueForRequest( 127 void ProcessLinkHeaderValueForRequest(
127 net::URLRequest* request, 128 net::URLRequest* request,
128 std::string::const_iterator value_begin, 129 std::string::const_iterator value_begin,
129 std::string::const_iterator value_end, 130 std::string::const_iterator value_end,
130 ServiceWorkerContextWrapper* service_worker_context_for_testing) { 131 ServiceWorkerContextWrapper* service_worker_context_for_testing) {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); 132 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 133
(...skipping 30 matching lines...) Expand all
163 net::URLRequest* request, 164 net::URLRequest* request,
164 const std::string& link_header, 165 const std::string& link_header,
165 ServiceWorkerContextWrapper* service_worker_context_for_testing) { 166 ServiceWorkerContextWrapper* service_worker_context_for_testing) {
166 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { 167 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) {
167 ProcessLinkHeaderValueForRequest(request, value.first, value.second, 168 ProcessLinkHeaderValueForRequest(request, value.first, value.second,
168 service_worker_context_for_testing); 169 service_worker_context_for_testing);
169 } 170 }
170 } 171 }
171 172
172 } // namespace content 173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698