OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service_worker_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "content/browser/service_worker/embedded_worker_status.h" | 14 #include "content/browser/service_worker/embedded_worker_status.h" |
15 #include "content/browser/service_worker/service_worker_context_core.h" | 15 #include "content/browser/service_worker/service_worker_context_core.h" |
16 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 16 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
17 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" | 17 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
18 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 18 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
19 #include "content/browser/service_worker/service_worker_handle.h" | 19 #include "content/browser/service_worker/service_worker_handle.h" |
20 #include "content/browser/service_worker/service_worker_registration_handle.h" | 20 #include "content/browser/service_worker/service_worker_registration_handle.h" |
21 #include "content/browser/service_worker/service_worker_version.h" | 21 #include "content/browser/service_worker/service_worker_version.h" |
| 22 #include "content/browser/url_loader_factory_getter.h" |
22 #include "content/common/resource_request_body_impl.h" | 23 #include "content/common/resource_request_body_impl.h" |
23 #include "content/common/service_worker/service_worker_messages.h" | 24 #include "content/common/service_worker/service_worker_messages.h" |
24 #include "content/common/service_worker/service_worker_types.h" | 25 #include "content/common/service_worker/service_worker_types.h" |
25 #include "content/common/service_worker/service_worker_utils.h" | 26 #include "content/common/service_worker/service_worker_utils.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/common/browser_side_navigation_policy.h" | 28 #include "content/public/common/browser_side_navigation_policy.h" |
28 #include "content/public/common/child_process_host.h" | 29 #include "content/public/common/child_process_host.h" |
29 #include "content/public/common/content_client.h" | 30 #include "content/public/common/content_client.h" |
30 #include "content/public/common/content_features.h" | 31 #include "content/public/common/content_features.h" |
31 #include "content/public/common/origin_util.h" | 32 #include "content/public/common/origin_util.h" |
32 #include "mojo/public/cpp/bindings/strong_associated_binding.h" | 33 #include "mojo/public/cpp/bindings/strong_associated_binding.h" |
33 #include "net/base/url_util.h" | 34 #include "net/base/url_util.h" |
| 35 #include "storage/browser/blob/blob_storage_context.h" |
34 | 36 |
35 namespace content { | 37 namespace content { |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 // PlzNavigate | 41 // Provider host for navigation with PlzNavigate or service worker's context is |
40 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps | 42 // created on the browser side. This function provides the next |
41 // going down. | 43 // ServiceWorkerProviderHost ID for them, starts at -2 and keeps going down. |
42 int g_next_navigation_provider_id = -2; | 44 int NextBrowserProvidedProviderId() { |
| 45 static int g_next_browser_provided_provider_id = -2; |
| 46 return g_next_browser_provided_provider_id--; |
| 47 } |
43 | 48 |
44 // A request handler derivative used to handle navigation requests when | 49 // A request handler derivative used to handle navigation requests when |
45 // skip_service_worker flag is set. It tracks the document URL and sets the url | 50 // skip_service_worker flag is set. It tracks the document URL and sets the url |
46 // to the provider host. | 51 // to the provider host. |
47 class ServiceWorkerURLTrackingRequestHandler | 52 class ServiceWorkerURLTrackingRequestHandler |
48 : public ServiceWorkerRequestHandler { | 53 : public ServiceWorkerRequestHandler { |
49 public: | 54 public: |
50 ServiceWorkerURLTrackingRequestHandler( | 55 ServiceWorkerURLTrackingRequestHandler( |
51 base::WeakPtr<ServiceWorkerContextCore> context, | 56 base::WeakPtr<ServiceWorkerContextCore> context, |
52 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 57 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
53 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 58 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
54 ResourceType resource_type) | 59 ResourceType resource_type) |
55 : ServiceWorkerRequestHandler(context, | 60 : ServiceWorkerRequestHandler(context, |
56 provider_host, | 61 provider_host, |
57 blob_storage_context, | 62 blob_storage_context, |
58 resource_type) {} | 63 resource_type) {} |
59 ~ServiceWorkerURLTrackingRequestHandler() override {} | 64 ~ServiceWorkerURLTrackingRequestHandler() override {} |
60 | 65 |
61 // Called via custom URLRequestJobFactory. | 66 // Called via custom URLRequestJobFactory. |
62 net::URLRequestJob* MaybeCreateJob( | 67 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, |
63 net::URLRequest* request, | 68 net::NetworkDelegate*, |
64 net::NetworkDelegate* /* network_delegate */, | 69 ResourceContext*) override { |
65 ResourceContext* /* resource_context */) override { | |
66 // |provider_host_| may have been deleted when the request is resumed. | 70 // |provider_host_| may have been deleted when the request is resumed. |
67 if (!provider_host_) | 71 if (!provider_host_) |
68 return nullptr; | 72 return nullptr; |
69 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); | 73 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); |
70 provider_host_->SetDocumentUrl(stripped_url); | 74 provider_host_->SetDocumentUrl(stripped_url); |
71 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); | 75 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); |
72 return nullptr; | 76 return nullptr; |
73 } | 77 } |
74 | 78 |
75 private: | 79 private: |
(...skipping 13 matching lines...) Expand all Loading... |
89 // process, to have been destroyed before being claimed by the renderer. The | 93 // process, to have been destroyed before being claimed by the renderer. The |
90 // provider is then destroyed in the renderer, and no matching host will be | 94 // provider is then destroyed in the renderer, and no matching host will be |
91 // found. | 95 // found. |
92 DCHECK(IsBrowserSideNavigationEnabled() && | 96 DCHECK(IsBrowserSideNavigationEnabled() && |
93 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); | 97 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); |
94 return; | 98 return; |
95 } | 99 } |
96 context->RemoveProviderHost(process_id, provider_id); | 100 context->RemoveProviderHost(process_id, provider_id); |
97 } | 101 } |
98 | 102 |
| 103 // Used by a Service Worker for script loading (only during installation, |
| 104 // eventually). For now this is just a proxy loader for the network loader. |
| 105 // TODO(kinuko): Implement this. Hook up the existing code in |
| 106 // ServiceWorkerContextRequestHandler. |
| 107 class ScriptURLLoader : public mojom::URLLoader, public mojom::URLLoaderClient { |
| 108 public: |
| 109 ScriptURLLoader( |
| 110 int32_t routing_id, |
| 111 int32_t request_id, |
| 112 uint32_t options, |
| 113 const ResourceRequest& url_request, |
| 114 mojom::URLLoaderClientPtr client, |
| 115 base::WeakPtr<ServiceWorkerContextCore> context, |
| 116 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 117 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 118 scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter, |
| 119 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) |
| 120 : network_client_binding_(this), |
| 121 forwarding_client_(std::move(client)), |
| 122 provider_host_(provider_host) { |
| 123 mojom::URLLoaderClientPtr network_client; |
| 124 network_client_binding_.Bind(mojo::MakeRequest(&network_client)); |
| 125 loader_factory_getter->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| 126 mojo::MakeRequest(&network_loader_), routing_id, request_id, options, |
| 127 url_request, std::move(network_client), traffic_annotation); |
| 128 } |
| 129 ~ScriptURLLoader() override {} |
| 130 |
| 131 // mojom::URLLoader: |
| 132 void FollowRedirect() override { network_loader_->FollowRedirect(); } |
| 133 void SetPriority(net::RequestPriority priority, |
| 134 int32_t intra_priority_value) override { |
| 135 network_loader_->SetPriority(priority, intra_priority_value); |
| 136 } |
| 137 |
| 138 // mojom::URLLoaderClient for simply proxying network: |
| 139 void OnReceiveResponse( |
| 140 const ResourceResponseHead& response_head, |
| 141 const base::Optional<net::SSLInfo>& ssl_info, |
| 142 mojom::DownloadedTempFilePtr downloaded_file) override { |
| 143 if (provider_host_) { |
| 144 // We don't have complete info here, but fill in what we have now. |
| 145 // At least we need headers and SSL info. |
| 146 net::HttpResponseInfo response_info; |
| 147 response_info.headers = response_head.headers; |
| 148 if (ssl_info.has_value()) |
| 149 response_info.ssl_info = *ssl_info; |
| 150 response_info.was_fetched_via_spdy = response_head.was_fetched_via_spdy; |
| 151 response_info.was_alpn_negotiated = response_head.was_alpn_negotiated; |
| 152 response_info.alpn_negotiated_protocol = |
| 153 response_head.alpn_negotiated_protocol; |
| 154 response_info.connection_info = response_head.connection_info; |
| 155 response_info.socket_address = response_head.socket_address; |
| 156 |
| 157 DCHECK(provider_host_->IsHostToRunningServiceWorker()); |
| 158 provider_host_->running_hosted_version()->SetMainScriptHttpResponseInfo( |
| 159 response_info); |
| 160 } |
| 161 forwarding_client_->OnReceiveResponse(response_head, ssl_info, |
| 162 std::move(downloaded_file)); |
| 163 } |
| 164 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
| 165 const ResourceResponseHead& response_head) override { |
| 166 forwarding_client_->OnReceiveRedirect(redirect_info, response_head); |
| 167 } |
| 168 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override { |
| 169 forwarding_client_->OnDataDownloaded(data_len, encoded_data_len); |
| 170 } |
| 171 void OnUploadProgress(int64_t current_position, |
| 172 int64_t total_size, |
| 173 OnUploadProgressCallback ack_callback) override { |
| 174 forwarding_client_->OnUploadProgress(current_position, total_size, |
| 175 std::move(ack_callback)); |
| 176 } |
| 177 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override { |
| 178 forwarding_client_->OnReceiveCachedMetadata(data); |
| 179 } |
| 180 void OnTransferSizeUpdated(int32_t transfer_size_diff) override { |
| 181 forwarding_client_->OnTransferSizeUpdated(transfer_size_diff); |
| 182 } |
| 183 void OnStartLoadingResponseBody( |
| 184 mojo::ScopedDataPipeConsumerHandle body) override { |
| 185 forwarding_client_->OnStartLoadingResponseBody(std::move(body)); |
| 186 } |
| 187 void OnComplete(const ResourceRequestCompletionStatus& status) override { |
| 188 forwarding_client_->OnComplete(status); |
| 189 } |
| 190 |
| 191 private: |
| 192 mojom::URLLoaderAssociatedPtr network_loader_; |
| 193 mojo::Binding<mojom::URLLoaderClient> network_client_binding_; |
| 194 mojom::URLLoaderClientPtr forwarding_client_; |
| 195 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(ScriptURLLoader); |
| 198 }; |
| 199 |
| 200 // Created per one controller worker for script loading (only during |
| 201 // installation, eventually). This is kept alive while |
| 202 // ServiceWorkerNetworkProvider in the renderer process is alive. |
| 203 // Used only when IsServicificationEnabled is true. |
| 204 class ScriptURLLoaderFactory : public mojom::URLLoaderFactory { |
| 205 public: |
| 206 ScriptURLLoaderFactory( |
| 207 base::WeakPtr<ServiceWorkerContextCore> context, |
| 208 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 209 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 210 scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter) |
| 211 : context_(context), |
| 212 provider_host_(provider_host), |
| 213 blob_storage_context_(blob_storage_context), |
| 214 loader_factory_getter_(loader_factory_getter) {} |
| 215 ~ScriptURLLoaderFactory() override {} |
| 216 |
| 217 // mojom::URLLoaderFactory: |
| 218 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
| 219 int32_t routing_id, |
| 220 int32_t request_id, |
| 221 uint32_t options, |
| 222 const ResourceRequest& url_request, |
| 223 mojom::URLLoaderClientPtr client, |
| 224 const net::MutableNetworkTrafficAnnotationTag& |
| 225 traffic_annotation) override { |
| 226 mojo::MakeStrongAssociatedBinding( |
| 227 base::MakeUnique<ScriptURLLoader>( |
| 228 routing_id, request_id, options, url_request, std::move(client), |
| 229 context_, provider_host_, blob_storage_context_, |
| 230 loader_factory_getter_, traffic_annotation), |
| 231 std::move(request)); |
| 232 } |
| 233 |
| 234 void SyncLoad(int32_t routing_id, |
| 235 int32_t request_id, |
| 236 const ResourceRequest& request, |
| 237 SyncLoadCallback callback) override { |
| 238 NOTREACHED(); |
| 239 } |
| 240 |
| 241 private: |
| 242 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 243 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 244 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 245 scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter_; |
| 246 DISALLOW_COPY_AND_ASSIGN(ScriptURLLoaderFactory); |
| 247 }; |
| 248 |
99 } // anonymous namespace | 249 } // anonymous namespace |
100 | 250 |
101 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( | 251 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
102 const GetRegistrationForReadyCallback& callback) | 252 const GetRegistrationForReadyCallback& callback) |
103 : callback(callback), | 253 : callback(callback), |
104 called(false) { | 254 called(false) { |
105 } | 255 } |
106 | 256 |
107 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { | 257 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { |
108 } | 258 } |
109 | 259 |
110 // static | 260 // static |
111 std::unique_ptr<ServiceWorkerProviderHost> | 261 std::unique_ptr<ServiceWorkerProviderHost> |
112 ServiceWorkerProviderHost::PreCreateNavigationHost( | 262 ServiceWorkerProviderHost::PreCreateNavigationHost( |
113 base::WeakPtr<ServiceWorkerContextCore> context, | 263 base::WeakPtr<ServiceWorkerContextCore> context, |
114 bool are_ancestors_secure, | 264 bool are_ancestors_secure, |
115 const WebContentsGetter& web_contents_getter) { | 265 const WebContentsGetter& web_contents_getter) { |
116 CHECK(IsBrowserSideNavigationEnabled()); | 266 CHECK(IsBrowserSideNavigationEnabled()); |
117 // Generate a new browser-assigned id for the host. | |
118 int provider_id = g_next_navigation_provider_id--; | |
119 auto host = base::WrapUnique(new ServiceWorkerProviderHost( | 267 auto host = base::WrapUnique(new ServiceWorkerProviderHost( |
120 ChildProcessHost::kInvalidUniqueID, | 268 ChildProcessHost::kInvalidUniqueID, |
121 ServiceWorkerProviderHostInfo(provider_id, MSG_ROUTING_NONE, | 269 ServiceWorkerProviderHostInfo( |
122 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 270 NextBrowserProvidedProviderId(), MSG_ROUTING_NONE, |
123 are_ancestors_secure), | 271 SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure), |
124 context, nullptr)); | 272 context, nullptr)); |
125 host->web_contents_getter_ = web_contents_getter; | 273 host->web_contents_getter_ = web_contents_getter; |
126 return host; | 274 return host; |
127 } | 275 } |
128 | 276 |
129 // static | 277 // static |
| 278 std::unique_ptr<ServiceWorkerProviderHost> |
| 279 ServiceWorkerProviderHost::PreCreateForController( |
| 280 ServiceWorkerVersion* version, |
| 281 base::WeakPtr<ServiceWorkerContextCore> context) { |
| 282 auto host = base::WrapUnique(new ServiceWorkerProviderHost( |
| 283 ChildProcessHost::kInvalidUniqueID, |
| 284 ServiceWorkerProviderHostInfo(NextBrowserProvidedProviderId(), |
| 285 MSG_ROUTING_NONE, |
| 286 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, |
| 287 true /* is_parent_frame_secure */), |
| 288 context, nullptr)); |
| 289 host->SetHostedVersion(version); |
| 290 return host; |
| 291 } |
| 292 |
| 293 // static |
130 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( | 294 std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( |
131 int process_id, | 295 int process_id, |
132 ServiceWorkerProviderHostInfo info, | 296 ServiceWorkerProviderHostInfo info, |
133 base::WeakPtr<ServiceWorkerContextCore> context, | 297 base::WeakPtr<ServiceWorkerContextCore> context, |
134 ServiceWorkerDispatcherHost* dispatcher_host) { | 298 ServiceWorkerDispatcherHost* dispatcher_host) { |
135 return base::WrapUnique(new ServiceWorkerProviderHost( | 299 return base::WrapUnique(new ServiceWorkerProviderHost( |
136 process_id, std::move(info), context, dispatcher_host)); | 300 process_id, std::move(info), context, dispatcher_host)); |
137 } | 301 } |
138 | 302 |
139 void ServiceWorkerProviderHost::BindWorkerFetchContext( | 303 void ServiceWorkerProviderHost::BindWorkerFetchContext( |
(...skipping 30 matching lines...) Expand all Loading... |
170 create_time_(base::TimeTicks::Now()), | 334 create_time_(base::TimeTicks::Now()), |
171 render_process_id_(render_process_id), | 335 render_process_id_(render_process_id), |
172 render_thread_id_(kDocumentMainThreadId), | 336 render_thread_id_(kDocumentMainThreadId), |
173 info_(std::move(info)), | 337 info_(std::move(info)), |
174 context_(context), | 338 context_(context), |
175 dispatcher_host_(dispatcher_host), | 339 dispatcher_host_(dispatcher_host), |
176 allow_association_(true), | 340 allow_association_(true), |
177 binding_(this) { | 341 binding_(this) { |
178 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); | 342 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); |
179 | 343 |
180 // PlzNavigate | |
181 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | |
182 IsBrowserSideNavigationEnabled()); | |
183 | 344 |
184 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 345 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
185 // Actual thread id is set when the service worker context gets started. | 346 // Actual |render_process_id| will be set after choosing a process for the |
| 347 // controller, and |render_thread id| will be set when the service worker |
| 348 // context gets started. |
| 349 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id); |
186 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 350 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| 351 } else { |
| 352 // PlzNavigate |
| 353 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
| 354 IsBrowserSideNavigationEnabled()); |
187 } | 355 } |
| 356 |
188 context_->RegisterProviderHostByClientID(client_uuid_, this); | 357 context_->RegisterProviderHostByClientID(client_uuid_, this); |
189 | 358 |
190 // PlzNavigate | 359 // |client_| and |binding_| will be bound on CompleteNavigationInitialized |
191 // |provider_| and |binding_| will be bound on CompleteNavigationInitialized. | 360 // (PlzNavigate) or on CompleteStartWorkerPreparation (providers for |
192 if (IsBrowserSideNavigationEnabled()) { | 361 // controller). |
193 DCHECK(!info.client_ptr_info.is_valid() && !info.host_request.is_pending()); | 362 if (!info_.client_ptr_info.is_valid() && !info_.host_request.is_pending()) { |
| 363 DCHECK(IsBrowserSideNavigationEnabled() || |
| 364 info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER); |
194 return; | 365 return; |
195 } | 366 } |
196 | 367 |
197 provider_.Bind(std::move(info_.client_ptr_info)); | 368 provider_.Bind(std::move(info_.client_ptr_info)); |
198 binding_.Bind(std::move(info_.host_request)); | 369 binding_.Bind(std::move(info_.host_request)); |
199 binding_.set_connection_error_handler(base::Bind( | 370 binding_.set_connection_error_handler(base::Bind( |
200 &RemoveProviderHost, context_, render_process_id, info_.provider_id)); | 371 &RemoveProviderHost, context_, render_process_id, info_.provider_id)); |
201 } | 372 } |
202 | 373 |
203 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 374 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 DCHECK(IsProviderForClient()); | 491 DCHECK(IsProviderForClient()); |
321 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 492 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
322 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version), | 493 render_thread_id_, provider_id(), GetOrCreateServiceWorkerHandle(version), |
323 notify_controllerchange, | 494 notify_controllerchange, |
324 version ? version->used_features() : std::set<uint32_t>())); | 495 version ? version->used_features() : std::set<uint32_t>())); |
325 } | 496 } |
326 | 497 |
327 void ServiceWorkerProviderHost::SetHostedVersion( | 498 void ServiceWorkerProviderHost::SetHostedVersion( |
328 ServiceWorkerVersion* version) { | 499 ServiceWorkerVersion* version) { |
329 DCHECK(!IsProviderForClient()); | 500 DCHECK(!IsProviderForClient()); |
330 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, version->running_status()); | 501 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, version->running_status()); |
331 DCHECK_EQ(render_process_id_, version->embedded_worker()->process_id()); | 502 DCHECK(!running_hosted_version_); |
332 running_hosted_version_ = version; | 503 running_hosted_version_ = version; |
333 } | 504 } |
334 | 505 |
335 bool ServiceWorkerProviderHost::IsProviderForClient() const { | 506 bool ServiceWorkerProviderHost::IsProviderForClient() const { |
336 switch (info_.type) { | 507 switch (info_.type) { |
337 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: | 508 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: |
338 case SERVICE_WORKER_PROVIDER_FOR_WORKER: | 509 case SERVICE_WORKER_PROVIDER_FOR_WORKER: |
339 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: | 510 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: |
340 return true; | 511 return true; |
341 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: | 512 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (get_ready_callback_) | 730 if (get_ready_callback_) |
560 return false; | 731 return false; |
561 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); | 732 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); |
562 ReturnRegistrationForReadyIfNeeded(); | 733 ReturnRegistrationForReadyIfNeeded(); |
563 return true; | 734 return true; |
564 } | 735 } |
565 | 736 |
566 std::unique_ptr<ServiceWorkerProviderHost> | 737 std::unique_ptr<ServiceWorkerProviderHost> |
567 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | 738 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { |
568 DCHECK(!IsBrowserSideNavigationEnabled()); | 739 DCHECK(!IsBrowserSideNavigationEnabled()); |
| 740 DCHECK(!ServiceWorkerUtils::IsServicificationEnabled()); |
569 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 741 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
570 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id); | 742 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id); |
571 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | 743 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
572 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); | 744 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); |
573 | 745 |
574 std::unique_ptr<ServiceWorkerProviderHost> provisional_host = | 746 std::unique_ptr<ServiceWorkerProviderHost> provisional_host = |
575 base::WrapUnique(new ServiceWorkerProviderHost( | 747 base::WrapUnique(new ServiceWorkerProviderHost( |
576 process_id(), | 748 process_id(), |
577 ServiceWorkerProviderHostInfo(std::move(info_), binding_.Unbind(), | 749 ServiceWorkerProviderHostInfo(std::move(info_), binding_.Unbind(), |
578 provider_.PassInterface()), | 750 provider_.PassInterface()), |
(...skipping 13 matching lines...) Expand all Loading... |
592 | 764 |
593 render_process_id_ = ChildProcessHost::kInvalidUniqueID; | 765 render_process_id_ = ChildProcessHost::kInvalidUniqueID; |
594 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 766 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
595 dispatcher_host_ = nullptr; | 767 dispatcher_host_ = nullptr; |
596 return provisional_host; | 768 return provisional_host; |
597 } | 769 } |
598 | 770 |
599 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 771 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
600 ServiceWorkerProviderHost* provisional_host) { | 772 ServiceWorkerProviderHost* provisional_host) { |
601 DCHECK(!IsBrowserSideNavigationEnabled()); | 773 DCHECK(!IsBrowserSideNavigationEnabled()); |
| 774 DCHECK(!ServiceWorkerUtils::IsServicificationEnabled()); |
602 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 775 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
603 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id()); | 776 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id()); |
604 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id()); | 777 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id()); |
605 | 778 |
606 render_process_id_ = provisional_host->process_id(); | 779 render_process_id_ = provisional_host->process_id(); |
607 render_thread_id_ = kDocumentMainThreadId; | 780 render_thread_id_ = kDocumentMainThreadId; |
608 dispatcher_host_ = provisional_host->dispatcher_host(); | 781 dispatcher_host_ = provisional_host->dispatcher_host(); |
609 info_ = std::move(provisional_host->info_); | 782 info_ = std::move(provisional_host->info_); |
610 | 783 |
611 // Take the connection over from the provisional host. | 784 // Take the connection over from the provisional host. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // Increase the references because the process which this provider host will | 825 // Increase the references because the process which this provider host will |
653 // host has been decided. | 826 // host has been decided. |
654 for (const GURL& pattern : associated_patterns_) | 827 for (const GURL& pattern : associated_patterns_) |
655 IncreaseProcessReference(pattern); | 828 IncreaseProcessReference(pattern); |
656 for (auto& key_registration : matching_registrations_) | 829 for (auto& key_registration : matching_registrations_) |
657 IncreaseProcessReference(key_registration.second->pattern()); | 830 IncreaseProcessReference(key_registration.second->pattern()); |
658 | 831 |
659 NotifyControllerToAssociatedProvider(); | 832 NotifyControllerToAssociatedProvider(); |
660 } | 833 } |
661 | 834 |
| 835 void ServiceWorkerProviderHost::CompleteStartWorkerPreparation( |
| 836 int process_id, |
| 837 mojom::ServiceWorkerProviderClientInfoPtr* out_provider_client_info) { |
| 838 DCHECK(context_); |
| 839 |
| 840 DCHECK_EQ(kInvalidEmbeddedWorkerThreadId, render_thread_id_); |
| 841 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 842 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type()); |
| 843 DCHECK(running_hosted_version_); |
| 844 |
| 845 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); |
| 846 |
| 847 ServiceWorkerDispatcherHost* dispatcher_host = |
| 848 context_->GetDispatcherHost(process_id); |
| 849 DCHECK(dispatcher_host); |
| 850 render_process_id_ = process_id; |
| 851 dispatcher_host_ = dispatcher_host; |
| 852 |
| 853 // Retrieve the registration associated with |version|. The registration |
| 854 // must be alive because the version keeps it during starting worker. |
| 855 ServiceWorkerRegistration* registration = context_->GetLiveRegistration( |
| 856 running_hosted_version()->registration_id()); |
| 857 DCHECK(registration); |
| 858 ServiceWorkerRegistrationObjectInfo info; |
| 859 ServiceWorkerVersionAttributes attrs; |
| 860 dispatcher_host->GetRegistrationObjectInfoAndVersionAttributes( |
| 861 AsWeakPtr(), registration, &info, &attrs); |
| 862 |
| 863 // Initialize provider_client_info. |
| 864 (*out_provider_client_info)->provider_id = provider_id(); |
| 865 (*out_provider_client_info)->type = provider_type(); |
| 866 (*out_provider_client_info)->attributes = std::move(attrs); |
| 867 (*out_provider_client_info)->registration = std::move(info); |
| 868 (*out_provider_client_info)->is_parent_frame_secure = |
| 869 is_parent_frame_secure(); |
| 870 (*out_provider_client_info)->client_request = mojo::MakeRequest(&provider_); |
| 871 |
| 872 mojom::URLLoaderFactoryAssociatedPtr loader_factory_ptr; |
| 873 if (ServiceWorkerUtils::IsServicificationEnabled()) { |
| 874 mojo::MakeStrongAssociatedBinding( |
| 875 base::MakeUnique<ScriptURLLoaderFactory>( |
| 876 context_, AsWeakPtr(), context_->blob_storage_context(), |
| 877 context_->loader_factory_getter()), |
| 878 mojo::MakeRequest(&loader_factory_ptr)); |
| 879 (*out_provider_client_info)->script_loader_factory_ptr_info = |
| 880 loader_factory_ptr.PassInterface(); |
| 881 } |
| 882 |
| 883 auto* host_ptr_info_ptr = &(*out_provider_client_info)->host_ptr_info; |
| 884 binding_.Bind(mojo::MakeRequest(host_ptr_info_ptr)); |
| 885 binding_.set_connection_error_handler( |
| 886 base::Bind(&RemoveProviderHost, context_, process_id, provider_id())); |
| 887 |
| 888 // Set the document URL to the script url in order to allow |
| 889 // register/unregister/getRegistration on ServiceWorkerGlobalScope. |
| 890 SetDocumentUrl(running_hosted_version()->script_url()); |
| 891 } |
| 892 |
662 void ServiceWorkerProviderHost::SendUpdateFoundMessage( | 893 void ServiceWorkerProviderHost::SendUpdateFoundMessage( |
663 int registration_handle_id) { | 894 int registration_handle_id) { |
664 if (!dispatcher_host_) | 895 if (!dispatcher_host_) |
665 return; // Could be nullptr in some tests. | 896 return; // Could be nullptr in some tests. |
666 | 897 |
667 if (!IsReadyToSendMessages()) { | 898 if (!IsReadyToSendMessages()) { |
668 queued_events_.push_back( | 899 queued_events_.push_back( |
669 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, | 900 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, |
670 AsWeakPtr(), registration_handle_id)); | 901 AsWeakPtr(), registration_handle_id)); |
671 return; | 902 return; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 render_thread_id_, provider_id(), | 1062 render_thread_id_, provider_id(), |
832 GetOrCreateServiceWorkerHandle( | 1063 GetOrCreateServiceWorkerHandle( |
833 associated_registration_->active_version()), | 1064 associated_registration_->active_version()), |
834 false /* shouldNotifyControllerChange */, | 1065 false /* shouldNotifyControllerChange */, |
835 associated_registration_->active_version()->used_features())); | 1066 associated_registration_->active_version()->used_features())); |
836 } | 1067 } |
837 } | 1068 } |
838 } | 1069 } |
839 | 1070 |
840 } // namespace content | 1071 } // namespace content |
OLD | NEW |