зеркало из https://github.com/mozilla/gecko-dev.git
Bug 86193
Add a preference allowing users to prevent sites from cancelling the contextmenu event, so right click will always bring up a context menu if the pref is set. r=jst sr=bryner
This commit is contained in:
Родитель
7a7dc95d1f
Коммит
bfd1f05ff4
|
@ -286,11 +286,11 @@ public:
|
|||
nsINodeInfoManager* aNodeInfoManager,
|
||||
nsINodeInfo** aNodeInfo);
|
||||
|
||||
private:
|
||||
static nsresult GetDocumentAndPrincipal(nsIDOMNode* aNode,
|
||||
nsIDocument** aDocument,
|
||||
nsIPrincipal** aPrincipal);
|
||||
|
||||
private:
|
||||
static nsresult doReparentContentWrapper(nsIContent *aChild,
|
||||
nsIDocument *aNewDocument,
|
||||
nsIDocument *aOldDocument,
|
||||
|
|
|
@ -47,6 +47,7 @@ REQUIRES = xpcom \
|
|||
xultmpl \
|
||||
webshell \
|
||||
view \
|
||||
pref \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMContextMenuListener.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
@ -67,6 +68,11 @@
|
|||
#include "nsIDOMNSUIEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIDOMNSEvent.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManagerUtils.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#include "nsIBoxObject.h"
|
||||
#include "nsIPopupBoxObject.h"
|
||||
|
@ -218,19 +224,53 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the node that was clicked on.
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
mouseEvent->GetTarget(getter_AddRefs(target));
|
||||
nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(target);
|
||||
|
||||
PRBool preventDefault;
|
||||
nsUIEvent->GetPreventDefault(&preventDefault);
|
||||
if (preventDefault && targetNode && popupType == eXULPopupType_context) {
|
||||
// Someone called preventDefault on a context menu.
|
||||
// Let's make sure they are allowed to do so.
|
||||
nsCOMPtr<nsIPrefService> prefService =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
|
||||
NS_ENSURE_TRUE(prefService, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
|
||||
PRBool eventEnabled;
|
||||
nsresult rv = prefBranch->GetBoolPref("dom.event.contextmenu.enabled",
|
||||
&eventEnabled);
|
||||
if (NS_SUCCEEDED(rv) && !eventEnabled) {
|
||||
// The user wants his contextmenus. Let's make sure that this is a website
|
||||
// and not chrome since there could be places in chrome which don't want
|
||||
// contextmenus.
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIPrincipal> prin;
|
||||
nsContentUtils::GetDocumentAndPrincipal(targetNode,
|
||||
getter_AddRefs(doc),
|
||||
getter_AddRefs(prin));
|
||||
if (prin) {
|
||||
nsCOMPtr<nsIPrincipal> system;
|
||||
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(system));
|
||||
if (prin != system) {
|
||||
// This isn't chrome. Cancel the preventDefault() and
|
||||
// let the event go forth.
|
||||
preventDefault = PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preventDefault) {
|
||||
// someone called preventDefault. bail.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the node that was clicked on.
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
mouseEvent->GetTarget( getter_AddRefs( target ) );
|
||||
nsCOMPtr<nsIDOMNode> targetNode;
|
||||
if (target) targetNode = do_QueryInterface(target);
|
||||
|
||||
// This is a gross hack to deal with a recursive popup situation happening in AIM code.
|
||||
// See http://bugzilla.mozilla.org/show_bug.cgi?id=96920.
|
||||
// If a menu item child was clicked on that leads to a popup needing
|
||||
|
|
|
@ -416,6 +416,8 @@ pref("dom.disable_open_during_load", false);
|
|||
pref("dom.popup_maximum", 20);
|
||||
pref("dom.popup_allowed_events", "change click dblclick error reset submit");
|
||||
|
||||
pref("dom.event.contextmenu.enabled", true);
|
||||
|
||||
pref("javascript.enabled", true);
|
||||
pref("javascript.allow.mailnews", false);
|
||||
pref("javascript.options.strict", false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче