OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/host/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 // If the client supplies an ID, it will expect it in the response. This | 111 // If the client supplies an ID, it will expect it in the response. This |
112 // might be a string or a number, so cope with both. | 112 // might be a string or a number, so cope with both. |
113 const base::Value* id; | 113 const base::Value* id; |
114 if (message_dict->Get("id", &id)) | 114 if (message_dict->Get("id", &id)) |
115 response->Set("id", id->DeepCopy()); | 115 response->Set("id", id->DeepCopy()); |
116 | 116 |
117 std::string type; | 117 std::string type; |
118 if (!message_dict->GetString("type", &type)) { | 118 if (!message_dict->GetString("type", &type)) { |
119 LOG(ERROR) << "'type' not found"; | 119 LOG(ERROR) << "'type' not found"; |
120 channel_->SendMessage(scoped_ptr<base::Value>()); | 120 channel_->SendMessage(nullptr); |
121 return; | 121 return; |
122 } | 122 } |
123 | 123 |
124 response->SetString("type", type + "Response"); | 124 response->SetString("type", type + "Response"); |
125 | 125 |
126 if (type == "hello") { | 126 if (type == "hello") { |
127 ProcessHello(message_dict.Pass(), response.Pass()); | 127 ProcessHello(message_dict.Pass(), response.Pass()); |
128 } else if (type == "clearPairedClients") { | 128 } else if (type == "clearPairedClients") { |
129 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); | 129 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); |
130 } else if (type == "deletePairedClient") { | 130 } else if (type == "deletePairedClient") { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 void Me2MeNativeMessagingHost::ProcessHello( | 167 void Me2MeNativeMessagingHost::ProcessHello( |
168 scoped_ptr<base::DictionaryValue> message, | 168 scoped_ptr<base::DictionaryValue> message, |
169 scoped_ptr<base::DictionaryValue> response) { | 169 scoped_ptr<base::DictionaryValue> response) { |
170 DCHECK(thread_checker_.CalledOnValidThread()); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
171 | 171 |
172 response->SetString("version", STRINGIZE(VERSION)); | 172 response->SetString("version", STRINGIZE(VERSION)); |
173 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); | 173 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); |
174 supported_features_list->AppendStrings(std::vector<std::string>( | 174 supported_features_list->AppendStrings(std::vector<std::string>( |
175 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); | 175 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); |
176 response->Set("supportedFeatures", supported_features_list.release()); | 176 response->Set("supportedFeatures", supported_features_list.release()); |
177 channel_->SendMessage(response.PassAs<base::Value>()); | 177 channel_->SendMessage(response.Pass()); |
178 } | 178 } |
179 | 179 |
180 void Me2MeNativeMessagingHost::ProcessClearPairedClients( | 180 void Me2MeNativeMessagingHost::ProcessClearPairedClients( |
181 scoped_ptr<base::DictionaryValue> message, | 181 scoped_ptr<base::DictionaryValue> message, |
182 scoped_ptr<base::DictionaryValue> response) { | 182 scoped_ptr<base::DictionaryValue> response) { |
183 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
184 | 184 |
185 if (needs_elevation_) { | 185 if (needs_elevation_) { |
186 if (!DelegateToElevatedHost(message.Pass())) | 186 if (!DelegateToElevatedHost(message.Pass())) |
187 SendBooleanResult(response.Pass(), false); | 187 SendBooleanResult(response.Pass(), false); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 SendBooleanResult(response.Pass(), false); | 225 SendBooleanResult(response.Pass(), false); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 void Me2MeNativeMessagingHost::ProcessGetHostName( | 229 void Me2MeNativeMessagingHost::ProcessGetHostName( |
230 scoped_ptr<base::DictionaryValue> message, | 230 scoped_ptr<base::DictionaryValue> message, |
231 scoped_ptr<base::DictionaryValue> response) { | 231 scoped_ptr<base::DictionaryValue> response) { |
232 DCHECK(thread_checker_.CalledOnValidThread()); | 232 DCHECK(thread_checker_.CalledOnValidThread()); |
233 | 233 |
234 response->SetString("hostname", net::GetHostName()); | 234 response->SetString("hostname", net::GetHostName()); |
235 channel_->SendMessage(response.PassAs<base::Value>()); | 235 channel_->SendMessage(response.Pass()); |
236 } | 236 } |
237 | 237 |
238 void Me2MeNativeMessagingHost::ProcessGetPinHash( | 238 void Me2MeNativeMessagingHost::ProcessGetPinHash( |
239 scoped_ptr<base::DictionaryValue> message, | 239 scoped_ptr<base::DictionaryValue> message, |
240 scoped_ptr<base::DictionaryValue> response) { | 240 scoped_ptr<base::DictionaryValue> response) { |
241 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
242 | 242 |
243 std::string host_id; | 243 std::string host_id; |
244 if (!message->GetString("hostId", &host_id)) { | 244 if (!message->GetString("hostId", &host_id)) { |
245 LOG(ERROR) << "'hostId' not found: " << message; | 245 LOG(ERROR) << "'hostId' not found: " << message; |
246 OnError(); | 246 OnError(); |
247 return; | 247 return; |
248 } | 248 } |
249 std::string pin; | 249 std::string pin; |
250 if (!message->GetString("pin", &pin)) { | 250 if (!message->GetString("pin", &pin)) { |
251 LOG(ERROR) << "'pin' not found: " << message; | 251 LOG(ERROR) << "'pin' not found: " << message; |
252 OnError(); | 252 OnError(); |
253 return; | 253 return; |
254 } | 254 } |
255 response->SetString("hash", MakeHostPinHash(host_id, pin)); | 255 response->SetString("hash", MakeHostPinHash(host_id, pin)); |
256 channel_->SendMessage(response.PassAs<base::Value>()); | 256 channel_->SendMessage(response.Pass()); |
257 } | 257 } |
258 | 258 |
259 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( | 259 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( |
260 scoped_ptr<base::DictionaryValue> message, | 260 scoped_ptr<base::DictionaryValue> message, |
261 scoped_ptr<base::DictionaryValue> response) { | 261 scoped_ptr<base::DictionaryValue> response) { |
262 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
263 | 263 |
264 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 264 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
265 response->SetString("privateKey", key_pair->ToString()); | 265 response->SetString("privateKey", key_pair->ToString()); |
266 response->SetString("publicKey", key_pair->GetPublicKey()); | 266 response->SetString("publicKey", key_pair->GetPublicKey()); |
267 channel_->SendMessage(response.PassAs<base::Value>()); | 267 channel_->SendMessage(response.Pass()); |
268 } | 268 } |
269 | 269 |
270 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( | 270 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( |
271 scoped_ptr<base::DictionaryValue> message, | 271 scoped_ptr<base::DictionaryValue> message, |
272 scoped_ptr<base::DictionaryValue> response) { | 272 scoped_ptr<base::DictionaryValue> response) { |
273 DCHECK(thread_checker_.CalledOnValidThread()); | 273 DCHECK(thread_checker_.CalledOnValidThread()); |
274 | 274 |
275 scoped_ptr<base::DictionaryValue> config_dict = | 275 scoped_ptr<base::DictionaryValue> config_dict = |
276 ConfigDictionaryFromMessage(message.Pass()); | 276 ConfigDictionaryFromMessage(message.Pass()); |
277 if (!config_dict) { | 277 if (!config_dict) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 case DaemonController::STATE_STARTED: | 380 case DaemonController::STATE_STARTED: |
381 response->SetString("state", "STARTED"); | 381 response->SetString("state", "STARTED"); |
382 break; | 382 break; |
383 case DaemonController::STATE_STOPPING: | 383 case DaemonController::STATE_STOPPING: |
384 response->SetString("state", "STOPPING"); | 384 response->SetString("state", "STOPPING"); |
385 break; | 385 break; |
386 case DaemonController::STATE_UNKNOWN: | 386 case DaemonController::STATE_UNKNOWN: |
387 response->SetString("state", "UNKNOWN"); | 387 response->SetString("state", "UNKNOWN"); |
388 break; | 388 break; |
389 } | 389 } |
390 channel_->SendMessage(response.PassAs<base::Value>()); | 390 channel_->SendMessage(response.Pass()); |
391 } | 391 } |
392 | 392 |
393 void Me2MeNativeMessagingHost::ProcessGetHostClientId( | 393 void Me2MeNativeMessagingHost::ProcessGetHostClientId( |
394 scoped_ptr<base::DictionaryValue> message, | 394 scoped_ptr<base::DictionaryValue> message, |
395 scoped_ptr<base::DictionaryValue> response) { | 395 scoped_ptr<base::DictionaryValue> response) { |
396 DCHECK(thread_checker_.CalledOnValidThread()); | 396 DCHECK(thread_checker_.CalledOnValidThread()); |
397 | 397 |
398 response->SetString("clientId", google_apis::GetOAuth2ClientID( | 398 response->SetString("clientId", google_apis::GetOAuth2ClientID( |
399 google_apis::CLIENT_REMOTING_HOST)); | 399 google_apis::CLIENT_REMOTING_HOST)); |
400 channel_->SendMessage(response.PassAs<base::Value>()); | 400 channel_->SendMessage(response.Pass()); |
401 } | 401 } |
402 | 402 |
403 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 403 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
404 scoped_ptr<base::DictionaryValue> message, | 404 scoped_ptr<base::DictionaryValue> message, |
405 scoped_ptr<base::DictionaryValue> response) { | 405 scoped_ptr<base::DictionaryValue> response) { |
406 DCHECK(thread_checker_.CalledOnValidThread()); | 406 DCHECK(thread_checker_.CalledOnValidThread()); |
407 | 407 |
408 std::string auth_code; | 408 std::string auth_code; |
409 if (!message->GetString("authorizationCode", &auth_code)) { | 409 if (!message->GetString("authorizationCode", &auth_code)) { |
410 LOG(ERROR) << "'authorizationCode' string not found."; | 410 LOG(ERROR) << "'authorizationCode' string not found."; |
(...skipping 16 matching lines...) Expand all Loading... |
427 void Me2MeNativeMessagingHost::SendConfigResponse( | 427 void Me2MeNativeMessagingHost::SendConfigResponse( |
428 scoped_ptr<base::DictionaryValue> response, | 428 scoped_ptr<base::DictionaryValue> response, |
429 scoped_ptr<base::DictionaryValue> config) { | 429 scoped_ptr<base::DictionaryValue> config) { |
430 DCHECK(thread_checker_.CalledOnValidThread()); | 430 DCHECK(thread_checker_.CalledOnValidThread()); |
431 | 431 |
432 if (config) { | 432 if (config) { |
433 response->Set("config", config.release()); | 433 response->Set("config", config.release()); |
434 } else { | 434 } else { |
435 response->Set("config", base::Value::CreateNullValue()); | 435 response->Set("config", base::Value::CreateNullValue()); |
436 } | 436 } |
437 channel_->SendMessage(response.PassAs<base::Value>()); | 437 channel_->SendMessage(response.Pass()); |
438 } | 438 } |
439 | 439 |
440 void Me2MeNativeMessagingHost::SendPairedClientsResponse( | 440 void Me2MeNativeMessagingHost::SendPairedClientsResponse( |
441 scoped_ptr<base::DictionaryValue> response, | 441 scoped_ptr<base::DictionaryValue> response, |
442 scoped_ptr<base::ListValue> pairings) { | 442 scoped_ptr<base::ListValue> pairings) { |
443 DCHECK(thread_checker_.CalledOnValidThread()); | 443 DCHECK(thread_checker_.CalledOnValidThread()); |
444 | 444 |
445 response->Set("pairedClients", pairings.release()); | 445 response->Set("pairedClients", pairings.release()); |
446 channel_->SendMessage(response.PassAs<base::Value>()); | 446 channel_->SendMessage(response.Pass()); |
447 } | 447 } |
448 | 448 |
449 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( | 449 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( |
450 scoped_ptr<base::DictionaryValue> response, | 450 scoped_ptr<base::DictionaryValue> response, |
451 const DaemonController::UsageStatsConsent& consent) { | 451 const DaemonController::UsageStatsConsent& consent) { |
452 DCHECK(thread_checker_.CalledOnValidThread()); | 452 DCHECK(thread_checker_.CalledOnValidThread()); |
453 | 453 |
454 response->SetBoolean("supported", consent.supported); | 454 response->SetBoolean("supported", consent.supported); |
455 response->SetBoolean("allowed", consent.allowed); | 455 response->SetBoolean("allowed", consent.allowed); |
456 response->SetBoolean("setByPolicy", consent.set_by_policy); | 456 response->SetBoolean("setByPolicy", consent.set_by_policy); |
457 channel_->SendMessage(response.PassAs<base::Value>()); | 457 channel_->SendMessage(response.Pass()); |
458 } | 458 } |
459 | 459 |
460 void Me2MeNativeMessagingHost::SendAsyncResult( | 460 void Me2MeNativeMessagingHost::SendAsyncResult( |
461 scoped_ptr<base::DictionaryValue> response, | 461 scoped_ptr<base::DictionaryValue> response, |
462 DaemonController::AsyncResult result) { | 462 DaemonController::AsyncResult result) { |
463 DCHECK(thread_checker_.CalledOnValidThread()); | 463 DCHECK(thread_checker_.CalledOnValidThread()); |
464 | 464 |
465 switch (result) { | 465 switch (result) { |
466 case DaemonController::RESULT_OK: | 466 case DaemonController::RESULT_OK: |
467 response->SetString("result", "OK"); | 467 response->SetString("result", "OK"); |
468 break; | 468 break; |
469 case DaemonController::RESULT_FAILED: | 469 case DaemonController::RESULT_FAILED: |
470 response->SetString("result", "FAILED"); | 470 response->SetString("result", "FAILED"); |
471 break; | 471 break; |
472 case DaemonController::RESULT_CANCELLED: | 472 case DaemonController::RESULT_CANCELLED: |
473 response->SetString("result", "CANCELLED"); | 473 response->SetString("result", "CANCELLED"); |
474 break; | 474 break; |
475 case DaemonController::RESULT_FAILED_DIRECTORY: | 475 case DaemonController::RESULT_FAILED_DIRECTORY: |
476 response->SetString("result", "FAILED_DIRECTORY"); | 476 response->SetString("result", "FAILED_DIRECTORY"); |
477 break; | 477 break; |
478 } | 478 } |
479 channel_->SendMessage(response.PassAs<base::Value>()); | 479 channel_->SendMessage(response.Pass()); |
480 } | 480 } |
481 | 481 |
482 void Me2MeNativeMessagingHost::SendBooleanResult( | 482 void Me2MeNativeMessagingHost::SendBooleanResult( |
483 scoped_ptr<base::DictionaryValue> response, bool result) { | 483 scoped_ptr<base::DictionaryValue> response, bool result) { |
484 DCHECK(thread_checker_.CalledOnValidThread()); | 484 DCHECK(thread_checker_.CalledOnValidThread()); |
485 | 485 |
486 response->SetBoolean("result", result); | 486 response->SetBoolean("result", result); |
487 channel_->SendMessage(response.PassAs<base::Value>()); | 487 channel_->SendMessage(response.Pass()); |
488 } | 488 } |
489 | 489 |
490 void Me2MeNativeMessagingHost::SendCredentialsResponse( | 490 void Me2MeNativeMessagingHost::SendCredentialsResponse( |
491 scoped_ptr<base::DictionaryValue> response, | 491 scoped_ptr<base::DictionaryValue> response, |
492 const std::string& user_email, | 492 const std::string& user_email, |
493 const std::string& refresh_token) { | 493 const std::string& refresh_token) { |
494 DCHECK(thread_checker_.CalledOnValidThread()); | 494 DCHECK(thread_checker_.CalledOnValidThread()); |
495 | 495 |
496 response->SetString("userEmail", user_email); | 496 response->SetString("userEmail", user_email); |
497 response->SetString("refreshToken", refresh_token); | 497 response->SetString("refreshToken", refresh_token); |
498 channel_->SendMessage(response.PassAs<base::Value>()); | 498 channel_->SendMessage(response.Pass()); |
499 } | 499 } |
500 | 500 |
501 void Me2MeNativeMessagingHost::OnError() { | 501 void Me2MeNativeMessagingHost::OnError() { |
502 // Trigger a host shutdown by sending a NULL message. | 502 // Trigger a host shutdown by sending a NULL message. |
503 channel_->SendMessage(scoped_ptr<base::Value>()); | 503 channel_->SendMessage(nullptr); |
504 } | 504 } |
505 | 505 |
506 void Me2MeNativeMessagingHost::Stop() { | 506 void Me2MeNativeMessagingHost::Stop() { |
507 DCHECK(thread_checker_.CalledOnValidThread()); | 507 DCHECK(thread_checker_.CalledOnValidThread()); |
508 | 508 |
509 if (!quit_closure_.is_null()) | 509 if (!quit_closure_.is_null()) |
510 base::ResetAndReturn(&quit_closure_).Run(); | 510 base::ResetAndReturn(&quit_closure_).Run(); |
511 } | 511 } |
512 | 512 |
513 #if defined(OS_WIN) | 513 #if defined(OS_WIN) |
(...skipping 15 matching lines...) Expand all Loading... |
529 } | 529 } |
530 | 530 |
531 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 531 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
532 scoped_ptr<base::DictionaryValue> message) { | 532 scoped_ptr<base::DictionaryValue> message) { |
533 DCHECK(thread_checker_.CalledOnValidThread()); | 533 DCHECK(thread_checker_.CalledOnValidThread()); |
534 | 534 |
535 EnsureElevatedHostCreated(); | 535 EnsureElevatedHostCreated(); |
536 | 536 |
537 // elevated_channel_ will be null if user rejects the UAC request. | 537 // elevated_channel_ will be null if user rejects the UAC request. |
538 if (elevated_channel_) | 538 if (elevated_channel_) |
539 elevated_channel_->SendMessage(message.PassAs<base::Value>()); | 539 elevated_channel_->SendMessage(message.Pass()); |
540 | 540 |
541 return elevated_channel_ != NULL; | 541 return elevated_channel_ != NULL; |
542 } | 542 } |
543 | 543 |
544 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { | 544 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { |
545 DCHECK(thread_checker_.CalledOnValidThread()); | 545 DCHECK(thread_checker_.CalledOnValidThread()); |
546 DCHECK(needs_elevation_); | 546 DCHECK(needs_elevation_); |
547 | 547 |
548 if (elevated_channel_) | 548 if (elevated_channel_) |
549 return; | 549 return; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 705 |
706 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 706 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
707 scoped_ptr<base::DictionaryValue> message) { | 707 scoped_ptr<base::DictionaryValue> message) { |
708 NOTREACHED(); | 708 NOTREACHED(); |
709 return false; | 709 return false; |
710 } | 710 } |
711 | 711 |
712 #endif // !defined(OS_WIN) | 712 #endif // !defined(OS_WIN) |
713 | 713 |
714 } // namespace remoting | 714 } // namespace remoting |
OLD | NEW |