Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/windowObserver.js

Issue 11624001: Fixed: WindowObserver ignoring primary browser window if instantiated before window visible (Closed)
Left Patch Set: Created Sept. 9, 2013, 2:54 p.m.
Right Patch Set: Created Sept. 16, 2013, 3:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 19 matching lines...) Expand all
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 windows = [];
39 let e = Services.wm.getZOrderDOMWindowEnumerator(null, true); 39 let e = Services.wm.getZOrderDOMWindowEnumerator(null, true);
40 if (!e.hasMoreElements())
41 {
42 // On Linux the list returned will be empty, see bug 156333. Fall back to ra ndom order.
43 e = Services.wm.getEnumerator(null);
44 }
Wladimir Palant 2013/09/11 11:31:26 I think we can drop the fallback here, ww.getWindo
45 while (e.hasMoreElements()) 40 while (e.hasMoreElements())
46 { 41 windows.push(e.getNext());
47 let element = e.getNext();
48 this._addWindowListener(element);
49 windows.push(element);
50 }
51 42
52 // Check if there are any windows that we missed because they are not visible yet 43 // Check if there are any windows that we missed
53 let eAll = Services.ww.getWindowEnumerator(); 44 let eAll = Services.ww.getWindowEnumerator();
54 while (eAll.hasMoreElements()) 45 while (eAll.hasMoreElements())
55 { 46 {
56 let element = eAll.getNext(); 47 let element = eAll.getNext();
57 if (windows.indexOf(element) < 0) 48 if (windows.indexOf(element) < 0)
58 this._addWindowListener(element); 49 windows.push(element);
Wladimir Palant 2013/09/11 11:31:26 I'd rather have windows.push(element) here - simpl
50 }
51
52 for (let i = 0; i < windows.length; i++)
53 {
54 let window = windows[i].QueryInterface(Ci.nsIDOMWindow);
55 if (when == "start" || window.document.readyState == "complete")
56 this._listener.applyToWindow(window);
57 else
58 this.observe(window, "chrome-document-global-created", null);
59 } 59 }
60 60
61 Services.obs.addObserver(this, "chrome-document-global-created", true); 61 Services.obs.addObserver(this, "chrome-document-global-created", true);
62 62
63 this._shutdownHandler = function() 63 this._shutdownHandler = function()
64 { 64 {
65 let e = Services.ww.getWindowEnumerator(); 65 let e = Services.ww.getWindowEnumerator();
66 while (e.hasMoreElements()) 66 while (e.hasMoreElements())
67 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow )); 67 this._listener.removeFromWindow(e.getNext().QueryInterface(Ci.nsIDOMWindow ));
68 68
69 Services.obs.removeObserver(this, "chrome-document-global-created"); 69 Services.obs.removeObserver(this, "chrome-document-global-created");
70 }.bind(this); 70 }.bind(this);
71 onShutdown.add(this._shutdownHandler); 71 onShutdown.add(this._shutdownHandler);
72 } 72 }
73 WindowObserver.prototype = 73 WindowObserver.prototype =
74 { 74 {
75 _listener: null, 75 _listener: null,
76 _when: null, 76 _when: null,
77 _shutdownHandler: null, 77 _shutdownHandler: null,
78
79 _addWindowListener: function(e)
80 {
81 let window = e.QueryInterface(Ci.nsIDOMWindow);
82 if (this._when == "start" || window.document.readyState == "complete")
83 this._listener.applyToWindow(window);
84 else
85 this.observe(window, "chrome-document-global-created", null);
86 },
87 78
88 shutdown: function() 79 shutdown: function()
89 { 80 {
90 if (!this._shutdownHandler) 81 if (!this._shutdownHandler)
91 return; 82 return;
92 83
93 onShutdown.remove(this._shutdownHandler); 84 onShutdown.remove(this._shutdownHandler);
94 this._shutdownHandler(); 85 this._shutdownHandler();
95 this._shutdownHandler = null; 86 this._shutdownHandler = null;
96 }, 87 },
(...skipping 15 matching lines...) Expand all
112 window.removeEventListener(event, listener, false); 103 window.removeEventListener(event, listener, false);
113 if (this._shutdownHandler) 104 if (this._shutdownHandler)
114 this._listener.applyToWindow(window); 105 this._listener.applyToWindow(window);
115 }.bind(this); 106 }.bind(this);
116 window.addEventListener(event, listener, false); 107 window.addEventListener(event, listener, false);
117 } 108 }
118 }, 109 },
119 110
120 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver]) 111 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse rver])
121 }; 112 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld