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. | |
falken
2016/11/21 04:13:42
nit: maybe it'd help the reader to add "To prevent
Marijn Kruisselbrink
2016/11/21 05:10:56
Done
| |
73 if (provider_host && provider_host->IsHostToRunningServiceWorker()) { | |
74 if (!provider_host->running_hosted_version()->HasControllee()) | |
75 return; | |
76 } | |
77 | |
68 if (ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType())) { | 78 if (ServiceWorkerUtils::IsMainResourceType(request_info->GetResourceType())) { |
69 // In case of navigations, make sure the navigation will actually result in | 79 // In case of navigations, make sure the navigation will actually result in |
70 // a secure context. | 80 // a secure context. |
71 ServiceWorkerProviderHost* provider_host = | |
72 ServiceWorkerRequestHandler::GetProviderHost(request); | |
73 if (!provider_host || !provider_host->IsContextSecureForServiceWorker()) | 81 if (!provider_host || !provider_host->IsContextSecureForServiceWorker()) |
74 return; | 82 return; |
75 } else { | 83 } else { |
76 // If this is not a navigation, make sure the request was initiated from a | 84 // If this is not a navigation, make sure the request was initiated from a |
77 // secure context. | 85 // secure context. |
78 if (!request_info->initiated_in_secure_context()) | 86 if (!request_info->initiated_in_secure_context()) |
79 return; | 87 return; |
80 } | 88 } |
81 | 89 |
82 // TODO(mek): support for a serviceworker link on a request that wouldn't ever | 90 // 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, | 171 const net::URLRequest* request, |
164 const std::string& link_header, | 172 const std::string& link_header, |
165 ServiceWorkerContextWrapper* service_worker_context_for_testing) { | 173 ServiceWorkerContextWrapper* service_worker_context_for_testing) { |
166 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { | 174 for (const auto& value : link_header_util::SplitLinkHeader(link_header)) { |
167 ProcessLinkHeaderValueForRequest(request, value.first, value.second, | 175 ProcessLinkHeaderValueForRequest(request, value.first, value.second, |
168 service_worker_context_for_testing); | 176 service_worker_context_for_testing); |
169 } | 177 } |
170 } | 178 } |
171 | 179 |
172 } // namespace content | 180 } // namespace content |
OLD | NEW |