aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyContentPolicy.cpp
diff options
context:
space:
mode:
authorJean-François Rameau <jframeau@cvs.gnome.org>2006-01-09 06:28:09 +0800
committerJean-François Rameau <jframeau@src.gnome.org>2006-01-09 06:28:09 +0800
commitc682e0acc7c7ff2e9c194d7db1a5b756ac6beb69 (patch)
tree42bd9a664c00471209c04abed19ae83197c0a340 /embed/mozilla/EphyContentPolicy.cpp
parent02aa0ad6720d78042850f3b8cd92d020aad47881 (diff)
downloadgsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar.gz
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar.bz2
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar.lz
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar.xz
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.tar.zst
gsoc2013-epiphany-c682e0acc7c7ff2e9c194d7db1a5b756ac6beb69.zip
EphyContentPolicy now emits a signal when a content is blocked.
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.
Diffstat (limited to 'embed/mozilla/EphyContentPolicy.cpp')
-rw-r--r--embed/mozilla/EphyContentPolicy.cpp60
1 files changed, 58 insertions, 2 deletions
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;
}