Bug 1376130 - Don't notify page-{shown,hidden} observers or dispatch pageshow/pagehide events when the document is an SVG used as image. r?smaug
MozReview-Commit-ID: 45L1MBYqTeK
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -9010,33 +9010,34 @@ nsDocument::OnPageShow(bool aPersisted,
}
if (aPersisted) {
ImageTracker()->SetAnimatingState(true);
}
UpdateVisibilityState();
- nsCOMPtr<EventTarget> target = aDispatchStartTarget;
- if (!target) {
- target = do_QueryInterface(GetWindow());
- }
-
- // Dispatch observer notification to notify observers page is shown.
- nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
- if (os) {
- nsIPrincipal *principal = GetPrincipal();
- os->NotifyObservers(static_cast<nsIDocument*>(this),
- nsContentUtils::IsSystemPrincipal(principal) ?
- "chrome-page-shown" :
- "content-page-shown",
- nullptr);
- }
-
- DispatchPageTransition(target, NS_LITERAL_STRING("pageshow"), aPersisted);
+ if (!mIsBeingUsedAsImage) {
+ // Dispatch observer notification to notify observers page is shown.
+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+ if (os) {
+ nsIPrincipal *principal = GetPrincipal();
+ os->NotifyObservers(static_cast<nsIDocument*>(this),
+ nsContentUtils::IsSystemPrincipal(principal) ?
+ "chrome-page-shown" :
+ "content-page-shown",
+ nullptr);
+ }
+
+ nsCOMPtr<EventTarget> target = aDispatchStartTarget;
+ if (!target) {
+ target = do_QueryInterface(GetWindow());
+ }
+ DispatchPageTransition(target, NS_LITERAL_STRING("pageshow"), aPersisted);
+ }
}
static bool
NotifyPageHide(nsIDocument* aDocument, void* aData)
{
const bool* aPersistedPtr = static_cast<const bool*>(aData);
aDocument->OnPageHide(*aPersistedPtr, nullptr);
return true;
@@ -9101,36 +9102,37 @@ nsDocument::OnPageHide(bool aPersisted,
// when the page is refreshing while being dragged out
nsDocShell* docShell = mDocumentContainer.get();
if (aPersisted && !(docShell && docShell->InFrameSwap())) {
ImageTracker()->SetAnimatingState(false);
}
ExitPointerLock();
- // Now send out a PageHide event.
- nsCOMPtr<EventTarget> target = aDispatchStartTarget;
- if (!target) {
- target = do_QueryInterface(GetWindow());
- }
-
- // Dispatch observer notification to notify observers page is hidden.
- nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
- if (os) {
- nsIPrincipal* principal = GetPrincipal();
- os->NotifyObservers(static_cast<nsIDocument*>(this),
- nsContentUtils::IsSystemPrincipal(principal) ?
- "chrome-page-hidden" :
- "content-page-hidden",
- nullptr);
- }
-
- {
- PageUnloadingEventTimeStamp timeStamp(this);
- DispatchPageTransition(target, NS_LITERAL_STRING("pagehide"), aPersisted);
+ if (!mIsBeingUsedAsImage) {
+ // Dispatch observer notification to notify observers page is hidden.
+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+ if (os) {
+ nsIPrincipal* principal = GetPrincipal();
+ os->NotifyObservers(static_cast<nsIDocument*>(this),
+ nsContentUtils::IsSystemPrincipal(principal) ?
+ "chrome-page-hidden" :
+ "content-page-hidden",
+ nullptr);
+ }
+
+ // Now send out a PageHide event.
+ nsCOMPtr<EventTarget> target = aDispatchStartTarget;
+ if (!target) {
+ target = do_QueryInterface(GetWindow());
+ }
+ {
+ PageUnloadingEventTimeStamp timeStamp(this);
+ DispatchPageTransition(target, NS_LITERAL_STRING("pagehide"), aPersisted);
+ }
}
mVisible = false;
UpdateVisibilityState();
EnumerateExternalResources(NotifyPageHide, &aPersisted);
EnumerateActivityObservers(NotifyActivityChanged, nullptr);