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:
caillon%redhat.com 2004-03-06 02:58:08 +00:00
Родитель 7a7dc95d1f
Коммит bfd1f05ff4
4 изменённых файлов: 50 добавлений и 7 удалений

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

@ -286,11 +286,11 @@ public:
nsINodeInfoManager* aNodeInfoManager, nsINodeInfoManager* aNodeInfoManager,
nsINodeInfo** aNodeInfo); nsINodeInfo** aNodeInfo);
private:
static nsresult GetDocumentAndPrincipal(nsIDOMNode* aNode, static nsresult GetDocumentAndPrincipal(nsIDOMNode* aNode,
nsIDocument** aDocument, nsIDocument** aDocument,
nsIPrincipal** aPrincipal); nsIPrincipal** aPrincipal);
private:
static nsresult doReparentContentWrapper(nsIContent *aChild, static nsresult doReparentContentWrapper(nsIContent *aChild,
nsIDocument *aNewDocument, nsIDocument *aNewDocument,
nsIDocument *aOldDocument, nsIDocument *aOldDocument,

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

@ -47,6 +47,7 @@ REQUIRES = xpcom \
xultmpl \ xultmpl \
webshell \ webshell \
view \ view \
pref \
$(NULL) $(NULL)
CPPSRCS = \ CPPSRCS = \

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

@ -56,6 +56,7 @@
#include "nsIDOMMouseListener.h" #include "nsIDOMMouseListener.h"
#include "nsIDOMContextMenuListener.h" #include "nsIDOMContextMenuListener.h"
#include "nsContentCID.h" #include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h" #include "nsIScriptContext.h"
@ -67,6 +68,11 @@
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
#include "nsIDOMEventTarget.h" #include "nsIDOMEventTarget.h"
#include "nsIDOMNSEvent.h" #include "nsIDOMNSEvent.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManagerUtils.h"
#include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsIBoxObject.h" #include "nsIBoxObject.h"
#include "nsIPopupBoxObject.h" #include "nsIPopupBoxObject.h"
@ -218,19 +224,53 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent)
return NS_OK; 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; PRBool preventDefault;
nsUIEvent->GetPreventDefault(&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) { if (preventDefault) {
// someone called preventDefault. bail. // someone called preventDefault. bail.
return NS_OK; 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. // 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. // See http://bugzilla.mozilla.org/show_bug.cgi?id=96920.
// If a menu item child was clicked on that leads to a popup needing // 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_maximum", 20);
pref("dom.popup_allowed_events", "change click dblclick error reset submit"); pref("dom.popup_allowed_events", "change click dblclick error reset submit");
pref("dom.event.contextmenu.enabled", true);
pref("javascript.enabled", true); pref("javascript.enabled", true);
pref("javascript.allow.mailnews", false); pref("javascript.allow.mailnews", false);
pref("javascript.options.strict", false); pref("javascript.options.strict", false);