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
--- 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;
}