| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the Adblock Plus build tools, | 2 * This file is part of the Adblock Plus build tools, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 17 matching lines...) Expand all Loading... |
| 28 * @param {String} [when] when to execute applyToWindow(). "start" means immed
iately | 28 * @param {String} [when] when to execute applyToWindow(). "start" means immed
iately |
| 29 * when the window opens, "ready" when its contents are
available | 29 * when the window opens, "ready" when its contents are
available |
| 30 * and "end" (default) means to wait until the "load" e
vent. | 30 * and "end" (default) means to wait until the "load" e
vent. |
| 31 * @constructor | 31 * @constructor |
| 32 */ | 32 */ |
| 33 function WindowObserver(listener, when) | 33 function WindowObserver(listener, when) |
| 34 { | 34 { |
| 35 this._listener = listener; | 35 this._listener = listener; |
| 36 this._when = when; | 36 this._when = when; |
| 37 | 37 |
| 38 let windows = []; |
| 38 let e = Services.wm.getZOrderDOMWindowEnumerator(null, true); | 39 let e = Services.wm.getZOrderDOMWindowEnumerator(null, true); |
| 39 if (!e.hasMoreElements()) | 40 while (e.hasMoreElements()) |
| 41 windows.push(e.getNext()); |
| 42 |
| 43 // Check if there are any windows that we missed |
| 44 let eAll = Services.ww.getWindowEnumerator(); |
| 45 while (eAll.hasMoreElements()) |
| 40 { | 46 { |
| 41 // On Linux the list returned will be empty, see bug 156333. Fall back to ra
ndom order. | 47 let element = eAll.getNext(); |
| 42 e = Services.wm.getEnumerator(null); | 48 if (windows.indexOf(element) < 0) |
| 49 windows.push(element); |
| 43 } | 50 } |
| 44 while (e.hasMoreElements()) | 51 |
| 52 for (let i = 0; i < windows.length; i++) |
| 45 { | 53 { |
| 46 let window = e.getNext().QueryInterface(Ci.nsIDOMWindow); | 54 let window = windows[i].QueryInterface(Ci.nsIDOMWindow); |
| 47 if (when == "start" || window.document.readyState == "complete") | 55 if (when == "start" || window.document.readyState == "complete") |
| 48 this._listener.applyToWindow(window); | 56 this._listener.applyToWindow(window); |
| 49 else | 57 else |
| 50 this.observe(window, "chrome-document-global-created", null); | 58 this.observe(window, "chrome-document-global-created", null); |
| 51 } | 59 } |
| 52 | 60 |
| 53 Services.obs.addObserver(this, "chrome-document-global-created", true); | 61 Services.obs.addObserver(this, "chrome-document-global-created", true); |
| 54 | 62 |
| 55 this._shutdownHandler = function() | 63 this._shutdownHandler = function() |
| 56 { | 64 { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 window.removeEventListener(event, listener, false); | 103 window.removeEventListener(event, listener, false); |
| 96 if (this._shutdownHandler) | 104 if (this._shutdownHandler) |
| 97 this._listener.applyToWindow(window); | 105 this._listener.applyToWindow(window); |
| 98 }.bind(this); | 106 }.bind(this); |
| 99 window.addEventListener(event, listener, false); | 107 window.addEventListener(event, listener, false); |
| 100 } | 108 } |
| 101 }, | 109 }, |
| 102 | 110 |
| 103 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | 111 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) |
| 104 }; | 112 }; |
| OLD | NEW |