Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "googleurl/src/gurl.h" | |
| 22 #include "jingle/glue/thread_wrapper.h" | 23 #include "jingle/glue/thread_wrapper.h" |
| 23 #include "media/base/media.h" | 24 #include "media/base/media.h" |
| 24 #include "net/socket/ssl_server_socket.h" | 25 #include "net/socket/ssl_server_socket.h" |
| 25 #include "ppapi/cpp/completion_callback.h" | 26 #include "ppapi/cpp/completion_callback.h" |
| 26 #include "ppapi/cpp/dev/url_util_dev.h" | 27 #include "ppapi/cpp/dev/url_util_dev.h" |
| 27 #include "ppapi/cpp/input_event.h" | 28 #include "ppapi/cpp/input_event.h" |
| 28 #include "ppapi/cpp/mouse_cursor.h" | 29 #include "ppapi/cpp/mouse_cursor.h" |
| 29 #include "ppapi/cpp/rect.h" | 30 #include "ppapi/cpp/rect.h" |
| 30 #include "remoting/base/constants.h" | 31 #include "remoting/base/constants.h" |
| 31 #include "remoting/base/util.h" | 32 #include "remoting/base/util.h" |
| 32 #include "remoting/client/chromoting_client.h" | 33 #include "remoting/client/chromoting_client.h" |
| 33 #include "remoting/client/client_config.h" | 34 #include "remoting/client/client_config.h" |
| 34 #include "remoting/client/frame_consumer_proxy.h" | 35 #include "remoting/client/frame_consumer_proxy.h" |
| 35 #include "remoting/client/plugin/pepper_audio_player.h" | 36 #include "remoting/client/plugin/pepper_audio_player.h" |
| 36 #include "remoting/client/plugin/pepper_input_handler.h" | 37 #include "remoting/client/plugin/pepper_input_handler.h" |
| 37 #include "remoting/client/plugin/pepper_port_allocator.h" | 38 #include "remoting/client/plugin/pepper_port_allocator.h" |
| 39 #include "remoting/client/plugin/pepper_token_fetcher.h" | |
| 38 #include "remoting/client/plugin/pepper_view.h" | 40 #include "remoting/client/plugin/pepper_view.h" |
| 39 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 41 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
| 40 #include "remoting/client/rectangle_update_decoder.h" | 42 #include "remoting/client/rectangle_update_decoder.h" |
| 41 #include "remoting/protocol/connection_to_host.h" | 43 #include "remoting/protocol/connection_to_host.h" |
| 42 #include "remoting/protocol/host_stub.h" | 44 #include "remoting/protocol/host_stub.h" |
| 43 #include "remoting/protocol/libjingle_transport_factory.h" | 45 #include "remoting/protocol/libjingle_transport_factory.h" |
| 44 | 46 |
| 45 // Windows defines 'PostMessage', so we have to undef it. | 47 // Windows defines 'PostMessage', so we have to undef it. |
| 46 #if defined(PostMessage) | 48 #if defined(PostMessage) |
| 47 #undef PostMessage | 49 #undef PostMessage |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 base::LazyInstance<base::Lock>::Leaky | 130 base::LazyInstance<base::Lock>::Leaky |
| 129 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 131 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
| 130 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 132 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| 131 | 133 |
| 132 } // namespace | 134 } // namespace |
| 133 | 135 |
| 134 // String sent in the "hello" message to the plugin to describe features. | 136 // String sent in the "hello" message to the plugin to describe features. |
| 135 const char ChromotingInstance::kApiFeatures[] = | 137 const char ChromotingInstance::kApiFeatures[] = |
| 136 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 138 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
| 137 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " | 139 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " |
| 138 "asyncPin"; | 140 "asyncPin thirdPartyAuth"; |
| 139 | 141 |
| 140 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | 142 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, |
| 141 ClientConfig* config) { | 143 ClientConfig* config) { |
| 142 std::vector<std::string> auth_methods; | 144 std::vector<std::string> auth_methods; |
| 143 base::SplitString(auth_methods_str, ',', &auth_methods); | 145 base::SplitString(auth_methods_str, ',', &auth_methods); |
| 144 for (std::vector<std::string>::iterator it = auth_methods.begin(); | 146 for (std::vector<std::string>::iterator it = auth_methods.begin(); |
| 145 it != auth_methods.end(); ++it) { | 147 it != auth_methods.end(); ++it) { |
| 146 protocol::AuthenticationMethod authentication_method = | 148 protocol::AuthenticationMethod authentication_method = |
| 147 protocol::AuthenticationMethod::FromString(*it); | 149 protocol::AuthenticationMethod::FromString(*it); |
| 148 if (authentication_method.is_valid()) | 150 if (authentication_method.is_valid()) |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 PauseAudio(pause); | 390 PauseAudio(pause); |
| 389 } else if (method == "useAsyncPinDialog") { | 391 } else if (method == "useAsyncPinDialog") { |
| 390 use_async_pin_dialog_ = true; | 392 use_async_pin_dialog_ = true; |
| 391 } else if (method == "onPinFetched") { | 393 } else if (method == "onPinFetched") { |
| 392 std::string pin; | 394 std::string pin; |
| 393 if (!data->GetString("pin", &pin)) { | 395 if (!data->GetString("pin", &pin)) { |
| 394 LOG(ERROR) << "Invalid onPinFetched."; | 396 LOG(ERROR) << "Invalid onPinFetched."; |
| 395 return; | 397 return; |
| 396 } | 398 } |
| 397 OnPinFetched(pin); | 399 OnPinFetched(pin); |
| 400 } else if (method == "onThirdPartyTokenFetched") { | |
| 401 std::string token; | |
| 402 std::string shared_secret; | |
| 403 if (!data->GetString("token", &token) || | |
| 404 !data->GetString("sharedSecret", &shared_secret)) { | |
| 405 LOG(ERROR) << "Invalid onThirdPartyTokenFetched data."; | |
| 406 return; | |
| 407 } | |
| 408 OnThirdPartyTokenFetched(token, shared_secret); | |
| 398 } | 409 } |
| 399 } | 410 } |
| 400 | 411 |
| 401 void ChromotingInstance::DidChangeView(const pp::View& view) { | 412 void ChromotingInstance::DidChangeView(const pp::View& view) { |
| 402 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 413 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 403 | 414 |
| 404 plugin_view_ = view; | 415 plugin_view_ = view; |
| 405 if (view_) { | 416 if (view_) { |
| 406 view_->SetView(view); | 417 view_->SetView(view); |
| 407 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); | 418 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 433 | 444 |
| 434 void ChromotingInstance::OnConnectionState( | 445 void ChromotingInstance::OnConnectionState( |
| 435 protocol::ConnectionToHost::State state, | 446 protocol::ConnectionToHost::State state, |
| 436 protocol::ErrorCode error) { | 447 protocol::ErrorCode error) { |
| 437 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 448 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 438 data->SetString("state", ConnectionStateToString(state)); | 449 data->SetString("state", ConnectionStateToString(state)); |
| 439 data->SetString("error", ConnectionErrorToString(error)); | 450 data->SetString("error", ConnectionErrorToString(error)); |
| 440 PostChromotingMessage("onConnectionStatus", data.Pass()); | 451 PostChromotingMessage("onConnectionStatus", data.Pass()); |
| 441 } | 452 } |
| 442 | 453 |
| 454 void ChromotingInstance::FetchThirdPartyToken( | |
| 455 const GURL& token_url, | |
| 456 const std::string& host_public_key, | |
| 457 const std::string& scope, | |
| 458 base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher) { | |
| 459 // Once the Session object calls this function, it won't continue the | |
| 460 // authentication until the callback is called (or connection is canceled). | |
| 461 // So, it's impossible to reach this with a callback already registered. | |
| 462 DCHECK(!pepper_token_fetcher_); | |
| 463 pepper_token_fetcher_ = pepper_token_fetcher; | |
| 464 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | |
| 465 data->SetString("tokenUrl", token_url.spec()); | |
| 466 data->SetString("hostPublicKey", host_public_key); | |
| 467 data->SetString("scope", scope); | |
| 468 PostChromotingMessage("fetchThirdPartyToken", data.Pass()); | |
| 469 } | |
| 470 | |
| 443 void ChromotingInstance::OnConnectionReady(bool ready) { | 471 void ChromotingInstance::OnConnectionReady(bool ready) { |
| 444 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 472 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 445 data->SetBoolean("ready", ready); | 473 data->SetBoolean("ready", ready); |
| 446 PostChromotingMessage("onConnectionReady", data.Pass()); | 474 PostChromotingMessage("onConnectionReady", data.Pass()); |
| 447 } | 475 } |
| 448 | 476 |
| 449 void ChromotingInstance::FetchSecretFromDialog( | 477 void ChromotingInstance::FetchSecretFromDialog( |
| 450 const protocol::SecretFetchedCallback& secret_fetched_callback) { | 478 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
| 451 // Once the Session object calls this function, it won't continue the | 479 // Once the Session object calls this function, it won't continue the |
| 452 // authentication until the callback is called (or connection is canceled). | 480 // authentication until the callback is called (or connection is canceled). |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 468 // crbug.com/138108 | 496 // crbug.com/138108 |
| 469 return this; | 497 return this; |
| 470 } | 498 } |
| 471 | 499 |
| 472 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { | 500 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { |
| 473 // TODO(sergeyu): Move cursor shape code to a separate class. | 501 // TODO(sergeyu): Move cursor shape code to a separate class. |
| 474 // crbug.com/138108 | 502 // crbug.com/138108 |
| 475 return this; | 503 return this; |
| 476 } | 504 } |
| 477 | 505 |
| 506 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | |
| 507 ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) { | |
| 508 return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>( | |
| 509 new PepperTokenFetcher(this->AsWeakPtr(), host_public_key)); | |
| 510 } | |
| 511 | |
| 478 void ChromotingInstance::InjectClipboardEvent( | 512 void ChromotingInstance::InjectClipboardEvent( |
| 479 const protocol::ClipboardEvent& event) { | 513 const protocol::ClipboardEvent& event) { |
| 480 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 514 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 481 data->SetString("mimeType", event.mime_type()); | 515 data->SetString("mimeType", event.mime_type()); |
| 482 data->SetString("item", event.data()); | 516 data->SetString("item", event.data()); |
| 483 PostChromotingMessage("injectClipboardItem", data.Pass()); | 517 PostChromotingMessage("injectClipboardItem", data.Pass()); |
| 484 } | 518 } |
| 485 | 519 |
| 486 void ChromotingInstance::SetCursorShape( | 520 void ChromotingInstance::SetCursorShape( |
| 487 const protocol::CursorShapeInfo& cursor_shape) { | 521 const protocol::CursorShapeInfo& cursor_shape) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 } | 715 } |
| 682 | 716 |
| 683 void ChromotingInstance::PauseAudio(bool pause) { | 717 void ChromotingInstance::PauseAudio(bool pause) { |
| 684 if (!IsConnected()) { | 718 if (!IsConnected()) { |
| 685 return; | 719 return; |
| 686 } | 720 } |
| 687 protocol::AudioControl audio_control; | 721 protocol::AudioControl audio_control; |
| 688 audio_control.set_enable(!pause); | 722 audio_control.set_enable(!pause); |
| 689 host_connection_->host_stub()->ControlAudio(audio_control); | 723 host_connection_->host_stub()->ControlAudio(audio_control); |
| 690 } | 724 } |
| 691 | |
| 692 void ChromotingInstance::OnPinFetched(const std::string& pin) { | 725 void ChromotingInstance::OnPinFetched(const std::string& pin) { |
| 693 if (!secret_fetched_callback_.is_null()) { | 726 if (!secret_fetched_callback_.is_null()) { |
| 694 secret_fetched_callback_.Run(pin); | 727 secret_fetched_callback_.Run(pin); |
| 695 secret_fetched_callback_.Reset(); | 728 secret_fetched_callback_.Reset(); |
| 696 } else { | 729 } else { |
| 697 VLOG(1) << "Ignored OnPinFetched received without a pending fetch."; | 730 VLOG(1) << "Ignored OnPinFetched received without a pending fetch."; |
| 698 } | 731 } |
| 699 } | 732 } |
| 700 | 733 |
| 734 void ChromotingInstance::OnThirdPartyTokenFetched( | |
| 735 const std::string& token, | |
| 736 const std::string& shared_secret) { | |
| 737 if (pepper_token_fetcher_) { | |
| 738 pepper_token_fetcher_->OnTokenFetched(token, shared_secret); | |
| 739 pepper_token_fetcher_.reset(); | |
| 740 } else { | |
| 741 VLOG(1) << "Ignored OnThirdPartyTokenFetched without a pending fetch."; | |
|
Sergey Ulanov
2013/04/05 18:34:57
might be better to use LOG(WARNING) here.
rmsousa
2013/04/06 01:11:03
Done. Changed the pin fetcher one as well.
| |
| 742 } | |
| 743 } | |
| 744 | |
| 701 ChromotingStats* ChromotingInstance::GetStats() { | 745 ChromotingStats* ChromotingInstance::GetStats() { |
| 702 if (!client_.get()) | 746 if (!client_.get()) |
| 703 return NULL; | 747 return NULL; |
| 704 return client_->GetStats(); | 748 return client_->GetStats(); |
| 705 } | 749 } |
| 706 | 750 |
| 707 void ChromotingInstance::PostChromotingMessage( | 751 void ChromotingInstance::PostChromotingMessage( |
| 708 const std::string& method, | 752 const std::string& method, |
| 709 scoped_ptr<base::DictionaryValue> data) { | 753 scoped_ptr<base::DictionaryValue> data) { |
| 710 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 754 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 url_components.scheme.len); | 911 url_components.scheme.len); |
| 868 return url_scheme == kChromeExtensionUrlScheme; | 912 return url_scheme == kChromeExtensionUrlScheme; |
| 869 } | 913 } |
| 870 | 914 |
| 871 bool ChromotingInstance::IsConnected() { | 915 bool ChromotingInstance::IsConnected() { |
| 872 return host_connection_.get() && | 916 return host_connection_.get() && |
| 873 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 917 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); |
| 874 } | 918 } |
| 875 | 919 |
| 876 } // namespace remoting | 920 } // namespace remoting |
| OLD | NEW |