| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 static std::unique_ptr<ServiceWorkerProviderHost> Create( | 81 static std::unique_ptr<ServiceWorkerProviderHost> Create( |
| 82 int process_id, | 82 int process_id, |
| 83 ServiceWorkerProviderHostInfo info, | 83 ServiceWorkerProviderHostInfo info, |
| 84 base::WeakPtr<ServiceWorkerContextCore> context, | 84 base::WeakPtr<ServiceWorkerContextCore> context, |
| 85 ServiceWorkerDispatcherHost* dispatcher_host); | 85 ServiceWorkerDispatcherHost* dispatcher_host); |
| 86 | 86 |
| 87 virtual ~ServiceWorkerProviderHost(); | 87 virtual ~ServiceWorkerProviderHost(); |
| 88 | 88 |
| 89 const std::string& client_uuid() const { return client_uuid_; } | 89 const std::string& client_uuid() const { return client_uuid_; } |
| 90 int process_id() const { return render_process_id_; } | 90 int process_id() const { return render_process_id_; } |
| 91 int provider_id() const { return info_.provider_id; } | 91 int provider_id() const { return provider_id_; } |
| 92 int frame_id() const; | 92 int frame_id() const; |
| 93 int route_id() const { return info_.route_id; } | 93 int route_id() const { return route_id_; } |
| 94 const WebContentsGetter& web_contents_getter() const { | 94 const WebContentsGetter& web_contents_getter() const { |
| 95 return web_contents_getter_; | 95 return web_contents_getter_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool is_parent_frame_secure() const { return info_.is_parent_frame_secure; } | 98 bool is_parent_frame_secure() const { return is_parent_frame_secure_; } |
| 99 | 99 |
| 100 // Returns whether this provider host is secure enough to have a service | 100 // Returns whether this provider host is secure enough to have a service |
| 101 // worker controller. | 101 // worker controller. |
| 102 // Analogous to Blink's Document::isSecureContext. Because of how service | 102 // Analogous to Blink's Document::isSecureContext. Because of how service |
| 103 // worker intercepts main resource requests, this check must be done | 103 // worker intercepts main resource requests, this check must be done |
| 104 // browser-side once the URL is known (see comments in | 104 // browser-side once the URL is known (see comments in |
| 105 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses | 105 // ServiceWorkerNetworkProvider::CreateForNavigation). This function uses |
| 106 // |document_url_| and |is_parent_frame_secure_| to determine context | 106 // |document_url_| and |is_parent_frame_secure_| to determine context |
| 107 // security, so they must be set properly before calling this function. | 107 // security, so they must be set properly before calling this function. |
| 108 bool IsContextSecureForServiceWorker() const; | 108 bool IsContextSecureForServiceWorker() const; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Only clients can have an associated registration. | 150 // Only clients can have an associated registration. |
| 151 DCHECK(!associated_registration_ || IsProviderForClient()); | 151 DCHECK(!associated_registration_ || IsProviderForClient()); |
| 152 return associated_registration_.get(); | 152 return associated_registration_.get(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // The running version, if any, that this provider is providing resource | 155 // The running version, if any, that this provider is providing resource |
| 156 // loads for. | 156 // loads for. |
| 157 ServiceWorkerVersion* running_hosted_version() const { | 157 ServiceWorkerVersion* running_hosted_version() const { |
| 158 // Only providers for controllers can host a running version. | 158 // Only providers for controllers can host a running version. |
| 159 DCHECK(!running_hosted_version_ || | 159 DCHECK(!running_hosted_version_ || |
| 160 info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER); | 160 provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER); |
| 161 return running_hosted_version_.get(); | 161 return running_hosted_version_.get(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Sets the |document_url_|. When this object is for a client, | 164 // Sets the |document_url_|. When this object is for a client, |
| 165 // |matching_registrations_| gets also updated to ensure that |document_url_| | 165 // |matching_registrations_| gets also updated to ensure that |document_url_| |
| 166 // is in scope of all |matching_registrations_|. | 166 // is in scope of all |matching_registrations_|. |
| 167 void SetDocumentUrl(const GURL& url); | 167 void SetDocumentUrl(const GURL& url); |
| 168 const GURL& document_url() const { return document_url_; } | 168 const GURL& document_url() const { return document_url_; } |
| 169 | 169 |
| 170 void SetTopmostFrameUrl(const GURL& url); | 170 void SetTopmostFrameUrl(const GURL& url); |
| 171 const GURL& topmost_frame_url() const { return topmost_frame_url_; } | 171 const GURL& topmost_frame_url() const { return topmost_frame_url_; } |
| 172 | 172 |
| 173 ServiceWorkerProviderType provider_type() const { return info_.type; } | 173 ServiceWorkerProviderType provider_type() const { return provider_type_; } |
| 174 bool IsProviderForClient() const; | 174 bool IsProviderForClient() const; |
| 175 blink::WebServiceWorkerClientType client_type() const; | 175 blink::WebServiceWorkerClientType client_type() const; |
| 176 | 176 |
| 177 // Associates to |registration| to listen for its version change events and | 177 // Associates to |registration| to listen for its version change events and |
| 178 // sets the controller. If |notify_controllerchange| is true, instructs the | 178 // sets the controller. If |notify_controllerchange| is true, instructs the |
| 179 // renderer to dispatch a 'controllerchange' event. | 179 // renderer to dispatch a 'controllerchange' event. |
| 180 void AssociateRegistration(ServiceWorkerRegistration* registration, | 180 void AssociateRegistration(ServiceWorkerRegistration* registration, |
| 181 bool notify_controllerchange); | 181 bool notify_controllerchange); |
| 182 | 182 |
| 183 // Clears the associated registration and stop listening to it. | 183 // Clears the associated registration and stop listening to it. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 struct OneShotGetReadyCallback { | 312 struct OneShotGetReadyCallback { |
| 313 GetRegistrationForReadyCallback callback; | 313 GetRegistrationForReadyCallback callback; |
| 314 bool called; | 314 bool called; |
| 315 | 315 |
| 316 explicit OneShotGetReadyCallback( | 316 explicit OneShotGetReadyCallback( |
| 317 const GetRegistrationForReadyCallback& callback); | 317 const GetRegistrationForReadyCallback& callback); |
| 318 ~OneShotGetReadyCallback(); | 318 ~OneShotGetReadyCallback(); |
| 319 }; | 319 }; |
| 320 | 320 |
| 321 ServiceWorkerProviderHost(int render_process_id, | 321 ServiceWorkerProviderHost(int render_process_id, |
| 322 ServiceWorkerProviderHostInfo info, | 322 int route_id, |
| 323 int provider_id, |
| 324 ServiceWorkerProviderType provider_type, |
| 325 bool is_parent_frame_secure, |
| 323 base::WeakPtr<ServiceWorkerContextCore> context, | 326 base::WeakPtr<ServiceWorkerContextCore> context, |
| 324 ServiceWorkerDispatcherHost* dispatcher_host); | 327 ServiceWorkerDispatcherHost* dispatcher_host); |
| 325 | 328 |
| 326 // ServiceWorkerRegistration::Listener overrides. | 329 // ServiceWorkerRegistration::Listener overrides. |
| 327 void OnVersionAttributesChanged( | 330 void OnVersionAttributesChanged( |
| 328 ServiceWorkerRegistration* registration, | 331 ServiceWorkerRegistration* registration, |
| 329 ChangedVersionAttributesMask changed_mask, | 332 ChangedVersionAttributesMask changed_mask, |
| 330 const ServiceWorkerRegistrationInfo& info) override; | 333 const ServiceWorkerRegistrationInfo& info) override; |
| 331 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 334 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
| 332 void OnRegistrationFinishedUninstalling( | 335 void OnRegistrationFinishedUninstalling( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 361 int frame_routing_id, | 364 int frame_routing_id, |
| 362 ServiceWorkerDispatcherHost* dispatcher_host); | 365 ServiceWorkerDispatcherHost* dispatcher_host); |
| 363 | 366 |
| 364 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or | 367 // Clears the information of the ServiceWorkerWorkerClient of dedicated (or |
| 365 // shared) worker, when the connection to the worker is disconnected. | 368 // shared) worker, when the connection to the worker is disconnected. |
| 366 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); | 369 void UnregisterWorkerFetchContext(mojom::ServiceWorkerWorkerClient*); |
| 367 | 370 |
| 368 std::string client_uuid_; | 371 std::string client_uuid_; |
| 369 int render_process_id_; | 372 int render_process_id_; |
| 370 | 373 |
| 374 // See the constructor's documentation. |
| 375 int route_id_; |
| 376 |
| 371 // For provider hosts that are hosting a running service worker, the id of the | 377 // For provider hosts that are hosting a running service worker, the id of the |
| 372 // service worker thread. Otherwise, |kDocumentMainThreadId|. May be | 378 // service worker thread. Otherwise, |kDocumentMainThreadId|. May be |
| 373 // |kInvalidEmbeddedWorkerThreadId| before the hosted service worker starts | 379 // |kInvalidEmbeddedWorkerThreadId| before the hosted service worker starts |
| 374 // up, or during cross-site transfers. | 380 // up, or during cross-site transfers. |
| 375 int render_thread_id_; | 381 int render_thread_id_; |
| 376 | 382 |
| 377 // Keeps the basic provider's info provided from the renderer side. | 383 // Unique within the renderer process. |
| 378 ServiceWorkerProviderHostInfo info_; | 384 int provider_id_; |
| 379 | 385 |
| 380 // PlzNavigate | 386 // PlzNavigate |
| 381 // Only set when this object is pre-created for a navigation. It indicates the | 387 // Only set when this object is pre-created for a navigation. It indicates the |
| 382 // tab where the navigation occurs. | 388 // tab where the navigation occurs. |
| 383 WebContentsGetter web_contents_getter_; | 389 WebContentsGetter web_contents_getter_; |
| 384 | 390 |
| 391 ServiceWorkerProviderType provider_type_; |
| 392 const bool is_parent_frame_secure_; |
| 385 GURL document_url_; | 393 GURL document_url_; |
| 386 GURL topmost_frame_url_; | 394 GURL topmost_frame_url_; |
| 387 | 395 |
| 388 std::vector<GURL> associated_patterns_; | 396 std::vector<GURL> associated_patterns_; |
| 389 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 397 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
| 390 | 398 |
| 391 // Keyed by registration scope URL length. | 399 // Keyed by registration scope URL length. |
| 392 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> | 400 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> |
| 393 ServiceWorkerRegistrationMap; | 401 ServiceWorkerRegistrationMap; |
| 394 // Contains all living registrations whose pattern this document's URL | 402 // Contains all living registrations whose pattern this document's URL |
| (...skipping 15 matching lines...) Expand all Loading... |
| 410 std::unordered_map<mojom::ServiceWorkerWorkerClient*, | 418 std::unordered_map<mojom::ServiceWorkerWorkerClient*, |
| 411 mojom::ServiceWorkerWorkerClientAssociatedPtr> | 419 mojom::ServiceWorkerWorkerClientAssociatedPtr> |
| 412 worker_clients_; | 420 worker_clients_; |
| 413 | 421 |
| 414 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 422 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
| 415 }; | 423 }; |
| 416 | 424 |
| 417 } // namespace content | 425 } // namespace content |
| 418 | 426 |
| 419 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 427 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
| OLD | NEW |