diff options
author | Jean-François Rameau <jframeau@cvs.gnome.org> | 2006-03-29 03:55:45 +0800 |
---|---|---|
committer | Jean-François Rameau <jframeau@src.gnome.org> | 2006-03-29 03:55:45 +0800 |
commit | c064ae70ee2c8029468479580b04b09bda3a7994 (patch) | |
tree | 4c2b5d565598111bc8465e5d11b48b55780f3c4c /embed | |
parent | 1ba9972501c252740f65d23552b447360425256d (diff) | |
download | gsoc2013-epiphany-c064ae70ee2c8029468479580b04b09bda3a7994.tar.gz gsoc2013-epiphany-c064ae70ee2c8029468479580b04b09bda3a7994.tar.zst gsoc2013-epiphany-c064ae70ee2c8029468479580b04b09bda3a7994.zip |
.
2006-03-28 Jean-François Rameau <jframeau@cvs.gnome.org>
* embed/mozilla/EphyContentPolicy.cpp: (ShouldLoad).
Mozilla backend now supports adblock.
Fix #335919.
Diffstat (limited to 'embed')
-rw-r--r-- | embed/mozilla/EphyContentPolicy.cpp | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp index 436ec0786..a78005b85 100644 --- a/embed/mozilla/EphyContentPolicy.cpp +++ b/embed/mozilla/EphyContentPolicy.cpp @@ -132,8 +132,8 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, if (isHttps) return NS_OK; /* is this url allowed ? */ - nsEmbedCString spec; - aContentLocation->GetSpec(spec); + nsEmbedCString contentSpec; + aContentLocation->GetSpec (contentSpec); EphyAdBlockManager *adblock_manager = EPHY_ADBLOCK_MANAGER (ephy_embed_shell_get_adblock_manager (embed_shell)); @@ -151,7 +151,9 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, }; if (kBlockType[aContentType < G_N_ELEMENTS (kBlockType) ? aContentType : 0] && - !ephy_adblock_manager_should_load (adblock_manager, spec.get (), AdUriCheckType (aContentType))) + !ephy_adblock_manager_should_load (adblock_manager, + contentSpec.get (), + AdUriCheckType (aContentType))) { *aDecision = nsIContentPolicy::REJECT_REQUEST; @@ -159,7 +161,9 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, if (embed) { - g_signal_emit_by_name (embed, "content-blocked", spec.get ()); + g_signal_emit_by_name (embed, + "content-blocked", + contentSpec.get ()); } return NS_OK; } @@ -168,8 +172,6 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, aContentLocation->SchemeIs ("http", &isHttp); if (isHttp) return NS_OK; - nsEmbedCString contentSpec; - aContentLocation->GetSpec (contentSpec); if (strcmp (contentSpec.get(), "about:blank") == 0) return NS_OK; nsEmbedCString contentScheme; @@ -212,10 +214,9 @@ NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 aContentType, *_retval = PR_TRUE; - PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; - aContentLocation->SchemeIs ("http", &isHttp); + PRBool isHttps = PR_FALSE; aContentLocation->SchemeIs ("https", &isHttps); - if (isHttp || isHttps) return NS_OK; + if (isHttps) return NS_OK; /* We have to always allow these, else forms and scrollbars break */ PRBool isChrome = PR_FALSE, isResource = PR_FALSE; @@ -225,6 +226,44 @@ NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 aContentType, nsEmbedCString contentSpec; aContentLocation->GetSpec (contentSpec); + + EphyAdBlockManager *adblock_manager = + EPHY_ADBLOCK_MANAGER (ephy_embed_shell_get_adblock_manager (embed_shell)); + + /* try to remap 1.7 types to 1.8 */ + static struct {PRBool should_block; PRUint32 remap;} kBlockType[nsIContentPolicy::DOCUMENT + 1] = { + {PR_TRUE /* TYPE_OTHER */, 1}, + {PR_TRUE /* TYPE_SCRIPT */,2}, + {PR_TRUE /* TYPE_IMAGE */, 3}, + {PR_FALSE /* TYPE_STYLESHEET */, 4}, + {PR_TRUE /* TYPE_OBJECT */, 5}, + {PR_TRUE /* TYPE_SUBDOCUMENT */, 7}, + {PR_TRUE /* TYPE_CONTROL_TAG */, 1}, + {PR_TRUE /* TYPE_RAW_URL */, 1}, + {PR_FALSE /* TYPE_DOCUMENT */, 6} + }; + + PRUint32 indexPolicy = aContentType < G_N_ELEMENTS (kBlockType) ? aContentType : 1; + if (kBlockType[indexPolicy].should_block && + !ephy_adblock_manager_should_load (adblock_manager, + contentSpec.get (), + AdUriCheckType (kBlockType[indexPolicy].remap))) + { + *_retval = PR_FALSE; + + GtkWidget *embed = GetEmbedFromContext (aContext); + + if (embed) + { + g_signal_emit_by_name (embed, "content-blocked", contentSpec.get ()); + } + return NS_OK; + } + + PRBool isHttp = PR_FALSE; + aContentLocation->SchemeIs ("http", &isHttp); + if (isHttp) return NS_OK; + if (strcmp (contentSpec.get(), "about:blank") == 0) return NS_OK; nsEmbedCString contentScheme; |