| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 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/>. | |
| 16 */ | |
| 17 | |
| 18 this.ext = function(ext) | |
| 19 { | |
| 20 function getURLParameters(data) | |
|
Thomas Greiner
2014/12/18 10:17:48
This name is not reflecting what the function is d
Wladimir Palant
2014/12/18 19:31:35
I went with updateFromURL() which isn't quite as v
Thomas Greiner
2014/12/19 10:53:38
Thanks, that's great.
| |
| 21 { | |
| 22 if (window.location.search) | |
| 23 { | |
| 24 var params = window.location.search.substr(1).split("&"); | |
| 25 for (var i = 0; i < params.length; i++) | |
| 26 { | |
| 27 var parts = params[i].split("=", 2); | |
| 28 if (parts.length == 2 && parts[0] in data) | |
| 29 data[parts[0]] = decodeURIComponent(parts[1]); | |
| 30 } | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 var subscriptions =[ | |
| 35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", | |
| 36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", | |
| 37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | |
| 38 ]; | |
| 39 | |
| 40 var listenerFilter = null; | |
| 41 | |
| 42 ext.backgroundPage = { | |
| 43 sendMessage: function(message, responseCallback) | |
| 44 { | |
| 45 var respond = function(response) | |
| 46 { | |
| 47 setTimeout(responseCallback.bind(responseCallback, response), 0); | |
| 48 }; | |
| 49 | |
| 50 var dispatchListenerNotification = function(action) | |
|
Thomas Greiner
2014/12/18 10:17:48
Nit: Since this is only used for subscription noti
Wladimir Palant
2014/12/18 19:31:35
I'm ignoring this nit because that callback is bei
| |
| 51 { | |
| 52 var match = /^subscription\.(.*)/.exec(action); | |
|
Thomas Greiner
2014/12/18 10:17:48
In addition to my comment above, by directly passi
Wladimir Palant
2014/12/18 19:31:35
Same here, this is no longer relevant because the
| |
| 53 if (match && listenerFilter && listenerFilter.indexOf(match[1]) >= 0) | |
| 54 { | |
| 55 ext.onMessage._dispatch({ | |
| 56 type: "subscriptions.listen", | |
| 57 action: match[1], | |
| 58 args: Array.prototype.slice.call(arguments, 1) | |
| 59 }); | |
| 60 } | |
| 61 }; | |
| 62 | |
| 63 switch (message.type) | |
|
Thomas Greiner
2014/12/18 10:17:48
Introducing new method names should not be the nor
Wladimir Palant
2014/12/18 19:31:35
I've mostly changed it like this. However, I'm not
Thomas Greiner
2014/12/19 10:53:38
Looks good. Not sure about whether an array for "a
Wladimir Palant
2014/12/19 13:32:37
The problem isn't checking what was requested - th
| |
| 64 { | |
| 65 case "app.doclink": | |
| 66 respond("https://adblockplus.org/redirect?link=" + encodeURIComponent( message.args[0])); | |
|
Thomas Greiner
2014/12/18 10:17:48
Nit: This line doesn't need to be that long.
Codi
Wladimir Palant
2014/12/18 19:31:35
This code is being rewritten by the next patch, no
| |
| 67 break; | |
| 68 case "app.info": | |
| 69 var response = {platform: "gecko", platformVersion: "34.0", applicatio n: "firefox", applicationVersion: "34.0"}; | |
|
Thomas Greiner
2014/12/18 10:17:48
Nit: This line doesn't need to be that long.
Wladimir Palant
2014/12/18 19:31:35
This code is being rewritten by the next patch, no
| |
| 70 getURLParameters(response); | |
| 71 respond(response); | |
| 72 break; | |
| 73 case "app.issues": | |
| 74 var response = {seenDataCorruption: false, filterlistsReinitialized: f alse}; | |
|
Thomas Greiner
2014/12/18 10:17:48
Nit: This line doesn't need to be that long.
Wladimir Palant
2014/12/18 19:31:35
This code is being rewritten by the next patch, no
| |
| 75 getURLParameters(response); | |
| 76 respond(response); | |
| 77 break; | |
| 78 case "app.options": | |
| 79 window.open("http://example.com/options.html", "_blank"); | |
| 80 break; | |
| 81 case "subscriptions.get": | |
| 82 respond(subscriptions); | |
| 83 break; | |
| 84 case "filters.blocked": | |
| 85 var params = {blockedURLs: ""}; | |
| 86 getURLParameters(params); | |
| 87 var blocked = params.blockedURLs.split(","); | |
| 88 respond(blocked.indexOf(message.url) >= 0); | |
| 89 break; | |
| 90 case "subscriptions.toggle": | |
| 91 var index = subscriptions.indexOf(message.url); | |
| 92 if (index >= 0) | |
| 93 { | |
| 94 subscriptions.splice(index, 1); | |
| 95 dispatchListenerNotification("subscription.removed", message.url); | |
| 96 } | |
| 97 else | |
| 98 { | |
| 99 subscriptions.push(message.url); | |
| 100 dispatchListenerNotification("subscription.added", message.url); | |
| 101 } | |
| 102 break; | |
| 103 case "subscriptions.listen": | |
| 104 listenerFilter = message.filter; | |
| 105 break; | |
| 106 } | |
| 107 } | |
| 108 }; | |
| 109 | |
| 110 var EventTarget = function(cancelable) | |
| 111 { | |
| 112 this._listeners = []; | |
| 113 this._cancelable = cancelable; | |
| 114 }; | |
| 115 EventTarget.prototype = { | |
| 116 addListener: function(listener) | |
| 117 { | |
| 118 if (this._listeners.indexOf(listener) == -1) | |
| 119 this._listeners.push(listener); | |
| 120 }, | |
| 121 removeListener: function(listener) | |
| 122 { | |
| 123 var idx = this._listeners.indexOf(listener); | |
| 124 if (idx != -1) | |
| 125 this._listeners.splice(idx, 1); | |
| 126 }, | |
| 127 _dispatch: function() | |
| 128 { | |
| 129 var result = null; | |
| 130 | |
| 131 for (var i = 0; i < this._listeners.length; i++) | |
| 132 { | |
| 133 result = this._listeners[i].apply(null, arguments); | |
| 134 | |
| 135 if (this._cancelable && result === false) | |
| 136 break; | |
| 137 } | |
| 138 | |
| 139 return result; | |
| 140 } | |
| 141 }; | |
| 142 ext.onMessage = new EventTarget(); | |
| 143 | |
| 144 return ext; | |
| 145 }(this.ext || {}); | |
| OLD | NEW |