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/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "remoting/base/auth_token_util.h" | 13 #include "remoting/base/auth_token_util.h" |
14 #include "remoting/base/util.h" | 14 #include "remoting/base/util.h" |
15 #include "remoting/host/chromoting_host.h" | 15 #include "remoting/host/chromoting_host.h" |
16 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
17 #include "remoting/host/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
18 #include "remoting/host/host_config.h" | 18 #include "remoting/host/host_config.h" |
19 #include "remoting/host/host_key_pair.h" | 19 #include "remoting/host/host_key_pair.h" |
20 #include "remoting/host/in_memory_host_config.h" | 20 #include "remoting/host/in_memory_host_config.h" |
21 #include "remoting/host/plugin/policy_hack/nat_policy.h" | 21 #include "remoting/host/plugin/policy_hack/nat_policy.h" |
22 #include "remoting/host/register_support_host_request.h" | 22 #include "remoting/host/register_support_host_request.h" |
23 #include "remoting/host/support_access_verifier.h" | 23 #include "remoting/host/support_access_verifier.h" |
24 #include "remoting/host/ui_strings.h" | |
25 | 24 |
26 namespace remoting { | 25 namespace remoting { |
27 | 26 |
28 // Supported Javascript interface: | 27 // Supported Javascript interface: |
29 // readonly attribute string accessCode; | 28 // readonly attribute string accessCode; |
30 // readonly attribute int accessCodeLifetime; | 29 // readonly attribute int accessCodeLifetime; |
31 // readonly attribute string client; | 30 // readonly attribute string client; |
32 // readonly attribute int state; | 31 // readonly attribute int state; |
33 // | 32 // |
34 // state: { | 33 // state: { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 } else { | 269 } else { |
271 SetException("SetProperty: unexpected type for property " + | 270 SetException("SetProperty: unexpected type for property " + |
272 property_name); | 271 property_name); |
273 } | 272 } |
274 return false; | 273 return false; |
275 } | 274 } |
276 | 275 |
277 if (property_name == kAttrNameLocalizeString) { | 276 if (property_name == kAttrNameLocalizeString) { |
278 if (NPVARIANT_IS_OBJECT(*value)) { | 277 if (NPVARIANT_IS_OBJECT(*value)) { |
279 localize_func_ = NPVARIANT_TO_OBJECT(*value); | 278 localize_func_ = NPVARIANT_TO_OBJECT(*value); |
279 LocalizeStrings(); | |
Sergey Ulanov
2011/08/29 21:22:05
Can we call this from Connect()? JavaScript may no
Jamie
2011/08/29 21:50:46
I don't think that buys us anything, and I prefer
Sergey Ulanov
2011/08/29 22:28:07
What bothers me is that javascript interface looks
Lambros
2011/08/29 23:24:59
Done.
| |
280 return true; | 280 return true; |
281 } else { | 281 } else { |
282 SetException("SetProperty: unexpected type for property " + | 282 SetException("SetProperty: unexpected type for property " + |
283 property_name); | 283 property_name); |
284 } | 284 } |
285 return false; | 285 return false; |
286 } | 286 } |
287 | 287 |
288 if (property_name == kAttrNameLogDebugInfo) { | 288 if (property_name == kAttrNameLogDebugInfo) { |
289 if (NPVARIANT_IS_OBJECT(*value)) { | 289 if (NPVARIANT_IS_OBJECT(*value)) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 476 |
477 // Create the Host. | 477 // Create the Host. |
478 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_; | 478 LOG(INFO) << "Connecting with NAT state: " << nat_traversal_enabled_; |
479 host_ = ChromotingHost::Create( | 479 host_ = ChromotingHost::Create( |
480 &host_context_, host_config_, desktop_environment_.get(), | 480 &host_context_, host_config_, desktop_environment_.get(), |
481 access_verifier.release(), nat_traversal_enabled_); | 481 access_verifier.release(), nat_traversal_enabled_); |
482 host_->AddStatusObserver(this); | 482 host_->AddStatusObserver(this); |
483 host_->AddStatusObserver(register_request_.get()); | 483 host_->AddStatusObserver(register_request_.get()); |
484 host_->set_it2me(true); | 484 host_->set_it2me(true); |
485 | 485 |
486 LocalizeStrings(); | 486 { |
487 base::AutoLock auto_lock(ui_strings_lock_); | |
488 host_->SetUiStrings(ui_strings_); | |
489 } | |
487 | 490 |
488 // Start the Host. | 491 // Start the Host. |
489 host_->Start(); | 492 host_->Start(); |
490 | 493 |
491 OnStateChanged(kRequestedAccessCode); | 494 OnStateChanged(kRequestedAccessCode); |
492 return; | 495 return; |
493 } | 496 } |
494 | 497 |
495 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 498 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
496 uint32_t arg_count, | 499 uint32_t arg_count, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 } | 642 } |
640 } | 643 } |
641 | 644 |
642 void HostNPScriptObject::SetException(const std::string& exception_string) { | 645 void HostNPScriptObject::SetException(const std::string& exception_string) { |
643 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 646 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
644 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 647 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
645 LOG(INFO) << exception_string; | 648 LOG(INFO) << exception_string; |
646 } | 649 } |
647 | 650 |
648 void HostNPScriptObject::LocalizeStrings() { | 651 void HostNPScriptObject::LocalizeStrings() { |
649 UiStrings ui_strings; | 652 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
Jamie
2011/08/29 20:59:22
Other similar checks in the same file use CHECK_EQ
Lambros
2011/08/29 21:21:42
Removed.
Sergey Ulanov
2011/08/29 21:22:05
IMO DCHECK is fine here. We should change this cod
Sergey Ulanov
2011/08/29 22:30:27
Please add it back. We do need this DCHECK to ensu
Lambros
2011/08/29 23:24:59
Done.
| |
653 | |
654 base::AutoLock auto_lock(ui_strings_lock_); | |
Jamie
2011/08/29 20:59:22
I worry slightly about holding this lock while we'
Lambros
2011/08/29 21:21:42
Done.
Sergey Ulanov
2011/08/29 21:22:05
+1. If javascript sets the localization callback i
| |
650 string16 direction; | 655 string16 direction; |
651 LocalizeString("@@bidi_dir", &direction); | 656 LocalizeString("@@bidi_dir", &direction); |
652 ui_strings.direction = UTF16ToUTF8(direction) == "rtl" ? | 657 ui_strings_.direction = UTF16ToUTF8(direction) == "rtl" ? |
653 remoting::UiStrings::RTL : remoting::UiStrings::LTR; | 658 remoting::UiStrings::RTL : remoting::UiStrings::LTR; |
654 LocalizeString(/*i18n-content*/"PRODUCT_NAME", &ui_strings.product_name); | 659 LocalizeString(/*i18n-content*/"PRODUCT_NAME", &ui_strings_.product_name); |
655 LocalizeString(/*i18n-content*/"DISCONNECT_BUTTON", | 660 LocalizeString(/*i18n-content*/"DISCONNECT_BUTTON", |
656 &ui_strings.disconnect_button_text); | 661 &ui_strings_.disconnect_button_text); |
657 LocalizeString( | 662 LocalizeString( |
658 #if defined(OS_WIN) | 663 #if defined(OS_WIN) |
659 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_WINDOWS", | 664 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_WINDOWS", |
660 #elif defined(OS_MAC) | 665 #elif defined(OS_MAC) |
661 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_MAC_OS_X", | 666 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_MAC_OS_X", |
662 #else | 667 #else |
663 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_LINUX", | 668 /*i18n-content*/"DISCONNECT_BUTTON_PLUS_SHORTCUT_LINUX", |
664 #endif | 669 #endif |
665 &ui_strings.disconnect_button_text_plus_shortcut); | 670 &ui_strings_.disconnect_button_text_plus_shortcut); |
666 LocalizeString(/*i18n-content*/"CONTINUE_PROMPT", | 671 LocalizeString(/*i18n-content*/"CONTINUE_PROMPT", |
667 &ui_strings.continue_prompt); | 672 &ui_strings_.continue_prompt); |
668 LocalizeString(/*i18n-content*/"CONTINUE_BUTTON", | 673 LocalizeString(/*i18n-content*/"CONTINUE_BUTTON", |
669 &ui_strings.continue_button_text); | 674 &ui_strings_.continue_button_text); |
670 LocalizeString(/*i18n-content*/"STOP_SHARING_BUTTON", | 675 LocalizeString(/*i18n-content*/"STOP_SHARING_BUTTON", |
671 &ui_strings.stop_sharing_button_text); | 676 &ui_strings_.stop_sharing_button_text); |
672 LocalizeString(/*i18n-content*/"MESSAGE_SHARED", | 677 LocalizeString(/*i18n-content*/"MESSAGE_SHARED", |
673 &ui_strings.disconnect_message); | 678 &ui_strings_.disconnect_message); |
674 | |
675 host_->SetUiStrings(ui_strings); | |
676 } | 679 } |
677 | 680 |
678 bool HostNPScriptObject::LocalizeString(const char* tag, string16* result) { | 681 bool HostNPScriptObject::LocalizeString(const char* tag, string16* result) { |
679 NPVariant args[2]; | 682 NPVariant args[2]; |
680 STRINGZ_TO_NPVARIANT(tag, args[0]); | 683 STRINGZ_TO_NPVARIANT(tag, args[0]); |
681 NPVariant np_result; | 684 NPVariant np_result; |
682 bool is_good = g_npnetscape_funcs->invokeDefault( | 685 bool is_good = g_npnetscape_funcs->invokeDefault( |
683 plugin_, localize_func_.get(), &args[0], 1, &np_result); | 686 plugin_, localize_func_.get(), &args[0], 1, &np_result); |
684 if (!is_good) { | 687 if (!is_good) { |
685 LOG(ERROR) << "Localization failed for " << tag; | 688 LOG(ERROR) << "Localization failed for " << tag; |
(...skipping 14 matching lines...) Expand all Loading... | |
700 uint32_t argCount) { | 703 uint32_t argCount) { |
701 NPVariant np_result; | 704 NPVariant np_result; |
702 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 705 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
703 argCount, &np_result); | 706 argCount, &np_result); |
704 if (is_good) | 707 if (is_good) |
705 g_npnetscape_funcs->releasevariantvalue(&np_result); | 708 g_npnetscape_funcs->releasevariantvalue(&np_result); |
706 return is_good; | 709 return is_good; |
707 } | 710 } |
708 | 711 |
709 } // namespace remoting | 712 } // namespace remoting |
OLD | NEW |