| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const int kElevatedHostTimeoutSeconds = 300; | 42 const int kElevatedHostTimeoutSeconds = 300; |
| 43 #endif // defined(OS_WIN) | 43 #endif // defined(OS_WIN) |
| 44 | 44 |
| 45 // redirect_uri to use when authenticating service accounts (service account | 45 // redirect_uri to use when authenticating service accounts (service account |
| 46 // codes are obtained "out-of-band", i.e., not through an OAuth redirect). | 46 // codes are obtained "out-of-band", i.e., not through an OAuth redirect). |
| 47 const char* kServiceAccountRedirectUri = "oob"; | 47 const char* kServiceAccountRedirectUri = "oob"; |
| 48 | 48 |
| 49 // Features supported in addition to the base protocol. | 49 // Features supported in addition to the base protocol. |
| 50 const char* kSupportedFeatures[] = { | 50 const char* kSupportedFeatures[] = { |
| 51 "pairingRegistry", | 51 "pairingRegistry", |
| 52 "oauthClient" | 52 "oauthClient", |
| 53 "getRefreshTokenFromAuthCode", |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 // Helper to extract the "config" part of a message as a DictionaryValue. | 56 // Helper to extract the "config" part of a message as a DictionaryValue. |
| 56 // Returns nullptr on failure, and logs an error message. | 57 // Returns nullptr on failure, and logs an error message. |
| 57 scoped_ptr<base::DictionaryValue> ConfigDictionaryFromMessage( | 58 scoped_ptr<base::DictionaryValue> ConfigDictionaryFromMessage( |
| 58 scoped_ptr<base::DictionaryValue> message) { | 59 scoped_ptr<base::DictionaryValue> message) { |
| 59 scoped_ptr<base::DictionaryValue> result; | 60 scoped_ptr<base::DictionaryValue> result; |
| 60 const base::DictionaryValue* config_dict; | 61 const base::DictionaryValue* config_dict; |
| 61 if (message->GetDictionary("config", &config_dict)) { | 62 if (message->GetDictionary("config", &config_dict)) { |
| 62 result.reset(config_dict->DeepCopy()); | 63 result.reset(config_dict->DeepCopy()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ProcessGetUsageStatsConsent(message_dict.Pass(), response.Pass()); | 154 ProcessGetUsageStatsConsent(message_dict.Pass(), response.Pass()); |
| 154 } else if (type == "startDaemon") { | 155 } else if (type == "startDaemon") { |
| 155 ProcessStartDaemon(message_dict.Pass(), response.Pass()); | 156 ProcessStartDaemon(message_dict.Pass(), response.Pass()); |
| 156 } else if (type == "stopDaemon") { | 157 } else if (type == "stopDaemon") { |
| 157 ProcessStopDaemon(message_dict.Pass(), response.Pass()); | 158 ProcessStopDaemon(message_dict.Pass(), response.Pass()); |
| 158 } else if (type == "getDaemonState") { | 159 } else if (type == "getDaemonState") { |
| 159 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); | 160 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); |
| 160 } else if (type == "getHostClientId") { | 161 } else if (type == "getHostClientId") { |
| 161 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); | 162 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); |
| 162 } else if (type == "getCredentialsFromAuthCode") { | 163 } else if (type == "getCredentialsFromAuthCode") { |
| 163 ProcessGetCredentialsFromAuthCode(message_dict.Pass(), response.Pass()); | 164 ProcessGetCredentialsFromAuthCode( |
| 165 message_dict.Pass(), response.Pass(), true); |
| 166 } else if (type == "getRefreshTokenFromAuthCode") { |
| 167 ProcessGetCredentialsFromAuthCode( |
| 168 message_dict.Pass(), response.Pass(), false); |
| 164 } else { | 169 } else { |
| 165 LOG(ERROR) << "Unsupported request type: " << type; | 170 LOG(ERROR) << "Unsupported request type: " << type; |
| 166 OnError(); | 171 OnError(); |
| 167 } | 172 } |
| 168 } | 173 } |
| 169 | 174 |
| 170 void Me2MeNativeMessagingHost::OnDisconnect() { | 175 void Me2MeNativeMessagingHost::OnDisconnect() { |
| 171 if (!quit_closure_.is_null()) | 176 if (!quit_closure_.is_null()) |
| 172 base::ResetAndReturn(&quit_closure_).Run(); | 177 base::ResetAndReturn(&quit_closure_).Run(); |
| 173 } | 178 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 scoped_ptr<base::DictionaryValue> response) { | 420 scoped_ptr<base::DictionaryValue> response) { |
| 416 DCHECK(thread_checker_.CalledOnValidThread()); | 421 DCHECK(thread_checker_.CalledOnValidThread()); |
| 417 | 422 |
| 418 response->SetString("clientId", google_apis::GetOAuth2ClientID( | 423 response->SetString("clientId", google_apis::GetOAuth2ClientID( |
| 419 google_apis::CLIENT_REMOTING_HOST)); | 424 google_apis::CLIENT_REMOTING_HOST)); |
| 420 channel_->SendMessage(response.Pass()); | 425 channel_->SendMessage(response.Pass()); |
| 421 } | 426 } |
| 422 | 427 |
| 423 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 428 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
| 424 scoped_ptr<base::DictionaryValue> message, | 429 scoped_ptr<base::DictionaryValue> message, |
| 425 scoped_ptr<base::DictionaryValue> response) { | 430 scoped_ptr<base::DictionaryValue> response, |
| 431 bool need_user_email) { |
| 426 DCHECK(thread_checker_.CalledOnValidThread()); | 432 DCHECK(thread_checker_.CalledOnValidThread()); |
| 427 | 433 |
| 428 std::string auth_code; | 434 std::string auth_code; |
| 429 if (!message->GetString("authorizationCode", &auth_code)) { | 435 if (!message->GetString("authorizationCode", &auth_code)) { |
| 430 LOG(ERROR) << "'authorizationCode' string not found."; | 436 LOG(ERROR) << "'authorizationCode' string not found."; |
| 431 OnError(); | 437 OnError(); |
| 432 return; | 438 return; |
| 433 } | 439 } |
| 434 | 440 |
| 435 gaia::OAuthClientInfo oauth_client_info = { | 441 gaia::OAuthClientInfo oauth_client_info = { |
| 436 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), | 442 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), |
| 437 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), | 443 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), |
| 438 kServiceAccountRedirectUri | 444 kServiceAccountRedirectUri |
| 439 }; | 445 }; |
| 440 | 446 |
| 441 oauth_client_->GetCredentialsFromAuthCode( | 447 oauth_client_->GetCredentialsFromAuthCode( |
| 442 oauth_client_info, auth_code, base::Bind( | 448 oauth_client_info, auth_code, need_user_email, base::Bind( |
| 443 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, | 449 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, |
| 444 base::Passed(&response))); | 450 base::Passed(&response))); |
| 445 } | 451 } |
| 446 | 452 |
| 447 void Me2MeNativeMessagingHost::SendConfigResponse( | 453 void Me2MeNativeMessagingHost::SendConfigResponse( |
| 448 scoped_ptr<base::DictionaryValue> response, | 454 scoped_ptr<base::DictionaryValue> response, |
| 449 scoped_ptr<base::DictionaryValue> config) { | 455 scoped_ptr<base::DictionaryValue> config) { |
| 450 DCHECK(thread_checker_.CalledOnValidThread()); | 456 DCHECK(thread_checker_.CalledOnValidThread()); |
| 451 | 457 |
| 452 if (config) { | 458 if (config) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 response->SetBoolean("result", result); | 512 response->SetBoolean("result", result); |
| 507 channel_->SendMessage(response.Pass()); | 513 channel_->SendMessage(response.Pass()); |
| 508 } | 514 } |
| 509 | 515 |
| 510 void Me2MeNativeMessagingHost::SendCredentialsResponse( | 516 void Me2MeNativeMessagingHost::SendCredentialsResponse( |
| 511 scoped_ptr<base::DictionaryValue> response, | 517 scoped_ptr<base::DictionaryValue> response, |
| 512 const std::string& user_email, | 518 const std::string& user_email, |
| 513 const std::string& refresh_token) { | 519 const std::string& refresh_token) { |
| 514 DCHECK(thread_checker_.CalledOnValidThread()); | 520 DCHECK(thread_checker_.CalledOnValidThread()); |
| 515 | 521 |
| 516 response->SetString("userEmail", user_email); | 522 if (!user_email.empty()) { |
| 523 response->SetString("userEmail", user_email); |
| 524 } |
| 517 response->SetString("refreshToken", refresh_token); | 525 response->SetString("refreshToken", refresh_token); |
| 518 channel_->SendMessage(response.Pass()); | 526 channel_->SendMessage(response.Pass()); |
| 519 } | 527 } |
| 520 | 528 |
| 521 void Me2MeNativeMessagingHost::OnError() { | 529 void Me2MeNativeMessagingHost::OnError() { |
| 522 // Trigger a host shutdown by sending a nullptr message. | 530 // Trigger a host shutdown by sending a nullptr message. |
| 523 channel_->SendMessage(nullptr); | 531 channel_->SendMessage(nullptr); |
| 524 } | 532 } |
| 525 | 533 |
| 526 void Me2MeNativeMessagingHost::Stop() { | 534 void Me2MeNativeMessagingHost::Stop() { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 735 |
| 728 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 736 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 729 scoped_ptr<base::DictionaryValue> message) { | 737 scoped_ptr<base::DictionaryValue> message) { |
| 730 NOTREACHED(); | 738 NOTREACHED(); |
| 731 return false; | 739 return false; |
| 732 } | 740 } |
| 733 | 741 |
| 734 #endif // !defined(OS_WIN) | 742 #endif // !defined(OS_WIN) |
| 735 | 743 |
| 736 } // namespace remoting | 744 } // namespace remoting |
| OLD | NEW |