| 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" |
| 11 #include "content/browser/loader/resource_message_filter.h" | 11 #include "content/browser/loader/resource_message_filter.h" |
| 12 #include "content/browser/loader/resource_request_info_impl.h" | 12 #include "content/browser/loader/resource_request_info_impl.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 14 #include "content/browser/service_worker/service_worker_request_handler.h" | 14 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 15 #include "content/common/origin_trials/trial_token_validator.h" |
| 15 #include "content/common/service_worker/service_worker_utils.h" | 16 #include "content/common/service_worker/service_worker_utils.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/common/origin_util.h" | 21 #include "content/public/common/origin_util.h" |
| 21 #include "net/http/http_util.h" | 22 #include "net/http/http_util.h" |
| 22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 24 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h" |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 void RegisterServiceWorkerFinished(int64_t trace_id, bool result) { | 30 void RegisterServiceWorkerFinished(int64_t trace_id, bool result) { |
| 29 TRACE_EVENT_ASYNC_END1("ServiceWorker", | 31 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 30 "LinkHeaderResourceThrottle::HandleServiceWorkerLink", | 32 "LinkHeaderResourceThrottle::HandleServiceWorkerLink", |
| 31 trace_id, "Success", result); | 33 trace_id, "Success", result); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void HandleServiceWorkerLink( | 36 void HandleServiceWorkerLink( |
| 35 const net::URLRequest* request, | 37 const net::URLRequest* request, |
| 36 const std::string& url, | 38 const std::string& url, |
| 37 const std::unordered_map<std::string, base::Optional<std::string>>& params, | 39 const std::unordered_map<std::string, base::Optional<std::string>>& params, |
| 38 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 40 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 | 42 |
| 41 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 43 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 42 switches::kEnableExperimentalWebPlatformFeatures)) { | 44 switches::kEnableExperimentalWebPlatformFeatures) && |
| 43 // TODO(mek): Integrate with experimental framework. | 45 !TrialTokenValidator::RequestEnablesFeature(request, "ForeignFetch")) { |
| 46 // TODO(mek): Log attempt to use without having correct token? |
| 44 return; | 47 return; |
| 45 } | 48 } |
| 46 | 49 |
| 47 if (ContainsKey(params, "anchor")) | 50 if (ContainsKey(params, "anchor")) |
| 48 return; | 51 return; |
| 49 | 52 |
| 50 const ResourceRequestInfoImpl* request_info = | 53 const ResourceRequestInfoImpl* request_info = |
| 51 ResourceRequestInfoImpl::ForRequest(request); | 54 ResourceRequestInfoImpl::ForRequest(request); |
| 52 ResourceMessageFilter* filter = request_info->filter(); | 55 ResourceMessageFilter* filter = request_info->filter(); |
| 53 ServiceWorkerContext* service_worker_context = | 56 ServiceWorkerContext* service_worker_context = |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const net::URLRequest* request, | 156 const net::URLRequest* request, |
| 154 const std::string& link_header, | 157 const std::string& link_header, |
| 155 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 158 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 156 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { | 159 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { |
| 157 ProcessLinkHeaderValueForRequest(request, value.first, value.second, | 160 ProcessLinkHeaderValueForRequest(request, value.first, value.second, |
| 158 service_worker_context_for_testing); | 161 service_worker_context_for_testing); |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace content | 165 } // namespace content |
| OLD | NEW |