| 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 <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "content/browser/service_worker/service_worker_registration.h" | 21 #include "content/browser/service_worker/service_worker_registration.h" |
| 22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 23 #include "content/common/service_worker/service_worker_provider.h" |
| 23 #include "content/common/service_worker/service_worker_types.h" | 24 #include "content/common/service_worker/service_worker_types.h" |
| 24 #include "content/public/common/request_context_frame_type.h" | 25 #include "content/public/common/request_context_frame_type.h" |
| 25 #include "content/public/common/request_context_type.h" | 26 #include "content/public/common/request_context_type.h" |
| 26 #include "content/public/common/resource_type.h" | 27 #include "content/public/common/resource_type.h" |
| 27 | 28 |
| 28 namespace storage { | 29 namespace storage { |
| 29 class BlobStorageContext; | 30 class BlobStorageContext; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // ServiceWorkerNetworkProvider will later be created in the renderer, should | 65 // ServiceWorkerNetworkProvider will later be created in the renderer, should |
| 65 // the navigation succeed. |is_parent_frame_is_secure| should be true for main | 66 // the navigation succeed. |is_parent_frame_is_secure| should be true for main |
| 66 // frames. Otherwise it is true iff all ancestor frames of this frame have a | 67 // frames. Otherwise it is true iff all ancestor frames of this frame have a |
| 67 // secure origin. |web_contents_getter| indicates the tab where the navigation | 68 // secure origin. |web_contents_getter| indicates the tab where the navigation |
| 68 // is occurring. | 69 // is occurring. |
| 69 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( | 70 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( |
| 70 base::WeakPtr<ServiceWorkerContextCore> context, | 71 base::WeakPtr<ServiceWorkerContextCore> context, |
| 71 bool are_ancestors_secure, | 72 bool are_ancestors_secure, |
| 72 const WebContentsGetter& web_contents_getter); | 73 const WebContentsGetter& web_contents_getter); |
| 73 | 74 |
| 74 enum class FrameSecurityLevel { UNINITIALIZED, INSECURE, SECURE }; | 75 // Used to create a ServiceWorkerProviderHost when the renderer-side provider |
| 76 // is created. This ProviderHost will be created for the process specified by |
| 77 // |process_id|. |
| 78 static std::unique_ptr<ServiceWorkerProviderHost> Create( |
| 79 int process_id, |
| 80 ServiceWorkerProviderHostInfo info, |
| 81 base::WeakPtr<ServiceWorkerContextCore> context, |
| 82 ServiceWorkerDispatcherHost* dispatcher_host); |
| 75 | 83 |
| 76 // When this provider host is for a Service Worker context, |route_id| is | |
| 77 // MSG_ROUTING_NONE. When this provider host is for a Document, | |
| 78 // |route_id| is the frame ID of the Document. When this provider host is for | |
| 79 // a Shared Worker, |route_id| is the Shared Worker route ID. | |
| 80 // |provider_type| gives additional information whether the provider is | |
| 81 // created for controller (ServiceWorker) or controllee (Document or | |
| 82 // SharedWorker). | |
| 83 ServiceWorkerProviderHost(int render_process_id, | |
| 84 int route_id, | |
| 85 int provider_id, | |
| 86 ServiceWorkerProviderType provider_type, | |
| 87 FrameSecurityLevel parent_frame_security_level, | |
| 88 base::WeakPtr<ServiceWorkerContextCore> context, | |
| 89 ServiceWorkerDispatcherHost* dispatcher_host); | |
| 90 virtual ~ServiceWorkerProviderHost(); | 84 virtual ~ServiceWorkerProviderHost(); |
| 91 | 85 |
| 92 const std::string& client_uuid() const { return client_uuid_; } | 86 const std::string& client_uuid() const { return client_uuid_; } |
| 93 int process_id() const { return render_process_id_; } | 87 int process_id() const { return render_process_id_; } |
| 94 int provider_id() const { return provider_id_; } | 88 int provider_id() const { return provider_id_; } |
| 95 int frame_id() const; | 89 int frame_id() const; |
| 96 int route_id() const { return route_id_; } | 90 int route_id() const { return route_id_; } |
| 97 const WebContentsGetter& web_contents_getter() const { | 91 const WebContentsGetter& web_contents_getter() const { |
| 98 return web_contents_getter_; | 92 return web_contents_getter_; |
| 99 } | 93 } |
| 100 | 94 |
| 101 bool is_parent_frame_secure() const { | 95 bool is_parent_frame_secure() const { return is_parent_frame_secure_; } |
| 102 return parent_frame_security_level_ == FrameSecurityLevel::SECURE; | |
| 103 } | |
| 104 void set_parent_frame_secure(bool is_parent_frame_secure) { | |
| 105 CHECK_EQ(parent_frame_security_level_, FrameSecurityLevel::UNINITIALIZED); | |
| 106 parent_frame_security_level_ = is_parent_frame_secure | |
| 107 ? FrameSecurityLevel::SECURE | |
| 108 : FrameSecurityLevel::INSECURE; | |
| 109 } | |
| 110 | 96 |
| 111 // Returns whether this provider host is secure enough to have a service | 97 // Returns whether this provider host is secure enough to have a service |
| 112 // worker controller. | 98 // worker controller. |
| 113 // Analogous to Blink's Document::isSecureContext. Because of how service | 99 // Analogous to Blink's Document::isSecureContext. Because of how service |
| 114 // worker intercepts main resource requests, this check must be done | 100 // worker intercepts main resource requests, this check must be done |
| 115 // browser-side once the URL is known (see comments in | 101 // browser-side once the URL is known (see comments in |
| 116 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses | 102 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses |
| 117 // |document_url_| and |is_parent_frame_secure_| to determine context | 103 // |document_url_| and |is_parent_frame_secure_| to determine context |
| 118 // security, so they must be set properly before calling this function. | 104 // security, so they must be set properly before calling this function. |
| 119 bool IsContextSecureForServiceWorker() const; | 105 bool IsContextSecureForServiceWorker() const; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 226 |
| 241 // |registration| claims the document to be controlled. | 227 // |registration| claims the document to be controlled. |
| 242 void ClaimedByRegistration(ServiceWorkerRegistration* registration); | 228 void ClaimedByRegistration(ServiceWorkerRegistration* registration); |
| 243 | 229 |
| 244 // Called by dispatcher host to get the registration for the "ready" property. | 230 // Called by dispatcher host to get the registration for the "ready" property. |
| 245 // Returns false if there's a completed or ongoing request for the document. | 231 // Returns false if there's a completed or ongoing request for the document. |
| 246 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-
service-worker-ready | 232 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-
service-worker-ready |
| 247 bool GetRegistrationForReady(const GetRegistrationForReadyCallback& callback); | 233 bool GetRegistrationForReady(const GetRegistrationForReadyCallback& callback); |
| 248 | 234 |
| 249 // Methods to support cross site navigations. | 235 // Methods to support cross site navigations. |
| 250 void PrepareForCrossSiteTransfer(); | 236 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer(); |
| 251 void CompleteCrossSiteTransfer( | 237 void CompleteCrossSiteTransfer( |
| 252 int new_process_id, | 238 int new_process_id, |
| 253 int new_frame_id, | 239 int new_frame_id, |
| 254 int new_provider_id, | 240 int new_provider_id, |
| 255 ServiceWorkerProviderType new_provider_type, | 241 ServiceWorkerProviderType new_provider_type, |
| 256 ServiceWorkerDispatcherHost* dispatcher_host); | 242 ServiceWorkerDispatcherHost* dispatcher_host); |
| 257 ServiceWorkerDispatcherHost* dispatcher_host() const { | 243 ServiceWorkerDispatcherHost* dispatcher_host() const { |
| 258 return dispatcher_host_; | 244 return dispatcher_host_; |
| 259 } | 245 } |
| 260 | 246 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 303 |
| 318 struct OneShotGetReadyCallback { | 304 struct OneShotGetReadyCallback { |
| 319 GetRegistrationForReadyCallback callback; | 305 GetRegistrationForReadyCallback callback; |
| 320 bool called; | 306 bool called; |
| 321 | 307 |
| 322 explicit OneShotGetReadyCallback( | 308 explicit OneShotGetReadyCallback( |
| 323 const GetRegistrationForReadyCallback& callback); | 309 const GetRegistrationForReadyCallback& callback); |
| 324 ~OneShotGetReadyCallback(); | 310 ~OneShotGetReadyCallback(); |
| 325 }; | 311 }; |
| 326 | 312 |
| 313 ServiceWorkerProviderHost(int render_process_id, |
| 314 int route_id, |
| 315 int provider_id, |
| 316 ServiceWorkerProviderType provider_type, |
| 317 bool is_parent_frame_secure, |
| 318 base::WeakPtr<ServiceWorkerContextCore> context, |
| 319 ServiceWorkerDispatcherHost* dispatcher_host); |
| 320 |
| 327 // ServiceWorkerRegistration::Listener overrides. | 321 // ServiceWorkerRegistration::Listener overrides. |
| 328 void OnVersionAttributesChanged( | 322 void OnVersionAttributesChanged( |
| 329 ServiceWorkerRegistration* registration, | 323 ServiceWorkerRegistration* registration, |
| 330 ChangedVersionAttributesMask changed_mask, | 324 ChangedVersionAttributesMask changed_mask, |
| 331 const ServiceWorkerRegistrationInfo& info) override; | 325 const ServiceWorkerRegistrationInfo& info) override; |
| 332 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 326 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
| 333 void OnRegistrationFinishedUninstalling( | 327 void OnRegistrationFinishedUninstalling( |
| 334 ServiceWorkerRegistration* registration) override; | 328 ServiceWorkerRegistration* registration) override; |
| 335 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 329 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
| 336 | 330 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 370 |
| 377 // Unique within the renderer process. | 371 // Unique within the renderer process. |
| 378 int provider_id_; | 372 int provider_id_; |
| 379 | 373 |
| 380 // PlzNavigate | 374 // PlzNavigate |
| 381 // Only set when this object is pre-created for a navigation. It indicates the | 375 // Only set when this object is pre-created for a navigation. It indicates the |
| 382 // tab where the navigation occurs. | 376 // tab where the navigation occurs. |
| 383 WebContentsGetter web_contents_getter_; | 377 WebContentsGetter web_contents_getter_; |
| 384 | 378 |
| 385 ServiceWorkerProviderType provider_type_; | 379 ServiceWorkerProviderType provider_type_; |
| 386 FrameSecurityLevel parent_frame_security_level_; | 380 const bool is_parent_frame_secure_; |
| 387 GURL document_url_; | 381 GURL document_url_; |
| 388 GURL topmost_frame_url_; | 382 GURL topmost_frame_url_; |
| 389 | 383 |
| 390 std::vector<GURL> associated_patterns_; | 384 std::vector<GURL> associated_patterns_; |
| 391 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 385 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
| 392 | 386 |
| 393 // Keyed by registration scope URL length. | 387 // Keyed by registration scope URL length. |
| 394 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> | 388 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> |
| 395 ServiceWorkerRegistrationMap; | 389 ServiceWorkerRegistrationMap; |
| 396 // Contains all living registrations whose pattern this document's URL | 390 // Contains all living registrations whose pattern this document's URL |
| 397 // starts with. It is empty if IsContextSecureForServiceWorker() is | 391 // starts with. It is empty if IsContextSecureForServiceWorker() is |
| 398 // false. | 392 // false. |
| 399 ServiceWorkerRegistrationMap matching_registrations_; | 393 ServiceWorkerRegistrationMap matching_registrations_; |
| 400 | 394 |
| 401 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; | 395 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; |
| 402 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 396 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
| 403 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 397 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
| 404 base::WeakPtr<ServiceWorkerContextCore> context_; | 398 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 405 ServiceWorkerDispatcherHost* dispatcher_host_; | 399 ServiceWorkerDispatcherHost* dispatcher_host_; |
| 406 bool allow_association_; | 400 bool allow_association_; |
| 407 | 401 |
| 408 std::vector<base::Closure> queued_events_; | 402 std::vector<base::Closure> queued_events_; |
| 409 | 403 |
| 410 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 404 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
| 411 }; | 405 }; |
| 412 | 406 |
| 413 } // namespace content | 407 } // namespace content |
| 414 | 408 |
| 415 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 409 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
| OLD | NEW |