| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const char* kFuncNameStopDaemon = "stopDaemon"; | 65 const char* kFuncNameStopDaemon = "stopDaemon"; |
| 66 | 66 |
| 67 // States. | 67 // States. |
| 68 const char* kAttrNameDisconnected = "DISCONNECTED"; | 68 const char* kAttrNameDisconnected = "DISCONNECTED"; |
| 69 const char* kAttrNameStarting = "STARTING"; | 69 const char* kAttrNameStarting = "STARTING"; |
| 70 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; | 70 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; |
| 71 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; | 71 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; |
| 72 const char* kAttrNameConnected = "CONNECTED"; | 72 const char* kAttrNameConnected = "CONNECTED"; |
| 73 const char* kAttrNameDisconnecting = "DISCONNECTING"; | 73 const char* kAttrNameDisconnecting = "DISCONNECTING"; |
| 74 const char* kAttrNameError = "ERROR"; | 74 const char* kAttrNameError = "ERROR"; |
| 75 const char* kAttrNameInvalidDomainError = "INVALID_DOMAIN_ERROR"; |
| 75 | 76 |
| 76 const int kMaxLoginAttempts = 5; | 77 const int kMaxLoginAttempts = 5; |
| 77 | 78 |
| 78 // We may need to have more than one task running at the same time | 79 // We may need to have more than one task running at the same time |
| 79 // (e.g. key generation and status update), yet unlikely to ever need | 80 // (e.g. key generation and status update), yet unlikely to ever need |
| 80 // more than 2 threads. | 81 // more than 2 threads. |
| 81 const int kMaxWorkerPoolThreads = 2; | 82 const int kMaxWorkerPoolThreads = 2; |
| 82 | 83 |
| 83 } // namespace | 84 } // namespace |
| 84 | 85 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 return true; | 309 return true; |
| 309 } else if (property_name == kAttrNameConnected) { | 310 } else if (property_name == kAttrNameConnected) { |
| 310 INT32_TO_NPVARIANT(kConnected, *result); | 311 INT32_TO_NPVARIANT(kConnected, *result); |
| 311 return true; | 312 return true; |
| 312 } else if (property_name == kAttrNameDisconnecting) { | 313 } else if (property_name == kAttrNameDisconnecting) { |
| 313 INT32_TO_NPVARIANT(kDisconnecting, *result); | 314 INT32_TO_NPVARIANT(kDisconnecting, *result); |
| 314 return true; | 315 return true; |
| 315 } else if (property_name == kAttrNameError) { | 316 } else if (property_name == kAttrNameError) { |
| 316 INT32_TO_NPVARIANT(kError, *result); | 317 INT32_TO_NPVARIANT(kError, *result); |
| 317 return true; | 318 return true; |
| 319 } else if (property_name == kAttrNameInvalidDomainError) { |
| 320 INT32_TO_NPVARIANT(kInvalidDomainError, *result); |
| 321 return true; |
| 318 } else { | 322 } else { |
| 319 SetException("GetProperty: unsupported property " + property_name); | 323 SetException("GetProperty: unsupported property " + property_name); |
| 320 return false; | 324 return false; |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 | 327 |
| 324 bool HostNPScriptObject::SetProperty(const std::string& property_name, | 328 bool HostNPScriptObject::SetProperty(const std::string& property_name, |
| 325 const NPVariant* value) { | 329 const NPVariant* value) { |
| 326 VLOG(2) << "SetProperty " << property_name; | 330 VLOG(2) << "SetProperty " << property_name; |
| 327 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 331 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } | 542 } |
| 539 | 543 |
| 540 if (state_ != kStarting) { | 544 if (state_ != kStarting) { |
| 541 // Host has been stopped while we were fetching policy. | 545 // Host has been stopped while we were fetching policy. |
| 542 return; | 546 return; |
| 543 } | 547 } |
| 544 | 548 |
| 545 // Check the host domain policy. | 549 // Check the host domain policy. |
| 546 if (!required_host_domain_.empty() && | 550 if (!required_host_domain_.empty() && |
| 547 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { | 551 !EndsWith(uid, std::string("@") + required_host_domain_, false)) { |
| 548 SetState(kError); | 552 SetState(kInvalidDomainError); |
| 549 return; | 553 return; |
| 550 } | 554 } |
| 551 | 555 |
| 552 // Generate a key pair for the Host to use. | 556 // Generate a key pair for the Host to use. |
| 553 // TODO(wez): Move this to the worker thread. | 557 // TODO(wez): Move this to the worker thread. |
| 554 host_key_pair_.Generate(); | 558 host_key_pair_.Generate(); |
| 555 | 559 |
| 556 // Create XMPP connection. | 560 // Create XMPP connection. |
| 557 scoped_ptr<SignalStrategy> signal_strategy( | 561 scoped_ptr<SignalStrategy> signal_strategy( |
| 558 new XmppSignalStrategy(host_context_->url_request_context_getter(), | 562 new XmppSignalStrategy(host_context_->url_request_context_getter(), |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 void HostNPScriptObject::SetState(State state) { | 1032 void HostNPScriptObject::SetState(State state) { |
| 1029 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 1033 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
| 1030 switch (state_) { | 1034 switch (state_) { |
| 1031 case kDisconnected: | 1035 case kDisconnected: |
| 1032 DCHECK(state == kStarting || | 1036 DCHECK(state == kStarting || |
| 1033 state == kError) << state; | 1037 state == kError) << state; |
| 1034 break; | 1038 break; |
| 1035 case kStarting: | 1039 case kStarting: |
| 1036 DCHECK(state == kRequestedAccessCode || | 1040 DCHECK(state == kRequestedAccessCode || |
| 1037 state == kDisconnecting || | 1041 state == kDisconnecting || |
| 1038 state == kError) << state; | 1042 state == kError || |
| 1043 state == kInvalidDomainError) << state; |
| 1039 break; | 1044 break; |
| 1040 case kRequestedAccessCode: | 1045 case kRequestedAccessCode: |
| 1041 DCHECK(state == kReceivedAccessCode || | 1046 DCHECK(state == kReceivedAccessCode || |
| 1042 state == kDisconnecting || | 1047 state == kDisconnecting || |
| 1043 state == kError) << state; | 1048 state == kError) << state; |
| 1044 break; | 1049 break; |
| 1045 case kReceivedAccessCode: | 1050 case kReceivedAccessCode: |
| 1046 DCHECK(state == kConnected || | 1051 DCHECK(state == kConnected || |
| 1047 state == kDisconnecting || | 1052 state == kDisconnecting || |
| 1048 state == kError) << state; | 1053 state == kError) << state; |
| 1049 break; | 1054 break; |
| 1050 case kConnected: | 1055 case kConnected: |
| 1051 DCHECK(state == kDisconnecting || | 1056 DCHECK(state == kDisconnecting || |
| 1052 state == kDisconnected || | 1057 state == kDisconnected || |
| 1053 state == kError) << state; | 1058 state == kError) << state; |
| 1054 break; | 1059 break; |
| 1055 case kDisconnecting: | 1060 case kDisconnecting: |
| 1056 DCHECK(state == kDisconnected) << state; | 1061 DCHECK(state == kDisconnected) << state; |
| 1057 break; | 1062 break; |
| 1058 case kError: | 1063 case kError: |
| 1059 DCHECK(state == kDisconnecting) << state; | 1064 DCHECK(state == kDisconnecting) << state; |
| 1060 break; | 1065 break; |
| 1066 case kInvalidDomainError: |
| 1067 DCHECK(state == kDisconnecting) << state; |
| 1068 break; |
| 1061 }; | 1069 }; |
| 1062 state_ = state; | 1070 state_ = state; |
| 1063 NotifyStateChanged(state); | 1071 NotifyStateChanged(state); |
| 1064 } | 1072 } |
| 1065 | 1073 |
| 1066 void HostNPScriptObject::NotifyStateChanged(State state) { | 1074 void HostNPScriptObject::NotifyStateChanged(State state) { |
| 1067 if (!plugin_task_runner_->BelongsToCurrentThread()) { | 1075 if (!plugin_task_runner_->BelongsToCurrentThread()) { |
| 1068 plugin_task_runner_->PostTask( | 1076 plugin_task_runner_->PostTask( |
| 1069 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, | 1077 FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, |
| 1070 base::Unretained(this), state)); | 1078 base::Unretained(this), state)); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 return is_good; | 1321 return is_good; |
| 1314 } | 1322 } |
| 1315 | 1323 |
| 1316 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1324 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 1317 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1325 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 1318 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1326 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 1319 LOG(INFO) << exception_string; | 1327 LOG(INFO) << exception_string; |
| 1320 } | 1328 } |
| 1321 | 1329 |
| 1322 } // namespace remoting | 1330 } // namespace remoting |
| OLD | NEW |