Bug 595020 - Group name isn't displayed in title before TabView is loaded the first time; r=dao
authorTim Taubert <tim.taubert@gmx.de>
Tue, 03 May 2011 20:30:08 +0200
changeset 71385 3a5d39bd32a66956b2d6361ceef89a52cc163873
parent 71384 0c47cb07f6894c26b8cd96f991d0ee5ae6955df5
child 71391 243b53ce24611ebadcb2b4833d6fcbba4ef995e7
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs595020
milestone7.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 595020 - Group name isn't displayed in title before TabView is loaded the first time; r=dao
browser/base/content/browser-tabview.js
browser/base/content/tabview/storage.js
browser/base/content/tabview/ui.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug595020.js
--- a/browser/base/content/browser-tabview.js
+++ b/browser/base/content/browser-tabview.js
@@ -39,22 +39,24 @@
 let TabView = {
   _deck: null,
   _iframe: null,
   _window: null,
   _initialized: false,
   _browserKeyHandlerInitialized: false,
   _isFrameLoading: false,
   _initFrameCallbacks: [],
+  _lastSessionGroupName: null,
   PREF_BRANCH: "browser.panorama.",
   PREF_FIRST_RUN: "browser.panorama.experienced_first_run",
   PREF_STARTUP_PAGE: "browser.startup.page",
   PREF_RESTORE_ENABLED_ONCE: "browser.panorama.session_restore_enabled_once",
+  GROUPS_IDENTIFIER: "tabview-groups",
   VISIBILITY_IDENTIFIER: "tabview-visibility",
-  GROUPS_IDENTIFIER: "tabview-groups",
+  LAST_SESSION_GROUP_NAME_IDENTIFIER: "tabview-last-session-group-name",
 
   // ----------
   get windowTitle() {
     delete this.windowTitle;
     let brandBundle = document.getElementById("bundle_brand");
     let brandShortName = brandBundle.getString("brandShortName");
     let title = gNavigatorBundle.getFormattedString("tabView2.title", [brandShortName]);
     return this.windowTitle = title;
@@ -119,16 +121,20 @@ let TabView = {
         this._tabShowEventListener = function (event) {
           if (!self._window)
             self._initFrame(function() {
               self._window.UI.onTabSelect(gBrowser.selectedTab);
             });
         };
         gBrowser.tabContainer.addEventListener(
           "TabShow", this._tabShowEventListener, true);
+
+       // grab the last used group title
+       this._lastSessionGroupName = sessionstore.getWindowValue(window,
+         this.LAST_SESSION_GROUP_NAME_IDENTIFIER);
       }
     }
 
     Services.prefs.addObserver(this.PREF_BRANCH, this, false);
 
     this._initialized = true;
   },
 
@@ -242,28 +248,38 @@ let TabView = {
   toggle: function() {
     if (this.isVisible())
       this.hide();
     else 
       this.show();
   },
   
   getActiveGroupName: function TabView_getActiveGroupName() {
+    if (!this._window)
+      return this._lastSessionGroupName;
+
     // We get the active group this way, instead of querying
     // GroupItems.getActiveGroupItem() because the tabSelect event
     // will not have happened by the time the browser tries to
     // update the title.
+    let groupItem = null;
     let activeTab = window.gBrowser.selectedTab;
-    if (activeTab._tabViewTabItem && activeTab._tabViewTabItem.parent){
-      let groupName = activeTab._tabViewTabItem.parent.getTitle();
-      if (groupName)
-        return groupName;
+    let activeTabItem = activeTab._tabViewTabItem;
+
+    if (activeTab.pinned) {
+      // It's an app tab, so it won't have a .tabItem. However, its .parent
+      // will already be set as the active group. 
+      groupItem = this._window.GroupItems.getActiveGroupItem();
+    } else if (activeTabItem) {
+      groupItem = activeTabItem.parent;
     }
-    return null;
-  },  
+
+    // groupItem may still be null, if the active tab is an orphan.
+    return groupItem ? groupItem.getTitle() : "";
+  },
 
   // ----------
   updateContextMenu: function(tab, popup) {
     let separator = document.getElementById("context_tabViewNamedGroups");
     let isEmpty = true;
 
     while (popup.firstChild && popup.firstChild != separator)
       popup.removeChild(popup.firstChild);
--- a/browser/base/content/tabview/storage.js
+++ b/browser/base/content/tabview/storage.js
@@ -216,16 +216,25 @@ let Storage = {
   // Function: saveVisibilityData
   // Saves visibility for the given window.
   saveVisibilityData: function Storage_saveVisibilityData(win, data) {
     this._sessionStore.setWindowValue(
       win, win.TabView.VISIBILITY_IDENTIFIER, data);
   },
 
   // ----------
+  // Function: saveActiveGroupName
+  // Saves the active group's name for the given window.
+  saveActiveGroupName: function Storage_saveActiveGroupName(win) {
+    let groupName = win.TabView.getActiveGroupName();
+    this._sessionStore.setWindowValue(
+      win, win.TabView.LAST_SESSION_GROUP_NAME_IDENTIFIER, groupName);
+  },
+
+  // ----------
   // Function: saveData
   // Generic routine for saving data to a window.
   saveData: function Storage_saveData(win, id, data) {
     try {
       this._sessionStore.setWindowValue(win, id, JSON.stringify(data));
     } catch (e) {
       Utils.log("Error in saveData: "+e);
     }
--- a/browser/base/content/tabview/ui.js
+++ b/browser/base/content/tabview/ui.js
@@ -260,16 +260,17 @@ let UI = {
       gWindow.addEventListener("SSWindowClosing", function onWindowClosing() {
         gWindow.removeEventListener("SSWindowClosing", onWindowClosing, false);
 
         self.isDOMWindowClosing = true;
 
         if (self.isTabViewVisible())
           GroupItems.removeHiddenGroups();
 
+        Storage.saveActiveGroupName(gWindow);
         TabItems.saveAll(true);
         self._save();
       }, false);
 
       // ___ Done
       this._frameInitialized = true;
       this._save();
 
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -54,16 +54,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug587351.js \
                  browser_tabview_bug587503.js \
                  browser_tabview_bug587990.js \
                  browser_tabview_bug588265.js \
                  browser_tabview_bug589324.js \
                  browser_tabview_bug590606.js \
                  browser_tabview_bug591706.js \
                  browser_tabview_bug594958.js \
+                 browser_tabview_bug595020.js \
                  browser_tabview_bug595191.js \
                  browser_tabview_bug595436.js \
                  browser_tabview_bug595518.js \
                  browser_tabview_bug595521.js \
                  browser_tabview_bug595560.js \
                  browser_tabview_bug595601.js \
                  browser_tabview_bug595804.js \
                  browser_tabview_bug595930.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug595020.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+
+let stateStartup = {windows:[
+  {tabs:[{entries:[{url:"about:home"}]}], extData:{"tabview-last-session-group-name":"title"}}
+]};
+
+function test() {
+  let assertWindowTitle = function (win, title) {
+    let browser = win.gBrowser.tabs[0].linkedBrowser;
+    let winTitle = win.gBrowser.getWindowTitleForBrowser(browser);
+    is(winTitle.indexOf(title), 0, "title starts with '" + title + "'");
+  };
+
+  let testGroupNameChange = function (win) {
+    showTabView(function () {
+      let cw = win.TabView.getContentWindow();
+      let groupItem = cw.GroupItems.groupItems[0];
+      groupItem.setTitle("new-title");
+
+      hideTabView(function () {
+        assertWindowTitle(win, "new-title");
+        waitForFocus(finish);
+      }, win);
+    }, win);
+  };
+
+  waitForExplicitFinish();
+
+  newWindowWithState(stateStartup, function (win) {
+    registerCleanupFunction(function () win.close());
+    assertWindowTitle(win, "title");
+    testGroupNameChange(win);
+  });
+}