From a3fe1e9c45610f229f6c524f27dec42289af4bf6 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 17 Feb 2016 08:47:11 +0800 Subject: [PATCH] Bug 743198 part 3 - Refactor nsDocument::IsFullScreenEnabled to be static local function GetFullscreenError. r=smaug --- dom/base/nsDocument.cpp | 91 ++++++++++++++++++++--------------------- dom/base/nsDocument.h | 9 ---- 2 files changed, 45 insertions(+), 55 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 19f075009c0..476f304be4c 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -11558,6 +11558,48 @@ ReleaseVRDeviceProxyRef(void *, nsIAtom*, void *aPropertyValue, void *) } } +static bool +HasFullScreenSubDocument(nsIDocument* aDoc) +{ + uint32_t count = CountFullscreenSubDocuments(aDoc); + NS_ASSERTION(count <= 1, "Fullscreen docs should have at most 1 fullscreen child!"); + return count >= 1; +} + +// Returns nullptr if a request for Fullscreen API is currently enabled +// in the given document. Returns a static string indicates the reason +// why it is not enabled otherwise. +static const char* +GetFullscreenError(nsIDocument* aDoc, bool aCallerIsChrome) +{ + if (nsContentUtils::IsFullScreenApiEnabled() && aCallerIsChrome) { + // Chrome code can always use the full-screen API, provided it's not + // explicitly disabled. Note IsCallerChrome() returns true when running + // in an nsRunnable, so don't use GetMozFullScreenEnabled() from an + // nsRunnable! + return nullptr; + } + + if (!nsContentUtils::IsFullScreenApiEnabled()) { + return "FullScreenDeniedDisabled"; + } + if (!aDoc->IsVisible()) { + return "FullScreenDeniedHidden"; + } + if (HasFullScreenSubDocument(aDoc)) { + return "FullScreenDeniedSubDocFullScreen"; + } + + // Ensure that all containing elements are