| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "google_apis/gaia/gaia_oauth_client.h" | 19 #include "google_apis/gaia/gaia_oauth_client.h" |
| 20 #include "google_apis/google_api_keys.h" | 20 #include "google_apis/google_api_keys.h" |
| 21 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
| 22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 23 #include "remoting/base/rsa_key_pair.h" | 23 #include "remoting/base/rsa_key_pair.h" |
| 24 #include "remoting/host/native_messaging/pipe_messaging_channel.h" |
| 24 #include "remoting/host/pin_hash.h" | 25 #include "remoting/host/pin_hash.h" |
| 25 #include "remoting/host/setup/oauth_client.h" | 26 #include "remoting/host/setup/oauth_client.h" |
| 26 #include "remoting/protocol/pairing_registry.h" | 27 #include "remoting/protocol/pairing_registry.h" |
| 27 | 28 |
| 28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 29 #include <shellapi.h> | 30 #include <shellapi.h> |
| 30 #include "base/win/win_util.h" | 31 #include "base/win/win_util.h" |
| 31 #include "remoting/host/win/security_descriptor.h" | 32 #include "remoting/host/win/security_descriptor.h" |
| 32 #endif // defined(OS_WIN) | 33 #endif // defined(OS_WIN) |
| 33 | 34 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return result.Pass(); | 66 return result.Pass(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 namespace remoting { | 71 namespace remoting { |
| 71 | 72 |
| 72 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( | 73 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( |
| 73 bool needs_elevation, | 74 bool needs_elevation, |
| 74 intptr_t parent_window_handle, | 75 intptr_t parent_window_handle, |
| 75 scoped_ptr<NativeMessagingChannel> channel, | 76 scoped_ptr<extensions::NativeMessagingChannel> channel, |
| 76 scoped_refptr<DaemonController> daemon_controller, | 77 scoped_refptr<DaemonController> daemon_controller, |
| 77 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 78 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
| 78 scoped_ptr<OAuthClient> oauth_client) | 79 scoped_ptr<OAuthClient> oauth_client) |
| 79 : needs_elevation_(needs_elevation), | 80 : needs_elevation_(needs_elevation), |
| 80 parent_window_handle_(parent_window_handle), | 81 parent_window_handle_(parent_window_handle), |
| 81 channel_(channel.Pass()), | 82 channel_(channel.Pass()), |
| 82 daemon_controller_(daemon_controller), | 83 daemon_controller_(daemon_controller), |
| 83 pairing_registry_(pairing_registry), | 84 pairing_registry_(pairing_registry), |
| 84 oauth_client_(oauth_client.Pass()), | 85 oauth_client_(oauth_client.Pass()), |
| 85 weak_factory_(this) { | 86 weak_factory_(this) { |
| 86 weak_ptr_ = weak_factory_.GetWeakPtr(); | 87 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { | 90 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void Me2MeNativeMessagingHost::Start( | 94 void Me2MeNativeMessagingHost::Start( |
| 94 const base::Closure& quit_closure) { | 95 const base::Closure& quit_closure) { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 96 DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 DCHECK(!quit_closure.is_null()); |
| 96 | 98 |
| 97 quit_closure_ = quit_closure; | 99 quit_closure_ = quit_closure; |
| 98 | 100 |
| 99 channel_->Start( | 101 channel_->Start(this); |
| 100 base::Bind(&Me2MeNativeMessagingHost::ProcessRequest, weak_ptr_), | |
| 101 base::Bind(&Me2MeNativeMessagingHost::Stop, weak_ptr_)); | |
| 102 } | 102 } |
| 103 | 103 |
| 104 void Me2MeNativeMessagingHost::ProcessRequest( | 104 void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { |
| 105 scoped_ptr<base::DictionaryValue> message) { | |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 | 106 |
| 107 scoped_ptr<base::DictionaryValue> message_dict( |
| 108 static_cast<base::DictionaryValue*>(message.release())); |
| 108 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 109 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
| 109 | 110 |
| 110 // 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 |
| 111 // might be a string or a number, so cope with both. | 112 // might be a string or a number, so cope with both. |
| 112 const base::Value* id; | 113 const base::Value* id; |
| 113 if (message->Get("id", &id)) | 114 if (message_dict->Get("id", &id)) |
| 114 response->Set("id", id->DeepCopy()); | 115 response->Set("id", id->DeepCopy()); |
| 115 | 116 |
| 116 std::string type; | 117 std::string type; |
| 117 if (!message->GetString("type", &type)) { | 118 if (!message_dict->GetString("type", &type)) { |
| 118 LOG(ERROR) << "'type' not found"; | 119 LOG(ERROR) << "'type' not found"; |
| 119 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); | 120 channel_->SendMessage(scoped_ptr<base::Value>()); |
| 120 return; | 121 return; |
| 121 } | 122 } |
| 122 | 123 |
| 123 response->SetString("type", type + "Response"); | 124 response->SetString("type", type + "Response"); |
| 124 | 125 |
| 125 if (type == "hello") { | 126 if (type == "hello") { |
| 126 ProcessHello(message.Pass(), response.Pass()); | 127 ProcessHello(message_dict.Pass(), response.Pass()); |
| 127 } else if (type == "clearPairedClients") { | 128 } else if (type == "clearPairedClients") { |
| 128 ProcessClearPairedClients(message.Pass(), response.Pass()); | 129 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); |
| 129 } else if (type == "deletePairedClient") { | 130 } else if (type == "deletePairedClient") { |
| 130 ProcessDeletePairedClient(message.Pass(), response.Pass()); | 131 ProcessDeletePairedClient(message_dict.Pass(), response.Pass()); |
| 131 } else if (type == "getHostName") { | 132 } else if (type == "getHostName") { |
| 132 ProcessGetHostName(message.Pass(), response.Pass()); | 133 ProcessGetHostName(message_dict.Pass(), response.Pass()); |
| 133 } else if (type == "getPinHash") { | 134 } else if (type == "getPinHash") { |
| 134 ProcessGetPinHash(message.Pass(), response.Pass()); | 135 ProcessGetPinHash(message_dict.Pass(), response.Pass()); |
| 135 } else if (type == "generateKeyPair") { | 136 } else if (type == "generateKeyPair") { |
| 136 ProcessGenerateKeyPair(message.Pass(), response.Pass()); | 137 ProcessGenerateKeyPair(message_dict.Pass(), response.Pass()); |
| 137 } else if (type == "updateDaemonConfig") { | 138 } else if (type == "updateDaemonConfig") { |
| 138 ProcessUpdateDaemonConfig(message.Pass(), response.Pass()); | 139 ProcessUpdateDaemonConfig(message_dict.Pass(), response.Pass()); |
| 139 } else if (type == "getDaemonConfig") { | 140 } else if (type == "getDaemonConfig") { |
| 140 ProcessGetDaemonConfig(message.Pass(), response.Pass()); | 141 ProcessGetDaemonConfig(message_dict.Pass(), response.Pass()); |
| 141 } else if (type == "getPairedClients") { | 142 } else if (type == "getPairedClients") { |
| 142 ProcessGetPairedClients(message.Pass(), response.Pass()); | 143 ProcessGetPairedClients(message_dict.Pass(), response.Pass()); |
| 143 } else if (type == "getUsageStatsConsent") { | 144 } else if (type == "getUsageStatsConsent") { |
| 144 ProcessGetUsageStatsConsent(message.Pass(), response.Pass()); | 145 ProcessGetUsageStatsConsent(message_dict.Pass(), response.Pass()); |
| 145 } else if (type == "startDaemon") { | 146 } else if (type == "startDaemon") { |
| 146 ProcessStartDaemon(message.Pass(), response.Pass()); | 147 ProcessStartDaemon(message_dict.Pass(), response.Pass()); |
| 147 } else if (type == "stopDaemon") { | 148 } else if (type == "stopDaemon") { |
| 148 ProcessStopDaemon(message.Pass(), response.Pass()); | 149 ProcessStopDaemon(message_dict.Pass(), response.Pass()); |
| 149 } else if (type == "getDaemonState") { | 150 } else if (type == "getDaemonState") { |
| 150 ProcessGetDaemonState(message.Pass(), response.Pass()); | 151 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); |
| 151 } else if (type == "getHostClientId") { | 152 } else if (type == "getHostClientId") { |
| 152 ProcessGetHostClientId(message.Pass(), response.Pass()); | 153 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); |
| 153 } else if (type == "getCredentialsFromAuthCode") { | 154 } else if (type == "getCredentialsFromAuthCode") { |
| 154 ProcessGetCredentialsFromAuthCode(message.Pass(), response.Pass()); | 155 ProcessGetCredentialsFromAuthCode(message_dict.Pass(), response.Pass()); |
| 155 } else { | 156 } else { |
| 156 LOG(ERROR) << "Unsupported request type: " << type; | 157 LOG(ERROR) << "Unsupported request type: " << type; |
| 157 OnError(); | 158 OnError(); |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 162 void Me2MeNativeMessagingHost::OnDisconnect() { |
| 163 if (!quit_closure_.is_null()) |
| 164 base::ResetAndReturn(&quit_closure_).Run(); |
| 165 } |
| 166 |
| 161 void Me2MeNativeMessagingHost::ProcessHello( | 167 void Me2MeNativeMessagingHost::ProcessHello( |
| 162 scoped_ptr<base::DictionaryValue> message, | 168 scoped_ptr<base::DictionaryValue> message, |
| 163 scoped_ptr<base::DictionaryValue> response) { | 169 scoped_ptr<base::DictionaryValue> response) { |
| 164 DCHECK(thread_checker_.CalledOnValidThread()); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
| 165 | 171 |
| 166 response->SetString("version", STRINGIZE(VERSION)); | 172 response->SetString("version", STRINGIZE(VERSION)); |
| 167 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); | 173 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); |
| 168 supported_features_list->AppendStrings(std::vector<std::string>( | 174 supported_features_list->AppendStrings(std::vector<std::string>( |
| 169 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); | 175 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); |
| 170 response->Set("supportedFeatures", supported_features_list.release()); | 176 response->Set("supportedFeatures", supported_features_list.release()); |
| 171 channel_->SendMessage(response.Pass()); | 177 channel_->SendMessage(response.PassAs<base::Value>()); |
| 172 } | 178 } |
| 173 | 179 |
| 174 void Me2MeNativeMessagingHost::ProcessClearPairedClients( | 180 void Me2MeNativeMessagingHost::ProcessClearPairedClients( |
| 175 scoped_ptr<base::DictionaryValue> message, | 181 scoped_ptr<base::DictionaryValue> message, |
| 176 scoped_ptr<base::DictionaryValue> response) { | 182 scoped_ptr<base::DictionaryValue> response) { |
| 177 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
| 178 | 184 |
| 179 if (needs_elevation_) { | 185 if (needs_elevation_) { |
| 180 if (!DelegateToElevatedHost(message.Pass())) | 186 if (!DelegateToElevatedHost(message.Pass())) |
| 181 SendBooleanResult(response.Pass(), false); | 187 SendBooleanResult(response.Pass(), false); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 SendBooleanResult(response.Pass(), false); | 225 SendBooleanResult(response.Pass(), false); |
| 220 } | 226 } |
| 221 } | 227 } |
| 222 | 228 |
| 223 void Me2MeNativeMessagingHost::ProcessGetHostName( | 229 void Me2MeNativeMessagingHost::ProcessGetHostName( |
| 224 scoped_ptr<base::DictionaryValue> message, | 230 scoped_ptr<base::DictionaryValue> message, |
| 225 scoped_ptr<base::DictionaryValue> response) { | 231 scoped_ptr<base::DictionaryValue> response) { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 232 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 | 233 |
| 228 response->SetString("hostname", net::GetHostName()); | 234 response->SetString("hostname", net::GetHostName()); |
| 229 channel_->SendMessage(response.Pass()); | 235 channel_->SendMessage(response.PassAs<base::Value>()); |
| 230 } | 236 } |
| 231 | 237 |
| 232 void Me2MeNativeMessagingHost::ProcessGetPinHash( | 238 void Me2MeNativeMessagingHost::ProcessGetPinHash( |
| 233 scoped_ptr<base::DictionaryValue> message, | 239 scoped_ptr<base::DictionaryValue> message, |
| 234 scoped_ptr<base::DictionaryValue> response) { | 240 scoped_ptr<base::DictionaryValue> response) { |
| 235 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 236 | 242 |
| 237 std::string host_id; | 243 std::string host_id; |
| 238 if (!message->GetString("hostId", &host_id)) { | 244 if (!message->GetString("hostId", &host_id)) { |
| 239 LOG(ERROR) << "'hostId' not found: " << message; | 245 LOG(ERROR) << "'hostId' not found: " << message; |
| 240 OnError(); | 246 OnError(); |
| 241 return; | 247 return; |
| 242 } | 248 } |
| 243 std::string pin; | 249 std::string pin; |
| 244 if (!message->GetString("pin", &pin)) { | 250 if (!message->GetString("pin", &pin)) { |
| 245 LOG(ERROR) << "'pin' not found: " << message; | 251 LOG(ERROR) << "'pin' not found: " << message; |
| 246 OnError(); | 252 OnError(); |
| 247 return; | 253 return; |
| 248 } | 254 } |
| 249 response->SetString("hash", MakeHostPinHash(host_id, pin)); | 255 response->SetString("hash", MakeHostPinHash(host_id, pin)); |
| 250 channel_->SendMessage(response.Pass()); | 256 channel_->SendMessage(response.PassAs<base::Value>()); |
| 251 } | 257 } |
| 252 | 258 |
| 253 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( | 259 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( |
| 254 scoped_ptr<base::DictionaryValue> message, | 260 scoped_ptr<base::DictionaryValue> message, |
| 255 scoped_ptr<base::DictionaryValue> response) { | 261 scoped_ptr<base::DictionaryValue> response) { |
| 256 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
| 257 | 263 |
| 258 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 264 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
| 259 response->SetString("privateKey", key_pair->ToString()); | 265 response->SetString("privateKey", key_pair->ToString()); |
| 260 response->SetString("publicKey", key_pair->GetPublicKey()); | 266 response->SetString("publicKey", key_pair->GetPublicKey()); |
| 261 channel_->SendMessage(response.Pass()); | 267 channel_->SendMessage(response.PassAs<base::Value>()); |
| 262 } | 268 } |
| 263 | 269 |
| 264 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( | 270 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( |
| 265 scoped_ptr<base::DictionaryValue> message, | 271 scoped_ptr<base::DictionaryValue> message, |
| 266 scoped_ptr<base::DictionaryValue> response) { | 272 scoped_ptr<base::DictionaryValue> response) { |
| 267 DCHECK(thread_checker_.CalledOnValidThread()); | 273 DCHECK(thread_checker_.CalledOnValidThread()); |
| 268 | 274 |
| 269 scoped_ptr<base::DictionaryValue> config_dict = | 275 scoped_ptr<base::DictionaryValue> config_dict = |
| 270 ConfigDictionaryFromMessage(message.Pass()); | 276 ConfigDictionaryFromMessage(message.Pass()); |
| 271 if (!config_dict) { | 277 if (!config_dict) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 case DaemonController::STATE_STARTED: | 380 case DaemonController::STATE_STARTED: |
| 375 response->SetString("state", "STARTED"); | 381 response->SetString("state", "STARTED"); |
| 376 break; | 382 break; |
| 377 case DaemonController::STATE_STOPPING: | 383 case DaemonController::STATE_STOPPING: |
| 378 response->SetString("state", "STOPPING"); | 384 response->SetString("state", "STOPPING"); |
| 379 break; | 385 break; |
| 380 case DaemonController::STATE_UNKNOWN: | 386 case DaemonController::STATE_UNKNOWN: |
| 381 response->SetString("state", "UNKNOWN"); | 387 response->SetString("state", "UNKNOWN"); |
| 382 break; | 388 break; |
| 383 } | 389 } |
| 384 channel_->SendMessage(response.Pass()); | 390 channel_->SendMessage(response.PassAs<base::Value>()); |
| 385 } | 391 } |
| 386 | 392 |
| 387 void Me2MeNativeMessagingHost::ProcessGetHostClientId( | 393 void Me2MeNativeMessagingHost::ProcessGetHostClientId( |
| 388 scoped_ptr<base::DictionaryValue> message, | 394 scoped_ptr<base::DictionaryValue> message, |
| 389 scoped_ptr<base::DictionaryValue> response) { | 395 scoped_ptr<base::DictionaryValue> response) { |
| 390 DCHECK(thread_checker_.CalledOnValidThread()); | 396 DCHECK(thread_checker_.CalledOnValidThread()); |
| 391 | 397 |
| 392 response->SetString("clientId", google_apis::GetOAuth2ClientID( | 398 response->SetString("clientId", google_apis::GetOAuth2ClientID( |
| 393 google_apis::CLIENT_REMOTING_HOST)); | 399 google_apis::CLIENT_REMOTING_HOST)); |
| 394 channel_->SendMessage(response.Pass()); | 400 channel_->SendMessage(response.PassAs<base::Value>()); |
| 395 } | 401 } |
| 396 | 402 |
| 397 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 403 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
| 398 scoped_ptr<base::DictionaryValue> message, | 404 scoped_ptr<base::DictionaryValue> message, |
| 399 scoped_ptr<base::DictionaryValue> response) { | 405 scoped_ptr<base::DictionaryValue> response) { |
| 400 DCHECK(thread_checker_.CalledOnValidThread()); | 406 DCHECK(thread_checker_.CalledOnValidThread()); |
| 401 | 407 |
| 402 std::string auth_code; | 408 std::string auth_code; |
| 403 if (!message->GetString("authorizationCode", &auth_code)) { | 409 if (!message->GetString("authorizationCode", &auth_code)) { |
| 404 LOG(ERROR) << "'authorizationCode' string not found."; | 410 LOG(ERROR) << "'authorizationCode' string not found."; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 421 void Me2MeNativeMessagingHost::SendConfigResponse( | 427 void Me2MeNativeMessagingHost::SendConfigResponse( |
| 422 scoped_ptr<base::DictionaryValue> response, | 428 scoped_ptr<base::DictionaryValue> response, |
| 423 scoped_ptr<base::DictionaryValue> config) { | 429 scoped_ptr<base::DictionaryValue> config) { |
| 424 DCHECK(thread_checker_.CalledOnValidThread()); | 430 DCHECK(thread_checker_.CalledOnValidThread()); |
| 425 | 431 |
| 426 if (config) { | 432 if (config) { |
| 427 response->Set("config", config.release()); | 433 response->Set("config", config.release()); |
| 428 } else { | 434 } else { |
| 429 response->Set("config", base::Value::CreateNullValue()); | 435 response->Set("config", base::Value::CreateNullValue()); |
| 430 } | 436 } |
| 431 channel_->SendMessage(response.Pass()); | 437 channel_->SendMessage(response.PassAs<base::Value>()); |
| 432 } | 438 } |
| 433 | 439 |
| 434 void Me2MeNativeMessagingHost::SendPairedClientsResponse( | 440 void Me2MeNativeMessagingHost::SendPairedClientsResponse( |
| 435 scoped_ptr<base::DictionaryValue> response, | 441 scoped_ptr<base::DictionaryValue> response, |
| 436 scoped_ptr<base::ListValue> pairings) { | 442 scoped_ptr<base::ListValue> pairings) { |
| 437 DCHECK(thread_checker_.CalledOnValidThread()); | 443 DCHECK(thread_checker_.CalledOnValidThread()); |
| 438 | 444 |
| 439 response->Set("pairedClients", pairings.release()); | 445 response->Set("pairedClients", pairings.release()); |
| 440 channel_->SendMessage(response.Pass()); | 446 channel_->SendMessage(response.PassAs<base::Value>()); |
| 441 } | 447 } |
| 442 | 448 |
| 443 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( | 449 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( |
| 444 scoped_ptr<base::DictionaryValue> response, | 450 scoped_ptr<base::DictionaryValue> response, |
| 445 const DaemonController::UsageStatsConsent& consent) { | 451 const DaemonController::UsageStatsConsent& consent) { |
| 446 DCHECK(thread_checker_.CalledOnValidThread()); | 452 DCHECK(thread_checker_.CalledOnValidThread()); |
| 447 | 453 |
| 448 response->SetBoolean("supported", consent.supported); | 454 response->SetBoolean("supported", consent.supported); |
| 449 response->SetBoolean("allowed", consent.allowed); | 455 response->SetBoolean("allowed", consent.allowed); |
| 450 response->SetBoolean("setByPolicy", consent.set_by_policy); | 456 response->SetBoolean("setByPolicy", consent.set_by_policy); |
| 451 channel_->SendMessage(response.Pass()); | 457 channel_->SendMessage(response.PassAs<base::Value>()); |
| 452 } | 458 } |
| 453 | 459 |
| 454 void Me2MeNativeMessagingHost::SendAsyncResult( | 460 void Me2MeNativeMessagingHost::SendAsyncResult( |
| 455 scoped_ptr<base::DictionaryValue> response, | 461 scoped_ptr<base::DictionaryValue> response, |
| 456 DaemonController::AsyncResult result) { | 462 DaemonController::AsyncResult result) { |
| 457 DCHECK(thread_checker_.CalledOnValidThread()); | 463 DCHECK(thread_checker_.CalledOnValidThread()); |
| 458 | 464 |
| 459 switch (result) { | 465 switch (result) { |
| 460 case DaemonController::RESULT_OK: | 466 case DaemonController::RESULT_OK: |
| 461 response->SetString("result", "OK"); | 467 response->SetString("result", "OK"); |
| 462 break; | 468 break; |
| 463 case DaemonController::RESULT_FAILED: | 469 case DaemonController::RESULT_FAILED: |
| 464 response->SetString("result", "FAILED"); | 470 response->SetString("result", "FAILED"); |
| 465 break; | 471 break; |
| 466 case DaemonController::RESULT_CANCELLED: | 472 case DaemonController::RESULT_CANCELLED: |
| 467 response->SetString("result", "CANCELLED"); | 473 response->SetString("result", "CANCELLED"); |
| 468 break; | 474 break; |
| 469 case DaemonController::RESULT_FAILED_DIRECTORY: | 475 case DaemonController::RESULT_FAILED_DIRECTORY: |
| 470 response->SetString("result", "FAILED_DIRECTORY"); | 476 response->SetString("result", "FAILED_DIRECTORY"); |
| 471 break; | 477 break; |
| 472 } | 478 } |
| 473 channel_->SendMessage(response.Pass()); | 479 channel_->SendMessage(response.PassAs<base::Value>()); |
| 474 } | 480 } |
| 475 | 481 |
| 476 void Me2MeNativeMessagingHost::SendBooleanResult( | 482 void Me2MeNativeMessagingHost::SendBooleanResult( |
| 477 scoped_ptr<base::DictionaryValue> response, bool result) { | 483 scoped_ptr<base::DictionaryValue> response, bool result) { |
| 478 DCHECK(thread_checker_.CalledOnValidThread()); | 484 DCHECK(thread_checker_.CalledOnValidThread()); |
| 479 | 485 |
| 480 response->SetBoolean("result", result); | 486 response->SetBoolean("result", result); |
| 481 channel_->SendMessage(response.Pass()); | 487 channel_->SendMessage(response.PassAs<base::Value>()); |
| 482 } | 488 } |
| 483 | 489 |
| 484 void Me2MeNativeMessagingHost::SendCredentialsResponse( | 490 void Me2MeNativeMessagingHost::SendCredentialsResponse( |
| 485 scoped_ptr<base::DictionaryValue> response, | 491 scoped_ptr<base::DictionaryValue> response, |
| 486 const std::string& user_email, | 492 const std::string& user_email, |
| 487 const std::string& refresh_token) { | 493 const std::string& refresh_token) { |
| 488 DCHECK(thread_checker_.CalledOnValidThread()); | 494 DCHECK(thread_checker_.CalledOnValidThread()); |
| 489 | 495 |
| 490 response->SetString("userEmail", user_email); | 496 response->SetString("userEmail", user_email); |
| 491 response->SetString("refreshToken", refresh_token); | 497 response->SetString("refreshToken", refresh_token); |
| 492 channel_->SendMessage(response.Pass()); | 498 channel_->SendMessage(response.PassAs<base::Value>()); |
| 493 } | 499 } |
| 494 | 500 |
| 495 void Me2MeNativeMessagingHost::OnError() { | 501 void Me2MeNativeMessagingHost::OnError() { |
| 496 // Trigger a host shutdown by sending a NULL message. | 502 // Trigger a host shutdown by sending a NULL message. |
| 497 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); | 503 channel_->SendMessage(scoped_ptr<base::Value>()); |
| 498 } | 504 } |
| 499 | 505 |
| 500 void Me2MeNativeMessagingHost::Stop() { | 506 void Me2MeNativeMessagingHost::Stop() { |
| 501 DCHECK(thread_checker_.CalledOnValidThread()); | 507 DCHECK(thread_checker_.CalledOnValidThread()); |
| 502 | 508 |
| 503 if (!quit_closure_.is_null()) | 509 if (!quit_closure_.is_null()) |
| 504 base::ResetAndReturn(&quit_closure_).Run(); | 510 base::ResetAndReturn(&quit_closure_).Run(); |
| 505 } | 511 } |
| 506 | 512 |
| 507 #if defined(OS_WIN) | 513 #if defined(OS_WIN) |
| 514 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: |
| 515 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) |
| 516 : parent_(host) { |
| 517 } |
| 518 |
| 519 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage( |
| 520 scoped_ptr<base::Value> message) { |
| 521 DCHECK(parent_->thread_checker_.CalledOnValidThread()); |
| 522 |
| 523 // Simply pass along the response from the elevated host to the client. |
| 524 parent_->channel_->SendMessage(message.Pass()); |
| 525 } |
| 526 |
| 527 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() { |
| 528 parent_->OnDisconnect(); |
| 529 } |
| 508 | 530 |
| 509 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 531 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 510 scoped_ptr<base::DictionaryValue> message) { | 532 scoped_ptr<base::DictionaryValue> message) { |
| 511 DCHECK(thread_checker_.CalledOnValidThread()); | 533 DCHECK(thread_checker_.CalledOnValidThread()); |
| 512 | 534 |
| 513 EnsureElevatedHostCreated(); | 535 EnsureElevatedHostCreated(); |
| 514 | 536 |
| 515 // elevated_channel_ will be null if user rejects the UAC request. | 537 // elevated_channel_ will be null if user rejects the UAC request. |
| 516 if (elevated_channel_) | 538 if (elevated_channel_) |
| 517 elevated_channel_->SendMessage(message.Pass()); | 539 elevated_channel_->SendMessage(message.PassAs<base::Value>()); |
| 518 | 540 |
| 519 return elevated_channel_ != NULL; | 541 return elevated_channel_ != NULL; |
| 520 } | 542 } |
| 521 | 543 |
| 522 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { | 544 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { |
| 523 DCHECK(thread_checker_.CalledOnValidThread()); | 545 DCHECK(thread_checker_.CalledOnValidThread()); |
| 524 DCHECK(needs_elevation_); | 546 DCHECK(needs_elevation_); |
| 525 | 547 |
| 526 if (elevated_channel_) | 548 if (elevated_channel_) |
| 527 return; | 549 return; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) { | 673 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) { |
| 652 DWORD error = ::GetLastError(); | 674 DWORD error = ::GetLastError(); |
| 653 if (error != ERROR_PIPE_CONNECTED) { | 675 if (error != ERROR_PIPE_CONNECTED) { |
| 654 PLOG(ERROR) << "Unable to connect '" << output_pipe_name << "'"; | 676 PLOG(ERROR) << "Unable to connect '" << output_pipe_name << "'"; |
| 655 OnError(); | 677 OnError(); |
| 656 return; | 678 return; |
| 657 } | 679 } |
| 658 } | 680 } |
| 659 | 681 |
| 660 // Set up the native messaging channel to talk to the elevated host. | 682 // Set up the native messaging channel to talk to the elevated host. |
| 661 // Note that input for the elevate channel is output forthe elevated host. | 683 // Note that input for the elevated channel is output for the elevated host. |
| 662 elevated_channel_.reset(new NativeMessagingChannel( | 684 elevated_channel_.reset( |
| 663 base::File(delegate_read_handle.Take()), | 685 new PipeMessagingChannel(base::File(delegate_read_handle.Take()), |
| 664 base::File(delegate_write_handle.Take()))); | 686 base::File(delegate_write_handle.Take()))); |
| 665 | 687 |
| 666 elevated_channel_->Start( | 688 elevated_channel_event_handler_.reset( |
| 667 base::Bind(&Me2MeNativeMessagingHost::ProcessDelegateResponse, weak_ptr_), | 689 new Me2MeNativeMessagingHost::ElevatedChannelEventHandler(this)); |
| 668 base::Bind(&Me2MeNativeMessagingHost::Stop, weak_ptr_)); | 690 elevated_channel_->Start(elevated_channel_event_handler_.get()); |
| 669 | 691 |
| 670 elevated_host_timer_.Start( | 692 elevated_host_timer_.Start( |
| 671 FROM_HERE, base::TimeDelta::FromSeconds(kElevatedHostTimeoutSeconds), | 693 FROM_HERE, base::TimeDelta::FromSeconds(kElevatedHostTimeoutSeconds), |
| 672 this, &Me2MeNativeMessagingHost::DisconnectElevatedHost); | 694 this, &Me2MeNativeMessagingHost::DisconnectElevatedHost); |
| 673 } | 695 } |
| 674 | 696 |
| 675 void Me2MeNativeMessagingHost::ProcessDelegateResponse( | |
| 676 scoped_ptr<base::DictionaryValue> message) { | |
| 677 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 678 | |
| 679 // Simply pass along the response from the elevated host to the client. | |
| 680 channel_->SendMessage(message.Pass()); | |
| 681 } | |
| 682 | |
| 683 void Me2MeNativeMessagingHost::DisconnectElevatedHost() { | 697 void Me2MeNativeMessagingHost::DisconnectElevatedHost() { |
| 684 DCHECK(thread_checker_.CalledOnValidThread()); | 698 DCHECK(thread_checker_.CalledOnValidThread()); |
| 685 | 699 |
| 686 // This will send an EOF to the elevated host, triggering its shutdown. | 700 // This will send an EOF to the elevated host, triggering its shutdown. |
| 687 elevated_channel_.reset(); | 701 elevated_channel_.reset(); |
| 688 } | 702 } |
| 689 | 703 |
| 690 #else // defined(OS_WIN) | 704 #else // defined(OS_WIN) |
| 691 | 705 |
| 692 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 706 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 693 scoped_ptr<base::DictionaryValue> message) { | 707 scoped_ptr<base::DictionaryValue> message) { |
| 694 NOTREACHED(); | 708 NOTREACHED(); |
| 695 return false; | 709 return false; |
| 696 } | 710 } |
| 697 | 711 |
| 698 #endif // !defined(OS_WIN) | 712 #endif // !defined(OS_WIN) |
| 699 | 713 |
| 700 } // namespace remoting | 714 } // namespace remoting |
| OLD | NEW |