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

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 21059003: Localized Chromoting Host on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "remoting/base/auth_token_util.h" 19 #include "remoting/base/auth_token_util.h"
20 #include "remoting/base/auto_thread.h" 20 #include "remoting/base/auto_thread.h"
21 #include "remoting/base/resources.h"
21 #include "remoting/base/rsa_key_pair.h" 22 #include "remoting/base/rsa_key_pair.h"
22 #include "remoting/host/chromoting_host.h" 23 #include "remoting/host/chromoting_host.h"
23 #include "remoting/host/chromoting_host_context.h" 24 #include "remoting/host/chromoting_host_context.h"
24 #include "remoting/host/host_config.h" 25 #include "remoting/host/host_config.h"
25 #include "remoting/host/host_event_logger.h" 26 #include "remoting/host/host_event_logger.h"
26 #include "remoting/host/host_secret.h" 27 #include "remoting/host/host_secret.h"
27 #include "remoting/host/host_status_observer.h" 28 #include "remoting/host/host_status_observer.h"
28 #include "remoting/host/it2me_desktop_environment.h" 29 #include "remoting/host/it2me_desktop_environment.h"
29 #include "remoting/host/pairing_registry_delegate.h" 30 #include "remoting/host/pairing_registry_delegate.h"
30 #include "remoting/host/pin_hash.h" 31 #include "remoting/host/pin_hash.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, 98 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner,
98 base::WeakPtr<HostNPScriptObject> script_object, 99 base::WeakPtr<HostNPScriptObject> script_object,
99 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 100 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
100 const std::string& directory_bot_jid); 101 const std::string& directory_bot_jid);
101 102
102 // Methods called by the script object, from the plugin thread. 103 // Methods called by the script object, from the plugin thread.
103 104
104 // Creates It2Me host structures and starts the host. 105 // Creates It2Me host structures and starts the host.
105 void Connect(const std::string& uid, 106 void Connect(const std::string& uid,
106 const std::string& auth_token, 107 const std::string& auth_token,
107 const std::string& auth_service, 108 const std::string& auth_service);
108 const UiStrings& ui_strings);
109 109
110 // Disconnects the host, ready for tear-down. 110 // Disconnects the host, ready for tear-down.
111 // Also called internally, from the network thread. 111 // Also called internally, from the network thread.
112 void Disconnect(); 112 void Disconnect();
113 113
114 // Request a NAT policy notification. 114 // Request a NAT policy notification.
115 void RequestNatPolicy(); 115 void RequestNatPolicy();
116 116
117 // remoting::HostStatusObserver implementation. 117 // remoting::HostStatusObserver implementation.
118 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; 118 virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 state_(kDisconnected), 215 state_(kDisconnected),
216 failed_login_attempts_(0), 216 failed_login_attempts_(0),
217 nat_traversal_enabled_(false), 217 nat_traversal_enabled_(false),
218 policy_received_(false) { 218 policy_received_(false) {
219 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 219 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
220 } 220 }
221 221
222 void HostNPScriptObject::It2MeImpl::Connect( 222 void HostNPScriptObject::It2MeImpl::Connect(
223 const std::string& uid, 223 const std::string& uid,
224 const std::string& auth_token, 224 const std::string& auth_token,
225 const std::string& auth_service, 225 const std::string& auth_service) {
226 const UiStrings& ui_strings) {
227 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { 226 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) {
228 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 227 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
229 host_context_->ui_task_runner()->PostTask( 228 host_context_->ui_task_runner()->PostTask(
230 FROM_HERE, 229 FROM_HERE,
231 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service, 230 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service));
232 ui_strings));
233 return; 231 return;
234 } 232 }
235 233
236 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory( 234 desktop_environment_factory_.reset(new It2MeDesktopEnvironmentFactory(
237 host_context_->network_task_runner(), 235 host_context_->network_task_runner(),
238 host_context_->input_task_runner(), 236 host_context_->input_task_runner(),
239 host_context_->ui_task_runner(), 237 host_context_->ui_task_runner()));
240 ui_strings));
241 238
242 // Start monitoring configured policies. 239 // Start monitoring configured policies.
243 policy_watcher_.reset( 240 policy_watcher_.reset(
244 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); 241 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner()));
245 policy_watcher_->StartWatching( 242 policy_watcher_->StartWatching(
246 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); 243 base::Bind(&It2MeImpl::OnPolicyUpdate, this));
247 244
248 // Switch to the network thread to start the actual connection. 245 // Switch to the network thread to start the actual connection.
249 host_context_->network_task_runner()->PostTask( 246 host_context_->network_task_runner()->PostTask(
250 FROM_HERE, base::Bind( 247 FROM_HERE, base::Bind(
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 ChromotingHostContext::Create(plugin_task_runner_); 1046 ChromotingHostContext::Create(plugin_task_runner_);
1050 if (!host_context) { 1047 if (!host_context) {
1051 SetException("connect: failed to start threads"); 1048 SetException("connect: failed to start threads");
1052 return false; 1049 return false;
1053 } 1050 }
1054 1051
1055 // Create the It2Me host implementation and start connecting. 1052 // Create the It2Me host implementation and start connecting.
1056 it2me_impl_ = new It2MeImpl( 1053 it2me_impl_ = new It2MeImpl(
1057 host_context.Pass(), plugin_task_runner_, weak_ptr_, 1054 host_context.Pass(), plugin_task_runner_, weak_ptr_,
1058 xmpp_server_config_, directory_bot_jid_); 1055 xmpp_server_config_, directory_bot_jid_);
1059 it2me_impl_->Connect(uid, auth_token, auth_service, ui_strings_); 1056 it2me_impl_->Connect(uid, auth_token, auth_service);
1060 1057
1061 return true; 1058 return true;
1062 } 1059 }
1063 1060
1064 bool HostNPScriptObject::Disconnect(const NPVariant* args, 1061 bool HostNPScriptObject::Disconnect(const NPVariant* args,
1065 uint32_t arg_count, 1062 uint32_t arg_count,
1066 NPVariant* result) { 1063 NPVariant* result) {
1067 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1064 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1068 if (arg_count != 0) { 1065 if (arg_count != 0) {
1069 SetException("disconnect: bad number of arguments"); 1066 SetException("disconnect: bad number of arguments");
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 1486
1490 void HostNPScriptObject::SetWindow(NPWindow* np_window) { 1487 void HostNPScriptObject::SetWindow(NPWindow* np_window) {
1491 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1488 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1492 1489
1493 daemon_controller_->SetWindow(np_window->window); 1490 daemon_controller_->SetWindow(np_window->window);
1494 } 1491 }
1495 1492
1496 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) { 1493 void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) {
1497 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1494 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1498 1495
1499 string16 direction; 1496 // Reload resources for the current locale. The default UI locale is used on
1500 LocalizeString(localize_func, "@@bidi_dir", &direction); 1497 // Windows.
1501 ui_strings_.direction = UTF16ToUTF8(direction) == "rtl" ? 1498 #if !defined(OS_WIN)
1502 remoting::UiStrings::RTL : remoting::UiStrings::LTR; 1499 string16 ui_locale;
1503 LocalizeString(localize_func, /*i18n-content*/"PRODUCT_NAME", 1500 LocalizeString(localize_func, "@@ui_locale", &ui_locale);
1504 &ui_strings_.product_name); 1501 remoting::LoadResources(UTF16ToUTF8(ui_locale));
1505 LocalizeString(localize_func, /*i18n-content*/"DISCONNECT_OTHER_BUTTON", 1502 #endif // !defined(OS_WIN)
1506 &ui_strings_.disconnect_button_text);
1507 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_PROMPT",
1508 &ui_strings_.continue_prompt);
1509 LocalizeString(localize_func, /*i18n-content*/"CONTINUE_BUTTON",
1510 &ui_strings_.continue_button_text);
1511 LocalizeString(localize_func, /*i18n-content*/"STOP_SHARING_BUTTON",
1512 &ui_strings_.stop_sharing_button_text);
1513 LocalizeStringWithSubstitution(localize_func,
1514 /*i18n-content*/"MESSAGE_SHARED", "$1",
1515 &ui_strings_.disconnect_message);
1516 } 1503 }
1517 1504
1518 bool HostNPScriptObject::LocalizeString(NPObject* localize_func, 1505 bool HostNPScriptObject::LocalizeString(NPObject* localize_func,
1519 const char* tag, string16* result) { 1506 const char* tag, string16* result) {
1520 return LocalizeStringWithSubstitution(localize_func, tag, NULL, result); 1507 return LocalizeStringWithSubstitution(localize_func, tag, NULL, result);
1521 } 1508 }
1522 1509
1523 bool HostNPScriptObject::LocalizeStringWithSubstitution( 1510 bool HostNPScriptObject::LocalizeStringWithSubstitution(
1524 NPObject* localize_func, 1511 NPObject* localize_func,
1525 const char* tag, 1512 const char* tag,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 } 1705 }
1719 1706
1720 void HostNPScriptObject::SetException(const std::string& exception_string) { 1707 void HostNPScriptObject::SetException(const std::string& exception_string) {
1721 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1708 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1722 1709
1723 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1710 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1724 LOG(INFO) << exception_string; 1711 LOG(INFO) << exception_string;
1725 } 1712 }
1726 1713
1727 } // namespace remoting 1714 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698