| 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/service_worker/service_worker_provider_context.h" | 9 #include "content/child/service_worker/service_worker_provider_context.h" |
| 10 #include "content/common/navigation_params.h" | 10 #include "content/common/navigation_params.h" |
| 11 #include "content/common/service_worker/service_worker_messages.h" | 11 #include "content/common/service_worker/service_worker_messages.h" |
| 12 #include "content/common/service_worker/service_worker_provider_host_info.h" |
| 12 #include "content/common/service_worker/service_worker_utils.h" | 13 #include "content/common/service_worker/service_worker_utils.h" |
| 13 #include "content/public/common/browser_side_navigation_policy.h" | 14 #include "content/public/common/browser_side_navigation_policy.h" |
| 14 #include "ipc/ipc_sync_channel.h" | 15 #include "ipc/ipc_sync_channel.h" |
| 15 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 18 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 120 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 120 int route_id, | 121 int route_id, |
| 121 ServiceWorkerProviderType provider_type, | 122 ServiceWorkerProviderType provider_type, |
| 122 int browser_provider_id, | 123 int browser_provider_id, |
| 123 bool is_parent_frame_secure) | 124 bool is_parent_frame_secure) |
| 124 : provider_id_(browser_provider_id) { | 125 : provider_id_(browser_provider_id) { |
| 125 if (provider_id_ == kInvalidServiceWorkerProviderId) | 126 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 126 return; | 127 return; |
| 127 if (!ChildThreadImpl::current()) | 128 if (!ChildThreadImpl::current()) |
| 128 return; // May be null in some tests. | 129 return; // May be null in some tests. |
| 130 ServiceWorkerProviderHostInfo provider_info( |
| 131 provider_id_, route_id, provider_type, is_parent_frame_secure); |
| 129 context_ = new ServiceWorkerProviderContext( | 132 context_ = new ServiceWorkerProviderContext( |
| 130 provider_id_, provider_type, | 133 provider_id_, provider_type, |
| 131 ChildThreadImpl::current()->thread_safe_sender()); | 134 ChildThreadImpl::current()->thread_safe_sender()); |
| 132 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 135 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( |
| 133 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( | 136 &dispatcher_host_); |
| 134 &dispatcher_host_); | 137 dispatcher_host_->OnProviderCreated(std::move(provider_info)); |
| 135 dispatcher_host_->OnProviderCreated(provider_id_, route_id, provider_type, | |
| 136 is_parent_frame_secure); | |
| 137 } else { | |
| 138 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_ProviderCreated( | |
| 139 provider_id_, route_id, provider_type, is_parent_frame_secure)); | |
| 140 } | |
| 141 } | 138 } |
| 142 | 139 |
| 143 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( | 140 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( |
| 144 int route_id, | 141 int route_id, |
| 145 ServiceWorkerProviderType provider_type, | 142 ServiceWorkerProviderType provider_type, |
| 146 bool is_parent_frame_secure) | 143 bool is_parent_frame_secure) |
| 147 : ServiceWorkerNetworkProvider(route_id, | 144 : ServiceWorkerNetworkProvider(route_id, |
| 148 provider_type, | 145 provider_type, |
| 149 GetNextProviderId(), | 146 GetNextProviderId(), |
| 150 is_parent_frame_secure) {} | 147 is_parent_frame_secure) {} |
| 151 | 148 |
| 152 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() | 149 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() |
| 153 : provider_id_(kInvalidServiceWorkerProviderId) {} | 150 : provider_id_(kInvalidServiceWorkerProviderId) {} |
| 154 | 151 |
| 155 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { | 152 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { |
| 156 if (provider_id_ == kInvalidServiceWorkerProviderId) | 153 if (provider_id_ == kInvalidServiceWorkerProviderId) |
| 157 return; | 154 return; |
| 158 if (!ChildThreadImpl::current()) | 155 if (!ChildThreadImpl::current()) |
| 159 return; // May be null in some tests. | 156 return; // May be null in some tests. |
| 160 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 157 dispatcher_host_->OnProviderDestroyed(provider_id()); |
| 161 dispatcher_host_->OnProviderDestroyed(provider_id()); | |
| 162 } else { | |
| 163 ChildThreadImpl::current()->Send( | |
| 164 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_)); | |
| 165 } | |
| 166 } | 158 } |
| 167 | 159 |
| 168 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( | 160 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( |
| 169 int64_t version_id, | 161 int64_t version_id, |
| 170 int embedded_worker_id) { | 162 int embedded_worker_id) { |
| 171 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); | 163 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); |
| 172 if (!ChildThreadImpl::current()) | 164 if (!ChildThreadImpl::current()) |
| 173 return; // May be null in some tests. | 165 return; // May be null in some tests. |
| 174 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 166 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, |
| 175 dispatcher_host_->OnSetHostedVersionId(provider_id(), version_id, | 167 embedded_worker_id); |
| 176 embedded_worker_id); | |
| 177 } else { | |
| 178 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_SetVersionId( | |
| 179 provider_id_, version_id, embedded_worker_id)); | |
| 180 } | |
| 181 } | 168 } |
| 182 | 169 |
| 183 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { | 170 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { |
| 184 return context() && context()->controller(); | 171 return context() && context()->controller(); |
| 185 } | 172 } |
| 186 | 173 |
| 187 } // namespace content | 174 } // namespace content |
| OLD | NEW |