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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 170 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
170 int route_id, | 171 int route_id, |
171 ServiceWorkerProviderType provider_type, | 172 ServiceWorkerProviderType provider_type, |
172 int browser_provider_id, | 173 int browser_provider_id, |
173 bool is_parent_frame_secure) | 174 bool is_parent_frame_secure) |
174 : provider_id_(browser_provider_id) { | 175 : provider_id_(browser_provider_id) { |
175 if (provider_id_ == kInvalidServiceWorkerProviderId) | 176 if (provider_id_ == kInvalidServiceWorkerProviderId) |
176 return; | 177 return; |
177 if (!ChildThreadImpl::current()) | 178 if (!ChildThreadImpl::current()) |
178 return; // May be null in some tests. | 179 return; // May be null in some tests. |
179 ServiceWorkerProviderHostInfo provider_info( | 180 |
180 provider_id_, route_id, provider_type, is_parent_frame_secure); | 181 ServiceWorkerProviderHostInfo host_info(provider_id_, route_id, provider_type, |
| 182 is_parent_frame_secure); |
| 183 host_info.host_request = mojo::MakeRequest(&provider_host_); |
| 184 mojom::ServiceWorkerProviderAssociatedRequest client_request = |
| 185 mojo::MakeRequest(&host_info.client_ptr_info); |
| 186 |
| 187 DCHECK(host_info.host_request.is_pending()); |
| 188 DCHECK(host_info.host_request.handle().is_valid()); |
181 context_ = new ServiceWorkerProviderContext( | 189 context_ = new ServiceWorkerProviderContext( |
182 provider_id_, provider_type, | 190 provider_id_, provider_type, std::move(client_request), |
183 ChildThreadImpl::current()->thread_safe_sender()); | 191 ChildThreadImpl::current()->thread_safe_sender()); |
184 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( | 192 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( |
185 &dispatcher_host_); | 193 &dispatcher_host_); |
186 dispatcher_host_->OnProviderCreated(std::move(provider_info)); | 194 dispatcher_host_->OnProviderCreated(std::move(host_info)); |
187 } | 195 } |
188 | 196 |
189 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 197 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
190 int route_id, | 198 int route_id, |
191 ServiceWorkerProviderType provider_type, | 199 ServiceWorkerProviderType provider_type, |
192 bool is_parent_frame_secure) | 200 bool is_parent_frame_secure) |
193 : ServiceWorkerNetworkProvider(route_id, | 201 : ServiceWorkerNetworkProvider(route_id, |
194 provider_type, | 202 provider_type, |
195 GetNextProviderId(), | 203 GetNextProviderId(), |
196 is_parent_frame_secure) {} | 204 is_parent_frame_secure) {} |
197 | 205 |
198 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() | 206 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
199 : provider_id_(kInvalidServiceWorkerProviderId) {} | 207 : provider_id_(kInvalidServiceWorkerProviderId) {} |
200 | 208 |
201 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 209 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
202 if (provider_id_ == kInvalidServiceWorkerProviderId) | 210 if (provider_id_ == kInvalidServiceWorkerProviderId) |
203 return; | 211 return; |
204 if (!ChildThreadImpl::current()) | 212 if (!ChildThreadImpl::current()) |
205 return; // May be null in some tests. | 213 return; // May be null in some tests. |
206 dispatcher_host_->OnProviderDestroyed(provider_id()); | 214 provider_host_.reset(); |
207 } | 215 } |
208 | 216 |
209 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( | 217 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( |
210 int64_t version_id, | 218 int64_t version_id, |
211 int embedded_worker_id) { | 219 int embedded_worker_id) { |
212 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); | 220 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); |
213 if (!ChildThreadImpl::current()) | 221 if (!ChildThreadImpl::current()) |
214 return; // May be null in some tests. | 222 return; // May be null in some tests. |
215 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, | 223 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, |
216 embedded_worker_id); | 224 embedded_worker_id); |
217 } | 225 } |
218 | 226 |
219 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 227 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
220 return context() && context()->controller(); | 228 return context() && context()->controller(); |
221 } | 229 } |
222 | 230 |
223 } // namespace content | 231 } // namespace content |
OLD | NEW |