Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 15 matching lines...) Expand all Loading... | |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 void RegisterServiceWorkerFinished(int64_t trace_id, bool result) { | 30 void RegisterServiceWorkerFinished(int64_t trace_id, bool result) { |
| 31 TRACE_EVENT_ASYNC_END1("ServiceWorker", | 31 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 32 "LinkHeaderResourceThrottle::HandleServiceWorkerLink", | 32 "LinkHeaderResourceThrottle::HandleServiceWorkerLink", |
| 33 trace_id, "Success", result); | 33 trace_id, "Success", result); |
| 34 } | 34 } |
| 35 | 35 |
| 36 blink::WebServiceWorkerUpdateViaCache ParseUpdateViaCache( | |
|
nhiroki
2017/06/21 15:04:58
Can you add a link to https://html.spec.whatwg.org
yuryu
2017/07/20 10:15:12
Done.
| |
| 37 const std::unordered_map<std::string, base::Optional<std::string>>& | |
| 38 params) { | |
| 39 auto cache_param = params.find("updateviacache"); | |
| 40 if (cache_param == params.end()) | |
| 41 return blink::WebServiceWorkerUpdateViaCache::kImports; | |
| 42 const std::string& cache = cache_param->second.value_or(""); | |
| 43 if (base::EqualsCaseInsensitiveASCII(cache, "imports")) | |
| 44 return blink::WebServiceWorkerUpdateViaCache::kImports; | |
| 45 if (base::EqualsCaseInsensitiveASCII(cache, "never")) | |
|
nhiroki
2017/06/21 15:04:58
never -> none?
https://w3c.github.io/ServiceWorker
yuryu
2017/07/20 10:15:12
Done.
| |
| 46 return blink::WebServiceWorkerUpdateViaCache::kNone; | |
| 47 if (base::EqualsCaseInsensitiveASCII(cache, "all")) | |
| 48 return blink::WebServiceWorkerUpdateViaCache::kAll; | |
| 49 return blink::WebServiceWorkerUpdateViaCache::kUnknown; | |
| 50 } | |
| 51 | |
| 36 void HandleServiceWorkerLink( | 52 void HandleServiceWorkerLink( |
| 37 net::URLRequest* request, | 53 net::URLRequest* request, |
| 38 const std::string& url, | 54 const std::string& url, |
| 39 const std::unordered_map<std::string, base::Optional<std::string>>& params, | 55 const std::unordered_map<std::string, base::Optional<std::string>>& params, |
| 40 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 56 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 57 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 42 | 58 |
| 43 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 59 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 44 switches::kEnableExperimentalWebPlatformFeatures) && | 60 switches::kEnableExperimentalWebPlatformFeatures) && |
| 45 !TrialTokenValidator::RequestEnablesFeature(request, "ForeignFetch")) { | 61 !TrialTokenValidator::RequestEnablesFeature(request, "ForeignFetch")) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // should share logic with ServiceWorkerRequestHandler and | 104 // should share logic with ServiceWorkerRequestHandler and |
| 89 // ForeignFetchRequestHandler to limit the requests for which serviceworker | 105 // ForeignFetchRequestHandler to limit the requests for which serviceworker |
| 90 // links are processed. | 106 // links are processed. |
| 91 | 107 |
| 92 GURL context_url = request->url(); | 108 GURL context_url = request->url(); |
| 93 GURL script_url = context_url.Resolve(url); | 109 GURL script_url = context_url.Resolve(url); |
| 94 auto scope_param = params.find("scope"); | 110 auto scope_param = params.find("scope"); |
| 95 GURL scope_url = scope_param == params.end() | 111 GURL scope_url = scope_param == params.end() |
| 96 ? script_url.Resolve("./") | 112 ? script_url.Resolve("./") |
| 97 : context_url.Resolve(scope_param->second.value_or("")); | 113 : context_url.Resolve(scope_param->second.value_or("")); |
| 114 blink::WebServiceWorkerUpdateViaCache update_via_cache = | |
| 115 ParseUpdateViaCache(params); | |
| 116 if (update_via_cache == blink::WebServiceWorkerUpdateViaCache::kUnknown) { | |
| 117 return; | |
| 118 } | |
| 98 | 119 |
| 99 if (!context_url.is_valid() || !script_url.is_valid() || | 120 if (!context_url.is_valid() || !script_url.is_valid() || |
| 100 !scope_url.is_valid()) | 121 !scope_url.is_valid()) |
| 101 return; | 122 return; |
| 102 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers( | 123 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers( |
| 103 {context_url, scope_url, script_url})) { | 124 {context_url, scope_url, script_url})) { |
| 104 return; | 125 return; |
| 105 } | 126 } |
| 106 std::string error; | 127 std::string error; |
| 107 if (ServiceWorkerUtils::ContainsDisallowedCharacter(scope_url, script_url, | 128 if (ServiceWorkerUtils::ContainsDisallowedCharacter(scope_url, script_url, |
| 108 &error)) | 129 &error)) |
| 109 return; | 130 return; |
| 110 | 131 |
| 111 if (!GetContentClient()->browser()->AllowServiceWorker( | 132 if (!GetContentClient()->browser()->AllowServiceWorker( |
| 112 scope_url, request->first_party_for_cookies(), | 133 scope_url, request->first_party_for_cookies(), |
| 113 request_info->GetContext(), | 134 request_info->GetContext(), |
| 114 request_info->GetWebContentsGetterForRequest())) | 135 request_info->GetWebContentsGetterForRequest())) |
| 115 return; | 136 return; |
| 116 | 137 |
| 117 static int64_t trace_id = 0; | 138 static int64_t trace_id = 0; |
| 118 TRACE_EVENT_ASYNC_BEGIN2( | 139 TRACE_EVENT_ASYNC_BEGIN2( |
| 119 "ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink", | 140 "ServiceWorker", "LinkHeaderResourceThrottle::HandleServiceWorkerLink", |
| 120 ++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec()); | 141 ++trace_id, "Pattern", scope_url.spec(), "Script URL", script_url.spec()); |
| 121 service_worker_context->RegisterServiceWorker( | 142 service_worker_context->RegisterServiceWorker( |
| 122 scope_url, script_url, | 143 scope_url, script_url, update_via_cache, |
| 123 base::Bind(&RegisterServiceWorkerFinished, trace_id)); | 144 base::Bind(&RegisterServiceWorkerFinished, trace_id)); |
| 124 } | 145 } |
| 125 | 146 |
| 126 void ProcessLinkHeaderValueForRequest( | 147 void ProcessLinkHeaderValueForRequest( |
| 127 net::URLRequest* request, | 148 net::URLRequest* request, |
| 128 std::string::const_iterator value_begin, | 149 std::string::const_iterator value_begin, |
| 129 std::string::const_iterator value_end, | 150 std::string::const_iterator value_end, |
| 130 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 151 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 152 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 132 | 153 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 163 net::URLRequest* request, | 184 net::URLRequest* request, |
| 164 const std::string& link_header, | 185 const std::string& link_header, |
| 165 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 186 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 166 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { | 187 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { |
| 167 ProcessLinkHeaderValueForRequest(request, value.first, value.second, | 188 ProcessLinkHeaderValueForRequest(request, value.first, value.second, |
| 168 service_worker_context_for_testing); | 189 service_worker_context_for_testing); |
| 169 } | 190 } |
| 170 } | 191 } |
| 171 | 192 |
| 172 } // namespace content | 193 } // namespace content |
| OLD | NEW |