Bug 1475262 - Only ignore XUL persist on top level windows. r?smaug draft
authorBrendan Dahl <brendan.dahl@gmail.com>
Thu, 12 Jul 2018 13:55:55 -0700
changeset 817553 1f187ed4016c982412aa47a2133c868248c8eb02
parent 814904 fa376bf17cc95539f5e37186977d760296fb5093
push id116104
push userbmo:bdahl@mozilla.com
push dateThu, 12 Jul 2018 20:56:13 +0000
reviewerssmaug
bugs1475262
milestone63.0a1
Bug 1475262 - Only ignore XUL persist on top level windows. r?smaug Fixes the incorrect assumption that all XUL <window> elements are top level windows and will have their attribute persistence handled by the nsXULWindow. An example of where this assumption fails is the password manager which opens a <window> within a sub dialog that has no nsXULWindow. MozReview-Commit-ID: 1f59QPIz42s
dom/xul/XULDocument.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1161,19 +1161,21 @@ XULDocument::Persist(Element* aElement, 
     if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
     }
 
     if (hasAttr && valuestr.IsEmpty()) {
         return mLocalStore->RemoveValue(uri, id, attrstr);
     }
 
-    // Persisting attributes to windows is handled by nsXULWindow.
+    // Persisting attributes to top level windows is handled by nsXULWindow.
     if (aElement->IsXULElement(nsGkAtoms::window)) {
-        return NS_OK;
+        if (nsCOMPtr<nsIXULWindow> win = GetXULWindowIfToplevelChrome()) {
+           return NS_OK;
+        }
     }
 
     return mLocalStore->SetValue(uri, id, attrstr, valuestr);
 }
 
 
 nsresult
 XULDocument::GetViewportSize(int32_t* aWidth,
@@ -1753,19 +1755,22 @@ XULDocument::ApplyPersistentAttributesTo
 
         uint32_t cnt = aElements.Count();
         for (int32_t i = int32_t(cnt) - 1; i >= 0; --i) {
             RefPtr<Element> element = aElements.SafeObjectAt(i);
             if (!element) {
                  continue;
             }
 
-            // Applying persistent attributes to windows is handled by nsXULWindow.
+            // Applying persistent attributes to top level windows is handled
+            // by nsXULWindow.
             if (element->IsXULElement(nsGkAtoms::window)) {
-                continue;
+                if (nsCOMPtr<nsIXULWindow> win = GetXULWindowIfToplevelChrome()) {
+                    continue;
+                }
             }
 
             Unused << element->SetAttr(kNameSpaceID_None, attr, value, true);
         }
     }
 
     return NS_OK;
 }