From 5dafabfff47118fd2a6475e7758ec2e6f042345b Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Tue, 16 Apr 2013 14:57:06 +0200 Subject: [PATCH] Bug 855484 - Wait for toplevel-window-ready instead of domwindowopen to avoid issues with private windows. --- lib/sdk/deprecated/window-utils.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/sdk/deprecated/window-utils.js b/lib/sdk/deprecated/window-utils.js index 554c1513d..78758ecea 100644 --- a/lib/sdk/deprecated/window-utils.js +++ b/lib/sdk/deprecated/window-utils.js @@ -11,6 +11,7 @@ const { Cc, Ci } = require('chrome'); const { EventEmitter } = require('../deprecated/events'); const { Trait } = require('../deprecated/traits'); const { when } = require('../system/unload'); +const events = require('../system/events'); const { getInnerId, getOuterId, windows, isDocumentLoaded, isBrowser, getMostRecentBrowserWindow, getMostRecentWindow } = require('../window/utils'); const errors = require('../deprecated/errors'); @@ -68,6 +69,8 @@ function WindowTracker(delegate) { for each (let window in getWindows()) this._regWindow(window); windowWatcher.registerNotification(this); + this._onToplevelWindowReady = this._onToplevelWindowReady.bind(this); + events.on('toplevel-window-ready', this._onToplevelWindowReady); require('../system/unload').ensure(this); @@ -116,6 +119,7 @@ WindowTracker.prototype = { unload: function unload() { windowWatcher.unregisterNotification(this); + events.off('toplevel-window-ready', this._onToplevelWindowReady); for each (let window in getWindows()) this._unregWindow(window); }, @@ -128,14 +132,20 @@ WindowTracker.prototype = { } }), + _onToplevelWindowReady: function _onToplevelWindowReady({subject}) { + let window = subject; + // ignore private windows if they are not supported + if (ignoreWindow(window)) + return; + this._regWindow(window); + }, + observe: errors.catchAndLog(function observe(subject, topic, data) { var window = subject.QueryInterface(Ci.nsIDOMWindow); // ignore private windows if they are not supported if (ignoreWindow(window)) return; - if (topic == 'domwindowopened') - this._regWindow(window); - else + if (topic == 'domwindowclosed') this._unregWindow(window); }) };