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

Unified Diff: webrequest.js

Issue 8684066: Fixed "Hide placeholders of blocked elements" feature (Closed)
Patch Set: Created Oct. 26, 2012, 1:56 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
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrequest.js
===================================================================
--- a/webrequest.js
+++ b/webrequest.js
@@ -26,27 +26,17 @@ function onBeforeRequest(details)
if (type == "sub_frame")
type = "SUBDOCUMENT";
else
type = type.toUpperCase();
var frame = (type != "SUBDOCUMENT" ? details.frameId : details.parentFrameId);
var filter = checkRequest(type, details.tabId, details.url, frame);
if (filter instanceof BlockingFilter)
- {
- var collapse = filter.collapse;
- if (collapse == null)
- collapse = (localStorage["hidePlaceholders"] != "false");
- if (collapse && type == "SUBDOCUMENT")
- return {redirectUrl: "about:blank"};
- else if (collapse && type == "IMAGE")
- return {redirectUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="};
- else
- return {cancel: true};
- }
+ return {cancel: true};
else
return {};
}
function onHeadersReceived(details)
{
if (details.tabId == -1)
return;
@@ -136,17 +126,35 @@ function checkRequest(type, tabId, url,
var documentUrl = getFrameUrl(tabId, frameId);
if (!documentUrl)
return false;
var requestHost = extractHostFromURL(url);
var documentHost = extractHostFromURL(documentUrl);
var thirdParty = isThirdParty(requestHost, documentHost);
- return defaultMatcher.matchesAny(url, type, documentHost, thirdParty);
+ var filter = defaultMatcher.matchesAny(url, type, documentHost, thirdParty);
+
+ if (filter instanceof BlockingFilter)
+ {
+ var collapse = filter.collapse;
+ if (collapse == null)
+ collapse = (localStorage["hidePlaceholders"] != "false");
+ if (collapse && (type == "SUBDOCUMENT" || type == "IMAGE"))
+ {
+ chrome.tabs.sendMessage(tabId, {
+ reqtype: "hide-element",
+ type: type,
+ url: url,
+ documentUrl: documentUrl
+ });
+ }
+ }
+
+ return filter;
}
function isFrameWhitelisted(tabId, frameId, type)
{
var parent = frameId;
while (parent != -1)
{
var parentUrl = getFrameUrl(tabId, parent);
« include.preload.js ('K') | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld