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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner> >::Leaky | 126 base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner> >::Leaky |
127 g_logging_task_runner = LAZY_INSTANCE_INITIALIZER; | 127 g_logging_task_runner = LAZY_INSTANCE_INITIALIZER; |
128 base::LazyInstance<base::WeakPtr<ChromotingInstance> >::Leaky | 128 base::LazyInstance<base::WeakPtr<ChromotingInstance> >::Leaky |
129 g_logging_instance = LAZY_INSTANCE_INITIALIZER; | 129 g_logging_instance = LAZY_INSTANCE_INITIALIZER; |
130 base::LazyInstance<base::Lock>::Leaky | 130 base::LazyInstance<base::Lock>::Leaky |
131 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 131 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
132 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 132 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | 135 |
136 // String sent in the "hello" message to the plugin to describe features. | 136 // String sent in the "hello" message to the webapp to describe features. |
137 const char ChromotingInstance::kApiFeatures[] = | 137 const char ChromotingInstance::kApiFeatures[] = |
138 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 138 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
139 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " | 139 "notifyClientDimensions notifyClientResolution pauseVideo pauseAudio " |
140 "asyncPin thirdPartyAuth"; | 140 "asyncPin thirdPartyAuth"; |
141 | 141 |
142 const char ChromotingInstance::kRequestedCapabilities[] = ""; | |
143 const char ChromotingInstance::kSupportedCapabilities[] = ""; | |
144 | |
142 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, | 145 bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str, |
143 ClientConfig* config) { | 146 ClientConfig* config) { |
144 std::vector<std::string> auth_methods; | 147 std::vector<std::string> auth_methods; |
145 base::SplitString(auth_methods_str, ',', &auth_methods); | 148 base::SplitString(auth_methods_str, ',', &auth_methods); |
146 for (std::vector<std::string>::iterator it = auth_methods.begin(); | 149 for (std::vector<std::string>::iterator it = auth_methods.begin(); |
147 it != auth_methods.end(); ++it) { | 150 it != auth_methods.end(); ++it) { |
148 protocol::AuthenticationMethod authentication_method = | 151 protocol::AuthenticationMethod authentication_method = |
149 protocol::AuthenticationMethod::FromString(*it); | 152 protocol::AuthenticationMethod::FromString(*it); |
150 if (authentication_method.is_valid()) | 153 if (authentication_method.is_valid()) |
151 config->authentication_methods.push_back(authentication_method); | 154 config->authentication_methods.push_back(authentication_method); |
(...skipping 28 matching lines...) Expand all Loading... | |
180 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 183 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
181 | 184 |
182 // Resister this instance to handle debug log messsages. | 185 // Resister this instance to handle debug log messsages. |
183 RegisterLoggingInstance(); | 186 RegisterLoggingInstance(); |
184 | 187 |
185 // Send hello message. | 188 // Send hello message. |
186 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 189 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
187 data->SetInteger("apiVersion", kApiVersion); | 190 data->SetInteger("apiVersion", kApiVersion); |
188 data->SetString("apiFeatures", kApiFeatures); | 191 data->SetString("apiFeatures", kApiFeatures); |
189 data->SetInteger("apiMinVersion", kApiMinMessagingVersion); | 192 data->SetInteger("apiMinVersion", kApiMinMessagingVersion); |
193 data->SetString("requestedCapabilities", kRequestedCapabilities); | |
194 data->SetString("supportedCapabilities", kSupportedCapabilities); | |
195 | |
190 PostChromotingMessage("hello", data.Pass()); | 196 PostChromotingMessage("hello", data.Pass()); |
191 } | 197 } |
192 | 198 |
193 ChromotingInstance::~ChromotingInstance() { | 199 ChromotingInstance::~ChromotingInstance() { |
194 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 200 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
195 | 201 |
196 // Unregister this instance so that debug log messages will no longer be sent | 202 // Unregister this instance so that debug log messages will no longer be sent |
197 // to it. This will stop all logging in all Chromoting instances. | 203 // to it. This will stop all logging in all Chromoting instances. |
198 UnregisterLoggingInstance(); | 204 UnregisterLoggingInstance(); |
199 | 205 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 this->AsWeakPtr()); | 292 this->AsWeakPtr()); |
287 } else { | 293 } else { |
288 std::string shared_secret; | 294 std::string shared_secret; |
289 if (!data->GetString("sharedSecret", &shared_secret)) { | 295 if (!data->GetString("sharedSecret", &shared_secret)) { |
290 LOG(ERROR) << "sharedSecret not specified in connect()."; | 296 LOG(ERROR) << "sharedSecret not specified in connect()."; |
291 return; | 297 return; |
292 } | 298 } |
293 config.fetch_secret_callback = | 299 config.fetch_secret_callback = |
294 base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); | 300 base::Bind(&ChromotingInstance::FetchSecretFromString, shared_secret); |
295 } | 301 } |
302 | |
303 // Read the list of capabilities, if any. | |
304 if (data->HasKey("capabilities")) { | |
Sergey Ulanov
2013/04/18 00:34:53
Don't need this. GetString() will return false if
alexeypa (please no reviews)
2013/04/18 18:56:36
This is needed to detect the case when "capabiliti
| |
305 if (!data->GetString("capabilities", &config.capabilities)) { | |
306 LOG(ERROR) << "Invalid connect() data."; | |
307 return; | |
308 } | |
309 } | |
310 | |
296 Connect(config); | 311 Connect(config); |
297 } else if (method == "disconnect") { | 312 } else if (method == "disconnect") { |
298 Disconnect(); | 313 Disconnect(); |
299 } else if (method == "incomingIq") { | 314 } else if (method == "incomingIq") { |
300 std::string iq; | 315 std::string iq; |
301 if (!data->GetString("iq", &iq)) { | 316 if (!data->GetString("iq", &iq)) { |
302 LOG(ERROR) << "Invalid onIq() data."; | 317 LOG(ERROR) << "Invalid onIq() data."; |
303 return; | 318 return; |
304 } | 319 } |
305 OnIncomingIq(iq); | 320 OnIncomingIq(iq); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 data->SetString("scope", scope); | 482 data->SetString("scope", scope); |
468 PostChromotingMessage("fetchThirdPartyToken", data.Pass()); | 483 PostChromotingMessage("fetchThirdPartyToken", data.Pass()); |
469 } | 484 } |
470 | 485 |
471 void ChromotingInstance::OnConnectionReady(bool ready) { | 486 void ChromotingInstance::OnConnectionReady(bool ready) { |
472 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 487 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
473 data->SetBoolean("ready", ready); | 488 data->SetBoolean("ready", ready); |
474 PostChromotingMessage("onConnectionReady", data.Pass()); | 489 PostChromotingMessage("onConnectionReady", data.Pass()); |
475 } | 490 } |
476 | 491 |
492 void ChromotingInstance::SetCapabilities(const std::string& capabilities) { | |
493 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | |
494 data->SetString("capabilities", capabilities); | |
495 PostChromotingMessage("setCapabilities", data.Pass()); | |
496 } | |
497 | |
477 void ChromotingInstance::FetchSecretFromDialog( | 498 void ChromotingInstance::FetchSecretFromDialog( |
478 const protocol::SecretFetchedCallback& secret_fetched_callback) { | 499 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
479 // Once the Session object calls this function, it won't continue the | 500 // Once the Session object calls this function, it won't continue the |
480 // authentication until the callback is called (or connection is canceled). | 501 // authentication until the callback is called (or connection is canceled). |
481 // So, it's impossible to reach this with a callback already registered. | 502 // So, it's impossible to reach this with a callback already registered. |
482 DCHECK(secret_fetched_callback_.is_null()); | 503 DCHECK(secret_fetched_callback_.is_null()); |
483 secret_fetched_callback_ = secret_fetched_callback; | 504 secret_fetched_callback_ = secret_fetched_callback; |
484 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 505 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
485 PostChromotingMessage("fetchPin", data.Pass()); | 506 PostChromotingMessage("fetchPin", data.Pass()); |
486 } | 507 } |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 url_components.scheme.len); | 935 url_components.scheme.len); |
915 return url_scheme == kChromeExtensionUrlScheme; | 936 return url_scheme == kChromeExtensionUrlScheme; |
916 } | 937 } |
917 | 938 |
918 bool ChromotingInstance::IsConnected() { | 939 bool ChromotingInstance::IsConnected() { |
919 return host_connection_.get() && | 940 return host_connection_.get() && |
920 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 941 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); |
921 } | 942 } |
922 | 943 |
923 } // namespace remoting | 944 } // namespace remoting |
OLD | NEW |