diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 243af0a3ac66..7f6b6d204886 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5097,6 +5097,12 @@ nsIDocument::DispatchContentLoadedEvents() true, true); } + nsPIDOMWindowInner* inner = GetInnerWindow(); + if (inner) { + inner->NoteDOMContentLoaded(); + } + + // TODO if (mMaybeServiceWorkerControlled) { using mozilla::dom::ServiceWorkerManager; RefPtr swm = ServiceWorkerManager::GetInstance(); diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 844cb6f7e3b6..4dd1bb2de309 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -2355,6 +2355,12 @@ nsPIDOMWindowInner::NoteCalledRegisterForServiceWorkerScope(const nsACString& aS nsGlobalWindowInner::Cast(this)->NoteCalledRegisterForServiceWorkerScope(aScope); } +void +nsPIDOMWindowInner::NoteDOMContentLoaded() +{ + nsGlobalWindowInner::Cast(this)->NoteDOMContentLoaded(); +} + bool nsGlobalWindowInner::ShouldReportForServiceWorkerScope(const nsAString& aScope) { @@ -2471,6 +2477,16 @@ nsGlobalWindowInner::NoteCalledRegisterForServiceWorkerScope(const nsACString& a mClientSource->NoteCalledRegisterForServiceWorkerScope(aScope); } +void +nsGlobalWindowInner::NoteDOMContentLoaded() +{ + if (!mClientSource) { + return; + } + + mClientSource->NoteDOMContentLoaded(); +} + void nsGlobalWindowInner::MigrateStateForDocumentOpen(nsGlobalWindowInner* aOldInner) { diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 40341e342b0e..ae76d2f0fb3d 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -365,6 +365,8 @@ public: void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope); + void NoteDOMContentLoaded(); + virtual nsresult FireDelayedDOMEvents() override; virtual nsresult SetNewDocument(nsIDocument *aDocument, diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 4bbf41d2933a..193859c05c62 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -332,6 +332,8 @@ public: void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope); + void NoteDOMContentLoaded(); + mozilla::dom::TabGroup* TabGroup(); virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0; diff --git a/dom/clients/manager/ClientSource.cpp b/dom/clients/manager/ClientSource.cpp index 13be3a8c2882..3bbc417b9136 100644 --- a/dom/clients/manager/ClientSource.cpp +++ b/dom/clients/manager/ClientSource.cpp @@ -477,6 +477,22 @@ ClientSource::GetController() const return mController; } +void +ClientSource::NoteDOMContentLoaded() +{ + if (mController.isSome() && !ServiceWorkerParentInterceptEnabled()) { + AssertIsOnMainThread(); + RefPtr swm = ServiceWorkerManager::GetInstance(); + if (swm) { + swm->MaybeCheckNavigationUpdate(mClientInfo); + } + } + + MaybeExecute([] (PClientSourceChild* aActor) { + aActor->SendNoteDOMContentLoaded(); + }); +} + RefPtr ClientSource::Focus(const ClientFocusArgs& aArgs) { diff --git a/dom/clients/manager/ClientSource.h b/dom/clients/manager/ClientSource.h index b67bcb6e8f3b..671f40ccae83 100644 --- a/dom/clients/manager/ClientSource.h +++ b/dom/clients/manager/ClientSource.h @@ -150,6 +150,11 @@ public: const Maybe& GetController() const; + // Note that the client has reached DOMContentLoaded. Only applies to window + // clients. + void + NoteDOMContentLoaded(); + RefPtr Focus(const ClientFocusArgs& aArgs); diff --git a/dom/clients/manager/ClientSourceParent.cpp b/dom/clients/manager/ClientSourceParent.cpp index 0b6b8736b3c3..a46f5ba49121 100644 --- a/dom/clients/manager/ClientSourceParent.cpp +++ b/dom/clients/manager/ClientSourceParent.cpp @@ -170,6 +170,24 @@ ClientSourceParent::RecvInheritController(const ClientControlledArgs& aArgs) return IPC_OK(); } +IPCResult +ClientSourceParent::RecvNoteDOMContentLoaded() +{ + if (mController.isSome() && ServiceWorkerParentInterceptEnabled()) { + nsCOMPtr r = NS_NewRunnableFunction( + "ClientSourceParent::RecvNoteDOMContentLoaded", + [clientInfo = mClientInfo] () { + RefPtr swm = ServiceWorkerManager::GetInstance(); + NS_ENSURE_TRUE_VOID(swm); + + swm->MaybeCheckNavigationUpdate(clientInfo); + }); + + MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget())); + } + return IPC_OK(); +} + void ClientSourceParent::ActorDestroy(ActorDestroyReason aReason) { diff --git a/dom/clients/manager/ClientSourceParent.h b/dom/clients/manager/ClientSourceParent.h index cce3734f394a..d618d5ee5cda 100644 --- a/dom/clients/manager/ClientSourceParent.h +++ b/dom/clients/manager/ClientSourceParent.h @@ -48,6 +48,9 @@ class ClientSourceParent final : public PClientSourceParent mozilla::ipc::IPCResult RecvInheritController(const ClientControlledArgs& aArgs) override; + mozilla::ipc::IPCResult + RecvNoteDOMContentLoaded() override; + void ActorDestroy(ActorDestroyReason aReason) override; diff --git a/dom/clients/manager/PClientSource.ipdl b/dom/clients/manager/PClientSource.ipdl index 1229bc01dcd7..41d7cbad59ba 100644 --- a/dom/clients/manager/PClientSource.ipdl +++ b/dom/clients/manager/PClientSource.ipdl @@ -26,6 +26,7 @@ parent: async Freeze(); async Thaw(); async InheritController(ClientControlledArgs aArgs); + async NoteDOMContentLoaded(); child: async PClientSourceOp(ClientOpConstructorArgs aArgs);