Bug 1320550 - Part 1 - Only try showing the "Undo close tab" snackbar if we actually have some closed tab data. r=sebastian
This can happen if the users sets browser.sessionstore.max_tabs_undo to 0 - with no closed tabs available, without this fix the resulting exception breaks browser.js's closed tab handling, meaning the tab gets closed in the UI but not in Gecko.
MozReview-Commit-ID: 7yMyIB6UzAB
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1245,37 +1245,39 @@ var BrowserApp = {
evt.initUIEvent("TabClose", true, false, window, tabIndex);
aTab.browser.dispatchEvent(evt);
if (aShowUndoSnackbar) {
// Get a title for the undo close snackbar. Fall back to the URL if there is no title.
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
let closedTabData = ss.getClosedTabs(window)[0];
- let message;
- let title = closedTabData.entries[closedTabData.index - 1].title;
- let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aTab.browser);
-
- if (isPrivate) {
- message = Strings.browser.GetStringFromName("privateClosedMessage.message");
- } else if (title) {
- message = Strings.browser.formatStringFromName("undoCloseToast.message", [title], 1);
- } else {
- message = Strings.browser.GetStringFromName("undoCloseToast.messageDefault");
- }
-
- Snackbars.show(message, Snackbars.LENGTH_LONG, {
- action: {
- label: Strings.browser.GetStringFromName("undoCloseToast.action2"),
- callback: function() {
- UITelemetry.addEvent("undo.1", "toast", null, "closetab");
- ss.undoCloseTab(window, closedTabData);
+ if (closedTabData) {
+ let message;
+ let title = closedTabData.entries[closedTabData.index - 1].title;
+ let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aTab.browser);
+
+ if (isPrivate) {
+ message = Strings.browser.GetStringFromName("privateClosedMessage.message");
+ } else if (title) {
+ message = Strings.browser.formatStringFromName("undoCloseToast.message", [title], 1);
+ } else {
+ message = Strings.browser.GetStringFromName("undoCloseToast.messageDefault");
+ }
+
+ Snackbars.show(message, Snackbars.LENGTH_LONG, {
+ action: {
+ label: Strings.browser.GetStringFromName("undoCloseToast.action2"),
+ callback: function() {
+ UITelemetry.addEvent("undo.1", "toast", null, "closetab");
+ 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
// to Java to select the tab in the Java UI (we'll get a Tab:Selected message