Move responsibility for l10n parameters to the caller.

BUG=132370
TEST=No behavioural change expected.


Review URL: https://chromiumcodereview.appspot.com/10661058

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148005 0039d316-1c4b-4281-b951-d872f2087c98
parent d1f87803
......@@ -1051,8 +1051,9 @@ void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) {
&ui_strings.continue_button_text);
LocalizeString(localize_func, /*i18n-content*/"STOP_SHARING_BUTTON",
&ui_strings.stop_sharing_button_text);
LocalizeString(localize_func, /*i18n-content*/"MESSAGE_SHARED",
&ui_strings.disconnect_message);
LocalizeStringWithSubstitution(localize_func,
/*i18n-content*/"MESSAGE_SHARED", "$1",
&ui_strings.disconnect_message);
base::AutoLock auto_lock(ui_strings_lock_);
ui_strings_ = ui_strings;
......@@ -1060,11 +1061,23 @@ void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) {
bool HostNPScriptObject::LocalizeString(NPObject* localize_func,
const char* tag, string16* result) {
NPVariant args[2];
return LocalizeStringWithSubstitution(localize_func, tag, NULL, result);
}
bool HostNPScriptObject::LocalizeStringWithSubstitution(
NPObject* localize_func,
const char* tag,
const char* substitution,
string16* result) {
int argc = substitution ? 2 : 1;
scoped_array<NPVariant> args(new NPVariant[argc]);
STRINGZ_TO_NPVARIANT(tag, args[0]);
if (substitution) {
STRINGZ_TO_NPVARIANT(substitution, args[1]);
}
NPVariant np_result;
bool is_good = g_npnetscape_funcs->invokeDefault(
plugin_, localize_func, &args[0], 1, &np_result);
plugin_, localize_func, args.get(), argc, &np_result);
if (!is_good) {
LOG(ERROR) << "Localization failed for " << tag;
return false;
......
......@@ -214,12 +214,21 @@ class HostNPScriptObject : public HostStatusObserver {
void LocalizeStrings(NPObject* localize_func);
// Helper function for executing InvokeDefault on an NPObject that performs
// a string->string mapping with one optional substitution parameter. Stores
// the translation in |result| and returns true on success, or leaves it
// unchanged and returns false on failure.
// a string->string mapping without substitution. Stores the translation in
// |result| and returns true on success, or leaves it unchanged and returns
// false on failure.
bool LocalizeString(NPObject* localize_func, const char* tag,
string16* result);
// Helper function for executing InvokeDefault on an NPObject that performs
// a string->string mapping with one substitution. Stores the translation in
// |result| and returns true on success, or leaves it unchanged and returns
// false on failure.
bool LocalizeStringWithSubstitution(NPObject* localize_func,
const char* tag,
const char* substitution,
string16* result);
// If the web-app has registered a callback to be notified of changes to the
// NAT traversal policy, notify it.
void UpdateWebappNatPolicy(bool nat_traversal_enabled);
......
......@@ -72,16 +72,7 @@ remoting.HostSession.prototype.createPluginAndConnect =
this.plugin.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged;
this.plugin.onStateChanged = onStateChanged;
this.plugin.logDebugInfo = logDebugInfo;
this.plugin.localize(
/** @param {string} id */
function(id) {
// Plugin takes care of string substitution, so we just keep
// $ placeholders.
// TODO(sergeyu): Refactor plugin location so that it
// doesn't need to do any substitutions. crbug.com/132370 .
return chrome.i18n.getMessage(id, ["$1", "$2", "$3"]);
}
);
this.plugin.localize(chrome.i18n.getMessage);
this.plugin.connect(email, 'oauth2:' + accessToken);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment