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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 g_logging_instance = LAZY_INSTANCE_INITIALIZER; | 127 g_logging_instance = LAZY_INSTANCE_INITIALIZER; |
| 128 base::LazyInstance<base::Lock>::Leaky | 128 base::LazyInstance<base::Lock>::Leaky |
| 129 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 129 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
| 130 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 130 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 // String sent in the "hello" message to the plugin to describe features. | 134 // String sent in the "hello" message to the plugin to describe features. |
| 135 const char ChromotingInstance::kApiFeatures[] = | 135 const char ChromotingInstance::kApiFeatures[] = |
| 136 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 136 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
| 137 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio"; | 137 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " |
| 138 "asyncPin"; | |
| 138 | 139 |
| 139 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | 140 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, |
| 140 ClientConfig* config) { | 141 ClientConfig* config) { |
| 141 std::vector<std::string> auth_methods; | 142 std::vector<std::string> auth_methods; |
| 142 base::SplitString(auth_methods_str, ',', &auth_methods); | 143 base::SplitString(auth_methods_str, ',', &auth_methods); |
| 143 for (std::vector<std::string>::iterator it = auth_methods.begin(); | 144 for (std::vector<std::string>::iterator it = auth_methods.begin(); |
| 144 it != auth_methods.end(); ++it) { | 145 it != auth_methods.end(); ++it) { |
| 145 protocol::AuthenticationMethod authentication_method = | 146 protocol::AuthenticationMethod authentication_method = |
| 146 protocol::AuthenticationMethod::FromString(*it); | 147 protocol::AuthenticationMethod::FromString(*it); |
| 147 if (authentication_method.is_valid()) | 148 if (authentication_method.is_valid()) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 input_tracker_(&mouse_input_filter_), | 165 input_tracker_(&mouse_input_filter_), |
| 165 #if defined(OS_MACOSX) | 166 #if defined(OS_MACOSX) |
| 166 // On Mac we need an extra filter to inject missing keyup events. | 167 // On Mac we need an extra filter to inject missing keyup events. |
| 167 // See remoting/client/plugin/mac_key_event_processor.h for more details. | 168 // See remoting/client/plugin/mac_key_event_processor.h for more details. |
| 168 mac_key_event_processor_(&input_tracker_), | 169 mac_key_event_processor_(&input_tracker_), |
| 169 key_mapper_(&mac_key_event_processor_), | 170 key_mapper_(&mac_key_event_processor_), |
| 170 #else | 171 #else |
| 171 key_mapper_(&input_tracker_), | 172 key_mapper_(&input_tracker_), |
| 172 #endif | 173 #endif |
| 173 input_handler_(&key_mapper_), | 174 input_handler_(&key_mapper_), |
| 175 use_async_pin_dialog_(false), | |
| 174 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 176 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 175 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); | 177 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
| 176 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 178 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| 177 | 179 |
| 178 // Resister this instance to handle debug log messsages. | 180 // Resister this instance to handle debug log messsages. |
| 179 RegisterLoggingInstance(); | 181 RegisterLoggingInstance(); |
| 180 | 182 |
| 181 // Send hello message. | 183 // Send hello message. |
| 182 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 184 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 183 data->SetInteger("apiVersion", kApiVersion); | 185 data->SetInteger("apiVersion", kApiVersion); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 LOG(ERROR) << "Received invalid message:" << message.AsString(); | 265 LOG(ERROR) << "Received invalid message:" << message.AsString(); |
| 264 return; | 266 return; |
| 265 } | 267 } |
| 266 | 268 |
| 267 if (method == "connect") { | 269 if (method == "connect") { |
| 268 ClientConfig config; | 270 ClientConfig config; |
| 269 std::string auth_methods; | 271 std::string auth_methods; |
| 270 if (!data->GetString("hostJid", &config.host_jid) || | 272 if (!data->GetString("hostJid", &config.host_jid) || |
| 271 !data->GetString("hostPublicKey", &config.host_public_key) || | 273 !data->GetString("hostPublicKey", &config.host_public_key) || |
| 272 !data->GetString("localJid", &config.local_jid) || | 274 !data->GetString("localJid", &config.local_jid) || |
| 273 !data->GetString("sharedSecret", &config.shared_secret) || | |
| 274 !data->GetString("authenticationMethods", &auth_methods) || | 275 !data->GetString("authenticationMethods", &auth_methods) || |
| 275 !ParseAuthMethods(auth_methods, &config) || | 276 !ParseAuthMethods(auth_methods, &config) || |
| 276 !data->GetString("authenticationTag", &config.authentication_tag)) { | 277 !data->GetString("authenticationTag", &config.authentication_tag)) { |
| 277 LOG(ERROR) << "Invalid connect() data."; | 278 LOG(ERROR) << "Invalid connect() data."; |
| 278 return; | 279 return; |
| 279 } | 280 } |
| 280 | 281 if (use_async_pin_dialog_) { |
| 282 config.fetch_secret_callback = | |
| 283 base::Bind(&ChromotingInstance::FetchSecretFromDialog, | |
| 284 this->AsWeakPtr()); | |
| 285 } else { | |
| 286 std::string shared_secret; | |
| 287 if (!data->GetString("sharedSecret", &shared_secret)) { | |
| 288 LOG(ERROR) << "Invalid connect() data."; | |
| 289 return; | |
| 290 } | |
| 291 config.fetch_secret_callback = | |
| 292 base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); | |
| 293 } | |
| 281 Connect(config); | 294 Connect(config); |
| 282 } else if (method == "disconnect") { | 295 } else if (method == "disconnect") { |
| 283 Disconnect(); | 296 Disconnect(); |
| 284 } else if (method == "incomingIq") { | 297 } else if (method == "incomingIq") { |
| 285 std::string iq; | 298 std::string iq; |
| 286 if (!data->GetString("iq", &iq)) { | 299 if (!data->GetString("iq", &iq)) { |
| 287 LOG(ERROR) << "Invalid onIq() data."; | 300 LOG(ERROR) << "Invalid onIq() data."; |
| 288 return; | 301 return; |
| 289 } | 302 } |
| 290 OnIncomingIq(iq); | 303 OnIncomingIq(iq); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 return; | 379 return; |
| 367 } | 380 } |
| 368 PauseVideo(pause); | 381 PauseVideo(pause); |
| 369 } else if (method == "pauseAudio") { | 382 } else if (method == "pauseAudio") { |
| 370 bool pause = false; | 383 bool pause = false; |
| 371 if (!data->GetBoolean("pause", &pause)) { | 384 if (!data->GetBoolean("pause", &pause)) { |
| 372 LOG(ERROR) << "Invalid pauseAudio."; | 385 LOG(ERROR) << "Invalid pauseAudio."; |
| 373 return; | 386 return; |
| 374 } | 387 } |
| 375 PauseAudio(pause); | 388 PauseAudio(pause); |
| 389 } else if (method == "useAsyncPinDialog") { | |
| 390 use_async_pin_dialog_ = true; | |
| 391 } else if (method == "onPinFetched") { | |
| 392 std::string pin; | |
| 393 if (!data->GetString("pin", &pin)) { | |
| 394 LOG(ERROR) << "Invalid onPinFetched."; | |
| 395 return; | |
| 396 } | |
| 397 OnPinFetched(pin); | |
| 376 } | 398 } |
| 377 } | 399 } |
| 378 | 400 |
| 379 void ChromotingInstance::DidChangeView(const pp::View& view) { | 401 void ChromotingInstance::DidChangeView(const pp::View& view) { |
| 380 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 402 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 381 | 403 |
| 382 plugin_view_ = view; | 404 plugin_view_ = view; |
| 383 if (view_) { | 405 if (view_) { |
| 384 view_->SetView(view); | 406 view_->SetView(view); |
| 385 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); | 407 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 data->SetString("error", ConnectionErrorToString(error)); | 439 data->SetString("error", ConnectionErrorToString(error)); |
| 418 PostChromotingMessage("onConnectionStatus", data.Pass()); | 440 PostChromotingMessage("onConnectionStatus", data.Pass()); |
| 419 } | 441 } |
| 420 | 442 |
| 421 void ChromotingInstance::OnConnectionReady(bool ready) { | 443 void ChromotingInstance::OnConnectionReady(bool ready) { |
| 422 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 444 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 423 data->SetBoolean("ready", ready); | 445 data->SetBoolean("ready", ready); |
| 424 PostChromotingMessage("onConnectionReady", data.Pass()); | 446 PostChromotingMessage("onConnectionReady", data.Pass()); |
| 425 } | 447 } |
| 426 | 448 |
| 449 void ChromotingInstance::FetchSecretFromDialog( | |
| 450 const protocol::SecretFetchedCallback& secret_fetched_callback) { | |
| 451 // Once the Session object calls this function, it won't continue the | |
| 452 // authentication until the callback is called (or connection is canceled). | |
| 453 // So, it's impossible to reach this with a callback already registered. | |
| 454 DCHECK(secret_fetched_callback_.is_null()); | |
| 455 secret_fetched_callback_ = secret_fetched_callback; | |
| 456 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | |
| 457 PostChromotingMessage("fetchPin", data.Pass()); | |
| 458 } | |
| 459 | |
| 460 void ChromotingInstance::FetchSecretFromString( | |
| 461 const std::string& shared_secret, | |
| 462 const protocol::SecretFetchedCallback& secret_fetched_callback) { | |
| 463 secret_fetched_callback.Run(shared_secret); | |
| 464 } | |
| 465 | |
| 427 protocol::ClipboardStub* ChromotingInstance::GetClipboardStub() { | 466 protocol::ClipboardStub* ChromotingInstance::GetClipboardStub() { |
| 428 // TODO(sergeyu): Move clipboard handling to a separate class. | 467 // TODO(sergeyu): Move clipboard handling to a separate class. |
| 429 // crbug.com/138108 | 468 // crbug.com/138108 |
| 430 return this; | 469 return this; |
| 431 } | 470 } |
| 432 | 471 |
| 433 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { | 472 protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { |
| 434 // TODO(sergeyu): Move cursor shape code to a separate class. | 473 // TODO(sergeyu): Move cursor shape code to a separate class. |
| 435 // crbug.com/138108 | 474 // crbug.com/138108 |
| 436 return this; | 475 return this; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 | 682 |
| 644 void ChromotingInstance::PauseAudio(bool pause) { | 683 void ChromotingInstance::PauseAudio(bool pause) { |
| 645 if (!IsConnected()) { | 684 if (!IsConnected()) { |
| 646 return; | 685 return; |
| 647 } | 686 } |
| 648 protocol::AudioControl audio_control; | 687 protocol::AudioControl audio_control; |
| 649 audio_control.set_enable(!pause); | 688 audio_control.set_enable(!pause); |
| 650 host_connection_->host_stub()->ControlAudio(audio_control); | 689 host_connection_->host_stub()->ControlAudio(audio_control); |
| 651 } | 690 } |
| 652 | 691 |
| 692 void ChromotingInstance::OnPinFetched(const std::string& pin) { | |
| 693 if (!secret_fetched_callback_.is_null()) { | |
| 694 secret_fetched_callback_.Run(pin); | |
| 695 secret_fetched_callback_.Reset(); | |
| 696 } else { | |
| 697 VLOG(1) << | |
|
Sergey Ulanov
2013/03/20 05:49:05
nit: operator << should be wrapped when used for I
rmsousa
2013/03/20 20:17:16
Done.
| |
| 698 "Ignored OnPinFetched received without a pending fetch."; | |
| 699 } | |
| 700 } | |
| 701 | |
| 653 ChromotingStats* ChromotingInstance::GetStats() { | 702 ChromotingStats* ChromotingInstance::GetStats() { |
| 654 if (!client_.get()) | 703 if (!client_.get()) |
| 655 return NULL; | 704 return NULL; |
| 656 return client_->GetStats(); | 705 return client_->GetStats(); |
| 657 } | 706 } |
| 658 | 707 |
| 659 void ChromotingInstance::PostChromotingMessage( | 708 void ChromotingInstance::PostChromotingMessage( |
| 660 const std::string& method, | 709 const std::string& method, |
| 661 scoped_ptr<base::DictionaryValue> data) { | 710 scoped_ptr<base::DictionaryValue> data) { |
| 662 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 711 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 url_components.scheme.len); | 868 url_components.scheme.len); |
| 820 return url_scheme == kChromeExtensionUrlScheme; | 869 return url_scheme == kChromeExtensionUrlScheme; |
| 821 } | 870 } |
| 822 | 871 |
| 823 bool ChromotingInstance::IsConnected() { | 872 bool ChromotingInstance::IsConnected() { |
| 824 return host_connection_.get() && | 873 return host_connection_.get() && |
| 825 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 874 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); |
| 826 } | 875 } |
| 827 | 876 |
| 828 } // namespace remoting | 877 } // namespace remoting |
| OLD | NEW |