From 32cd47583c51b9b5e633dd77971d11ef508160de Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Thu, 7 Apr 2011 15:31:11 -0700 Subject: [PATCH] Bug 648338 - Remove remaining Firefox 3.5/3.6 compat code. r=rnewman --- services/sync/modules/engines/passwords.js | 9 +- services/sync/modules/engines/prefs.js | 30 ++--- services/sync/modules/util.js | 122 +----------------- services/sync/tests/unit/test_utils_file.js | 135 -------------------- services/sync/tests/unit/test_utils_json.js | 13 +- 5 files changed, 26 insertions(+), 283 deletions(-) delete mode 100644 services/sync/tests/unit/test_utils_file.js diff --git a/services/sync/modules/engines/passwords.js b/services/sync/modules/engines/passwords.js index 2b1aee3d482c..7b9b0d07299a 100644 --- a/services/sync/modules/engines/passwords.js +++ b/services/sync/modules/engines/passwords.js @@ -114,13 +114,8 @@ function PasswordStore(name) { "@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 = { diff --git a/services/sync/modules/engines/prefs.js b/services/sync/modules/engines/prefs.js index 4a7047654612..82286bdb1484 100644 --- a/services/sync/modules/engines/prefs.js +++ b/services/sync/modules/engines/prefs.js @@ -47,6 +47,7 @@ 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); @@ -138,20 +139,9 @@ PrefStore.prototype = { }, _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)) @@ -171,14 +161,12 @@ PrefStore.prototype = { } // 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]; } }, diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 4c2fedbc6e97..505951a1d3ed 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -47,15 +47,7 @@ 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 = {}; @@ -220,15 +212,6 @@ let Utils = { } }, - 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. @@ -1069,21 +1052,6 @@ let Utils = { 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"; @@ -1127,21 +1095,10 @@ let Utils = { 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") { @@ -1190,59 +1147,6 @@ let Utils = { 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); @@ -1263,16 +1167,6 @@ let Utils = { 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); @@ -1672,15 +1566,9 @@ this.__defineGetter__("_sessionCID", function() { 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; }); diff --git a/services/sync/tests/unit/test_utils_file.js b/services/sync/tests/unit/test_utils_file.js deleted file mode 100644 index dbfdbea834c0..000000000000 --- 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); -} diff --git a/services/sync/tests/unit/test_utils_json.js b/services/sync/tests/unit/test_utils_json.js index a9427ae8aa54..dd890d0db097 100644 --- a/services/sync/tests/unit/test_utils_json.js +++ b/services/sync/tests/unit/test_utils_json.js @@ -1,5 +1,6 @@ _("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(); @@ -68,9 +69,15 @@ function run_test() { // 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",