Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Unified Diff: remoting/host/plugin/host_script_object.cc

Issue 7635012: Host process i18n and Linux implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change UIStrings to UiStrings. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/plugin/host_script_object.cc
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 2ba2c468dda1327ce00b3802c8d244df4d71afd5..7eb197c4bd960c9fd171517d46002ab654d0cd40 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -15,9 +15,9 @@
#include "remoting/host/host_config.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/in_memory_host_config.h"
-#include "remoting/host/plugin/host_plugin_utils.h"
#include "remoting/host/register_support_host_request.h"
#include "remoting/host/support_access_verifier.h"
+#include "remoting/host/ui_strings.h"
namespace remoting {
@@ -38,6 +38,7 @@ namespace remoting {
//
// attribute Function void logDebugInfo(string);
// attribute Function void onStateChanged();
+// attribute Function string localize(string,...);
//
// // The |auth_service_with_token| parameter should be in the format
// // "auth_service:auth_token". An example would be "oauth2:1/2a3912vd".
@@ -50,6 +51,7 @@ const char* kAttrNameAccessCode = "accessCode";
const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime";
const char* kAttrNameClient = "client";
const char* kAttrNameState = "state";
+const char* kAttrNameLocalize = "localize";
const char* kAttrNameLogDebugInfo = "logDebugInfo";
const char* kAttrNameOnStateChanged = "onStateChanged";
const char* kFuncNameConnect = "connect";
@@ -78,8 +80,6 @@ HostNPScriptObject::HostNPScriptObject(NPP plugin, NPObject* parent)
: plugin_(plugin),
parent_(parent),
state_(kDisconnected),
- log_debug_info_func_(NULL),
- on_state_changed_func_(NULL),
np_thread_id_(base::PlatformThread::CurrentId()),
failed_login_attempts_(0),
disconnected_event_(true, false) {
@@ -123,13 +123,6 @@ HostNPScriptObject::~HostNPScriptObject() {
// Stop all threads.
host_context_.Stop();
-
- if (log_debug_info_func_) {
- g_npnetscape_funcs->releaseobject(log_debug_info_func_);
- }
- if (on_state_changed_func_) {
- g_npnetscape_funcs->releaseobject(on_state_changed_func_);
- }
}
bool HostNPScriptObject::Init() {
@@ -178,6 +171,7 @@ bool HostNPScriptObject::HasProperty(const std::string& property_name) {
property_name == kAttrNameAccessCodeLifetime ||
property_name == kAttrNameClient ||
property_name == kAttrNameState ||
+ property_name == kAttrNameLocalize ||
property_name == kAttrNameLogDebugInfo ||
property_name == kAttrNameOnStateChanged ||
property_name == kAttrNameDisconnected ||
@@ -198,10 +192,13 @@ bool HostNPScriptObject::GetProperty(const std::string& property_name,
}
if (property_name == kAttrNameOnStateChanged) {
- OBJECT_TO_NPVARIANT(on_state_changed_func_, *result);
+ OBJECT_TO_NPVARIANT(on_state_changed_func_.get(), *result);
+ return true;
+ } else if (property_name == kAttrNameLocalize) {
+ OBJECT_TO_NPVARIANT(localize_func_.get(), *result);
return true;
} else if (property_name == kAttrNameLogDebugInfo) {
- OBJECT_TO_NPVARIANT(log_debug_info_func_, *result);
+ OBJECT_TO_NPVARIANT(log_debug_info_func_.get(), *result);
return true;
} else if (property_name == kAttrNameState) {
INT32_TO_NPVARIANT(state_, *result);
@@ -246,13 +243,18 @@ bool HostNPScriptObject::SetProperty(const std::string& property_name,
if (property_name == kAttrNameOnStateChanged) {
if (NPVARIANT_IS_OBJECT(*value)) {
- if (on_state_changed_func_) {
- g_npnetscape_funcs->releaseobject(on_state_changed_func_);
- }
- on_state_changed_func_ = NPVARIANT_TO_OBJECT(*value);
- if (on_state_changed_func_) {
- g_npnetscape_funcs->retainobject(on_state_changed_func_);
- }
+ on_state_changed_func_.replace(NPVARIANT_TO_OBJECT(*value));
+ return true;
+ } else {
+ SetException("SetProperty: unexpected type for property " +
+ property_name);
+ }
+ return false;
+ }
+
+ if (property_name == kAttrNameLocalize) {
+ if (NPVARIANT_IS_OBJECT(*value)) {
+ localize_func_.replace(NPVARIANT_TO_OBJECT(*value));
return true;
} else {
SetException("SetProperty: unexpected type for property " +
@@ -263,13 +265,7 @@ bool HostNPScriptObject::SetProperty(const std::string& property_name,
if (property_name == kAttrNameLogDebugInfo) {
if (NPVARIANT_IS_OBJECT(*value)) {
- if (log_debug_info_func_) {
- g_npnetscape_funcs->releaseobject(log_debug_info_func_);
- }
- log_debug_info_func_ = NPVARIANT_TO_OBJECT(*value);
- if (log_debug_info_func_) {
- g_npnetscape_funcs->retainobject(log_debug_info_func_);
- }
+ log_debug_info_func_.replace(NPVARIANT_TO_OBJECT(*value));
return true;
} else {
SetException("SetProperty: unexpected type for property " +
@@ -293,6 +289,7 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) {
const char* entries[] = {
kAttrNameAccessCode,
kAttrNameState,
+ kAttrNameLocalize,
kAttrNameLogDebugInfo,
kAttrNameOnStateChanged,
kFuncNameConnect,
@@ -333,6 +330,28 @@ void HostNPScriptObject::OnClientAuthenticated(
if (pos != std::string::npos)
client_username_.replace(pos, std::string::npos, "");
LOG(INFO) << "Client " << client_username_ << " connected.";
+ UiStrings* ui_strings = host_->ui_strings();
+ std::string direction;
+ Localize("@@bidi_dir", NULL, &direction);
+ ui_strings->direction =
+ direction == "rtl" ? remoting::UiStrings::RTL
+ : remoting::UiStrings::LTR;
+ Localize("productName", NULL, &ui_strings->productName);
+ Localize("disconnectButton", NULL, &ui_strings->disconnectButtonText);
+ Localize(
+#if defined(OS_WIN)
+ "disconnectButtonShortcutWindows",
+#elif defined(OS_MAC)
+ "disconnectButtonShortcutMacOSX",
+#else
+ "disconnectButtonShortcutLinux",
+#endif
+ NULL, &ui_strings->disconnectButtonShortcut);
+ Localize("continuePrompt", NULL, &ui_strings->continuePrompt);
+ Localize("continueButton", NULL, &ui_strings->continueButtonText);
+ Localize("stopSharingButton", NULL, &ui_strings->stopSharingButtonText);
+ Localize("messageShared", client_username_.c_str(),
+ &ui_strings->disconnectMessage);
OnStateChanged(kConnected);
}
@@ -523,9 +542,9 @@ void HostNPScriptObject::OnStateChanged(State state) {
return;
}
state_ = state;
- if (on_state_changed_func_) {
+ if (on_state_changed_func_.get()) {
VLOG(2) << "Calling state changed " << state;
- bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0);
+ bool is_good = InvokeAndIgnoreResult(on_state_changed_func_.get(), NULL, 0);
LOG_IF(ERROR, !is_good) << "OnStateChanged failed";
}
}
@@ -561,10 +580,10 @@ void HostNPScriptObject::LogDebugInfo(const std::string& message) {
return;
}
- if (log_debug_info_func_) {
+ if (log_debug_info_func_.get()) {
NPVariant log_message;
STRINGZ_TO_NPVARIANT(message.c_str(), log_message);
- bool is_good = InvokeAndIgnoreResult(log_debug_info_func_,
+ bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(),
&log_message, 1);
LOG_IF(ERROR, !is_good) << "LogDebugInfo failed";
}
@@ -576,6 +595,30 @@ void HostNPScriptObject::SetException(const std::string& exception_string) {
LOG(INFO) << exception_string;
}
+bool HostNPScriptObject::Localize(const char* tag, const char* parameter,
+ std::string* result) {
+ NPVariant args[2];
+ STRINGZ_TO_NPVARIANT(tag, args[0]);
+ if (parameter) {
+ STRINGZ_TO_NPVARIANT(parameter, args[1]);
+ }
+ NPVariant np_result;
+ bool is_good = g_npnetscape_funcs->invokeDefault(
+ plugin_, localize_func_.get(), &args[0], parameter ? 2 : 1, &np_result);
+ if (!is_good) {
+ LOG(ERROR) << "Localization failed for " << tag;
+ return false;
+ }
+ std::string translation = StringFromNPVariant(np_result);
+ g_npnetscape_funcs->releasevariantvalue(&np_result);
+ if (translation.empty()) {
+ LOG(ERROR) << "Missing translation for " << tag;
+ return false;
+ }
+ *result = translation;
+ return true;
+}
+
bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
const NPVariant* args,
uint32_t argCount) {

Powered by Google App Engine
This is Rietveld 408576698