From e00ebeda6a452b7c7aa58ed1a9a1a488277f1ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 11 Mar 2018 15:30:57 +0100 Subject: [PATCH] Bug 1444580: Move OnPageShow / OnPageHide to nsIDocument, devirtualize OnPageHide. r=smaug MozReview-Commit-ID: HlOpJ8Rg9IG --- dom/base/nsDocument.cpp | 24 +++++++++++------------- dom/base/nsDocument.h | 7 ------- dom/base/nsIDocument.h | 10 +++++++--- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 6d9314b433cb..e5171733fa95 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -8451,9 +8451,9 @@ nsIDocument::GetContentInThisDocument(nsIFrame* aFrame) const } void -nsDocument::DispatchPageTransition(EventTarget* aDispatchTarget, - const nsAString& aType, - bool aPersisted) +nsIDocument::DispatchPageTransition(EventTarget* aDispatchTarget, + const nsAString& aType, + bool aPersisted) { if (!aDispatchTarget) { return; @@ -8485,8 +8485,7 @@ NotifyPageShow(nsIDocument* aDocument, void* aData) } void -nsDocument::OnPageShow(bool aPersisted, - EventTarget* aDispatchStartTarget) +nsIDocument::OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget) { mVisible = true; @@ -8527,8 +8526,8 @@ nsDocument::OnPageShow(bool aPersisted, // Dispatch observer notification to notify observers page is shown. nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { - nsIPrincipal *principal = GetPrincipal(); - os->NotifyObservers(static_cast(this), + nsIPrincipal* principal = NodePrincipal(); + os->NotifyObservers(this, nsContentUtils::IsSystemPrincipal(principal) ? "chrome-page-shown" : "content-page-shown", @@ -8577,16 +8576,15 @@ DispatchFullScreenChange(nsIDocument* aTarget) static void ClearPendingFullscreenRequests(nsIDocument* aDoc); void -nsDocument::OnPageHide(bool aPersisted, - EventTarget* aDispatchStartTarget) +nsIDocument::OnPageHide(bool aPersisted, EventTarget* aDispatchStartTarget) { // Send out notifications that our elements are detached, // but only if this is not a full unload. Element* root = GetRootElement(); if (aPersisted && root) { RefPtr links = NS_GetContentList(root, - kNameSpaceID_XHTML, - NS_LITERAL_STRING("link")); + kNameSpaceID_XHTML, + NS_LITERAL_STRING("link")); uint32_t linkCount = links->Length(true); for (uint32_t i = 0; i < linkCount; ++i) { @@ -8618,8 +8616,8 @@ nsDocument::OnPageHide(bool aPersisted, // Dispatch observer notification to notify observers page is hidden. nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { - nsIPrincipal* principal = GetPrincipal(); - os->NotifyObservers(static_cast(this), + nsIPrincipal* principal = NodePrincipal(); + os->NotifyObservers(this, nsContentUtils::IsSystemPrincipal(principal) ? "chrome-page-hidden" : "content-page-hidden", diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 5825c3042562..fe8eb3f4ca50 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -205,9 +205,6 @@ public: nsAString& aEncoding, nsAString& Standalone) override; - virtual void OnPageShow(bool aPersisted, mozilla::dom::EventTarget* aDispatchStartTarget) override; - virtual void OnPageHide(bool aPersisted, mozilla::dom::EventTarget* aDispatchStartTarget) override; - virtual void WillDispatchMutationEvent(nsINode* aTarget) override; virtual void MutationEventDispatched(nsINode* aTarget) override; @@ -393,10 +390,6 @@ public: protected: - void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget, - const nsAString& aType, - bool aPersisted); - void UpdateScreenOrientation(); #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_) do { \ diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 880a2389a0af..0544292a435e 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1406,6 +1406,10 @@ public: mozilla::Maybe GetController() const; protected: + void DispatchPageTransition(mozilla::dom::EventTarget* aDispatchTarget, + const nsAString& aType, + bool aPersisted); + // Call this before the document does something that will unbind all content. // That will stop us from doing a lot of work as each element is removed. void DestroyElementMaps(); @@ -2358,7 +2362,7 @@ public: * document won't be altered. */ virtual void OnPageShow(bool aPersisted, - mozilla::dom::EventTarget* aDispatchStartTarget) = 0; + mozilla::dom::EventTarget* aDispatchStartTarget); /** * Notification that the page has been hidden, for documents which are loaded @@ -2372,8 +2376,8 @@ public: * Note: if aDispatchStartTarget isn't null, the showing state of the * document won't be altered. */ - virtual void OnPageHide(bool aPersisted, - mozilla::dom::EventTarget* aDispatchStartTarget) = 0; + void OnPageHide(bool aPersisted, + mozilla::dom::EventTarget* aDispatchStartTarget); /* * We record the set of links in the document that are relevant to