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

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

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Remove a break line 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.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
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 84 enum class FrameSecurityLevel { INSECURE, SECURE };
horo 2017/02/08 02:14:11 you can remove this.
shimazu 2017/02/13 03:25:56 Done.
77 // MSG_ROUTING_NONE. When this provider host is for a Document, 85
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(); 86 virtual ~ServiceWorkerProviderHost();
91 87
92 const std::string& client_uuid() const { return client_uuid_; } 88 const std::string& client_uuid() const { return client_uuid_; }
93 int process_id() const { return render_process_id_; } 89 int process_id() const { return render_process_id_; }
94 int provider_id() const { return provider_id_; } 90 int provider_id() const { return provider_id_; }
95 int frame_id() const; 91 int frame_id() const;
96 int route_id() const { return route_id_; } 92 int route_id() const { return route_id_; }
97 const WebContentsGetter& web_contents_getter() const { 93 const WebContentsGetter& web_contents_getter() const {
98 return web_contents_getter_; 94 return web_contents_getter_;
99 } 95 }
100 96
101 bool is_parent_frame_secure() const { 97 bool is_parent_frame_secure() const {
102 return parent_frame_security_level_ == FrameSecurityLevel::SECURE; 98 return parent_frame_security_level_ == FrameSecurityLevel::SECURE;
103 } 99 }
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 100
111 // Returns whether this provider host is secure enough to have a service 101 // Returns whether this provider host is secure enough to have a service
112 // worker controller. 102 // worker controller.
113 // Analogous to Blink's Document::isSecureContext. Because of how service 103 // Analogous to Blink's Document::isSecureContext. Because of how service
114 // worker intercepts main resource requests, this check must be done 104 // worker intercepts main resource requests, this check must be done
115 // browser-side once the URL is known (see comments in 105 // browser-side once the URL is known (see comments in
116 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses 106 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses
117 // |document_url_| and |is_parent_frame_secure_| to determine context 107 // |document_url_| and |is_parent_frame_secure_| to determine context
118 // security, so they must be set properly before calling this function. 108 // security, so they must be set properly before calling this function.
119 bool IsContextSecureForServiceWorker() const; 109 bool IsContextSecureForServiceWorker() const;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 230
241 // |registration| claims the document to be controlled. 231 // |registration| claims the document to be controlled.
242 void ClaimedByRegistration(ServiceWorkerRegistration* registration); 232 void ClaimedByRegistration(ServiceWorkerRegistration* registration);
243 233
244 // Called by dispatcher host to get the registration for the "ready" property. 234 // 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. 235 // 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 236 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator- service-worker-ready
247 bool GetRegistrationForReady(const GetRegistrationForReadyCallback& callback); 237 bool GetRegistrationForReady(const GetRegistrationForReadyCallback& callback);
248 238
249 // Methods to support cross site navigations. 239 // Methods to support cross site navigations.
250 void PrepareForCrossSiteTransfer(); 240 std::unique_ptr<ServiceWorkerProviderHost> PrepareForCrossSiteTransfer();
251 void CompleteCrossSiteTransfer( 241 void CompleteCrossSiteTransfer(
252 int new_process_id, 242 int new_process_id,
253 int new_frame_id, 243 int new_frame_id,
254 int new_provider_id, 244 int new_provider_id,
255 ServiceWorkerProviderType new_provider_type, 245 ServiceWorkerProviderType new_provider_type,
256 ServiceWorkerDispatcherHost* dispatcher_host); 246 ServiceWorkerDispatcherHost* dispatcher_host);
257 ServiceWorkerDispatcherHost* dispatcher_host() const { 247 ServiceWorkerDispatcherHost* dispatcher_host() const {
258 return dispatcher_host_; 248 return dispatcher_host_;
259 } 249 }
260 250
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 307
318 struct OneShotGetReadyCallback { 308 struct OneShotGetReadyCallback {
319 GetRegistrationForReadyCallback callback; 309 GetRegistrationForReadyCallback callback;
320 bool called; 310 bool called;
321 311
322 explicit OneShotGetReadyCallback( 312 explicit OneShotGetReadyCallback(
323 const GetRegistrationForReadyCallback& callback); 313 const GetRegistrationForReadyCallback& callback);
324 ~OneShotGetReadyCallback(); 314 ~OneShotGetReadyCallback();
325 }; 315 };
326 316
317 ServiceWorkerProviderHost(int render_process_id,
318 int route_id,
319 int provider_id,
320 ServiceWorkerProviderType provider_type,
321 FrameSecurityLevel parent_frame_security_level,
322 base::WeakPtr<ServiceWorkerContextCore> context,
323 ServiceWorkerDispatcherHost* dispatcher_host);
324
327 // ServiceWorkerRegistration::Listener overrides. 325 // ServiceWorkerRegistration::Listener overrides.
328 void OnVersionAttributesChanged( 326 void OnVersionAttributesChanged(
329 ServiceWorkerRegistration* registration, 327 ServiceWorkerRegistration* registration,
330 ChangedVersionAttributesMask changed_mask, 328 ChangedVersionAttributesMask changed_mask,
331 const ServiceWorkerRegistrationInfo& info) override; 329 const ServiceWorkerRegistrationInfo& info) override;
332 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; 330 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override;
333 void OnRegistrationFinishedUninstalling( 331 void OnRegistrationFinishedUninstalling(
334 ServiceWorkerRegistration* registration) override; 332 ServiceWorkerRegistration* registration) override;
335 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; 333 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override;
336 334
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 374
377 // Unique within the renderer process. 375 // Unique within the renderer process.
378 int provider_id_; 376 int provider_id_;
379 377
380 // PlzNavigate 378 // PlzNavigate
381 // Only set when this object is pre-created for a navigation. It indicates the 379 // Only set when this object is pre-created for a navigation. It indicates the
382 // tab where the navigation occurs. 380 // tab where the navigation occurs.
383 WebContentsGetter web_contents_getter_; 381 WebContentsGetter web_contents_getter_;
384 382
385 ServiceWorkerProviderType provider_type_; 383 ServiceWorkerProviderType provider_type_;
386 FrameSecurityLevel parent_frame_security_level_; 384 const FrameSecurityLevel parent_frame_security_level_;
horo 2017/02/08 02:14:11 "const bool is_parent_frame_secure;" is enough?
shimazu 2017/02/13 03:25:56 Done.
387 GURL document_url_; 385 GURL document_url_;
388 GURL topmost_frame_url_; 386 GURL topmost_frame_url_;
389 387
390 std::vector<GURL> associated_patterns_; 388 std::vector<GURL> associated_patterns_;
391 scoped_refptr<ServiceWorkerRegistration> associated_registration_; 389 scoped_refptr<ServiceWorkerRegistration> associated_registration_;
392 390
393 // Keyed by registration scope URL length. 391 // Keyed by registration scope URL length.
394 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> 392 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>>
395 ServiceWorkerRegistrationMap; 393 ServiceWorkerRegistrationMap;
396 // Contains all living registrations whose pattern this document's URL 394 // Contains all living registrations whose pattern this document's URL
397 // starts with. It is empty if IsContextSecureForServiceWorker() is 395 // starts with. It is empty if IsContextSecureForServiceWorker() is
398 // false. 396 // false.
399 ServiceWorkerRegistrationMap matching_registrations_; 397 ServiceWorkerRegistrationMap matching_registrations_;
400 398
401 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; 399 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_;
402 scoped_refptr<ServiceWorkerVersion> controlling_version_; 400 scoped_refptr<ServiceWorkerVersion> controlling_version_;
403 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 401 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
404 base::WeakPtr<ServiceWorkerContextCore> context_; 402 base::WeakPtr<ServiceWorkerContextCore> context_;
405 ServiceWorkerDispatcherHost* dispatcher_host_; 403 ServiceWorkerDispatcherHost* dispatcher_host_;
406 bool allow_association_; 404 bool allow_association_;
407 405
408 std::vector<base::Closure> queued_events_; 406 std::vector<base::Closure> queued_events_;
409 407
410 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 408 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
411 }; 409 };
412 410
413 } // namespace content 411 } // namespace content
414 412
415 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 413 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698