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 /** | 18 /** |
19 * @fileOverview Various application-specific functions. | 19 * @fileOverview Various application-specific functions. |
20 */ | 20 */ |
21 | 21 |
22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
23 Cu.import("resource://gre/modules/Services.jsm"); | 23 Cu.import("resource://gre/modules/Services.jsm"); |
| 24 Cu.import("resource://gre/modules/AddonManager.jsm"); |
24 | 25 |
25 /** | 26 /** |
26 * Checks whether an application window is known and should get Adblock Plus | 27 * Checks whether an application window is known and should get Adblock Plus |
27 * user interface elements. | 28 * user interface elements. |
28 * @result Boolean | 29 * @result Boolean |
29 */ | 30 */ |
30 exports.isKnownWindow = function isKnownWindow(/**Window*/ window) | 31 exports.isKnownWindow = (/**Window*/ window) => false; |
31 { | |
32 return false; | |
33 } | |
34 | 32 |
35 /** | 33 /** |
36 * HACK: In some applications the window finishes initialization during load | 34 * HACK: In some applications the window finishes initialization during load |
37 * event processing which makes an additional delay necessary. This flag | 35 * event processing which makes an additional delay necessary. This flag |
38 * indicates that. | 36 * indicates that. |
39 * @type Boolean | 37 * @type Boolean |
40 */ | 38 */ |
41 exports.delayInitialization = false; | 39 exports.delayInitialization = false; |
42 | 40 |
43 /** | 41 /** |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 let {application} = require("info"); | 257 let {application} = require("info"); |
260 switch (application) | 258 switch (application) |
261 { | 259 { |
262 case "firefox": | 260 case "firefox": |
263 { | 261 { |
264 exports.isKnownWindow = function ff_isKnownWindow(window) | 262 exports.isKnownWindow = function ff_isKnownWindow(window) |
265 { | 263 { |
266 return (window.document.documentElement.getAttribute("windowtype") == "nav
igator:browser"); | 264 return (window.document.documentElement.getAttribute("windowtype") == "nav
igator:browser"); |
267 }; | 265 }; |
268 | 266 |
269 exports.getBrowser = function ff_getBrowser(window) { | 267 exports.getBrowser = (window) => window.gBrowser; |
270 return window.gBrowser | |
271 }; | |
272 | 268 |
273 exports.addTab = function ff_addTab(window, url, event) | 269 exports.addTab = function ff_addTab(window, url, event) |
274 { | 270 { |
275 if (event) | 271 if (event) |
276 window.openNewTabWith(url, exports.getBrowser(window).contentDocument, n
ull, event, false); | 272 window.openNewTabWith(url, exports.getBrowser(window).contentDocument, n
ull, event, false); |
277 else | 273 else |
278 window.gBrowser.loadOneTab(url, {inBackground: false}); | 274 window.gBrowser.loadOneTab(url, {inBackground: false}); |
279 }; | 275 }; |
280 | 276 |
281 exports.contentContextMenu = "contentAreaContextMenu"; | 277 exports.contentContextMenu = "contentAreaContextMenu"; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 case "thunderbird": | 389 case "thunderbird": |
394 { | 390 { |
395 exports.isKnownWindow = function tb_isKnownWindow(window) | 391 exports.isKnownWindow = function tb_isKnownWindow(window) |
396 { | 392 { |
397 let type = window.document.documentElement.getAttribute("windowtype"); | 393 let type = window.document.documentElement.getAttribute("windowtype"); |
398 return (type == "mail:3pane" || type == "mail:messageWindow"); | 394 return (type == "mail:3pane" || type == "mail:messageWindow"); |
399 }; | 395 }; |
400 | 396 |
401 exports.delayInitialization = true; | 397 exports.delayInitialization = true; |
402 | 398 |
403 exports.getBrowser = function tb_getBrowser(window) { | 399 exports.getBrowser = (window) => window.getBrowser(); |
404 return window.getBrowser(); | |
405 } | |
406 | 400 |
407 exports.addTab = function tb_addTab(window, url, event) | 401 exports.addTab = function tb_addTab(window, url, event) |
408 { | 402 { |
409 let tabmail = window.document.getElementById("tabmail"); | 403 let tabmail = window.document.getElementById("tabmail"); |
410 if (!tabmail) | 404 if (!tabmail) |
411 { | 405 { |
412 let wnd = Services.wm.getMostRecentWindow("mail:3pane"); | 406 let wnd = Services.wm.getMostRecentWindow("mail:3pane"); |
413 if (window) | 407 if (window) |
414 tabmail = wnd.document.getElementById("tabmail"); | 408 tabmail = wnd.document.getElementById("tabmail"); |
415 } | 409 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 listener.detach(); | 676 listener.detach(); |
683 this.listeners.delete(window); | 677 this.listeners.delete(window); |
684 } | 678 } |
685 }); | 679 }); |
686 | 680 |
687 break; | 681 break; |
688 } | 682 } |
689 | 683 |
690 case "fennec2": | 684 case "fennec2": |
691 { | 685 { |
692 exports.isKnownWindow = function fmn_isKnownWindow(/**Window*/ window) { | 686 exports.isKnownWindow = (window) => window.document.documentElement.id == "m
ain-window"; |
693 return window.document.documentElement.id == "main-window"; | 687 |
694 }; | 688 exports.getBrowser = (window) => window.BrowserApp.selectedBrowser; |
695 | 689 |
696 exports.getBrowser = function fmn_getBrowser(window) { | 690 exports.addTab = (window, url, event) => window.BrowserApp.addTab(url, {sele
cted: true}); |
697 return window.BrowserApp.selectedBrowser; | |
698 }; | |
699 | |
700 exports.addTab = function fmn_addTab(window, url, event) { | |
701 return window.BrowserApp.addTab(url, {selected: true}); | |
702 }; | |
703 | 691 |
704 let BrowserChangeListener = function(window, callback) | 692 let BrowserChangeListener = function(window, callback) |
705 { | 693 { |
706 this.window = window; | 694 this.window = window; |
707 this.callback = callback; | 695 this.callback = callback; |
708 this.onSelect = this.onSelect.bind(this); | 696 this.onSelect = this.onSelect.bind(this); |
709 this.attach(); | 697 this.attach(); |
710 }; | 698 }; |
711 BrowserChangeListener.prototype = { | 699 BrowserChangeListener.prototype = { |
712 window: null, | 700 window: null, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 }; | 911 }; |
924 | 912 |
925 UI.openSubscriptionDialog = function(window, url, title, mainURL, mainTitle) | 913 UI.openSubscriptionDialog = function(window, url, title, mainURL, mainTitle) |
926 { | 914 { |
927 let dialogTitle = this.overlay.attributes.subscriptionDialogTitle; | 915 let dialogTitle = this.overlay.attributes.subscriptionDialogTitle; |
928 let dialogMessage = this.overlay.attributes.subscriptionDialogMessage.repl
ace(/\?1\?/, title).replace(/\?2\?/, url); | 916 let dialogMessage = this.overlay.attributes.subscriptionDialogMessage.repl
ace(/\?1\?/, title).replace(/\?2\?/, url); |
929 if (Utils.confirm(window, dialogMessage, dialogTitle)) | 917 if (Utils.confirm(window, dialogMessage, dialogTitle)) |
930 this.setSubscription(url, title); | 918 this.setSubscription(url, title); |
931 }; | 919 }; |
932 | 920 |
| 921 UI.openFiltersDialog = function() |
| 922 { |
| 923 let window = UI.currentWindow; |
| 924 if (!window) |
| 925 return |
| 926 |
| 927 let browser = exports.addTab(window, "about:addons").browser; |
| 928 browser.addEventListener("load", function openAddonPrefs(event) |
| 929 { |
| 930 browser.removeEventListener("load", openAddonPrefs, true); |
| 931 Utils.runAsync(function() |
| 932 { |
| 933 // The page won't be ready until the add-on manager data is loaded so
we call this method |
| 934 // to know when the data will be ready. |
| 935 AddonManager.getAddonsByTypes(["extension", "theme", "locale"], functi
on() |
| 936 { |
| 937 let event = new Event("Event"); |
| 938 event.initEvent("popstate", true, false); |
| 939 event.state = {id: require("info").addonID}; |
| 940 browser._contentWindow.dispatchEvent(event); |
| 941 }); |
| 942 }); |
| 943 }, true); |
| 944 }; |
| 945 |
933 break; | 946 break; |
934 } | 947 } |
935 } | 948 } |
LEFT | RIGHT |