| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 : service_worker_context_for_testing; | 58 : service_worker_context_for_testing; |
| 59 if (IsBrowserSideNavigationEnabled() && | 59 if (IsBrowserSideNavigationEnabled() && |
| 60 ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType()) && | 60 ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType()) && |
| 61 !service_worker_context) { | 61 !service_worker_context) { |
| 62 service_worker_context = request_info->service_worker_context(); | 62 service_worker_context = request_info->service_worker_context(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 if (!service_worker_context) | 65 if (!service_worker_context) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 ServiceWorkerProviderHost* provider_host = |
| 69 ServiceWorkerRequestHandler::GetProviderHost(request); |
| 70 |
| 71 // If fetched from a service worker, make sure fetching service worker is |
| 72 // controlling at least one client to prevent a service worker from spawning |
| 73 // new service workers in the background. |
| 74 if (provider_host && provider_host->IsHostToRunningServiceWorker()) { |
| 75 if (!provider_host->running_hosted_version()->HasControllee()) |
| 76 return; |
| 77 } |
| 78 |
| 68 if (ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType())) { | 79 if (ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType())) { |
| 69 // In case of navigations, make sure the navigation will actually result in | 80 // In case of navigations, make sure the navigation will actually result in |
| 70 // a secure context. | 81 // a secure context. |
| 71 ServiceWorkerProviderHost* provider_host = | |
| 72 ServiceWorkerRequestHandler::GetProviderHost(request); | |
| 73 if (!provider_host || !provider_host->IsContextSecureForServiceWorker()) | 82 if (!provider_host || !provider_host->IsContextSecureForServiceWorker()) |
| 74 return; | 83 return; |
| 75 } else { | 84 } else { |
| 76 // If this is not a navigation, make sure the request was initiated from a | 85 // If this is not a navigation, make sure the request was initiated from a |
| 77 // secure context. | 86 // secure context. |
| 78 if (!request_info->initiated_in_secure_context()) | 87 if (!request_info->initiated_in_secure_context()) |
| 79 return; | 88 return; |
| 80 } | 89 } |
| 81 | 90 |
| 82 // TODO(mek): support for a serviceworker link on a request that wouldn't ever | 91 // TODO(mek): support for a serviceworker link on a request that wouldn't ever |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 const net::URLRequest* request, | 172 const net::URLRequest* request, |
| 164 const std::string& link_header, | 173 const std::string& link_header, |
| 165 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 174 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
| 166 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { | 175 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { |
| 167 ProcessLinkHeaderValueForRequest(request, value.first, value.second, | 176 ProcessLinkHeaderValueForRequest(request, value.first, value.second, |
| 168 service_worker_context_for_testing); | 177 service_worker_context_for_testing); |
| 169 } | 178 } |
| 170 } | 179 } |
| 171 | 180 |
| 172 } // namespace content | 181 } // namespace content |
| OLD | NEW |