Bug 956368: Keep track of tab groups when switching to Metro and only switch over tabs from the current group. r=mbrubeck
authorMarina Samuel <msamuel@mozilla.com>
Wed, 08 Jan 2014 13:32:38 -0500
changeset 162559 6c4862a2b752fa76cd058181c49c2f712069bee8
parent 162558 9e1c24e4206b3394bee4634288793600bbe97518
child 162560 885af7c6cdc30445cfb930127a5f594060a9684b
push id25959
push userryanvm@gmail.com
push dateWed, 08 Jan 2014 20:28:56 +0000
treeherdermozilla-central@9ca0f64ee634 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs956368
milestone29.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 956368: Keep track of tab groups when switching to Metro and only switch over tabs from the current group. r=mbrubeck
browser/metro/components/SessionStore.js
--- a/browser/metro/components/SessionStore.js
+++ b/browser/metro/components/SessionStore.js
@@ -37,16 +37,17 @@ SessionStore.prototype = {
   classID: Components.ID("{8c1f07d6-cba3-4226-a315-8bd43d67d032}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISessionStore,
                                          Ci.nsIDOMEventListener,
                                          Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
   _windows: {},
+  _tabsFromOtherGroups: [],
   _selectedWindow: 1,
   _orderedWindows: [],
   _lastSaveTime: 0,
   _lastSessionTime: 0,
   _interval: 10000,
   _maxTabsUndo: 1,
   _shouldRestore: false,
 
@@ -533,37 +534,42 @@ SessionStore.prototype = {
     let tabData = {};
     tabData.entries = aHistory.entries;
     tabData.index = aHistory.index;
     tabData.attributes = { image: aBrowser.mIconURL };
 
     aBrowser.__SS_data = tabData;
   },
 
+  _saveTabData: function(aTabList, aWinData) {
+    for (let tab of aTabList) {
+      let browser = tab.browser;
+      if (browser.__SS_data) {
+        let tabData = browser.__SS_data;
+        if (browser.__SS_extdata)
+          tabData.extData = browser.__SS_extdata;
+        aWinData.tabs.push(tabData);
+      }
+    }
+  },
+
   _collectWindowData: function ss__collectWindowData(aWindow) {
     // Ignore windows not tracked by SessionStore
     if (!aWindow.__SSID || !this._windows[aWindow.__SSID])
       return;
 
     let winData = this._windows[aWindow.__SSID];
     winData.tabs = [];
 
     let index = aWindow.Elements.browsers.selectedIndex;
     winData.selected = parseInt(index) + 1; // 1-based
 
     let tabs = aWindow.Browser.tabs;
-    for (let i = 0; i < tabs.length; i++) {
-      let browser = tabs[i].browser;
-      if (browser.__SS_data) {
-        let tabData = browser.__SS_data;
-        if (browser.__SS_extdata)
-          tabData.extData = browser.__SS_extdata;
-        winData.tabs.push(tabData);
-      }
-    }
+    this._saveTabData(tabs, winData);
+    this._saveTabData(this._tabsFromOtherGroups, winData);
   },
 
   _forEachBrowserWindow: function ss_forEachBrowserWindow(aFunc) {
     let windowsEnum = Services.wm.getEnumerator("navigator:browser");
     while (windowsEnum.hasMoreElements()) {
       let window = windowsEnum.getNext();
       if (window.__SSID && !window.closed)
         aFunc.call(this, window);
@@ -769,16 +775,21 @@ SessionStore.prototype = {
 
         let window = Services.wm.getMostRecentWindow("navigator:browser");
 
         this._selectedWindow = data.selectedWindow;
         let windowIndex = this._selectedWindow - 1;
         let tabs = data.windows[windowIndex].tabs;
         let selected = data.windows[windowIndex].selected;
 
+        let currentGroupId;
+        try {
+          currentGroupId = JSON.parse(data.windows[windowIndex].extData["tabview-groups"]).activeGroupId;
+        } catch (ex) { /* currentGroupId is undefined if user has no tab groups */ }
+
         // Move all window data from sessionstore.js to this._windows.
         for (let i = 0; i < data.windows.length; i++) {
           let SSID;
           if (i != windowIndex) {
             SSID = "window" + gUUIDGenerator.generateUUID().toString();
             this._windows[SSID] = data.windows[i];
           } else {
             SSID = window.__SSID;
@@ -788,16 +799,23 @@ SessionStore.prototype = {
           this._orderedWindows.push(SSID);
         }
 
         if (selected > tabs.length) // Clamp the selected index if it's bogus
           selected = 1;
 
         for (let i=0; i<tabs.length; i++) {
           let tabData = tabs[i];
+          let tabGroupId = (typeof currentGroupId == "number") ?
+            JSON.parse(tabData.extData["tabview-tab"]).groupID : null;
+
+          if (tabGroupId && tabGroupId != currentGroupId) {
+            this._tabsFromOtherGroups.push(tabData);
+            continue;
+          }
 
           // We must have selected tabs as soon as possible, so we let all tabs be selected
           // until we get the real selected tab. Then we stop selecting tabs. The end result
           // is that the right tab is selected, but we also don't get a bunch of errors
           let bringToFront = (i + 1 <= selected) && aBringToFront;
           let tab = window.Browser.addTab(tabData.entries[tabData.index - 1].url, bringToFront);
 
           // Start a real load for the selected tab