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

Unified Diff: background.js

Issue 8354161: Align whitelisting behavior in Chrome with Firefox (Closed)
Patch Set: Created Sept. 17, 2012, 2:52 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 | « no previous file | include.preload.js » ('j') | webrequest.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -49,24 +49,24 @@ function setDefaultOptions()
// Upgrade options before we do anything else.
setDefaultOptions();
/**
* Checks whether a page is whitelisted.
* @param url {String}
* @return {Filter} filter that matched the URL or null if not whitelisted
*/
-function isWhitelisted(url)
+function isWhitelisted(url, type)
Felix Dahlke 2012/09/18 13:23:14 The new type parameter isn't documented above.
{
// Ignore fragment identifier
var index = url.indexOf("#");
if (index >= 0)
url = url.substring(0, index);
- var result = defaultMatcher.matchesAny(url, "DOCUMENT", extractHostFromURL(url), false);
+ var result = defaultMatcher.matchesAny(url, type || "DOCUMENT", extractHostFromURL(url), false);
return (result instanceof WhitelistFilter ? result : null);
}
// Adds or removes page action icon according to options.
function refreshIconAndContextMenu(tab)
{
// The tab could have been closed by the time this function is called
if(!tab)
@@ -351,21 +351,43 @@ function showContextMenu()
chrome.extension.onRequest.addListener(function(request, sender, sendResponse)
{
switch (request.reqtype)
{
case "get-settings":
var hostDomain = null;
var selectors = null;
- var enabled = sender.tab ? !isWhitelisted(sender.tab.url) : true;
+
+ // HACK: We don't know which frame sent us the message, try to find it
+ // in webRequest's frame data.
+ var tabId = -1;
+ var frameId = -1;
+ if (sender.tab)
+ {
+ var tabId = sender.tab.id;
Felix Dahlke 2012/09/18 13:23:14 You're redeclaring tabId here.
+ if (tabId in frames)
Felix Dahlke 2012/09/18 13:23:14 I don't think this statement is necessary here. Th
Wladimir Palant 2012/09/18 15:12:11 Yes, I don't usually rely on this and generally av
+ {
+ for (var f in frames[tabId])
+ {
+ if (getFrameUrl(tabId, f) == request.frameUrl)
+ {
+ frameId = f;
+ break;
+ }
+ }
+ }
+ }
+
+ var enabled = !isFrameWhitelisted(tabId, frameId, "DOCUMENT") && !isFrameWhitelisted(tabId, frameId, "ELEMHIDE");
if (enabled && request.selectors)
{
var noStyleRules = false;
- var host = request.host;
+ var host = extractHostFromURL(request.frameUrl);
+ hostDomain = getBaseDomain(host);
for (var i = 0; i < noStyleRulesHosts.length; i++)
{
var noStyleHost = noStyleRulesHosts[i];
if (host == noStyleHost || (host.length > noStyleHost.length &&
host.substr(host.length - noStyleHost.length - 1) == "." + noStyleHost))
{
noStyleRules = true;
}
@@ -374,18 +396,17 @@ chrome.extension.onRequest.addListener(f
if (noStyleRules)
{
selectors = selectors.filter(function(s)
{
return !/\[style[\^\$]?=/.test(s);
});
}
}
- if (enabled)
- hostDomain = getBaseDomain(request.host);
+
sendResponse({enabled: enabled, hostDomain: hostDomain, selectors: selectors});
break;
case "get-domain-enabled-state":
// Returns whether this domain is in the exclusion list.
// The page action popup asks us this.
if(sender.tab)
{
sendResponse({enabled: !isWhitelisted(sender.tab.url), specialCaseYouTube: localStorage["specialCaseYouTube"] == "true", disableInlineTextAds: localStorage["disableInlineTextAds"] == "true"});
« no previous file with comments | « no previous file | include.preload.js » ('j') | webrequest.js » ('J')

Powered by Google App Engine
This is Rietveld