Fennec tabs and Firefox tabs now handled in different functions, and the Fennec one at least works.
authorjonathandicarlo@jonathan-dicarlos-macbook-pro.local
Tue, 10 Feb 2009 19:23:06 -0800
changeset 45238 09e78e93eda5d18d763629dfe400494f8cf28a8e
parent 45233 50cb25ce097885dfe8e1e47f9ad7b3df7dd9d5a1
child 45239 1e58336e9f6db16bfa42d16e5548bd8843810cc2
push idunknown
push userunknown
push dateunknown
Fennec tabs and Firefox tabs now handled in different functions, and the Fennec one at least works.
services/sync/modules/engines/tabs.js
--- a/services/sync/modules/engines/tabs.js
+++ b/services/sync/modules/engines/tabs.js
@@ -95,23 +95,16 @@ TabStore.prototype = {
   get _localClientGUID() {
     return Clients.clientID;
   },
 
   get _localClientName() {
     return Clients.clientName;
   },
 
-  get _fennecTabs() {
-    let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
-	       .getService(Ci.nsIWindowMediator);
-    let browserWindow = wm.getMostRecentWindow("navigator:browser");
-    return browserWindow.Browser._tabs;
-  },
-
   _writeToFile: function TabStore_writeToFile() {
     // use JSON service to serialize the records...
     this._log.debug("Writing out to file...");
     let file = Utils.getProfileFile(
       {path: this._filePath, autoCreate: true});
     let jsonObj = {};
     for (let id in this._remoteClients) {
       jsonObj[id] = this._remoteClients[id].toJson();
@@ -152,53 +145,65 @@ TabStore.prototype = {
   },
 
   get _json() {
     let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
     this.__defineGetter__("_json", function() {return json;});
     return this._json;
   },
 
-  _addTabToRecord: function( tab, record ) {
-    // TODO contentDocument not defined for fennec's tab objects
-    let title = tab.contentDocument.title.innerHtml; // will this work?
-    this._log.debug("Wrapping a tab with title " + title);
-    let urlHistory = [];
-    let entries = tab.entries.slice(tab.entries.length - 10);
-    for (let entry in entries) {
-      urlHistory.push( entry.url );
-    }
-    record.addTab(title, urlHistory);
-  },
-
   _createLocalClientTabSetRecord: function TabStore__createLocalTabSet() {
     // Test for existence of sessionStore.  If it doesn't exist, then
     // use get _fennecTabs instead.
     let record = new TabSetRecord();
     record.setClientName( this._localClientName );
 
     if (Cc["@mozilla.org/browser/sessionstore;1"])  {
-      let session = this._json.decode(this._sessionStore.getBrowserState());
-      for (let i = 0; i < session.windows.length; i++) {
-	let window = session.windows[i];
-	/* For some reason, session store uses one-based array index references,
-	 (f.e. in the "selectedWindow" and each tab's "index" properties), so we
-	 convert them to and from JavaScript's zero-based indexes as needed. */
-	let windowID = i + 1;
+      this._addFirefoxTabsToRecord(record);
+    } else {
+      this._addFennecTabsToRecord(record);
+    }
+    return record;
+  },
 
-	for (let j = 0; j < window.tabs.length; j++) {
-	  this._addTabToRecord(window.tabs[j], record);
-	}
-      }
-    } else {
-      for each ( let tab in this._fennecTabs) {
-	this._addTabToRecord(tab, record);
+  _addFirefoxTabsToRecord: function TabStore__addFirefoxTabs(record) {
+    let session = this._json.decode(this._sessionStore.getBrowserState());
+    for (let i = 0; i < session.windows.length; i++) {
+      let window = session.windows[i];
+      /* For some reason, session store uses one-based array index references,
+        (f.e. in the "selectedWindow" and each tab's "index" properties), so we
+        convert them to and from JavaScript's zero-based indexes as needed. */
+      let windowID = i + 1;
+
+      for (let j = 0; j < window.tabs.length; j++) {
+        let tab = window.tabs[j];
+        let title = tab.contentDocument.title.innerHtml; // will this work?
+        this._log.debug("Wrapping a tab with title " + title);
+        let urlHistory = [];
+        let entries = tab.entries.slice(tab.entries.length - 10);
+        for (let entry in entries) {
+          urlHistory.push( entry.url );
+        }
+        record.addTab(title, urlHistory);
       }
     }
-    return record;
+  },
+
+  _addFennecTabsToRecord: function TabStore__addFennecTabs(record) {
+    let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
+	       .getService(Ci.nsIWindowMediator);
+    let browserWindow = wm.getMostRecentWindow("navigator:browser");
+    for each (let tab in browserWindow.Browser._tabs ) {
+      let title = tab.browser.contentDocument.title;
+      let url = tab.browser.contentWindow.location;
+      let urlHistory = [url];
+      // TODO how to get older entries in urlHistory?
+      dump("Making tab with title = " + title + ", url = " + url + "\n");
+      record.addTab(title, urlHistory);
+    }
   },
 
   itemExists: function TabStore_itemExists(id) {
     this._log.debug("ItemExists called.");
     if (id == this._localClientGUID) {
       this._log.debug("It's me.");
       return true;
     } else if (this._remoteClients[id]) {