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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 (function() | 20 (function() |
21 { | 21 { |
22 function E(id) | |
23 { | |
24 return document.getElementById(id); | |
25 } | |
26 | |
27 // Load subscriptions for features | 22 // Load subscriptions for features |
28 var featureSubscriptions = [ | 23 var featureSubscriptions = [ |
29 { | 24 { |
30 feature: "malware", | 25 feature: "malware", |
31 homepage: "http://malwaredomains.com/", | 26 homepage: "http://malwaredomains.com/", |
32 title: "Malware Domains", | 27 title: "Malware Domains", |
33 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" | 28 url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt" |
34 }, | 29 }, |
35 { | 30 { |
36 feature: "social", | 31 feature: "social", |
37 homepage: "https://www.fanboy.co.nz/", | 32 homepage: "https://www.fanboy.co.nz/", |
38 title: "Fanboy's Social Blocking List", | 33 title: "Fanboy's Social Blocking List", |
39 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 34 url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
40 }, | 35 }, |
41 { | 36 { |
42 feature: "tracking", | 37 feature: "tracking", |
43 homepage: "https://easylist.adblockplus.org/", | 38 homepage: "https://easylist.adblockplus.org/", |
44 title: "EasyPrivacy", | 39 title: "EasyPrivacy", |
45 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" | 40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" |
46 } | 41 } |
47 ]; | 42 ]; |
48 | 43 |
49 function getDocLink(link, callback) | |
50 { | |
51 ext.backgroundPage.sendMessage({ | |
52 type: "app.get", | |
53 what: "doclink", | |
54 link: link | |
55 }, callback); | |
56 } | |
57 | |
58 function onDOMLoaded() | 44 function onDOMLoaded() |
59 { | 45 { |
60 // Set up logo image | 46 // Set up logo image |
61 var logo = E("logo"); | 47 var logo = E("logo"); |
62 logo.src = "skin/abp-128.png"; | 48 logo.src = "skin/abp-128.png"; |
63 var errorCallback = function() | 49 var errorCallback = function() |
64 { | 50 { |
65 logo.removeEventListener("error", errorCallback, false); | 51 logo.removeEventListener("error", errorCallback, false); |
66 // We are probably in Chrome/Opera/Safari, the image has a different path. | 52 // We are probably in Chrome/Opera/Safari, the image has a different path. |
67 logo.src = "icons/detailed/abp-128.png"; | 53 logo.src = "icons/detailed/abp-128.png"; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 { | 129 { |
144 ext.backgroundPage.sendMessage({ | 130 ext.backgroundPage.sendMessage({ |
145 type: "subscriptions.toggle", | 131 type: "subscriptions.toggle", |
146 url: featureSubscription.url, | 132 url: featureSubscription.url, |
147 title: featureSubscription.title, | 133 title: featureSubscription.title, |
148 homepage: featureSubscription.homepage | 134 homepage: featureSubscription.homepage |
149 }); | 135 }); |
150 }, false); | 136 }, false); |
151 } | 137 } |
152 | 138 |
153 function openSharePopup(url) | |
154 { | |
155 var iframe = E("share-popup"); | |
156 var glassPane = E("glass-pane"); | |
157 var popupMessageReceived = false; | |
158 | |
159 // Firefox 38+ no longer allows messaging using postMessage so we need | |
160 // to have a fake top level frame to avoid problems with scripts that try to | |
161 // communicate with the first-run page | |
162 var isGecko = ("Components" in window); | |
163 if (isGecko) | |
164 { | |
165 try | |
166 { | |
167 var Ci = Components.interfaces; | |
168 iframe.contentWindow | |
169 .QueryInterface(Ci.nsIInterfaceRequestor) | |
170 .getInterface(Ci.nsIDocShell) | |
171 .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID); | |
172 } | |
173 catch(ex) | |
174 { | |
175 console.error(ex); | |
176 } | |
177 } | |
178 | |
179 function resizePopup(width, height) | |
180 { | |
181 iframe.width = width; | |
182 iframe.height = height; | |
183 iframe.style.marginTop = -height / 2 + "px"; | |
184 iframe.style.marginLeft = -width / 2 + "px"; | |
185 popupMessageReceived = true; | |
186 window.removeEventListener("message", popupMessageListener); | |
187 } | |
188 | |
189 var popupMessageListener = function(event) | |
190 { | |
191 if (!/[.\/]adblockplus\.org$/.test(event.origin)) | |
192 return; | |
193 | |
194 resizePopup(event.data.width, event.data.height); | |
195 }; | |
196 // Firefox requires last parameter to be true to be triggered by | |
197 // unprivileged pages | |
198 window.addEventListener("message", popupMessageListener, false, true); | |
199 | |
200 var popupLoadListener = function() | |
201 { | |
202 if (!popupMessageReceived && isGecko) | |
203 { | |
204 var rootElement = iframe.contentDocument.documentElement; | |
205 var width = rootElement.dataset.width; | |
206 var height = rootElement.dataset.height; | |
207 if (width && height) | |
208 resizePopup(width, height); | |
209 } | |
210 | |
211 if (popupMessageReceived) | |
212 { | |
213 iframe.className = "visible"; | |
214 | |
215 var popupCloseListener = function() | |
216 { | |
217 iframe.className = glassPane.className = ""; | |
218 document.removeEventListener("click", popupCloseListener); | |
219 }; | |
220 document.addEventListener("click", popupCloseListener, false); | |
221 } | |
222 else | |
223 { | |
224 glassPane.className = ""; | |
225 window.removeEventListener("message", popupMessageListener); | |
226 } | |
227 | |
228 iframe.removeEventListener("load", popupLoadListener); | |
229 }; | |
230 iframe.addEventListener("load", popupLoadListener, false); | |
231 | |
232 iframe.src = url; | |
233 glassPane.className = "visible"; | |
234 } | |
235 | |
236 function updateSocialLinks() | 139 function updateSocialLinks() |
237 { | 140 { |
238 var networks = ["twitter", "facebook", "gplus"]; | 141 var networks = ["twitter", "facebook", "gplus"]; |
239 networks.forEach(function(network) | 142 networks.forEach(function(network) |
240 { | 143 { |
241 var link = E("share-" + network); | 144 var link = E("share-" + network); |
242 var message = { | 145 checkShareResource(link.getAttribute("data-script"), function(isBlocked) |
243 type: "filters.blocked", | |
244 url: link.getAttribute("data-script"), | |
245 requestType: "SCRIPT", | |
246 docDomain: "adblockplus.org", | |
247 thirdParty: true | |
248 }; | |
249 ext.backgroundPage.sendMessage(message, function(blocked) | |
250 { | 146 { |
251 // Don't open the share page if the sharing script would be blocked | 147 // Don't open the share page if the sharing script would be blocked |
252 if (blocked) | 148 if (isBlocked) |
253 link.removeEventListener("click", onSocialLinkClick, false); | 149 link.removeEventListener("click", onSocialLinkClick, false); |
254 else | 150 else |
255 link.addEventListener("click", onSocialLinkClick, false); | 151 link.addEventListener("click", onSocialLinkClick, false); |
256 }); | 152 }); |
257 }); | 153 }); |
258 } | 154 } |
259 | 155 |
260 function onSocialLinkClick(event) | 156 function onSocialLinkClick(event) |
261 { | 157 { |
262 event.preventDefault(); | 158 event.preventDefault(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 { | 216 { |
321 var button = E("toggle-" + feature); | 217 var button = E("toggle-" + feature); |
322 if (isEnabled) | 218 if (isEnabled) |
323 button.classList.remove("off"); | 219 button.classList.remove("off"); |
324 else | 220 else |
325 button.classList.add("off"); | 221 button.classList.add("off"); |
326 } | 222 } |
327 | 223 |
328 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 224 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
329 })(); | 225 })(); |
OLD | NEW |