| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** @module requestBlocker */ | 18 /** @module requestBlocker */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 let {RegExpFilter, BlockingFilter} = require("filterClasses"); | 22 let {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); |
| 23 let {Subscription} = require("subscriptionClasses"); |
| 23 let {defaultMatcher} = require("matcher"); | 24 let {defaultMatcher} = require("matcher"); |
| 24 let {FilterNotifier} = require("filterNotifier"); | 25 let {FilterNotifier} = require("filterNotifier"); |
| 25 let {Prefs} = require("prefs"); | 26 let {Prefs} = require("prefs"); |
| 26 let {checkWhitelisted, getKey} = require("whitelisting"); | 27 let {checkWhitelisted, getKey} = require("whitelisting"); |
| 27 let {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); | 28 let {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); |
| 28 let {port} = require("messaging"); | 29 let {port} = require("messaging"); |
| 29 let devtools = require("devtools"); | 30 let devtools = require("devtools"); |
| 30 | 31 |
| 31 ext.webRequest.getIndistinguishableTypes().forEach(types => | 32 ext.webRequest.getIndistinguishableTypes().forEach(types => |
| 32 { | 33 { |
| 33 for (let i = 1; i < types.length; i++) | 34 for (let i = 1; i < types.length; i++) |
| 34 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; | 35 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; |
| 35 }); | 36 }); |
| 36 | 37 |
| 37 function onBeforeRequestAsync(page, url, type, docDomain, | 38 function onBeforeRequestAsync(page, url, type, docDomain, |
| 38 thirdParty, sitekey, | 39 thirdParty, sitekey, |
| 39 specificOnly, filter) | 40 specificOnly, filter) |
| 40 { | 41 { |
| 41 if (filter) | 42 if (filter) |
| 42 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); | 43 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| 43 | 44 |
| 44 if (devtools) | 45 if (devtools) |
| 45 devtools.logRequest( | 46 devtools.logRequest( |
| 46 page, url, type, docDomain, | 47 page, url, type, docDomain, |
| 47 thirdParty, sitekey, | 48 thirdParty, sitekey, |
| 48 specificOnly, filter | 49 specificOnly, filter |
| 49 ); | 50 ); |
| 50 } | 51 } |
| 51 | 52 |
| 52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => | 53 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (filter.collapse != null) | 107 if (filter.collapse != null) |
| 107 return filter.collapse; | 108 return filter.collapse; |
| 108 blocked = true; | 109 blocked = true; |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 return blocked && Prefs.hidePlaceholders; | 113 return blocked && Prefs.hidePlaceholders; |
| 113 }); | 114 }); |
| 114 | 115 |
| 115 let ignoreFilterNotifications = false; | 116 let ignoreFilterNotifications = false; |
| 116 FilterNotifier.addListener((action, arg) => | 117 |
| 118 function onFilterChange(arg, isDisabledAction) |
| 117 { | 119 { |
| 118 // Avoid triggering filters.behaviorChanged multiple times | 120 // Avoid triggering filters.behaviorChanged multiple times |
| 119 // when multiple filter hanges happen at the same time. | 121 // when multiple filter hanges happen at the same time. |
| 120 if (ignoreFilterNotifications) | 122 if (ignoreFilterNotifications) |
| 121 return; | 123 return; |
| 122 | 124 |
| 123 if (action != "load") | 125 // Ignore disabled subscriptions and filters, unless they just got |
| 124 { | 126 // disabled, otherwise they have no effect on the handler behavior. |
| 125 let parts = action.split("."); | 127 if (arg && arg.disabled && !isDisabledAction) |
| 126 let [category, event] = parts; | 128 return; |
| 127 if (category == "subscription") | |
| 128 { | |
| 129 if (event != "added" && | |
| 130 event != "removed" && | |
| 131 event != "updated" && | |
| 132 event != "disabled") | |
| 133 return; | |
| 134 | 129 |
| 135 // Ignore empty subscriptions. This includes subscriptions | 130 // Ignore empty subscriptions. This includes subscriptions |
| 136 // that have just been added, but not downloaded yet. | 131 // that have just been added, but not downloaded yet. |
| 137 if (arg.filters.length == 0) | 132 if (arg instanceof Subscription && arg.filters.length == 0) |
| 138 return; | 133 return; |
| 139 } | |
| 140 else if (category == "filter") | |
| 141 { | |
| 142 if (event != "added" && | |
| 143 event != "removed" && | |
| 144 event != "disabled") | |
| 145 return; | |
| 146 | 134 |
| 147 // Ignore all types of filters but request filters, | 135 // Ignore all types of filters but request filters, |
| 148 // only these have an effect on the handler behavior. | 136 // only these have an effect on the handler behavior. |
| 149 if (!(arg instanceof RegExpFilter)) | 137 if (arg instanceof Filter && !(arg instanceof RegExpFilter)) |
| 150 return; | 138 return; |
| 151 } | |
| 152 else | |
| 153 return; | |
| 154 | |
| 155 // Ignore disabled subscriptions and filters, unless they just got | |
| 156 // disabled, otherwise they have no effect on the handler behavior. | |
| 157 if (arg.disabled && event != "disabled") | |
| 158 return; | |
| 159 } | |
| 160 | 139 |
| 161 ignoreFilterNotifications = true; | 140 ignoreFilterNotifications = true; |
| 162 setTimeout(() => | 141 setTimeout(() => |
| 163 { | 142 { |
| 164 ignoreFilterNotifications = false; | 143 ignoreFilterNotifications = false; |
| 165 ext.webRequest.handlerBehaviorChanged(); | 144 ext.webRequest.handlerBehaviorChanged(); |
| 166 FilterNotifier.triggerListeners("filter.behaviorChanged"); | 145 FilterNotifier.emit("filter.behaviorChanged"); |
| 167 }); | 146 }); |
| 168 }); | 147 } |
| 148 |
| 149 FilterNotifier.on("subscription.added", onFilterChange) |
| 150 FilterNotifier.on("subscription.removed", onFilterChange); |
| 151 FilterNotifier.on("subscription.updated", onFilterChange); |
| 152 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
| 153 FilterNotifier.on("filter.added", onFilterChange); |
| 154 FilterNotifier.on("filter.removed", onFilterChange); |
| 155 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
| 156 FilterNotifier.on("load", onFilterChange); |
| OLD | NEW |