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