OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 #else | 1044 #else |
1045 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_LINUX", | 1045 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_LINUX", |
1046 #endif | 1046 #endif |
1047 &ui_strings.disconnect_button_text_plus_shortcut); | 1047 &ui_strings.disconnect_button_text_plus_shortcut); |
1048 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_PROMPT", | 1048 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_PROMPT", |
1049 &ui_strings.continue_prompt); | 1049 &ui_strings.continue_prompt); |
1050 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_BUTTON", | 1050 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_BUTTON", |
1051 &ui_strings.continue_button_text); | 1051 &ui_strings.continue_button_text); |
1052 LocalizeString(localize_func, /*i18n-content*/"STOP_SHARING_BUTTON", | 1052 LocalizeString(localize_func, /*i18n-content*/"STOP_SHARING_BUTTON", |
1053 &ui_strings.stop_sharing_button_text); | 1053 &ui_strings.stop_sharing_button_text); |
1054 LocalizeString(localize_func, /*i18n-content*/"MESSAGE_SHARED", | 1054 const char* substitutions[] = { "$1" }; |
1055 &ui_strings.disconnect_message); | 1055 LocalizeStringWithSubstitutions(localize_func, |
1056 /*i18n-content*/"MESSAGE_SHARED", | |
1057 substitutions, arraysize(substitutions), | |
1058 &ui_strings.disconnect_message); | |
1056 | 1059 |
1057 base::AutoLock auto_lock(ui_strings_lock_); | 1060 base::AutoLock auto_lock(ui_strings_lock_); |
1058 ui_strings_ = ui_strings; | 1061 ui_strings_ = ui_strings; |
1059 } | 1062 } |
1060 | 1063 |
1061 bool HostNPScriptObject::LocalizeString(NPObject* localize_func, | 1064 bool HostNPScriptObject::LocalizeString(NPObject* localize_func, |
1062 const char* tag, string16* result) { | 1065 const char* tag, string16* result) { |
1063 NPVariant args[2]; | 1066 return LocalizeStringWithSubstitutions(localize_func, tag, NULL, 0, result); |
1067 } | |
1068 | |
1069 bool HostNPScriptObject::LocalizeStringWithSubstitutions( | |
1070 NPObject* localize_func, const char* tag, const char** substitutions, | |
1071 int number_of_substitutions, string16* result) { | |
1072 scoped_array<NPVariant> args(new NPVariant[number_of_substitutions + 1]); | |
1064 STRINGZ_TO_NPVARIANT(tag, args[0]); | 1073 STRINGZ_TO_NPVARIANT(tag, args[0]); |
1074 for (int i = 0; i < number_of_substitutions; ++i) { | |
1075 STRINGZ_TO_NPVARIANT(substitutions[i], args[i + 1]); | |
1076 } | |
1065 NPVariant np_result; | 1077 NPVariant np_result; |
1066 bool is_good = g_npnetscape_funcs->invokeDefault( | 1078 bool is_good = g_npnetscape_funcs->invokeDefault( |
1067 plugin_, localize_func, &args[0], 1, &np_result); | 1079 plugin_, localize_func, args.get(), number_of_substitutions + 1, |
Sergey Ulanov
2012/06/28 01:11:24
Actually chrome.i18n.getMessage() takes only two p
Jamie
2012/06/28 23:02:41
So it does--good catch! Passing arrays over NPAPI
| |
1080 &np_result); | |
1068 if (!is_good) { | 1081 if (!is_good) { |
1069 LOG(ERROR) << "Localization failed for " << tag; | 1082 LOG(ERROR) << "Localization failed for " << tag; |
1070 return false; | 1083 return false; |
1071 } | 1084 } |
1072 std::string translation = StringFromNPVariant(np_result); | 1085 std::string translation = StringFromNPVariant(np_result); |
1073 g_npnetscape_funcs->releasevariantvalue(&np_result); | 1086 g_npnetscape_funcs->releasevariantvalue(&np_result); |
1074 if (translation.empty()) { | 1087 if (translation.empty()) { |
1075 LOG(ERROR) << "Missing translation for " << tag; | 1088 LOG(ERROR) << "Missing translation for " << tag; |
1076 return false; | 1089 return false; |
1077 } | 1090 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 return is_good; | 1239 return is_good; |
1227 } | 1240 } |
1228 | 1241 |
1229 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1242 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1230 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1243 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
1231 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1244 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1232 LOG(INFO) << exception_string; | 1245 LOG(INFO) << exception_string; |
1233 } | 1246 } |
1234 | 1247 |
1235 } // namespace remoting | 1248 } // namespace remoting |
OLD | NEW |