OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child/service_worker/service_worker_network_provider.h" | 5 #include "content/child/service_worker/service_worker_network_provider.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "content/child/child_thread_impl.h" | 8 #include "content/child/child_thread_impl.h" |
9 #include "content/child/request_extra_data.h" | 9 #include "content/child/request_extra_data.h" |
10 #include "content/child/service_worker/service_worker_dispatcher.h" | |
11 #include "content/child/service_worker/service_worker_handle_reference.h" | 10 #include "content/child/service_worker/service_worker_handle_reference.h" |
12 #include "content/child/service_worker/service_worker_provider_context.h" | 11 #include "content/child/service_worker/service_worker_provider_context.h" |
13 #include "content/common/navigation_params.h" | 12 #include "content/common/navigation_params.h" |
14 #include "content/common/service_worker/service_worker_messages.h" | 13 #include "content/common/service_worker/service_worker_messages.h" |
15 #include "content/common/service_worker/service_worker_provider_host_info.h" | 14 #include "content/common/service_worker/service_worker_provider_host_info.h" |
16 #include "content/common/service_worker/service_worker_utils.h" | 15 #include "content/common/service_worker/service_worker_utils.h" |
17 #include "content/public/common/browser_side_navigation_policy.h" | 16 #include "content/public/common/browser_side_navigation_policy.h" |
18 #include "ipc/ipc_sync_channel.h" | 17 #include "ipc/ipc_sync_channel.h" |
19 #include "mojo/public/cpp/bindings/associated_group.h" | 18 #include "mojo/public/cpp/bindings/associated_group.h" |
20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 19 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 200 |
202 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 201 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
203 int route_id, | 202 int route_id, |
204 ServiceWorkerProviderType provider_type, | 203 ServiceWorkerProviderType provider_type, |
205 bool is_parent_frame_secure) | 204 bool is_parent_frame_secure) |
206 : ServiceWorkerNetworkProvider(route_id, | 205 : ServiceWorkerNetworkProvider(route_id, |
207 provider_type, | 206 provider_type, |
208 GetNextProviderId(), | 207 GetNextProviderId(), |
209 is_parent_frame_secure) {} | 208 is_parent_frame_secure) {} |
210 | 209 |
211 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | |
212 mojom::ServiceWorkerProviderInfoForStartWorkerPtr info) | |
213 : provider_id_(info->provider_id) { | |
214 context_ = new ServiceWorkerProviderContext( | |
215 provider_id_, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | |
216 std::move(info->client_request), | |
217 ChildThreadImpl::current()->thread_safe_sender()); | |
218 | |
219 ServiceWorkerDispatcher* dispatcher = | |
220 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | |
221 ChildThreadImpl::current()->thread_safe_sender(), | |
222 base::ThreadTaskRunnerHandle::Get().get()); | |
223 // TODO(shimazu): Set registration/attributes directly to |context_|. | |
224 dispatcher->OnAssociateRegistration(-1 /* unused thread_id */, | |
225 info->provider_id, info->registration, | |
226 info->attributes); | |
227 provider_host_.Bind(std::move(info->host_ptr_info)); | |
228 } | |
229 | |
230 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() | 210 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
231 : provider_id_(kInvalidServiceWorkerProviderId) {} | 211 : provider_id_(kInvalidServiceWorkerProviderId) {} |
232 | 212 |
233 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 213 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
234 if (provider_id_ == kInvalidServiceWorkerProviderId) | 214 if (provider_id_ == kInvalidServiceWorkerProviderId) |
235 return; | 215 return; |
236 if (!ChildThreadImpl::current()) | 216 if (!ChildThreadImpl::current()) |
237 return; // May be null in some tests. | 217 return; // May be null in some tests. |
238 provider_host_.reset(); | 218 provider_host_.reset(); |
239 } | 219 } |
240 | 220 |
| 221 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( |
| 222 int64_t version_id, |
| 223 int embedded_worker_id) { |
| 224 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); |
| 225 if (!ChildThreadImpl::current()) |
| 226 return; // May be null in some tests. |
| 227 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, |
| 228 embedded_worker_id); |
| 229 } |
| 230 |
241 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 231 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
242 if (ServiceWorkerUtils::IsServicificationEnabled()) { | 232 if (ServiceWorkerUtils::IsServicificationEnabled()) { |
243 // Interception for subresource loading is not working (yet) | 233 // Interception for subresource loading is not working (yet) |
244 // when servicification is enabled. | 234 // when servicification is enabled. |
245 return false; | 235 return false; |
246 } | 236 } |
247 return context() && context()->controller(); | 237 return context() && context()->controller(); |
248 } | 238 } |
249 | 239 |
250 } // namespace content | 240 } // namespace content |
OLD | NEW |