Bug 1335877 - Remove resource://services-common/stringbundle.js from gecko. r=gandalf

MozReview-Commit-ID: FNoj7XH71E4

--HG--
extra : rebase_source : 294d3e425ca60e2aac6149998da7f39f62864ae5
This commit is contained in:
Zibi Braniecki 2017-03-06 09:39:52 -08:00
Родитель 53cf8e265c
Коммит 100766fec4
11 изменённых файлов: 37 добавлений и 250 удалений

Просмотреть файл

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
if (AppConstants.MOZ_SERVICES_CLOUDSYNC) {
XPCOMUtils.defineLazyModuleGetter(this, "CloudSync",
@ -40,8 +41,6 @@ var gSyncUI = {
_syncAnimationTimer: 0,
init() {
Cu.import("resource://services-common/stringbundle.js");
// Proceed to set up the UI if Sync has already started up.
// Otherwise we'll do it when Sync is firing up.
if (this.weaveService.ready) {
@ -224,8 +223,9 @@ var gSyncUI = {
},
_getAppName() {
let brand = new StringBundle("chrome://branding/locale/brand.properties");
return brand.get("brandShortName");
let brand = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
return brand.GetStringFromName("brandShortName");
},
// Commands
@ -475,9 +475,8 @@ var gSyncUI = {
XPCOMUtils.defineLazyGetter(gSyncUI, "_stringBundle", function() {
// XXXzpao these strings should probably be moved from /services to /browser... (bug 583381)
// but for now just make it work
return Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle("chrome://weave/locale/services/sync.properties");
return Services.strings.createBundle(
"chrome://weave/locale/services/sync.properties");
});
XPCOMUtils.defineLazyGetter(gSyncUI, "log", function() {

Просмотреть файл

@ -192,9 +192,11 @@ add_task(function* checkAllTheProperties() {
ok(uris.length, `Found ${uris.length} .properties files to scan for misused characters`);
for (let uri of uris) {
let bundle = new StringBundle(uri.spec);
let entities = bundle.getAll();
for (let entity of entities) {
let bundle = Services.strings.createBundle(uri.spec);
let enumerator = bundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
let entity = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
testForErrors(uri.spec, entity.key, entity.value);
}
}

Просмотреть файл

@ -11,14 +11,14 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://services-common/stringbundle.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://services-common/utils.js");
Cu.import("resource://services-crypto/utils.js");
Cu.import("resource://gre/modules/Preferences.jsm");
function lazyStrings(name) {
let bundle = "chrome://weave/locale/services/" + name + ".properties";
return () => new StringBundle(bundle);
return () => Services.strings.createBundle(
`chrome://weave/locale/services//${name}.properties`);
}
this.Str = {};
@ -58,12 +58,13 @@ Local.prototype = {
.getService(Ci.nsIEnvironment);
let user = env.get("USER") || env.get("USERNAME");
let appName;
let brand = new StringBundle("chrome://branding/locale/brand.properties");
let brandName = brand.get("brandShortName");
let brand = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
let brandName = brand.GetStringFromName("brandShortName");
try {
let syncStrings = new StringBundle("chrome://browser/locale/sync.properties");
appName = syncStrings.getFormattedString("sync.defaultAccountApplication", [brandName]);
let syncStrings = Services.strings.createBundle("chrome://browser/locale/sync.properties");
appName = syncStrings.formatStringFromName("sync.defaultAccountApplication", [brandName], 1);
} catch (ex) {
}
@ -77,7 +78,7 @@ Local.prototype = {
// fall back on ua info string
Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).oscpu;
return this.name = Str.sync.get("client.name2", [user, appName, system]);
return this.name = Str.sync.formatStringFromName("client.name2", [user, appName, system], 3);
},
set name(value) {

Просмотреть файл

@ -23,7 +23,6 @@ EXTRA_JS_MODULES['services-common'] += [
'logmanager.js',
'observers.js',
'rest.js',
'stringbundle.js',
'utils.js',
]

Просмотреть файл

@ -1,201 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
this.EXPORTED_SYMBOLS = ["StringBundle"];
var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
/**
* A string bundle.
*
* This object presents two APIs: a deprecated one that is equivalent to the API
* for the stringbundle XBL binding, to make it easy to switch from that binding
* to this module, and a new one that is simpler and easier to use.
*
* The benefit of this module over the XBL binding is that it can also be used
* in JavaScript modules and components, not only in chrome JS.
*
* To use this module, import it, create a new instance of StringBundle,
* and then use the instance's |get| and |getAll| methods to retrieve strings
* (you can get both plain and formatted strings with |get|):
*
* let strings =
* new StringBundle("chrome://example/locale/strings.properties");
* let foo = strings.get("foo");
* let barFormatted = strings.get("bar", [arg1, arg2]);
* for (let string of strings.getAll())
* dump (string.key + " = " + string.value + "\n");
*
* @param url {String}
* the URL of the string bundle
*/
this.StringBundle = function StringBundle(url) {
this.url = url;
}
StringBundle.prototype = {
/**
* the locale associated with the application
* @type nsILocale
* @private
*/
get _appLocale() {
try {
return Cc["@mozilla.org/intl/nslocaleservice;1"].
getService(Ci.nsILocaleService).
getApplicationLocale();
} catch (ex) {
return null;
}
},
/**
* the wrapped nsIStringBundle
* @type nsIStringBundle
* @private
*/
get _stringBundle() {
let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle(this.url, this._appLocale);
this.__defineGetter__("_stringBundle", () => stringBundle);
return this._stringBundle;
},
// the new API
/**
* the URL of the string bundle
* @type String
*/
_url: null,
get url() {
return this._url;
},
set url(newVal) {
this._url = newVal;
delete this._stringBundle;
},
/**
* Get a string from the bundle.
*
* @param key {String}
* the identifier of the string to get
* @param args {array} [optional]
* an array of arguments that replace occurrences of %S in the string
*
* @returns {String} the value of the string
*/
get(key, args) {
if (args)
return this.stringBundle.formatStringFromName(key, args, args.length);
return this.stringBundle.GetStringFromName(key);
},
/**
* Get all the strings in the bundle.
*
* @returns {Array}
* an array of objects with key and value properties
*/
getAll() {
let strings = [];
// FIXME: for performance, return an enumerable array that wraps the string
// bundle's nsISimpleEnumerator (does JavaScript already support this?).
let enumerator = this.stringBundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
// We could simply return the nsIPropertyElement objects, but I think
// it's better to return standard JS objects that behave as consumers
// expect JS objects to behave (f.e. you can modify them dynamically).
let string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
strings.push({ key: string.key, value: string.value });
}
return strings;
},
// the deprecated XBL binding-compatible API
/**
* the URL of the string bundle
* @deprecated because its name doesn't make sense outside of an XBL binding
* @type String
*/
get src() {
return this.url;
},
set src(newVal) {
this.url = newVal;
},
/**
* the locale associated with the application
* @deprecated because it has never been used outside the XBL binding itself,
* and consumers should obtain it directly from the locale service anyway.
* @type nsILocale
*/
get appLocale() {
return this._appLocale;
},
/**
* the wrapped nsIStringBundle
* @deprecated because this module should provide all necessary functionality
* @type nsIStringBundle
*
* If you do ever need to use this, let the authors of this module know why
* so they can surface functionality for your use case in the module itself
* and you don't have to access this underlying XPCOM component.
*/
get stringBundle() {
return this._stringBundle;
},
/**
* Get a string from the bundle.
* @deprecated use |get| instead
*
* @param key {String}
* the identifier of the string to get
*
* @returns {String}
* the value of the string
*/
getString(key) {
return this.get(key);
},
/**
* Get a formatted string from the bundle.
* @deprecated use |get| instead
*
* @param key {string}
* the identifier of the string to get
* @param args {array}
* an array of arguments that replace occurrences of %S in the string
*
* @returns {String}
* the formatted value of the string
*/
getFormattedString(key, args) {
return this.get(key, args);
},
/**
* Get an enumeration of the strings in the bundle.
* @deprecated use |getAll| instead
*
* @returns {nsISimpleEnumerator}
* a enumeration of the strings in the bundle
*/
get strings() {
return this.stringBundle.getSimpleEnumeration();
}
}

Просмотреть файл

@ -8,7 +8,6 @@ const shared_modules = [
"async.js",
"logmanager.js",
"rest.js",
"stringbundle.js",
"utils.js",
];

Просмотреть файл

@ -28,7 +28,6 @@ this.EXPORTED_SYMBOLS = [
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://services-common/async.js");
Cu.import("resource://services-common/stringbundle.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/record.js");
@ -174,8 +173,9 @@ ClientEngine.prototype = {
},
get brandName() {
let brand = new StringBundle("chrome://branding/locale/brand.properties");
return brand.get("brandShortName");
let brand = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
return brand.GetStringFromName("brandShortName");
},
get localName() {

Просмотреть файл

@ -8,7 +8,6 @@ var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/observers.js");
Cu.import("resource://services-common/stringbundle.js");
Cu.import("resource://services-common/utils.js");
Cu.import("resource://services-common/async.js", this);
Cu.import("resource://services-crypto/utils.js");
@ -218,8 +217,8 @@ this.Utils = {
},
lazyStrings: function Weave_lazyStrings(name) {
let bundle = "chrome://weave/locale/services/" + name + ".properties";
return () => new StringBundle(bundle);
return () => Services.strings.createBundle(
`chrome://weave/locale/services/${name}.properties`);
},
deepEquals: function eq(a, b) {
@ -461,11 +460,15 @@ this.Utils = {
getErrorString: function Utils_getErrorString(error, args) {
try {
return Str.errors.get(error, args || null);
if (args) {
return Str.errors.formatStringFromName(error, args, args.length);
} else {
return Str.errors.GetStringFromName(error);
}
} catch (e) {}
// basically returns "Unknown Error"
return Str.errors.get("error.reason.unknown");
return Str.errors.GetStringFromName('error.reason.unknown');
},
/**
@ -683,13 +686,14 @@ this.Utils = {
user = env.get("USERNAME");
}
let brand = new StringBundle("chrome://branding/locale/brand.properties");
let brandName = brand.get("brandShortName");
let brand = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
let brandName = brand.GetStringFromName("brandShortName");
let appName;
try {
let syncStrings = new StringBundle("chrome://browser/locale/sync.properties");
appName = syncStrings.getFormattedString("sync.defaultAccountApplication", [brandName]);
let syncStrings = Services.strings.createBundle("chrome://browser/locale/sync.properties");
appName = syncStrings.formatStringFromName("sync.defaultAccountApplication", [brandName], 1);
} catch (ex) {}
appName = appName || brandName;
@ -701,7 +705,7 @@ this.Utils = {
// fall back on ua info string
Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).oscpu;
return Str.sync.get("client.name2", [user, appName, system]);
return Str.sync.formatStringFromName("client.name2", [user, appName, system], 3);
},
getDeviceName() {

Просмотреть файл

@ -1,14 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-common/stringbundle.js");
Cu.import("resource://services-sync/util.js");
function run_test() {
let fn = Utils.lazyStrings("sync");
do_check_eq(typeof fn, "function");
let bundle = fn();
do_check_true(bundle instanceof StringBundle);
let url = bundle.url;
do_check_eq(url, "chrome://weave/locale/services/sync.properties");
}

Просмотреть файл

@ -30,7 +30,6 @@ support-files =
[test_utils_keyEncoding.js]
[test_utils_getErrorString.js]
[test_utils_json.js]
[test_utils_lazyStrings.js]
[test_utils_lock.js]
[test_utils_makeGUID.js]
[test_utils_notify.js]

Просмотреть файл

@ -205,7 +205,6 @@
"StateMachineHelper.jsm": ["State", "CommandType"],
"status.js": ["Status"],
"storageserver.js": ["ServerBSO", "StorageServerCallback", "StorageServerCollection", "StorageServer", "storageServerForUsers"],
"stringbundle.js": ["StringBundle"],
"strings.js": ["trim", "vslice"],
"StructuredLog.jsm": ["StructuredLogger", "StructuredFormatter"],
"StyleEditorUtil.jsm": ["getString", "assert", "log", "text", "wire", "showFilePicker"],