Bug 743198 part 4 - Rename LogFullScreenDenied to nsIDocument::DispatchFullscreenError, and reuse it in Element::RequestFullscreen.
MozReview-Commit-ID: 7Tv74t5Q6n5
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -3254,28 +3254,18 @@ Element::RequestFullscreen(JSContext* aC
MOZ_ASSERT_IF(!aCx, aOptions.isNullOrUndefined());
// Only grant full-screen requests if this is called from inside a trusted
// event handler (i.e. inside an event handler for a user initiated event).
// This stops the full-screen from being abused similar to the popups of old,
// and it also makes it harder for bad guys' script to go full-screen and
// 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<AsyncEventDispatcher> asyncDispatcher =
- new AsyncEventDispatcher(OwnerDoc(),
- NS_LITERAL_STRING("mozfullscreenerror"),
- true,
- false);
- asyncDispatcher->PostDOMEvent();
+ if (const char* error = GetFullScreenError(OwnerDoc())) {
+ OwnerDoc()->DispatchFullscreenError(error);
return;
}
auto request = MakeUnique<FullscreenRequest>(this);
request->mIsCallerChrome = nsContentUtils::IsCallerChrome();
RequestFullscreenOptions fsOptions;
// We need to check if options is convertible to a dict first before
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -11349,30 +11349,27 @@ nsDocument::AsyncRequestFullScreen(Uniqu
return;
}
// Request full-screen asynchronously.
nsCOMPtr<nsIRunnable> event(new nsCallRequestFullScreen(Move(aRequest)));
NS_DispatchToCurrentThread(event);
}
-static void
-LogFullScreenDenied(bool aLogFailure, const char* aMessage, nsIDocument* aDoc)
-{
- if (!aLogFailure) {
- return;
- }
+void
+nsIDocument::DispatchFullscreenError(const char* aMessage)
+{
RefPtr<AsyncEventDispatcher> 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);
}
static void
UpdateViewportScrollbarOverrideForFullscreen(nsIDocument* aDoc)
{
if (nsIPresShell* presShell = aDoc->GetShell()) {
@@ -11605,54 +11602,54 @@ nsDocument::FullscreenElementReadyCheck(
bool aWasCallerChrome)
{
NS_ASSERTION(aElement,
"Must pass non-null element to nsDocument::RequestFullScreen");
if (!aElement || aElement == GetFullscreenElement()) {
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.
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm) {
NS_WARNING("Failed to retrieve focus manager in full-screen request.");
return false;
}
nsCOMPtr<nsIDOMElement> focusedElement;
fm->GetFocusedElement(getter_AddRefs(focusedElement));
if (focusedElement) {
nsCOMPtr<nsIContent> content = do_QueryInterface(focusedElement);
if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(content)) {
- LogFullScreenDenied(true, "FullScreenDeniedFocusedPlugin", this);
+ DispatchFullscreenError("FullScreenDeniedFocusedPlugin");
return false;
}
}
return true;
}
FullscreenRequest::FullscreenRequest(Element* aElement)
: mElement(aElement)
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1226,16 +1226,22 @@ public:
/**
* Handles any pending fullscreen in aDocument or its subdocuments.
*
* Returns whether there is any fullscreen request handled.
*/
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);
// ScreenOrientation related APIs
virtual void SetCurrentOrientation(mozilla::dom::OrientationType aType,
uint16_t aAngle) = 0;