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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 base::LazyInstance<base::Lock>::Leaky | 137 base::LazyInstance<base::Lock>::Leaky |
138 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 138 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
139 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 139 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
140 | 140 |
141 } // namespace | 141 } // namespace |
142 | 142 |
143 // String sent in the "hello" message to the webapp to describe features. | 143 // String sent in the "hello" message to the webapp to describe features. |
144 const char ChromotingInstance::kApiFeatures[] = | 144 const char ChromotingInstance::kApiFeatures[] = |
145 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 145 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
146 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " | 146 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " |
147 "asyncPin thirdPartyAuth pinlessAuth"; | 147 "asyncPin thirdPartyAuth pinlessAuth extensionMessage"; |
148 | 148 |
149 const char ChromotingInstance::kRequestedCapabilities[] = ""; | 149 const char ChromotingInstance::kRequestedCapabilities[] = ""; |
150 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; | 150 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; |
151 | 151 |
152 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | 152 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, |
153 ClientConfig* config) { | 153 ClientConfig* config) { |
154 std::vector<std::string> auth_methods; | 154 std::vector<std::string> auth_methods; |
155 base::SplitString(auth_methods_str, ',', &auth_methods); | 155 base::SplitString(auth_methods_str, ',', &auth_methods); |
156 for (std::vector<std::string>::iterator it = auth_methods.begin(); | 156 for (std::vector<std::string>::iterator it = auth_methods.begin(); |
157 it != auth_methods.end(); ++it) { | 157 it != auth_methods.end(); ++it) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return; | 426 return; |
427 } | 427 } |
428 OnThirdPartyTokenFetched(token, shared_secret); | 428 OnThirdPartyTokenFetched(token, shared_secret); |
429 } else if (method == "requestPairing") { | 429 } else if (method == "requestPairing") { |
430 std::string client_name; | 430 std::string client_name; |
431 if (!data->GetString("clientName", &client_name)) { | 431 if (!data->GetString("clientName", &client_name)) { |
432 LOG(ERROR) << "Invalid requestPairing"; | 432 LOG(ERROR) << "Invalid requestPairing"; |
433 return; | 433 return; |
434 } | 434 } |
435 RequestPairing(client_name); | 435 RequestPairing(client_name); |
| 436 } else if (method == "extensionMessage") { |
| 437 std::string type, message; |
| 438 if (!data->GetString("type", &type) || !data->GetString("data", &message)) { |
| 439 LOG(ERROR) << "Invalid extensionMessage."; |
| 440 return; |
| 441 } |
| 442 SendClientMessage(type, message); |
436 } | 443 } |
437 } | 444 } |
438 | 445 |
439 void ChromotingInstance::DidChangeView(const pp::View& view) { | 446 void ChromotingInstance::DidChangeView(const pp::View& view) { |
440 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 447 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
441 | 448 |
442 plugin_view_ = view; | 449 plugin_view_ = view; |
443 if (view_) { | 450 if (view_) { |
444 view_->SetView(view); | 451 view_->SetView(view); |
445 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); | 452 mouse_input_filter_.set_input_size(view_->get_view_size_dips()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 537 } |
531 | 538 |
532 void ChromotingInstance::SetPairingResponse( | 539 void ChromotingInstance::SetPairingResponse( |
533 const protocol::PairingResponse& pairing_response) { | 540 const protocol::PairingResponse& pairing_response) { |
534 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 541 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
535 data->SetString("clientId", pairing_response.client_id()); | 542 data->SetString("clientId", pairing_response.client_id()); |
536 data->SetString("sharedSecret", pairing_response.shared_secret()); | 543 data->SetString("sharedSecret", pairing_response.shared_secret()); |
537 PostChromotingMessage("pairingResponse", data.Pass()); | 544 PostChromotingMessage("pairingResponse", data.Pass()); |
538 } | 545 } |
539 | 546 |
| 547 void ChromotingInstance::DeliverHostMessage( |
| 548 const protocol::ExtensionMessage& message) { |
| 549 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 550 data->SetString("type", message.type()); |
| 551 data->SetString("data", message.data()); |
| 552 PostChromotingMessage("extensionMessage", data.Pass()); |
| 553 } |
| 554 |
540 void ChromotingInstance::FetchSecretFromDialog( | 555 void ChromotingInstance::FetchSecretFromDialog( |
541 bool pairing_supported, | 556 bool pairing_supported, |
542 const protocol::SecretFetchedCallback& secret_fetched_callback) { | 557 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
543 // Once the Session object calls this function, it won't continue the | 558 // Once the Session object calls this function, it won't continue the |
544 // authentication until the callback is called (or connection is canceled). | 559 // authentication until the callback is called (or connection is canceled). |
545 // So, it's impossible to reach this with a callback already registered. | 560 // So, it's impossible to reach this with a callback already registered. |
546 DCHECK(secret_fetched_callback_.is_null()); | 561 DCHECK(secret_fetched_callback_.is_null()); |
547 secret_fetched_callback_ = secret_fetched_callback; | 562 secret_fetched_callback_ = secret_fetched_callback; |
548 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 563 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
549 data->SetBoolean("pairingSupported", pairing_supported); | 564 data->SetBoolean("pairingSupported", pairing_supported); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 | 847 |
833 void ChromotingInstance::RequestPairing(const std::string& client_name) { | 848 void ChromotingInstance::RequestPairing(const std::string& client_name) { |
834 if (!IsConnected()) { | 849 if (!IsConnected()) { |
835 return; | 850 return; |
836 } | 851 } |
837 protocol::PairingRequest pairing_request; | 852 protocol::PairingRequest pairing_request; |
838 pairing_request.set_client_name(client_name); | 853 pairing_request.set_client_name(client_name); |
839 host_connection_->host_stub()->RequestPairing(pairing_request); | 854 host_connection_->host_stub()->RequestPairing(pairing_request); |
840 } | 855 } |
841 | 856 |
| 857 void ChromotingInstance::SendClientMessage(const std::string& type, |
| 858 const std::string& data) { |
| 859 if (!IsConnected()) { |
| 860 return; |
| 861 } |
| 862 protocol::ExtensionMessage message; |
| 863 message.set_type(type); |
| 864 message.set_data(data); |
| 865 host_connection_->host_stub()->DeliverClientMessage(message); |
| 866 } |
| 867 |
842 ChromotingStats* ChromotingInstance::GetStats() { | 868 ChromotingStats* ChromotingInstance::GetStats() { |
843 if (!client_.get()) | 869 if (!client_.get()) |
844 return NULL; | 870 return NULL; |
845 return client_->GetStats(); | 871 return client_->GetStats(); |
846 } | 872 } |
847 | 873 |
848 void ChromotingInstance::PostChromotingMessage( | 874 void ChromotingInstance::PostChromotingMessage( |
849 const std::string& method, | 875 const std::string& method, |
850 scoped_ptr<base::DictionaryValue> data) { | 876 scoped_ptr<base::DictionaryValue> data) { |
851 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 877 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 url_components.scheme.len); | 1035 url_components.scheme.len); |
1010 return url_scheme == kChromeExtensionUrlScheme; | 1036 return url_scheme == kChromeExtensionUrlScheme; |
1011 } | 1037 } |
1012 | 1038 |
1013 bool ChromotingInstance::IsConnected() { | 1039 bool ChromotingInstance::IsConnected() { |
1014 return host_connection_.get() && | 1040 return host_connection_.get() && |
1015 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 1041 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); |
1016 } | 1042 } |
1017 | 1043 |
1018 } // namespace remoting | 1044 } // namespace remoting |
OLD | NEW |