Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.h

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

Powered by Google App Engine
This is Rietveld 408576698