Back out bug 818371 because what we used to do actually matches the spec.
authorBoris Zbarsky <bzbarsky@mit.edu>
Sun, 16 Dec 2012 00:16:47 -0500
changeset 121760 3f93a72920e07d74fd3b6a71199e2f60c6290f62
parent 121759 1fb70af2d687199712cb861372ffe4fc098b716b
child 121761 3e4e600adc3bd5d36e995881211e36552e13ab94
push idunknown
push userunknown
push dateunknown
bugs818371
milestone20.0a1
Back out bug 818371 because what we used to do actually matches the spec.
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
docshell/base/nsDocShell.cpp
docshell/test/chrome/Makefile.in
docshell/test/chrome/test_bug818371.xul
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -74,18 +74,18 @@ class ImageLoader;
 
 namespace dom {
 class Link;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 #define NS_IDOCUMENT_IID \
-{ 0xcb362f1b, 0x8a05, 0x4d4f, \
-  { 0x90, 0x63, 0xf2, 0x5f, 0x8b, 0x8c, 0xb2, 0xe1 } }
+{ 0x1517f31a, 0x0ef9, 0x4629, \
+ { 0xb4, 0x7f, 0x56, 0x31, 0x0d, 0x80, 0x61, 0xaf } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 // Enum for requesting a particular type of document when creating a doc
 enum DocumentFlavor {
   DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
   DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
@@ -1680,19 +1680,17 @@ public:
 #define DEPRECATED_OPERATION(_op) e##_op,
   enum DeprecatedOperations {
 #include "nsDeprecatedOperationList.h"
     eDeprecatedOperationCount
   };
 #undef DEPRECATED_OPERATION
   void WarnOnceAbout(DeprecatedOperations aOperation, bool asError = false);
 
-  // This method may fire a DOM event; if it does so it will happen
-  // synchronously if aFireEventSync is true, asynchronously otherwise.
-  virtual void UpdateVisibilityState(bool aFireEventSync) = 0;
+  virtual void PostVisibilityUpdateEvent() = 0;
   
   bool IsSyntheticDocument() { return mIsSyntheticDocument; }
 
   void SetNeedLayoutFlush() {
     mNeedLayoutFlush = true;
     if (mDisplayDocument) {
       mDisplayDocument->SetNeedLayoutFlush();
     }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -7060,17 +7060,17 @@ nsDocument::OnPageShow(bool aPersisted,
   if (mAnimationController) {
     mAnimationController->OnPageShow();
   }
 
   if (aPersisted) {
     SetImagesNeedAnimating(true);
   }
 
-  UpdateVisibilityState(true);
+  UpdateVisibilityState();
 
   nsCOMPtr<nsIDOMEventTarget> target = aDispatchStartTarget;
   if (!target) {
     target = do_QueryInterface(GetWindow());
   }
   DispatchPageTransition(target, NS_LITERAL_STRING("pageshow"), aPersisted);
 }
 
@@ -7122,17 +7122,17 @@ nsDocument::OnPageHide(bool aPersisted,
   nsCOMPtr<nsIDOMEventTarget> target = aDispatchStartTarget;
   if (!target) {
     target = do_QueryInterface(GetWindow());
   }
   DispatchPageTransition(target, NS_LITERAL_STRING("pagehide"), aPersisted);
 
   mVisible = false;
 
-  UpdateVisibilityState(true);
+  UpdateVisibilityState();
 
   EnumerateExternalResources(NotifyPageHide, &aPersisted);
   EnumerateFreezableElements(NotifyActivityChanged, nullptr);
 
   if (IsFullScreenDoc()) {
     // A full-screen doc has been hidden. We need to ensure we exit
     // full-screen, i.e. remove full-screen state from all full-screen
     // documents, and exit the top-level window from full-screen mode.
@@ -9480,47 +9480,35 @@ nsDocument::GetMozPointerLockElement(nsI
   }
 #define TOUCH_EVENT EVENT
 #define DOCUMENT_ONLY_EVENT EVENT
 #include "nsEventNameList.h"
 #undef DOCUMENT_ONLY_EVENT
 #undef TOUCH_EVENT
 #undef EVENT
 
-/* virtual */ void
-nsDocument::UpdateVisibilityState(bool aFireEventSync)
+void
+nsDocument::UpdateVisibilityState()
 {
   VisibilityState oldState = mVisibilityState;
   mVisibilityState = GetVisibilityState();
   if (oldState != mVisibilityState) {
-    if (aFireEventSync) {
-      FireVisibilityChangeEvent();
-    } else {
-      nsCOMPtr<nsIRunnable> event =
-        NS_NewRunnableMethod(this, &nsDocument::FireVisibilityChangeEvent);
-      NS_DispatchToMainThread(event);
-    }
+    nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
+                                         NS_LITERAL_STRING("visibilitychange"),
+                                         /* bubbles = */ true,
+                                         /* cancelable = */ false);
+    nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
+                                         NS_LITERAL_STRING("mozvisibilitychange"),
+                                         /* bubbles = */ true,
+                                         /* cancelable = */ false);
 
     EnumerateFreezableElements(NotifyActivityChanged, nullptr);
   }
 }
 
-void
-nsDocument::FireVisibilityChangeEvent()
-{
-  nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
-                                       NS_LITERAL_STRING("visibilitychange"),
-                                       /* bubbles = */ true,
-                                       /* cancelable = */ false);
-  nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
-                                       NS_LITERAL_STRING("mozvisibilitychange"),
-                                       /* bubbles = */ true,
-                                       /* cancelable = */ false);
-}
-
 nsDocument::VisibilityState
 nsDocument::GetVisibilityState() const
 {
   // We have to check a few pieces of information here:
   // 1)  Are we in bfcache (!IsVisible())?  If so, nothing else matters.
   // 2)  Do we have an outer window?  If not, we're hidden.  Note that we don't
   //     want to use GetWindow here because it does weird groveling for windows
   //     in some cases.
@@ -9529,16 +9517,24 @@ nsDocument::GetVisibilityState() const
   if (!IsVisible() || !mWindow || !mWindow->GetOuterWindow() ||
       mWindow->GetOuterWindow()->IsBackground()) {
     return eHidden;
   }
 
   return eVisible;
 }
 
+/* virtual */ void
+nsDocument::PostVisibilityUpdateEvent()
+{
+  nsCOMPtr<nsIRunnable> event =
+    NS_NewRunnableMethod(this, &nsDocument::UpdateVisibilityState);
+  NS_DispatchToMainThread(event);
+}
+
 NS_IMETHODIMP
 nsDocument::GetMozHidden(bool* aHidden)
 {
   WarnOnceAbout(ePrefixedVisibilityAPI);
   return GetHidden(aHidden);
 }
 
 NS_IMETHODIMP
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -990,18 +990,21 @@ public:
   // Returns the top element from the full-screen stack.
   Element* FullScreenStackTop();
 
   void RequestPointerLock(Element* aElement);
   bool ShouldLockPointer(Element* aElement);
   bool SetPointerLock(Element* aElement, int aCursorStyle);
   static void UnlockPointer();
 
-  virtual void UpdateVisibilityState(bool aFireEventSync);
-  void FireVisibilityChangeEvent();
+  // This method may fire a DOM event; if it does so it will happen
+  // synchronously.
+  void UpdateVisibilityState();
+  // Posts an event to call UpdateVisibilityState
+  virtual void PostVisibilityUpdateEvent();
 
   virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
   // DocSizeOfIncludingThis is inherited from nsIDocument.
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   friend class nsNodeUtils;
 
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5214,17 +5214,17 @@ nsDocShell::SetIsActive(bool aIsActive)
     pshell->SetIsActive(aIsActive);
 
   // Tell the window about it
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mScriptGlobal);
   if (win) {
       win->SetIsBackground(!aIsActive);
       nsCOMPtr<nsIDocument> doc = do_QueryInterface(win->GetExtantDocument());
       if (doc) {
-          doc->UpdateVisibilityState(false);
+          doc->PostVisibilityUpdateEvent();
       }
   }
 
   // Recursively tell all of our children, but don't tell <iframe mozbrowser>
   // children; they handle their state separately.
   int32_t n = mChildList.Count();
   for (int32_t i = 0; i < n; ++i) {
       nsCOMPtr<nsIDocShell> docshell = do_QueryInterface(ChildAt(i));
--- a/docshell/test/chrome/Makefile.in
+++ b/docshell/test/chrome/Makefile.in
@@ -91,17 +91,16 @@ MOCHITEST_CHROME_FILES =	\
 		test_bug311007.xul \
 		bug311007_window.xul \
 		test_principalInherit.xul \
 		test_mozFrameType.xul \
 		mozFrameType_window.xul \
 		test_bug789773.xul \
 		test_bug754029.xul \
 		bug754029_window.xul \
-		test_bug818371.xul \
     docshell_helpers.js \
     generic.html \
     $(NULL)
 
 ifneq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 MOCHITEST_CHROME_FILES += \
 		test_bug454235.xul \
 		$(NULL)
deleted file mode 100644
--- a/docshell/test/chrome/test_bug818371.xul
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
-<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=818371
--->
-<window title="Mozilla Bug 818371"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
-
-  <!-- test results are displayed in the html:body -->
-  <body xmlns="http://www.w3.org/1999/xhtml">
-  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=818371"
-     target="_blank">Mozilla Bug 818371</a>
-  </body>
-
-  <browser id="b" src="data:text/html,&lt;iframe&gt;&lt;/iframe&gt;"></browser>
-
-  <!-- test code goes here -->
-  <script type="application/javascript">
-  <![CDATA[
-  /** Test for Bug 818371 **/
-  SimpleTest.waitForExplicitFinish();
-  addLoadEvent(function() {
-    function listener(e) {
-      ok(e.target.hidden, "Document should now be hidden");
-      ok(e.target.defaultView.frames[0].document.hidden,
-         "Subdocument should now be hidden");
-      e.target.removeEventListener("visibilitychange", listener);
-      SimpleTest.finish();
-    }
-
-    var doc = frames[0].document;
-    ok(!doc.hidden, "Document should be visible");
-    ok(!frames[0].frames[0].document.hidden,
-       "Subdocument should now be hidden");
-    doc.addEventListener("visibilitychange", listener);
-    $("b").docShell.isActive = false;
-  });
-
-  ]]>
-  </script>
-</window>