Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 const char* kAttrNameOnStateChanged = "onStateChanged"; | 45 const char* kAttrNameOnStateChanged = "onStateChanged"; |
| 46 const char* kFuncNameConnect = "connect"; | 46 const char* kFuncNameConnect = "connect"; |
| 47 const char* kFuncNameDisconnect = "disconnect"; | 47 const char* kFuncNameDisconnect = "disconnect"; |
| 48 const char* kFuncNameLocalize = "localize"; | 48 const char* kFuncNameLocalize = "localize"; |
| 49 const char* kFuncNameGetHostName = "getHostName"; | 49 const char* kFuncNameGetHostName = "getHostName"; |
| 50 const char* kFuncNameGetPinHash = "getPinHash"; | 50 const char* kFuncNameGetPinHash = "getPinHash"; |
| 51 const char* kFuncNameGenerateKeyPair = "generateKeyPair"; | 51 const char* kFuncNameGenerateKeyPair = "generateKeyPair"; |
| 52 const char* kFuncNameUpdateDaemonConfig = "updateDaemonConfig"; | 52 const char* kFuncNameUpdateDaemonConfig = "updateDaemonConfig"; |
| 53 const char* kFuncNameGetDaemonConfig = "getDaemonConfig"; | 53 const char* kFuncNameGetDaemonConfig = "getDaemonConfig"; |
| 54 const char* kFuncNameGetDaemonVersion = "getDaemonVersion"; | 54 const char* kFuncNameGetDaemonVersion = "getDaemonVersion"; |
| 55 const char* kFuncNameGetUsageStatsConsent = "getUsageStatsConsent"; | |
| 56 const char* kFuncNameSetUsageStatsConsent = "setUsageStatsConsent"; | |
| 55 const char* kFuncNameStartDaemon = "startDaemon"; | 57 const char* kFuncNameStartDaemon = "startDaemon"; |
| 56 const char* kFuncNameStopDaemon = "stopDaemon"; | 58 const char* kFuncNameStopDaemon = "stopDaemon"; |
| 57 | 59 |
| 58 // States. | 60 // States. |
| 59 const char* kAttrNameDisconnected = "DISCONNECTED"; | 61 const char* kAttrNameDisconnected = "DISCONNECTED"; |
| 60 const char* kAttrNameStarting = "STARTING"; | 62 const char* kAttrNameStarting = "STARTING"; |
| 61 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; | 63 const char* kAttrNameRequestedAccessCode = "REQUESTED_ACCESS_CODE"; |
| 62 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; | 64 const char* kAttrNameReceivedAccessCode = "RECEIVED_ACCESS_CODE"; |
| 63 const char* kAttrNameConnected = "CONNECTED"; | 65 const char* kAttrNameConnected = "CONNECTED"; |
| 64 const char* kAttrNameDisconnecting = "DISCONNECTING"; | 66 const char* kAttrNameDisconnecting = "DISCONNECTING"; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 156 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 155 return (method_name == kFuncNameConnect || | 157 return (method_name == kFuncNameConnect || |
| 156 method_name == kFuncNameDisconnect || | 158 method_name == kFuncNameDisconnect || |
| 157 method_name == kFuncNameLocalize || | 159 method_name == kFuncNameLocalize || |
| 158 method_name == kFuncNameGetHostName || | 160 method_name == kFuncNameGetHostName || |
| 159 method_name == kFuncNameGetPinHash || | 161 method_name == kFuncNameGetPinHash || |
| 160 method_name == kFuncNameGenerateKeyPair || | 162 method_name == kFuncNameGenerateKeyPair || |
| 161 method_name == kFuncNameUpdateDaemonConfig || | 163 method_name == kFuncNameUpdateDaemonConfig || |
| 162 method_name == kFuncNameGetDaemonConfig || | 164 method_name == kFuncNameGetDaemonConfig || |
| 163 method_name == kFuncNameGetDaemonVersion || | 165 method_name == kFuncNameGetDaemonVersion || |
| 166 method_name == kFuncNameGetUsageStatsConsent || | |
| 167 method_name == kFuncNameSetUsageStatsConsent || | |
| 164 method_name == kFuncNameStartDaemon || | 168 method_name == kFuncNameStartDaemon || |
| 165 method_name == kFuncNameStopDaemon); | 169 method_name == kFuncNameStopDaemon); |
| 166 } | 170 } |
| 167 | 171 |
| 168 bool HostNPScriptObject::InvokeDefault(const NPVariant* args, | 172 bool HostNPScriptObject::InvokeDefault(const NPVariant* args, |
| 169 uint32_t arg_count, | 173 uint32_t arg_count, |
| 170 NPVariant* result) { | 174 NPVariant* result) { |
| 171 VLOG(2) << "InvokeDefault"; | 175 VLOG(2) << "InvokeDefault"; |
| 172 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); | 176 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
| 173 SetException("exception during default invocation"); | 177 SetException("exception during default invocation"); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 191 } else if (method_name == kFuncNameGetPinHash) { | 195 } else if (method_name == kFuncNameGetPinHash) { |
| 192 return GetPinHash(args, arg_count, result); | 196 return GetPinHash(args, arg_count, result); |
| 193 } else if (method_name == kFuncNameGenerateKeyPair) { | 197 } else if (method_name == kFuncNameGenerateKeyPair) { |
| 194 return GenerateKeyPair(args, arg_count, result); | 198 return GenerateKeyPair(args, arg_count, result); |
| 195 } else if (method_name == kFuncNameUpdateDaemonConfig) { | 199 } else if (method_name == kFuncNameUpdateDaemonConfig) { |
| 196 return UpdateDaemonConfig(args, arg_count, result); | 200 return UpdateDaemonConfig(args, arg_count, result); |
| 197 } else if (method_name == kFuncNameGetDaemonConfig) { | 201 } else if (method_name == kFuncNameGetDaemonConfig) { |
| 198 return GetDaemonConfig(args, arg_count, result); | 202 return GetDaemonConfig(args, arg_count, result); |
| 199 } else if (method_name == kFuncNameGetDaemonVersion) { | 203 } else if (method_name == kFuncNameGetDaemonVersion) { |
| 200 return GetDaemonVersion(args, arg_count, result); | 204 return GetDaemonVersion(args, arg_count, result); |
| 205 } else if (method_name == kFuncNameGetUsageStatsConsent) { | |
| 206 return GetUsageStatsConsent(args, arg_count, result); | |
| 207 } else if (method_name == kFuncNameSetUsageStatsConsent) { | |
| 208 return SetUsageStatsConsent(args, arg_count, result); | |
| 201 } else if (method_name == kFuncNameStartDaemon) { | 209 } else if (method_name == kFuncNameStartDaemon) { |
| 202 return StartDaemon(args, arg_count, result); | 210 return StartDaemon(args, arg_count, result); |
| 203 } else if (method_name == kFuncNameStopDaemon) { | 211 } else if (method_name == kFuncNameStopDaemon) { |
| 204 return StopDaemon(args, arg_count, result); | 212 return StopDaemon(args, arg_count, result); |
| 205 } else { | 213 } else { |
| 206 SetException("Invoke: unknown method " + method_name); | 214 SetException("Invoke: unknown method " + method_name); |
| 207 return false; | 215 return false; |
| 208 } | 216 } |
| 209 } | 217 } |
| 210 | 218 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 kAttrNameError, | 372 kAttrNameError, |
| 365 kFuncNameConnect, | 373 kFuncNameConnect, |
| 366 kFuncNameDisconnect, | 374 kFuncNameDisconnect, |
| 367 kFuncNameLocalize, | 375 kFuncNameLocalize, |
| 368 kFuncNameGetHostName, | 376 kFuncNameGetHostName, |
| 369 kFuncNameGetPinHash, | 377 kFuncNameGetPinHash, |
| 370 kFuncNameGenerateKeyPair, | 378 kFuncNameGenerateKeyPair, |
| 371 kFuncNameUpdateDaemonConfig, | 379 kFuncNameUpdateDaemonConfig, |
| 372 kFuncNameGetDaemonConfig, | 380 kFuncNameGetDaemonConfig, |
| 373 kFuncNameGetDaemonVersion, | 381 kFuncNameGetDaemonVersion, |
| 382 kFuncNameGetUsageStatsConsent, | |
| 383 kFuncNameSetUsageStatsConsent, | |
| 374 kFuncNameStartDaemon, | 384 kFuncNameStartDaemon, |
| 375 kFuncNameStopDaemon | 385 kFuncNameStopDaemon |
| 376 }; | 386 }; |
| 377 for (size_t i = 0; i < arraysize(entries); ++i) { | 387 for (size_t i = 0; i < arraysize(entries); ++i) { |
| 378 values->push_back(entries[i]); | 388 values->push_back(entries[i]); |
| 379 } | 389 } |
| 380 return true; | 390 return true; |
| 381 } | 391 } |
| 382 | 392 |
| 383 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { | 393 void HostNPScriptObject::OnAccessDenied(const std::string& jid) { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 | 761 |
| 752 // We control lifetime of the |daemon_controller_| so it's safe to | 762 // We control lifetime of the |daemon_controller_| so it's safe to |
| 753 // use base::Unretained() here. | 763 // use base::Unretained() here. |
| 754 daemon_controller_->GetVersion( | 764 daemon_controller_->GetVersion( |
| 755 base::Bind(&HostNPScriptObject::InvokeGetDaemonVersionCallback, | 765 base::Bind(&HostNPScriptObject::InvokeGetDaemonVersionCallback, |
| 756 base::Unretained(this), callback_obj)); | 766 base::Unretained(this), callback_obj)); |
| 757 | 767 |
| 758 return true; | 768 return true; |
| 759 } | 769 } |
| 760 | 770 |
| 771 bool HostNPScriptObject::GetUsageStatsConsent(const NPVariant* args, | |
| 772 uint32_t arg_count, | |
| 773 NPVariant* result) { | |
| 774 if (arg_count != 1) { | |
| 775 SetException("GetUsageStatsConsent: bad number of arguments"); | |
|
Jamie
2012/06/14 23:43:56
Nit: camelCase for the message (ie, the name as vi
alexeypa (please no reviews)
2012/06/19 23:27:29
Done.
| |
| 776 return false; | |
| 777 } | |
| 778 | |
| 779 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); | |
| 780 if (!callback_obj.get()) { | |
| 781 SetException("GetUsageStatsConsent: invalid callback parameter"); | |
|
Jamie
2012/06/14 23:43:56
And here.
alexeypa (please no reviews)
2012/06/19 23:27:29
Done.
| |
| 782 return false; | |
| 783 } | |
| 784 | |
| 785 // We control lifetime of the |daemon_controller_| so it's safe to | |
| 786 // use base::Unretained() here. | |
| 787 daemon_controller_->GetUsageStatsConsent( | |
| 788 base::Bind(&HostNPScriptObject::InvokeGetUsageStatsConsentCallback, | |
| 789 base::Unretained(this), callback_obj)); | |
| 790 | |
| 791 return true; | |
| 792 } | |
| 793 | |
| 794 bool HostNPScriptObject::SetUsageStatsConsent(const NPVariant* args, | |
| 795 uint32_t arg_count, | |
| 796 NPVariant* result) { | |
| 797 if (arg_count != 1) { | |
| 798 SetException("setUsageStatsConsent: bad number of arguments"); | |
| 799 return false; | |
| 800 } | |
| 801 | |
| 802 if (!NPVARIANT_IS_BOOLEAN(args[0])) { | |
| 803 SetException("setUsageStatsConsent: invalid allowed parameter"); | |
| 804 return false; | |
| 805 } | |
| 806 | |
| 807 daemon_controller_->SetUsageStatsConsent(NPVARIANT_TO_BOOLEAN(args[0])); | |
| 808 return true; | |
| 809 } | |
| 810 | |
| 761 bool HostNPScriptObject::StartDaemon(const NPVariant* args, | 811 bool HostNPScriptObject::StartDaemon(const NPVariant* args, |
| 762 uint32_t arg_count, | 812 uint32_t arg_count, |
| 763 NPVariant* result) { | 813 NPVariant* result) { |
| 764 if (arg_count != 2) { | 814 if (arg_count != 2) { |
| 765 SetException("startDaemon: bad number of arguments"); | 815 SetException("startDaemon: bad number of arguments"); |
| 766 return false; | 816 return false; |
| 767 } | 817 } |
| 768 | 818 |
| 769 std::string config_str = StringFromNPVariant(args[0]); | 819 std::string config_str = StringFromNPVariant(args[0]); |
| 770 scoped_ptr<base::Value> config( | 820 scoped_ptr<base::Value> config( |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1131 &HostNPScriptObject::InvokeGetDaemonVersionCallback, | 1181 &HostNPScriptObject::InvokeGetDaemonVersionCallback, |
| 1132 base::Unretained(this), callback, version)); | 1182 base::Unretained(this), callback, version)); |
| 1133 return; | 1183 return; |
| 1134 } | 1184 } |
| 1135 | 1185 |
| 1136 NPVariant version_val = NPVariantFromString(version); | 1186 NPVariant version_val = NPVariantFromString(version); |
| 1137 InvokeAndIgnoreResult(callback.get(), &version_val, 1); | 1187 InvokeAndIgnoreResult(callback.get(), &version_val, 1); |
| 1138 g_npnetscape_funcs->releasevariantvalue(&version_val); | 1188 g_npnetscape_funcs->releasevariantvalue(&version_val); |
| 1139 } | 1189 } |
| 1140 | 1190 |
| 1191 void HostNPScriptObject::InvokeGetUsageStatsConsentCallback( | |
| 1192 const ScopedRefNPObject& callback, bool set_by_policy, bool allowed) { | |
| 1193 if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { | |
| 1194 plugin_message_loop_proxy_->PostTask( | |
| 1195 FROM_HERE, base::Bind( | |
| 1196 &HostNPScriptObject::InvokeGetUsageStatsConsentCallback, | |
| 1197 base::Unretained(this), callback, set_by_policy, allowed)); | |
| 1198 return; | |
| 1199 } | |
| 1200 | |
| 1201 NPVariant params[2]; | |
| 1202 BOOLEAN_TO_NPVARIANT(set_by_policy, params[0]); | |
| 1203 BOOLEAN_TO_NPVARIANT(allowed, params[1]); | |
| 1204 InvokeAndIgnoreResult(callback.get(), params, arraysize(params)); | |
| 1205 g_npnetscape_funcs->releasevariantvalue(&(params[0])); | |
| 1206 g_npnetscape_funcs->releasevariantvalue(&(params[1])); | |
| 1207 } | |
| 1208 | |
| 1141 void HostNPScriptObject::LogDebugInfo(const std::string& message) { | 1209 void HostNPScriptObject::LogDebugInfo(const std::string& message) { |
| 1142 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1210 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
| 1143 if (log_debug_info_func_.get()) { | 1211 if (log_debug_info_func_.get()) { |
| 1144 am_currently_logging_ = true; | 1212 am_currently_logging_ = true; |
| 1145 NPVariant log_message; | 1213 NPVariant log_message; |
| 1146 STRINGZ_TO_NPVARIANT(message.c_str(), log_message); | 1214 STRINGZ_TO_NPVARIANT(message.c_str(), log_message); |
| 1147 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(), | 1215 bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(), |
| 1148 &log_message, 1); | 1216 &log_message, 1); |
| 1149 if (!is_good) { | 1217 if (!is_good) { |
| 1150 LOG(ERROR) << "ERROR - LogDebugInfo failed\n"; | 1218 LOG(ERROR) << "ERROR - LogDebugInfo failed\n"; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1165 return is_good; | 1233 return is_good; |
| 1166 } | 1234 } |
| 1167 | 1235 |
| 1168 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1236 void HostNPScriptObject::SetException(const std::string& exception_string) { |
| 1169 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); | 1237 DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); |
| 1170 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1238 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
| 1171 LOG(INFO) << exception_string; | 1239 LOG(INFO) << exception_string; |
| 1172 } | 1240 } |
| 1173 | 1241 |
| 1174 } // namespace remoting | 1242 } // namespace remoting |
| OLD | NEW |