summaryrefslogtreecommitdiff
path: root/chromium/content/browser/service_worker/service_worker_provider_host.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-10-24 11:30:15 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-10-30 12:56:19 +0000
commit6036726eb981b6c4b42047513b9d3f4ac865daac (patch)
tree673593e70678e7789766d1f732eb51f613a2703b /chromium/content/browser/service_worker/service_worker_provider_host.h
parent466052c4e7c052268fd931888cd58961da94c586 (diff)
downloadqtwebengine-chromium-6036726eb981b6c4b42047513b9d3f4ac865daac.tar.gz
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/content/browser/service_worker/service_worker_provider_host.h')
-rw-r--r--chromium/content/browser/service_worker/service_worker_provider_host.h151
1 files changed, 76 insertions, 75 deletions
diff --git a/chromium/content/browser/service_worker/service_worker_provider_host.h b/chromium/content/browser/service_worker/service_worker_provider_host.h
index ded291f894a..2fe3e1ef2b8 100644
--- a/chromium/content/browser/service_worker/service_worker_provider_host.h
+++ b/chromium/content/browser/service_worker/service_worker_provider_host.h
@@ -203,47 +203,21 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// and if it has a fetch event handler.
blink::mojom::ControllerServiceWorkerMode GetControllerMode() const;
- // Returns this provider's controller. The controller is typically the same as
- // active_version() but can differ in the following cases:
- // (1) The client was created before the registration existed or had an active
- // version (in spec language, it is not "using" the registration).
- // (2) The client had a controller but NotifyControllerLost() was called due
- // to an exceptional circumstance (here also it is not "using" the
- // registration).
- // (3) During algorithms such as the update, skipWaiting(), and claim() steps,
- // the active version and controller may temporarily differ. For example, to
- // perform skipWaiting(), the registration's active version is updated first
- // and then the provider host's controlling version is updated to match it.
+ // For service worker clients. Returns this client's controller.
ServiceWorkerVersion* controller() const {
- // Only clients can have controllers.
- DCHECK(!controller_ || IsProviderForClient());
- return controller_.get();
- }
-
- ServiceWorkerVersion* active_version() const {
- return associated_registration_.get()
- ? associated_registration_->active_version()
- : nullptr;
- }
+#if DCHECK_IS_ON()
+ CheckControllerConsistency();
+#endif // DCHECK_IS_ON()
- ServiceWorkerVersion* waiting_version() const {
- return associated_registration_.get()
- ? associated_registration_->waiting_version()
- : nullptr;
+ return controller_.get();
}
- ServiceWorkerVersion* installing_version() const {
- return associated_registration_.get()
- ? associated_registration_->installing_version()
- : nullptr;
- }
+ ServiceWorkerRegistration* controller_registration() const {
+#if DCHECK_IS_ON()
+ CheckControllerConsistency();
+#endif // DCHECK_IS_ON()
- // Returns the associated registration. The provider host listens to this
- // registration to resolve the .ready promise and set its controller.
- ServiceWorkerRegistration* associated_registration() const {
- // Only clients can have an associated registration.
- DCHECK(!associated_registration_ || IsProviderForClient());
- return associated_registration_.get();
+ return controller_registration_.get();
}
// For service worker execution contexts. The version of the service worker.
@@ -267,10 +241,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
//
// - During navigation, right after a request handler for the main resource
// has found the matching registration and has started the worker.
- // - When a controller is updated by SetControllerVersionAttribute() (e.g.
- // by OnSkippedWaiting, {Dis,}AssociateRegistration, NotifyControllerLost
- // or ClaimedByRegistration). In some cases the controller worker may not
- // be started yet.
+ // - When a controller is updated by UpdateController() (e.g.
+ // by OnSkippedWaiting() or SetControllerRegistration()).
+ // In some cases the controller worker may not be started yet.
//
// This may return nullptr if the controller service worker does not have a
// fetch handler, i.e. when the renderer does not need the controller ptr.
@@ -320,15 +293,29 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// Can only be called when IsProviderForClient() is true.
blink::mojom::ServiceWorkerClientType client_type() const;
- // For service worker clients. Associates to |registration| to listen for its
- // version change events and sets the controller. If |notify_controllerchange|
- // is true, instructs the renderer to dispatch a 'controllerchange' event.
- void AssociateRegistration(ServiceWorkerRegistration* registration,
- bool notify_controllerchange);
+ // For service worker clients. Makes this client be controlled by
+ // |registration|'s active worker, or makes this client be not
+ // controlled if |registration| is null. If |notify_controllerchange| is true,
+ // instructs the renderer to dispatch a 'controllerchange' event.
+ void SetControllerRegistration(
+ scoped_refptr<ServiceWorkerRegistration> controller_registration,
+ bool notify_controllerchange);
- // For service worker clients. Clears the associated registration and stops
- // listening to it.
- void DisassociateRegistration();
+ // For use by the ServiceWorkerControlleeRequestHandler to disallow a
+ // registration claiming this host while its main resource request is
+ // occurring.
+ //
+ // TODO(crbug.com/866353): This should be unneccessary: registration code
+ // already avoids claiming clients that are not execution ready. However
+ // there may be edge cases with shared workers (pre-NetS13nServiceWorker) and
+ // about:blank iframes, since |is_execution_ready_| is initialized true for
+ // them. Try to remove this after S13nServiceWorker.
+ void AllowSetControllerRegistration(bool allow) {
+ allow_set_controller_registration_ = allow;
+ }
+ bool IsSetControllerRegistrationAllowed() {
+ return allow_set_controller_registration_;
+ }
// Returns a handler for a request. May return nullptr if the request doesn't
// require special handling.
@@ -366,14 +353,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
base::WeakPtr<ServiceWorkerObjectHost> GetOrCreateServiceWorkerObjectHost(
scoped_refptr<ServiceWorkerVersion> version);
- // Returns true if |registration| can be associated with this provider.
- bool CanAssociateRegistration(ServiceWorkerRegistration* registration);
-
- // For use by the ServiceWorkerControlleeRequestHandler to disallow
- // new registration association while a navigation is occurring and
- // an existing registration is being looked for.
- void SetAllowAssociation(bool allow) { allow_association_ = allow; }
-
// Returns true if the context referred to by this host (i.e. |context_|) is
// still alive.
bool IsContextAlive();
@@ -387,7 +366,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
void CountFeature(blink::mojom::WebFeature feature);
// |registration| claims the document to be controlled.
- void ClaimedByRegistration(ServiceWorkerRegistration* registration);
+ void ClaimedByRegistration(
+ scoped_refptr<ServiceWorkerRegistration> registration);
// For service worker clients. Completes initialization of
// provider hosts used for navigation requests.
@@ -419,6 +399,16 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// After this is called, is_execution_ready() returns true.
void CompleteSharedWorkerPreparation();
+ // For service worker clients. The host keeps track of all the prospective
+ // longest-matching registrations, in order to resolve .ready or respond to
+ // claim() attempts.
+ //
+ // This is subtle: it doesn't keep all registrations (e.g., from storage) in
+ // memory, but just the ones that are possibly the longest-matching one. The
+ // best match from storage is added at load time. That match can't uninstall
+ // while this host is a controllee, so all the other stored registrations can
+ // be ignored. Only a newly installed registration can claim it, and new
+ // installing registrations are added as matches.
void AddMatchingRegistration(ServiceWorkerRegistration* registration);
void RemoveMatchingRegistration(ServiceWorkerRegistration* registration);
@@ -471,6 +461,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
friend class ServiceWorkerProviderHostTest;
friend class ServiceWorkerWriteToCacheJobTest;
friend class ServiceWorkerContextRequestHandlerTest;
+ friend class service_worker_controllee_request_handler_unittest::
+ ServiceWorkerControlleeRequestHandlerTest;
friend class service_worker_object_host_unittest::ServiceWorkerObjectHostTest;
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
@@ -509,17 +501,20 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
ServiceWorkerRegistration* registration) override;
void OnSkippedWaiting(ServiceWorkerRegistration* registration) override;
- // Sets the controller field to |version| or if |version| is nullptr, clears
- // the field. If |notify_controllerchange| is true, instructs the renderer to
- // dispatch a 'controller' change event.
- void SetControllerVersionAttribute(ServiceWorkerVersion* version,
- bool notify_controllerchange);
-
- void SendAssociateRegistrationMessage();
+ // Sets the controller to |controller_registration_->active_version()| or null
+ // if there is no associated registration.
+ //
+ // If |notify_controllerchange| is true, instructs the renderer to dispatch a
+ // 'controller' change event.
+ void UpdateController(bool notify_controllerchange);
// Syncs matching registrations with live registrations.
void SyncMatchingRegistrations();
+#if DCHECK_IS_ON()
+ bool IsMatchingRegistration(ServiceWorkerRegistration* registration) const;
+#endif // DCHECK_IS_ON()
+
// Discards all references to matching registrations.
void RemoveAllMatchingRegistrations();
@@ -530,6 +525,10 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// instructs the renderer to dispatch a 'controllerchange' event.
void SendSetControllerServiceWorker(bool notify_controllerchange);
+#if DCHECK_IS_ON()
+ void CheckControllerConsistency() const;
+#endif // DCHECK_IS_ON()
+
// Implements mojom::ServiceWorkerContainerHost.
void Register(const GURL& script_url,
blink::mojom::ServiceWorkerRegistrationOptionsPtr options,
@@ -550,6 +549,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// Callback for ServiceWorkerContextCore::RegisterServiceWorker().
void RegistrationComplete(RegisterCallback callback,
int64_t trace_id,
+ mojo::ReportBadMessageCallback bad_message_callback,
blink::ServiceWorkerStatusCode status,
const std::string& status_message,
int64_t registration_id);
@@ -572,10 +572,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
mojom::ControllerServiceWorkerRequest controller_request,
blink::ServiceWorkerStatusCode status);
- bool IsValidRegisterMessage(
- const GURL& script_url,
- const blink::mojom::ServiceWorkerRegistrationOptions& options,
- std::string* out_error) const;
bool IsValidGetRegistrationMessage(const GURL& client_url,
std::string* out_error) const;
bool IsValidGetRegistrationsMessage(std::string* out_error) const;
@@ -616,14 +612,13 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
GURL document_url_;
GURL topmost_frame_url_;
- scoped_refptr<ServiceWorkerRegistration> associated_registration_;
-
// Keyed by registration scope URL length.
using ServiceWorkerRegistrationMap =
std::map<size_t, scoped_refptr<ServiceWorkerRegistration>>;
// Contains all living registrations whose pattern this document's URL
- // starts with. It is empty if IsContextSecureForServiceWorker() is
- // false.
+ // starts with, used for .ready and claim(). It is empty if
+ // IsContextSecureForServiceWorker() is false. See also
+ // AddMatchingRegistration().
ServiceWorkerRegistrationMap matching_registrations_;
// Contains all ServiceWorkerRegistrationObjectHost instances corresponding to
@@ -651,16 +646,22 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
std::unique_ptr<GetRegistrationForReadyCallback> get_ready_callback_;
// For service worker clients. The controller service worker (i.e.,
- // ServiceWorkerContainer#controller).
+ // ServiceWorkerContainer#controller) and its registration. The controller is
+ // typically the same as the registration's active version, but during
+ // algorithms such as the update, skipWaiting(), and claim() steps, the active
+ // version and controller may temporarily differ. For example, to perform
+ // skipWaiting(), the registration's active version is updated first and then
+ // the provider host's controller is updated to match it.
scoped_refptr<ServiceWorkerVersion> controller_;
+ scoped_refptr<ServiceWorkerRegistration> controller_registration_;
+ bool allow_set_controller_registration_ = true;
+
// For service worker execution contexts. The ServiceWorkerVersion of the
// service worker this is a provider for.
scoped_refptr<ServiceWorkerVersion> running_hosted_version_;
base::WeakPtr<ServiceWorkerContextCore> context_;
- bool allow_association_;
-
// |container_| is the Mojo endpoint to the renderer-side
// ServiceWorkerContainer that |this| is a ServiceWorkerContainerHost for.
mojom::ServiceWorkerContainerAssociatedPtr container_;