Bug 1018661 - Use session store data instead of current browser data for undo close tab toast. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 04 Jun 2014 19:10:05 -0700
changeset 207095 80a57d37adcb84ac08bf4a6159dbc8d7de51827f
parent 207094 18925acdcbbfffcda69b2c6adcccca69902ad986
child 207096 0dc1743249550e578e3aca7fb980501729a252f0
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1018661
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1018661 - Use session store data instead of current browser data for undo close tab toast. r=bnicholson
mobile/android/chrome/content/browser.js
mobile/android/components/SessionStore.idl
mobile/android/components/SessionStore.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -971,31 +971,34 @@ var BrowserApp = {
   _handleTabClosed: function _handleTabClosed(aTab, aShowUndoToast) {
     if (aTab == this.selectedTab)
       this.selectedTab = null;
 
     let evt = document.createEvent("UIEvents");
     evt.initUIEvent("TabClose", true, false, window, null);
     aTab.browser.dispatchEvent(evt);
 
-    // Get a title for the undo close toast. Fall back to the URL if there is no title.
-    let title = aTab.browser.contentDocument.title || aTab.browser.contentDocument.URL;
-
     aTab.destroy();
     this._tabs.splice(this._tabs.indexOf(aTab), 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);
+      let closedTabData = ss.getClosedTabs(window)[0];
+
+      let historyEntry = closedTabData.entries[closedTabData.index - 1];
+      let title = historyEntry.title || historyEntry.url;
+
       let message = Strings.browser.formatStringFromName("undoCloseToast.message", [title], 1);
       NativeWindow.toast.show(message, "short", {
         button: {
           icon: "drawable://undo_button_icon",
           label: Strings.browser.GetStringFromName("undoCloseToast.action2"),
           callback: function() {
             UITelemetry.addEvent("undo.1", "toast", null, "closetab");
-            let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
             ss.undoCloseTab(window, 0);
           }
         }
       });
     }
   },
 
   // Use this method to select a tab from JS. This method sends a message
--- a/mobile/android/components/SessionStore.idl
+++ b/mobile/android/components/SessionStore.idl
@@ -9,17 +9,17 @@ interface nsIDOMNode;
 
 /**
  * nsISessionStore keeps track of the current browsing state.
  *
  * The nsISessionStore API operates mostly on browser windows and the browser
  * tabs contained in them.
  */
 
-[scriptable, uuid(fe116b56-0226-4562-b52a-a623dad07ead)]
+[scriptable, uuid(91eca9cf-6741-4c8f-a3a0-2e957240894d)]
 interface nsISessionStore : nsISupports
 {
   /**
    * Get the current browsing state.
    * @returns a JSON string representing the session state.
    */
   AString getBrowserState();
 
@@ -27,19 +27,19 @@ interface nsISessionStore : nsISupports
    * Get the number of restore-able tabs for a browser window
    */
   unsigned long getClosedTabCount(in nsIDOMWindow aWindow);
 
   /**
    * Get closed tab data
    *
    * @param aWindow is the browser window for which to get closed tab data
-   * @returns a JSON string representing the list of closed tabs.
+   * @returns a JS array of closed tabs.
    */
-  AString getClosedTabData(in nsIDOMWindow aWindow);
+  jsval getClosedTabs(in nsIDOMWindow aWindow);
 
   /**
    * @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).
    * @returns a reference to the reopened tab.
    */
   nsIDOMNode undoCloseTab(in nsIDOMWindow aWindow, in unsigned long aIndex);
 
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -813,21 +813,21 @@ SessionStore.prototype = {
 
   getClosedTabCount: function ss_getClosedTabCount(aWindow) {
     if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID])
       return 0; // not a browser window, or not otherwise tracked by SS.
 
     return this._windows[aWindow.__SSID].closedTabs.length;
   },
 
-  getClosedTabData: function ss_getClosedTabData(aWindow) {
+  getClosedTabs: function ss_getClosedTabs(aWindow) {
     if (!aWindow.__SSID)
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
 
-    return JSON.stringify(this._windows[aWindow.__SSID].closedTabs);
+    return this._windows[aWindow.__SSID].closedTabs;
   },
 
   undoCloseTab: function ss_undoCloseTab(aWindow, aIndex) {
     if (!aWindow.__SSID)
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
     if (!closedTabs)