Bug 380637, move reserved key checking into ContentUtils so that it can be shared with menu accesskey checks , r=felipe

This commit is contained in:
Neil Deakin 2017-11-09 18:42:39 -05:00
Родитель ee8929c13f
Коммит 695749c30c
3 изменённых файлов: 47 добавлений и 31 удалений

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

@ -165,6 +165,7 @@
#include "nsIParser.h"
#include "nsIPermissionManager.h"
#include "nsIPluginHost.h"
#include "nsIRemoteBrowser.h"
#include "nsIRequest.h"
#include "nsIRunnable.h"
#include "nsIScriptContext.h"
@ -10590,6 +10591,40 @@ nsContentUtils::CreateJSValueFromSequenceOfObject(JSContext* aCx,
return NS_OK;
}
/* static */
bool
nsContentUtils::ShouldBlockReservedKeys(WidgetKeyboardEvent* aKeyEvent)
{
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIRemoteBrowser> targetBrowser = do_QueryInterface(aKeyEvent->mOriginalTarget);
if (targetBrowser) {
targetBrowser->GetContentPrincipal(getter_AddRefs(principal));
}
else {
// Get the top-level document.
nsCOMPtr<nsIContent> content = do_QueryInterface(aKeyEvent->mOriginalTarget);
if (content) {
nsIDocument* doc = content->GetUncomposedDoc();
if (doc) {
nsCOMPtr<nsIDocShellTreeItem> docShell = doc->GetDocShell();
if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeContent) {
nsCOMPtr<nsIDocShellTreeItem> rootItem;
docShell->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
if (rootItem && rootItem->GetDocument()) {
principal = rootItem->GetDocument()->NodePrincipal();
}
}
}
}
}
if (principal) {
return nsContentUtils::IsSitePermDeny(principal, "shortcuts");
}
return false;
}
/* static */ Element*
nsContentUtils::GetClosestNonNativeAnonymousAncestor(Element* aElement)
{

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

@ -3128,6 +3128,12 @@ public:
static bool
IsWebComponentsEnabled() { return sIsWebComponentsEnabled; }
/**
* Returns true if reserved key events should be prevented from being sent
* to their target. Instead, the key event should be handled by chrome only.
*/
static bool ShouldBlockReservedKeys(mozilla::WidgetKeyboardEvent* aKeyEvent);
/**
* Walks up the tree from aElement until it finds an element that is
* not native anonymous content. aElement must be NAC itself.
@ -3411,6 +3417,7 @@ private:
static int32_t sBytecodeCacheStrategy;
static uint32_t sCookiesLifetimePolicy;
static uint32_t sCookiesBehavior;
static bool sShortcutsCustomized;
static int32_t sPrivacyMaxInnerWidth;
static int32_t sPrivacyMaxInnerHeight;

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

@ -23,7 +23,6 @@
#include "nsPIDOMWindow.h"
#include "nsIDocShell.h"
#include "nsIDOMDocument.h"
#include "nsIRemoteBrowser.h"
#include "nsISelectionController.h"
#include "nsIPresShell.h"
#include "mozilla/EventListenerManager.h"
@ -817,40 +816,15 @@ nsXBLWindowKeyHandler::IsReservedKey(WidgetKeyboardEvent* aKeyEvent,
// reserved="true" means that the key is always reserved. reserved="false"
// means that the key is never reserved. Otherwise, we check site-specific
// permissions.
if (reserved == XBLReservedKey_False) {
return false;
}
if (reserved == XBLReservedKey_True) {
return true;
}
if (reserved == XBLReservedKey_Unset) {
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIRemoteBrowser> targetBrowser = do_QueryInterface(aKeyEvent->mOriginalTarget);
if (targetBrowser) {
targetBrowser->GetContentPrincipal(getter_AddRefs(principal));
}
else {
// Get the top-level document.
nsCOMPtr<nsIContent> content = do_QueryInterface(aKeyEvent->mOriginalTarget);
if (content) {
nsIDocument* doc = content->GetUncomposedDoc();
if (doc) {
nsCOMPtr<nsIDocShellTreeItem> docShell = doc->GetDocShell();
if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeContent) {
nsCOMPtr<nsIDocShellTreeItem> rootItem;
docShell->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
if (rootItem && rootItem->GetDocument()) {
principal = rootItem->GetDocument()->NodePrincipal();
}
}
}
}
}
if (principal) {
return nsContentUtils::IsSitePermDeny(principal, "shortcuts");
}
}
return false;
return nsContentUtils::ShouldBlockReservedKeys(aKeyEvent);
}
bool