Bug 956368 - Keep track of tab groups when switching to Metro and only switch over tabs from the current group. r=mbrubeck, a=lsblakk
authorMarina Samuel <msamuel@mozilla.com>
Wed, 08 Jan 2014 13:32:38 -0500
changeset 175791 1f6eaab92cb98210ae1fb233856ef673821b4bf1
parent 175790 31db6a06fc521b0558d0cc834604f409764c7493
child 175792 cb1622bda20842af930c012ff076ad7c18aae56b
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck, lsblakk
bugs956368
milestone28.0a2
Bug 956368 - Keep track of tab groups when switching to Metro and only switch over tabs from the current group. r=mbrubeck, a=lsblakk
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