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

Side by Side Diff: webrequest.js

Issue 8684066: Fixed "Hide placeholders of blocked elements" feature (Closed)
Patch Set: Created Oct. 26, 2012, 2:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://* /*", "https://*/*"]}, ["blocking"]); 7 chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://* /*", "https://*/*"]}, ["blocking"]);
8 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["http ://*/*", "https://*/*"]}, ["responseHeaders"]); 8 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["http ://*/*", "https://*/*"]}, ["responseHeaders"]);
9 chrome.tabs.onRemoved.addListener(forgetTab); 9 chrome.tabs.onRemoved.addListener(forgetTab);
10 10
(...skipping 13 matching lines...) Expand all
24 24
25 // Type names match Mozilla's with main_frame and sub_frame being the only exc eptions. 25 // Type names match Mozilla's with main_frame and sub_frame being the only exc eptions.
26 if (type == "sub_frame") 26 if (type == "sub_frame")
27 type = "SUBDOCUMENT"; 27 type = "SUBDOCUMENT";
28 else 28 else
29 type = type.toUpperCase(); 29 type = type.toUpperCase();
30 30
31 var frame = (type != "SUBDOCUMENT" ? details.frameId : details.parentFrameId); 31 var frame = (type != "SUBDOCUMENT" ? details.frameId : details.parentFrameId);
32 var filter = checkRequest(type, details.tabId, details.url, frame); 32 var filter = checkRequest(type, details.tabId, details.url, frame);
33 if (filter instanceof BlockingFilter) 33 if (filter instanceof BlockingFilter)
34 { 34 return {cancel: true};
35 var collapse = filter.collapse;
36 if (collapse == null)
37 collapse = (localStorage["hidePlaceholders"] != "false");
38 if (collapse && type == "SUBDOCUMENT")
39 return {redirectUrl: "about:blank"};
40 else if (collapse && type == "IMAGE")
41 return {redirectUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAA ABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="};
42 else
43 return {cancel: true};
44 }
45 else 35 else
46 return {}; 36 return {};
47 } 37 }
48 38
49 function onHeadersReceived(details) 39 function onHeadersReceived(details)
50 { 40 {
51 if (details.tabId == -1) 41 if (details.tabId == -1)
52 return; 42 return;
53 43
54 var type = details.type; 44 var type = details.type;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (isFrameWhitelisted(tabId, frameId)) 124 if (isFrameWhitelisted(tabId, frameId))
135 return false; 125 return false;
136 126
137 var documentUrl = getFrameUrl(tabId, frameId); 127 var documentUrl = getFrameUrl(tabId, frameId);
138 if (!documentUrl) 128 if (!documentUrl)
139 return false; 129 return false;
140 130
141 var requestHost = extractHostFromURL(url); 131 var requestHost = extractHostFromURL(url);
142 var documentHost = extractHostFromURL(documentUrl); 132 var documentHost = extractHostFromURL(documentUrl);
143 var thirdParty = isThirdParty(requestHost, documentHost); 133 var thirdParty = isThirdParty(requestHost, documentHost);
144 return defaultMatcher.matchesAny(url, type, documentHost, thirdParty); 134 var filter = defaultMatcher.matchesAny(url, type, documentHost, thirdParty);
135
136 if (filter instanceof BlockingFilter)
137 {
138 var collapse = filter.collapse;
139 if (collapse == null)
140 collapse = (localStorage["hidePlaceholders"] != "false");
141 if (collapse && (type == "SUBDOCUMENT" || type == "IMAGE"))
142 {
143 chrome.tabs.sendMessage(tabId, {
144 reqtype: "hide-element",
145 type: type,
146 url: url,
147 documentUrl: documentUrl
148 });
149 }
150 }
151
152 return filter;
145 } 153 }
146 154
147 function isFrameWhitelisted(tabId, frameId, type) 155 function isFrameWhitelisted(tabId, frameId, type)
148 { 156 {
149 var parent = frameId; 157 var parent = frameId;
150 while (parent != -1) 158 while (parent != -1)
151 { 159 {
152 var parentUrl = getFrameUrl(tabId, parent); 160 var parentUrl = getFrameUrl(tabId, parent);
153 if (parentUrl && isWhitelisted(parentUrl, type)) 161 if (parentUrl && isWhitelisted(parentUrl, type))
154 return true; 162 return true;
155 if (parentUrl && "keyException" in frames[tabId][frameId]) 163 if (parentUrl && "keyException" in frames[tabId][frameId])
156 return true; 164 return true;
157 parent = getFrameParent(tabId, parent); 165 parent = getFrameParent(tabId, parent);
158 } 166 }
159 return false; 167 return false;
160 } 168 }
OLDNEW
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld