Bug 687687 - Log helpful messages to web-console when full-screen is denied/revoked. r=bz

This commit is contained in:
Chris Pearce 2011-11-22 10:23:48 +13:00
Родитель 2e82ee83f4
Коммит 23007a032c
6 изменённых файлов: 87 добавлений и 17 удалений

Просмотреть файл

@ -8606,6 +8606,8 @@ public:
void
nsDocument::AsyncRequestFullScreen(Element* aElement)
{
NS_ASSERTION(aElement,
"Must pass non-null element to nsDocument::AsyncRequestFullScreen");
if (!aElement) {
return;
}
@ -8614,20 +8616,48 @@ nsDocument::AsyncRequestFullScreen(Element* aElement)
NS_DispatchToCurrentThread(event);
}
static void
LogFullScreenDenied(bool aLogFailure, const char* aMessage, nsIDocument* aDoc)
{
if (!aLogFailure) {
return;
}
nsRefPtr<nsPLDOMEvent> e =
new nsPLDOMEvent(aDoc,
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
e->PostDOMEvent();
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
aMessage,
nsnull, 0, nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM", aDoc);
}
void
nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome)
{
if (!aElement ||
!aElement->IsInDoc() ||
aElement->OwnerDoc() != this ||
!IsFullScreenEnabled(aWasCallerChrome) ||
!GetWindow()) {
nsRefPtr<nsPLDOMEvent> e =
new nsPLDOMEvent(this,
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
e->PostDOMEvent();
NS_ASSERTION(aElement,
"Must pass non-null element to nsDocument::RequestFullScreen");
if (!aElement) {
return;
}
if (!aElement->IsInDoc()) {
LogFullScreenDenied(true, "FullScreenDeniedNotInDocument", this);
return;
}
if (aElement->OwnerDoc() != this) {
LogFullScreenDenied(true, "FullScreenDeniedMovedDocument", this);
return;
}
if (!GetWindow()) {
LogFullScreenDenied(true, "FullScreenDeniedLostWindow", this);
return;
}
if (!IsFullScreenEnabled(aWasCallerChrome, true)) {
// IsFullScreenEnabled calls LogFullScreenDenied, no need to log.
return;
}
@ -8722,12 +8752,12 @@ NS_IMETHODIMP
nsDocument::GetMozFullScreenEnabled(bool *aFullScreen)
{
NS_ENSURE_ARG_POINTER(aFullScreen);
*aFullScreen = IsFullScreenEnabled(nsContentUtils::IsCallerChrome());
*aFullScreen = IsFullScreenEnabled(nsContentUtils::IsCallerChrome(), false);
return NS_OK;
}
bool
nsDocument::IsFullScreenEnabled(bool aCallerIsChrome)
nsDocument::IsFullScreenEnabled(bool aCallerIsChrome, bool aLogFailure)
{
if (nsContentUtils::IsFullScreenApiEnabled() && aCallerIsChrome) {
// Chrome code can always use the full-screen API, provided it's not
@ -8737,9 +8767,16 @@ nsDocument::IsFullScreenEnabled(bool aCallerIsChrome)
return true;
}
if (!nsContentUtils::IsFullScreenApiEnabled() ||
nsContentUtils::HasPluginWithUncontrolledEventDispatch(this) ||
!IsVisible()) {
if (!nsContentUtils::IsFullScreenApiEnabled()) {
LogFullScreenDenied(aLogFailure, "FullScreenDeniedDisabled", this);
return false;
}
if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(this)) {
LogFullScreenDenied(aLogFailure, "FullScreenDeniedPlugins", this);
return false;
}
if (!IsVisible()) {
LogFullScreenDenied(aLogFailure, "FullScreenDeniedHidden", this);
return false;
}
@ -8753,6 +8790,7 @@ nsDocument::IsFullScreenEnabled(bool aCallerIsChrome)
// The node requesting fullscreen, or one of its crossdoc ancestors,
// is an iframe which doesn't have the "mozalllowfullscreen" attribute.
// This request is not authorized by the parent document.
LogFullScreenDenied(aLogFailure, "FullScreenDeniedIframeDisallowed", this);
return false;
}
node = nsContentUtils::GetCrossDocParentNode(node);

Просмотреть файл

@ -978,7 +978,9 @@ protected:
// 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.
bool IsFullScreenEnabled(bool aIsCallerChrome);
// 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

Просмотреть файл

@ -3067,6 +3067,12 @@ nsGenericElement::UnbindFromTree(bool aDeep, bool aNullParent)
if (IsFullScreenAncestor(this)) {
// The element being removed is an ancestor of the full-screen element,
// exit full-screen state.
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
"RemovedFullScreenElement",
nsnull, 0, nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM", OwnerDoc());
OwnerDoc()->CancelFullScreen();
}
if (GetParent()) {

Просмотреть файл

@ -118,6 +118,7 @@
#include "nsHTMLFieldSetElement.h"
#include "nsHTMLMenuElement.h"
#include "nsPLDOMEvent.h"
#include "nsIScriptError.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/FromParser.h"
@ -3468,6 +3469,12 @@ nsresult nsGenericHTMLElement::MozRequestFullScreen()
// and it also makes it harder for bad guys' script to go full-screen and
// spoof the browser chrome/window and phish logins etc.
if (!nsContentUtils::IsRequestFullScreenAllowed()) {
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
"FullScreenDeniedNotInputDriven",
nsnull, 0, nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM", OwnerDoc());
nsRefPtr<nsPLDOMEvent> e =
new nsPLDOMEvent(OwnerDoc(),
NS_LITERAL_STRING("mozfullscreenerror"),

Просмотреть файл

@ -49,6 +49,7 @@
#include "nsThreadUtils.h"
#include "nsIDOMGetSVGDocument.h"
#include "nsIDOMSVGDocument.h"
#include "nsIScriptError.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -297,6 +298,12 @@ nsHTMLSharedObjectElement::BindToTree(nsIDocument *aDocument,
// to prevent phishing attacks.
NS_DispatchToCurrentThread(
NS_NewRunnableMethod(aDocument, &nsIDocument::CancelFullScreen));
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
"AddedWindowedPluginWhileFullScreen",
nsnull, 0, nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM", aDocument);
}
#endif
return NS_OK;

Просмотреть файл

@ -115,5 +115,15 @@ nsIJSONEncodeDeprecatedWarning=nsIJSON.encode is deprecated. Please use JSON.st
nsIDOMWindowInternalWarning=Use of nsIDOMWindowInternal is deprecated. Use nsIDOMWindow instead.
InputEncodingWarning=Use of inputEncoding is deprecated.
GlobalStorageWarning=Use of globalStorage is deprecated. Please use localStorage instead.
FullScreenDeniedDisabled=Request for full-screen was denied because full-screen API is disabled by user preference.
FullScreenDeniedPlugins=Request for full-screen was denied because a document on this page contains a windowed plugin.
FullScreenDeniedHidden=Request for full-screen was denied because the document is no longer visible.
FullScreenDeniedIframeDisallowed=Request for full-screen was denied because at least one of the document's containing iframes does not have a "mozallowfullscreen" attribute.
FullScreenDeniedNotInputDriven=Request for full-screen was denied because Element.mozRequestFullScreen() was not called from inside a short running user-generated event handler.
FullScreenDeniedNotInDocument=Request for full-screen was denied because requesting element is no longer in its document.
FullScreenDeniedMovedDocument=Request for full-screen was denied because requesting element has moved document.
FullScreenDeniedLostWindow=Request for full-screen was denied because we no longer have a window.
RemovedFullScreenElement=Exited full-screen because full-screen element was removed from document.
AddedWindowedPluginWhileFullScreen=Exited full-screen because windowed plugin was added to document.
HTMLMultipartXHRWarning=HTML parsing in XMLHttpRequest is not supported for multipart responses.
HTMLSyncXHRWarning=HTML parsing in XMLHttpRequest is not supported in the synchronous mode.