Bug 743198 part 3 - Refactor nsDocument::IsFullScreenEnabled to be static local function GetFullscreenError.
MozReview-Commit-ID: 35xuB34dwz5
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -11553,16 +11553,58 @@ nsresult nsDocument::RemoteFrameFullscre
static void
ReleaseVRDeviceProxyRef(void *, nsIAtom*, void *aPropertyValue, void *)
{
if (aPropertyValue) {
static_cast<gfx::VRDeviceProxy*>(aPropertyValue)->Release();
}
}
+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 <iframe> and have
+ // allowfullscreen attribute set.
+ nsCOMPtr<nsIDocShell> docShell(aDoc->GetDocShell());
+ if (!docShell || !docShell->GetFullscreenAllowed()) {
+ return "FullScreenDeniedContainerNotAllowed";
+ }
+
+ return nullptr;
+}
+
bool
nsDocument::FullscreenElementReadyCheck(Element* aElement,
bool aWasCallerChrome)
{
NS_ASSERTION(aElement,
"Must pass non-null element to nsDocument::RequestFullScreen");
if (!aElement || aElement == GetFullscreenElement()) {
return false;
@@ -11574,18 +11616,18 @@ nsDocument::FullscreenElementReadyCheck(
if (aElement->OwnerDoc() != this) {
LogFullScreenDenied(true, "FullScreenDeniedMovedDocument", this);
return false;
}
if (!GetWindow()) {
LogFullScreenDenied(true, "FullScreenDeniedLostWindow", this);
return false;
}
- if (!IsFullScreenEnabled(aWasCallerChrome, true)) {
- // IsFullScreenEnabled calls LogFullScreenDenied, no need to log.
+ if (const char* msg = GetFullscreenError(this, aWasCallerChrome)) {
+ LogFullScreenDenied(true, msg, this);
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);
return false;
@@ -11984,60 +12026,17 @@ nsDocument::GetMozFullScreenEnabled(bool
NS_ENSURE_ARG_POINTER(aFullScreen);
*aFullScreen = FullscreenEnabled();
return NS_OK;
}
bool
nsDocument::FullscreenEnabled()
{
- return IsFullScreenEnabled(nsContentUtils::IsCallerChrome(), false);
-}
-
-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;
-}
-
-bool
-nsDocument::IsFullScreenEnabled(bool aCallerIsChrome, bool aLogFailure)
-{
- 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 true;
- }
-
- if (!nsContentUtils::IsFullScreenApiEnabled()) {
- LogFullScreenDenied(aLogFailure, "FullScreenDeniedDisabled", this);
- return false;
- }
- if (!IsVisible()) {
- LogFullScreenDenied(aLogFailure, "FullScreenDeniedHidden", this);
- return false;
- }
- if (HasFullScreenSubDocument(this)) {
- LogFullScreenDenied(aLogFailure, "FullScreenDeniedSubDocFullScreen", this);
- return false;
- }
-
- // Ensure that all containing elements are <iframe> and have
- // allowfullscreen attribute set.
- nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
- if (!docShell || !docShell->GetFullscreenAllowed()) {
- LogFullScreenDenied(aLogFailure, "FullScreenDeniedContainerNotAllowed", this);
- return false;
- }
-
- return true;
+ return !GetFullscreenError(this, nsContentUtils::IsCallerChrome());
}
uint16_t
nsDocument::CurrentOrientationAngle() const
{
return mCurrentOrientationAngle;
}
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1413,25 +1413,16 @@ protected:
void DecreaseStackRefCnt()
{
if (--mStackRefCnt == 0 && mNeedsReleaseAfterStackRefCntRelease) {
mNeedsReleaseAfterStackRefCntRelease = false;
NS_RELEASE_THIS();
}
}
- // Returns true if a request for DOM full-screen is currently enabled in
- // this document. This returns true if there are no windowed plugins in this
- // doc tree, and if the document is visible, and if the api is not
- // disabled by pref. aIsCallerChrome must contain the return value of
- // nsContentUtils::IsCallerChrome() from the context we're checking.
- // If aLogFailure is true, an appropriate warning message is logged to the
- // console, and a "mozfullscreenerror" event is dispatched to this document.
- bool IsFullScreenEnabled(bool aIsCallerChrome, bool aLogFailure);
-
/**
* Check that aId is not empty and log a message to the console
* service if it is.
* @returns true if aId looks correct, false otherwise.
*/
inline bool CheckGetElementByIdArg(const nsAString& aId)
{
if (aId.IsEmpty()) {