[Pkg-mozext-commits] [tabmixplus] 16/22: [e10s] Use SessionStore.getTabState to get history data, can't use historyEntry.getScrollPosition with remote tab

David Prévot taffit at moszumanska.debian.org
Sun Jan 4 16:46:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit a71d3febd9b319c3a096bb5abbc44e1312efd00e
Author: onemen <tabmix.onemen at gmail.com>
Date:   Sat Dec 27 16:00:32 2014 +0200

    [e10s] Use SessionStore.getTabState to get history data, can't use historyEntry.getScrollPosition with remote tab
---
 chrome/content/session/session.js      | 136 +++++++++++++++------------------
 chrome/content/session/sessionStore.js |  11 ++-
 2 files changed, 73 insertions(+), 74 deletions(-)

diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index 43c75aa..c66051d 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -2820,7 +2820,6 @@ try{
    },
 
    // call from tabloaded, tabClosed, saveAllTab
-// xxx add flag what to save : all, history, property, scrollPosition
    saveTab: function SM_saveTab(aTab, rdfLabelTabs, tabContainer, needToAppend) {
       if (this.isTabPrivate(aTab))
          return false;
@@ -2836,23 +2835,16 @@ try{
 
       var sessionHistory = aBrowser.webNavigation.sessionHistory;
       if (!sessionHistory)
-        return false;
+         return false;
       var rdfLabelTab = rdfLabelTabs + "/" + aTab.linkedPanel;
-      var index = sessionHistory.index < 0 ? 0 : sessionHistory.index;
-      var bContent = aBrowser[TabmixSvc.contentWindowAsCPOW];
-      try {
-         var curHistory = sessionHistory.getEntryAtIndex(index, false);
-         curHistory.QueryInterface(Ci.nsISHEntry).setScrollPosition(bContent.scrollX, bContent.scrollY);
-      } catch (ex) {Tabmix.assert(ex, "saveTab error at index " + sessionHistory.index);}
       var rdfNodeTab = this.RDFService.GetResource(rdfLabelTab);
-      var data = {
-         index: this.enableSaveHistory ? index : 0,
-         pos: aTab._tPos,
-         image: gBrowser.getIcon(aTab),
-         properties: TabmixSessionData.getTabProperties(aTab, true),
-         history: this.saveTabHistory(sessionHistory),
-         scroll: bContent.scrollX + "," + bContent.scrollY
-      };
+      var tabState = JSON.parse(TabmixSvc.ss.getTabState(aTab));
+      var data = this.serializeHistory(tabState);
+      if (!data)
+         return false;
+      data.pos = aTab._tPos;
+      data.image = tabState.image;
+      data.properties = TabmixSessionData.getTabProperties(aTab, true);
       this.saveTabData(rdfNodeTab, data);
       this.saveTabviewTab(rdfNodeTab, aTab);
 
@@ -2884,19 +2876,39 @@ try{
       this.setLiteral   (aNode, "scroll",     aData.scroll);
    },
 
-   saveTabHistory: function(sessionHistory) {
-      var historyStart = this.enableSaveHistory ? 0 : sessionHistory.index;
-      var historyEnd = this.enableSaveHistory ? sessionHistory.count : sessionHistory.index+1;
+  /**
+   * Convert SessionStore tab history state object
+   *
+   * @param state
+   *        SessionStore tab state object
+   * @return object containing history entries, current history index and
+   *                current history scroll position
+   */
+   serializeHistory: function(state) {
+      // Ensure sure that all entries have url
+      var entries = state.entries.filter(function(e) e.url);
+      if (!entries.length)
+        return null;
+      // Ensure the index is in bounds.
+      var index = (state.index || entries.length) - 1;
+      index = Math.min(index, entries.length - 1);
+      index = Math.max(index, 0);
+      var historyStart = this.enableSaveHistory ? 0 : index;
+      var historyEnd = this.enableSaveHistory ? entries.length : index + 1;
       var history = [];
-      sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
+
+      var saveScroll = this.prefBranch.getBoolPref("save.scrollposition");
+      var currentScroll = saveScroll && state.scroll ? state.scroll.scroll : "0,0";
+      if (currentScroll != "0,0")
+        entries[index].scroll = currentScroll;
+
       for (let j = historyStart; j < historyEnd; j++) {
-         try {
-            let historyEntry = sessionHistory.getEntryAtIndex(j, false);
-            historyEntry.QueryInterface(Ci.nsISHEntry);
-            history.push(historyEntry.title);
-            history.push(historyEntry.URI.spec);
-            history.push(this.getScrollPosHs(historyEntry)); // not in use yet
-         } catch (ex) {Tabmix.assert(ex, "saveTabHistory error at index " + j); }
+        try {
+          let historyEntry = entries[j];
+          history.push(historyEntry.title || "");
+          history.push(historyEntry.url);
+          history.push(saveScroll && historyEntry.scroll || "0,0");
+        } catch (ex) {Tabmix.assert(ex, "serializeHistory error at index " + j); }
       }
       // generate unique separator and combine the array to one string
       var separator = "][", extraSeparator = "@";
@@ -2904,19 +2916,13 @@ try{
          while (history[i].indexOf(separator) > -1)
             separator += extraSeparator;
       }
-      // insert the separator to history so we can extract it in loadTabHistory
-      return separator + "|-|" + encodeURI(history.join(separator));
-   },
-
-   getScrollPosHs: function(historyEntry) {
-      if (this.prefBranch.getBoolPref("save.scrollposition")) {
-        try {
-          var x={}, y={};
-          historyEntry.getScrollPosition(x, y);
-          return x.value + "," + y.value;
-        } catch (ex) {}
-      }
-      return "0,0";
+      return {
+        // insert the separator to history so we can extract it in
+        // TabmixConvertSession.getHistoryState
+        history: separator + "|-|" + encodeURI(history.join(separator)),
+        index: index,
+        scroll: currentScroll
+      };
    },
 
    get canRestoreLastSession() {
@@ -3521,14 +3527,16 @@ try{
       var tabCount = ctabs.length;
       var maxTabsUndo = Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo");
       for (var i = tabCount - 1; i >= 0; i--) {
-         let tabData, uniqueId, rdfLabelSession, newNode;
+         let tabData = ctabs[i];
+         let data = this.getSessionStoreDataForRDF(tabData);
+         if (!data)
+            continue;
+         let uniqueId, rdfLabelSession, newNode;
          uniqueId = "panel" + Date.now() + i;
          rdfLabelSession = rdfLabelTabs + "/" + uniqueId;
          newNode = this.RDFService.GetResource(rdfLabelSession);
          toContainer.AppendElement(newNode);
-         tabData = ctabs[i];
-         this.getSessionStoreDataForRDF(tabData);
-         this.saveTabData(newNode, tabData);
+         this.saveTabData(newNode, data);
 
          // delete old entry if closedTabs container wasn't empty
          if (toContainer.GetCount() > maxTabsUndo)
@@ -3539,51 +3547,33 @@ try{
 
    getSessionStoreDataForRDF: function SM_getSessionStoreDataForRDF(aTabData) {
       var tabState = aTabData.state;
-      var count = tabState.entries.length;
-      var activeIndex = (tabState.index || count) - 1;
-      var historyStart = this.enableSaveHistory ? 0 : activeIndex;
-      var historyEnd = this.enableSaveHistory ? count : activeIndex + 1;
-      var historyEntry, history = [];
-      for (let j = historyStart; j < historyEnd; j++) {
-         try {
-            historyEntry = tabState.entries[j];
-            history.push(historyEntry.title || "");
-            history.push(historyEntry.url);
-            history.push(historyEntry.scroll || "0,0"); // not in use yet
-         } catch (ex) {Tabmix.assert(ex, "saveTabHistory error at index " + j); }
-      }
-      // generate unique separator and combine the array to one string
-      var separator = "][", extraSeparator = "@";
-      for (var i = 0; i < history.length; ++i) {
-         while (history[i].indexOf(separator) > -1)
-            separator += extraSeparator;
-      }
-      // insert the separator to history so we can extract it in loadTabHistory
-      aTabData.history = separator + "|-|" + encodeURI(history.join(separator));
-      aTabData.index = this.enableSaveHistory ? activeIndex : 0;
-      aTabData.scroll = this.prefBranch.getBoolPref("save.scrollposition") ?
-                         (tabState.entries[activeIndex].scroll || "0,0") : "0,0";
+      var data = this.serializeHistory(tabState);
+      if (!data)
+         return false;
+      data.pos = aTabData.pos;
+      data.image = aTabData.image;
       // closed tab can not be protected - set protected to 0
       var _locked = TMP_SessionStore._getAttribute(tabState, "_locked") != "false" ? "1" : "0";
-      aTabData.properties = "0" + _locked;
+      data.properties = "0" + _locked;
       if ("disallow" in tabState && tabState.disallow) {
          for (let j = 0; j < TabmixSessionData.docShellItems.length; j++ )
-            aTabData.properties += tabState.disallow.indexOf(TabmixSessionData.docShellItems[j]) == -1 ? "1" : "0";
+            data.properties += tabState.disallow.indexOf(TabmixSessionData.docShellItems[j]) == -1 ? "1" : "0";
       }
       else {
-         aTabData.properties += "11111";
+         data.properties += "11111";
       }
       if ("attributes" in tabState && tabState.attributes) {
          delete tabState.attributes["_locked"];
          for (var name in tabState.attributes) {
-            aTabData.properties += " " + name + "=" + encodeURI(tabState.attributes[name]);
+            data.properties += " " + name + "=" + encodeURI(tabState.attributes[name]);
          }
       }
       if ("xultab" in tabState && tabState.xultab) {
          tabState.xultab = tabState.xultab.replace(" _locked=true", "").replace(" _locked=false", "");
          if (tabState.xultab)
-            aTabData.properties += " " + tabState.xultab;
+            data.properties += " " + tabState.xultab;
       }
+      return data;
    },
 
    deleteAllClosedtabs: function(sessionContainer) { // delete all closed tabs in this session
diff --git a/chrome/content/session/sessionStore.js b/chrome/content/session/sessionStore.js
index fd7e952..80f645b 100644
--- a/chrome/content/session/sessionStore.js
+++ b/chrome/content/session/sessionStore.js
@@ -809,7 +809,14 @@ var TabmixConvertSession = { // jshint ignore:line
         return null;
       tabData.image = TabmixSessionManager.getLiteralValue(rdfNodeTab, "image", null);
       let index = TabmixSessionManager.getIntValue(rdfNodeTab, "index");
-      tabData.index = Math.min(index + 1, tabData.entries.length);
+      tabData.index = Math.max(1, Math.min(index + 1, tabData.entries.length));
+      let scroll = TabmixSessionManager.getLiteralValue(rdfNodeTab, "scroll", "0,0");
+      // until version 0.4.1.5 textZoom was included in scroll data
+      scroll = scroll.split(",").splice(0, 2).join(",");
+      if (scroll != "0,0") {
+        tabData.scroll = {scroll: scroll};
+      }
+
       var properties = TabmixSessionManager.getLiteralValue(rdfNodeTab, "properties");
       var tabAttribute = ["Images","Subframes","MetaRedirects","Plugins","Javascript"];
 
@@ -908,6 +915,8 @@ var TabmixConvertSession = { // jshint ignore:line
          let entry = { url:"", children:[], ID: 0};
          let index = i * 3;
          entry.url = historyData[index + 1];
+         if (!entry.url)
+            continue;
          entry.title = decodeData(historyData[index], !newFormat);
          entry.scroll = historyData[index + 2];
          entries.push(entry);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list