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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 static bool g_logging_to_plugin = false; | 95 static bool g_logging_to_plugin = false; |
| 96 static bool g_has_logging_instance = false; | 96 static bool g_has_logging_instance = false; |
| 97 static ChromotingInstance* g_logging_instance = NULL; | 97 static ChromotingInstance* g_logging_instance = NULL; |
| 98 static logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 98 static logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| 99 | 99 |
| 100 static base::LazyInstance<base::Lock>::Leaky | 100 static base::LazyInstance<base::Lock>::Leaky |
| 101 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 101 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
| 102 | 102 |
| 103 // String sent in the "hello" message to the plugin to describe features. | 103 // String sent in the "hello" message to the plugin to describe features. |
| 104 const char ChromotingInstance::kApiFeatures[] = | 104 const char ChromotingInstance::kApiFeatures[] = |
| 105 "highQualityScaling injectKeyEvent sendClipboardItem"; | 105 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey"; |
| 106 | 106 |
| 107 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | 107 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, |
| 108 ClientConfig* config) { | 108 ClientConfig* config) { |
| 109 if (auth_methods_str == "v1_token") { | 109 if (auth_methods_str == "v1_token") { |
| 110 config->use_v1_authenticator = true; | 110 config->use_v1_authenticator = true; |
| 111 } else { | 111 } else { |
| 112 config->use_v1_authenticator = false; | 112 config->use_v1_authenticator = false; |
| 113 | 113 |
| 114 std::vector<std::string> auth_methods; | 114 std::vector<std::string> auth_methods; |
| 115 base::SplitString(auth_methods_str, ',', &auth_methods); | 115 base::SplitString(auth_methods_str, ',', &auth_methods); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 LOG(ERROR) << "Invalid injectKeyEvent."; | 262 LOG(ERROR) << "Invalid injectKeyEvent."; |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 | 265 |
| 266 protocol::KeyEvent event; | 266 protocol::KeyEvent event; |
| 267 event.set_usb_keycode(usb_keycode); | 267 event.set_usb_keycode(usb_keycode); |
| 268 event.set_pressed(is_pressed); | 268 event.set_pressed(is_pressed); |
| 269 // Even though new hosts will ignore keycode, it's a required field. | 269 // Even though new hosts will ignore keycode, it's a required field. |
| 270 event.set_keycode(0); | 270 event.set_keycode(0); |
| 271 InjectKeyEvent(event); | 271 InjectKeyEvent(event); |
| 272 } else if (method == "remapKey") { | |
| 273 int from_keycode = 0; | |
| 274 int to_keycode = 0; | |
| 275 if (!data->GetInteger("from_keycode", &from_keycode) || | |
|
Sergey Ulanov
2012/04/07 01:50:14
this should be fromKeycode and toKeycode
Wez
2012/04/08 00:12:41
Done.
Unfortunately injectKeyEvent uses |usb_keyc
| |
| 276 !data->GetInteger("to_keycode", &to_keycode)) { | |
| 277 LOG(ERROR) << "Invalid remapKey."; | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 RemapKey(from_keycode, to_keycode); | |
| 282 } else if (method == "trapKey") { | |
| 283 int keycode = 0; | |
| 284 bool trap = false; | |
| 285 if (!data->GetInteger("keycode", &keycode) || | |
| 286 !data->GetBoolean("trap", &trap)) { | |
| 287 LOG(ERROR) << "Invalid trapKey."; | |
| 288 return; | |
| 289 } | |
| 290 | |
| 291 TrapKey(keycode, trap); | |
| 272 } else if (method == "sendClipboardItem") { | 292 } else if (method == "sendClipboardItem") { |
| 273 std::string mime_type; | 293 std::string mime_type; |
| 274 std::string item; | 294 std::string item; |
| 275 if (!data->GetString("mimeType", &mime_type) || | 295 if (!data->GetString("mimeType", &mime_type) || |
| 276 !data->GetString("item", &item)) { | 296 !data->GetString("item", &item)) { |
| 277 LOG(ERROR) << "Invalid sendClipboardItem() data."; | 297 LOG(ERROR) << "Invalid sendClipboardItem() data."; |
| 278 return; | 298 return; |
| 279 } | 299 } |
| 280 SendClipboardItem(mime_type, item); | 300 SendClipboardItem(mime_type, item); |
| 281 } | 301 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), | 383 client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), |
| 364 view_.get(), rectangle_decoder_.get(), | 384 view_.get(), rectangle_decoder_.get(), |
| 365 base::Closure())); | 385 base::Closure())); |
| 366 | 386 |
| 367 // Construct the input pipeline | 387 // Construct the input pipeline |
| 368 mouse_input_filter_.reset( | 388 mouse_input_filter_.reset( |
| 369 new MouseInputFilter(host_connection_->input_stub())); | 389 new MouseInputFilter(host_connection_->input_stub())); |
| 370 mouse_input_filter_->set_input_size(view_->get_view_size()); | 390 mouse_input_filter_->set_input_size(view_->get_view_size()); |
| 371 input_tracker_.reset( | 391 input_tracker_.reset( |
| 372 new protocol::InputEventTracker(mouse_input_filter_.get())); | 392 new protocol::InputEventTracker(mouse_input_filter_.get())); |
| 393 key_mapper_.set_input_stub(input_tracker_.get()); | |
| 373 input_handler_.reset( | 394 input_handler_.reset( |
| 374 new PepperInputHandler(input_tracker_.get())); | 395 new PepperInputHandler(&key_mapper_)); |
| 375 | 396 |
| 376 LOG(INFO) << "Connecting to " << config.host_jid | 397 LOG(INFO) << "Connecting to " << config.host_jid |
| 377 << ". Local jid: " << config.local_jid << "."; | 398 << ". Local jid: " << config.local_jid << "."; |
| 378 | 399 |
| 379 // Setup the XMPP Proxy. | 400 // Setup the XMPP Proxy. |
| 380 xmpp_proxy_ = new PepperXmppProxy( | 401 xmpp_proxy_ = new PepperXmppProxy( |
| 381 base::Bind(&ChromotingInstance::SendOutgoingIq, AsWeakPtr()), | 402 base::Bind(&ChromotingInstance::SendOutgoingIq, AsWeakPtr()), |
| 382 plugin_message_loop_, | 403 plugin_message_loop_, |
| 383 context_.network_message_loop()); | 404 context_.network_message_loop()); |
| 384 | 405 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 void ChromotingInstance::OnIncomingIq(const std::string& iq) { | 439 void ChromotingInstance::OnIncomingIq(const std::string& iq) { |
| 419 xmpp_proxy_->OnIq(iq); | 440 xmpp_proxy_->OnIq(iq); |
| 420 } | 441 } |
| 421 | 442 |
| 422 void ChromotingInstance::ReleaseAllKeys() { | 443 void ChromotingInstance::ReleaseAllKeys() { |
| 423 if (input_tracker_.get()) | 444 if (input_tracker_.get()) |
| 424 input_tracker_->ReleaseAll(); | 445 input_tracker_->ReleaseAll(); |
| 425 } | 446 } |
| 426 | 447 |
| 427 void ChromotingInstance::InjectKeyEvent(const protocol::KeyEvent& event) { | 448 void ChromotingInstance::InjectKeyEvent(const protocol::KeyEvent& event) { |
| 449 // Inject after the KeyEventMapper, so the event won't get mapped or trapped. | |
| 428 if (input_tracker_.get()) | 450 if (input_tracker_.get()) |
| 429 input_tracker_->InjectKeyEvent(event); | 451 input_tracker_->InjectKeyEvent(event); |
| 430 } | 452 } |
| 431 | 453 |
| 454 void ChromotingInstance::RemapKey(uint32 in_usb_keycode, | |
| 455 uint32 out_usb_keycode) { | |
| 456 key_mapper_.RemapKey(in_usb_keycode, out_usb_keycode); | |
| 457 } | |
| 458 | |
| 459 void ChromotingInstance::TrapKey(uint32 usb_keycode, bool trap) { | |
| 460 key_mapper_.TrapKey(usb_keycode, trap); | |
| 461 } | |
| 462 | |
| 432 void ChromotingInstance::SendClipboardItem(const std::string& mime_type, | 463 void ChromotingInstance::SendClipboardItem(const std::string& mime_type, |
| 433 const std::string& item) { | 464 const std::string& item) { |
| 434 if (!host_connection_.get()) { | 465 if (!host_connection_.get()) { |
| 435 return; | 466 return; |
| 436 } | 467 } |
| 437 protocol::ClipboardEvent event; | 468 protocol::ClipboardEvent event; |
| 438 event.set_mime_type(mime_type); | 469 event.set_mime_type(mime_type); |
| 439 event.set_data(item); | 470 event.set_data(item); |
| 440 host_connection_->clipboard_stub()->InjectClipboardEvent(event); | 471 host_connection_->clipboard_stub()->InjectClipboardEvent(event); |
| 441 } | 472 } |
| 442 | 473 |
| 443 ChromotingStats* ChromotingInstance::GetStats() { | 474 ChromotingStats* ChromotingInstance::GetStats() { |
| 444 if (!client_.get()) | 475 if (!client_.get()) |
| 445 return NULL; | 476 return NULL; |
| 446 return client_->GetStats(); | 477 return client_->GetStats(); |
| 447 } | 478 } |
| 448 | 479 |
| 449 void ChromotingInstance::PostChromotingMessage( | 480 void ChromotingInstance::PostChromotingMessage( |
| 450 const std::string& method, | 481 const std::string& method, |
| 451 scoped_ptr<base::DictionaryValue> data) { | 482 scoped_ptr<base::DictionaryValue> data) { |
| 452 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 483 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
| 453 message->SetString("method", method); | 484 message->SetString("method", method); |
| 454 message->Set("data", data.release()); | 485 message->Set("data", data.release()); |
| 455 | 486 |
| 456 std::string message_json; | 487 std::string message_json; |
| 457 base::JSONWriter::Write(message.get(), &message_json); | 488 base::JSONWriter::Write(message.get(), &message_json); |
| 458 PostMessage(pp::Var(message_json)); | 489 PostMessage(pp::Var(message_json)); |
| 459 } | 490 } |
| 460 | 491 |
| 492 void ChromotingInstance::SendTrappedKey(uint32 usb_keycode, bool pressed) { | |
| 493 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | |
| 494 data->SetInteger("usb_keycode", usb_keycode); | |
|
Sergey Ulanov
2012/04/07 01:50:14
usbKeycode
Wez
2012/04/08 00:12:41
Done.
| |
| 495 data->SetBoolean("pressed", pressed); | |
| 496 PostChromotingMessage("trappedKeyEvent", data.Pass()); | |
| 497 } | |
| 498 | |
| 461 void ChromotingInstance::SendOutgoingIq(const std::string& iq) { | 499 void ChromotingInstance::SendOutgoingIq(const std::string& iq) { |
| 462 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 500 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 463 data->SetString("iq", iq); | 501 data->SetString("iq", iq); |
| 464 PostChromotingMessage("sendOutgoingIq", data.Pass()); | 502 PostChromotingMessage("sendOutgoingIq", data.Pass()); |
| 465 | 503 |
| 466 GetScriptableObject()->SendIq(iq); | 504 GetScriptableObject()->SendIq(iq); |
| 467 } | 505 } |
| 468 | 506 |
| 469 void ChromotingInstance::SendPerfStats() { | 507 void ChromotingInstance::SendPerfStats() { |
| 470 if (!client_.get()) { | 508 if (!client_.get()) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 627 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 590 data->SetString("message", message); | 628 data->SetString("message", message); |
| 591 PostChromotingMessage("logDebugMessage", data.Pass()); | 629 PostChromotingMessage("logDebugMessage", data.Pass()); |
| 592 | 630 |
| 593 scriptable_object->LogDebugInfo(message); | 631 scriptable_object->LogDebugInfo(message); |
| 594 } | 632 } |
| 595 g_logging_to_plugin = false; | 633 g_logging_to_plugin = false; |
| 596 } | 634 } |
| 597 | 635 |
| 598 } // namespace remoting | 636 } // namespace remoting |
| OLD | NEW |