| 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/client/jni/chromoting_jni_instance.h" | 5 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "remoting/client/audio_player.h" | 9 #include "remoting/client/audio_player.h" |
| 10 #include "remoting/client/jni/android_keymap.h" | 10 #include "remoting/client/jni/android_keymap.h" |
| 11 #include "remoting/client/jni/chromoting_jni_runtime.h" | 11 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 12 #include "remoting/protocol/host_stub.h" |
| 12 #include "remoting/protocol/libjingle_transport_factory.h" | 13 #include "remoting/protocol/libjingle_transport_factory.h" |
| 13 | 14 |
| 14 // TODO(solb) Move into location shared with client plugin. | 15 // TODO(solb) Move into location shared with client plugin. |
| 15 const char* const kXmppServer = "talk.google.com"; | 16 const char* const kXmppServer = "talk.google.com"; |
| 16 const int kXmppPort = 5222; | 17 const int kXmppPort = 5222; |
| 17 const bool kXmppUseTls = true; | 18 const bool kXmppUseTls = true; |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 | 21 |
| 21 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, | 22 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, |
| 22 const char* username, | 23 const char* username, |
| 23 const char* auth_token, | 24 const char* auth_token, |
| 24 const char* host_jid, | 25 const char* host_jid, |
| 25 const char* host_id, | 26 const char* host_id, |
| 26 const char* host_pubkey) | 27 const char* host_pubkey, |
| 28 const char* pairing_id, |
| 29 const char* pairing_secret) |
| 27 : jni_runtime_(jni_runtime), | 30 : jni_runtime_(jni_runtime), |
| 28 username_(username), | 31 username_(username), |
| 29 auth_token_(auth_token), | 32 auth_token_(auth_token), |
| 30 host_jid_(host_jid), | 33 host_jid_(host_jid), |
| 31 host_id_(host_id), | 34 host_id_(host_id), |
| 32 host_pubkey_(host_pubkey) { | 35 host_pubkey_(host_pubkey), |
| 36 pairing_id_(pairing_id), |
| 37 pairing_secret_(pairing_secret), |
| 38 create_pairing_(false) { |
| 33 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 39 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 34 | 40 |
| 35 jni_runtime_->display_task_runner()->PostTask( | 41 jni_runtime_->display_task_runner()->PostTask( |
| 36 FROM_HERE, | 42 FROM_HERE, |
| 37 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, | 43 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, |
| 38 this)); | 44 this)); |
| 39 } | 45 } |
| 40 | 46 |
| 41 ChromotingJniInstance::~ChromotingJniInstance() {} | 47 ChromotingJniInstance::~ChromotingJniInstance() {} |
| 42 | 48 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 | 59 |
| 54 // The weak pointers must be invalidated on the same thread they were used. | 60 // The weak pointers must be invalidated on the same thread they were used. |
| 55 view_weak_factory_->InvalidateWeakPtrs(); | 61 view_weak_factory_->InvalidateWeakPtrs(); |
| 56 | 62 |
| 57 jni_runtime_->network_task_runner()->PostTask( | 63 jni_runtime_->network_task_runner()->PostTask( |
| 58 FROM_HERE, | 64 FROM_HERE, |
| 59 base::Bind(&ChromotingJniInstance::DisconnectFromHostOnNetworkThread, | 65 base::Bind(&ChromotingJniInstance::DisconnectFromHostOnNetworkThread, |
| 60 this)); | 66 this)); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void ChromotingJniInstance::ProvideSecret(const std::string& pin) { | 69 void ChromotingJniInstance::ProvideSecret(const std::string& pin, |
| 70 bool create_pairing) { |
| 64 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 71 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 65 DCHECK(!pin_callback_.is_null()); | 72 DCHECK(!pin_callback_.is_null()); |
| 66 | 73 |
| 74 create_pairing_ = create_pairing; |
| 75 |
| 67 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, | 76 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, |
| 68 base::Bind(pin_callback_, pin)); | 77 base::Bind(pin_callback_, pin)); |
| 69 } | 78 } |
| 70 | 79 |
| 71 void ChromotingJniInstance::RedrawDesktop() { | 80 void ChromotingJniInstance::RedrawDesktop() { |
| 72 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { | 81 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 73 jni_runtime_->display_task_runner()->PostTask( | 82 jni_runtime_->display_task_runner()->PostTask( |
| 74 FROM_HERE, | 83 FROM_HERE, |
| 75 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); | 84 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); |
| 76 return; | 85 return; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 connection_->input_stub()->InjectKeyEvent(action); | 134 connection_->input_stub()->InjectKeyEvent(action); |
| 126 } | 135 } |
| 127 else { | 136 else { |
| 128 LOG(WARNING) << "Ignoring unknown keycode: " << key_code; | 137 LOG(WARNING) << "Ignoring unknown keycode: " << key_code; |
| 129 } | 138 } |
| 130 } | 139 } |
| 131 | 140 |
| 132 void ChromotingJniInstance::OnConnectionState( | 141 void ChromotingJniInstance::OnConnectionState( |
| 133 protocol::ConnectionToHost::State state, | 142 protocol::ConnectionToHost::State state, |
| 134 protocol::ErrorCode error) { | 143 protocol::ErrorCode error) { |
| 135 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 144 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 136 jni_runtime_->ui_task_runner()->PostTask( | 145 |
| 137 FROM_HERE, | 146 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 138 base::Bind(&ChromotingJniInstance::OnConnectionState, | 147 LOG(INFO) << "Attempting to pair with host"; |
| 139 this, | 148 protocol::PairingRequest request; |
| 140 state, | 149 request.set_client_name("Android"); |
| 141 error)); | 150 connection_->host_stub()->RequestPairing(request); |
| 142 return; | |
| 143 } | 151 } |
| 144 | 152 |
| 145 jni_runtime_->ReportConnectionStatus(state, error); | 153 jni_runtime_->ui_task_runner()->PostTask( |
| 154 FROM_HERE, |
| 155 base::Bind(&ChromotingJniRuntime::ReportConnectionStatus, |
| 156 base::Unretained(jni_runtime_), |
| 157 state, |
| 158 error)); |
| 146 } | 159 } |
| 147 | 160 |
| 148 void ChromotingJniInstance::OnConnectionReady(bool ready) { | 161 void ChromotingJniInstance::OnConnectionReady(bool ready) { |
| 149 // We ignore this message, since OnConnectionState() tells us the same thing. | 162 // We ignore this message, since OnConnectoinState tells us the same thing. |
| 150 } | 163 } |
| 151 | 164 |
| 152 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {} | 165 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {} |
| 153 | 166 |
| 154 void ChromotingJniInstance::SetPairingResponse( | 167 void ChromotingJniInstance::SetPairingResponse( |
| 155 const protocol::PairingResponse& response) { | 168 const protocol::PairingResponse& response) { |
| 156 NOTIMPLEMENTED(); | 169 LOG(INFO) << "Successfully established pairing with host"; |
| 170 |
| 171 jni_runtime_->ui_task_runner()->PostTask( |
| 172 FROM_HERE, |
| 173 base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, |
| 174 base::Unretained(jni_runtime_), |
| 175 host_id_, |
| 176 response.client_id(), |
| 177 response.shared_secret())); |
| 157 } | 178 } |
| 158 | 179 |
| 159 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { | 180 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { |
| 160 return this; | 181 return this; |
| 161 } | 182 } |
| 162 | 183 |
| 163 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { | 184 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { |
| 164 return this; | 185 return this; |
| 165 } | 186 } |
| 166 | 187 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 221 |
| 201 client_config_.reset(new ClientConfig()); | 222 client_config_.reset(new ClientConfig()); |
| 202 client_config_->host_jid = host_jid_; | 223 client_config_->host_jid = host_jid_; |
| 203 client_config_->host_public_key = host_pubkey_; | 224 client_config_->host_public_key = host_pubkey_; |
| 204 | 225 |
| 205 client_config_->fetch_secret_callback = base::Bind( | 226 client_config_->fetch_secret_callback = base::Bind( |
| 206 &ChromotingJniInstance::FetchSecret, | 227 &ChromotingJniInstance::FetchSecret, |
| 207 this); | 228 this); |
| 208 client_config_->authentication_tag = host_id_; | 229 client_config_->authentication_tag = host_id_; |
| 209 | 230 |
| 231 if (!pairing_id_.empty() && !pairing_secret_.empty()) { |
| 232 client_config_->client_pairing_id = pairing_id_; |
| 233 client_config_->client_paired_secret = pairing_secret_; |
| 234 client_config_->authentication_methods.push_back( |
| 235 protocol::AuthenticationMethod::FromString("spake2_pair")); |
| 236 } |
| 237 |
| 210 client_config_->authentication_methods.push_back( | 238 client_config_->authentication_methods.push_back( |
| 211 protocol::AuthenticationMethod::FromString("spake2_hmac")); | 239 protocol::AuthenticationMethod::FromString("spake2_hmac")); |
| 212 client_config_->authentication_methods.push_back( | 240 client_config_->authentication_methods.push_back( |
| 213 protocol::AuthenticationMethod::FromString("spake2_plain")); | 241 protocol::AuthenticationMethod::FromString("spake2_plain")); |
| 214 | 242 |
| 215 client_context_.reset(new ClientContext( | 243 client_context_.reset(new ClientContext( |
| 216 jni_runtime_->network_task_runner().get())); | 244 jni_runtime_->network_task_runner().get())); |
| 217 client_context_->Start(); | 245 client_context_->Start(); |
| 218 | 246 |
| 219 connection_.reset(new protocol::ConnectionToHost(true)); | 247 connection_.reset(new protocol::ConnectionToHost(true)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 296 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
| 269 jni_runtime_->ui_task_runner()->PostTask( | 297 jni_runtime_->ui_task_runner()->PostTask( |
| 270 FROM_HERE, | 298 FROM_HERE, |
| 271 base::Bind(&ChromotingJniInstance::FetchSecret, | 299 base::Bind(&ChromotingJniInstance::FetchSecret, |
| 272 this, | 300 this, |
| 273 pairable, | 301 pairable, |
| 274 callback)); | 302 callback)); |
| 275 return; | 303 return; |
| 276 } | 304 } |
| 277 | 305 |
| 306 if (!pairing_id_.empty() || !pairing_secret_.empty()) { |
| 307 // We attempted to connect using an existing pairing that was rejected. |
| 308 // Unless we forget about the stale credentials, we'll continue trying them. |
| 309 LOG(INFO) << "Deleting rejected pairing credentials"; |
| 310 jni_runtime_->CommitPairingCredentials(host_id_, "", ""); |
| 311 } |
| 312 |
| 278 pin_callback_ = callback; | 313 pin_callback_ = callback; |
| 279 jni_runtime_->DisplayAuthenticationPrompt(); | 314 jni_runtime_->DisplayAuthenticationPrompt(); |
| 280 } | 315 } |
| 281 | 316 |
| 282 } // namespace remoting | 317 } // namespace remoting |
| OLD | NEW |