Bug 655269 - Don't rely on 'domwindowclosed' being fired in the expected order; f=raymond, r=dao

This commit is contained in:
Tim Taubert 2011-06-10 11:40:10 +02:00
parent 4d83370881
commit 2017680bf0
4 changed files with 45 additions and 17 deletions

View File

@ -40,6 +40,7 @@ let TabView = {
_deck: null,
_iframe: null,
_window: null,
_initialized: false,
_browserKeyHandlerInitialized: false,
_isFrameLoading: false,
_initFrameCallbacks: [],
@ -89,6 +90,9 @@ let TabView = {
// ----------
init: function TabView_init() {
if (this._initialized)
return;
if (this.firstUseExperienced) {
if ((gBrowser.tabs.length - gBrowser.visibleTabs.length) > 0)
this._setBrowserKeyHandlers();
@ -124,6 +128,8 @@ let TabView = {
}
Services.prefs.addObserver(this.PREF_BRANCH, this, false);
this._initialized = true;
},
// ----------
@ -138,12 +144,17 @@ let TabView = {
// ----------
// Uninitializes TabView.
uninit: function TabView_uninit() {
if (!this._initialized)
return;
Services.prefs.removeObserver(this.PREF_BRANCH, this);
if (this._tabShowEventListener) {
gBrowser.tabContainer.removeEventListener(
"TabShow", this._tabShowEventListener, true);
}
this._initialized = false;
},
// ----------

View File

@ -128,8 +128,7 @@ let UI = {
_storageBusyCount: 0,
// Variable: isDOMWindowClosing
// Tells wether we already received the "domwindowclosed" event and the parent
// windows is about to close.
// Tells wether the parent window is about to close
isDOMWindowClosing: false,
// Variable: _browserKeys
@ -257,21 +256,18 @@ let UI = {
self._resize();
});
// ___ setup observer to save canvas images
function domWinClosedObserver(subject, topic, data) {
if (topic == "domwindowclosed" && subject == gWindow) {
self.isDOMWindowClosing = true;
if (self.isTabViewVisible())
GroupItems.removeHiddenGroups();
TabItems.saveAll(true);
self._save();
}
}
Services.obs.addObserver(
domWinClosedObserver, "domwindowclosed", false);
this._cleanupFunctions.push(function() {
Services.obs.removeObserver(domWinClosedObserver, "domwindowclosed");
});
// ___ setup event listener to save canvas images
gWindow.addEventListener("SSWindowClosing", function onWindowClosing() {
gWindow.removeEventListener("SSWindowClosing", onWindowClosing, false);
self.isDOMWindowClosing = true;
if (self.isTabViewVisible())
GroupItems.removeHiddenGroups();
TabItems.saveAll(true);
self._save();
}, false);
// ___ Done
this._frameInitialized = true;

View File

@ -143,6 +143,7 @@ _BROWSER_FILES = \
browser_tabview_bug650573.js \
browser_tabview_bug651311.js \
browser_tabview_bug654941.js \
browser_tabview_bug655269.js \
browser_tabview_bug656778.js \
browser_tabview_bug656913.js \
browser_tabview_dragdrop.js \

View File

@ -0,0 +1,20 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
waitForExplicitFinish();
newWindowWithTabView(function (win) {
let cw = win.TabView.getContentWindow();
let tabItem = win.gBrowser.tabs[0]._tabViewTabItem;
tabItem.addSubscriber(tabItem, "savedCachedImageData", function () {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
ok(cw.UI.isDOMWindowClosing, "dom window is closing");
waitForFocus(finish);
});
win.close();
});
}