| 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 | 
| 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 /* globals require */ | 
|  | 19 | 
| 18 "use strict"; | 20 "use strict"; | 
| 19 | 21 | 
|  | 22 (function(global) | 
| 20 { | 23 { | 
| 21   if (typeof ext == "undefined") | 24   let ext = global.ext || require("ext_background"); | 
| 22     window.ext = require("ext_background"); |  | 
| 23 | 25 | 
| 24   const {port} = require("messaging"); | 26   const {port} = require("messaging"); | 
| 25   const {Prefs} = require("prefs"); | 27   const {Prefs} = require("prefs"); | 
| 26   const {Utils} = require("utils"); | 28   const {Utils} = require("utils"); | 
| 27   const {FilterStorage} = require("filterStorage"); | 29   const {FilterStorage} = require("filterStorage"); | 
| 28   const {FilterNotifier} = require("filterNotifier"); | 30   const {FilterNotifier} = require("filterNotifier"); | 
| 29   const {defaultMatcher} = require("matcher"); | 31   const {defaultMatcher} = require("matcher"); | 
| 30   const {ElemHideEmulation} = require("elemHideEmulation"); | 32   const {ElemHideEmulation} = require("elemHideEmulation"); | 
| 31   const {Notification: NotificationStorage} = require("notification"); | 33   const {Notification: NotificationStorage} = require("notification"); | 
| 32 | 34 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 71                              "lastDownload", "title", "url"], subscription); | 73                              "lastDownload", "title", "url"], subscription); | 
| 72     obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 74     obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 
| 73     return obj; | 75     return obj; | 
| 74   } | 76   } | 
| 75 | 77 | 
| 76   let convertFilter = convertObject.bind(null, ["text"]); | 78   let convertFilter = convertObject.bind(null, ["text"]); | 
| 77 | 79 | 
| 78   let changeListeners = new ext.PageMap(); | 80   let changeListeners = new ext.PageMap(); | 
| 79   let listenedPreferences = Object.create(null); | 81   let listenedPreferences = Object.create(null); | 
| 80   let listenedFilterChanges = Object.create(null); | 82   let listenedFilterChanges = Object.create(null); | 
| 81   let messageTypes = { | 83   let messageTypes = new Map([ | 
| 82     app: "app.respond", | 84     ["app", "app.respond"], | 
| 83     filter: "filters.respond", | 85     ["filter", "filters.respond"], | 
| 84     pref: "prefs.respond", | 86     ["pref", "prefs.respond"], | 
| 85     subscription: "subscriptions.respond" | 87     ["subscription", "subscriptions.respond"] | 
| 86   }; | 88   ]); | 
| 87 | 89 | 
| 88   function sendMessage(type, action, ...args) | 90   function sendMessage(type, action, ...args) | 
| 89   { | 91   { | 
| 90     let pages = changeListeners.keys(); | 92     let pages = changeListeners.keys(); | 
| 91     if (pages.length == 0) | 93     if (pages.length == 0) | 
| 92       return; | 94       return; | 
| 93 | 95 | 
| 94     for (let i = 0; i < args.length; i++) | 96     let convertedArgs = []; | 
| 95     { | 97     for (let arg of args) | 
| 96       let arg = args[i]; | 98     { | 
| 97       if (arg instanceof Subscription) | 99       if (arg instanceof Subscription) | 
| 98         args[i] = convertSubscription(arg); | 100         convertedArgs.push(convertSubscription(arg)); | 
| 99       else if (arg instanceof Filter) | 101       else if (arg instanceof Filter) | 
| 100         args[i] = convertFilter(arg); | 102         convertedArgs.push(convertFilter(arg)); | 
|  | 103       else | 
|  | 104         convertedArgs.push(arg); | 
| 101     } | 105     } | 
| 102 | 106 | 
| 103     for (let page of pages) | 107     for (let page of pages) | 
| 104     { | 108     { | 
| 105       let filters = changeListeners.get(page); | 109       let filters = changeListeners.get(page); | 
| 106       let actions = filters[type]; | 110       let actions = filters[type]; | 
| 107       if (actions && actions.indexOf(action) != -1) | 111       if (actions && actions.indexOf(action) != -1) | 
| 108       { | 112       { | 
| 109         page.sendMessage({ | 113         page.sendMessage({ | 
| 110           type: messageTypes[type], | 114           type: messageTypes.get(type), | 
| 111           action, | 115           action, | 
| 112           args | 116           args: convertedArgs | 
| 113         }); | 117         }); | 
| 114       } | 118       } | 
| 115     } | 119     } | 
| 116   } | 120   } | 
| 117 | 121 | 
| 118   function addFilterListeners(type, actions) | 122   function addFilterListeners(type, actions) | 
| 119   { | 123   { | 
| 120     for (let action of actions) | 124     for (let action of actions) | 
| 121     { | 125     { | 
| 122       let name; | 126       let name; | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 145       changeListeners.set(page, listenerFilters); | 149       changeListeners.set(page, listenerFilters); | 
| 146     } | 150     } | 
| 147     return listenerFilters; | 151     return listenerFilters; | 
| 148   } | 152   } | 
| 149 | 153 | 
| 150   port.on("app.get", (message, sender) => | 154   port.on("app.get", (message, sender) => | 
| 151   { | 155   { | 
| 152     if (message.what == "issues") | 156     if (message.what == "issues") | 
| 153     { | 157     { | 
| 154       let subscriptionInit = tryRequire("subscriptionInit"); | 158       let subscriptionInit = tryRequire("subscriptionInit"); | 
| 155       return { | 159       let result = subscriptionInit ? subscriptionInit.reinitialized : false; | 
| 156         filterlistsReinitialized: subscriptionInit | 160       return {filterlistsReinitialized: result}; | 
| 157           ? subscriptionInit.reinitialized : false |  | 
| 158       }; |  | 
| 159     } | 161     } | 
| 160 | 162 | 
| 161     if (message.what == "doclink") | 163     if (message.what == "doclink") | 
| 162       return Utils.getDocLink(message.link); | 164       return Utils.getDocLink(message.link); | 
| 163 | 165 | 
| 164     if (message.what == "localeInfo") | 166     if (message.what == "localeInfo") | 
| 165     { | 167     { | 
| 166       let bidiDir; | 168       let bidiDir; | 
| 167       if ("chromeRegistry" in Utils) | 169       if ("chromeRegistry" in Utils) | 
| 168       { | 170       { | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 223     { | 225     { | 
| 224       let filters = []; | 226       let filters = []; | 
| 225       const {checkWhitelisted} = require("whitelisting"); | 227       const {checkWhitelisted} = require("whitelisting"); | 
| 226 | 228 | 
| 227       if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 229       if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 
| 228                             RegExpFilter.typeMap.DOCUMENT | | 230                             RegExpFilter.typeMap.DOCUMENT | | 
| 229                             RegExpFilter.typeMap.ELEMHIDE)) | 231                             RegExpFilter.typeMap.ELEMHIDE)) | 
| 230       { | 232       { | 
| 231         let {hostname} = sender.frame.url; | 233         let {hostname} = sender.frame.url; | 
| 232         filters = ElemHideEmulation.getRulesForDomain(hostname); | 234         filters = ElemHideEmulation.getRulesForDomain(hostname); | 
| 233         filters = filters.map(filter => | 235         filters = filters.map((filter) => | 
| 234         { | 236         { | 
| 235           return { | 237           return { | 
| 236             selector: filter.selector, | 238             selector: filter.selector, | 
| 237             text: filter.text | 239             text: filter.text | 
| 238           }; | 240           }; | 
| 239         }); | 241         }); | 
| 240       } | 242       } | 
| 241       return filters; | 243       return filters; | 
| 242     } | 244     } | 
| 243 | 245 | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 359       FilterStorage.addSubscription(subscription); | 361       FilterStorage.addSubscription(subscription); | 
| 360 | 362 | 
| 361       if (subscription instanceof DownloadableSubscription && | 363       if (subscription instanceof DownloadableSubscription && | 
| 362           !subscription.lastDownload) | 364           !subscription.lastDownload) | 
| 363         Synchronizer.execute(subscription); | 365         Synchronizer.execute(subscription); | 
| 364     } | 366     } | 
| 365   }); | 367   }); | 
| 366 | 368 | 
| 367   port.on("subscriptions.get", (message, sender) => | 369   port.on("subscriptions.get", (message, sender) => | 
| 368   { | 370   { | 
| 369     let subscriptions = FilterStorage.subscriptions.filter(s => | 371     let subscriptions = FilterStorage.subscriptions.filter((s) => | 
| 370     { | 372     { | 
| 371       if (message.ignoreDisabled && s.disabled) | 373       if (message.ignoreDisabled && s.disabled) | 
| 372         return false; | 374         return false; | 
| 373       if (s instanceof DownloadableSubscription && message.downloadable) | 375       if (s instanceof DownloadableSubscription && message.downloadable) | 
| 374         return true; | 376         return true; | 
| 375       if (s instanceof SpecialSubscription && message.special) | 377       if (s instanceof SpecialSubscription && message.special) | 
| 376         return true; | 378         return true; | 
| 377       return false; | 379       return false; | 
| 378     }); | 380     }); | 
| 379 | 381 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 409       subscription.title = message.title; | 411       subscription.title = message.title; | 
| 410       subscription.homepage = message.homepage; | 412       subscription.homepage = message.homepage; | 
| 411       FilterStorage.addSubscription(subscription); | 413       FilterStorage.addSubscription(subscription); | 
| 412       if (!subscription.lastDownload) | 414       if (!subscription.lastDownload) | 
| 413         Synchronizer.execute(subscription); | 415         Synchronizer.execute(subscription); | 
| 414     } | 416     } | 
| 415   }); | 417   }); | 
| 416 | 418 | 
| 417   port.on("subscriptions.update", (message, sender) => | 419   port.on("subscriptions.update", (message, sender) => | 
| 418   { | 420   { | 
| 419     let subscriptions = message.url ? [Subscription.fromURL(message.url)] | 421     let {subscriptions} = FilterStorage; | 
| 420                         : FilterStorage.subscriptions; | 422     if (message.url) | 
|  | 423       subscriptions = [Subscription.fromURL(message.url)]; | 
|  | 424 | 
| 421     for (let subscription of subscriptions) | 425     for (let subscription of subscriptions) | 
| 422     { | 426     { | 
| 423       if (subscription instanceof DownloadableSubscription) | 427       if (subscription instanceof DownloadableSubscription) | 
| 424         Synchronizer.execute(subscription, true); | 428         Synchronizer.execute(subscription, true); | 
| 425     } | 429     } | 
| 426   }); | 430   }); | 
| 427 } | 431 })(this); | 
| LEFT | RIGHT | 
|---|