Bug 716107 part 3 - Don't dispatch 'MozShowFullScreenWarning' event upon keypress in DOM fullscreen mode. r=smaug

This commit is contained in:
Chris Pearce 2012-05-09 09:47:18 +12:00
parent 1379e2c7dc
commit b3d3b85810
5 changed files with 61 additions and 70 deletions

View File

@ -614,10 +614,17 @@ public:
static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix,
nsIAtom **aTagName, PRInt32 *aNameSpaceID);
// Get a permission-manager setting for the given uri and type.
// Get a permission-manager setting for the given principal and type.
// If the pref doesn't exist or if it isn't ALLOW_ACTION, false is
// returned, otherwise true is returned.
static bool IsSitePermAllow(nsIURI* aURI, const char* aType);
// returned, otherwise true is returned. Always returns true for the
// system principal, and false for a null principal.
static bool IsSitePermAllow(nsIPrincipal* aPrincipal, const char* aType);
// Get a permission-manager setting for the given principal and type.
// If the pref doesn't exist or if it isn't DENY_ACTION, false is
// returned, otherwise true is returned. Always returns false for the
// system principal, and true for a null principal.
static bool IsSitePermDeny(nsIPrincipal* aPrincipal, const char* aType);
static nsILineBreaker* LineBreaker()
{

View File

@ -2801,18 +2801,44 @@ nsContentUtils::IsDraggableLink(const nsIContent* aContent) {
return aContent->IsLink(getter_AddRefs(absURI));
}
bool
nsContentUtils::IsSitePermAllow(nsIURI* aURI, const char* aType)
static bool
TestSitePerm(nsIPrincipal* aPrincipal, const char* aType, PRUint32 aPerm)
{
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
// System principal is always allowed and never denied permission.
return aPerm == nsIPermissionManager::ALLOW_ACTION;
}
nsCOMPtr<nsIURI> uri;
if (NS_FAILED(!aPrincipal ||
aPrincipal->GetURI(getter_AddRefs(uri))) ||
!uri) {
// We always deny (i.e. don't allow) the permission if we don't
// have a principal or we don't know the URI.
return aPerm != nsIPermissionManager::ALLOW_ACTION;
}
nsCOMPtr<nsIPermissionManager> permMgr =
do_GetService("@mozilla.org/permissionmanager;1");
NS_ENSURE_TRUE(permMgr, false);
PRUint32 perm;
nsresult rv = permMgr->TestPermission(aURI, aType, &perm);
nsresult rv = permMgr->TestPermission(uri, aType, &perm);
NS_ENSURE_SUCCESS(rv, false);
return perm == nsIPermissionManager::ALLOW_ACTION;
return perm == aPerm;
}
bool
nsContentUtils::IsSitePermAllow(nsIPrincipal* aPrincipal, const char* aType)
{
return TestSitePerm(aPrincipal, aType, nsIPermissionManager::ALLOW_ACTION);
}
bool
nsContentUtils::IsSitePermDeny(nsIPrincipal* aPrincipal, const char* aType)
{
return TestSitePerm(aPrincipal, aType, nsIPermissionManager::DENY_ACTION);
}
static const char *gEventNames[] = {"event"};
@ -6326,7 +6352,7 @@ nsContentUtils::AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal)
return princURI &&
((sAllowXULXBL_for_file && SchemeIs(princURI, "file")) ||
IsSitePermAllow(princURI, "allowXULXBL"));
IsSitePermAllow(aPrincipal, "allowXULXBL"));
}
already_AddRefed<nsIDocumentLoaderFactory>

View File

@ -6482,6 +6482,20 @@ nsINode::Length() const
}
}
static const char*
GetFullScreenError(nsIDocument* aDoc)
{
if (!nsContentUtils::IsRequestFullScreenAllowed()) {
return "FullScreenDeniedNotInputDriven";
}
if (nsContentUtils::IsSitePermDeny(aDoc->NodePrincipal(), "fullscreen")) {
return "FullScreenDeniedBlocked";
}
return nsnull;
}
nsresult nsGenericElement::MozRequestFullScreen()
{
// Only grant full-screen requests if this is called from inside a trusted
@ -6489,11 +6503,12 @@ nsresult nsGenericElement::MozRequestFullScreen()
// 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.
if (!nsContentUtils::IsRequestFullScreenAllowed()) {
const char* error = GetFullScreenError(OwnerDoc());
if (error) {
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
"DOM", OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES,
"FullScreenDeniedNotInputDriven");
error);
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(OwnerDoc(),
NS_LITERAL_STRING("mozfullscreenerror"),

View File

@ -116,6 +116,7 @@ nsIDOMWindowInternalWarning=Use of nsIDOMWindowInternal is deprecated. Use nsIDO
InputEncodingWarning=Use of inputEncoding is deprecated.
# LOCALIZATION NOTE: Do not translate "MozBeforePaint" and "mozRequestAnimationFrame"
MozBeforePaintWarning=MozBeforePaint events are no longer supported. mozRequestAnimationFrame must be passed a non-null callback argument.
FullScreenDeniedBlocked=Request for full-screen was denied because this domain has been blocked from full-screen by user.
FullScreenDeniedDisabled=Request for full-screen was denied because full-screen API is disabled by user preference.
FullScreenDeniedFocusedPlugin=Request for full-screen was denied because a windowed plugin is focused.
FullScreenDeniedHidden=Request for full-screen was denied because the document is no longer visible.

View File

@ -6227,56 +6227,6 @@ static bool CanHandleContextMenuEvent(nsMouseEvent* aMouseEvent,
return true;
}
static bool
IsFullScreenAndRestrictedKeyEvent(nsIContent* aTarget, const nsEvent* aEvent)
{
NS_ABORT_IF_FALSE(aEvent, "Must have an event to check.");
// Bail out if the event is not a key event, or the target's document is
// not in DOM full screen mode, or full-screen key input is not restricted.
nsIDocument *root = nsnull;
if (!aTarget ||
(aEvent->message != NS_KEY_DOWN &&
aEvent->message != NS_KEY_UP &&
aEvent->message != NS_KEY_PRESS) ||
!(root = nsContentUtils::GetRootDocument(aTarget->OwnerDoc())) ||
!root->IsFullScreenDoc()) {
return false;
}
// We're in full-screen mode. We whitelist key codes, and we will
// show a warning when keys not in this list are pressed.
const nsKeyEvent* keyEvent = static_cast<const nsKeyEvent*>(aEvent);
int key = keyEvent->keyCode ? keyEvent->keyCode : keyEvent->charCode;
switch (key) {
case NS_VK_TAB:
case NS_VK_SPACE:
case NS_VK_PAGE_UP:
case NS_VK_PAGE_DOWN:
case NS_VK_END:
case NS_VK_HOME:
case NS_VK_LEFT:
case NS_VK_UP:
case NS_VK_RIGHT:
case NS_VK_DOWN:
case NS_VK_SHIFT:
case NS_VK_CONTROL:
case NS_VK_ALT:
case NS_VK_META:
#ifdef XP_WIN
case VK_VOLUME_MUTE:
case VK_VOLUME_DOWN:
case VK_VOLUME_UP:
#endif
// Unrestricted key code.
return false;
default:
// Otherwise, fullscreen is enabled, key input is restricted, and the key
// code is not an allowed key code.
return true;
}
}
nsresult
PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus)
{
@ -6335,18 +6285,10 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus)
NS_EVENT_FLAG_ONLY_CHROME_DISPATCH);
if (aEvent->message == NS_KEY_UP) {
// ESC key released while in DOM full-screen mode.
// Exit full-screen mode.
// ESC key released while in DOM full-screen mode.
// Exit full-screen mode.
nsIDocument::ExitFullScreen(true);
}
} else if (IsFullScreenAndRestrictedKeyEvent(mCurrentEventContent, aEvent)) {
// Restricted key press while in DOM full-screen mode. Dispatch
// an event to chrome so it knows to show a warning message
// informing the user how to exit full-screen.
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(doc, NS_LITERAL_STRING("MozShowFullScreenWarning"),
true, true);
e->PostDOMEvent();
}
// Else not full-screen mode or key code is unrestricted, fall
// through to normal handling.