diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-11-18 21:22:36 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-11-18 21:22:36 +0800 |
commit | 978fdbb10a9e7e5ec5e498044722588a3b32368c (patch) | |
tree | d10acad1ba4402fc43fbd5c79e10bc8cfb65ad05 /embed | |
parent | 650d8ac764ed07e90aafae4b9e8f6b86614fa82a (diff) | |
download | gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar.gz gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar.bz2 gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar.lz gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar.xz gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.tar.zst gsoc2013-epiphany-978fdbb10a9e7e5ec5e498044722588a3b32368c.zip |
Disallow favicon links from subframes.
2004-11-18 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/EphyBrowser.cpp:
* embed/mozilla/EphyBrowser.h:
Disallow favicon links from subframes.
* embed/mozilla/mozilla-embed-single.cpp:
Include stdlib.h.
Diffstat (limited to 'embed')
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 49 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.h | 15 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 2 |
3 files changed, 48 insertions, 18 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index b640776b4..ca63724fb 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -65,6 +65,8 @@ #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsIDOMWindow2.h" +#include "nsIDOMDocumentView.h" +#include "nsIDOMAbstractView.h" #define MOZILLA_STRICT_API #include "nsEmbedString.h" #undef MOZILLA_STRICT_API @@ -118,7 +120,7 @@ EphyEventListener::~EphyEventListener() NS_IMPL_ISUPPORTS1(EphyEventListener, nsIDOMEventListener) nsresult -EphyEventListener::Init(EphyEmbed *aOwner) +EphyEventListener::Init (EphyBrowser *aOwner) { mOwner = aOwner; return NS_OK; @@ -161,6 +163,23 @@ EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) node->GetOwnerDocument(getter_AddRefs(domDoc)); NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); + nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (domDoc)); + NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); + + nsCOMPtr<nsIDOMAbstractView> abstractView; + docView->GetDefaultView (getter_AddRefs (abstractView)); + + nsCOMPtr<nsIDOMWindow> domWin (do_QueryInterface (abstractView)); + NS_ENSURE_TRUE (domWin, NS_ERROR_FAILURE); + + nsCOMPtr<nsIDOMWindow> topDomWin; + domWin->GetTop (getter_AddRefs (topDomWin)); + + nsCOMPtr<nsISupports> domWinAsISupports (do_QueryInterface (domWin)); + nsCOMPtr<nsISupports> topDomWinAsISupports (do_QueryInterface (topDomWin)); + /* disallow subframes to set favicon */ + if (domWinAsISupports != topDomWinAsISupports) return NS_OK; + nsCOMPtr<nsIDOM3Document> doc = do_QueryInterface (domDoc); NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); @@ -219,16 +238,14 @@ EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) PRBool shouldLoad = PR_FALSE; rv = policy->ShouldLoad (nsIContentPolicy::IMAGE, favUri, eventTarget, - nsnull /* FIXME: DOM window*/, + mOwner->mDOMWindow, &shouldLoad); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); if (!shouldLoad) return NS_OK; #endif /* ok, we accept this as a valid favicon for this site */ - char *url = g_strdup (faviconUrl.get()); - g_signal_emit_by_name (mOwner, "ge_favicon", url); - g_free (url); + g_signal_emit_by_name (mOwner->mEmbed, "ge_favicon", faviconUrl.get()); } return NS_OK; @@ -237,8 +254,6 @@ EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) NS_IMETHODIMP EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) { - NS_ENSURE_TRUE (mOwner != NULL, NS_ERROR_FAILURE); - nsCOMPtr<nsIDOMPopupBlockedEvent> popupEvent = do_QueryInterface (aDOMEvent); NS_ENSURE_TRUE (popupEvent, NS_ERROR_FAILURE); @@ -261,7 +276,7 @@ EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) NS_CSTRING_ENCODING_UTF8, popupWindowFeaturesString); - g_signal_emit_by_name(mOwner, "ge_popup_blocked", + g_signal_emit_by_name(mOwner->mEmbed, "ge_popup_blocked", popupWindowURIString.get(), popupWindowFeaturesString.get()); @@ -294,7 +309,7 @@ EphyModalAlertEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) if (strcmp (cType.get(), "DOMWillOpenModalDialog") == 0) { gboolean retval = FALSE; - g_signal_emit_by_name (mOwner, "ge-modal-alert", &retval); + g_signal_emit_by_name (mOwner->mEmbed, "ge-modal-alert", &retval); /* suppress alert */ if (retval) @@ -305,7 +320,7 @@ EphyModalAlertEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) } else if (strcmp (cType.get(), "DOMModalDialogClosed") == 0) { - g_signal_emit_by_name (mOwner, "ge-modal-alert-closed"); + g_signal_emit_by_name (mOwner->mEmbed, "ge-modal-alert-closed"); } #endif @@ -330,6 +345,8 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) { if (mInitialized) return NS_OK; + mEmbed = GTK_WIDGET (mozembed); + gtk_moz_embed_get_nsIWebBrowser (mozembed, getter_AddRefs(mWebBrowser)); NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); @@ -346,24 +363,27 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) mFaviconEventListener = new EphyFaviconEventListener(); if (!mFaviconEventListener) return NS_ERROR_OUT_OF_MEMORY; - rv = mFaviconEventListener->Init (EPHY_EMBED (mozembed)); + rv = mFaviconEventListener->Init (this); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); mPopupBlockEventListener = new EphyPopupBlockEventListener(); if (!mPopupBlockEventListener) return NS_ERROR_OUT_OF_MEMORY; - rv = mPopupBlockEventListener->Init (EPHY_EMBED (mozembed)); + rv = mPopupBlockEventListener->Init (this); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); mModalAlertListener = new EphyModalAlertEventListener (); if (!mModalAlertListener) return NS_ERROR_OUT_OF_MEMORY; - rv = mModalAlertListener->Init (EPHY_EMBED (mozembed)); + rv = mModalAlertListener->Init (this); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); rv = GetListener(); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + rv = AttachListeners(); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + #ifdef HAVE_MOZILLA_PSM /* FIXME: mozilla sucks! nsWebBrowser already has an instance of this, * but we cannot get to it! @@ -376,7 +396,7 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) mInitialized = PR_TRUE; - return AttachListeners(); + return NS_OK; } nsresult @@ -526,6 +546,7 @@ nsresult EphyBrowser::Destroy () mWebBrowser = nsnull; mDOMWindow = nsnull; mEventTarget = nsnull; + mEmbed = nsnull; mInitialized = PR_FALSE; diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h index 0fc21a5d8..925aeff88 100644 --- a/embed/mozilla/EphyBrowser.h +++ b/embed/mozilla/EphyBrowser.h @@ -25,8 +25,8 @@ #include "config.h" #endif -#include "ephy-encodings.h" #include "ephy-embed.h" +#include <gtk/gtkwidget.h> #include <gtkmozembed.h> #include <nsCOMPtr.h> @@ -48,13 +48,15 @@ #include <nsISecureBrowserUI.h> #endif +class EphyBrowser; + class EphyEventListener : public nsIDOMEventListener { public: EphyEventListener(); virtual ~EphyEventListener(); - nsresult Init(EphyEmbed *aOwner); + nsresult Init (EphyBrowser *aOwner); NS_DECL_ISUPPORTS @@ -63,7 +65,7 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) = 0; protected: - EphyEmbed *mOwner; + EphyBrowser *mOwner; }; class EphyFaviconEventListener : public EphyEventListener @@ -86,6 +88,10 @@ public: class EphyBrowser { +friend class EphyEventListener; +friend class EphyFaviconEventListener; +friend class EphyPopupBlockEventListener; +friend class EphyModalAlertEventListener; public: EphyBrowser(); ~EphyBrowser(); @@ -144,8 +150,9 @@ public: nsresult ShowCertificate (); nsCOMPtr<nsIWebBrowser> mWebBrowser; - private: + GtkWidget *mEmbed; + nsCOMPtr<nsIDOMDocument> mTargetDocument; nsCOMPtr<nsIDOMEventTarget> mEventTarget; nsCOMPtr<nsIDOMWindow> mDOMWindow; diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 12ba6729a..496b566ad 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -89,6 +89,8 @@ #include <nsIIDNService.h> #endif +#include <stdlib.h> + #define MOZILLA_PROFILE_DIR "/mozilla" #define MOZILLA_PROFILE_NAME "epiphany" #define MOZILLA_PROFILE_FILE "prefs.js" |