Index: embed/mozilla/EphyBrowser.h =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.h,v retrieving revision 1.37 diff -p -u -u -p -r1.37 EphyBrowser.h --- embed/mozilla/EphyBrowser.h 23 Jan 2005 15:38:02 -0000 1.37 +++ embed/mozilla/EphyBrowser.h 3 Feb 2005 15:49:03 -0000 @@ -85,6 +85,12 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); }; +class EphyMouseDownEventListener : public EphyEventListener +{ +public: + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); +}; + class EphyContextMenuListener : public nsIDOMContextMenuListener { public: @@ -110,6 +116,7 @@ friend class EphyEventListener; friend class EphyFaviconEventListener; friend class EphyPopupBlockEventListener; friend class EphyModalAlertEventListener; +friend class EphyMouseDownEventListener; friend class EphyContextMenuListener; public: EphyBrowser(); @@ -180,6 +187,7 @@ private: EphyFaviconEventListener *mFaviconEventListener; EphyPopupBlockEventListener *mPopupBlockEventListener; EphyModalAlertEventListener *mModalAlertListener; + EphyMouseDownEventListener *mMouseDownEventListener; EphyContextMenuListener *mContextMenuListener; PRBool mInitialized; #ifdef HAVE_MOZILLA_PSM Index: embed/mozilla/EphyBrowser.cpp =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.cpp,v retrieving revision 1.76 diff -p -u -u -p -r1.76 EphyBrowser.cpp --- embed/mozilla/EphyBrowser.cpp 28 Jan 2005 22:23:38 -0000 1.76 +++ embed/mozilla/EphyBrowser.cpp 3 Feb 2005 15:49:04 -0000 @@ -113,6 +113,7 @@ static PRUnichar DOMWillOpenModalDialog[ static PRUnichar DOMModalDialogClosed[] = { 'D', 'O', 'M', 'M', 'o', 'd', 'a', 'l', 'D', 'i', 'a', 'l', 'o', 'g', 'C', 'l', 'o', 's', 'e', 'd', '\0' }; +static PRUnichar MouseDown[] = { 'm', 'o', 'u', 's', 'e', 'd', 'o', 'w', 'n', '\0' }; EphyEventListener::EphyEventListener() : mOwner(nsnull) @@ -338,6 +339,28 @@ EphyModalAlertEventListener::HandleEvent return NS_OK; } +nsresult +EphyMouseDownEventListener::HandleEvent(nsIDOMEvent *aEvent) +{ + nsCOMPtr mouseEvent (do_QueryInterface (aEvent)); + NS_ENSURE_TRUE (mouseEvent, NS_ERROR_FAILURE); + + PRUint16 button = 1729; + mouseEvent->GetButton (&button); + + /* right mouse button */ + if (button == 2) + { + /* prevent stupid web pages from preventing context menus by doing + * things like onmousedown="window.close()" etc. + */ + aEvent->PreventDefault (); + aEvent->StopPropagation(); + } + + return NS_OK; +} + EphyContextMenuListener::EphyContextMenuListener() : mOwner(nsnull) { @@ -483,6 +506,12 @@ nsresult EphyBrowser::Init (GtkMozEmbed rv = mModalAlertListener->Init (this); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + mMouseDownEventListener = new EphyMouseDownEventListener(); + if (!mMouseDownEventListener) return NS_ERROR_OUT_OF_MEMORY; + + rv = mMouseDownEventListener->Init (this); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + mContextMenuListener = new EphyContextMenuListener(); if (!mContextMenuListener) return NS_ERROR_OUT_OF_MEMORY; @@ -574,6 +603,8 @@ EphyBrowser::AttachListeners(void) mModalAlertListener, PR_TRUE); rv |= mEventTarget->AddEventListener(nsEmbedString(DOMModalDialogClosed), mModalAlertListener, PR_TRUE); + rv |= mEventTarget->AddEventListener(nsEmbedString(MouseDown), + mMouseDownEventListener, PR_TRUE /* capture */); rv |= mEventTarget->AddEventListener(nsEmbedString(ContextMenu), mContextMenuListener, PR_TRUE /* capture */); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); @@ -595,6 +626,8 @@ EphyBrowser::DetachListeners(void) mModalAlertListener, PR_TRUE); rv |= mEventTarget->RemoveEventListener(nsEmbedString(DOMModalDialogClosed), mModalAlertListener, PR_TRUE); + rv |= mEventTarget->RemoveEventListener(nsEmbedString(MouseDown), + mMouseDownEventListener, PR_TRUE /* capture */); rv |= mEventTarget->RemoveEventListener(nsEmbedString(ContextMenu), mContextMenuListener, PR_TRUE /* capture */); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);