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

Side by Side Diff: lib/requestBlocker.js

Issue 29737602: Issue 4580 - Make filter/request logging use plain tabIds, prepare for multi-tab requests (Closed)
Patch Set: Removed outdated comment Created April 4, 2018, 1:48 a.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 | « lib/popupBlocker.js ('k') | lib/stats.js » ('j') | 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 file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // WEBRTC gets addressed through a workaround, even if the webRequest API is 66 // WEBRTC gets addressed through a workaround, even if the webRequest API is
67 // lacking support to block this kind of a request. 67 // lacking support to block this kind of a request.
68 yield "WEBRTC"; 68 yield "WEBRTC";
69 69
70 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types. 70 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types.
71 yield "POPUP"; 71 yield "POPUP";
72 yield "ELEMHIDE"; 72 yield "ELEMHIDE";
73 yield "CSP"; 73 yield "CSP";
74 }()); 74 }());
75 75
76 function onBeforeRequestAsync(page, url, type, docDomain, 76 function onBeforeRequestAsync(tabId, url, type, docDomain,
77 thirdParty, sitekey, 77 thirdParty, sitekey,
78 specificOnly, filter) 78 specificOnly, filter)
79 { 79 {
80 let tabIds = tabId != -1 ? [tabId] : [];
81
80 if (filter) 82 if (filter)
81 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); 83 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
82 84
83 if (devtools) 85 devtools.logRequest(
84 { 86 tabIds, url, type, docDomain,
85 devtools.logRequest( 87 thirdParty, sitekey,
86 page, url, type, docDomain, 88 specificOnly, filter
87 thirdParty, sitekey, 89 );
88 specificOnly, filter
89 );
90 }
91 } 90 }
92 91
93 browser.webRequest.onBeforeRequest.addListener(details => 92 browser.webRequest.onBeforeRequest.addListener(details =>
94 { 93 {
95 // Never block top-level documents. 94 // Never block top-level documents.
96 if (details.type == "main_frame") 95 if (details.type == "main_frame")
97 return; 96 return;
98 97
99 // Filter out requests from non web protocols. Ideally, we'd explicitly 98 // Filter out requests from non web protocols. Ideally, we'd explicitly
100 // specify the protocols we are interested in (i.e. http://, https://, 99 // specify the protocols we are interested in (i.e. http://, https://,
(...skipping 17 matching lines...) Expand all
118 117
119 let frame = ext.getFrame( 118 let frame = ext.getFrame(
120 details.tabId, 119 details.tabId,
121 // We are looking for the frame that contains the element which 120 // We are looking for the frame that contains the element which
122 // has triggered this request. For most requests (e.g. images) we 121 // has triggered this request. For most requests (e.g. images) we
123 // can just use the request's frame ID, but for subdocument requests 122 // can just use the request's frame ID, but for subdocument requests
124 // (e.g. iframes) we must instead use the request's parent frame ID. 123 // (e.g. iframes) we must instead use the request's parent frame ID.
125 details.type == "sub_frame" ? details.parentFrameId : details.frameId 124 details.type == "sub_frame" ? details.parentFrameId : details.frameId
126 ); 125 );
127 126
128 let page = null;
129 let docDomain = null; 127 let docDomain = null;
130 let sitekey = null; 128 let sitekey = null;
131 let thirdParty = false; 129 let thirdParty = false;
132 let specificOnly = false; 130 let specificOnly = false;
133 131
134 if (frame) 132 if (frame)
135 { 133 {
136 page = new ext.Page({id: details.tabId}); 134 let page = new ext.Page({id: details.tabId});
137 135
138 if (checkWhitelisted(page, frame)) 136 if (checkWhitelisted(page, frame))
139 return; 137 return;
140 138
141 docDomain = extractHostFromFrame(frame); 139 docDomain = extractHostFromFrame(frame);
142 sitekey = getKey(page, frame); 140 sitekey = getKey(page, frame);
143 thirdParty = isThirdParty(url, docDomain); 141 thirdParty = isThirdParty(url, docDomain);
144 specificOnly = !!checkWhitelisted(page, frame, 142 specificOnly = !!checkWhitelisted(page, frame,
145 RegExpFilter.typeMap.GENERICBLOCK); 143 RegExpFilter.typeMap.GENERICBLOCK);
146 } 144 }
147 145
148 let urlString = stringifyURL(url); 146 let urlString = stringifyURL(url);
149 let type = resourceTypes.get(details.type) || "OTHER"; 147 let type = resourceTypes.get(details.type) || "OTHER";
150 let filter = defaultMatcher.matchesAny( 148 let filter = defaultMatcher.matchesAny(
151 urlString, RegExpFilter.typeMap[type], 149 urlString, RegExpFilter.typeMap[type],
152 docDomain, thirdParty, sitekey, specificOnly 150 docDomain, thirdParty, sitekey, specificOnly
153 ); 151 );
154 152
155 setTimeout(onBeforeRequestAsync, 0, page, urlString, 153 setTimeout(onBeforeRequestAsync, 0, details.tabId, urlString,
156 type, docDomain, 154 type, docDomain,
157 thirdParty, sitekey, 155 thirdParty, sitekey,
158 specificOnly, filter); 156 specificOnly, filter);
159 157
160 if (filter instanceof BlockingFilter) 158 if (filter instanceof BlockingFilter)
161 return {cancel: true}; 159 return {cancel: true};
162 }, {urls: ["<all_urls>"]}, ["blocking"]); 160 }, {urls: ["<all_urls>"]}, ["blocking"]);
163 161
164 port.on("filters.collapse", (message, sender) => 162 port.on("filters.collapse", (message, sender) =>
165 { 163 {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 239
242 port.on("request.blockedByRTCWrapper", (msg, sender) => 240 port.on("request.blockedByRTCWrapper", (msg, sender) =>
243 { 241 {
244 return ext.webRequest.onBeforeRequest._dispatch( 242 return ext.webRequest.onBeforeRequest._dispatch(
245 new URL(msg.url), 243 new URL(msg.url),
246 "webrtc", 244 "webrtc",
247 sender.page, 245 sender.page,
248 sender.frame 246 sender.frame
249 ).includes(false); 247 ).includes(false);
250 }); 248 });
OLDNEW
« no previous file with comments | « lib/popupBlocker.js ('k') | lib/stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld