| 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 "use strict"; | 18 "use strict"; | 
| 19 | 19 | 
| 20 { | 20 { | 
| 21   var ext = ext || require("ext_background"); | 21   if (typeof ext == "undefined") | 
|  | 22     window.ext = require("ext_background"); | 
| 22 | 23 | 
| 23   const {port} = require("messaging"); | 24   const {port} = require("messaging"); | 
| 24   const {Prefs} = require("prefs"); | 25   const {Prefs} = require("prefs"); | 
| 25   const {Utils} = require("utils"); | 26   const {Utils} = require("utils"); | 
| 26   const {FilterStorage} = require("filterStorage"); | 27   const {FilterStorage} = require("filterStorage"); | 
| 27   const {FilterNotifier} = require("filterNotifier"); | 28   const {FilterNotifier} = require("filterNotifier"); | 
| 28   const {defaultMatcher} = require("matcher"); | 29   const {defaultMatcher} = require("matcher"); | 
| 29   const {ElemHideEmulation} = require("elemHideEmulation"); | 30   const {ElemHideEmulation} = require("elemHideEmulation"); | 
| 30   const {Notification: NotificationStorage} = require("notification"); | 31   const {Notification: NotificationStorage} = require("notification"); | 
| 31 | 32 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 71     obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 72     obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 
| 72     return obj; | 73     return obj; | 
| 73   } | 74   } | 
| 74 | 75 | 
| 75   let convertFilter = convertObject.bind(null, ["text"]); | 76   let convertFilter = convertObject.bind(null, ["text"]); | 
| 76 | 77 | 
| 77   let changeListeners = new ext.PageMap(); | 78   let changeListeners = new ext.PageMap(); | 
| 78   let listenedPreferences = Object.create(null); | 79   let listenedPreferences = Object.create(null); | 
| 79   let listenedFilterChanges = Object.create(null); | 80   let listenedFilterChanges = Object.create(null); | 
| 80   let messageTypes = { | 81   let messageTypes = { | 
| 81     "app": "app.respond", | 82     app: "app.respond", | 
| 82     "filter": "filters.respond", | 83     filter: "filters.respond", | 
| 83     "pref": "prefs.respond", | 84     pref: "prefs.respond", | 
| 84     "subscription": "subscriptions.respond" | 85     subscription: "subscriptions.respond" | 
| 85   }; | 86   }; | 
| 86 | 87 | 
| 87   function sendMessage(type, action) | 88   function sendMessage(type, action, ...args) | 
| 88   { | 89   { | 
| 89     let pages = changeListeners.keys(); | 90     let pages = changeListeners.keys(); | 
| 90     if (pages.length == 0) | 91     if (pages.length == 0) | 
| 91       return; | 92       return; | 
| 92 | 93 | 
| 93     let args = []; | 94     for (let i = 0; i < args.length; i++) | 
| 94     for (let i = 2; i < arguments.length; i++) |  | 
| 95     { | 95     { | 
| 96       let arg = arguments[i]; | 96       let arg = args[i]; | 
| 97       if (arg instanceof Subscription) | 97       if (arg instanceof Subscription) | 
| 98         args.push(convertSubscription(arg)); | 98         args[i] = convertSubscription(arg); | 
| 99       else if (arg instanceof Filter) | 99       else if (arg instanceof Filter) | 
| 100         args.push(convertFilter(arg)); | 100         args[i] = convertFilter(arg); | 
| 101       else |  | 
| 102         args.push(arg); |  | 
| 103     } | 101     } | 
| 104 | 102 | 
| 105     for (let page of pages) | 103     for (let page of pages) | 
| 106     { | 104     { | 
| 107       let filters = changeListeners.get(page); | 105       let filters = changeListeners.get(page); | 
| 108       let actions = filters[type]; | 106       let actions = filters[type]; | 
| 109       if (actions && actions.indexOf(action) != -1) | 107       if (actions && actions.indexOf(action) != -1) | 
| 110       { | 108       { | 
| 111         page.sendMessage({ | 109         page.sendMessage({ | 
| 112           type: messageTypes[type], | 110           type: messageTypes[type], | 
| 113           action: action, | 111           action, | 
| 114           args: args | 112           args | 
| 115         }); | 113         }); | 
| 116       } | 114       } | 
| 117     } | 115     } | 
| 118   } | 116   } | 
| 119 | 117 | 
| 120   function addFilterListeners(type, actions) | 118   function addFilterListeners(type, actions) | 
| 121   { | 119   { | 
| 122     for (let action of actions) | 120     for (let action of actions) | 
| 123     { | 121     { | 
| 124       let name; | 122       let name; | 
| 125       if (type == "filter" && action == "loaded") | 123       if (type == "filter" && action == "loaded") | 
| 126         name = "load"; | 124         name = "load"; | 
| 127       else | 125       else | 
| 128         name = type + "." + action; | 126         name = type + "." + action; | 
| 129 | 127 | 
| 130       if (!(name in listenedFilterChanges)) | 128       if (!(name in listenedFilterChanges)) | 
| 131       { | 129       { | 
| 132         listenedFilterChanges[name] = null; | 130         listenedFilterChanges[name] = null; | 
| 133         FilterNotifier.on(name, function() | 131         FilterNotifier.on(name, (...args) => | 
| 134         { | 132         { | 
| 135           let args = [type, action]; | 133           sendMessage(type, action, ...args); | 
| 136           for (let arg of arguments) |  | 
| 137             args.push(arg); |  | 
| 138           sendMessage.apply(null, args); |  | 
| 139         }); | 134         }); | 
| 140       } | 135       } | 
| 141     } | 136     } | 
| 142   } | 137   } | 
| 143 | 138 | 
| 144   function getListenerFilters(page) | 139   function getListenerFilters(page) | 
| 145   { | 140   { | 
| 146     let listenerFilters = changeListeners.get(page); | 141     let listenerFilters = changeListeners.get(page); | 
| 147     if (!listenerFilters) | 142     if (!listenerFilters) | 
| 148     { | 143     { | 
| 149       listenerFilters = Object.create(null); | 144       listenerFilters = Object.create(null); | 
| 150       changeListeners.set(page, listenerFilters); | 145       changeListeners.set(page, listenerFilters); | 
| 151     } | 146     } | 
| 152     return listenerFilters; | 147     return listenerFilters; | 
| 153   } | 148   } | 
| 154 | 149 | 
| 155   port.on("app.get", (message, sender) => | 150   port.on("app.get", (message, sender) => | 
| 156   { | 151   { | 
| 157     if (message.what == "issues") | 152     if (message.what == "issues") | 
| 158     { | 153     { | 
| 159       let subscriptionInit = tryRequire("subscriptionInit"); | 154       let subscriptionInit = tryRequire("subscriptionInit"); | 
| 160       return { | 155       return { | 
| 161         filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali
     zed : false | 156         filterlistsReinitialized: subscriptionInit | 
|  | 157           ? subscriptionInit.reinitialized : false | 
| 162       }; | 158       }; | 
| 163     } | 159     } | 
| 164 | 160 | 
| 165     if (message.what == "doclink") | 161     if (message.what == "doclink") | 
| 166       return Utils.getDocLink(message.link); | 162       return Utils.getDocLink(message.link); | 
| 167 | 163 | 
| 168     if (message.what == "localeInfo") | 164     if (message.what == "localeInfo") | 
| 169     { | 165     { | 
| 170       let bidiDir; | 166       let bidiDir; | 
| 171       if ("chromeRegistry" in Utils) | 167       if ("chromeRegistry" in Utils) | 
| 172         bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr
     "; | 168       { | 
|  | 169         let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus"); | 
|  | 170         bidiDir = isRtl ? "rtl" : "ltr"; | 
|  | 171       } | 
| 173       else | 172       else | 
| 174         bidiDir = ext.i18n.getMessage("@@bidi_dir"); | 173         bidiDir = ext.i18n.getMessage("@@bidi_dir"); | 
| 175 | 174 | 
| 176       return {locale: Utils.appLocale, bidiDir: bidiDir}; | 175       return {locale: Utils.appLocale, bidiDir}; | 
| 177     } | 176     } | 
| 178 | 177 | 
| 179     if (message.what == "features") | 178     if (message.what == "features") | 
| 180     { | 179     { | 
| 181       return { | 180       return { | 
| 182         devToolsPanel: info.platform == "chromium" | 181         devToolsPanel: info.platform == "chromium" | 
| 183       }; | 182       }; | 
| 184     } | 183     } | 
| 185 | 184 | 
| 186     return info[message.what]; | 185     return info[message.what]; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 222   { | 221   { | 
| 223     if (message.what == "elemhideemulation") | 222     if (message.what == "elemhideemulation") | 
| 224     { | 223     { | 
| 225       let filters = []; | 224       let filters = []; | 
| 226       const {checkWhitelisted} = require("whitelisting"); | 225       const {checkWhitelisted} = require("whitelisting"); | 
| 227 | 226 | 
| 228       if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 227       if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 
| 229                             RegExpFilter.typeMap.DOCUMENT | | 228                             RegExpFilter.typeMap.DOCUMENT | | 
| 230                             RegExpFilter.typeMap.ELEMHIDE)) | 229                             RegExpFilter.typeMap.ELEMHIDE)) | 
| 231       { | 230       { | 
| 232         let hostname = sender.frame.url.hostname; | 231         let {hostname} = sender.frame.url; | 
| 233         filters = ElemHideEmulation.getRulesForDomain(hostname); | 232         filters = ElemHideEmulation.getRulesForDomain(hostname); | 
| 234         filters = filters.map(filter => | 233         filters = filters.map(filter => | 
| 235         { | 234         { | 
| 236           return { | 235           return { | 
| 237             selector: filter.selector, | 236             selector: filter.selector, | 
| 238             text: filter.text | 237             text: filter.text | 
| 239           }; | 238           }; | 
| 240         }); | 239         }); | 
| 241       } | 240       } | 
| 242       return filters; | 241       return filters; | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 273       return errors; | 272       return errors; | 
| 274 | 273 | 
| 275     for (let subscription of FilterStorage.subscriptions) | 274     for (let subscription of FilterStorage.subscriptions) | 
| 276     { | 275     { | 
| 277       if (!(subscription instanceof SpecialSubscription)) | 276       if (!(subscription instanceof SpecialSubscription)) | 
| 278         continue; | 277         continue; | 
| 279 | 278 | 
| 280       for (let j = subscription.filters.length - 1; j >= 0; j--) | 279       for (let j = subscription.filters.length - 1; j >= 0; j--) | 
| 281       { | 280       { | 
| 282         let filter = subscription.filters[j]; | 281         let filter = subscription.filters[j]; | 
| 283         if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | 282         if (/^@@\|\|([^/:]+)\^\$document$/.test(filter.text)) | 
| 284           continue; | 283           continue; | 
| 285 | 284 | 
| 286         if (!(filter.text in seenFilter)) | 285         if (!(filter.text in seenFilter)) | 
| 287           FilterStorage.removeFilter(filter); | 286           FilterStorage.removeFilter(filter); | 
| 288       } | 287       } | 
| 289     } | 288     } | 
| 290 | 289 | 
| 291     return errors; | 290     return errors; | 
| 292   }); | 291   }); | 
| 293 | 292 | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 352       ext.showOptions(() => | 351       ext.showOptions(() => | 
| 353       { | 352       { | 
| 354         sendMessage("app", "addSubscription", subscription); | 353         sendMessage("app", "addSubscription", subscription); | 
| 355       }); | 354       }); | 
| 356     } | 355     } | 
| 357     else | 356     else | 
| 358     { | 357     { | 
| 359       subscription.disabled = false; | 358       subscription.disabled = false; | 
| 360       FilterStorage.addSubscription(subscription); | 359       FilterStorage.addSubscription(subscription); | 
| 361 | 360 | 
| 362       if (subscription instanceof DownloadableSubscription && !subscription.last
     Download) | 361       if (subscription instanceof DownloadableSubscription && | 
|  | 362           !subscription.lastDownload) | 
| 363         Synchronizer.execute(subscription); | 363         Synchronizer.execute(subscription); | 
| 364     } | 364     } | 
| 365   }); | 365   }); | 
| 366 | 366 | 
| 367   port.on("subscriptions.get", (message, sender) => | 367   port.on("subscriptions.get", (message, sender) => | 
| 368   { | 368   { | 
| 369     let subscriptions = FilterStorage.subscriptions.filter(s => | 369     let subscriptions = FilterStorage.subscriptions.filter(s => | 
| 370     { | 370     { | 
| 371       if (message.ignoreDisabled && s.disabled) | 371       if (message.ignoreDisabled && s.disabled) | 
| 372         return false; | 372         return false; | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 409       subscription.title = message.title; | 409       subscription.title = message.title; | 
| 410       subscription.homepage = message.homepage; | 410       subscription.homepage = message.homepage; | 
| 411       FilterStorage.addSubscription(subscription); | 411       FilterStorage.addSubscription(subscription); | 
| 412       if (!subscription.lastDownload) | 412       if (!subscription.lastDownload) | 
| 413         Synchronizer.execute(subscription); | 413         Synchronizer.execute(subscription); | 
| 414     } | 414     } | 
| 415   }); | 415   }); | 
| 416 | 416 | 
| 417   port.on("subscriptions.update", (message, sender) => | 417   port.on("subscriptions.update", (message, sender) => | 
| 418   { | 418   { | 
| 419     let subscriptions = message.url ? [Subscription.fromURL(message.url)] : | 419     let subscriptions = message.url ? [Subscription.fromURL(message.url)] | 
| 420                         FilterStorage.subscriptions; | 420                         : FilterStorage.subscriptions; | 
| 421     for (let subscription of subscriptions) | 421     for (let subscription of subscriptions) | 
| 422     { | 422     { | 
| 423       if (subscription instanceof DownloadableSubscription) | 423       if (subscription instanceof DownloadableSubscription) | 
| 424         Synchronizer.execute(subscription, true); | 424         Synchronizer.execute(subscription, true); | 
| 425     } | 425     } | 
| 426   }); | 426   }); | 
| 427 } | 427 } | 
| OLD | NEW | 
|---|