Bug 648338 - Remove remaining Firefox 3.5/3.6 compat code. r=rnewman
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Thu, 07 Apr 2011 15:31:11 -0700
changeset 67776 7a31e654594358df05f20849c63fcd6f6b26ef02
parent 67775 7249a475841963025662109455c1ba4cbda88a48
child 67777 4ad9a3906f713c5a38de8209e616150eea621034
push id19427
push userpweitershausen@mozilla.com
push dateSun, 10 Apr 2011 18:54:44 +0000
treeherdermozilla-central@21ce62e6aebe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs648338
milestone2.2a1pre
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 648338 - Remove remaining Firefox 3.5/3.6 compat code. r=rnewman
services/sync/modules/engines/passwords.js
services/sync/modules/engines/prefs.js
services/sync/modules/util.js
services/sync/tests/unit/test_utils_file.js
services/sync/tests/unit/test_utils_json.js
--- a/services/sync/modules/engines/passwords.js
+++ b/services/sync/modules/engines/passwords.js
@@ -109,23 +109,18 @@ PasswordEngine.prototype = {
 };
 
 function PasswordStore(name) {
   Store.call(this, name);
   this._nsLoginInfo = new Components.Constructor(
     "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init");
 
   Utils.lazy2(this, "DBConnection", function() {
-    try {
-      return Svc.Login.QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.mozIStorageConnection);
-    } catch (ex if (ex.result == Cr.NS_ERROR_NO_INTERFACE)) {
-      // Gecko <2.0 *sadface*
-      return null;
-    }
+    return Svc.Login.QueryInterface(Ci.nsIInterfaceRequestor)
+                    .getInterface(Ci.mozIStorageConnection);
   });
 }
 PasswordStore.prototype = {
   __proto__: Store.prototype,
 
   _nsLoginInfoFromRecord: function PasswordStore__nsLoginInfoRec(record) {
     if (record.formSubmitURL &&
         record.httpRealm) {
--- a/services/sync/modules/engines/prefs.js
+++ b/services/sync/modules/engines/prefs.js
@@ -42,16 +42,17 @@ const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const WEAVE_SYNC_PREFS = "services.sync.prefs.sync.";
 
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/ext/Preferences.js");
+Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
 
 const PREFS_GUID = Utils.encodeBase64url(Svc.AppInfo.ID);
 
 function PrefRec(collection, id) {
   CryptoWrapper.call(this, collection, id);
 }
 PrefRec.prototype = {
   __proto__: CryptoWrapper.prototype,
@@ -133,30 +134,19 @@ PrefStore.prototype = {
         // Missing prefs get the null value.
         values[pref] = this._prefs.get(pref, null);
       }
     }
     return values;
   },
 
   _setAllPrefs: function PrefStore__setAllPrefs(values) {
-    // cache 
-    let ltmExists = true;
-    let ltm = {};
-    let enabledBefore = false;
     let enabledPref = "lightweightThemes.isThemeSelected";
-    let prevTheme = "";
-    try {
-      Cu.import("resource://gre/modules/LightweightThemeManager.jsm", ltm);
-      ltm = ltm.LightweightThemeManager;
-      enabledBefore = this._prefs.get(enabledPref, false);
-      prevTheme = ltm.currentTheme;
-    } catch(ex) {
-      ltmExists = false;
-    } // LightweightThemeManager only exists in Firefox 3.6+
+    let enabledBefore = this._prefs.get(enabledPref, false);
+    let prevTheme = LightweightThemeManager.currentTheme;
 
     for (let [pref, value] in Iterator(values)) {
       if (!this._isSynced(pref))
         continue;
 
       // Pref has gone missing, best we can do is reset it.
       if (value == null) {
         this._prefs.reset(pref);
@@ -166,24 +156,22 @@ PrefStore.prototype = {
       try {
         this._prefs.set(pref, value);
       } catch(ex) {
         this._log.trace("Failed to set pref: " + pref + ": " + ex);
       } 
     }
 
     // Notify the lightweight theme manager of all the new values
-    if (ltmExists) {
-      let enabledNow = this._prefs.get(enabledPref, false);
-      if (enabledBefore && !enabledNow)
-        ltm.currentTheme = null;
-      else if (enabledNow && ltm.usedThemes[0] != prevTheme) {
-        ltm.currentTheme = null;
-        ltm.currentTheme = ltm.usedThemes[0];
-      }
+    let enabledNow = this._prefs.get(enabledPref, false);
+    if (enabledBefore && !enabledNow) {
+      LightweightThemeManager.currentTheme = null;
+    } else if (enabledNow && LightweightThemeManager.usedThemes[0] != prevTheme) {
+      LightweightThemeManager.currentTheme = null;
+      LightweightThemeManager.currentTheme = ltm.usedThemes[0];
     }
   },
 
   getAllIDs: function PrefStore_getAllIDs() {
     /* We store all prefs in just one WBO, with just one GUID */
     let allprefs = {};
     allprefs[PREFS_GUID] = true;
     return allprefs;
--- a/services/sync/modules/util.js
+++ b/services/sync/modules/util.js
@@ -42,25 +42,17 @@ const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/ext/Observers.js");
 Cu.import("resource://services-sync/ext/Preferences.js");
 Cu.import("resource://services-sync/ext/StringBundle.js");
 Cu.import("resource://services-sync/log4moz.js");
-
-let NetUtil;
-try {
-  let ns = {};
-  Cu.import("resource://gre/modules/NetUtil.jsm", ns);
-  NetUtil = ns.NetUtil;
-} catch (ex) {
-  // Firefox 3.5 :(
-}
+Cu.import("resource://gre/modules/NetUtil.jsm");
 
 // Constants for makeSyncCallback, waitForSyncCallback
 const CB_READY = {};
 const CB_COMPLETE = {};
 const CB_FAIL = {};
 
 
 /*
@@ -215,25 +207,16 @@ let Utils = {
       return callback.call(thisObj);
     } finally {
       if (hasTransaction) {
         db.commitTransaction();
       }
     }
   },
 
-  createStatement: function createStatement(db, query) {
-    // Gecko 2.0
-    if (db.createAsyncStatement)
-      return db.createAsyncStatement(query);
-
-    // Gecko <2.0
-    return db.createStatement(query);
-  },
-
   // Prototype for mozIStorageCallback, used in queryAsync below.
   // This allows us to define the handle* functions just once rather
   // than on every queryAsync invocation.
   _storageCallbackPrototype: {
     results: null,
     // These are set by queryAsync
     names: null,
     syncCb: null,
@@ -1064,31 +1047,16 @@ let Utils = {
       that._log.trace("Loading json from disk: " + filePath);
 
     let file = Utils.getProfileFile(filePath);
     if (!file.exists()) {
       callback.call(that);
       return;
     }
 
-    // Gecko < 2.0
-    if (!NetUtil || !NetUtil.newChannel) {
-      let json;
-      try {
-        let [is] = Utils.open(file, "<");
-        json = JSON.parse(Utils.readStream(is));
-        is.close();
-      } catch (ex) {
-        if (that._log)
-          that._log.debug("Failed to load json: " + Utils.exceptionStr(ex));
-      }
-      callback.call(that, json);
-      return;
-    }
-
     let channel = NetUtil.newChannel(file);
     channel.contentType = "application/json";
 
     NetUtil.asyncFetch(channel, function (is, result) {
       if (!Components.isSuccessCode(result)) {
         callback.call(that);
         return;
       }
@@ -1122,31 +1090,20 @@ let Utils = {
     filePath = "weave/" + filePath + ".json";
     if (that._log)
       that._log.trace("Saving json to disk: " + filePath);
 
     let file = Utils.getProfileFile({ autoCreate: true, path: filePath });
     let json = typeof obj == "function" ? obj.call(that) : obj;
     let out = JSON.stringify(json);
 
-    // Firefox 3.5
-    if (!NetUtil) {
-      let [fos] = Utils.open(file, ">");
-      fos.writeString(out);
-      fos.close();
-      if (typeof callback == "function") {
-        callback.call(that);
-      }
-      return;
-    }
-
     let fos = Cc["@mozilla.org/network/safe-file-output-stream;1"]
                 .createInstance(Ci.nsIFileOutputStream);
     fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE,
-             fos.DEFER_OPEN || 0);
+             fos.DEFER_OPEN);
     let is = this._utf8Converter.convertToInputStream(out);
     NetUtil.asyncCopy(is, fos, function (result) {
       if (typeof callback == "function") {
         callback.call(that);        
       }
     });
   },
 
@@ -1185,69 +1142,16 @@ let Utils = {
         timer.clear();
         callback.call(thisObj, timer);
       }
     }, wait, timer.TYPE_ONE_SHOT);
 
     return thisObj[name] = timer;
   },
 
-  // Gecko <2.0
-  open: function open(pathOrFile, mode, perms) {
-    let stream, file;
-
-    if (pathOrFile instanceof Ci.nsIFile) {
-      file = pathOrFile;
-    } else {
-      file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
-      dump("PATH IS" + pathOrFile + "\n");
-      file.initWithPath(pathOrFile);
-    }
-
-    if (!perms)
-      perms = PERMS_FILE;
-
-    switch(mode) {
-    case "<": {
-      if (!file.exists())
-        throw "Cannot open file for reading, file does not exist";
-      let fis = Cc["@mozilla.org/network/file-input-stream;1"].
-        createInstance(Ci.nsIFileInputStream);
-      fis.init(file, MODE_RDONLY, perms, 0);
-      stream = Cc["@mozilla.org/intl/converter-input-stream;1"].
-        createInstance(Ci.nsIConverterInputStream);
-      stream.init(fis, "UTF-8", 4096,
-                  Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
-    } break;
-
-    case ">": {
-      let fos = Cc["@mozilla.org/network/file-output-stream;1"].
-        createInstance(Ci.nsIFileOutputStream);
-      fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, perms, 0);
-      stream = Cc["@mozilla.org/intl/converter-output-stream;1"]
-        .createInstance(Ci.nsIConverterOutputStream);
-      stream.init(fos, "UTF-8", 4096, 0x0000);
-    } break;
-
-    case ">>": {
-      let fos = Cc["@mozilla.org/network/file-output-stream;1"].
-        createInstance(Ci.nsIFileOutputStream);
-      fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_APPEND, perms, 0);
-      stream = Cc["@mozilla.org/intl/converter-output-stream;1"]
-        .createInstance(Ci.nsIConverterOutputStream);
-      stream.init(fos, "UTF-8", 4096, 0x0000);
-    } break;
-
-    default:
-      throw "Illegal mode to open(): " + mode;
-    }
-
-    return [stream, file];
-  },
-
   getIcon: function(iconUri, defaultIcon) {
     try {
       let iconURI = Utils.makeURI(iconUri);
       return Svc.Favicon.getFaviconLinkForIcon(iconURI).spec;
     }
     catch(ex) {}
 
     // Just give the provided default icon or the system's default
@@ -1258,26 +1162,16 @@ let Utils = {
     try {
       return Str.errors.get(error, args || null);
     } catch (e) {}
 
     // basically returns "Unknown Error"
     return Str.errors.get("error.reason.unknown");
   },
 
-  // Gecko <2.0
-  // assumes an nsIConverterInputStream
-  readStream: function Weave_readStream(is) {
-    let ret = "", str = {};
-    while (is.readString(4096, str) != 0) {
-      ret += str.value;
-    }
-    return ret;
-  },
-
   encodeUTF8: function(str) {
     try {
       str = this._utf8Converter.ConvertFromUnicode(str);
       return str + this._utf8Converter.Finish();
     } catch(ex) {
       return null;
     }
   },
@@ -1667,25 +1561,19 @@ this.__defineGetter__("_sessionCID", fun
  ["Version", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
  ["WinMediator", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
  ["WinWatcher", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
  ["Session", this._sessionCID, "nsISessionStore"],
 ].forEach(function(lazy) Utils.lazySvc(Svc, lazy[0], lazy[1], lazy[2]));
 
 Svc.__defineGetter__("Crypto", function() {
   let cryptoSvc;
-  try {
-    let ns = {};
-    Cu.import("resource://services-crypto/WeaveCrypto.js", ns);
-    cryptoSvc = new ns.WeaveCrypto();
-  } catch (ex) {
-    // Fallback to binary WeaveCrypto
-    cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"].
-                getService(Ci.IWeaveCrypto);
-  }
+  let ns = {};
+  Cu.import("resource://services-crypto/WeaveCrypto.js", ns);
+  cryptoSvc = new ns.WeaveCrypto();
   delete Svc.Crypto;
   return Svc.Crypto = cryptoSvc;
 });
 
 let Str = {};
 ["errors", "sync"]
   .forEach(function(lazy) Utils.lazy2(Str, lazy, Utils.lazyStrings(lazy)));
 
deleted file mode 100644
--- a/services/sync/tests/unit/test_utils_file.js
+++ /dev/null
@@ -1,135 +0,0 @@
-_("Test file-related utility functions");
-
-Cu.import("resource://services-sync/util.js");
-Cu.import("resource://services-sync/constants.js");
-
-function run_test() {
-  // Disabled due to Windows failures (bug 599193)
-  //_test_getTmp();
-  //_test_open();
-}
-
-function _test_getTmp() {
-  // as the setup phase remove the tmp directory from the
-  // filesystem
-  let svc = Cc["@mozilla.org/file/directory_service;1"]
-              .getService(Ci.nsIProperties);
-  let tmp = svc.get("ProfD", Ci.nsIFile);
-  tmp.QueryInterface(Ci.nsILocalFile);
-  tmp.append("weave");
-  tmp.append("tmp");
-  if (tmp.exists())
-    tmp.remove(true);
-
-  // call getTmp with no argument. A ref to the tmp
-  // dir is returned
-  _("getTmp with no argument");
-  let tmpDir = Utils.getTmp();
-  do_check_true(tmpDir instanceof Ci.nsILocalFile);
-  do_check_true(tmpDir.isDirectory());
-  do_check_true(tmpDir.exists());
-  do_check_eq(tmpDir.leafName, "tmp");
-
-  // call getTmp with a string. A ref to the file
-  // named with this string and included in the
-  // tmp dir is returned
-  _("getTmp with a string");
-  let tmpFile = Utils.getTmp("name");
-  do_check_true(tmpFile instanceof Ci.nsILocalFile);
-  do_check_true(!tmpFile.exists()); // getTmp doesn't create the file!
-  do_check_eq(tmpFile.leafName, "name");
-  do_check_true(tmpDir.contains(tmpFile, false));
-}
-
-function _test_open() {
-
-  // we rely on Utils.getTmp to get a temporary file and
-  // test Utils.open on that file, that's ok Util.getTmp
-  // is also tested (test_getTmp)
-  function createFile() {
-    let f = Utils.getTmp("_test_");
-    f.create(f.NORMAL_FILE_TYPE, PERMS_FILE);
-    return f;
-  }
-
-  // we should probably test more things here, for example
-  // we should test that we cannot write to a stream that
-  // is created as a result of opening a file for reading
-
-  let s, f;
-
-  _("Open for reading, providing a file");
-  let f1 = createFile();
-  [s, f] = Utils.open(f1, "<");
-  do_check_eq(f.path, f1.path);
-  do_check_true(s instanceof Ci.nsIConverterInputStream);
-  f1.remove(false);
-
-  _("Open for reading, providing a file name");
-  let f2 = createFile();
-  let path2 = f2.path;
-  [s, f] = Utils.open(path2, "<");
-  do_check_eq(f.path, path2);
-  do_check_true(s instanceof Ci.nsIConverterInputStream);
-  f2.remove(false);
-
-  _("Open for writing with truncate mode, providing a file");
-  let f3 = createFile();
-  [s, f] = Utils.open(f3, ">");
-  do_check_eq(f.path, f3.path);
-  do_check_true(s instanceof Ci.nsIConverterOutputStream);
-  f3.remove(false);
-
-  _("Open for writing with truncate mode, providing a file name");
-  let f4 = createFile();
-  let path4 = f4.path;
-  [s, f] = Utils.open(path4, ">");
-  do_check_eq(f.path, path4);
-  do_check_true(s instanceof Ci.nsIConverterOutputStream);
-  f4.remove(false);
-
-  _("Open for writing with append mode, providing a file");
-  let f5 = createFile();
-  [s, f] = Utils.open(f5, ">>");
-  do_check_eq(f.path, f5.path);
-  do_check_true(s instanceof Ci.nsIConverterOutputStream);
-  f5.remove(false);
-
-  _("Open for writing with append mode, providing a file name");
-  let f6 = createFile();
-  let path6 = f6.path;
-  [s, f] = Utils.open(path6, ">>");
-  do_check_eq(f.path, path6);
-  do_check_true(s instanceof Ci.nsIConverterOutputStream);
-  f6.remove(false);
-
-  _("Open with illegal mode");
-  let f7 = createFile();
-  let except7;
-  try {
-    Utils.open(f7, "?!");
-  } catch(e) {
-    except7 = e;
-  }
-  do_check_true(!!except7);
-  f7.remove(false);
-
-  _("Open non-existing file for reading");
-  let f8 = createFile();
-  let path8 = f8.path;
-  f8.remove(false);
-  let except8;
-  try {
-    Utils.open(path8, "<");
-  } catch(e) {
-    except8 = e;
-  }
-  do_check_true(!!except8);
-
-  _("Open for reading, provide permissions");
-  let f9 = createFile();
-  [s, f] = Utils.open(f9, "<", 0644);
-  do_check_eq(f.path, f9.path);
-  do_check_true(s instanceof Ci.nsIConverterInputStream);
-  f9.remove(false);
-}
--- a/services/sync/tests/unit/test_utils_json.js
+++ b/services/sync/tests/unit/test_utils_json.js
@@ -1,10 +1,11 @@
 _("Make sure json saves and loads from disk");
 Cu.import("resource://services-sync/util.js");
+Cu.import("resource://services-sync/constants.js");
 
 function run_test() {
   do_test_pending();
   Utils.asyncChain(function (next) {
 
     _("Do a simple write of an array to json and read");
     Utils.jsonSave("foo", {}, ["v1", "v2"], ensureThrows(function() {
       Utils.jsonLoad("foo", {}, ensureThrows(function(val) {
@@ -63,19 +64,25 @@ function run_test() {
 
   }, function (next) {
 
     _("Verify that reads and read errors are logged.");
 
     // Write a file with some invalid JSON
     let file = Utils.getProfileFile({ autoCreate: true,
                                       path: "weave/log.json" });
-    let [fos] = Utils.open(file, ">");
-    fos.writeString("invalid json!");
-    fos.close();
+    let fos = Cc["@mozilla.org/network/file-output-stream;1"]
+                .createInstance(Ci.nsIFileOutputStream);
+    fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE,
+             fos.DEFER_OPEN);
+    let stream = Cc["@mozilla.org/intl/converter-output-stream;1"]
+                   .createInstance(Ci.nsIConverterOutputStream);
+    stream.init(fos, "UTF-8", 4096, 0x0000);
+    stream.writeString("invalid json!");
+    stream.close();
 
     let trace, debug;
     Utils.jsonLoad("log",
                    {_log: {trace: function(msg) { trace = msg; },
                            debug: function(msg) { debug = msg; }}},
                    ensureThrows(function(val) {
       do_check_true(!!trace);
       do_check_true(!!debug);