aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--embed/ephy-embed.c16
-rw-r--r--embed/ephy-embed.h2
-rw-r--r--embed/mozilla/EphyContentPolicy.cpp60
-rw-r--r--embed/mozilla/EphyContentPolicy.h4
5 files changed, 89 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 18535d122..19494aeb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-01-08 Jean-François Rameau <jframeau@cvs.gnome.org>
+
+ * embed/mozilla/EphyContentPolicy.h:
+ * embed/mozilla/EphyContentPolicy.cpp: (ShouldLoad):
+ * embed/ephy-embed.h:
+ * embed/ephy-embed.c: (ephy_embed_base_init):
+
+ EphyContentPolicy now emits a signal when a content is blocked.
+
2006-01-08 Christian Persch <chpe@cvs.gnome.org>
* data/Makefile.am:
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index c016408c7..7c6a5bf52 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -386,6 +386,22 @@ ephy_embed_base_init (gpointer g_class)
ephy_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
+/**
+ * EphyEmbed::content-blocked:
+ * @embed:
+ * @uri: blocked URI
+ *
+ * The ::content-blocked signal is emitted when an url has been blocked.
+ **/
+ g_signal_new ("content-blocked",
+ EPHY_TYPE_EMBED,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyEmbedIface, content_blocked),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
initialized = TRUE;
}
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 6190c14b4..326385c9b 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -142,6 +142,8 @@ struct _EphyEmbedIface
float new_zoom);
void (* content_change) (EphyEmbed *embed,
const char *uri);
+ void (* content_blocked) (EphyEmbed *embed,
+ const char *uri);
gboolean (* modal_alert) (EphyEmbed *embed);
void (* modal_alert_closed) (EphyEmbed *embed);
void (* document_type) (EphyEmbed *embed,
diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp
index aedcc8aac..b5910063b 100644
--- a/embed/mozilla/EphyContentPolicy.cpp
+++ b/embed/mozilla/EphyContentPolicy.cpp
@@ -24,6 +24,7 @@
#include "config.h"
#include "EphyContentPolicy.h"
+#include "EphyUtils.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
@@ -32,10 +33,15 @@
#include "ephy-debug.h"
#include <nsCOMPtr.h>
-#include <nsIURI.h>
#undef MOZILLA_INTERNAL_API
#include <nsEmbedString.h>
#define MOZILLA_INTERNAL_API 1
+#include <nsIDOMAbstractView.h>
+#include <nsIDOMDocument.h>
+#include <nsIDOMDocumentView.h>
+#include <nsIDOMNode.h>
+#include <nsIDOMWindow.h>
+#include <nsIURI.h>
#define CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS "/apps/epiphany/lockdown/disable_unsafe_protocols"
#define CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS "/apps/epiphany/lockdown/additional_safe_protocols"
@@ -62,6 +68,49 @@ EphyContentPolicy::~EphyContentPolicy()
g_slist_free (mSafeProtocols);
}
+GtkWidget *
+EphyContentPolicy::GetEmbedFromContext (nsISupports *aContext)
+{
+ GtkWidget *ret;
+
+ /*
+ * aContext is either an nsIDOMWindow, an nsIDOMNode, or NULL. If it's
+ * an nsIDOMNode, we need the nsIDOMWindow to get the EphyEmbed.
+ */
+ if (aContext == NULL) return NULL;
+
+ nsCOMPtr<nsIDOMWindow> window;
+
+ nsCOMPtr<nsIDOMNode> node (do_QueryInterface (aContext));
+ if (node != NULL)
+ {
+ nsCOMPtr<nsIDOMDocument> domDocument;
+
+ node->GetOwnerDocument (getter_AddRefs (domDocument));
+ if (domDocument == NULL) return NULL; /* resource://... */
+
+ nsCOMPtr<nsIDOMDocumentView> docView =
+ do_QueryInterface (domDocument);
+ NS_ENSURE_TRUE (docView, NULL);
+
+ nsCOMPtr<nsIDOMAbstractView> view;
+
+ docView->GetDefaultView (getter_AddRefs (view));
+
+ window = do_QueryInterface (view);
+ }
+ else
+ {
+ window = do_QueryInterface (aContext);
+ }
+ NS_ENSURE_TRUE (window, NULL);
+
+ ret = EphyUtils::FindEmbed (window);
+ if (EPHY_IS_EMBED (ret)) return GTK_WIDGET (ret);
+
+ return NULL;
+}
+
#if MOZ_NSICONTENTPOLICY_VARIANT == 2
NS_IMETHODIMP
EphyContentPolicy::ShouldLoad(PRUint32 aContentType,
@@ -94,9 +143,16 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType,
EphyAdBlockManager *adblock_manager =
EPHY_ADBLOCK_MANAGER (ephy_embed_shell_get_adblock_manager (embed_shell));
- if (!ephy_adblock_manager_should_load (adblock_manager, spec.get (), AdUriCheckType(aContentType)))
+ if (!ephy_adblock_manager_should_load (adblock_manager, spec.get (), AdUriCheckType (aContentType)))
{
*aDecision = nsIContentPolicy::REJECT_REQUEST;
+
+ GtkWidget *embed = GetEmbedFromContext (aContext);
+
+ if (embed)
+ {
+ g_signal_emit_by_name (embed, "content-blocked", spec.get ());
+ }
return NS_OK;
}
diff --git a/embed/mozilla/EphyContentPolicy.h b/embed/mozilla/EphyContentPolicy.h
index 11e0ce9bd..3c4813a17 100644
--- a/embed/mozilla/EphyContentPolicy.h
+++ b/embed/mozilla/EphyContentPolicy.h
@@ -25,6 +25,8 @@
#include <glib.h>
#include <glib-object.h>
+#include "ephy-embed.h"
+
#include <nsISupports.h>
#include <nsIContentPolicy.h>
@@ -48,6 +50,8 @@ public:
EphyContentPolicy();
virtual ~EphyContentPolicy();
private:
+ GtkWidget *GetEmbedFromContext (nsISupports *aContext);
+
GObject *mEmbedSingle;
gboolean mLocked;
GSList *mSafeProtocols;