diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 393fa5da582..115088cf696 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -3259,18 +3259,8 @@ Element::RequestFullscreen(JSContext* aCx, JS::Handle aOptions, // spoof the browser chrome/window and phish logins etc. // Note that requests for fullscreen inside a web app's origin are exempt // from this restriction. - const char* error = GetFullScreenError(OwnerDoc()); - if (error) { - nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, - NS_LITERAL_CSTRING("DOM"), OwnerDoc(), - nsContentUtils::eDOM_PROPERTIES, - error); - RefPtr asyncDispatcher = - new AsyncEventDispatcher(OwnerDoc(), - NS_LITERAL_STRING("mozfullscreenerror"), - true, - false); - asyncDispatcher->PostDOMEvent(); + if (const char* error = GetFullScreenError(OwnerDoc())) { + OwnerDoc()->DispatchFullscreenError(error); return; } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 476f304be4c..d67069227bd 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -11354,20 +11354,17 @@ nsDocument::AsyncRequestFullScreen(UniquePtr&& aRequest) NS_DispatchToCurrentThread(event); } -static void -LogFullScreenDenied(bool aLogFailure, const char* aMessage, nsIDocument* aDoc) +void +nsIDocument::DispatchFullscreenError(const char* aMessage) { - if (!aLogFailure) { - return; - } RefPtr asyncDispatcher = - new AsyncEventDispatcher(aDoc, + new AsyncEventDispatcher(this, NS_LITERAL_STRING("mozfullscreenerror"), true, false); asyncDispatcher->PostDOMEvent(); nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, - NS_LITERAL_CSTRING("DOM"), aDoc, + NS_LITERAL_CSTRING("DOM"), this, nsContentUtils::eDOM_PROPERTIES, aMessage); } @@ -11610,30 +11607,30 @@ nsDocument::FullscreenElementReadyCheck(Element* aElement, return false; } if (!aElement->IsInDoc()) { - LogFullScreenDenied(true, "FullScreenDeniedNotInDocument", this); + DispatchFullscreenError("FullScreenDeniedNotInDocument"); return false; } if (aElement->OwnerDoc() != this) { - LogFullScreenDenied(true, "FullScreenDeniedMovedDocument", this); + DispatchFullscreenError("FullScreenDeniedMovedDocument"); return false; } if (!GetWindow()) { - LogFullScreenDenied(true, "FullScreenDeniedLostWindow", this); + DispatchFullscreenError("FullScreenDeniedLostWindow"); return false; } if (const char* msg = GetFullscreenError(this, aWasCallerChrome)) { - LogFullScreenDenied(true, msg, this); + DispatchFullscreenError(msg); return false; } if (GetFullscreenElement() && !nsContentUtils::ContentIsDescendantOf(aElement, GetFullscreenElement())) { // If this document is full-screen, only grant full-screen requests from // a descendant of the current full-screen element. - LogFullScreenDenied(true, "FullScreenDeniedNotDescendant", this); + DispatchFullscreenError("FullScreenDeniedNotDescendant"); return false; } if (!nsContentUtils::IsChromeDoc(this) && !IsInActiveTab(this)) { - LogFullScreenDenied(true, "FullScreenDeniedNotFocusedTab", this); + DispatchFullscreenError("FullScreenDeniedNotFocusedTab"); return false; } // Deny requests when a windowed plugin is focused. @@ -11647,7 +11644,7 @@ nsDocument::FullscreenElementReadyCheck(Element* aElement, if (focusedElement) { nsCOMPtr content = do_QueryInterface(focusedElement); if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(content)) { - LogFullScreenDenied(true, "FullScreenDeniedFocusedPlugin", this); + DispatchFullscreenError("FullScreenDeniedFocusedPlugin"); return false; } } diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 6fdcabf7c24..2156f3a5015 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1231,6 +1231,12 @@ public: */ static bool HandlePendingFullscreenRequests(nsIDocument* aDocument); + /** + * Dispatch fullscreenerror event and report the failure message to + * the console. + */ + void DispatchFullscreenError(const char* aMessage); + virtual void RequestPointerLock(Element* aElement) = 0; static void UnlockPointer(nsIDocument* aDoc = nullptr);