| Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 if (!(browser.webRequest.ResourceType)) | 63 if (!(browser.webRequest.ResourceType)) | 
| 64 return; | 64 return; | 
| 65 | 65 | 
| 66 for (let type in browser.webRequest.ResourceType) | 66 for (let type in browser.webRequest.ResourceType) | 
| 67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; | 67 yield resourceTypes.get(browser.webRequest.ResourceType[type]) || "OTHER"; | 
| 68 | 68 | 
| 69 // WEBRTC gets addressed through a workaround, even if the webRequest API is | 69 // WEBRTC gets addressed through a workaround, even if the webRequest API is | 
| 70 // lacking support to block this kind of a request. | 70 // lacking support to block this kind of a request. | 
| 71 yield "WEBRTC"; | 71 yield "WEBRTC"; | 
| 72 | 72 | 
| 73 // POPUP, CSP and ELEMHIDE filters aren't mapped to resource types. | 73 // These filter types aren't mapped to resource types. | 
| 74 yield "POPUP"; | 74 yield "POPUP"; | 
| 75 yield "ELEMHIDE"; | 75 yield "ELEMHIDE"; | 
| 76 yield "CSP"; | 76 yield "CSP"; | 
| 77 }()); | 77 }()); | 
| 78 | 78 | 
| 79 function getDocumentInfo(page, frame, originUrl) | 79 function getDocumentInfo(page, frame, originUrl) | 
| 80 { | 80 { | 
| 81 return [ | 81 return [ | 
| 82 extractHostFromFrame(frame, originUrl), | 82 extractHostFromFrame(frame, originUrl), | 
| 83 getKey(page, frame, originUrl), | 83 getKey(page, frame, originUrl), | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox | 116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox | 
| 117 // except that its not a full URL but just | 117 // except that its not a full URL but just | 
| 118 // an origin (proto + host). | 118 // an origin (proto + host). | 
| 119 else | 119 else | 
| 120 return Promise.resolve([]); | 120 return Promise.resolve([]); | 
| 121 | 121 | 
| 122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); | 122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); | 
| 123 } | 123 } | 
| 124 | 124 | 
| 125 function logRequest(tabIds, url, type, docDomain, thirdParty, | 125 function logRequest(tabIds, url, type, docDomain, thirdParty, | 
| 126 sitekey, specificOnly, filter) | 126 sitekey, specificOnly, filter, rewrittenTo) | 
| 127 { | 127 { | 
| 128 if (filter) | 128 if (filter) | 
| 129 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 129 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 
| 130 | 130 | 
| 131 devtools.logRequest( | 131 devtools.logRequest( | 
| 132 tabIds, url, type, docDomain, | 132 tabIds, url, type, docDomain, | 
| 133 thirdParty, sitekey, | 133 thirdParty, sitekey, | 
| 134 specificOnly, filter | 134 specificOnly, filter, rewrittenTo | 
| 135 ); | 135 ); | 
| 136 } | 136 } | 
| 137 | 137 | 
| 138 browser.webRequest.onBeforeRequest.addListener(details => | 138 browser.webRequest.onBeforeRequest.addListener(details => | 
| 139 { | 139 { | 
| 140 // Never block top-level documents. | 140 // Never block top-level documents. | 
| 141 if (details.type == "main_frame") | 141 if (details.type == "main_frame") | 
| 142 return; | 142 return; | 
| 143 | 143 | 
| 144 // Filter out requests from non web protocols. Ideally, we'd explicitly | 144 // Filter out requests from non web protocols. Ideally, we'd explicitly | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 187 | 
| 188 if (checkWhitelisted(page, frame, originUrl)) | 188 if (checkWhitelisted(page, frame, originUrl)) | 
| 189 return; | 189 return; | 
| 190 | 190 | 
| 191 let type = resourceTypes.get(details.type) || "OTHER"; | 191 let type = resourceTypes.get(details.type) || "OTHER"; | 
| 192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 
| 193 originUrl); | 193 originUrl); | 
| 194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, | 194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, | 
| 195 sitekey, specificOnly); | 195 sitekey, specificOnly); | 
| 196 | 196 | 
| 197 let result; | |
| 198 let rewritten; | |
| 
 
Sebastian Noack
2018/05/05 13:46:53
Nit: Since these variables are no always assigned
 
hub
2018/05/07 20:13:04
In both cases they are undefined which is totally
 
 | |
| 199 | |
| 200 if (filter instanceof BlockingFilter) | |
| 201 { | |
| 202 if (filter.rewrite) | |
| 203 { | |
| 204 rewritten = filter.rewriteUrl(urlString); | |
| 205 // if no rewrite happened (error, diff origin), we'll | |
| 
 
Sebastian Noack
2018/05/05 13:46:53
Nit: Capitalize first letter of comment (if it is
 
hub
2018/05/07 20:13:04
Done.
 
 | |
| 206 // return undefined avoid an "infinite" loop. | |
| 
 
Sebastian Noack
2018/05/05 13:46:53
Typo: ... in order to avoid ...
 
hub
2018/05/07 20:13:04
Done.
 
 | |
| 207 if (rewritten != urlString) | |
| 208 result = {redirectUrl: rewritten}; | |
| 209 } | |
| 210 else | |
| 211 result = {cancel: true}; | |
| 212 } | |
| 213 | |
| 197 getRelatedTabIds(details).then(tabIds => | 214 getRelatedTabIds(details).then(tabIds => | 
| 198 { | 215 { | 
| 199 logRequest(tabIds, urlString, type, docDomain, | 216 logRequest(tabIds, urlString, type, docDomain, | 
| 200 thirdParty, sitekey, specificOnly, filter); | 217 thirdParty, sitekey, specificOnly, filter, rewritten); | 
| 
 
Manish Jethani
2018/05/05 00:54:12
For what it's worth, I think we should do the logg
 
Sebastian Noack
2018/05/05 13:46:53
Without the logging changes, I consider the result
 
hub
2018/05/07 20:13:04
Without the UI patch, it will just be logged as a
 
 | |
| 201 }); | 218 }); | 
| 202 | 219 | 
| 203 if (filter instanceof BlockingFilter) | 220 return result; | 
| 204 return {cancel: true}; | |
| 205 }, {urls: ["<all_urls>"]}, ["blocking"]); | 221 }, {urls: ["<all_urls>"]}, ["blocking"]); | 
| 206 | 222 | 
| 207 port.on("filters.collapse", (message, sender) => | 223 port.on("filters.collapse", (message, sender) => | 
| 208 { | 224 { | 
| 209 let {page, frame} = sender; | 225 let {page, frame} = sender; | 
| 210 | 226 | 
| 211 if (checkWhitelisted(page, frame)) | 227 if (checkWhitelisted(page, frame)) | 
| 212 return false; | 228 return false; | 
| 213 | 229 | 
| 214 let blocked = false; | 230 let blocked = false; | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 325 } | 
| 310 | 326 | 
| 311 FilterNotifier.on("subscription.added", onFilterChange); | 327 FilterNotifier.on("subscription.added", onFilterChange); | 
| 312 FilterNotifier.on("subscription.removed", onFilterChange); | 328 FilterNotifier.on("subscription.removed", onFilterChange); | 
| 313 FilterNotifier.on("subscription.updated", onFilterChange); | 329 FilterNotifier.on("subscription.updated", onFilterChange); | 
| 314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 330 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 
| 315 FilterNotifier.on("filter.added", onFilterChange); | 331 FilterNotifier.on("filter.added", onFilterChange); | 
| 316 FilterNotifier.on("filter.removed", onFilterChange); | 332 FilterNotifier.on("filter.removed", onFilterChange); | 
| 317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 333 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 
| 318 FilterNotifier.on("load", onFilterChange); | 334 FilterNotifier.on("load", onFilterChange); | 
| OLD | NEW |