| OLD | NEW |
| 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/client/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ppapi/cpp/completion_callback.h" | 31 #include "ppapi/cpp/completion_callback.h" |
| 32 #include "ppapi/cpp/dev/url_util_dev.h" | 32 #include "ppapi/cpp/dev/url_util_dev.h" |
| 33 #include "ppapi/cpp/image_data.h" | 33 #include "ppapi/cpp/image_data.h" |
| 34 #include "ppapi/cpp/input_event.h" | 34 #include "ppapi/cpp/input_event.h" |
| 35 #include "ppapi/cpp/rect.h" | 35 #include "ppapi/cpp/rect.h" |
| 36 #include "ppapi/cpp/var_array_buffer.h" | 36 #include "ppapi/cpp/var_array_buffer.h" |
| 37 #include "ppapi/cpp/var_dictionary.h" | 37 #include "ppapi/cpp/var_dictionary.h" |
| 38 #include "remoting/base/constants.h" | 38 #include "remoting/base/constants.h" |
| 39 #include "remoting/base/util.h" | 39 #include "remoting/base/util.h" |
| 40 #include "remoting/client/chromoting_client.h" | 40 #include "remoting/client/chromoting_client.h" |
| 41 #include "remoting/client/client_config.h" | |
| 42 #include "remoting/client/frame_consumer_proxy.h" | 41 #include "remoting/client/frame_consumer_proxy.h" |
| 43 #include "remoting/client/plugin/delegating_signal_strategy.h" | 42 #include "remoting/client/plugin/delegating_signal_strategy.h" |
| 44 #include "remoting/client/plugin/media_source_video_renderer.h" | 43 #include "remoting/client/plugin/media_source_video_renderer.h" |
| 45 #include "remoting/client/plugin/normalizing_input_filter_cros.h" | 44 #include "remoting/client/plugin/normalizing_input_filter_cros.h" |
| 46 #include "remoting/client/plugin/normalizing_input_filter_mac.h" | 45 #include "remoting/client/plugin/normalizing_input_filter_mac.h" |
| 47 #include "remoting/client/plugin/pepper_audio_player.h" | 46 #include "remoting/client/plugin/pepper_audio_player.h" |
| 48 #include "remoting/client/plugin/pepper_input_handler.h" | 47 #include "remoting/client/plugin/pepper_input_handler.h" |
| 49 #include "remoting/client/plugin/pepper_port_allocator.h" | 48 #include "remoting/client/plugin/pepper_port_allocator.h" |
| 50 #include "remoting/client/plugin/pepper_view.h" | 49 #include "remoting/client/plugin/pepper_view.h" |
| 51 #include "remoting/client/software_video_renderer.h" | 50 #include "remoting/client/software_video_renderer.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Returns true if |pixel| is not completely transparent. | 155 // Returns true if |pixel| is not completely transparent. |
| 157 bool IsVisiblePixel(uint32_t pixel) { | 156 bool IsVisiblePixel(uint32_t pixel) { |
| 158 return (pixel & kPixelAlphaMask) != 0; | 157 return (pixel & kPixelAlphaMask) != 0; |
| 159 } | 158 } |
| 160 | 159 |
| 161 // Returns true if there is at least one visible pixel in the given range. | 160 // Returns true if there is at least one visible pixel in the given range. |
| 162 bool IsVisibleRow(const uint32_t* begin, const uint32_t* end) { | 161 bool IsVisibleRow(const uint32_t* begin, const uint32_t* end) { |
| 163 return std::find_if(begin, end, &IsVisiblePixel) != end; | 162 return std::find_if(begin, end, &IsVisiblePixel) != end; |
| 164 } | 163 } |
| 165 | 164 |
| 165 bool ParseAuthMethods( |
| 166 const std::string& auth_methods_str, |
| 167 std::vector<protocol::AuthenticationMethod>* auth_methods) { |
| 168 std::vector<std::string> parts; |
| 169 base::SplitString(auth_methods_str, ',', &parts); |
| 170 for (std::vector<std::string>::iterator it = parts.begin(); |
| 171 it != parts.end(); ++it) { |
| 172 protocol::AuthenticationMethod authentication_method = |
| 173 protocol::AuthenticationMethod::FromString(*it); |
| 174 if (authentication_method.is_valid()) |
| 175 auth_methods->push_back(authentication_method); |
| 176 } |
| 177 if (auth_methods->empty()) { |
| 178 LOG(ERROR) << "No valid authentication methods specified."; |
| 179 return false; |
| 180 } |
| 181 |
| 182 return true; |
| 183 } |
| 184 |
| 166 // This flag blocks LOGs to the UI if we're already in the middle of logging | 185 // This flag blocks LOGs to the UI if we're already in the middle of logging |
| 167 // to the UI. This prevents a potential infinite loop if we encounter an error | 186 // to the UI. This prevents a potential infinite loop if we encounter an error |
| 168 // while sending the log message to the UI. | 187 // while sending the log message to the UI. |
| 169 bool g_logging_to_plugin = false; | 188 bool g_logging_to_plugin = false; |
| 170 bool g_has_logging_instance = false; | 189 bool g_has_logging_instance = false; |
| 171 base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner> >::Leaky | 190 base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner> >::Leaky |
| 172 g_logging_task_runner = LAZY_INSTANCE_INITIALIZER; | 191 g_logging_task_runner = LAZY_INSTANCE_INITIALIZER; |
| 173 base::LazyInstance<base::WeakPtr<ChromotingInstance> >::Leaky | 192 base::LazyInstance<base::WeakPtr<ChromotingInstance> >::Leaky |
| 174 g_logging_instance = LAZY_INSTANCE_INITIALIZER; | 193 g_logging_instance = LAZY_INSTANCE_INITIALIZER; |
| 175 base::LazyInstance<base::Lock>::Leaky | 194 base::LazyInstance<base::Lock>::Leaky |
| 176 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 195 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
| 177 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 196 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| 178 | 197 |
| 179 } // namespace | 198 } // namespace |
| 180 | 199 |
| 181 // String sent in the "hello" message to the webapp to describe features. | 200 // String sent in the "hello" message to the webapp to describe features. |
| 182 const char ChromotingInstance::kApiFeatures[] = | 201 const char ChromotingInstance::kApiFeatures[] = |
| 183 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 202 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
| 184 "notifyClientResolution pauseVideo pauseAudio asyncPin thirdPartyAuth " | 203 "notifyClientResolution pauseVideo pauseAudio asyncPin thirdPartyAuth " |
| 185 "pinlessAuth extensionMessage allowMouseLock mediaSourceRendering " | 204 "pinlessAuth extensionMessage allowMouseLock mediaSourceRendering " |
| 186 "videoControl"; | 205 "videoControl"; |
| 187 | 206 |
| 188 const char ChromotingInstance::kRequestedCapabilities[] = ""; | 207 const char ChromotingInstance::kRequestedCapabilities[] = ""; |
| 189 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; | 208 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; |
| 190 | 209 |
| 191 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | |
| 192 ClientConfig* config) { | |
| 193 std::vector<std::string> auth_methods; | |
| 194 base::SplitString(auth_methods_str, ',', &auth_methods); | |
| 195 for (std::vector<std::string>::iterator it = auth_methods.begin(); | |
| 196 it != auth_methods.end(); ++it) { | |
| 197 protocol::AuthenticationMethod authentication_method = | |
| 198 protocol::AuthenticationMethod::FromString(*it); | |
| 199 if (authentication_method.is_valid()) | |
| 200 config->authentication_methods.push_back(authentication_method); | |
| 201 } | |
| 202 if (config->authentication_methods.empty()) { | |
| 203 LOG(ERROR) << "No valid authentication methods specified."; | |
| 204 return false; | |
| 205 } | |
| 206 | |
| 207 return true; | |
| 208 } | |
| 209 | |
| 210 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) | 210 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) |
| 211 : pp::Instance(pp_instance), | 211 : pp::Instance(pp_instance), |
| 212 initialized_(false), | 212 initialized_(false), |
| 213 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), | 213 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), |
| 214 context_(plugin_task_runner_.get()), | 214 context_(plugin_task_runner_.get()), |
| 215 input_tracker_(&mouse_input_filter_), | 215 input_tracker_(&mouse_input_filter_), |
| 216 key_mapper_(&input_tracker_), | 216 key_mapper_(&input_tracker_), |
| 217 input_handler_(this), | 217 input_handler_(this), |
| 218 use_async_pin_dialog_(false), | 218 use_async_pin_dialog_(false), |
| 219 use_media_source_rendering_(false), | 219 use_media_source_rendering_(false), |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // crbug.com/138108 | 530 // crbug.com/138108 |
| 531 return this; | 531 return this; |
| 532 } | 532 } |
| 533 | 533 |
| 534 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { | 534 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { |
| 535 // TODO(sergeyu): Move cursor shape code to a separate class. | 535 // TODO(sergeyu): Move cursor shape code to a separate class. |
| 536 // crbug.com/138108 | 536 // crbug.com/138108 |
| 537 return this; | 537 return this; |
| 538 } | 538 } |
| 539 | 539 |
| 540 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | |
| 541 ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) { | |
| 542 return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>( | |
| 543 new TokenFetcherProxy( | |
| 544 base::Bind(&ChromotingInstance::FetchThirdPartyToken, | |
| 545 weak_factory_.GetWeakPtr()), | |
| 546 host_public_key)); | |
| 547 } | |
| 548 | |
| 549 void ChromotingInstance::InjectClipboardEvent( | 540 void ChromotingInstance::InjectClipboardEvent( |
| 550 const protocol::ClipboardEvent& event) { | 541 const protocol::ClipboardEvent& event) { |
| 551 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 542 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 552 data->SetString("mimeType", event.mime_type()); | 543 data->SetString("mimeType", event.mime_type()); |
| 553 data->SetString("item", event.data()); | 544 data->SetString("item", event.data()); |
| 554 PostLegacyJsonMessage("injectClipboardItem", data.Pass()); | 545 PostLegacyJsonMessage("injectClipboardItem", data.Pass()); |
| 555 } | 546 } |
| 556 | 547 |
| 557 void ChromotingInstance::SetCursorShape( | 548 void ChromotingInstance::SetCursorShape( |
| 558 const protocol::CursorShapeInfo& cursor_shape) { | 549 const protocol::CursorShapeInfo& cursor_shape) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 input_handler_.SetMouseCursor(cursor_image.Pass(), cursor_hotspot); | 630 input_handler_.SetMouseCursor(cursor_image.Pass(), cursor_hotspot); |
| 640 } | 631 } |
| 641 } | 632 } |
| 642 | 633 |
| 643 void ChromotingInstance::OnFirstFrameReceived() { | 634 void ChromotingInstance::OnFirstFrameReceived() { |
| 644 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 635 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 645 PostLegacyJsonMessage("onFirstFrameReceived", data.Pass()); | 636 PostLegacyJsonMessage("onFirstFrameReceived", data.Pass()); |
| 646 } | 637 } |
| 647 | 638 |
| 648 void ChromotingInstance::HandleConnect(const base::DictionaryValue& data) { | 639 void ChromotingInstance::HandleConnect(const base::DictionaryValue& data) { |
| 649 ClientConfig config; | |
| 650 std::string local_jid; | 640 std::string local_jid; |
| 651 std::string auth_methods; | 641 std::string host_jid; |
| 652 if (!data.GetString("hostJid", &config.host_jid) || | 642 std::string host_public_key; |
| 653 !data.GetString("hostPublicKey", &config.host_public_key) || | 643 std::string auth_methods_str; |
| 644 std::string authentication_tag; |
| 645 std::vector<protocol::AuthenticationMethod> auth_methods; |
| 646 if (!data.GetString("hostJid", &host_jid) || |
| 647 !data.GetString("hostPublicKey", &host_public_key) || |
| 654 !data.GetString("localJid", &local_jid) || | 648 !data.GetString("localJid", &local_jid) || |
| 655 !data.GetString("authenticationMethods", &auth_methods) || | 649 !data.GetString("authenticationMethods", &auth_methods_str) || |
| 656 !ParseAuthMethods(auth_methods, &config) || | 650 !ParseAuthMethods(auth_methods_str, &auth_methods) || |
| 657 !data.GetString("authenticationTag", &config.authentication_tag)) { | 651 !data.GetString("authenticationTag", &authentication_tag)) { |
| 658 LOG(ERROR) << "Invalid connect() data."; | 652 LOG(ERROR) << "Invalid connect() data."; |
| 659 return; | 653 return; |
| 660 } | 654 } |
| 661 data.GetString("clientPairingId", &config.client_pairing_id); | 655 |
| 662 data.GetString("clientPairedSecret", &config.client_paired_secret); | 656 std::string client_pairing_id; |
| 657 data.GetString("clientPairingId", &client_pairing_id); |
| 658 std::string client_paired_secret; |
| 659 data.GetString("clientPairedSecret", &client_paired_secret); |
| 660 |
| 661 protocol::FetchSecretCallback fetch_secret_callback; |
| 663 if (use_async_pin_dialog_) { | 662 if (use_async_pin_dialog_) { |
| 664 config.fetch_secret_callback = | 663 fetch_secret_callback = base::Bind( |
| 665 base::Bind(&ChromotingInstance::FetchSecretFromDialog, | 664 &ChromotingInstance::FetchSecretFromDialog, weak_factory_.GetWeakPtr()); |
| 666 weak_factory_.GetWeakPtr()); | |
| 667 } else { | 665 } else { |
| 668 std::string shared_secret; | 666 std::string shared_secret; |
| 669 if (!data.GetString("sharedSecret", &shared_secret)) { | 667 if (!data.GetString("sharedSecret", &shared_secret)) { |
| 670 LOG(ERROR) << "sharedSecret not specified in connect()."; | 668 LOG(ERROR) << "sharedSecret not specified in connect()."; |
| 671 return; | 669 return; |
| 672 } | 670 } |
| 673 config.fetch_secret_callback = | 671 fetch_secret_callback = |
| 674 base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); | 672 base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); |
| 675 } | 673 } |
| 676 | 674 |
| 677 // Read the list of capabilities, if any. | 675 // Read the list of capabilities, if any. |
| 676 std::string capabilities; |
| 678 if (data.HasKey("capabilities")) { | 677 if (data.HasKey("capabilities")) { |
| 679 if (!data.GetString("capabilities", &config.capabilities)) { | 678 if (!data.GetString("capabilities", &capabilities)) { |
| 680 LOG(ERROR) << "Invalid connect() data."; | 679 LOG(ERROR) << "Invalid connect() data."; |
| 681 return; | 680 return; |
| 682 } | 681 } |
| 683 } | 682 } |
| 684 | 683 |
| 684 VLOG(0) << "Connecting to " << host_jid |
| 685 << ". Local jid: " << local_jid << "."; |
| 686 |
| 685 #if defined(OS_NACL) | 687 #if defined(OS_NACL) |
| 686 std::string key_filter; | 688 std::string key_filter; |
| 687 if (!data.GetString("keyFilter", &key_filter)) { | 689 if (!data.GetString("keyFilter", &key_filter)) { |
| 688 NOTREACHED(); | 690 NOTREACHED(); |
| 689 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); | 691 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); |
| 690 } else if (key_filter == "mac") { | 692 } else if (key_filter == "mac") { |
| 691 normalizing_input_filter_.reset( | 693 normalizing_input_filter_.reset( |
| 692 new NormalizingInputFilterMac(&key_mapper_)); | 694 new NormalizingInputFilterMac(&key_mapper_)); |
| 693 } else if (key_filter == "cros") { | 695 } else if (key_filter == "cros") { |
| 694 normalizing_input_filter_.reset( | 696 normalizing_input_filter_.reset( |
| 695 new NormalizingInputFilterCros(&key_mapper_)); | 697 new NormalizingInputFilterCros(&key_mapper_)); |
| 696 } else { | 698 } else { |
| 697 DCHECK(key_filter.empty()); | 699 DCHECK(key_filter.empty()); |
| 698 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); | 700 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); |
| 699 } | 701 } |
| 700 #elif defined(OS_MACOSX) | 702 #elif defined(OS_MACOSX) |
| 701 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); | 703 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); |
| 702 #elif defined(OS_CHROMEOS) | 704 #elif defined(OS_CHROMEOS) |
| 703 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); | 705 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); |
| 704 #else | 706 #else |
| 705 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); | 707 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); |
| 706 #endif | 708 #endif |
| 707 input_handler_.set_input_stub(normalizing_input_filter_.get()); | 709 input_handler_.set_input_stub(normalizing_input_filter_.get()); |
| 708 | 710 |
| 709 ConnectWithConfig(config, local_jid); | |
| 710 } | |
| 711 | |
| 712 void ChromotingInstance::ConnectWithConfig(const ClientConfig& config, | |
| 713 const std::string& local_jid) { | |
| 714 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | |
| 715 | |
| 716 if (use_media_source_rendering_) { | 711 if (use_media_source_rendering_) { |
| 717 video_renderer_.reset(new MediaSourceVideoRenderer(this)); | 712 video_renderer_.reset(new MediaSourceVideoRenderer(this)); |
| 718 } else { | 713 } else { |
| 719 view_.reset(new PepperView(this, &context_)); | 714 view_.reset(new PepperView(this, &context_)); |
| 720 view_weak_factory_.reset( | 715 view_weak_factory_.reset( |
| 721 new base::WeakPtrFactory<FrameConsumer>(view_.get())); | 716 new base::WeakPtrFactory<FrameConsumer>(view_.get())); |
| 722 | 717 |
| 723 // SoftwareVideoRenderer runs on a separate thread so for now we wrap | 718 // SoftwareVideoRenderer runs on a separate thread so for now we wrap |
| 724 // PepperView with a ref-counted proxy object. | 719 // PepperView with a ref-counted proxy object. |
| 725 scoped_refptr<FrameConsumerProxy> consumer_proxy = | 720 scoped_refptr<FrameConsumerProxy> consumer_proxy = |
| 726 new FrameConsumerProxy(plugin_task_runner_, | 721 new FrameConsumerProxy(plugin_task_runner_, |
| 727 view_weak_factory_->GetWeakPtr()); | 722 view_weak_factory_->GetWeakPtr()); |
| 728 | 723 |
| 729 SoftwareVideoRenderer* renderer = | 724 SoftwareVideoRenderer* renderer = |
| 730 new SoftwareVideoRenderer(context_.main_task_runner(), | 725 new SoftwareVideoRenderer(context_.main_task_runner(), |
| 731 context_.decode_task_runner(), | 726 context_.decode_task_runner(), |
| 732 consumer_proxy); | 727 consumer_proxy); |
| 733 view_->Initialize(renderer); | 728 view_->Initialize(renderer); |
| 734 if (!plugin_view_.is_null()) | 729 if (!plugin_view_.is_null()) |
| 735 view_->SetView(plugin_view_); | 730 view_->SetView(plugin_view_); |
| 736 video_renderer_.reset(renderer); | 731 video_renderer_.reset(renderer); |
| 737 } | 732 } |
| 738 | 733 |
| 739 host_connection_.reset(new protocol::ConnectionToHost(true)); | |
| 740 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); | 734 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); |
| 741 client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), | 735 client_.reset(new ChromotingClient(&context_, this, video_renderer_.get(), |
| 742 this, video_renderer_.get(), | |
| 743 audio_player.Pass())); | 736 audio_player.Pass())); |
| 744 | 737 |
| 745 // Connect the input pipeline to the protocol stub & initialize components. | 738 // Connect the input pipeline to the protocol stub & initialize components. |
| 746 mouse_input_filter_.set_input_stub(host_connection_->input_stub()); | 739 mouse_input_filter_.set_input_stub(client_->input_stub()); |
| 747 if (!plugin_view_.is_null()) { | 740 if (!plugin_view_.is_null()) { |
| 748 mouse_input_filter_.set_input_size(webrtc::DesktopSize( | 741 mouse_input_filter_.set_input_size(webrtc::DesktopSize( |
| 749 plugin_view_.GetRect().width(), plugin_view_.GetRect().height())); | 742 plugin_view_.GetRect().width(), plugin_view_.GetRect().height())); |
| 750 } | 743 } |
| 751 | 744 |
| 752 VLOG(0) << "Connecting to " << config.host_jid | |
| 753 << ". Local jid: " << local_jid << "."; | |
| 754 | |
| 755 // Setup the signal strategy. | 745 // Setup the signal strategy. |
| 756 signal_strategy_.reset(new DelegatingSignalStrategy( | 746 signal_strategy_.reset(new DelegatingSignalStrategy( |
| 757 local_jid, base::Bind(&ChromotingInstance::SendOutgoingIq, | 747 local_jid, base::Bind(&ChromotingInstance::SendOutgoingIq, |
| 758 weak_factory_.GetWeakPtr()))); | 748 weak_factory_.GetWeakPtr()))); |
| 759 | 749 |
| 760 scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator( | 750 // Create TransportFactory. |
| 761 PepperPortAllocator::Create(this)); | |
| 762 scoped_ptr<protocol::TransportFactory> transport_factory( | 751 scoped_ptr<protocol::TransportFactory> transport_factory( |
| 763 new protocol::LibjingleTransportFactory( | 752 new protocol::LibjingleTransportFactory( |
| 764 signal_strategy_.get(), port_allocator.Pass(), | 753 signal_strategy_.get(), |
| 754 PepperPortAllocator::Create(this) |
| 755 .PassAs<cricket::HttpPortAllocatorBase>(), |
| 765 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_FULL))); | 756 NetworkSettings(NetworkSettings::NAT_TRAVERSAL_FULL))); |
| 766 | 757 |
| 758 // Create Authenticator. |
| 759 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
| 760 token_fetcher(new TokenFetcherProxy( |
| 761 base::Bind(&ChromotingInstance::FetchThirdPartyToken, |
| 762 weak_factory_.GetWeakPtr()), |
| 763 host_public_key)); |
| 764 scoped_ptr<protocol::Authenticator> authenticator( |
| 765 new protocol::NegotiatingClientAuthenticator( |
| 766 client_pairing_id, client_paired_secret, authentication_tag, |
| 767 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); |
| 768 |
| 767 // Kick off the connection. | 769 // Kick off the connection. |
| 768 client_->Start(signal_strategy_.get(), transport_factory.Pass()); | 770 client_->Start(signal_strategy_.get(), authenticator.Pass(), |
| 771 transport_factory.Pass(), host_jid, capabilities); |
| 769 | 772 |
| 770 // Start timer that periodically sends perf stats. | 773 // Start timer that periodically sends perf stats. |
| 771 plugin_task_runner_->PostDelayedTask( | 774 plugin_task_runner_->PostDelayedTask( |
| 772 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, | 775 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, |
| 773 weak_factory_.GetWeakPtr()), | 776 weak_factory_.GetWeakPtr()), |
| 774 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 777 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 775 } | 778 } |
| 776 | 779 |
| 777 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { | 780 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { |
| 778 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 781 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 779 | 782 |
| 780 // PepperView must be destroyed before the client. | 783 // PepperView must be destroyed before the client. |
| 781 view_weak_factory_.reset(); | 784 view_weak_factory_.reset(); |
| 782 view_.reset(); | 785 view_.reset(); |
| 783 | 786 |
| 784 VLOG(0) << "Disconnecting from host."; | 787 VLOG(0) << "Disconnecting from host."; |
| 785 | 788 |
| 786 client_.reset(); | |
| 787 | |
| 788 // Disconnect the input pipeline and teardown the connection. | 789 // Disconnect the input pipeline and teardown the connection. |
| 789 mouse_input_filter_.set_input_stub(NULL); | 790 mouse_input_filter_.set_input_stub(NULL); |
| 790 host_connection_.reset(); | 791 client_.reset(); |
| 791 } | 792 } |
| 792 | 793 |
| 793 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { | 794 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { |
| 794 std::string iq; | 795 std::string iq; |
| 795 if (!data.GetString("iq", &iq)) { | 796 if (!data.GetString("iq", &iq)) { |
| 796 LOG(ERROR) << "Invalid incomingIq() data."; | 797 LOG(ERROR) << "Invalid incomingIq() data."; |
| 797 return; | 798 return; |
| 798 } | 799 } |
| 799 | 800 |
| 800 // Just ignore the message if it's received before Connect() is called. It's | 801 // Just ignore the message if it's received before Connect() is called. It's |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 !data.GetString("item", &item)) { | 861 !data.GetString("item", &item)) { |
| 861 LOG(ERROR) << "Invalid sendClipboardItem data."; | 862 LOG(ERROR) << "Invalid sendClipboardItem data."; |
| 862 return; | 863 return; |
| 863 } | 864 } |
| 864 if (!IsConnected()) { | 865 if (!IsConnected()) { |
| 865 return; | 866 return; |
| 866 } | 867 } |
| 867 protocol::ClipboardEvent event; | 868 protocol::ClipboardEvent event; |
| 868 event.set_mime_type(mime_type); | 869 event.set_mime_type(mime_type); |
| 869 event.set_data(item); | 870 event.set_data(item); |
| 870 host_connection_->clipboard_forwarder()->InjectClipboardEvent(event); | 871 client_->clipboard_forwarder()->InjectClipboardEvent(event); |
| 871 } | 872 } |
| 872 | 873 |
| 873 void ChromotingInstance::HandleNotifyClientResolution( | 874 void ChromotingInstance::HandleNotifyClientResolution( |
| 874 const base::DictionaryValue& data) { | 875 const base::DictionaryValue& data) { |
| 875 int width = 0; | 876 int width = 0; |
| 876 int height = 0; | 877 int height = 0; |
| 877 int x_dpi = kDefaultDPI; | 878 int x_dpi = kDefaultDPI; |
| 878 int y_dpi = kDefaultDPI; | 879 int y_dpi = kDefaultDPI; |
| 879 if (!data.GetInteger("width", &width) || | 880 if (!data.GetInteger("width", &width) || |
| 880 !data.GetInteger("height", &height) || | 881 !data.GetInteger("height", &height) || |
| (...skipping 12 matching lines...) Expand all Loading... |
| 893 protocol::ClientResolution client_resolution; | 894 protocol::ClientResolution client_resolution; |
| 894 client_resolution.set_width(width); | 895 client_resolution.set_width(width); |
| 895 client_resolution.set_height(height); | 896 client_resolution.set_height(height); |
| 896 client_resolution.set_x_dpi(x_dpi); | 897 client_resolution.set_x_dpi(x_dpi); |
| 897 client_resolution.set_y_dpi(y_dpi); | 898 client_resolution.set_y_dpi(y_dpi); |
| 898 | 899 |
| 899 // Include the legacy width & height in DIPs for use by older hosts. | 900 // Include the legacy width & height in DIPs for use by older hosts. |
| 900 client_resolution.set_dips_width((width * kDefaultDPI) / x_dpi); | 901 client_resolution.set_dips_width((width * kDefaultDPI) / x_dpi); |
| 901 client_resolution.set_dips_height((height * kDefaultDPI) / y_dpi); | 902 client_resolution.set_dips_height((height * kDefaultDPI) / y_dpi); |
| 902 | 903 |
| 903 host_connection_->host_stub()->NotifyClientResolution(client_resolution); | 904 client_->host_stub()->NotifyClientResolution(client_resolution); |
| 904 } | 905 } |
| 905 | 906 |
| 906 void ChromotingInstance::HandlePauseVideo(const base::DictionaryValue& data) { | 907 void ChromotingInstance::HandlePauseVideo(const base::DictionaryValue& data) { |
| 907 if (!data.HasKey("pause")) { | 908 if (!data.HasKey("pause")) { |
| 908 LOG(ERROR) << "Invalid pauseVideo."; | 909 LOG(ERROR) << "Invalid pauseVideo."; |
| 909 return; | 910 return; |
| 910 } | 911 } |
| 911 HandleVideoControl(data); | 912 HandleVideoControl(data); |
| 912 } | 913 } |
| 913 | 914 |
| 914 void ChromotingInstance::HandleVideoControl(const base::DictionaryValue& data) { | 915 void ChromotingInstance::HandleVideoControl(const base::DictionaryValue& data) { |
| 915 protocol::VideoControl video_control; | 916 protocol::VideoControl video_control; |
| 916 bool pause_video = false; | 917 bool pause_video = false; |
| 917 if (data.GetBoolean("pause", &pause_video)) { | 918 if (data.GetBoolean("pause", &pause_video)) { |
| 918 video_control.set_enable(!pause_video); | 919 video_control.set_enable(!pause_video); |
| 919 } | 920 } |
| 920 bool lossless_encode = false; | 921 bool lossless_encode = false; |
| 921 if (data.GetBoolean("losslessEncode", &lossless_encode)) { | 922 if (data.GetBoolean("losslessEncode", &lossless_encode)) { |
| 922 video_control.set_lossless_encode(lossless_encode); | 923 video_control.set_lossless_encode(lossless_encode); |
| 923 } | 924 } |
| 924 bool lossless_color = false; | 925 bool lossless_color = false; |
| 925 if (data.GetBoolean("losslessColor", &lossless_color)) { | 926 if (data.GetBoolean("losslessColor", &lossless_color)) { |
| 926 video_control.set_lossless_color(lossless_color); | 927 video_control.set_lossless_color(lossless_color); |
| 927 } | 928 } |
| 928 if (!IsConnected()) { | 929 if (!IsConnected()) { |
| 929 return; | 930 return; |
| 930 } | 931 } |
| 931 host_connection_->host_stub()->ControlVideo(video_control); | 932 client_->host_stub()->ControlVideo(video_control); |
| 932 } | 933 } |
| 933 | 934 |
| 934 void ChromotingInstance::HandlePauseAudio(const base::DictionaryValue& data) { | 935 void ChromotingInstance::HandlePauseAudio(const base::DictionaryValue& data) { |
| 935 bool pause = false; | 936 bool pause = false; |
| 936 if (!data.GetBoolean("pause", &pause)) { | 937 if (!data.GetBoolean("pause", &pause)) { |
| 937 LOG(ERROR) << "Invalid pauseAudio."; | 938 LOG(ERROR) << "Invalid pauseAudio."; |
| 938 return; | 939 return; |
| 939 } | 940 } |
| 940 if (!IsConnected()) { | 941 if (!IsConnected()) { |
| 941 return; | 942 return; |
| 942 } | 943 } |
| 943 protocol::AudioControl audio_control; | 944 protocol::AudioControl audio_control; |
| 944 audio_control.set_enable(!pause); | 945 audio_control.set_enable(!pause); |
| 945 host_connection_->host_stub()->ControlAudio(audio_control); | 946 client_->host_stub()->ControlAudio(audio_control); |
| 946 } | 947 } |
| 947 void ChromotingInstance::HandleOnPinFetched(const base::DictionaryValue& data) { | 948 void ChromotingInstance::HandleOnPinFetched(const base::DictionaryValue& data) { |
| 948 std::string pin; | 949 std::string pin; |
| 949 if (!data.GetString("pin", &pin)) { | 950 if (!data.GetString("pin", &pin)) { |
| 950 LOG(ERROR) << "Invalid onPinFetched."; | 951 LOG(ERROR) << "Invalid onPinFetched."; |
| 951 return; | 952 return; |
| 952 } | 953 } |
| 953 if (!secret_fetched_callback_.is_null()) { | 954 if (!secret_fetched_callback_.is_null()) { |
| 954 secret_fetched_callback_.Run(pin); | 955 secret_fetched_callback_.Run(pin); |
| 955 secret_fetched_callback_.Reset(); | 956 secret_fetched_callback_.Reset(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 980 std::string client_name; | 981 std::string client_name; |
| 981 if (!data.GetString("clientName", &client_name)) { | 982 if (!data.GetString("clientName", &client_name)) { |
| 982 LOG(ERROR) << "Invalid requestPairing"; | 983 LOG(ERROR) << "Invalid requestPairing"; |
| 983 return; | 984 return; |
| 984 } | 985 } |
| 985 if (!IsConnected()) { | 986 if (!IsConnected()) { |
| 986 return; | 987 return; |
| 987 } | 988 } |
| 988 protocol::PairingRequest pairing_request; | 989 protocol::PairingRequest pairing_request; |
| 989 pairing_request.set_client_name(client_name); | 990 pairing_request.set_client_name(client_name); |
| 990 host_connection_->host_stub()->RequestPairing(pairing_request); | 991 client_->host_stub()->RequestPairing(pairing_request); |
| 991 } | 992 } |
| 992 | 993 |
| 993 void ChromotingInstance::HandleExtensionMessage( | 994 void ChromotingInstance::HandleExtensionMessage( |
| 994 const base::DictionaryValue& data) { | 995 const base::DictionaryValue& data) { |
| 995 std::string type; | 996 std::string type; |
| 996 std::string message_data; | 997 std::string message_data; |
| 997 if (!data.GetString("type", &type) || | 998 if (!data.GetString("type", &type) || |
| 998 !data.GetString("data", &message_data)) { | 999 !data.GetString("data", &message_data)) { |
| 999 LOG(ERROR) << "Invalid extensionMessage."; | 1000 LOG(ERROR) << "Invalid extensionMessage."; |
| 1000 return; | 1001 return; |
| 1001 } | 1002 } |
| 1002 if (!IsConnected()) { | 1003 if (!IsConnected()) { |
| 1003 return; | 1004 return; |
| 1004 } | 1005 } |
| 1005 protocol::ExtensionMessage message; | 1006 protocol::ExtensionMessage message; |
| 1006 message.set_type(type); | 1007 message.set_type(type); |
| 1007 message.set_data(message_data); | 1008 message.set_data(message_data); |
| 1008 host_connection_->host_stub()->DeliverClientMessage(message); | 1009 client_->host_stub()->DeliverClientMessage(message); |
| 1009 } | 1010 } |
| 1010 | 1011 |
| 1011 void ChromotingInstance::HandleAllowMouseLockMessage() { | 1012 void ChromotingInstance::HandleAllowMouseLockMessage() { |
| 1012 input_handler_.AllowMouseLock(); | 1013 input_handler_.AllowMouseLock(); |
| 1013 } | 1014 } |
| 1014 | 1015 |
| 1015 void ChromotingInstance::HandleEnableMediaSourceRendering() { | 1016 void ChromotingInstance::HandleEnableMediaSourceRendering() { |
| 1016 use_media_source_rendering_ = true; | 1017 use_media_source_rendering_ = true; |
| 1017 } | 1018 } |
| 1018 | 1019 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 if (!url_var.is_string()) | 1198 if (!url_var.is_string()) |
| 1198 return false; | 1199 return false; |
| 1199 | 1200 |
| 1200 std::string url = url_var.AsString(); | 1201 std::string url = url_var.AsString(); |
| 1201 std::string url_scheme = url.substr(url_components.scheme.begin, | 1202 std::string url_scheme = url.substr(url_components.scheme.begin, |
| 1202 url_components.scheme.len); | 1203 url_components.scheme.len); |
| 1203 return url_scheme == kChromeExtensionUrlScheme; | 1204 return url_scheme == kChromeExtensionUrlScheme; |
| 1204 } | 1205 } |
| 1205 | 1206 |
| 1206 bool ChromotingInstance::IsConnected() { | 1207 bool ChromotingInstance::IsConnected() { |
| 1207 return host_connection_.get() && | 1208 return client_ && |
| 1208 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 1209 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); |
| 1209 } | 1210 } |
| 1210 | 1211 |
| 1211 void ChromotingInstance::OnMediaSourceSize(const webrtc::DesktopSize& size, | 1212 void ChromotingInstance::OnMediaSourceSize(const webrtc::DesktopSize& size, |
| 1212 const webrtc::DesktopVector& dpi) { | 1213 const webrtc::DesktopVector& dpi) { |
| 1213 SetDesktopSize(size, dpi); | 1214 SetDesktopSize(size, dpi); |
| 1214 } | 1215 } |
| 1215 | 1216 |
| 1216 void ChromotingInstance::OnMediaSourceShape( | 1217 void ChromotingInstance::OnMediaSourceShape( |
| 1217 const webrtc::DesktopRegion& shape) { | 1218 const webrtc::DesktopRegion& shape) { |
| 1218 SetDesktopShape(shape); | 1219 SetDesktopShape(shape); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1230 void* data_ptr = array_buffer.Map(); | 1231 void* data_ptr = array_buffer.Map(); |
| 1231 memcpy(data_ptr, buffer, buffer_size); | 1232 memcpy(data_ptr, buffer, buffer_size); |
| 1232 array_buffer.Unmap(); | 1233 array_buffer.Unmap(); |
| 1233 pp::VarDictionary data_dictionary; | 1234 pp::VarDictionary data_dictionary; |
| 1234 data_dictionary.Set(pp::Var("buffer"), array_buffer); | 1235 data_dictionary.Set(pp::Var("buffer"), array_buffer); |
| 1235 data_dictionary.Set(pp::Var("keyframe"), keyframe); | 1236 data_dictionary.Set(pp::Var("keyframe"), keyframe); |
| 1236 PostChromotingMessage("mediaSourceData", data_dictionary); | 1237 PostChromotingMessage("mediaSourceData", data_dictionary); |
| 1237 } | 1238 } |
| 1238 | 1239 |
| 1239 } // namespace remoting | 1240 } // namespace remoting |
| OLD | NEW |