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 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 #include <unordered_map> | 15 #include <unordered_map> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "content/browser/service_worker/service_worker_registration.h" | 22 #include "content/browser/service_worker/service_worker_registration.h" |
23 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
24 #include "content/common/service_worker/service_worker_provider_host_info.h" | 24 #include "content/common/service_worker/service_worker_provider_host_info.h" |
25 #include "content/common/service_worker/service_worker_provider_interfaces.mojom .h" | |
25 #include "content/common/service_worker/service_worker_types.h" | 26 #include "content/common/service_worker/service_worker_types.h" |
26 #include "content/common/worker_url_loader_factory_provider.mojom.h" | 27 #include "content/common/worker_url_loader_factory_provider.mojom.h" |
27 #include "content/public/common/request_context_frame_type.h" | 28 #include "content/public/common/request_context_frame_type.h" |
28 #include "content/public/common/request_context_type.h" | 29 #include "content/public/common/request_context_type.h" |
29 #include "content/public/common/resource_type.h" | 30 #include "content/public/common/resource_type.h" |
31 #include "mojo/public/cpp/bindings/associated_binding.h" | |
30 | 32 |
31 namespace storage { | 33 namespace storage { |
32 class BlobStorageContext; | 34 class BlobStorageContext; |
33 } | 35 } |
34 | 36 |
35 namespace content { | 37 namespace content { |
36 | 38 |
37 class MessagePort; | 39 class MessagePort; |
38 class ResourceRequestBodyImpl; | 40 class ResourceRequestBodyImpl; |
39 class ServiceWorkerContextCore; | 41 class ServiceWorkerContextCore; |
40 class ServiceWorkerDispatcherHost; | 42 class ServiceWorkerDispatcherHost; |
41 class ServiceWorkerRequestHandler; | 43 class ServiceWorkerRequestHandler; |
42 class ServiceWorkerVersion; | 44 class ServiceWorkerVersion; |
43 class WebContents; | 45 class WebContents; |
44 | 46 |
45 // This class is the browser-process representation of a service worker | 47 // This class is the browser-process representation of a service worker |
46 // provider. There are two general types of providers: 1) those for a client | 48 // provider. There are two general types of providers: 1) those for a client |
47 // (windows, dedicated workers, or shared workers), and 2) those for hosting a | 49 // (windows, dedicated workers, or shared workers), and 2) those for hosting a |
48 // running service worker. | 50 // running service worker. |
49 // | 51 // |
50 // 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 |
51 // 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 |
52 // 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 |
53 // to an individual document or a worker. | 55 // to an individual document or a worker. |
54 // | 56 // |
55 // For providers hosting a running service worker, this class will observe | 57 // For providers hosting a running service worker, this class will observe |
56 // resource loads made directly by the service worker. | 58 // resource loads made directly by the service worker. |
59 // | |
60 // This instance is created when navigation is started and | |
falken
2017/05/30 04:12:31
s/This instance/A ServiceWorkerProviderHost instan
shimazu
2017/06/01 08:18:54
Addressed this at https://chromium-review.googleso
| |
61 // ServiceWorkerNetworkProvider is create on the renderer process. Mojo's | |
falken
2017/05/30 04:12:32
s/create/created
shimazu
2017/06/01 08:18:54
Addressed this at https://chromium-review.googleso
| |
62 // connection from ServiceWorkerNetworkProvider is established on the creation | |
63 // time, and the instance is destroyed on disconnection from the renderer side. | |
64 // If PlzNavigate is turned on, this instance is pre-created on the browser | |
falken
2017/05/30 04:12:32
s/this instance/an instance
shimazu
2017/06/01 08:18:54
Addressed this at https://chromium-review.googleso
| |
65 // before ServiceWorkerNetworkProvider is created on the renderer because | |
66 // navigation is possible to be initiated on the browser side. In that case, | |
falken
2017/05/30 04:12:32
s/is possible to be/is/
shimazu
2017/06/01 08:18:54
Addressed this at https://chromium-review.googleso
| |
67 // establishment of Mojo's connection will be deferred until | |
68 // ServiceWorkerNetworkProvider is created on the renderer. | |
falken
2017/05/30 04:12:31
Thanks for the comment!
shimazu
2017/06/01 08:18:54
Your welcome!:)
| |
57 class CONTENT_EXPORT ServiceWorkerProviderHost | 69 class CONTENT_EXPORT ServiceWorkerProviderHost |
58 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 70 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
59 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 71 public base::SupportsWeakPtr<ServiceWorkerProviderHost>, |
72 public NON_EXPORTED_BASE(mojom::ServiceWorkerProviderHost) { | |
60 public: | 73 public: |
61 using GetRegistrationForReadyCallback = | 74 using GetRegistrationForReadyCallback = |
62 base::Callback<void(ServiceWorkerRegistration* reigstration)>; | 75 base::Callback<void(ServiceWorkerRegistration* reigstration)>; |
63 | 76 |
64 using WebContentsGetter = base::Callback<WebContents*(void)>; | 77 using WebContentsGetter = base::Callback<WebContents*(void)>; |
65 | 78 |
66 // PlzNavigate | 79 // PlzNavigate |
67 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The | 80 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The |
68 // ServiceWorkerNetworkProvider will later be created in the renderer, should | 81 // ServiceWorkerNetworkProvider will later be created in the renderer, should |
69 // the navigation succeed. |is_parent_frame_is_secure| should be true for main | 82 // the navigation succeed. |is_parent_frame_is_secure| should be true for main |
70 // frames. Otherwise it is true iff all ancestor frames of this frame have a | 83 // frames. Otherwise it is true iff all ancestor frames of this frame have a |
71 // secure origin. |web_contents_getter| indicates the tab where the navigation | 84 // secure origin. |web_contents_getter| indicates the tab where the navigation |
72 // is occurring. | 85 // is occurring. |
73 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( | 86 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( |
74 base::WeakPtr<ServiceWorkerContextCore> context, | 87 base::WeakPtr<ServiceWorkerContextCore> context, |
75 bool are_ancestors_secure, | 88 bool are_ancestors_secure, |
76 const WebContentsGetter& web_contents_getter); | 89 const WebContentsGetter& web_contents_getter); |
77 | 90 |
78 // Used to create a ServiceWorkerProviderHost when the renderer-side provider | 91 // Used to create a ServiceWorkerProviderHost when the renderer-side provider |
79 // is created. This ProviderHost will be created for the process specified by | 92 // is created. This ProviderHost will be created for the process specified by |
80 // |process_id|. | 93 // |process_id|. |
81 static std::unique_ptr<ServiceWorkerProviderHost> Create( | 94 static std::unique_ptr<ServiceWorkerProviderHost> Create( |
82 int process_id, | 95 int process_id, |
83 ServiceWorkerProviderHostInfo info, | 96 ServiceWorkerProviderHostInfo info, |
84 base::WeakPtr<ServiceWorkerContextCore> context, | 97 base::WeakPtr<ServiceWorkerContextCore> context, |
85 ServiceWorkerDispatcherHost* dispatcher_host); | 98 ServiceWorkerDispatcherHost* dispatcher_host); |
86 | 99 |
87 virtual ~ServiceWorkerProviderHost(); | 100 ~ServiceWorkerProviderHost() override; |
88 | 101 |
89 const std::string& client_uuid() const { return client_uuid_; } | 102 const std::string& client_uuid() const { return client_uuid_; } |
90 int process_id() const { return render_process_id_; } | 103 int process_id() const { return render_process_id_; } |
91 int provider_id() const { return info_.provider_id; } | 104 int provider_id() const { return info_.provider_id; } |
92 int frame_id() const; | 105 int frame_id() const; |
93 int route_id() const { return info_.route_id; } | 106 int route_id() const { return info_.route_id; } |
94 const WebContentsGetter& web_contents_getter() const { | 107 const WebContentsGetter& web_contents_getter() const { |
95 return web_contents_getter_; | 108 return web_contents_getter_; |
96 } | 109 } |
97 | 110 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer(); | 256 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer(); |
244 void CompleteCrossSiteTransfer(ServiceWorkerProviderHost* provisional_host); | 257 void CompleteCrossSiteTransfer(ServiceWorkerProviderHost* provisional_host); |
245 ServiceWorkerDispatcherHost* dispatcher_host() const { | 258 ServiceWorkerDispatcherHost* dispatcher_host() const { |
246 return dispatcher_host_; | 259 return dispatcher_host_; |
247 } | 260 } |
248 | 261 |
249 // PlzNavigate | 262 // PlzNavigate |
250 // Completes initialization of provider hosts used for navigation requests. | 263 // Completes initialization of provider hosts used for navigation requests. |
251 void CompleteNavigationInitialized( | 264 void CompleteNavigationInitialized( |
252 int process_id, | 265 int process_id, |
253 int frame_routing_id, | 266 ServiceWorkerProviderHostInfo info, |
254 ServiceWorkerDispatcherHost* dispatcher_host); | 267 ServiceWorkerDispatcherHost* dispatcher_host); |
255 | 268 |
256 // Sends event messages to the renderer. Events for the worker are queued up | 269 // Sends event messages to the renderer. Events for the worker are queued up |
257 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 270 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
258 void SendUpdateFoundMessage( | 271 void SendUpdateFoundMessage( |
259 int registration_handle_id); | 272 int registration_handle_id); |
260 void SendSetVersionAttributesMessage( | 273 void SendSetVersionAttributesMessage( |
261 int registration_handle_id, | 274 int registration_handle_id, |
262 ChangedVersionAttributesMask changed_mask, | 275 ChangedVersionAttributesMask changed_mask, |
263 ServiceWorkerVersion* installing_version, | 276 ServiceWorkerVersion* installing_version, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 324 |
312 struct OneShotGetReadyCallback { | 325 struct OneShotGetReadyCallback { |
313 GetRegistrationForReadyCallback callback; | 326 GetRegistrationForReadyCallback callback; |
314 bool called; | 327 bool called; |
315 | 328 |
316 explicit OneShotGetReadyCallback( | 329 explicit OneShotGetReadyCallback( |
317 const GetRegistrationForReadyCallback& callback); | 330 const GetRegistrationForReadyCallback& callback); |
318 ~OneShotGetReadyCallback(); | 331 ~OneShotGetReadyCallback(); |
319 }; | 332 }; |
320 | 333 |
321 ServiceWorkerProviderHost(int render_process_id, | 334 ServiceWorkerProviderHost(int process_id, |
322 ServiceWorkerProviderHostInfo info, | 335 ServiceWorkerProviderHostInfo info, |
323 base::WeakPtr<ServiceWorkerContextCore> context, | 336 base::WeakPtr<ServiceWorkerContextCore> context, |
324 ServiceWorkerDispatcherHost* dispatcher_host); | 337 ServiceWorkerDispatcherHost* dispatcher_host); |
325 | 338 |
326 // ServiceWorkerRegistration::Listener overrides. | 339 // ServiceWorkerRegistration::Listener overrides. |
327 void OnVersionAttributesChanged( | 340 void OnVersionAttributesChanged( |
328 ServiceWorkerRegistration* registration, | 341 ServiceWorkerRegistration* registration, |
329 ChangedVersionAttributesMask changed_mask, | 342 ChangedVersionAttributesMask changed_mask, |
330 const ServiceWorkerRegistrationInfo& info) override; | 343 const ServiceWorkerRegistrationInfo& info) override; |
331 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 344 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 // false. | 409 // false. |
397 ServiceWorkerRegistrationMap matching_registrations_; | 410 ServiceWorkerRegistrationMap matching_registrations_; |
398 | 411 |
399 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; | 412 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; |
400 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 413 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
401 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 414 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
402 base::WeakPtr<ServiceWorkerContextCore> context_; | 415 base::WeakPtr<ServiceWorkerContextCore> context_; |
403 ServiceWorkerDispatcherHost* dispatcher_host_; | 416 ServiceWorkerDispatcherHost* dispatcher_host_; |
404 bool allow_association_; | 417 bool allow_association_; |
405 | 418 |
419 // |provider_| is the renderer-side Mojo endpoint for provider. | |
420 mojom::ServiceWorkerProviderAssociatedPtr provider_; | |
421 // |binding_| is the Mojo binding that keeps the connection to the | |
422 // renderer-side counterpart (content::ServiceWorkerNetworkProvider). When the | |
423 // connection bound on |binding_| gets killed from the renderer side, this | |
424 // content::ServiceWorkerProviderHost will be destroyed. | |
425 mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_; | |
426 | |
406 std::vector<base::Closure> queued_events_; | 427 std::vector<base::Closure> queued_events_; |
407 | 428 |
408 // Keeps ServiceWorkerWorkerClient pointers of dedicated or shared workers | 429 // Keeps ServiceWorkerWorkerClient pointers of dedicated or shared workers |
409 // which are associated with the ServiceWorkerProviderHost. | 430 // which are associated with the ServiceWorkerProviderHost. |
410 std::unordered_map<mojom::ServiceWorkerWorkerClient*, | 431 std::unordered_map<mojom::ServiceWorkerWorkerClient*, |
411 mojom::ServiceWorkerWorkerClientAssociatedPtr> | 432 mojom::ServiceWorkerWorkerClientAssociatedPtr> |
412 worker_clients_; | 433 worker_clients_; |
413 | 434 |
414 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 435 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
415 }; | 436 }; |
416 | 437 |
417 } // namespace content | 438 } // namespace content |
418 | 439 |
419 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 440 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |