Bug 743198 part 3 - Refactor nsDocument::IsFullScreenEnabled to be static local function GetFullscreenError. r=smaug

This commit is contained in:
Xidorn Quan 2016-02-17 08:47:11 +08:00
parent be1c4afde9
commit a3fe1e9c45
2 changed files with 45 additions and 55 deletions

View File

@ -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 <iframe> and have
// allowfullscreen attribute set.
nsCOMPtr<nsIDocShell> docShell(aDoc->GetDocShell());
if (!docShell || !docShell->GetFullscreenAllowed()) {
return "FullScreenDeniedContainerNotAllowed";
}
return nullptr;
}
bool bool
nsDocument::FullscreenElementReadyCheck(Element* aElement, nsDocument::FullscreenElementReadyCheck(Element* aElement,
bool aWasCallerChrome) bool aWasCallerChrome)
@ -11579,8 +11621,8 @@ nsDocument::FullscreenElementReadyCheck(Element* aElement,
LogFullScreenDenied(true, "FullScreenDeniedLostWindow", this); LogFullScreenDenied(true, "FullScreenDeniedLostWindow", this);
return false; return false;
} }
if (!IsFullScreenEnabled(aWasCallerChrome, true)) { if (const char* msg = GetFullscreenError(this, aWasCallerChrome)) {
// IsFullScreenEnabled calls LogFullScreenDenied, no need to log. LogFullScreenDenied(true, msg, this);
return false; return false;
} }
if (GetFullscreenElement() && if (GetFullscreenElement() &&
@ -11989,50 +12031,7 @@ nsDocument::GetMozFullScreenEnabled(bool *aFullScreen)
bool bool
nsDocument::FullscreenEnabled() nsDocument::FullscreenEnabled()
{ {
return IsFullScreenEnabled(nsContentUtils::IsCallerChrome(), false); return !GetFullscreenError(this, nsContentUtils::IsCallerChrome());
}
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;
} }
uint16_t uint16_t

View File

@ -1418,15 +1418,6 @@ protected:
} }
} }
// 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 * Check that aId is not empty and log a message to the console
* service if it is. * service if it is.