| Left: | ||
| Right: |
| 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-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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 let {port} = require("messaging"); | 28 let {port} = require("messaging"); |
| 29 let devtools = require("devtools"); | 29 let devtools = require("devtools"); |
| 30 | 30 |
| 31 ext.webRequest.getIndistinguishableTypes().forEach(types => | 31 ext.webRequest.getIndistinguishableTypes().forEach(types => |
| 32 { | 32 { |
| 33 for (let i = 1; i < types.length; i++) | 33 for (let i = 1; i < types.length; i++) |
| 34 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; | 34 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 function onBeforeRequestAsync(page, url, type, docDomain, | 37 function onBeforeRequestAsync(page, url, type, docDomain, |
| 38 thirdParty, key, specificOnly, | 38 thirdParty, sitekey, |
| 39 filter) | 39 specificOnly, filter) |
| 40 { | 40 { |
| 41 if (filter) | 41 if (filter) |
| 42 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); | 42 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); |
| 43 | 43 |
| 44 if (devtools) | 44 if (devtools) |
| 45 devtools.logRequest( | 45 devtools.logRequest( |
| 46 page, url, type, docDomain, | 46 page, url, type, docDomain, |
| 47 thirdParty, key, specificOnly, | 47 thirdParty, sitekey, |
| 48 filter | 48 specificOnly, filter |
| 49 ); | 49 ); |
| 50 } | 50 } |
| 51 | 51 |
| 52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => | 52 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| 53 { | 53 { |
| 54 if (checkWhitelisted(page, frame)) | 54 if (checkWhitelisted(page, frame)) |
| 55 return true; | 55 return true; |
| 56 | 56 |
| 57 let urlString = stringifyURL(url); | 57 let urlString = stringifyURL(url); |
| 58 let docDomain = extractHostFromFrame(frame); | 58 let docDomain = extractHostFromFrame(frame); |
| 59 let thirdParty = isThirdParty(url, docDomain); | 59 let thirdParty = isThirdParty(url, docDomain); |
| 60 let key = getKey(page, frame); | 60 let sitekey = getKey(page, frame); |
| 61 | 61 |
| 62 let specificOnly = !!checkWhitelisted( | 62 let specificOnly = !!checkWhitelisted( |
| 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK | 63 page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| 64 ); | 64 ); |
| 65 | 65 |
| 66 let filter = defaultMatcher.matchesAny( | 66 let filter = defaultMatcher.matchesAny( |
| 67 urlString, RegExpFilter.typeMap[type], | 67 urlString, RegExpFilter.typeMap[type], |
| 68 docDomain, thirdParty, key, specificOnly | 68 docDomain, thirdParty, sitekey, specificOnly |
| 69 ); | 69 ); |
| 70 | 70 |
| 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, | 71 setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| 72 type, docDomain, | 72 type, docDomain, |
| 73 thirdParty, key, | 73 thirdParty, sitekey, |
| 74 specificOnly, filter); | 74 specificOnly, filter); |
| 75 | 75 |
| 76 return !(filter instanceof BlockingFilter); | 76 return !(filter instanceof BlockingFilter); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 port.on("filters.collapse", (message, sender) => | 79 port.on("filters.collapse", (message, sender) => |
| 80 { | 80 { |
| 81 if (checkWhitelisted(sender.page, sender.frame)) | 81 if (checkWhitelisted(sender.page, sender.frame)) |
| 82 return false; | 82 return false; |
| 83 | 83 |
| 84 let typeMask = RegExpFilter.typeMap[message.mediatype]; | 84 let typeMask = RegExpFilter.typeMap[message.mediatype]; |
| 85 let documentHost = extractHostFromFrame(sender.frame); | 85 let documentHost = extractHostFromFrame(sender.frame); |
| 86 let sitekey = getKey(sender.page, sender.frame); | 86 let sitekey = getKey(sender.page, sender.frame); |
|
kzar
2016/03/23 15:36:00
Nit: the name `sitekey` seems inconsistent with th
Sebastian Noack
2016/03/23 16:44:48
Well, it was inconsistent before. But fine with me
| |
| 87 let blocked = false; | 87 let blocked = false; |
| 88 | 88 |
| 89 let specificOnly = checkWhitelisted( | 89 let specificOnly = checkWhitelisted( |
| 90 sender.page, sender.frame, | 90 sender.page, sender.frame, |
| 91 RegExpFilter.typeMap.GENERICBLOCK | 91 RegExpFilter.typeMap.GENERICBLOCK |
| 92 ); | 92 ); |
| 93 | 93 |
| 94 for (let url of message.urls) | 94 for (let url of message.urls) |
| 95 { | 95 { |
| 96 let urlObj = new URL(url, message.baseURL); | 96 let urlObj = new URL(url, message.baseURL); |
| 97 let filter = defaultMatcher.matchesAny( | 97 let filter = defaultMatcher.matchesAny( |
| 98 stringifyURL(urlObj), | 98 stringifyURL(urlObj), |
| 99 typeMask, documentHost, | 99 typeMask, documentHost, |
| 100 isThirdParty(urlObj, documentHost), | 100 isThirdParty(urlObj, documentHost), |
| 101 sitekey, specificOnly | 101 sitekey, specificOnly |
| 102 ); | 102 ); |
| 103 | 103 |
| 104 if (!(filter instanceof BlockingFilter)) | 104 if (filter instanceof BlockingFilter) |
|
kzar
2016/03/23 15:35:59
I think it would be clearer to check if the filter
Sebastian Noack
2016/03/23 16:44:47
I'm not sure whether I agree, that this is any eas
| |
| 105 continue; | 105 { |
| 106 if (filter.collapse != null) | 106 if (filter.collapse != null) |
| 107 return filter.collapse; | 107 return filter.collapse; |
| 108 | 108 blocked = true; |
| 109 blocked = true; | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 return blocked && Prefs.hidePlaceholders; | 112 return blocked && Prefs.hidePlaceholders; |
| 113 }); | 113 }); |
| 114 | 114 |
| 115 let ignoreFilterNotifications = false; | 115 let ignoreFilterNotifications = false; |
| 116 FilterNotifier.addListener((action, arg) => | 116 FilterNotifier.addListener((action, arg) => |
|
Sebastian Noack
2016/03/23 14:02:06
I hope you don't mind that I revisited the logic t
kzar
2016/03/23 15:35:59
Acknowledged.
| |
| 117 { | 117 { |
| 118 // Handler behavior is already going to be changed. We do so asynchronously, t o | 118 // Avoid triggering filters.behaviorChanged multiple times |
|
kzar
2016/03/23 15:35:59
Nit: Mind wrapping this long line?
kzar
2016/03/23 15:35:59
I don't really understand this comment. Maybe some
Sebastian Noack
2016/03/23 16:44:47
Done.
| |
| 119 // not trigger multiple times if multiple filter changes occur simultaneously. | 119 // when multiple filter hanges happen at the same time. |
| 120 if (ignoreFilterNotifications) | 120 if (ignoreFilterNotifications) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 if (action != "load") | 123 if (action != "load") |
| 124 { | 124 { |
| 125 let parts = action.split("."); | 125 let parts = action.split("."); |
| 126 let [category, event] = parts; | 126 let [category, event] = parts; |
| 127 if (category == "subscription") | 127 if (category == "subscription") |
| 128 { | 128 { |
| 129 if (event != "added" && | 129 if (event != "added" && |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 159 } | 159 } |
| 160 | 160 |
| 161 ignoreFilterNotifications = true; | 161 ignoreFilterNotifications = true; |
| 162 setTimeout(() => | 162 setTimeout(() => |
| 163 { | 163 { |
| 164 ignoreFilterNotifications = false; | 164 ignoreFilterNotifications = false; |
| 165 ext.webRequest.handlerBehaviorChanged(); | 165 ext.webRequest.handlerBehaviorChanged(); |
| 166 FilterNotifier.triggerListeners("filter.behaviorChanged"); | 166 FilterNotifier.triggerListeners("filter.behaviorChanged"); |
| 167 }); | 167 }); |
| 168 }); | 168 }); |
| LEFT | RIGHT |