From 00e4d5d5e32a077453a3a1d409e3f18fa6e754e8 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 2 Sep 2004 15:25:39 +0000 Subject: [PATCH] Fixing bug 257431. Make the tabbrowser code only listen to events initiated by the user. r=trev@gtchat.de, sr=bzbarsky@mit.edu --- content/events/public/nsIPrivateDOMEvent.h | 7 ++- content/events/src/nsDOMEvent.cpp | 15 +++--- content/events/src/nsDOMEvent.h | 1 - content/xbl/src/nsXBLPrototypeHandler.cpp | 14 +++--- content/xbl/src/nsXBLWindowKeyHandler.cpp | 16 ++++--- dom/public/idl/events/nsIDOMNSEvent.idl | 4 +- layout/xul/base/src/nsMenuBarListener.cpp | 48 +++++++++---------- layout/xul/base/src/nsMenuListener.cpp | 19 ++++---- toolkit/content/widgets/tabbox.xml | 5 ++ .../resources/content/bindings/tabbox.xml | 5 ++ 10 files changed, 73 insertions(+), 61 deletions(-) diff --git a/content/events/public/nsIPrivateDOMEvent.h b/content/events/public/nsIPrivateDOMEvent.h index 3b2175f0f9a..d6953311d43 100644 --- a/content/events/public/nsIPrivateDOMEvent.h +++ b/content/events/public/nsIPrivateDOMEvent.h @@ -46,9 +46,9 @@ class nsPresContext; * Event listener manager interface. */ #define NS_IPRIVATEDOMEVENT_IID \ -{ /* 80a98c80-2036-11d2-bd89-00805f8ae3f4 */ \ -0x80a98c80, 0x2036, 0x11d2, \ -{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } +{ /* 25e6626c-8e54-409b-87b5-2beceaac399e */ \ +0x25e6626c, 0x8e54, 0x409b, \ +{0x87, 0xb5, 0x2b, 0xec, 0xea, 0xac, 0x39, 0x9e} } class nsIDOMEventTarget; class nsIDOMEvent; @@ -66,7 +66,6 @@ public: NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0; NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0; - NS_IMETHOD IsTrustedEvent(PRBool* aResult)=0; NS_IMETHOD SetTrusted(PRBool aTrusted)=0; }; diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index fa813c28a8d..cece0917832 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -283,13 +283,6 @@ nsDOMEvent::HasOriginalTarget(PRBool* aResult) return NS_OK; } -NS_IMETHODIMP -nsDOMEvent::IsTrustedEvent(PRBool* aResult) -{ - *aResult = mEventIsTrusted; - return NS_OK; -} - NS_IMETHODIMP nsDOMEvent::SetTrusted(PRBool aTrusted) { @@ -364,6 +357,14 @@ nsDOMEvent::PreventCapture() return NS_OK; } +NS_IMETHODIMP +nsDOMEvent::GetIsTrusted(PRBool *aIsTrusted) +{ + *aIsTrusted = mEventIsTrusted; + + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::PreventDefault() { diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 4b6fd571640..cad93a0653a 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -141,7 +141,6 @@ public: NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent); NS_IMETHOD HasOriginalTarget(PRBool* aResult); - NS_IMETHOD IsTrustedEvent(PRBool* aResult); NS_IMETHOD SetTrusted(PRBool aTrusted); NS_IMETHOD IsHandled(PRBool* aHandled); diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index bb16ceb46e3..a54fc2b7893 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -63,6 +63,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIDOMEventListener.h" #include "nsIPrivateDOMEvent.h" +#include "nsIDOMNSEvent.h" #include "nsPIDOMWindow.h" #include "nsPIWindowRoot.h" #include "nsIDOMWindowInternal.h" @@ -228,13 +229,14 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, // XUL handlers and commands shouldn't be triggered by non-trusted // events. if (isXULKey || isXBLCommand) { - nsCOMPtr privateEvent = do_QueryInterface(aEvent); - if (privateEvent) { - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; + nsCOMPtr domNSEvent = do_QueryInterface(aEvent); + PRBool trustedEvent = PR_FALSE; + if (domNSEvent) { + domNSEvent->GetIsTrusted(&trustedEvent); } + + if (!trustedEvent) + return NS_OK; } PRBool isReceiverCommandElement = PR_FALSE; diff --git a/content/xbl/src/nsXBLWindowKeyHandler.cpp b/content/xbl/src/nsXBLWindowKeyHandler.cpp index 7028de8f70b..a324f5509c3 100644 --- a/content/xbl/src/nsXBLWindowKeyHandler.cpp +++ b/content/xbl/src/nsXBLWindowKeyHandler.cpp @@ -46,7 +46,7 @@ #include "nsIDOMNSUIEvent.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMEventReceiver.h" -#include "nsIPrivateDOMEvent.h" +#include "nsIDOMNSEvent.h" #include "nsXBLService.h" #include "nsIServiceManager.h" #include "nsHTMLAtoms.h" @@ -124,15 +124,17 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType) if (prevent) return NS_OK; - nsCOMPtr privateEvent = do_QueryInterface(aKeyEvent); - if (privateEvent) { + nsCOMPtr domNSEvent = do_QueryInterface(aKeyEvent); + PRBool trustedEvent = PR_FALSE; + + if (domNSEvent) { //Don't process the event if it was not dispatched from a trusted source - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; + domNSEvent->GetIsTrusted(&trustedEvent); } + if (!trustedEvent) + return NS_OK; + // Make sure our event is really a key event nsCOMPtr keyEvent(do_QueryInterface(aKeyEvent)); if (!keyEvent) diff --git a/dom/public/idl/events/nsIDOMNSEvent.idl b/dom/public/idl/events/nsIDOMNSEvent.idl index 1db5de94a24..e8f9019887e 100644 --- a/dom/public/idl/events/nsIDOMNSEvent.idl +++ b/dom/public/idl/events/nsIDOMNSEvent.idl @@ -38,7 +38,7 @@ #include "domstubs.idl" -[scriptable, uuid(a90977dd-a80b-49bb-8169-cc90e3d1da98)] +[scriptable, uuid(e565d518-4510-407f-a3d9-3b4107549c6d)] interface nsIDOMNSEvent : nsISupports { const long MOUSEDOWN = 0x00000001; @@ -100,4 +100,6 @@ interface nsIDOMNSEvent : nsISupports void preventBubble(); void preventCapture(); + + readonly attribute boolean isTrusted; }; diff --git a/layout/xul/base/src/nsMenuBarListener.cpp b/layout/xul/base/src/nsMenuBarListener.cpp index 4632feb3e3f..919c0cfd988 100644 --- a/layout/xul/base/src/nsMenuBarListener.cpp +++ b/layout/xul/base/src/nsMenuBarListener.cpp @@ -46,7 +46,6 @@ #include "nsIDOMNSUIEvent.h" #include "nsIDOMNSEvent.h" #include "nsGUIEvent.h" -#include "nsIPrivateDOMEvent.h" // Drag & Drop, Clipboard #include "nsIServiceManager.h" @@ -142,16 +141,16 @@ nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent) InitAccessKey(); //handlers shouldn't be triggered by non-trusted events. - if (aKeyEvent) { - nsCOMPtr privateEvent = do_QueryInterface(aKeyEvent); - if (privateEvent) { - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; - } + nsCOMPtr domNSEvent = do_QueryInterface(aKeyEvent); + PRBool trustedEvent = PR_FALSE; + + if (domNSEvent) { + domNSEvent->GetIsTrusted(&trustedEvent); } + if (!trustedEvent) + return NS_OK; + if (mAccessKey && mAccessKeyFocuses) { // On a press of the ALT key by itself, we toggle the menu's @@ -202,16 +201,15 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent) } //handlers shouldn't be triggered by non-trusted events. - if (aKeyEvent) { - nsCOMPtr privateEvent = do_QueryInterface(aKeyEvent); - if (privateEvent) { - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; - } + nsCOMPtr domNSEvent = do_QueryInterface(aKeyEvent); + PRBool trustedEvent = PR_FALSE; + if (domNSEvent) { + domNSEvent->GetIsTrusted(&trustedEvent); } + if (!trustedEvent) + return NS_OK; + nsresult retVal = NS_OK; // default is to not consume event InitAccessKey(); @@ -322,16 +320,16 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent) InitAccessKey(); //handlers shouldn't be triggered by non-trusted events. - if (aKeyEvent) { - nsCOMPtr privateEvent = do_QueryInterface(aKeyEvent); - if (privateEvent) { - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; - } + nsCOMPtr domNSEvent = do_QueryInterface(aKeyEvent); + PRBool trustedEvent = PR_FALSE; + + if (domNSEvent) { + domNSEvent->GetIsTrusted(&trustedEvent); } + if (!trustedEvent) + return NS_OK; + if (mAccessKey && mAccessKeyFocuses) { nsCOMPtr keyEvent = do_QueryInterface(aKeyEvent); diff --git a/layout/xul/base/src/nsMenuListener.cpp b/layout/xul/base/src/nsMenuListener.cpp index ea798c4dfd0..f9d76d7dd1c 100644 --- a/layout/xul/base/src/nsMenuListener.cpp +++ b/layout/xul/base/src/nsMenuListener.cpp @@ -44,7 +44,6 @@ #include "nsIDOMEventReceiver.h" #include "nsIDOMEventListener.h" #include "nsIDOMNSUIEvent.h" -#include "nsIDOMNSEvent.h" #include "nsGUIEvent.h" // Drag & Drop, Clipboard @@ -52,7 +51,7 @@ #include "nsWidgetsCID.h" #include "nsCOMPtr.h" #include "nsIDOMKeyEvent.h" -#include "nsIPrivateDOMEvent.h" +#include "nsIDOMNSEvent.h" #include "nsPresContext.h" #include "nsIContent.h" #include "nsIDOMNode.h" @@ -173,16 +172,16 @@ nsMenuListener::KeyPress(nsIDOMEvent* aKeyEvent) } //handlers shouldn't be triggered by non-trusted events. - if (aKeyEvent) { - nsCOMPtr privateEvent = do_QueryInterface(aKeyEvent); - if (privateEvent) { - PRBool trustedEvent; - privateEvent->IsTrustedEvent(&trustedEvent); - if (!trustedEvent) - return NS_OK; - } + nsCOMPtr domNSEvent = do_QueryInterface(aKeyEvent); + PRBool trustedEvent = PR_FALSE; + + if (domNSEvent) { + domNSEvent->GetIsTrusted(&trustedEvent); } + if (!trustedEvent) + return NS_OK; + nsCOMPtr keyEvent = do_QueryInterface(aKeyEvent); PRUint32 theChar; keyEvent->GetKeyCode(&theChar); diff --git a/toolkit/content/widgets/tabbox.xml b/toolkit/content/widgets/tabbox.xml index 9c46ba8c86c..a89ebb99ac0 100644 --- a/toolkit/content/widgets/tabbox.xml +++ b/toolkit/content/widgets/tabbox.xml @@ -114,6 +114,11 @@