Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 } | 343 } |
| 344 | 344 |
| 345 void HostNPScriptObject::OnClientAuthenticated( | 345 void HostNPScriptObject::OnClientAuthenticated( |
| 346 remoting::protocol::ConnectionToClient* client) { | 346 remoting::protocol::ConnectionToClient* client) { |
| 347 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | 347 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
| 348 client_username_ = client->session()->jid(); | 348 client_username_ = client->session()->jid(); |
| 349 size_t pos = client_username_.find('/'); | 349 size_t pos = client_username_.find('/'); |
| 350 if (pos != std::string::npos) | 350 if (pos != std::string::npos) |
| 351 client_username_.replace(pos, std::string::npos, ""); | 351 client_username_.replace(pos, std::string::npos, ""); |
| 352 LOG(INFO) << "Client " << client_username_ << " connected."; | 352 LOG(INFO) << "Client " << client_username_ << " connected."; |
| 353 LocalizeStrings(); | |
| 354 OnStateChanged(kConnected); | 353 OnStateChanged(kConnected); |
| 355 } | 354 } |
| 356 | 355 |
| 357 void HostNPScriptObject::OnClientDisconnected( | 356 void HostNPScriptObject::OnClientDisconnected( |
| 358 remoting::protocol::ConnectionToClient* client) { | 357 remoting::protocol::ConnectionToClient* client) { |
| 359 client_username_.clear(); | 358 client_username_.clear(); |
| 360 OnStateChanged(kDisconnected); | 359 OnStateChanged(kDisconnected); |
| 361 } | 360 } |
| 362 | 361 |
| 363 void HostNPScriptObject::OnShutdown() { | 362 void HostNPScriptObject::OnShutdown() { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 | 474 |
| 476 // Create the Host. | 475 // Create the Host. |
| 477 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_; | 476 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_; |
| 478 host_ = ChromotingHost::Create( | 477 host_ = ChromotingHost::Create( |
| 479 &host_context_, host_config_, desktop_environment_.get(), | 478 &host_context_, host_config_, desktop_environment_.get(), |
| 480 access_verifier.release(), nat_traversal_enabled_); | 479 access_verifier.release(), nat_traversal_enabled_); |
| 481 host_->AddStatusObserver(this); | 480 host_->AddStatusObserver(this); |
| 482 host_->AddStatusObserver(register_request_.get()); | 481 host_->AddStatusObserver(register_request_.get()); |
| 483 host_->set_it2me(true); | 482 host_->set_it2me(true); |
| 484 | 483 |
| 484 LocalizeStrings(); | |
|
Jamie
2011/08/18 16:28:41
Do we know the username at this point? Your object
Sergey Ulanov
2011/08/18 18:04:32
I updated DisconnectWindow to substitute user name
| |
| 485 | |
| 485 // Start the Host. | 486 // Start the Host. |
| 486 host_->Start(); | 487 host_->Start(); |
| 487 | 488 |
| 488 OnStateChanged(kRequestedAccessCode); | 489 OnStateChanged(kRequestedAccessCode); |
| 489 return; | 490 return; |
| 490 } | 491 } |
| 491 | 492 |
| 492 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 493 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
| 493 uint32_t arg_count, | 494 uint32_t arg_count, |
| 494 NPVariant* result) { | 495 NPVariant* result) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 } | 636 } |
| 636 } | 637 } |
| 637 | 638 |
| 638 void HostNPScriptObject::SetException(const std::string& exception_string) { | 639 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 639 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 640 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 640 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 641 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 641 LOG(INFO) << exception_string; | 642 LOG(INFO) << exception_string; |
| 642 } | 643 } |
| 643 | 644 |
| 644 void HostNPScriptObject::LocalizeStrings() { | 645 void HostNPScriptObject::LocalizeStrings() { |
| 645 UiStrings* ui_strings = host_->ui_strings(); | 646 UiStrings ui_strings; |
| 646 std::string direction; | 647 std::string direction; |
| 647 LocalizeString("@@bidi_dir", NULL, &direction); | 648 LocalizeString("@@bidi_dir", NULL, &direction); |
| 648 ui_strings->direction = | 649 ui_strings.direction = |
| 649 direction == "rtl" ? remoting::UiStrings::RTL | 650 direction == "rtl" ? remoting::UiStrings::RTL |
| 650 : remoting::UiStrings::LTR; | 651 : remoting::UiStrings::LTR; |
| 651 LocalizeString("productName", NULL, &ui_strings->product_name); | 652 LocalizeString("productName", NULL, &ui_strings.product_name); |
| 652 LocalizeString("disconnectButton", NULL, &ui_strings->disconnect_button_text); | 653 LocalizeString("disconnectButton", NULL, &ui_strings.disconnect_button_text); |
| 653 LocalizeString( | 654 LocalizeString( |
| 654 #if defined(OS_WIN) | 655 #if defined(OS_WIN) |
| 655 "disconnectButtonPlusShortcutWindows", | 656 "disconnectButtonPlusShortcutWindows", |
| 656 #elif defined(OS_MAC) | 657 #elif defined(OS_MAC) |
| 657 "disconnectButtonPlusShortcutMacOSX", | 658 "disconnectButtonPlusShortcutMacOSX", |
| 658 #else | 659 #else |
| 659 "disconnectButtonPlusShortcutLinux", | 660 "disconnectButtonPlusShortcutLinux", |
| 660 #endif | 661 #endif |
| 661 NULL, &ui_strings->disconnect_button_text_plus_shortcut); | 662 NULL, &ui_strings.disconnect_button_text_plus_shortcut); |
| 662 LocalizeString("continuePrompt", NULL, &ui_strings->continue_prompt); | 663 LocalizeString("continuePrompt", NULL, &ui_strings.continue_prompt); |
| 663 LocalizeString("continueButton", NULL, &ui_strings->continue_button_text); | 664 LocalizeString("continueButton", NULL, &ui_strings.continue_button_text); |
| 664 LocalizeString("stopSharingButton", NULL, | 665 LocalizeString("stopSharingButton", NULL, |
| 665 &ui_strings->stop_sharing_button_text); | 666 &ui_strings.stop_sharing_button_text); |
| 666 LocalizeString("messageShared", client_username_.c_str(), | 667 LocalizeString("messageShared", client_username_.c_str(), |
| 667 &ui_strings->disconnect_message); | 668 &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, |
| 671 const char* substitution, | 674 const char* substitution, |
| 672 std::string* result) { | 675 std::string* result) { |
| 673 NPVariant args[2]; | 676 NPVariant args[2]; |
| 674 STRINGZ_TO_NPVARIANT(tag, args[0]); | 677 STRINGZ_TO_NPVARIANT(tag, args[0]); |
| 675 int arg_count = 1; | 678 int arg_count = 1; |
| 676 if (substitution) { | 679 if (substitution) { |
| 677 STRINGZ_TO_NPVARIANT(substitution, args[1]); | 680 STRINGZ_TO_NPVARIANT(substitution, args[1]); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 699 uint32_t argCount) { | 702 uint32_t argCount) { |
| 700 NPVariant np_result; | 703 NPVariant np_result; |
| 701 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 704 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
| 702 argCount, &np_result); | 705 argCount, &np_result); |
| 703 if (is_good) | 706 if (is_good) |
| 704 g_npnetscape_funcs->releasevariantvalue(&np_result); | 707 g_npnetscape_funcs->releasevariantvalue(&np_result); |
| 705 return is_good; | 708 return is_good; |
| 706 } | 709 } |
| 707 | 710 |
| 708 } // namespace remoting | 711 } // namespace remoting |
| OLD | NEW |