| 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_handle_reference.h" | 10 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 11 #include "content/child/service_worker/service_worker_provider_context.h" | 11 #include "content/child/service_worker/service_worker_provider_context.h" |
| 12 #include "content/common/navigation_params.h" | 12 #include "content/common/navigation_params.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" | 13 #include "content/common/service_worker/service_worker_messages.h" |
| 14 #include "content/common/service_worker/service_worker_provider_host_info.h" | 14 #include "content/common/service_worker/service_worker_provider_host_info.h" |
| 15 #include "content/common/service_worker/service_worker_utils.h" | 15 #include "content/common/service_worker/service_worker_utils.h" |
| 16 #include "content/public/common/browser_side_navigation_policy.h" | 16 #include "content/public/common/browser_side_navigation_policy.h" |
| 17 #include "ipc/ipc_sync_channel.h" | 17 #include "ipc/ipc_sync_channel.h" |
| 18 #include "mojo/public/cpp/bindings/associated_group.h" |
| 18 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 19 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerNetworkProvider.h" | 20 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerNetworkProvider.h" |
| 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 21 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 22 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Must be unique in the child process. | 28 // Must be unique in the child process. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 168 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 168 int route_id, | 169 int route_id, |
| 169 ServiceWorkerProviderType provider_type, | 170 ServiceWorkerProviderType provider_type, |
| 170 int browser_provider_id, | 171 int browser_provider_id, |
| 171 bool is_parent_frame_secure) | 172 bool is_parent_frame_secure) |
| 172 : provider_id_(browser_provider_id) { | 173 : provider_id_(browser_provider_id) { |
| 173 if (provider_id_ == kInvalidServiceWorkerProviderId) | 174 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 174 return; | 175 return; |
| 175 if (!ChildThreadImpl::current()) | 176 if (!ChildThreadImpl::current()) |
| 176 return; // May be null in some tests. | 177 return; // May be null in some tests. |
| 177 ServiceWorkerProviderHostInfo provider_info( | 178 |
| 178 provider_id_, route_id, provider_type, is_parent_frame_secure); | 179 ServiceWorkerProviderHostInfo host_info(provider_id_, route_id, provider_type, |
| 180 is_parent_frame_secure); |
| 181 host_info.host_request = mojo::MakeRequest(&provider_host_); |
| 182 mojom::ServiceWorkerProviderAssociatedRequest client_request = |
| 183 mojo::MakeRequest(&host_info.client_ptr_info); |
| 184 |
| 185 DCHECK(host_info.host_request.is_pending()); |
| 186 DCHECK(host_info.host_request.handle().is_valid()); |
| 179 context_ = new ServiceWorkerProviderContext( | 187 context_ = new ServiceWorkerProviderContext( |
| 180 provider_id_, provider_type, | 188 provider_id_, provider_type, std::move(client_request), |
| 181 ChildThreadImpl::current()->thread_safe_sender()); | 189 ChildThreadImpl::current()->thread_safe_sender()); |
| 182 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( | 190 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( |
| 183 &dispatcher_host_); | 191 &dispatcher_host_); |
| 184 dispatcher_host_->OnProviderCreated(std::move(provider_info)); | 192 dispatcher_host_->OnProviderCreated(std::move(host_info)); |
| 185 } | 193 } |
| 186 | 194 |
| 187 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 195 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 188 int route_id, | 196 int route_id, |
| 189 ServiceWorkerProviderType provider_type, | 197 ServiceWorkerProviderType provider_type, |
| 190 bool is_parent_frame_secure) | 198 bool is_parent_frame_secure) |
| 191 : ServiceWorkerNetworkProvider(route_id, | 199 : ServiceWorkerNetworkProvider(route_id, |
| 192 provider_type, | 200 provider_type, |
| 193 GetNextProviderId(), | 201 GetNextProviderId(), |
| 194 is_parent_frame_secure) {} | 202 is_parent_frame_secure) {} |
| 195 | 203 |
| 196 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() | 204 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
| 197 : provider_id_(kInvalidServiceWorkerProviderId) {} | 205 : provider_id_(kInvalidServiceWorkerProviderId) {} |
| 198 | 206 |
| 199 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 207 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
| 200 if (provider_id_ == kInvalidServiceWorkerProviderId) | 208 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 201 return; | 209 return; |
| 202 if (!ChildThreadImpl::current()) | 210 if (!ChildThreadImpl::current()) |
| 203 return; // May be null in some tests. | 211 return; // May be null in some tests. |
| 204 dispatcher_host_->OnProviderDestroyed(provider_id()); | 212 provider_host_.reset(); |
| 205 } | 213 } |
| 206 | 214 |
| 207 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( | 215 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( |
| 208 int64_t version_id, | 216 int64_t version_id, |
| 209 int embedded_worker_id) { | 217 int embedded_worker_id) { |
| 210 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); | 218 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); |
| 211 if (!ChildThreadImpl::current()) | 219 if (!ChildThreadImpl::current()) |
| 212 return; // May be null in some tests. | 220 return; // May be null in some tests. |
| 213 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, | 221 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, |
| 214 embedded_worker_id); | 222 embedded_worker_id); |
| 215 } | 223 } |
| 216 | 224 |
| 217 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 225 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
| 218 return context() && context()->controller(); | 226 return context() && context()->controller(); |
| 219 } | 227 } |
| 220 | 228 |
| 221 } // namespace content | 229 } // namespace content |
| OLD | NEW |