Bug 1137009 - Do not persist attributes of xul window if the window is in fullscreen. r=janv

This commit is contained in:
Xidorn Quan 2015-09-09 10:45:39 +10:00
parent d7d49993cb
commit 0ade7a7b49
2 changed files with 39 additions and 11 deletions

View File

@ -924,6 +924,23 @@ XULDocument::AttributeWillChange(nsIDocument* aDocument,
} }
} }
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 void
XULDocument::AttributeChanged(nsIDocument* aDocument, XULDocument::AttributeChanged(nsIDocument* aDocument,
Element* aElement, int32_t aNameSpaceID, Element* aElement, int32_t aNameSpaceID,
@ -999,18 +1016,19 @@ XULDocument::AttributeChanged(nsIDocument* aDocument,
bool listener, resolved; bool listener, resolved;
CheckBroadcasterHookup(aElement, &listener, &resolved); CheckBroadcasterHookup(aElement, &listener, &resolved);
// See if there is anything we need to persist in the localstore. if (ShouldPersistAttribute(aDocument, aElement)) {
// // See if there is anything we need to persist in the localstore.
// XXX Namespace handling broken :-( //
nsAutoString persist; // XXX Namespace handling broken :-(
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist); nsString persist;
if (!persist.IsEmpty()) { aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
// XXXldb This should check that it's a token, not just a substring. if (!persist.IsEmpty() &&
if (persist.Find(nsDependentAtomString(aAttribute)) >= 0) { // XXXldb This should check that it's a token, not just a substring.
persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs
<nsIContent*, int32_t, nsIAtom*> <nsIContent*, int32_t, nsIAtom*>
(this, &XULDocument::DoPersist, aElement, kNameSpaceID_None, (this, &XULDocument::DoPersist, aElement,
aAttribute)); kNameSpaceID_None, aAttribute));
} }
} }
} }

View File

@ -1436,6 +1436,16 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
if (!mDocShell) if (!mDocShell)
return NS_ERROR_FAILURE; 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(); nsCOMPtr<dom::Element> docShellElement = GetWindowDOMElement();
if (!docShellElement) if (!docShellElement)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;