OLD | NEW |
1 /* | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * This file is part of the Adblock Plus build tools, | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
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 | 4 |
18 Cu.import("resource://gre/modules/Services.jsm"); | 5 Cu.import("resource://gre/modules/Services.jsm"); |
19 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
20 | 7 |
21 exports.WindowObserver = WindowObserver; | 8 exports.WindowObserver = WindowObserver; |
22 | 9 |
23 /** | 10 /** |
24 * This class will call listener's method applyToWindow() for all new chrome | 11 * This class will call listener's method applyToWindow() for all new chrome |
25 * windows being opened. It will also call listener's method removeFromWindow() | 12 * windows being opened. It will also call listener's method removeFromWindow() |
26 * for all windows still open when the extension is shut down. | 13 * for all windows still open when the extension is shut down. |
(...skipping 14 matching lines...) Expand all Loading... |
41 windows.push(e.getNext()); | 28 windows.push(e.getNext()); |
42 | 29 |
43 // Check if there are any windows that we missed | 30 // Check if there are any windows that we missed |
44 let eAll = Services.ww.getWindowEnumerator(); | 31 let eAll = Services.ww.getWindowEnumerator(); |
45 while (eAll.hasMoreElements()) | 32 while (eAll.hasMoreElements()) |
46 { | 33 { |
47 let element = eAll.getNext(); | 34 let element = eAll.getNext(); |
48 if (windows.indexOf(element) < 0) | 35 if (windows.indexOf(element) < 0) |
49 windows.push(element); | 36 windows.push(element); |
50 } | 37 } |
51 | 38 |
52 for (let i = 0; i < windows.length; i++) | 39 for (let i = 0; i < windows.length; i++) |
53 { | 40 { |
54 let window = windows[i].QueryInterface(Ci.nsIDOMWindow); | 41 let window = windows[i].QueryInterface(Ci.nsIDOMWindow); |
55 if (when == "start" || window.document.readyState == "complete") | 42 if (when == "start" || window.document.readyState == "complete") |
56 this._listener.applyToWindow(window); | 43 this._listener.applyToWindow(window); |
57 else | 44 else |
58 this.observe(window, "chrome-document-global-created", null); | 45 this.observe(window, "chrome-document-global-created", null); |
59 } | 46 } |
60 | 47 |
61 Services.obs.addObserver(this, "chrome-document-global-created", true); | 48 Services.obs.addObserver(this, "chrome-document-global-created", true); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 window.removeEventListener(event, listener, false); | 90 window.removeEventListener(event, listener, false); |
104 if (this._shutdownHandler) | 91 if (this._shutdownHandler) |
105 this._listener.applyToWindow(window); | 92 this._listener.applyToWindow(window); |
106 }.bind(this); | 93 }.bind(this); |
107 window.addEventListener(event, listener, false); | 94 window.addEventListener(event, listener, false); |
108 } | 95 } |
109 }, | 96 }, |
110 | 97 |
111 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | 98 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) |
112 }; | 99 }; |
OLD | NEW |