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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // running service worker. | 50 // running service worker. |
51 // | 51 // |
52 // For client providers, there is a provider per document or a worker and the | 52 // For client providers, there is a provider per document or a worker and the |
53 // lifetime of this object is tied to the lifetime of its document or the worker | 53 // lifetime of this object is tied to the lifetime of its document or the worker |
54 // in the renderer process. This class holds service worker state that is scoped | 54 // in the renderer process. This class holds service worker state that is scoped |
55 // to an individual document or a worker. | 55 // to an individual document or a worker. |
56 // | 56 // |
57 // For providers hosting a running service worker, this class will observe | 57 // For providers hosting a running service worker, this class will observe |
58 // resource loads made directly by the service worker. | 58 // resource loads made directly by the service worker. |
59 // | 59 // |
60 // A ServiceWorkerProviderHost instance is created when a | 60 // A ServiceWorkerProviderHost instance is possible to be created on the browser |
61 // ServiceWorkerNetworkProvider is created on the renderer process, which | 61 // and the renderer. 1) When it's for a document or worker (i.e., a service |
62 // happens 1) when a document or worker (i.e., a service worker client) is | 62 // worker client), the provider host is created when |
63 // created, or 2) during service worker startup. Mojo's connection from | 63 // ServiceWorkerNetworkProvider is created on the renderer process. Mojo's |
64 // ServiceWorkerNetworkProvider is established on the creation time, and the | 64 // connection from ServiceWorkerNetworkProvider is established on the creation |
65 // instance is destroyed on disconnection from the renderer side. | 65 // time. |
66 // If PlzNavigate is turned on, an instance is pre-created on the browser | 66 // 2) When it's for a service worker context, the provider host is created on |
| 67 // the browser process before launching the service worker's thread. Mojo's |
| 68 // connection to the renderer is established with the StartWorker message. |
| 69 // 3) When PlzNavigate is turned on, an instance is pre-created on the browser |
67 // before ServiceWorkerNetworkProvider is created on the renderer because | 70 // before ServiceWorkerNetworkProvider is created on the renderer because |
68 // navigation is initiated on the browser side. In that case, establishment of | 71 // navigation is initiated on the browser side. In that case, establishment of |
69 // Mojo's connection will be deferred until ServiceWorkerNetworkProvider is | 72 // Mojo's connection will be deferred until ServiceWorkerNetworkProvider is |
70 // created on the renderer. | 73 // created on the renderer. |
| 74 // Destruction of the ServiceWorkerProviderHost instance happens on |
| 75 // disconnection of the Mojo's pipe from the renderer side regardless of what |
| 76 // the provider is for. |
71 class CONTENT_EXPORT ServiceWorkerProviderHost | 77 class CONTENT_EXPORT ServiceWorkerProviderHost |
72 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 78 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
73 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, | 79 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, |
74 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { | 80 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { |
75 public: | 81 public: |
76 using GetRegistrationForReadyCallback = | 82 using GetRegistrationForReadyCallback = |
77 base::Callback<void(ServiceWorkerRegistration* reigstration)>; | 83 base::Callback<void(ServiceWorkerRegistration* reigstration)>; |
78 | 84 |
79 using WebContentsGetter = base::Callback<WebContents*(void)>; | 85 using WebContentsGetter = base::Callback<WebContents*(void)>; |
80 | 86 |
81 // PlzNavigate | 87 // PlzNavigate |
82 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The | 88 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The |
83 // ServiceWorkerNetworkProvider will later be created in the renderer, should | 89 // ServiceWorkerNetworkProvider will later be created in the renderer, should |
84 // the navigation succeed. |is_parent_frame_is_secure| should be true for main | 90 // the navigation succeed. |is_parent_frame_is_secure| should be true for main |
85 // frames. Otherwise it is true iff all ancestor frames of this frame have a | 91 // frames. Otherwise it is true iff all ancestor frames of this frame have a |
86 // secure origin. |web_contents_getter| indicates the tab where the navigation | 92 // secure origin. |web_contents_getter| indicates the tab where the navigation |
87 // is occurring. | 93 // is occurring. |
88 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( | 94 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( |
89 base::WeakPtr<ServiceWorkerContextCore> context, | 95 base::WeakPtr<ServiceWorkerContextCore> context, |
90 bool are_ancestors_secure, | 96 bool are_ancestors_secure, |
91 const WebContentsGetter& web_contents_getter); | 97 const WebContentsGetter& web_contents_getter); |
92 | 98 |
| 99 // Creates ServiceWorkerProviderHost for the worker's context. Information |
| 100 // about the ServiceWorkerProviderHost is passed with the StartWorker message. |
| 101 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateForWorkerContext( |
| 102 ServiceWorkerVersion* hosted_version, |
| 103 base::WeakPtr<ServiceWorkerContextCore> context); |
| 104 |
93 // Used to create a ServiceWorkerProviderHost when the renderer-side provider | 105 // Used to create a ServiceWorkerProviderHost when the renderer-side provider |
94 // is created. This ProviderHost will be created for the process specified by | 106 // is created. This ProviderHost will be created for the process specified by |
95 // |process_id|. | 107 // |process_id|. |
96 static std::unique_ptr<ServiceWorkerProviderHost> Create( | 108 static std::unique_ptr<ServiceWorkerProviderHost> Create( |
97 int process_id, | 109 int process_id, |
98 ServiceWorkerProviderHostInfo info, | 110 ServiceWorkerProviderHostInfo info, |
99 base::WeakPtr<ServiceWorkerContextCore> context, | 111 base::WeakPtr<ServiceWorkerContextCore> context, |
100 ServiceWorkerDispatcherHost* dispatcher_host); | 112 ServiceWorkerDispatcherHost* dispatcher_host); |
101 | 113 |
102 ~ServiceWorkerProviderHost() override; | 114 ~ServiceWorkerProviderHost() override; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 203 |
192 // Associates to |registration| to listen for its version change events and | 204 // Associates to |registration| to listen for its version change events and |
193 // sets the controller. If |notify_controllerchange| is true, instructs the | 205 // sets the controller. If |notify_controllerchange| is true, instructs the |
194 // renderer to dispatch a 'controllerchange' event. | 206 // renderer to dispatch a 'controllerchange' event. |
195 void AssociateRegistration(ServiceWorkerRegistration* registration, | 207 void AssociateRegistration(ServiceWorkerRegistration* registration, |
196 bool notify_controllerchange); | 208 bool notify_controllerchange); |
197 | 209 |
198 // Clears the associated registration and stop listening to it. | 210 // Clears the associated registration and stop listening to it. |
199 void DisassociateRegistration(); | 211 void DisassociateRegistration(); |
200 | 212 |
201 void SetHostedVersion(ServiceWorkerVersion* version); | |
202 | |
203 // Returns a handler for a request, the handler may return NULL if | 213 // Returns a handler for a request, the handler may return NULL if |
204 // the request doesn't require special handling. | 214 // the request doesn't require special handling. |
205 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( | 215 std::unique_ptr<ServiceWorkerRequestHandler> CreateRequestHandler( |
206 FetchRequestMode request_mode, | 216 FetchRequestMode request_mode, |
207 FetchCredentialsMode credentials_mode, | 217 FetchCredentialsMode credentials_mode, |
208 FetchRedirectMode redirect_mode, | 218 FetchRedirectMode redirect_mode, |
209 ResourceType resource_type, | 219 ResourceType resource_type, |
210 RequestContextType request_context_type, | 220 RequestContextType request_context_type, |
211 RequestContextFrameType frame_type, | 221 RequestContextFrameType frame_type, |
212 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 222 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 return dispatcher_host_; | 271 return dispatcher_host_; |
262 } | 272 } |
263 | 273 |
264 // PlzNavigate | 274 // PlzNavigate |
265 // Completes initialization of provider hosts used for navigation requests. | 275 // Completes initialization of provider hosts used for navigation requests. |
266 void CompleteNavigationInitialized( | 276 void CompleteNavigationInitialized( |
267 int process_id, | 277 int process_id, |
268 ServiceWorkerProviderHostInfo info, | 278 ServiceWorkerProviderHostInfo info, |
269 ServiceWorkerDispatcherHost* dispatcher_host); | 279 ServiceWorkerDispatcherHost* dispatcher_host); |
270 | 280 |
| 281 // Completes initialization of provider hosts for controllers. |
| 282 virtual void CompleteStartWorkerPreparation( |
| 283 int process_id, |
| 284 mojom::ServiceWorkerProviderClientInfoPtr* provider_client_info); |
| 285 |
271 // Sends event messages to the renderer. Events for the worker are queued up | 286 // Sends event messages to the renderer. Events for the worker are queued up |
272 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 287 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
273 void SendUpdateFoundMessage( | 288 void SendUpdateFoundMessage( |
274 int registration_handle_id); | 289 int registration_handle_id); |
275 void SendSetVersionAttributesMessage( | 290 void SendSetVersionAttributesMessage( |
276 int registration_handle_id, | 291 int registration_handle_id, |
277 ChangedVersionAttributesMask changed_mask, | 292 ChangedVersionAttributesMask changed_mask, |
278 ServiceWorkerVersion* installing_version, | 293 ServiceWorkerVersion* installing_version, |
279 ServiceWorkerVersion* waiting_version, | 294 ServiceWorkerVersion* waiting_version, |
280 ServiceWorkerVersion* active_version); | 295 ServiceWorkerVersion* active_version); |
(...skipping 15 matching lines...) Expand all Loading... |
296 // exceptional condition like it could no longer be read from the script | 311 // exceptional condition like it could no longer be read from the script |
297 // cache. | 312 // cache. |
298 void NotifyControllerLost(); | 313 void NotifyControllerLost(); |
299 | 314 |
300 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to | 315 // Binds the ServiceWorkerWorkerClient of a dedicated (or shared) worker to |
301 // the parent frame's ServiceWorkerProviderHost. (This is used only when | 316 // the parent frame's ServiceWorkerProviderHost. (This is used only when |
302 // off-main-thread-fetch is enabled.) | 317 // off-main-thread-fetch is enabled.) |
303 void BindWorkerFetchContext( | 318 void BindWorkerFetchContext( |
304 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); | 319 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info); |
305 | 320 |
| 321 protected: |
| 322 ServiceWorkerProviderHost(int process_id, |
| 323 ServiceWorkerProviderHostInfo info, |
| 324 base::WeakPtr<ServiceWorkerContextCore> context, |
| 325 ServiceWorkerDispatcherHost* dispatcher_host); |
| 326 |
306 private: | 327 private: |
307 friend class ForeignFetchRequestHandlerTest; | 328 friend class ForeignFetchRequestHandlerTest; |
308 friend class LinkHeaderServiceWorkerTest; | 329 friend class LinkHeaderServiceWorkerTest; |
309 friend class ServiceWorkerProviderHostTest; | 330 friend class ServiceWorkerProviderHostTest; |
310 friend class ServiceWorkerWriteToCacheJobTest; | 331 friend class ServiceWorkerWriteToCacheJobTest; |
311 friend class ServiceWorkerContextRequestHandlerTest; | 332 friend class ServiceWorkerContextRequestHandlerTest; |
312 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); | 333 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript); |
313 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, | 334 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, |
314 Update_SameSizeScript); | 335 Update_SameSizeScript); |
315 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, | 336 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, |
(...skipping 10 matching lines...) Expand all Loading... |
326 | 347 |
327 struct OneShotGetReadyCallback { | 348 struct OneShotGetReadyCallback { |
328 GetRegistrationForReadyCallback callback; | 349 GetRegistrationForReadyCallback callback; |
329 bool called; | 350 bool called; |
330 | 351 |
331 explicit OneShotGetReadyCallback( | 352 explicit OneShotGetReadyCallback( |
332 const GetRegistrationForReadyCallback& callback); | 353 const GetRegistrationForReadyCallback& callback); |
333 ~OneShotGetReadyCallback(); | 354 ~OneShotGetReadyCallback(); |
334 }; | 355 }; |
335 | 356 |
336 ServiceWorkerProviderHost(int process_id, | |
337 ServiceWorkerProviderHostInfo info, | |
338 base::WeakPtr<ServiceWorkerContextCore> context, | |
339 ServiceWorkerDispatcherHost* dispatcher_host); | |
340 | |
341 // ServiceWorkerRegistration::Listener overrides. | 357 // ServiceWorkerRegistration::Listener overrides. |
342 void OnVersionAttributesChanged( | 358 void OnVersionAttributesChanged( |
343 ServiceWorkerRegistration* registration, | 359 ServiceWorkerRegistration* registration, |
344 ChangedVersionAttributesMask changed_mask, | 360 ChangedVersionAttributesMask changed_mask, |
345 const ServiceWorkerRegistrationInfo& info) override; | 361 const ServiceWorkerRegistrationInfo& info) override; |
346 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 362 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
347 void OnRegistrationFinishedUninstalling( | 363 void OnRegistrationFinishedUninstalling( |
348 ServiceWorkerRegistration* registration) override; | 364 ServiceWorkerRegistration* registration) override; |
349 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 365 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
350 | 366 |
(...skipping 13 matching lines...) Expand all Loading... |
364 | 380 |
365 // Increase/decrease this host's process reference for |pattern|. | 381 // Increase/decrease this host's process reference for |pattern|. |
366 void IncreaseProcessReference(const GURL& pattern); | 382 void IncreaseProcessReference(const GURL& pattern); |
367 void DecreaseProcessReference(const GURL& pattern); | 383 void DecreaseProcessReference(const GURL& pattern); |
368 | 384 |
369 void ReturnRegistrationForReadyIfNeeded(); | 385 void ReturnRegistrationForReadyIfNeeded(); |
370 | 386 |
371 bool IsReadyToSendMessages() const; | 387 bool IsReadyToSendMessages() const; |
372 void Send(IPC::Message* message) const; | 388 void Send(IPC::Message* message) const; |
373 | 389 |
| 390 // Sets the version hosted by this provider. This method should be used only |
| 391 // for provider hosts for controllers. |
| 392 void SetHostedVersion(ServiceWorkerVersion* version); |
| 393 |
374 // Finalizes cross-site transfers and navigation-initalized hosts. | 394 // Finalizes cross-site transfers and navigation-initalized hosts. |
375 void FinalizeInitialization(int process_id, | 395 void FinalizeInitialization(int process_id, |
376 ServiceWorkerDispatcherHost* dispatcher_host); | 396 ServiceWorkerDispatcherHost* dispatcher_host); |
377 | 397 |
378 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or | 398 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or |
379 // shared) worker, when the connection to the worker is disconnected. | 399 // shared) worker, when the connection to the worker is disconnected. |
380 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); | 400 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); |
381 | 401 |
382 std::string client_uuid_; | 402 std::string client_uuid_; |
383 int render_process_id_; | 403 int render_process_id_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 std::unordered_map<mojom::ServiceWorkerWorkerClient*, | 452 std::unordered_map<mojom::ServiceWorkerWorkerClient*, |
433 mojom::ServiceWorkerWorkerClientAssociatedPtr> | 453 mojom::ServiceWorkerWorkerClientAssociatedPtr> |
434 worker_clients_; | 454 worker_clients_; |
435 | 455 |
436 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 456 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
437 }; | 457 }; |
438 | 458 |
439 } // namespace content | 459 } // namespace content |
440 | 460 |
441 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 461 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |