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

Delta Between Two Patch Sets: webrequest.js

Issue 8354161: Align whitelisting behavior in Chrome with Firefox (Closed)
Left Patch Set: Created Sept. 17, 2012, 2:52 p.m.
Right Patch Set: Created Sept. 18, 2012, 3:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: [" http://*/*", "https://*/*"]}, ["requestHeaders", "blocking"]); 8 chrome.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, {urls: [" http://*/*", "https://*/*"]}, ["requestHeaders", "blocking"]);
9 chrome.tabs.onRemoved.addListener(forgetTab); 9 chrome.tabs.onRemoved.addListener(forgetTab);
10 10
11 var frames = {}; 11 var frames = {};
12 12
13 function onBeforeRequest(details) 13 function onBeforeRequest(details)
14 { 14 {
15 if (details.tabId == -1) 15 if (details.tabId == -1)
16 return {}; 16 return {};
17 17
18 var type = details.type; 18 var type = details.type;
19 if (type == "main_frame" || type == "sub_frame") 19 if (type == "main_frame" || type == "sub_frame")
20 recordFrame(details.tabId, details.frameId, details.parentFrameId, details.u rl, type == "main_frame"); 20 recordFrame(details.tabId, details.frameId, details.parentFrameId, details.u rl);
Felix Dahlke 2012/09/18 13:23:14 type == "main_frame" is redundant here, I'd assign
21 21
22 if (type == "main_frame") 22 if (type == "main_frame")
23 return {}; 23 return {};
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
(...skipping 23 matching lines...) Expand all
54 var headers = details.requestHeaders || []; 54 var headers = details.requestHeaders || [];
55 if (!headers.some(function(header) { header.name == "DNT";})) 55 if (!headers.some(function(header) { header.name == "DNT";}))
56 { 56 {
57 headers.push({name: "DNT", value: "1"}); 57 headers.push({name: "DNT", value: "1"});
58 return {requestHeaders: headers}; 58 return {requestHeaders: headers};
59 } 59 }
60 } 60 }
61 return null; 61 return null;
62 } 62 }
63 63
64 function recordFrame(tabId, frameId, parentFrameId, frameUrl, isMain) 64 function recordFrame(tabId, frameId, parentFrameId, frameUrl)
Felix Dahlke 2012/09/18 13:23:14 This parameter is no longer used, it could be remo
65 { 65 {
66 if (!(tabId in frames)) 66 if (!(tabId in frames))
67 frames[tabId] = {}; 67 frames[tabId] = {};
68 frames[tabId][frameId] = {url: frameUrl, parent: parentFrameId}; 68 frames[tabId][frameId] = {url: frameUrl, parent: parentFrameId};
69 } 69 }
70 70
71 function getFrameUrl(tabId, frameId) 71 function getFrameUrl(tabId, frameId)
72 { 72 {
73 if (tabId in frames && frameId in frames[tabId]) 73 if (tabId in frames && frameId in frames[tabId])
74 return frames[tabId][frameId].url; 74 return frames[tabId][frameId].url;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 var parent = frameId; 107 var parent = frameId;
108 while (parent != -1) 108 while (parent != -1)
109 { 109 {
110 var parentUrl = getFrameUrl(tabId, parent); 110 var parentUrl = getFrameUrl(tabId, parent);
111 if (parentUrl && isWhitelisted(parentUrl, type)) 111 if (parentUrl && isWhitelisted(parentUrl, type))
112 return true; 112 return true;
113 parent = getFrameParent(tabId, parent); 113 parent = getFrameParent(tabId, parent);
114 } 114 }
115 return false; 115 return false;
116 } 116 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld