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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | |
66 // When this provider host is for a Service Worker context, |route_id| is | 64 // When this provider host is for a Service Worker context, |route_id| is |
67 // MSG_ROUTING_NONE. When this provider host is for a Document, | 65 // MSG_ROUTING_NONE. When this provider host is for a Document, |
68 // |route_id| is the frame ID of the Document. When this provider host is for | 66 // |route_id| is the frame ID of the Document. When this provider host is for |
69 // a Shared Worker, |route_id| is the Shared Worker route ID. | 67 // a Shared Worker, |route_id| is the Shared Worker route ID. |
70 // |provider_type| gives additional information whether the provider is | 68 // |provider_type| gives additional information whether the provider is |
71 // created for controller (ServiceWorker) or controllee (Document or | 69 // created for controller (ServiceWorker) or controllee (Document or |
72 // SharedWorker). | 70 // SharedWorker). |
73 ServiceWorkerProviderHost(int render_process_id, | 71 ServiceWorkerProviderHost(int render_process_id, |
74 int route_id, | 72 int route_id, |
75 int provider_id, | 73 int provider_id, |
76 ServiceWorkerProviderType provider_type, | 74 ServiceWorkerProviderType provider_type, |
77 FrameSecurityLevel parent_frame_security_level, | |
78 base::WeakPtr<ServiceWorkerContextCore> context, | 75 base::WeakPtr<ServiceWorkerContextCore> context, |
79 ServiceWorkerDispatcherHost* dispatcher_host); | 76 ServiceWorkerDispatcherHost* dispatcher_host); |
80 virtual ~ServiceWorkerProviderHost(); | 77 virtual ~ServiceWorkerProviderHost(); |
81 | 78 |
82 const std::string& client_uuid() const { return client_uuid_; } | 79 const std::string& client_uuid() const { return client_uuid_; } |
83 int process_id() const { return render_process_id_; } | 80 int process_id() const { return render_process_id_; } |
84 int provider_id() const { return provider_id_; } | 81 int provider_id() const { return provider_id_; } |
85 int frame_id() const; | 82 int frame_id() const; |
86 int route_id() const { return route_id_; } | 83 int route_id() const { return route_id_; } |
87 | 84 |
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 | |
108 bool IsHostToRunningServiceWorker() { | 85 bool IsHostToRunningServiceWorker() { |
109 return running_hosted_version_.get() != NULL; | 86 return running_hosted_version_.get() != NULL; |
110 } | 87 } |
111 | 88 |
112 ServiceWorkerVersion* controlling_version() const { | 89 ServiceWorkerVersion* controlling_version() const { |
113 return controlling_version_.get(); | 90 return controlling_version_.get(); |
114 } | 91 } |
115 ServiceWorkerVersion* active_version() const { | 92 ServiceWorkerVersion* active_version() const { |
116 return associated_registration_.get() ? | 93 return associated_registration_.get() ? |
117 associated_registration_->active_version() : NULL; | 94 associated_registration_->active_version() : NULL; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 252 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
276 DispatchExtendableMessageEvent_Fail); | 253 DispatchExtendableMessageEvent_Fail); |
277 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 254 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
278 UpdateBefore24Hours); | 255 UpdateBefore24Hours); |
279 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 256 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
280 UpdateAfter24Hours); | 257 UpdateAfter24Hours); |
281 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 258 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
282 UpdateForceBypassCache); | 259 UpdateForceBypassCache); |
283 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 260 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
284 ServiceWorkerDataRequestAnnotation); | 261 ServiceWorkerDataRequestAnnotation); |
285 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostTest, ContextSecurity); | |
286 | 262 |
287 struct OneShotGetReadyCallback { | 263 struct OneShotGetReadyCallback { |
288 GetRegistrationForReadyCallback callback; | 264 GetRegistrationForReadyCallback callback; |
289 bool called; | 265 bool called; |
290 | 266 |
291 explicit OneShotGetReadyCallback( | 267 explicit OneShotGetReadyCallback( |
292 const GetRegistrationForReadyCallback& callback); | 268 const GetRegistrationForReadyCallback& callback); |
293 ~OneShotGetReadyCallback(); | 269 ~OneShotGetReadyCallback(); |
294 }; | 270 }; |
295 | 271 |
(...skipping 28 matching lines...) Expand all Loading... |
324 void FinalizeInitialization(int process_id, | 300 void FinalizeInitialization(int process_id, |
325 int frame_routing_id, | 301 int frame_routing_id, |
326 ServiceWorkerDispatcherHost* dispatcher_host); | 302 ServiceWorkerDispatcherHost* dispatcher_host); |
327 | 303 |
328 std::string client_uuid_; | 304 std::string client_uuid_; |
329 int render_process_id_; | 305 int render_process_id_; |
330 int route_id_; | 306 int route_id_; |
331 int render_thread_id_; | 307 int render_thread_id_; |
332 int provider_id_; | 308 int provider_id_; |
333 ServiceWorkerProviderType provider_type_; | 309 ServiceWorkerProviderType provider_type_; |
334 FrameSecurityLevel parent_frame_security_level_; | |
335 GURL document_url_; | 310 GURL document_url_; |
336 GURL topmost_frame_url_; | 311 GURL topmost_frame_url_; |
337 | 312 |
338 std::vector<GURL> associated_patterns_; | 313 std::vector<GURL> associated_patterns_; |
339 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 314 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
340 | 315 |
341 // Keyed by registration scope URL length. | 316 // Keyed by registration scope URL length. |
342 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> | 317 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> |
343 ServiceWorkerRegistrationMap; | 318 ServiceWorkerRegistrationMap; |
344 // Contains all living registrations which has pattern this document's | 319 // Contains all living registrations which has pattern this document's |
345 // URL starts with. | 320 // URL starts with. |
346 ServiceWorkerRegistrationMap matching_registrations_; | 321 ServiceWorkerRegistrationMap matching_registrations_; |
347 | 322 |
348 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; | 323 std::unique_ptr<OneShotGetReadyCallback> get_ready_callback_; |
349 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 324 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
350 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 325 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
351 base::WeakPtr<ServiceWorkerContextCore> context_; | 326 base::WeakPtr<ServiceWorkerContextCore> context_; |
352 ServiceWorkerDispatcherHost* dispatcher_host_; | 327 ServiceWorkerDispatcherHost* dispatcher_host_; |
353 bool allow_association_; | 328 bool allow_association_; |
354 | 329 |
355 std::vector<base::Closure> queued_events_; | 330 std::vector<base::Closure> queued_events_; |
356 | 331 |
357 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 332 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
358 }; | 333 }; |
359 | 334 |
360 } // namespace content | 335 } // namespace content |
361 | 336 |
362 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 337 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |