Bug 1137009 - Do not persist attributes of xul window if the window is in fullscreen. r=janv
☠☠ backed out by 76826fe33431 ☠ ☠
authorXidorn Quan <quanxunzhen@gmail.com>
Wed, 09 Sep 2015 10:45:39 +1000
changeset 294059 873acda091b75ba8aee7f374cd8e6c8627d64494
parent 294058 53e7018a7b15ae3c352151d374037640be7b481c
child 294060 36cd6ef44a0d39604767db4d8c29978be6adea01
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1137009
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1137009 - Do not persist attributes of xul window if the window is in fullscreen. r=janv
dom/xul/XULDocument.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -919,16 +919,33 @@ XULDocument::AttributeWillChange(nsIDocu
     // See if we need to update our ref map.
     if (aAttribute == nsGkAtoms::ref) {
         // Might not need this, but be safe for now.
         nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
         RemoveElementFromRefMap(aElement);
     }
 }
 
+static bool
+ShouldPersistAttribute(nsIDocument* aDocument, Element* aElement)
+{
+    if (aElement->IsXULElement(nsGkAtoms::window)) {
+        if (nsCOMPtr<nsPIDOMWindow> window = aDocument->GetWindow()) {
+            bool isFullscreen;
+            window->GetFullScreen(&isFullscreen);
+            if (isFullscreen) {
+                // Don't persist attributes if it is window element and
+                // we are in fullscreen state.
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
 void
 XULDocument::AttributeChanged(nsIDocument* aDocument,
                               Element* aElement, int32_t aNameSpaceID,
                               nsIAtom* aAttribute, int32_t aModType,
                               const nsAttrValue* aOldValue)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
 
@@ -994,28 +1011,29 @@ XULDocument::AttributeChanged(nsIDocumen
             }
         }
     }
 
     // checks for modifications in broadcasters
     bool listener, resolved;
     CheckBroadcasterHookup(aElement, &listener, &resolved);
 
-    // See if there is anything we need to persist in the localstore.
-    //
-    // XXX Namespace handling broken :-(
-    nsAutoString persist;
-    aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
-    if (!persist.IsEmpty()) {
-        // XXXldb This should check that it's a token, not just a substring.
-        if (persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
+    if (ShouldPersistAttribute(aDocument, aElement)) {
+        // See if there is anything we need to persist in the localstore.
+        //
+        // XXX Namespace handling broken :-(
+        nsString persist;
+        aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
+        if (!persist.IsEmpty() &&
+            // XXXldb This should check that it's a token, not just a substring.
+            persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
             nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs
-              <nsIContent*, int32_t, nsIAtom*>
-              (this, &XULDocument::DoPersist, aElement, kNameSpaceID_None,
-               aAttribute));
+                <nsIContent*, int32_t, nsIAtom*>
+                (this, &XULDocument::DoPersist, aElement,
+                 kNameSpaceID_None, aAttribute));
         }
     }
 }
 
 void
 XULDocument::ContentAppended(nsIDocument* aDocument,
                              nsIContent* aContainer,
                              nsIContent* aFirstNewContent,
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1431,16 +1431,26 @@ void nsXULWindow::SyncAttributesToWidget
 
 NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
 {
   // can happen when the persistence timer fires at an inopportune time
   // during window shutdown
   if (!mDocShell)
     return NS_ERROR_FAILURE;
 
+  nsCOMPtr<nsIDOMWindow> domWindow;
+  GetWindowDOMWindow(getter_AddRefs(domWindow));
+  if (domWindow) {
+    bool isFullscreen;
+    domWindow->GetFullScreen(&isFullscreen);
+    if (isFullscreen) {
+      return NS_OK;
+    }
+  }
+
   nsCOMPtr<dom::Element> docShellElement = GetWindowDOMElement();
   if (!docShellElement)
     return NS_ERROR_FAILURE;
 
   nsAutoString   persistString;
   docShellElement->GetAttribute(PERSIST_ATTRIBUTE, persistString);
   if (persistString.IsEmpty()) { // quick check which sometimes helps
     mPersistentAttributesDirty = 0;