Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -462,42 +462,48 @@ function openOptions(callback) |
} |
}; |
chrome.tabs.onUpdated.addListener(listener); |
} |
}); |
} |
} |
+/** |
+ * This function is a hack - we only know the tabId and document URL for a |
+ * message but we need to know the frame ID. Try to find it in webRequest's |
+ * frame data. |
+ */ |
+function getFrameId(tabId, url) |
+{ |
+ if (tabId in frames) |
+ { |
+ for (var f in frames[tabId]) |
+ { |
+ if (getFrameUrl(tabId, f) == url) |
+ return f; |
+ } |
+ } |
+ return -1; |
+} |
+ |
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) |
{ |
switch (request.reqtype) |
{ |
case "get-settings": |
var hostDomain = null; |
var selectors = null; |
- // 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) |
{ |
tabId = sender.tab.id; |
- if (tabId in frames) |
- { |
- for (var f in frames[tabId]) |
- { |
- if (getFrameUrl(tabId, f) == request.frameUrl) |
- { |
- frameId = f; |
- break; |
- } |
- } |
- } |
+ frameId = getFrameId(tabId, request.frameUrl); |
} |
var enabled = !isFrameWhitelisted(tabId, frameId, "DOCUMENT") && !isFrameWhitelisted(tabId, frameId, "ELEMHIDE"); |
if (enabled && request.selectors) |
{ |
var noStyleRules = false; |
var host = extractHostFromURL(request.frameUrl); |
hostDomain = getBaseDomain(host); |
@@ -517,16 +523,46 @@ chrome.extension.onRequest.addListener(f |
{ |
return !/\[style[\^\$]?=/.test(s); |
}); |
} |
} |
sendResponse({enabled: enabled, hostDomain: hostDomain, selectors: selectors}); |
break; |
+ case "should-collapse": |
+ var tabId = -1; |
+ var frameId = -1; |
+ if (sender.tab) |
+ { |
+ tabId = sender.tab.id; |
+ frameId = getFrameId(tabId, request.documentUrl); |
+ } |
+ |
+ var enabled = !isFrameWhitelisted(tabId, frameId, "DOCUMENT"); |
+ if (!enabled) |
Thomas Greiner
2012/10/31 11:32:00
very confusing
why not simply like that:
if (isFr
Wladimir Palant
2012/10/31 12:17:53
That's code copied from element hiding handling ab
|
+ { |
+ sendResponse(false); |
+ break; |
+ } |
+ |
+ var requestHost = extractHostFromURL(request.url); |
+ var documentHost = extractHostFromURL(request.documentUrl); |
+ var thirdParty = isThirdParty(requestHost, documentHost); |
+ var filter = defaultMatcher.matchesAny(request.url, request.type, documentHost, thirdParty); |
+ if (filter instanceof BlockingFilter) |
+ { |
+ var collapse = filter.collapse; |
+ if (collapse == null) |
+ collapse = (localStorage.hidePlaceholders != "false"); |
+ sendResponse(collapse); |
+ } |
+ else |
+ sendResponse(false); |
+ 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"}); |
return; |
} |