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

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

Issue 7669045: Make ChromotingHost::ui_strings() immutable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/ui_strings.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/sys_string_conversions.h"
10 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "base/utf_string_conversions.h"
11 #include "remoting/base/auth_token_util.h" 13 #include "remoting/base/auth_token_util.h"
12 #include "remoting/base/util.h" 14 #include "remoting/base/util.h"
13 #include "remoting/host/chromoting_host.h" 15 #include "remoting/host/chromoting_host.h"
14 #include "remoting/host/chromoting_host_context.h" 16 #include "remoting/host/chromoting_host_context.h"
15 #include "remoting/host/desktop_environment.h" 17 #include "remoting/host/desktop_environment.h"
16 #include "remoting/host/host_config.h" 18 #include "remoting/host/host_config.h"
17 #include "remoting/host/host_key_pair.h" 19 #include "remoting/host/host_key_pair.h"
18 #include "remoting/host/in_memory_host_config.h" 20 #include "remoting/host/in_memory_host_config.h"
19 #include "remoting/host/plugin/policy_hack/nat_policy.h" 21 #include "remoting/host/plugin/policy_hack/nat_policy.h"
20 #include "remoting/host/register_support_host_request.h" 22 #include "remoting/host/register_support_host_request.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 345 }
344 346
345 void HostNPScriptObject::OnClientAuthenticated( 347 void HostNPScriptObject::OnClientAuthenticated(
346 remoting::protocol::ConnectionToClient* client) { 348 remoting::protocol::ConnectionToClient* client) {
347 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); 349 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_);
348 client_username_ = client->session()->jid(); 350 client_username_ = client->session()->jid();
349 size_t pos = client_username_.find('/'); 351 size_t pos = client_username_.find('/');
350 if (pos != std::string::npos) 352 if (pos != std::string::npos)
351 client_username_.replace(pos, std::string::npos, ""); 353 client_username_.replace(pos, std::string::npos, "");
352 LOG(INFO) << "Client " << client_username_ << " connected."; 354 LOG(INFO) << "Client " << client_username_ << " connected.";
353 LocalizeStrings();
354 OnStateChanged(kConnected); 355 OnStateChanged(kConnected);
355 } 356 }
356 357
357 void HostNPScriptObject::OnClientDisconnected( 358 void HostNPScriptObject::OnClientDisconnected(
358 remoting::protocol::ConnectionToClient* client) { 359 remoting::protocol::ConnectionToClient* client) {
359 client_username_.clear(); 360 client_username_.clear();
360 OnStateChanged(kDisconnected); 361 OnStateChanged(kDisconnected);
361 } 362 }
362 363
363 void HostNPScriptObject::OnShutdown() { 364 void HostNPScriptObject::OnShutdown() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 476
476 // Create the Host. 477 // Create the Host.
477 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_; 478 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_;
478 host_ = ChromotingHost::Create( 479 host_ = ChromotingHost::Create(
479 &host_context_, host_config_, desktop_environment_.get(), 480 &host_context_, host_config_, desktop_environment_.get(),
480 access_verifier.release(), nat_traversal_enabled_); 481 access_verifier.release(), nat_traversal_enabled_);
481 host_->AddStatusObserver(this); 482 host_->AddStatusObserver(this);
482 host_->AddStatusObserver(register_request_.get()); 483 host_->AddStatusObserver(register_request_.get());
483 host_->set_it2me(true); 484 host_->set_it2me(true);
484 485
486 LocalizeStrings();
487
485 // Start the Host. 488 // Start the Host.
486 host_->Start(); 489 host_->Start();
487 490
488 OnStateChanged(kRequestedAccessCode); 491 OnStateChanged(kRequestedAccessCode);
489 return; 492 return;
490 } 493 }
491 494
492 bool HostNPScriptObject::Disconnect(const NPVariant* args, 495 bool HostNPScriptObject::Disconnect(const NPVariant* args,
493 uint32_t arg_count, 496 uint32_t arg_count,
494 NPVariant* result) { 497 NPVariant* result) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 638 }
636 } 639 }
637 640
638 void HostNPScriptObject::SetException(const std::string& exception_string) { 641 void HostNPScriptObject::SetException(const std::string& exception_string) {
639 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 642 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
640 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 643 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
641 LOG(INFO) << exception_string; 644 LOG(INFO) << exception_string;
642 } 645 }
643 646
644 void HostNPScriptObject::LocalizeStrings() { 647 void HostNPScriptObject::LocalizeStrings() {
645 UiStrings* ui_strings = host_->ui_strings(); 648 UiStrings ui_strings;
646 std::string direction; 649 string16 direction;
647 LocalizeString("@@bidi_dir", NULL, &direction); 650 LocalizeString("@@bidi_dir", &direction);
648 ui_strings->direction = 651 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ?
649 direction == "rtl" ? remoting::UiStrings::RTL 652 remoting::UiStrings::RTL : remoting::UiStrings::LTR;
650 : remoting::UiStrings::LTR; 653 LocalizeString("productName", &ui_strings.product_name);
651 LocalizeString("productName", NULL, &ui_strings->product_name); 654 LocalizeString("disconnectButton", &ui_strings.disconnect_button_text);
652 LocalizeString("disconnectButton", NULL, &ui_strings->disconnect_button_text);
653 LocalizeString( 655 LocalizeString(
654 #if defined(OS_WIN) 656 #if defined(OS_WIN)
655 "disconnectButtonPlusShortcutWindows", 657 "disconnectButtonPlusShortcutWindows",
656 #elif defined(OS_MAC) 658 #elif defined(OS_MAC)
657 "disconnectButtonPlusShortcutMacOSX", 659 "disconnectButtonPlusShortcutMacOSX",
658 #else 660 #else
659 "disconnectButtonPlusShortcutLinux", 661 "disconnectButtonPlusShortcutLinux",
660 #endif 662 #endif
661 NULL, &ui_strings->disconnect_button_text_plus_shortcut); 663 &ui_strings.disconnect_button_text_plus_shortcut);
662 LocalizeString("continuePrompt", NULL, &ui_strings->continue_prompt); 664 LocalizeString("continuePrompt", &ui_strings.continue_prompt);
663 LocalizeString("continueButton", NULL, &ui_strings->continue_button_text); 665 LocalizeString("continueButton", &ui_strings.continue_button_text);
664 LocalizeString("stopSharingButton", NULL, 666 LocalizeString("stopSharingButton",
665 &ui_strings->stop_sharing_button_text); 667 &ui_strings.stop_sharing_button_text);
666 LocalizeString("messageShared", client_username_.c_str(), 668 LocalizeString("messageShared", &ui_strings.disconnect_message);
667 &ui_strings->disconnect_message); 669
670 host_->SetUiStrings(ui_strings);
668 } 671 }
669 672
670 bool HostNPScriptObject::LocalizeString(const char* tag, 673 bool HostNPScriptObject::LocalizeString(const char* tag, string16* result) {
671 const char* substitution,
672 std::string* result) {
673 NPVariant args[2]; 674 NPVariant args[2];
674 STRINGZ_TO_NPVARIANT(tag, args[0]); 675 STRINGZ_TO_NPVARIANT(tag, args[0]);
675 int arg_count = 1;
676 if (substitution) {
677 STRINGZ_TO_NPVARIANT(substitution, args[1]);
678 ++arg_count;
679 }
680 NPVariant np_result; 676 NPVariant np_result;
681 bool is_good = g_npnetscape_funcs->invokeDefault( 677 bool is_good = g_npnetscape_funcs->invokeDefault(
682 plugin_, localize_func_.get(), &args[0], arg_count, &np_result); 678 plugin_, localize_func_.get(), &args[0], 1, &np_result);
683 if (!is_good) { 679 if (!is_good) {
684 LOG(ERROR) << "Localization failed for " << tag; 680 LOG(ERROR) << "Localization failed for " << tag;
685 return false; 681 return false;
686 } 682 }
687 std::string translation = StringFromNPVariant(np_result); 683 std::string translation = StringFromNPVariant(np_result);
688 g_npnetscape_funcs->releasevariantvalue(&np_result); 684 g_npnetscape_funcs->releasevariantvalue(&np_result);
689 if (translation.empty()) { 685 if (translation.empty()) {
690 LOG(ERROR) << "Missing translation for " << tag; 686 LOG(ERROR) << "Missing translation for " << tag;
691 return false; 687 return false;
692 } 688 }
693 *result = translation; 689 *result = UTF8ToUTF16(translation);
694 return true; 690 return true;
695 } 691 }
696 692
697 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, 693 bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
698 const NPVariant* args, 694 const NPVariant* args,
699 uint32_t argCount) { 695 uint32_t argCount) {
700 NPVariant np_result; 696 NPVariant np_result;
701 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, 697 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args,
702 argCount, &np_result); 698 argCount, &np_result);
703 if (is_good) 699 if (is_good)
704 g_npnetscape_funcs->releasevariantvalue(&np_result); 700 g_npnetscape_funcs->releasevariantvalue(&np_result);
705 return is_good; 701 return is_good;
706 } 702 }
707 703
708 } // namespace remoting 704 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/ui_strings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698