Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 5788069215076352: Issue 1282 - Show error message when user tries to block whitelisted elements (Closed)
Patch Set: Created Dec. 13, 2014, 1:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « _locales/en_US/messages.json ('k') | include.postload.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -519,6 +519,55 @@
else
sendResponse(false);
break;
+ case "can-block":
+ var documentHost = extractHostFromFrame(sender.frame);
+
+ if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT"))
+ {
+ sendResponse({canBlock: false, reason: ext.i18n.getMessage("cannot_block_because_domain_whitelisted", documentHost)});
+ break;
+ }
+
+ var sitekey = getKey(sender.page, sender.frame);
+ var exception = null;
+
+ for (var i = 0; !exception && i < msg.urls.length; i++)
+ {
+ var requestHost = extractHostFromURL(msg.url);
+ var thirdParty = isThirdParty(requestHost, documentHost);
+
+ var filter = defaultMatcher.matchesAny(msg.urls[i], msg.mediatype, documentHost, thirdParty, sitekey);
+ if (filter instanceof WhitelistFilter)
+ exception = filter;
+ }
+
+ for (var i = 0; !exception && i < msg.elemHideFilters.length; i++)
+ exception = ElemHide.getException(Filter.fromText(msg.elemHideFilters[i]), documentHost);
+
+ if (exception)
+ {
+ var reason = ext.i18n.getMessage("cannot_block_because_exception_rule", exception.text);
+
+ for (var i = 0; i < exception.subscriptions.length; i++)
+ {
+ var subscription = exception.subscriptions[i];
+ if (!subscription.disabled)
+ {
+ if (subscription.url == Prefs.subscriptions_exceptionsurl)
+ reason = ext.i18n.getMessage("cannot_block_because_acceptable_ads");
+ else if (subscription.title)
+ reason = ext.i18n.getMessage("cannot_block_because_exception_rule_with_origin", [exception.text, '"' + subscription.title + '"']);
+
+ break;
+ }
+ }
+
+ sendResponse({canBlock: false, reason: reason});
+ break;
+ }
+
+ sendResponse({canBlock: true});
+ break;
case "get-domain-enabled-state":
// Returns whether this domain is in the exclusion list.
// The browser action popup asks us this.
« no previous file with comments | « _locales/en_US/messages.json ('k') | include.postload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld