From c1da559e350711a1fe8c83c2af1189434596f23f Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 15 Dec 2011 22:09:55 +0000 Subject: [PATCH] Backout 80831e4a10de (bug 706672) for build failures on a CLOSED TREE --- content/base/src/nsDocument.cpp | 72 +++----------- .../content/src/nsHTMLSharedObjectElement.cpp | 14 +++ .../content/test/file_fullscreen-plugins.html | 98 +++++++++++++------ dom/base/nsFocusManager.cpp | 20 ---- dom/locales/en-US/chrome/dom/dom.properties | 5 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 5 + .../chrome/dom_fullscreen_warning.xul | 10 +- .../chrome/test_dom_fullscreen_warning.xul | 3 +- 8 files changed, 108 insertions(+), 119 deletions(-) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index e0aeec74a18..54d3a2851ac 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -8801,43 +8801,6 @@ nsDocument::FullScreenStackTop() return element; } -static bool -IsInFocusedTab(nsIDocument* aDoc) -{ - nsIFocusManager* fm = nsFocusManager::GetFocusManager(); - if (!fm) { - return false; - } - - // Is there a focused DOMWindow? - nsCOMPtr focusedWindow; - fm->GetFocusedWindow(getter_AddRefs(focusedWindow)); - if (!focusedWindow) { - return false; - } - - // Retreive the focused document. - nsCOMPtr domDocument; - focusedWindow->GetDocument(getter_AddRefs(domDocument)); - nsCOMPtr focusedDoc = do_QueryInterface(domDocument); - - // When the chrome document is focused, only grant requests from the - // chrome document. - if (nsContentUtils::IsChromeDoc(focusedDoc)) { - return aDoc == focusedDoc; - } - - // Find the common ancestor of aDoc and the focused document. - nsIDocument* commonAncestor = GetCommonAncestor(focusedDoc, aDoc); - if (commonAncestor == focusedDoc || commonAncestor == aDoc) { - // The focused document is either above or below aDoc in the - // doctree. It must be in the same tab (doctree branch). - return true; - } - - return false; -} - void nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome) { @@ -8869,25 +8832,6 @@ nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome) LogFullScreenDenied(true, "FullScreenDeniedNotDescendant", this); return; } - if (!IsInFocusedTab(this)) { - LogFullScreenDenied(true, "FullScreenDeniedNotFocusedTab", this); - return; - } - // Deny requests when a windowed plugin is focused. - nsIFocusManager* fm = nsFocusManager::GetFocusManager(); - if (!fm) { - NS_WARNING("Failed to retrieve focus manager in full-screen request."); - return; - } - nsCOMPtr focusedElement; - fm->GetFocusedElement(getter_AddRefs(focusedElement)); - if (focusedElement) { - nsCOMPtr content = do_QueryInterface(focusedElement); - if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(content)) { - LogFullScreenDenied(true, "FullScreenDeniedFocusedPlugin", this); - return; - } - } // Stores a list of documents which we must dispatch "mozfullscreenchange" // too. We're required by the spec to dispatch the events in root-to-leaf @@ -8896,6 +8840,16 @@ nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome) // as specified. nsAutoTArray changed; + // If another top-level window is full-screen. Exit it from full-screen. + nsCOMPtr fullScreenDoc(do_QueryReferent(sFullScreenDoc)); + nsIDocument* commonAncestor = GetCommonAncestor(fullScreenDoc, this); + if (fullScreenDoc && !commonAncestor) { + // A document which doesn't have a common ancestor is full-screen, this + // must be in a separate browser window. Fully exit full-screen, to move + // the other browser window/doctree out of full-screen. + nsIDocument::ExitFullScreen(false); + } + // Remember the root document, so that if a full-screen document is hidden // we can reset full-screen state in the remaining visible full-screen documents. sFullScreenRootDoc = do_GetWeakReference(nsContentUtils::GetRootDocument(this)); @@ -8920,6 +8874,8 @@ nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome) changed.AppendElement(parent); child = parent; } else { + NS_ASSERTION(!commonAncestor || child == commonAncestor, + "Should finish loop at common ancestor (or null)"); // We've reached either the root, or a point in the doctree where the // new full-screen element container is the same as the previous // full-screen element's container. No more changes need to be made @@ -9032,6 +8988,10 @@ nsDocument::IsFullScreenEnabled(bool aCallerIsChrome, bool aLogFailure) LogFullScreenDenied(aLogFailure, "FullScreenDeniedDisabled", this); return false; } + if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(this)) { + LogFullScreenDenied(aLogFailure, "FullScreenDeniedPlugins", this); + return false; + } if (!IsVisible()) { LogFullScreenDenied(aLogFailure, "FullScreenDeniedHidden", this); return false; diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp index 0210e79ffd5..c25d8b4486d 100644 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -290,6 +290,20 @@ nsHTMLSharedObjectElement::BindToTree(nsIDocument *aDocument, nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, start)); } +#ifndef XP_MACOSX + if (aDocument && + aDocument->IsFullScreenDoc() && + nsContentUtils::HasPluginWithUncontrolledEventDispatch(this)) { + // This content contains a windowed plugin for which we don't control + // event dispatch, and we're in full-screen mode. Exit full-screen mode + // to prevent phishing attacks. + nsIDocument::ExitFullScreen(true); + nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, + "DOM", aDocument, + nsContentUtils::eDOM_PROPERTIES, + "AddedWindowedPluginWhileFullScreen"); + } +#endif return NS_OK; } diff --git a/content/html/content/test/file_fullscreen-plugins.html b/content/html/content/test/file_fullscreen-plugins.html index 9ed09ec43ee..f91480d5946 100644 --- a/content/html/content/test/file_fullscreen-plugins.html +++ b/content/html/content/test/file_fullscreen-plugins.html @@ -23,12 +23,11 @@ Test plugins with DOM full-screen API: - - + - - + + - +