Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "remoting/base/auth_token_util.h" | 10 #include "remoting/base/auth_token_util.h" |
| 11 #include "remoting/host/chromoting_host.h" | 11 #include "remoting/host/chromoting_host.h" |
| 12 #include "remoting/host/chromoting_host_context.h" | 12 #include "remoting/host/chromoting_host_context.h" |
| 13 #include "remoting/host/desktop_environment.h" | 13 #include "remoting/host/desktop_environment.h" |
| 14 #include "remoting/host/host_config.h" | 14 #include "remoting/host/host_config.h" |
| 15 #include "remoting/host/host_key_pair.h" | 15 #include "remoting/host/host_key_pair.h" |
| 16 #include "remoting/host/in_memory_host_config.h" | 16 #include "remoting/host/in_memory_host_config.h" |
| 17 #include "remoting/host/plugin/host_plugin_utils.h" | 17 #include "remoting/host/plugin/host_plugin_utils.h" |
| 18 #include "remoting/host/register_support_host_request.h" | 18 #include "remoting/host/register_support_host_request.h" |
| 19 #include "remoting/host/support_access_verifier.h" | 19 #include "remoting/host/support_access_verifier.h" |
| 20 | 20 |
| 21 namespace remoting { | 21 namespace remoting { |
| 22 | 22 |
| 23 // Supported Javascript interface: | 23 // Supported Javascript interface: |
| 24 // readonly attribute string accessCode; | 24 // readonly attribute string accessCode; |
| 25 // readonly attribute int accessCodeLifetime; | 25 // readonly attribute int accessCodeLifetime; |
| 26 // readonly attribute string client; | |
| 26 // readonly attribute int state; | 27 // readonly attribute int state; |
| 27 // | 28 // |
| 28 // state: { | 29 // state: { |
| 29 // DISCONNECTED, | 30 // DISCONNECTED, |
| 30 // REQUESTED_ACCESS_CODE, | 31 // REQUESTED_ACCESS_CODE, |
| 31 // RECEIVED_ACCESS_CODE, | 32 // RECEIVED_ACCESS_CODE, |
| 32 // CONNECTED, | 33 // CONNECTED, |
| 33 // AFFIRMING_CONNECTION, | 34 // AFFIRMING_CONNECTION, |
| 34 // ERROR, | 35 // ERROR, |
| 35 // } | 36 // } |
| 36 // | 37 // |
| 37 // attribute Function void logDebugInfo(string); | 38 // attribute Function void logDebugInfo(string); |
| 38 // attribute Function void onStateChanged(); | 39 // attribute Function void onStateChanged(); |
| 39 // | 40 // |
| 40 // // The |auth_service_with_token| parameter should be in the format | 41 // // The |auth_service_with_token| parameter should be in the format |
| 41 // // "auth_service:auth_token". An example would be "oauth2:1/2a3912vd". | 42 // // "auth_service:auth_token". An example would be "oauth2:1/2a3912vd". |
| 42 // void connect(string uid, string auth_service_with_token); | 43 // void connect(string uid, string auth_service_with_token); |
| 43 // void disconnect(); | 44 // void disconnect(); |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 const char* kAttrNameAccessCode = "accessCode"; | 48 const char* kAttrNameAccessCode = "accessCode"; |
| 48 const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; | 49 const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; |
| 50 const char* kAttrNameClient = "client"; | |
| 49 const char* kAttrNameState = "state"; | 51 const char* kAttrNameState = "state"; |
| 50 const char* kAttrNameLogDebugInfo = "logDebugInfo"; | 52 const char* kAttrNameLogDebugInfo = "logDebugInfo"; |
| 51 const char* kAttrNameOnStateChanged = "onStateChanged"; | 53 const char* kAttrNameOnStateChanged = "onStateChanged"; |
| 52 const char* kFuncNameConnect = "connect"; | 54 const char* kFuncNameConnect = "connect"; |
| 53 const char* kFuncNameDisconnect = "disconnect"; | 55 const char* kFuncNameDisconnect = "disconnect"; |
| 54 | 56 |
| 55 // States. | 57 // States. |
| 56 const char* kAttrNameDisconnected = "DISCONNECTED"; | 58 const char* kAttrNameDisconnected = "DISCONNECTED"; |
| 57 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; | 59 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; |
| 58 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; | 60 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 SetException("Invoke: unknown method " + method_name); | 145 SetException("Invoke: unknown method " + method_name); |
| 144 return false; | 146 return false; |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 | 149 |
| 148 bool HostNPScriptObject::HasProperty(const std::string& property_name) { | 150 bool HostNPScriptObject::HasProperty(const std::string& property_name) { |
| 149 logger_->VLog(2, "HasProperty %s", property_name.c_str()); | 151 logger_->VLog(2, "HasProperty %s", property_name.c_str()); |
| 150 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 152 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 151 return (property_name == kAttrNameAccessCode || | 153 return (property_name == kAttrNameAccessCode || |
| 152 property_name == kAttrNameAccessCodeLifetime || | 154 property_name == kAttrNameAccessCodeLifetime || |
| 155 property_name == kAttrNameClient || | |
| 153 property_name == kAttrNameState || | 156 property_name == kAttrNameState || |
| 154 property_name == kAttrNameLogDebugInfo || | 157 property_name == kAttrNameLogDebugInfo || |
| 155 property_name == kAttrNameOnStateChanged || | 158 property_name == kAttrNameOnStateChanged || |
| 156 property_name == kAttrNameDisconnected || | 159 property_name == kAttrNameDisconnected || |
| 157 property_name == kAttrNameRequestedAccessCode || | 160 property_name == kAttrNameRequestedAccessCode || |
| 158 property_name == kAttrNameReceivedAccessCode || | 161 property_name == kAttrNameReceivedAccessCode || |
| 159 property_name == kAttrNameConnected || | 162 property_name == kAttrNameConnected || |
| 160 property_name == kAttrNameAffirmingConnection || | 163 property_name == kAttrNameAffirmingConnection || |
| 161 property_name == kAttrNameError); | 164 property_name == kAttrNameError); |
| 162 } | 165 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 178 return true; | 181 return true; |
| 179 } else if (property_name == kAttrNameState) { | 182 } else if (property_name == kAttrNameState) { |
| 180 INT32_TO_NPVARIANT(state_, *result); | 183 INT32_TO_NPVARIANT(state_, *result); |
| 181 return true; | 184 return true; |
| 182 } else if (property_name == kAttrNameAccessCode) { | 185 } else if (property_name == kAttrNameAccessCode) { |
| 183 *result = NPVariantFromString(access_code_); | 186 *result = NPVariantFromString(access_code_); |
| 184 return true; | 187 return true; |
| 185 } else if (property_name == kAttrNameAccessCodeLifetime) { | 188 } else if (property_name == kAttrNameAccessCodeLifetime) { |
| 186 INT32_TO_NPVARIANT(access_code_lifetime_.InSeconds(), *result); | 189 INT32_TO_NPVARIANT(access_code_lifetime_.InSeconds(), *result); |
| 187 return true; | 190 return true; |
| 191 } else if (property_name == kAttrNameClient) { | |
| 192 *result = NPVariantFromString(client_username_); | |
| 193 return true; | |
| 188 } else if (property_name == kAttrNameDisconnected) { | 194 } else if (property_name == kAttrNameDisconnected) { |
| 189 INT32_TO_NPVARIANT(kDisconnected, *result); | 195 INT32_TO_NPVARIANT(kDisconnected, *result); |
| 190 return true; | 196 return true; |
| 191 } else if (property_name == kAttrNameRequestedAccessCode) { | 197 } else if (property_name == kAttrNameRequestedAccessCode) { |
| 192 INT32_TO_NPVARIANT(kRequestedAccessCode, *result); | 198 INT32_TO_NPVARIANT(kRequestedAccessCode, *result); |
| 193 return true; | 199 return true; |
| 194 } else if (property_name == kAttrNameReceivedAccessCode) { | 200 } else if (property_name == kAttrNameReceivedAccessCode) { |
| 195 INT32_TO_NPVARIANT(kReceivedAccessCode, *result); | 201 INT32_TO_NPVARIANT(kReceivedAccessCode, *result); |
| 196 return true; | 202 return true; |
| 197 } else if (property_name == kAttrNameConnected) { | 203 } else if (property_name == kAttrNameConnected) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 294 } |
| 289 | 295 |
| 290 void HostNPScriptObject::OnAccessDenied() { | 296 void HostNPScriptObject::OnAccessDenied() { |
| 291 DCHECK_EQ(MessageLoop::current(), host_context_.network_message_loop()); | 297 DCHECK_EQ(MessageLoop::current(), host_context_.network_message_loop()); |
| 292 | 298 |
| 293 ++failed_login_attempts_; | 299 ++failed_login_attempts_; |
| 294 if (failed_login_attempts_ == kMaxLoginAttempts) | 300 if (failed_login_attempts_ == kMaxLoginAttempts) |
| 295 DisconnectInternal(); | 301 DisconnectInternal(); |
| 296 } | 302 } |
| 297 | 303 |
| 298 void HostNPScriptObject::OnAuthenticatedClientsChanged(int clients_connected) { | 304 void HostNPScriptObject::OnClientAuthenticated( |
| 305 remoting::protocol::ConnectionToClient* client) { | |
| 299 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); | 306 DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); |
| 300 OnStateChanged(clients_connected ? kConnected : kDisconnected); | 307 client_username_ = client->session()->jid(); |
| 308 size_t pos = client_username_.find('/'); | |
| 309 if (pos != std::string::npos) | |
| 310 client_username_.replace(pos, std::string::npos, ""); | |
| 311 LOG(INFO) << "Client " << client_username_ << " connected."; | |
|
Wez
2011/08/02 21:38:01
nit: The client has authenticated; they were alrea
| |
| 312 OnStateChanged(kConnected); | |
| 313 } | |
| 314 | |
| 315 void HostNPScriptObject::OnClientDisconnected( | |
| 316 remoting::protocol::ConnectionToClient* client) { | |
| 317 client_username_.clear(); | |
| 318 OnStateChanged(kDisconnected); | |
| 301 } | 319 } |
| 302 | 320 |
| 303 void HostNPScriptObject::OnShutdown() { | 321 void HostNPScriptObject::OnShutdown() { |
| 304 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 322 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); |
| 305 | 323 |
| 306 OnStateChanged(kDisconnected); | 324 OnStateChanged(kDisconnected); |
| 307 } | 325 } |
| 308 | 326 |
| 309 // string uid, string auth_token | 327 // string uid, string auth_token |
| 310 bool HostNPScriptObject::Connect(const NPVariant* args, | 328 bool HostNPScriptObject::Connect(const NPVariant* args, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 556 } |
| 539 | 557 |
| 540 // static | 558 // static |
| 541 void HostNPScriptObject::NPTaskSpringboard(void* task) { | 559 void HostNPScriptObject::NPTaskSpringboard(void* task) { |
| 542 base::Closure* real_task = reinterpret_cast<base::Closure*>(task); | 560 base::Closure* real_task = reinterpret_cast<base::Closure*>(task); |
| 543 real_task->Run(); | 561 real_task->Run(); |
| 544 delete real_task; | 562 delete real_task; |
| 545 } | 563 } |
| 546 | 564 |
| 547 } // namespace remoting | 565 } // namespace remoting |
| OLD | NEW |