| LEFT | RIGHT |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 function getDocumentInfo(page, frame, originUrl) | 80 function getDocumentInfo(page, frame, originUrl) |
| 81 { | 81 { |
| 82 return [ | 82 return [ |
| 83 extractHostFromFrame(frame, originUrl), | 83 extractHostFromFrame(frame, originUrl), |
| 84 getKey(page, frame, originUrl), | 84 getKey(page, frame, originUrl), |
| 85 !!checkWhitelisted(page, frame, originUrl, | 85 !!checkWhitelisted(page, frame, originUrl, |
| 86 RegExpFilter.typeMap.GENERICBLOCK) | 86 RegExpFilter.typeMap.GENERICBLOCK) |
| 87 ]; | 87 ]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 function matchRequest(url, type, docDomain, sitekey, specificOnly) | |
| 91 { | |
| 92 return defaultMatcher.matchesAny(url, RegExpFilter.typeMap[type], | |
| 93 docDomain, sitekey, specificOnly); | |
| 94 } | |
| 95 | |
| 96 function getRelatedTabIds(details) | 90 function getRelatedTabIds(details) |
| 97 { | 91 { |
| 98 // This is the common case, the request is associated with a single tab. | 92 // This is the common case, the request is associated with a single tab. |
| 99 // If tabId is -1, its not (e.g. the request was sent by | 93 // If tabId is -1, its not (e.g. the request was sent by |
| 100 // a Service/Shared Worker) and we have to identify the related tabs. | 94 // a Service/Shared Worker) and we have to identify the related tabs. |
| 101 if (details.tabId != -1) | 95 if (details.tabId != -1) |
| 102 return Promise.resolve([details.tabId]); | 96 return Promise.resolve([details.tabId]); |
| 103 | 97 |
| 104 let url; // Firefox provides "originUrl" indicating the | 98 let url; // Firefox provides "originUrl" indicating the |
| 105 if (details.originUrl) // URL of the tab that caused this request. | 99 if (details.originUrl) // URL of the tab that caused this request. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // this can also indicate a request sent by a Shared/Service Worker). | 171 // this can also indicate a request sent by a Shared/Service Worker). |
| 178 if (!frame && !originUrl) | 172 if (!frame && !originUrl) |
| 179 return; | 173 return; |
| 180 | 174 |
| 181 if (checkWhitelisted(page, frame, originUrl)) | 175 if (checkWhitelisted(page, frame, originUrl)) |
| 182 return; | 176 return; |
| 183 | 177 |
| 184 let type = resourceTypes.get(details.type) || "OTHER"; | 178 let type = resourceTypes.get(details.type) || "OTHER"; |
| 185 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 179 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
| 186 originUrl); | 180 originUrl); |
| 187 let filter = matchRequest(url, type, docDomain, sitekey, specificOnly); | 181 let filter = defaultMatcher.matchesAny(url, RegExpFilter.typeMap[type], |
| 182 docDomain, sitekey, specificOnly); |
| 188 | 183 |
| 189 let result; | 184 let result; |
| 190 let rewrittenUrl; | 185 let rewrittenUrl; |
| 191 | 186 |
| 192 if (filter instanceof BlockingFilter) | 187 if (filter instanceof BlockingFilter) |
| 193 { | 188 { |
| 194 if (typeof filter.rewrite == "string") | 189 if (typeof filter.rewrite == "string") |
| 195 { | 190 { |
| 196 rewrittenUrl = filter.rewriteUrl(details.url); | 191 rewrittenUrl = filter.rewriteUrl(details.url); |
| 197 // If no rewrite happened (error, different origin), we'll | 192 // If no rewrite happened (error, different origin), we'll |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 let {page, frame} = sender; | 218 let {page, frame} = sender; |
| 224 | 219 |
| 225 if (checkWhitelisted(page, frame)) | 220 if (checkWhitelisted(page, frame)) |
| 226 return false; | 221 return false; |
| 227 | 222 |
| 228 let blocked = false; | 223 let blocked = false; |
| 229 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); | 224 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); |
| 230 | 225 |
| 231 for (let url of message.urls) | 226 for (let url of message.urls) |
| 232 { | 227 { |
| 233 let filter = matchRequest(new URL(url, message.baseURL), | 228 let filter = defaultMatcher.matchesAny(new URL(url, message.baseURL), |
| 234 message.mediatype, docDomain, | 229 RegExpFilter.typeMap[message.mediatyp
e], |
| 235 sitekey, specificOnly); | 230 docDomain, sitekey, specificOnly); |
| 236 | 231 |
| 237 if (filter instanceof BlockingFilter) | 232 if (filter instanceof BlockingFilter) |
| 238 { | 233 { |
| 239 if (filter.collapse != null) | 234 if (filter.collapse != null) |
| 240 return filter.collapse; | 235 return filter.collapse; |
| 241 blocked = true; | 236 blocked = true; |
| 242 } | 237 } |
| 243 } | 238 } |
| 244 | 239 |
| 245 return blocked && Prefs.hidePlaceholders; | 240 return blocked && Prefs.hidePlaceholders; |
| 246 }); | 241 }); |
| 247 | 242 |
| 248 port.on("request.blockedByRTCWrapper", (msg, sender) => | 243 port.on("request.blockedByRTCWrapper", (msg, sender) => |
| 249 { | 244 { |
| 250 let {page, frame} = sender; | 245 let {page, frame} = sender; |
| 251 | 246 |
| 252 if (checkWhitelisted(page, frame)) | 247 if (checkWhitelisted(page, frame)) |
| 253 return false; | 248 return false; |
| 254 | 249 |
| 255 let {url} = msg; | 250 let {url} = msg; |
| 256 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); | 251 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); |
| 257 let filter = matchRequest(new URL(url), "WEBRTC", docDomain, sitekey, | 252 let filter = defaultMatcher.matchesAny(new URL(url), |
| 258 specificOnly); | 253 RegExpFilter.typeMap.WEBRTC, |
| 254 docDomain, sitekey, specificOnly); |
| 259 logRequest( | 255 logRequest( |
| 260 [sender.page.id], | 256 [sender.page.id], |
| 261 {url, type: "WEBRTC", docDomain, sitekey, specificOnly}, | 257 {url, type: "WEBRTC", docDomain, sitekey, specificOnly}, |
| 262 filter | 258 filter |
| 263 ); | 259 ); |
| 264 | 260 |
| 265 return filter instanceof BlockingFilter; | 261 return filter instanceof BlockingFilter; |
| 266 }); | 262 }); |
| 267 | 263 |
| 268 let ignoreFilterNotifications = false; | 264 let ignoreFilterNotifications = false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 321 } |
| 326 | 322 |
| 327 filterNotifier.on("subscription.added", onFilterChange); | 323 filterNotifier.on("subscription.added", onFilterChange); |
| 328 filterNotifier.on("subscription.removed", arg => onFilterChange(arg, false)); | 324 filterNotifier.on("subscription.removed", arg => onFilterChange(arg, false)); |
| 329 filterNotifier.on("subscription.updated", onFilterChange); | 325 filterNotifier.on("subscription.updated", onFilterChange); |
| 330 filterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 326 filterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
| 331 filterNotifier.on("filter.added", onFilterChange); | 327 filterNotifier.on("filter.added", onFilterChange); |
| 332 filterNotifier.on("filter.removed", onFilterChange); | 328 filterNotifier.on("filter.removed", onFilterChange); |
| 333 filterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 329 filterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
| 334 filterNotifier.on("load", onFilterChange); | 330 filterNotifier.on("load", onFilterChange); |
| LEFT | RIGHT |