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

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

Issue 2142523004: M52: Merge "Reland: service worker: Don't control a subframe of an insecure context" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: fix compile errors Created 4 years, 5 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(static_cast<int>(parent_frame_security_level_),
93 static_cast<int>(FrameSecurityLevel::UNINITIALIZED));
94 parent_frame_security_level_ = is_parent_frame_secure
95 ? FrameSecurityLevel::SECURE
96 : FrameSecurityLevel::INSECURE;
97 }
98
99 // Returns whether this provider host is secure enough to have a service
100 // worker controller.
101 // Analogous to Blink's Document::isSecureContext. Because of how service
102 // worker intercepts main resource requests, this check must be done
103 // browser-side once the URL is known (see comments in
104 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses
105 // |document_url_| and |is_parent_frame_secure_| to determine context
106 // security, so they must be set properly before calling this function.
107 bool IsContextSecureForServiceWorker() const;
108
85 bool IsHostToRunningServiceWorker() { 109 bool IsHostToRunningServiceWorker() {
86 return running_hosted_version_.get() != NULL; 110 return running_hosted_version_.get() != NULL;
87 } 111 }
88 112
89 ServiceWorkerVersion* controlling_version() const { 113 ServiceWorkerVersion* controlling_version() const {
90 return controlling_version_.get(); 114 return controlling_version_.get();
91 } 115 }
92 ServiceWorkerVersion* active_version() const { 116 ServiceWorkerVersion* active_version() const {
93 return associated_registration_.get() ? 117 return associated_registration_.get() ?
94 associated_registration_->active_version() : NULL; 118 associated_registration_->active_version() : NULL;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, 276 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest,
253 DispatchExtendableMessageEvent_Fail); 277 DispatchExtendableMessageEvent_Fail);
254 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 278 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
255 UpdateBefore24Hours); 279 UpdateBefore24Hours);
256 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 280 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
257 UpdateAfter24Hours); 281 UpdateAfter24Hours);
258 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 282 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
259 UpdateForceBypassCache); 283 UpdateForceBypassCache);
260 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, 284 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
261 ServiceWorkerDataRequestAnnotation); 285 ServiceWorkerDataRequestAnnotation);
286 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostTest, ContextSecurity);
262 287
263 struct OneShotGetReadyCallback { 288 struct OneShotGetReadyCallback {
264 GetRegistrationForReadyCallback callback; 289 GetRegistrationForReadyCallback callback;
265 bool called; 290 bool called;
266 291
267 explicit OneShotGetReadyCallback( 292 explicit OneShotGetReadyCallback(
268 const GetRegistrationForReadyCallback& callback); 293 const GetRegistrationForReadyCallback& callback);
269 ~OneShotGetReadyCallback(); 294 ~OneShotGetReadyCallback();
270 }; 295 };
271 296
(...skipping 28 matching lines...) Expand all
300 void FinalizeInitialization(int process_id, 325 void FinalizeInitialization(int process_id,
301 int frame_routing_id, 326 int frame_routing_id,
302 ServiceWorkerDispatcherHost* dispatcher_host); 327 ServiceWorkerDispatcherHost* dispatcher_host);
303 328
304 std::string client_uuid_; 329 std::string client_uuid_;
305 int render_process_id_; 330 int render_process_id_;
306 int route_id_; 331 int route_id_;
307 int render_thread_id_; 332 int render_thread_id_;
308 int provider_id_; 333 int provider_id_;
309 ServiceWorkerProviderType provider_type_; 334 ServiceWorkerProviderType provider_type_;
335 FrameSecurityLevel parent_frame_security_level_;
310 GURL document_url_; 336 GURL document_url_;
311 GURL topmost_frame_url_; 337 GURL topmost_frame_url_;
312 338
313 std::vector<GURL> associated_patterns_; 339 std::vector<GURL> associated_patterns_;
314 scoped_refptr<ServiceWorkerRegistration> associated_registration_; 340 scoped_refptr<ServiceWorkerRegistration> associated_registration_;
315 341
316 // Keyed by registration scope URL length. 342 // Keyed by registration scope URL length.
317 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> 343 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>>
318 ServiceWorkerRegistrationMap; 344 ServiceWorkerRegistrationMap;
319 // Contains all living registrations which has pattern this document's 345 // Contains all living registrations whose pattern this document's URL
320 // URL starts with. 346 // starts with. It is empty if IsContextSecureForServiceWorker() is
347 // false.
321 ServiceWorkerRegistrationMap matching_registrations_; 348 ServiceWorkerRegistrationMap matching_registrations_;
322 349
323 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; 350 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_;
324 scoped_refptr<ServiceWorkerVersion> controlling_version_; 351 scoped_refptr<ServiceWorkerVersion> controlling_version_;
325 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; 352 scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
326 base::WeakPtr<ServiceWorkerContextCore> context_; 353 base::WeakPtr<ServiceWorkerContextCore> context_;
327 ServiceWorkerDispatcherHost* dispatcher_host_; 354 ServiceWorkerDispatcherHost* dispatcher_host_;
328 bool allow_association_; 355 bool allow_association_;
329 356
330 std::vector<base::Closure> queued_events_; 357 std::vector<base::Closure> queued_events_;
331 358
332 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 359 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
333 }; 360 };
334 361
335 } // namespace content 362 } // namespace content
336 363
337 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 364 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698