| 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 |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 | 695 |
| 696 exports.getBrowser = (window) => window.BrowserApp.selectedBrowser; | 696 exports.getBrowser = (window) => window.BrowserApp.selectedBrowser; |
| 697 | 697 |
| 698 exports.addTab = (window, url, event) => window.BrowserApp.addTab(url, {sele cted: true}); | 698 exports.addTab = (window, url, event) => window.BrowserApp.addTab(url, {sele cted: true}); |
| 699 | 699 |
| 700 let BrowserChangeListener = function(window, callback) | 700 let BrowserChangeListener = function(window, callback) |
| 701 { | 701 { |
| 702 this.window = window; | 702 this.window = window; |
| 703 this.callback = callback; | 703 this.callback = callback; |
| 704 this.onSelect = this.onSelect.bind(this); | 704 this.onSelect = this.onSelect.bind(this); |
| 705 this.attach = this.attach.bind(this); | |
| 705 if (window.BrowserApp.deck) | 706 if (window.BrowserApp.deck) |
| 706 this.attach(); | 707 this.attach(); |
| 707 else | 708 else |
| 708 window.addEventListener("UIReady", this.attach.bind(this), false); | 709 window.addEventListener("UIReady", this.attach, false); |
|
Wladimir Palant
2014/12/28 11:28:23
This listener needs to be removed when it fires, o
saroyanm
2014/12/28 19:30:14
Done.
| |
| 709 }; | 710 }; |
| 710 BrowserChangeListener.prototype = { | 711 BrowserChangeListener.prototype = { |
| 711 window: null, | 712 window: null, |
| 712 callback: null, | 713 callback: null, |
| 713 currentBrowser: null, | 714 currentBrowser: null, |
| 714 | 715 |
| 715 setBrowser: function(browser) | 716 setBrowser: function(browser) |
| 716 { | 717 { |
| 717 if (browser != this.currentBrowser) | 718 if (browser != this.currentBrowser) |
| 718 { | 719 { |
| 719 let oldBrowser = this.currentBrowser; | 720 let oldBrowser = this.currentBrowser; |
| 720 this.currentBrowser = browser; | 721 this.currentBrowser = browser; |
| 721 this.callback(oldBrowser, browser); | 722 this.callback(oldBrowser, browser); |
| 722 } | 723 } |
| 723 }, | 724 }, |
| 724 | 725 |
| 725 onSelect: function() | 726 onSelect: function() |
| 726 { | 727 { |
| 727 let {Utils} = require("utils"); | 728 let {Utils} = require("utils"); |
| 728 Utils.runAsync(function() | 729 Utils.runAsync(function() |
| 729 { | 730 { |
| 730 this.setBrowser(exports.getBrowser(this.window)); | 731 this.setBrowser(exports.getBrowser(this.window)); |
| 731 }.bind(this)); | 732 }.bind(this)); |
| 732 }, | 733 }, |
| 733 | 734 |
| 734 attach: function() | 735 attach: function() |
| 735 { | 736 { |
| 737 this.window.removeEventListener("UIReady", this.attach, false); | |
| 736 this.onSelect(); | 738 this.onSelect(); |
| 737 | |
| 738 this.window.BrowserApp.deck.addEventListener("TabSelect", this.onSelect, false); | 739 this.window.BrowserApp.deck.addEventListener("TabSelect", this.onSelect, false); |
| 739 }, | 740 }, |
| 740 detach: function() | 741 detach: function() |
| 741 { | 742 { |
| 742 this.window.BrowserApp.deck.removeEventListener("TabSelect", this.onSele ct, false); | 743 this.window.BrowserApp.deck.removeEventListener("TabSelect", this.onSele ct, false); |
| 743 | 744 |
| 744 this.setBrowser(null); | 745 this.setBrowser(null); |
| 745 } | 746 } |
| 746 }; | 747 }; |
| 747 | 748 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 event.state = {id: require("info").addonID}; | 951 event.state = {id: require("info").addonID}; |
| 951 browser._contentWindow.dispatchEvent(event); | 952 browser._contentWindow.dispatchEvent(event); |
| 952 }); | 953 }); |
| 953 }); | 954 }); |
| 954 }, true); | 955 }, true); |
| 955 }; | 956 }; |
| 956 | 957 |
| 957 break; | 958 break; |
| 958 } | 959 } |
| 959 } | 960 } |
| LEFT | RIGHT |