Fixing bug 257431. Make the tabbrowser code only listen to events initiated by the user. r=trev@gtchat.de, sr=bzbarsky@mit.edu

This commit is contained in:
jst%mozilla.jstenback.com 2004-09-02 15:25:39 +00:00
Родитель 7ead66e29a
Коммит 00e4d5d5e3
10 изменённых файлов: 73 добавлений и 61 удалений

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

@ -46,9 +46,9 @@ class nsPresContext;
* Event listener manager interface. * Event listener manager interface.
*/ */
#define NS_IPRIVATEDOMEVENT_IID \ #define NS_IPRIVATEDOMEVENT_IID \
{ /* 80a98c80-2036-11d2-bd89-00805f8ae3f4 */ \ { /* 25e6626c-8e54-409b-87b5-2beceaac399e */ \
0x80a98c80, 0x2036, 0x11d2, \ 0x25e6626c, 0x8e54, 0x409b, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } {0x87, 0xb5, 0x2b, 0xec, 0xea, 0xac, 0x39, 0x9e} }
class nsIDOMEventTarget; class nsIDOMEventTarget;
class nsIDOMEvent; class nsIDOMEvent;
@ -66,7 +66,6 @@ public:
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0; NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0;
NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0; NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0;
NS_IMETHOD IsTrustedEvent(PRBool* aResult)=0;
NS_IMETHOD SetTrusted(PRBool aTrusted)=0; NS_IMETHOD SetTrusted(PRBool aTrusted)=0;
}; };

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

@ -283,13 +283,6 @@ nsDOMEvent::HasOriginalTarget(PRBool* aResult)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMEvent::IsTrustedEvent(PRBool* aResult)
{
*aResult = mEventIsTrusted;
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMEvent::SetTrusted(PRBool aTrusted) nsDOMEvent::SetTrusted(PRBool aTrusted)
{ {
@ -364,6 +357,14 @@ nsDOMEvent::PreventCapture()
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMEvent::GetIsTrusted(PRBool *aIsTrusted)
{
*aIsTrusted = mEventIsTrusted;
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMEvent::PreventDefault() nsDOMEvent::PreventDefault()
{ {

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

@ -141,7 +141,6 @@ public:
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent); NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent);
NS_IMETHOD HasOriginalTarget(PRBool* aResult); NS_IMETHOD HasOriginalTarget(PRBool* aResult);
NS_IMETHOD IsTrustedEvent(PRBool* aResult);
NS_IMETHOD SetTrusted(PRBool aTrusted); NS_IMETHOD SetTrusted(PRBool aTrusted);
NS_IMETHOD IsHandled(PRBool* aHandled); NS_IMETHOD IsHandled(PRBool* aHandled);

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

@ -63,6 +63,7 @@
#include "nsIDOMEventReceiver.h" #include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsIPrivateDOMEvent.h" #include "nsIPrivateDOMEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h" #include "nsPIWindowRoot.h"
#include "nsIDOMWindowInternal.h" #include "nsIDOMWindowInternal.h"
@ -228,14 +229,15 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver,
// XUL handlers and commands shouldn't be triggered by non-trusted // XUL handlers and commands shouldn't be triggered by non-trusted
// events. // events.
if (isXULKey || isXBLCommand) { if (isXULKey || isXBLCommand) {
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aEvent); nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aEvent);
if (privateEvent) { PRBool trustedEvent = PR_FALSE;
PRBool trustedEvent; if (domNSEvent) {
privateEvent->IsTrustedEvent(&trustedEvent); domNSEvent->GetIsTrusted(&trustedEvent);
}
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
} }
}
PRBool isReceiverCommandElement = PR_FALSE; PRBool isReceiverCommandElement = PR_FALSE;
nsCOMPtr<nsIContent> content(do_QueryInterface(aReceiver)); nsCOMPtr<nsIContent> content(do_QueryInterface(aReceiver));

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

@ -46,7 +46,7 @@
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
#include "nsIDOMKeyEvent.h" #include "nsIDOMKeyEvent.h"
#include "nsIDOMEventReceiver.h" #include "nsIDOMEventReceiver.h"
#include "nsIPrivateDOMEvent.h" #include "nsIDOMNSEvent.h"
#include "nsXBLService.h" #include "nsXBLService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
@ -124,14 +124,16 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType)
if (prevent) if (prevent)
return NS_OK; return NS_OK;
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aKeyEvent); nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
if (privateEvent) { PRBool trustedEvent = PR_FALSE;
if (domNSEvent) {
//Don't process the event if it was not dispatched from a trusted source //Don't process the event if it was not dispatched from a trusted source
PRBool trustedEvent; domNSEvent->GetIsTrusted(&trustedEvent);
privateEvent->IsTrustedEvent(&trustedEvent); }
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
}
// Make sure our event is really a key event // Make sure our event is really a key event
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aKeyEvent)); nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aKeyEvent));

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

@ -38,7 +38,7 @@
#include "domstubs.idl" #include "domstubs.idl"
[scriptable, uuid(a90977dd-a80b-49bb-8169-cc90e3d1da98)] [scriptable, uuid(e565d518-4510-407f-a3d9-3b4107549c6d)]
interface nsIDOMNSEvent : nsISupports interface nsIDOMNSEvent : nsISupports
{ {
const long MOUSEDOWN = 0x00000001; const long MOUSEDOWN = 0x00000001;
@ -100,4 +100,6 @@ interface nsIDOMNSEvent : nsISupports
void preventBubble(); void preventBubble();
void preventCapture(); void preventCapture();
readonly attribute boolean isTrusted;
}; };

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

@ -46,7 +46,6 @@
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
#include "nsIDOMNSEvent.h" #include "nsIDOMNSEvent.h"
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
#include "nsIPrivateDOMEvent.h"
// Drag & Drop, Clipboard // Drag & Drop, Clipboard
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -142,15 +141,15 @@ nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
InitAccessKey(); InitAccessKey();
//handlers shouldn't be triggered by non-trusted events. //handlers shouldn't be triggered by non-trusted events.
if (aKeyEvent) { nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aKeyEvent); PRBool trustedEvent = PR_FALSE;
if (privateEvent) {
PRBool trustedEvent; if (domNSEvent) {
privateEvent->IsTrustedEvent(&trustedEvent); domNSEvent->GetIsTrusted(&trustedEvent);
}
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
}
}
if (mAccessKey && mAccessKeyFocuses) if (mAccessKey && mAccessKeyFocuses)
{ {
@ -202,15 +201,14 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
} }
//handlers shouldn't be triggered by non-trusted events. //handlers shouldn't be triggered by non-trusted events.
if (aKeyEvent) { nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aKeyEvent); PRBool trustedEvent = PR_FALSE;
if (privateEvent) { if (domNSEvent) {
PRBool trustedEvent; domNSEvent->GetIsTrusted(&trustedEvent);
privateEvent->IsTrustedEvent(&trustedEvent); }
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
}
}
nsresult retVal = NS_OK; // default is to not consume event nsresult retVal = NS_OK; // default is to not consume event
@ -322,15 +320,15 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
InitAccessKey(); InitAccessKey();
//handlers shouldn't be triggered by non-trusted events. //handlers shouldn't be triggered by non-trusted events.
if (aKeyEvent) { nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aKeyEvent); PRBool trustedEvent = PR_FALSE;
if (privateEvent) {
PRBool trustedEvent; if (domNSEvent) {
privateEvent->IsTrustedEvent(&trustedEvent); domNSEvent->GetIsTrusted(&trustedEvent);
}
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
}
}
if (mAccessKey && mAccessKeyFocuses) if (mAccessKey && mAccessKeyFocuses)
{ {

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

@ -44,7 +44,6 @@
#include "nsIDOMEventReceiver.h" #include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
// Drag & Drop, Clipboard // Drag & Drop, Clipboard
@ -52,7 +51,7 @@
#include "nsWidgetsCID.h" #include "nsWidgetsCID.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIDOMKeyEvent.h" #include "nsIDOMKeyEvent.h"
#include "nsIPrivateDOMEvent.h" #include "nsIDOMNSEvent.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsIContent.h" #include "nsIContent.h"
#include "nsIDOMNode.h" #include "nsIDOMNode.h"
@ -173,15 +172,15 @@ nsMenuListener::KeyPress(nsIDOMEvent* aKeyEvent)
} }
//handlers shouldn't be triggered by non-trusted events. //handlers shouldn't be triggered by non-trusted events.
if (aKeyEvent) { nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aKeyEvent); PRBool trustedEvent = PR_FALSE;
if (privateEvent) {
PRBool trustedEvent; if (domNSEvent) {
privateEvent->IsTrustedEvent(&trustedEvent); domNSEvent->GetIsTrusted(&trustedEvent);
}
if (!trustedEvent) if (!trustedEvent)
return NS_OK; return NS_OK;
}
}
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent); nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar; PRUint32 theChar;

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

@ -114,6 +114,11 @@
<![CDATA[({ <![CDATA[({
tabbox: this, tabbox: this,
handleEvent: function handleEvent(event) { handleEvent: function handleEvent(event) {
if (!event.isTrusted) {
// Don't let untrusted events mess with tabs.
return;
}
switch (event.keyCode) { switch (event.keyCode) {
case event.DOM_VK_TAB: case event.DOM_VK_TAB:
if (event.ctrlKey && !event.altKey && !event.metaKey) if (event.ctrlKey && !event.altKey && !event.metaKey)

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

@ -114,6 +114,11 @@
<![CDATA[({ <![CDATA[({
tabbox: this, tabbox: this,
handleEvent: function handleEvent(event) { handleEvent: function handleEvent(event) {
if (!event.isTrusted) {
// Don't let untrusted events mess with tabs.
return;
}
switch (event.keyCode) { switch (event.keyCode) {
case event.DOM_VK_TAB: case event.DOM_VK_TAB:
if (event.ctrlKey && !event.altKey && !event.metaKey) if (event.ctrlKey && !event.altKey && !event.metaKey)