Index: remoting/host/plugin/host_script_object.cc |
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc |
index b4ca6ad2e9276ac4de83d05027b4b044d2b4b32b..2afc889ad0f845d74e0413b113dc7f0f41880a72 100644 |
--- a/remoting/host/plugin/host_script_object.cc |
+++ b/remoting/host/plugin/host_script_object.cc |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
#include "remoting/host/plugin/host_script_object.h" |
+#include "remoting/host/plugin/daemon_npapi.h" |
#include "base/bind.h" |
#include "base/message_loop.h" |
@@ -25,37 +26,12 @@ |
namespace remoting { |
-// Supported Javascript interface: |
-// readonly attribute string accessCode; |
-// readonly attribute int accessCodeLifetime; |
-// readonly attribute string client; |
-// readonly attribute int state; |
-// |
-// state: { |
-// DISCONNECTED, |
-// STARTING, |
-// REQUESTED_ACCESS_CODE, |
-// RECEIVED_ACCESS_CODE, |
-// CONNECTED, |
-// DISCONNECTING, |
-// ERROR, |
-// } |
-// |
-// attribute Function void logDebugInfo(string); |
-// attribute Function void onNatTraversalPolicyChanged(boolean); |
-// attribute Function void onStateChanged(state); |
-// |
-// // The |auth_service_with_token| parameter should be in the format |
-// // "auth_service:auth_token". An example would be "oauth2:1/2a3912vd". |
-// void connect(string uid, string auth_service_with_token); |
-// void disconnect(); |
-// void localize(string (*localize_func)(string,...)); |
- |
namespace { |
const char* kAttrNameAccessCode = "accessCode"; |
const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; |
const char* kAttrNameClient = "client"; |
+const char* kAttrNameDaemonState = "daemonState"; |
const char* kAttrNameState = "state"; |
const char* kAttrNameLogDebugInfo = "logDebugInfo"; |
const char* kAttrNameOnNatTraversalPolicyChanged = |
@@ -64,6 +40,8 @@ const char* kAttrNameOnStateChanged = "onStateChanged"; |
const char* kFuncNameConnect = "connect"; |
const char* kFuncNameDisconnect = "disconnect"; |
const char* kFuncNameLocalize = "localize"; |
+const char* kFuncNameStartDaemon = "startDaemon"; |
+const char* kFuncNameStopDaemon = "stopDaemon"; |
// States. |
const char* kAttrNameDisconnected = "DISCONNECTED"; |
@@ -90,6 +68,7 @@ HostNPScriptObject::HostNPScriptObject( |
new PluginMessageLoopProxy(plugin_thread_delegate)), |
host_context_(plugin_message_loop_proxy_), |
failed_login_attempts_(0), |
+ daemon_npapi_(DaemonNpapi::Create()), |
disconnected_event_(true, false), |
am_currently_logging_(false), |
nat_traversal_enabled_(false), |
@@ -147,7 +126,9 @@ bool HostNPScriptObject::HasMethod(const std::string& method_name) { |
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); |
return (method_name == kFuncNameConnect || |
method_name == kFuncNameDisconnect || |
- method_name == kFuncNameLocalize); |
+ method_name == kFuncNameLocalize || |
+ method_name == kFuncNameStartDaemon || |
+ method_name == kFuncNameStopDaemon); |
} |
bool HostNPScriptObject::InvokeDefault(const NPVariant* args, |
@@ -171,6 +152,10 @@ bool HostNPScriptObject::Invoke(const std::string& method_name, |
return Disconnect(args, argCount, result); |
} else if (method_name == kFuncNameLocalize) { |
return Localize(args, argCount, result); |
+ } else if (method_name == kFuncNameStartDaemon) { |
+ return StartDaemon(args, argCount, result); |
+ } else if (method_name == kFuncNameStopDaemon) { |
+ return StopDaemon(args, argCount, result); |
} else { |
SetException("Invoke: unknown method " + method_name); |
return false; |
@@ -183,6 +168,7 @@ bool HostNPScriptObject::HasProperty(const std::string& property_name) { |
return (property_name == kAttrNameAccessCode || |
property_name == kAttrNameAccessCodeLifetime || |
property_name == kAttrNameClient || |
+ property_name == kAttrNameDaemonState || |
property_name == kAttrNameState || |
property_name == kAttrNameLogDebugInfo || |
property_name == kAttrNameOnNatTraversalPolicyChanged || |
@@ -228,6 +214,9 @@ bool HostNPScriptObject::GetProperty(const std::string& property_name, |
} else if (property_name == kAttrNameClient) { |
*result = NPVariantFromString(client_username_); |
return true; |
+ } else if (property_name == kAttrNameDaemonState) { |
+ INT32_TO_NPVARIANT(daemon_npapi_->GetState(), *result); |
+ return true; |
} else if (property_name == kAttrNameDisconnected) { |
INT32_TO_NPVARIANT(kDisconnected, *result); |
return true; |
@@ -320,16 +309,18 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) { |
kAttrNameState, |
kAttrNameLogDebugInfo, |
kAttrNameOnStateChanged, |
- kFuncNameConnect, |
- kFuncNameDisconnect, |
- kFuncNameLocalize, |
kAttrNameDisconnected, |
kAttrNameStarting, |
kAttrNameRequestedAccessCode, |
kAttrNameReceivedAccessCode, |
kAttrNameConnected, |
kAttrNameDisconnecting, |
- kAttrNameError |
+ kAttrNameError, |
+ kFuncNameConnect, |
+ kFuncNameDisconnect, |
+ kFuncNameLocalize, |
+ kFuncNameStartDaemon, |
+ kFuncNameStopDaemon |
}; |
for (size_t i = 0; i < arraysize(entries); ++i) { |
values->push_back(entries[i]); |
@@ -566,6 +557,35 @@ bool HostNPScriptObject::Localize(const NPVariant* args, |
} |
} |
+bool HostNPScriptObject::StartDaemon(const NPVariant* args, |
+ uint32_t arg_count, |
+ NPVariant* result) { |
+ if (arg_count != 1) { |
+ SetException("startDaemon: bad number of arguments"); |
+ return false; |
+ } |
+ if (NPVARIANT_IS_STRING(args[0])) { |
+ NPString pin = NPVARIANT_TO_STRING(args[0]); |
+ daemon_npapi_->Start( |
+ std::string(pin.UTF8Characters, pin.UTF8Length).c_str()); |
Wez
2012/02/03 01:25:36
Definitely cleaner for Start() to accept a std::st
Jamie
2012/02/03 01:40:15
Done.
|
+ return true; |
+ } else { |
+ SetException("startDaemon: unexpected type for argument 1"); |
+ return false; |
+ } |
+} |
+ |
+bool HostNPScriptObject::StopDaemon(const NPVariant* args, |
+ uint32_t arg_count, |
+ NPVariant* result) { |
+ if (arg_count != 0) { |
+ SetException("startDaemon: bad number of arguments"); |
+ return false; |
+ } |
+ daemon_npapi_->Stop(); |
+ return true; |
+} |
+ |
void HostNPScriptObject::DisconnectInternal() { |
if (!host_context_.network_message_loop()->BelongsToCurrentThread()) { |
host_context_.network_message_loop()->PostTask( |