| Index: messageResponder.js |
| diff --git a/messageResponder.js b/messageResponder.js |
| index e8b911a4519f8a20e86cb53a04d9b330753b127f..aba044e0f87e6e66dac01a75b8c1247095e4d0c6 100644 |
| --- a/messageResponder.js |
| +++ b/messageResponder.js |
| @@ -18,7 +18,8 @@ |
| "use strict"; |
| { |
| - var ext = ext || require("ext_background"); |
| + if (typeof ext == "undefined") |
|
kzar
2017/02/08 08:39:24
(This change is required since we'll be using `let
|
| + window.ext = require("ext_background"); |
| const {port} = require("messaging"); |
| const {Prefs} = require("prefs"); |
| @@ -78,28 +79,25 @@ |
| let listenedPreferences = Object.create(null); |
| let listenedFilterChanges = Object.create(null); |
| let messageTypes = { |
| - "app": "app.respond", |
| - "filter": "filters.respond", |
| - "pref": "prefs.respond", |
| - "subscription": "subscriptions.respond" |
| + app: "app.respond", |
| + filter: "filters.respond", |
| + pref: "prefs.respond", |
| + subscription: "subscriptions.respond" |
| }; |
| - function sendMessage(type, action) |
| + function sendMessage(type, action, ...args) |
| { |
| let pages = changeListeners.keys(); |
| if (pages.length == 0) |
| return; |
| - let args = []; |
| - for (let i = 2; i < arguments.length; i++) |
| + for (let i = 0; i < args.length; i++) |
|
Thomas Greiner
2017/02/08 10:11:09
Why not use a for-of loop instead to simplify the
kzar
2017/02/08 10:27:24
Since we need to replace some arguments in place.
Thomas Greiner
2017/02/08 10:37:26
Ah, don't know how I overlooked that. :p You're of
|
| { |
| - let arg = arguments[i]; |
| + let arg = args[i]; |
| if (arg instanceof Subscription) |
| - args.push(convertSubscription(arg)); |
| + args[i] = convertSubscription(arg); |
| else if (arg instanceof Filter) |
| - args.push(convertFilter(arg)); |
| - else |
| - args.push(arg); |
| + args[i] = convertFilter(arg); |
| } |
| for (let page of pages) |
| @@ -110,14 +108,14 @@ |
| { |
| page.sendMessage({ |
| type: messageTypes[type], |
| - action: action, |
| - args: args |
| + action, |
| + args |
| }); |
| } |
| } |
| } |
| - function addFilterListeners(type, actions) |
| + function addFilterListeners(type, actions, ...args) |
| { |
| for (let action of actions) |
| { |
| @@ -130,12 +128,9 @@ |
| if (!(name in listenedFilterChanges)) |
| { |
| listenedFilterChanges[name] = null; |
| - FilterNotifier.on(name, function() |
| + FilterNotifier.on(name, () => |
| { |
| - let args = [type, action]; |
| - for (let arg of arguments) |
| - args.push(arg); |
| - sendMessage.apply(null, args); |
| + sendMessage(...[type, action].concat(args)); |
|
Thomas Greiner
2017/02/08 10:11:09
Looks like a more complicated way of writing `send
kzar
2017/02/08 10:27:24
Good point, Done.
|
| }); |
| } |
| } |
| @@ -158,7 +153,8 @@ |
| { |
| let subscriptionInit = tryRequire("subscriptionInit"); |
| return { |
| - filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false |
| + filterlistsReinitialized: subscriptionInit |
| + ? subscriptionInit.reinitialized : false |
| }; |
| } |
| @@ -169,11 +165,16 @@ |
| { |
| let bidiDir; |
| if ("chromeRegistry" in Utils) |
| - bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr"; |
| + { |
| + let rtl = Utils.chromeRegistry.isLocaleRTL("adblockplus"); |
|
Thomas Greiner
2017/02/08 10:11:09
Detail: It'd be great if the variable name would r
kzar
2017/02/08 10:27:24
Done.
|
| + bidiDir = rtl ? "rtl" : "ltr"; |
| + } |
| else |
| + { |
| bidiDir = ext.i18n.getMessage("@@bidi_dir"); |
| + } |
| - return {locale: Utils.appLocale, bidiDir: bidiDir}; |
| + return {locale: Utils.appLocale, bidiDir}; |
| } |
| if (message.what == "features") |
| @@ -229,7 +230,7 @@ |
| RegExpFilter.typeMap.DOCUMENT | |
| RegExpFilter.typeMap.ELEMHIDE)) |
| { |
| - let hostname = sender.frame.url.hostname; |
| + let {hostname} = sender.frame.url; |
| filters = ElemHideEmulation.getRulesForDomain(hostname); |
| filters = filters.map(filter => |
| { |
| @@ -280,7 +281,7 @@ |
| for (let j = subscription.filters.length - 1; j >= 0; j--) |
| { |
| let filter = subscription.filters[j]; |
| - if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
| + if (/^@@\|\|([^/:]+)\^\$document$/.test(filter.text)) |
| continue; |
| if (!(filter.text in seenFilter)) |
| @@ -359,7 +360,8 @@ |
| subscription.disabled = false; |
| FilterStorage.addSubscription(subscription); |
| - if (subscription instanceof DownloadableSubscription && !subscription.lastDownload) |
| + if (subscription instanceof DownloadableSubscription && |
| + !subscription.lastDownload) |
| Synchronizer.execute(subscription); |
| } |
| }); |
| @@ -416,8 +418,8 @@ |
| port.on("subscriptions.update", (message, sender) => |
| { |
| - let subscriptions = message.url ? [Subscription.fromURL(message.url)] : |
| - FilterStorage.subscriptions; |
| + let subscriptions = message.url ? [Subscription.fromURL(message.url)] |
| + : FilterStorage.subscriptions; |
| for (let subscription of subscriptions) |
| { |
| if (subscription instanceof DownloadableSubscription) |