Bug 1035439 - Part 4: Change undoCloseTab to accept closed tab data. r=margaret

This commit is contained in:
Brian Nicholson 2014-07-14 17:21:14 -07:00
parent 2cf7a6f34e
commit 25b7f98ebb
3 changed files with 20 additions and 20 deletions

View File

@ -1020,9 +1020,6 @@ var BrowserApp = {
evt.initUIEvent("TabClose", true, false, window, tabIndex);
aTab.browser.dispatchEvent(evt);
aTab.destroy();
this._tabs.splice(tabIndex, 1);
if (aShowUndoToast) {
// Get a title for the undo close toast. Fall back to the URL if there is no title.
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
@ -1043,11 +1040,14 @@ var BrowserApp = {
label: Strings.browser.GetStringFromName("undoCloseToast.action2"),
callback: function() {
UITelemetry.addEvent("undo.1", "toast", null, "closetab");
ss.undoCloseTab(window, 0);
ss.undoCloseTab(window, closedTabData);
}
}
});
}
aTab.destroy();
this._tabs.splice(tabIndex, 1);
},
// Use this method to select a tab from JS. This method sends a message

View File

@ -14,7 +14,7 @@ interface nsIDOMNode;
* tabs contained in them.
*/
[scriptable, uuid(91eca9cf-6741-4c8f-a3a0-2e957240894d)]
[scriptable, uuid(5497d9a1-c378-47a9-9488-4c47a644131a)]
interface nsISessionStore : nsISupports
{
/**
@ -38,10 +38,10 @@ interface nsISessionStore : nsISupports
/**
* @param aWindow is the browser window to reopen a closed tab in.
* @param aIndex is the index of the tab to be restored (FIFO ordered).
* @param aCloseTabData is the data of the tab to be restored.
* @returns a reference to the reopened tab.
*/
nsIDOMNode undoCloseTab(in nsIDOMWindow aWindow, in unsigned long aIndex);
nsIDOMNode undoCloseTab(in nsIDOMWindow aWindow, in jsval aCloseTabData);
/**
* @param aWindow is the browser window associated with the closed tab.

View File

@ -865,7 +865,7 @@ SessionStore.prototype = {
return this._windows[aWindow.__SSID].closedTabs;
},
undoCloseTab: function ss_undoCloseTab(aWindow, aIndex) {
undoCloseTab: function ss_undoCloseTab(aWindow, aCloseTabData) {
if (!aWindow.__SSID)
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
@ -873,28 +873,28 @@ SessionStore.prototype = {
if (!closedTabs)
return null;
// default to the most-recently closed tab
aIndex = aIndex || 0;
if (!(aIndex in closedTabs))
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
// fetch the data of closed tab, while removing it from the array
let closedTab = closedTabs.splice(aIndex, 1).shift();
// If the tab data is in the closedTabs array, remove it.
closedTabs.find(function (tabData, i) {
if (tabData == aCloseTabData) {
closedTabs.splice(i, 1);
return true;
}
});
// create a new tab and bring to front
let params = {
selected: true,
isPrivate: closedTab.isPrivate,
desktopMode: closedTab.desktopMode,
isPrivate: aCloseTabData.isPrivate,
desktopMode: aCloseTabData.desktopMode,
tabIndex: this._lastClosedTabIndex
};
let tab = aWindow.BrowserApp.addTab(closedTab.entries[closedTab.index - 1].url, params);
this._restoreHistory(closedTab, tab.browser.sessionHistory);
let tab = aWindow.BrowserApp.addTab(aCloseTabData.entries[aCloseTabData.index - 1].url, params);
this._restoreHistory(aCloseTabData, tab.browser.sessionHistory);
this._lastClosedTabIndex = -1;
// Put back the extra data
tab.browser.__SS_extdata = closedTab.extData;
tab.browser.__SS_extdata = aCloseTabData.extData;
if (this._notifyClosedTabs) {
this._sendClosedTabsToJava(aWindow);