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

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

Issue 2071433003: Reland: service worker: Don't control a subframe of an insecure context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised Created 4 years, 6 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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 using GetRegistrationForReadyCallback = 54 using GetRegistrationForReadyCallback =
55 base::Callback<void(ServiceWorkerRegistration* reigstration)>; 55 base::Callback<void(ServiceWorkerRegistration* reigstration)>;
56 56
57 // PlzNavigate 57 // PlzNavigate
58 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The 58 // Used to pre-create a ServiceWorkerProviderHost for a navigation. The
59 // ServiceWorkerNetworkProvider will later be created in the renderer, should 59 // ServiceWorkerNetworkProvider will later be created in the renderer, should
60 // the navigation succeed. 60 // the navigation succeed.
61 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost( 61 static std::unique_ptr<ServiceWorkerProviderHost> PreCreateNavigationHost(
62 base::WeakPtr<ServiceWorkerContextCore> context); 62 base::WeakPtr<ServiceWorkerContextCore> context);
63 63
64 enum class FrameSecurityLevel { UNINITIALIZED, INSECURE, SECURE };
65
64 // When this provider host is for a Service Worker context, |route_id| is 66 // When this provider host is for a Service Worker context, |route_id| is
65 // MSG_ROUTING_NONE. When this provider host is for a Document, 67 // MSG_ROUTING_NONE. When this provider host is for a Document,
66 // |route_id| is the frame ID of the Document. When this provider host is for 68 // |route_id| is the frame ID of the Document. When this provider host is for
67 // a Shared Worker, |route_id| is the Shared Worker route ID. 69 // a Shared Worker, |route_id| is the Shared Worker route ID.
68 // |provider_type| gives additional information whether the provider is 70 // |provider_type| gives additional information whether the provider is
69 // created for controller (ServiceWorker) or controllee (Document or 71 // created for controller (ServiceWorker) or controllee (Document or
70 // SharedWorker). 72 // SharedWorker).
71 ServiceWorkerProviderHost(int render_process_id, 73 ServiceWorkerProviderHost(int render_process_id,
72 int route_id, 74 int route_id,
73 int provider_id, 75 int provider_id,
74 ServiceWorkerProviderType provider_type, 76 ServiceWorkerProviderType provider_type,
77 FrameSecurityLevel parent_frame_security_level,
75 base::WeakPtr<ServiceWorkerContextCore> context, 78 base::WeakPtr<ServiceWorkerContextCore> context,
76 ServiceWorkerDispatcherHost* dispatcher_host); 79 ServiceWorkerDispatcherHost* dispatcher_host);
77 virtual ~ServiceWorkerProviderHost(); 80 virtual ~ServiceWorkerProviderHost();
78 81
79 const std::string& client_uuid() const { return client_uuid_; } 82 const std::string& client_uuid() const { return client_uuid_; }
80 int process_id() const { return render_process_id_; } 83 int process_id() const { return render_process_id_; }
81 int provider_id() const { return provider_id_; } 84 int provider_id() const { return provider_id_; }
82 int frame_id() const; 85 int frame_id() const;
83 int route_id() const { return route_id_; } 86 int route_id() const { return route_id_; }
84 87
88 bool is_parent_frame_secure() const {
89 return parent_frame_security_level_ == FrameSecurityLevel::SECURE;
90 }
91 void set_parent_frame_secure(bool is_parent_frame_secure) {
92 CHECK_EQ(parent_frame_security_level_, FrameSecurityLevel::UNINITIALIZED);
93 parent_frame_security_level_ = is_parent_frame_secure
94 ? FrameSecurityLevel::SECURE
95 : FrameSecurityLevel::INSECURE;
96 }
97
98 // Returns whether this provider host is secure enough to have a service
99 // worker controller.
100 // Analogous to Blink's Document::isSecureContext. Because of how service
101 // worker intercepts main resource requests, this check must be done
102 // browser-side once the URL is known (see comments in
103 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses
104 // |document_url_| and |is_parent_frame_secure_| to determine context
105 // security, so they must be set properly before calling this function.
106 bool IsContextSecureForServiceWorker() const;
107
85 bool IsHostToRunningServiceWorker() { 108 bool IsHostToRunningServiceWorker() {
86 return running_hosted_version_.get() != NULL; 109 return running_hosted_version_.get() != NULL;
87 } 110 }
88 111
89 ServiceWorkerVersion* controlling_version() const { 112 ServiceWorkerVersion* controlling_version() const {
90 return controlling_version_.get(); 113 return controlling_version_.get();
91 } 114 }
92 ServiceWorkerVersion* active_version() const { 115 ServiceWorkerVersion* active_version() const {
93 return associated_registration_.get() ? 116 return associated_registration_.get() ?
94 associated_registration_->active_version() : NULL; 117 associated_registration_->active_version() : NULL;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, 275 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest,
253 DispatchExtendableMessageEvent_Fail); 276 DispatchExtendableMessageEvent_Fail);
254 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 277 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
255 UpdateBefore24Hours); 278 UpdateBefore24Hours);
256 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 279 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
257 UpdateAfter24Hours); 280 UpdateAfter24Hours);
258 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 281 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
259 UpdateForceBypassCache); 282 UpdateForceBypassCache);
260 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 283 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
261 ServiceWorkerDataRequestAnnotation); 284 ServiceWorkerDataRequestAnnotation);
285 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostTest, ContextSecurity);
262 286
263 struct OneShotGetReadyCallback { 287 struct OneShotGetReadyCallback {
264 GetRegistrationForReadyCallback callback; 288 GetRegistrationForReadyCallback callback;
265 bool called; 289 bool called;
266 290
267 explicit OneShotGetReadyCallback( 291 explicit OneShotGetReadyCallback(
268 const GetRegistrationForReadyCallback& callback); 292 const GetRegistrationForReadyCallback& callback);
269 ~OneShotGetReadyCallback(); 293 ~OneShotGetReadyCallback();
270 }; 294 };
271 295
(...skipping 28 matching lines...) Expand all
300 void FinalizeInitialization(int process_id, 324 void FinalizeInitialization(int process_id,
301 int frame_routing_id, 325 int frame_routing_id,
302 ServiceWorkerDispatcherHost* dispatcher_host); 326 ServiceWorkerDispatcherHost* dispatcher_host);
303 327
304 std::string client_uuid_; 328 std::string client_uuid_;
305 int render_process_id_; 329 int render_process_id_;
306 int route_id_; 330 int route_id_;
307 int render_thread_id_; 331 int render_thread_id_;
308 int provider_id_; 332 int provider_id_;
309 ServiceWorkerProviderType provider_type_; 333 ServiceWorkerProviderType provider_type_;
334 FrameSecurityLevel parent_frame_security_level_;
310 GURL document_url_; 335 GURL document_url_;
311 GURL topmost_frame_url_; 336 GURL topmost_frame_url_;
312 337
313 std::vector<GURL> associated_patterns_; 338 std::vector<GURL> associated_patterns_;
314 scoped_refptr<ServiceWorkerRegistration> associated_registration_; 339 scoped_refptr<ServiceWorkerRegistration> associated_registration_;
315 340
316 // Keyed by registration scope URL length. 341 // Keyed by registration scope URL length.
317 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> 342 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>>
318 ServiceWorkerRegistrationMap; 343 ServiceWorkerRegistrationMap;
319 // Contains all living registrations which has pattern this document's 344 // Contains all living registrations whose pattern this document's URL
320 // URL starts with. 345 // starts with. It is empty if IsContextSecureForServiceWorker() is
346 // false.
321 ServiceWorkerRegistrationMap matching_registrations_; 347 ServiceWorkerRegistrationMap matching_registrations_;
322 348
323 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; 349 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_;
324 scoped_refptr<ServiceWorkerVersion> controlling_version_; 350 scoped_refptr<ServiceWorkerVersion> controlling_version_;
325 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 351 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
326 base::WeakPtr<ServiceWorkerContextCore> context_; 352 base::WeakPtr<ServiceWorkerContextCore> context_;
327 ServiceWorkerDispatcherHost* dispatcher_host_; 353 ServiceWorkerDispatcherHost* dispatcher_host_;
328 bool allow_association_; 354 bool allow_association_;
329 355
330 std::vector<base::Closure> queued_events_; 356 std::vector<base::Closure> queued_events_;
331 357
332 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 358 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
333 }; 359 };
334 360
335 } // namespace content 361 } // namespace content
336 362
337 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 363 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698