Backed out changeset 6d739868bd90 (bug 887515) for leaking windows on a CLOSED TREE.

This commit is contained in:
Jared Wein 2013-07-15 21:39:32 -04:00
parent 2557cd2077
commit aa9a9db36b
14 changed files with 29 additions and 140 deletions

View File

@ -571,7 +571,7 @@ HistoryMenu.prototype = {
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++)
undoCloseTab(0);
undoCloseTab();
}, false);
},

View File

@ -6259,31 +6259,15 @@ function undoCloseTab(aIndex) {
var tab = null;
var ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
let numberOfTabsToUndoClose = 0;
if (Number.isInteger(aIndex)) {
if (ss.getClosedTabCount(window) > aIndex) {
numberOfTabsToUndoClose = 1;
} else {
return tab;
}
} else {
numberOfTabsToUndoClose = ss.getNumberOfTabsClosedLast(window);
aIndex = 0;
}
while (numberOfTabsToUndoClose > 0 &&
numberOfTabsToUndoClose--) {
if (ss.getClosedTabCount(window) > (aIndex || 0)) {
TabView.prepareUndoCloseTab(blankTabToRemove);
tab = ss.undoCloseTab(window, aIndex);
tab = ss.undoCloseTab(window, aIndex || 0);
TabView.afterUndoCloseTab();
if (blankTabToRemove) {
if (blankTabToRemove)
gBrowser.removeTab(blankTabToRemove);
blankTabToRemove = null;
}
}
// Reset the number of tabs closed last time to the default.
ss.setNumberOfTabsClosedLast(window, 1);
return tab;
}
@ -7077,15 +7061,10 @@ var TabContextMenu = {
menuItem.disabled = disabled;
// Session store
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
let undoCloseTabElement = document.getElementById("context_undoCloseTab");
let closedTabCount = ss.getNumberOfTabsClosedLast(window);
undoCloseTabElement.disabled = closedTabCount == 0;
// Change the label of "Undo Close Tab" to specify if it will undo a batch-close
// or a single close.
let visibleLabel = closedTabCount <= 1 ? "singletablabel" : "multipletablabel";
undoCloseTabElement.setAttribute("label", undoCloseTabElement.getAttribute(visibleLabel));
document.getElementById("context_undoCloseTab").disabled =
Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore).
getClosedTabCount(window) == 0;
// Only one of pin/unpin should be visible
document.getElementById("context_pinTab").hidden = this.contextTab.pinned;

View File

@ -103,8 +103,7 @@
oncommand="gBrowser.removeAllTabsBut(TabContextMenu.contextTab);"/>
<menuseparator/>
<menuitem id="context_undoCloseTab"
singletablabel="&undoCloseTab.label;"
multipletablabel="&undoCloseTabs.label;"
label="&undoCloseTab.label;"
accesskey="&undoCloseTab.accesskey;"
observes="History:UndoCloseTab"/>
<menuitem id="context_closeTab" label="&closeTab.label;" accesskey="&closeTab.accesskey;"

View File

@ -1565,9 +1565,13 @@
throw new Error("Invalid argument: " + aCloseTabs);
}
if (tabsToClose <= 1 ||
aCloseTabs != this.closingTabsEnum.ALL ||
!Services.prefs.getBoolPref("browser.tabs.warnOnClose"))
if (tabsToClose <= 1)
return true;
const pref = aCloseTabs == this.closingTabsEnum.ALL ?
"browser.tabs.warnOnClose" : "browser.tabs.warnOnCloseOtherTabs";
var shouldPrompt = Services.prefs.getBoolPref(pref);
if (!shouldPrompt)
return true;
var ps = Services.prompt;
@ -1591,12 +1595,13 @@
+ (ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1),
bundle.getString("tabs.closeButtonMultiple"),
null, null,
bundle.getString("tabs.closeWarningPromptMe"),
aCloseTabs == this.closingTabsEnum.ALL ?
bundle.getString("tabs.closeWarningPromptMe") : null,
warnOnClose);
var reallyClose = (buttonPressed == 0);
// don't set the pref unless they press OK and it's false
if (reallyClose && !warnOnClose.value)
if (aCloseTabs == this.closingTabsEnum.ALL && reallyClose && !warnOnClose.value)
Services.prefs.setBoolPref(pref, false);
return reallyClose;
@ -1624,13 +1629,9 @@
<![CDATA[
if (this.warnAboutClosingTabs(this.closingTabsEnum.TO_END, aTab)) {
let tabs = this.getTabsToTheEndFrom(aTab);
let numberOfTabsToClose = tabs.length;
for (let i = numberOfTabsToClose - 1; i >= 0; --i) {
for (let i = tabs.length - 1; i >= 0; --i) {
this.removeTab(tabs[i], {animate: true});
}
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
ss.setNumberOfTabsClosedLast(window, numberOfTabsToClose);
}
]]>
</body>
@ -1647,16 +1648,10 @@
let tabs = this.visibleTabs;
this.selectedTab = aTab;
let closedTabs = 0;
for (let i = tabs.length - 1; i >= 0; --i) {
if (tabs[i] != aTab && !tabs[i].pinned) {
if (tabs[i] != aTab && !tabs[i].pinned)
this.removeTab(tabs[i]);
closedTabs++;
}
}
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
ss.setNumberOfTabsClosedLast(window, closedTabs);
}
]]>
</body>
@ -1685,10 +1680,6 @@
var byMouse = aParams.byMouse;
}
let ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
ss.setNumberOfTabsClosedLast(window, 1);
// Handle requests for synchronously removing an already
// asynchronously closing tab.
if (!animate &&

View File

@ -25,7 +25,7 @@ interface nsIDOMNode;
* |gBrowser.tabContainer| such as e.g. |gBrowser.selectedTab|.
*/
[scriptable, uuid(0aa5492c-15ad-4376-8eac-28895796826e)]
[scriptable, uuid(59bfaf00-e3d8-4728-b4f0-cc0b9dfb4806)]
interface nsISessionStore : nsISupports
{
/**
@ -105,20 +105,6 @@ interface nsISessionStore : nsISupports
nsIDOMNode duplicateTab(in nsIDOMWindow aWindow, in nsIDOMNode aTab,
[optional] in long aDelta);
/**
* Set the number of tabs that was closed during the last close-tabs
* operation. This helps us keep track of batch-close operations so
* we can restore multiple tabs at once.
*/
void setNumberOfTabsClosedLast(in nsIDOMWindow aWindow, in unsigned long aNumber);
/**
* Get the number of tabs that was closed during the last close-tabs
* operation. This helps us keep track of batch-close operations so
* we can restore multiple tabs at once.
*/
unsigned long getNumberOfTabsClosedLast(in nsIDOMWindow aWindow);
/**
* Get the number of restore-able tabs for a browser window
*/

View File

@ -170,14 +170,6 @@ this.SessionStore = {
return SessionStoreInternal.duplicateTab(aWindow, aTab, aDelta);
},
getNumberOfTabsClosedLast: function ss_getNumberOfTabsClosedLast(aWindow) {
return SessionStoreInternal.getNumberOfTabsClosedLast(aWindow);
},
setNumberOfTabsClosedLast: function ss_setNumberOfTabsClosedLast(aWindow, aNumber) {
return SessionStoreInternal.setNumberOfTabsClosedLast(aWindow, aNumber);
},
getClosedTabCount: function ss_getClosedTabCount(aWindow) {
return SessionStoreInternal.getClosedTabCount(aWindow);
},
@ -1537,28 +1529,6 @@ let SessionStoreInternal = {
return newTab;
},
setNumberOfTabsClosedLast: function ssi_setNumberOfTabsClosedLast(aWindow, aNumber) {
if ("__SSi" in aWindow) {
return NumberOfTabsClosedLastPerWindow.set(aWindow, aNumber);
}
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
},
/* Used to undo batch tab-close operations. Defaults to 1. */
getNumberOfTabsClosedLast: function ssi_getNumberOfTabsClosedLast(aWindow) {
if ("__SSi" in aWindow) {
// Blank tabs cannot be undo-closed, so the number returned by
// the NumberOfTabsClosedLastPerWindow can be greater than the
// return value of getClosedTabCount. We won't restore blank
// tabs, so we return the minimum of these two values.
return Math.min(NumberOfTabsClosedLastPerWindow.get(aWindow) || 1,
this.getClosedTabCount(aWindow));
}
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
},
getClosedTabCount: function ssi_getClosedTabCount(aWindow) {
if ("__SSi" in aWindow) {
return this._windows[aWindow.__SSi]._closedTabs.length;
@ -4724,11 +4694,6 @@ let DyingWindowCache = {
}
};
// A map storing the number of tabs last closed per windoow. This only
// stores the most recent tab-close operation, and is used to undo
// batch tab-closing operations.
let NumberOfTabsClosedLastPerWindow = new WeakMap();
// A set of tab attributes to persist. We will read a given list of tab
// attributes when collecting tab data and will re-set those attributes when
// the given tab data is restored to a new tab.

View File

@ -40,8 +40,4 @@ function test() {
"Invalid window for getWindowValue throws");
ok(test(function() ss.setWindowValue({}, "", "")),
"Invalid window for setWindowValue throws");
ok(test(function() ss.getNumberOfTabsClosedLast({})),
"Invalid window for getNumberOfTabsClosedLast throws");
ok(test(function() ss.setNumberOfTabsClosedLast({}, 1)),
"Invalid window for setNumberOfTabsClosedLast throws");
}

View File

@ -38,5 +38,5 @@ function onTabViewWindowLoaded() {
gBrowser.removeTab(tabTwo);
finish();
});
}, 0);
});
}

View File

@ -55,25 +55,6 @@ function test() {
}, aWindow);
}
// [887515] testing undo closing multiple tabs
let testUndoCloseMultipleTabs = function (aWindow) {
aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
afterAllTabsLoaded(function () {
assertNumberOfVisibleTabs(aWindow, 5);
aWindow.gBrowser.removeTabsToTheEndFrom(aWindow.gBrowser.tabs[0]);
assertNumberOfVisibleTabs(aWindow, 1);
restoreTab(function () {
assertNumberOfVisibleTabs(aWindow, 5);
next(aWindow);
}, undefined, aWindow);
}, aWindow);
}
// [623792] duplicating tab via middle click on reload button
let testDuplicateTab = function (aWindow) {
aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
@ -131,9 +112,6 @@ function test() {
// Tests for #624265
tests.push(testUndoCloseTabs);
// Tests for #887515
tests.push(testUndoCloseMultipleTabs);
// Tests for #623792
tests.push(testDuplicateTab);
tests.push(testBackForwardDuplicateTab);

View File

@ -64,7 +64,7 @@ function test() {
createBlankTab();
afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab);
}, 0);
});
});
}
@ -94,7 +94,7 @@ function test() {
gBrowser.removeTab(gBrowser.tabs[0]);
afterAllTabsLoaded(finishTest);
}, 0);
});
});
}

View File

@ -81,7 +81,7 @@ function test() {
gBrowser.removeTab(gBrowser.tabs[1]);
gBrowser.removeTab(gBrowser.tabs[1]);
hideTabView(finishTest);
}, 0);
});
}
waitForExplicitFinish();

View File

@ -20,7 +20,7 @@ function test() {
whenTabViewIsHidden(function() {
win.gBrowser.removeTab(win.gBrowser.selectedTab);
executeSoon(function() {
win.undoCloseTab(0);
win.undoCloseTab();
groupItemTwo.addSubscriber("childAdded", function onChildAdded(data) {
groupItemTwo.removeSubscriber("childAdded", onChildAdded);

View File

@ -359,7 +359,7 @@ function newWindowWithState(state, callback) {
function restoreTab(callback, index, win) {
win = win || window;
let tab = win.undoCloseTab(index);
let tab = win.undoCloseTab(index || 0);
let tabItem = tab._tabViewTabItem;
let finalize = function () {

View File

@ -46,11 +46,6 @@ can reach it easily. -->
<!ENTITY bookmarkAllTabs.accesskey "T">
<!ENTITY undoCloseTab.label "Undo Close Tab">
<!ENTITY undoCloseTab.accesskey "U">
<!-- LOCALIZATION NOTE (undoCloseTabs.label) : This label is used
when the previous tab-closing operation closed more than one tab. It
replaces the undoCloseTab.label and will use the same accesskey as the
undoCloseTab.label so users will not need to learn new keyboard controls. -->
<!ENTITY undoCloseTabs.label "Undo Close Tabs">
<!ENTITY closeTab.label "Close Tab">
<!ENTITY closeTab.accesskey "c">