Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 this.ext = function(ext) | 18 (function(global) |
19 { | 19 { |
20 function getURLParameters(data) | 20 if (!global.ext) |
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 global.ext = {}; | |
22 | |
23 function updateFromURL(data) | |
21 { | 24 { |
22 if (window.location.search) | 25 if (window.location.search) |
23 { | 26 { |
24 var params = window.location.search.substr(1).split("&"); | 27 var params = window.location.search.substr(1).split("&"); |
25 for (var i = 0; i < params.length; i++) | 28 for (var i = 0; i < params.length; i++) |
26 { | 29 { |
27 var parts = params[i].split("=", 2); | 30 var parts = params[i].split("=", 2); |
28 if (parts.length == 2 && parts[0] in data) | 31 if (parts.length == 2 && parts[0] in data) |
29 data[parts[0]] = decodeURIComponent(parts[1]); | 32 data[parts[0]] = decodeURIComponent(parts[1]); |
30 } | 33 } |
31 } | 34 } |
32 } | 35 } |
33 | 36 |
34 var subscriptions =[ | 37 var subscriptions =[ |
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", | 38 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", |
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", | 39 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", |
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 40 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
38 ]; | 41 ]; |
39 | 42 |
40 var listenerFilter = null; | 43 var listenerFilter = null; |
41 | 44 |
42 ext.backgroundPage = { | 45 global.ext.backgroundPage = { |
43 sendMessage: function(message, responseCallback) | 46 sendMessage: function(message, responseCallback) |
44 { | 47 { |
45 var respond = function(response) | 48 var respond = function(response) |
46 { | 49 { |
47 setTimeout(responseCallback.bind(responseCallback, response), 0); | 50 setTimeout(responseCallback.bind(responseCallback, response), 0); |
48 }; | 51 }; |
49 | 52 |
50 var dispatchListenerNotification = function(action) | 53 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 { | 54 { |
52 var match = /^subscription\.(.*)/.exec(action); | 55 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) | 56 if (match && listenerFilter && listenerFilter.indexOf(match[1]) >= 0) |
54 { | 57 { |
55 ext.onMessage._dispatch({ | 58 global.ext.onMessage._dispatch({ |
56 type: "subscriptions.listen", | 59 type: "subscriptions.listen", |
57 action: match[1], | 60 action: match[1], |
58 args: Array.prototype.slice.call(arguments, 1) | 61 args: Array.prototype.slice.call(arguments, 1) |
59 }); | 62 }); |
60 } | 63 } |
61 }; | 64 }; |
62 | 65 |
63 switch (message.type) | 66 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 { | 67 { |
65 case "app.doclink": | 68 case "app.get": |
66 respond("https://adblockplus.org/redirect?link=" + encodeURIComponent( message.args[0])); | 69 if (message.what == "issues") |
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
| |
70 { | |
71 var response = {seenDataCorruption: false, filterlistsReinitialized: false}; | |
72 updateFromURL(response); | |
73 | |
74 var info = {platform: "gecko", platformVersion: "34.0", application: "firefox", applicationVersion: "34.0"}; | |
75 updateFromURL(info); | |
76 response.legacySafariVersion = (info.platform == "safari" && ( | |
77 parseInt(info.platformVersion, 10) < 6 || // beforeload breaks we bsites in Safari 5 | |
78 info.platformVersion == "6.1" || // extensions are broke n in 6.1 and 7.0 | |
79 info.platformVersion == "7.0")); | |
80 | |
81 respond(response); | |
82 } | |
83 else if (message.what == "doclink") | |
84 respond("https://adblockplus.org/redirect?link=" + encodeURIComponen t(message.link)); | |
85 else | |
86 respond(null); | |
67 break; | 87 break; |
68 case "app.info": | 88 case "app.open": |
69 var response = {platform: "gecko", platformVersion: "34.0", applicatio n: "firefox", applicationVersion: "34.0"}; | 89 if (message.what == "options") |
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); | 90 window.open("http://example.com/options.html", "_blank"); |
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; | 91 break; |
81 case "subscriptions.get": | 92 case "subscriptions.get": |
82 respond(subscriptions); | 93 respond(subscriptions); |
83 break; | 94 break; |
84 case "filters.blocked": | 95 case "filters.blocked": |
85 var params = {blockedURLs: ""}; | 96 var params = {blockedURLs: ""}; |
86 getURLParameters(params); | 97 updateFromURL(params); |
87 var blocked = params.blockedURLs.split(","); | 98 var blocked = params.blockedURLs.split(","); |
88 respond(blocked.indexOf(message.url) >= 0); | 99 respond(blocked.indexOf(message.url) >= 0); |
89 break; | 100 break; |
90 case "subscriptions.toggle": | 101 case "subscriptions.toggle": |
91 var index = subscriptions.indexOf(message.url); | 102 var index = subscriptions.indexOf(message.url); |
92 if (index >= 0) | 103 if (index >= 0) |
93 { | 104 { |
94 subscriptions.splice(index, 1); | 105 subscriptions.splice(index, 1); |
95 dispatchListenerNotification("subscription.removed", message.url); | 106 dispatchListenerNotification("subscription.removed", message.url); |
96 } | 107 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 { | 143 { |
133 result = this._listeners[i].apply(null, arguments); | 144 result = this._listeners[i].apply(null, arguments); |
134 | 145 |
135 if (this._cancelable && result === false) | 146 if (this._cancelable && result === false) |
136 break; | 147 break; |
137 } | 148 } |
138 | 149 |
139 return result; | 150 return result; |
140 } | 151 } |
141 }; | 152 }; |
142 ext.onMessage = new EventTarget(); | 153 global.ext.onMessage = new EventTarget(); |
143 | 154 })(this); |
144 return ext; | |
145 }(this.ext || {}); | |
LEFT | RIGHT |