Chromium Code Reviews| Index: remoting/client/plugin/chromoting_scriptable_object.cc |
| diff --git a/remoting/client/plugin/chromoting_scriptable_object.cc b/remoting/client/plugin/chromoting_scriptable_object.cc |
| index 106141fbcb59beceb57ad3f654e65e2f9ce726b4..62556442052cbb08d0a4f1b71e420e803e03b6bb 100644 |
| --- a/remoting/client/plugin/chromoting_scriptable_object.cc |
| +++ b/remoting/client/plugin/chromoting_scriptable_object.cc |
| @@ -24,6 +24,7 @@ const char kDesktopHeight[] = "desktopHeight"; |
| const char kDesktopWidth[] = "desktopWidth"; |
| const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; |
| const char kLoginChallenge[] = "loginChallenge"; |
| +const char kSandboxedAttribute[] = "sandboxed"; |
| const char kSendIq[] = "sendIq"; |
| const char kQualityAttribute[] = "quality"; |
| const char kStatusAttribute[] = "status"; |
| @@ -51,6 +52,9 @@ void ChromotingScriptableObject::Init() { |
| // Connection status. |
| AddAttribute(kStatusAttribute, Var(STATUS_UNKNOWN)); |
| + // Sandbox status. |
| + AddAttribute(kSandboxedAttribute, Var(true)); |
| + |
| // Connection status values. |
| AddAttribute("STATUS_UNKNOWN", Var(STATUS_UNKNOWN)); |
| AddAttribute("STATUS_CONNECTING", Var(STATUS_CONNECTING)); |
| @@ -85,11 +89,10 @@ void ChromotingScriptableObject::Init() { |
| AddAttribute(kRoundTripLatencyAttribute, Var()); |
| AddMethod("connect", &ChromotingScriptableObject::DoConnect); |
| - AddMethod("connectSandboxed", |
| - &ChromotingScriptableObject::DoConnectSandboxed); |
| AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); |
| AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); |
| AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); |
| + AddMethod("setSandboxed", &ChromotingScriptableObject::DoSetSandboxed); |
| AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); |
| } |
| @@ -327,79 +330,91 @@ void ChromotingScriptableObject::SendIq(const std::string& message_xml) { |
| cb.Call(Var(), Var(message_xml), &exception); |
| if (!exception.is_undefined()) |
| - LogDebugInfo("Exception when invoking loginChallenge JS callback."); |
| + LogDebugInfo("Exception when invoking sendiq JS callback."); |
| } |
| Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, |
| Var* exception) { |
| - if (args.size() != 4) { |
| - *exception = Var("Usage: connect(username, host_jid, auth_token)"); |
| - return Var(); |
| - } |
| - |
| - ClientConfig config; |
| - |
| - if (!args[0].is_string()) { |
| - *exception = Var("The username must be a string."); |
| - return Var(); |
| - } |
| - config.username = args[0].AsString(); |
| - |
| - if (!args[1].is_string()) { |
| + int sandboxed_index = property_names_[kSandboxedAttribute]; |
| + bool sandboxed = properties_[sandboxed_index].attribute.AsBool(); |
| + |
| + // Parameter order is: |
| + // host_jid |
| + // auth_type: ACCESS_CODE or AUTHENTICATE |
| + // if sandboxed: |
| + // client_jid |
| + // else: |
| + // username (TODO remove support for non-sandboxed) |
| + // xmpp_auth_token |
| + // if ACCESS_CODE: |
| + // access_code |
| + unsigned int arg = 0; |
| + if (!args[arg].is_string()) { |
| *exception = Var("The host_jid must be a string."); |
| return Var(); |
| } |
| - config.host_jid = args[1].AsString(); |
| + std::string host_jid = args[arg++].AsString(); |
| - if (!args[2].is_string()) { |
| - *exception = Var("The auth_token must be a string."); |
| + if (!args[arg].is_string()) { |
| + *exception = Var("The authentication type must be a string."); |
| return Var(); |
| } |
| - config.auth_token = args[2].AsString(); |
| - |
| - if (!args[3].is_string()) { |
| - *exception = Var("nonce must be a string."); |
| - return Var(); |
| + std::string auth_type = args[arg++].AsString(); |
| + bool use_access_code = (auth_type == "ACCESS_CODE"); |
| + |
| + std::string client_jid; |
| + std::string username; |
| + std::string auth_token; |
| + if (sandboxed) { |
| + if (!args[arg].is_string()) { |
| + *exception = Var("The client_jid must be a string."); |
| + return Var(); |
| + } |
| + client_jid = args[arg++].AsString(); |
| + } else { |
| + // TODO(garykac): Remove support for non-sandboxed connections. |
| + if (!args[arg].is_string()) { |
| + *exception = Var("The username must be a string."); |
| + return Var(); |
| + } |
| + username = args[arg++].AsString(); |
| + |
| + if (!args[arg].is_string()) { |
| + *exception = Var("The auth_token must be a string."); |
| + return Var(); |
| + } |
| + auth_token = args[arg++].AsString(); |
| } |
| - config.nonce = args[3].AsString(); |
| - |
| - LogDebugInfo("Connecting to host."); |
| - instance_->Connect(config); |
| - return Var(); |
| -} |
| - |
| -Var ChromotingScriptableObject::DoConnectSandboxed( |
| - const std::vector<Var>& args, Var* exception) { |
| - if (args.size() != 3) { |
| - *exception = Var("Usage: connectSandboxed(your_jid, host_jid, nonce)"); |
| - return Var(); |
| + std::string access_code; |
| + if (use_access_code) { |
| + if (!args[arg].is_string()) { |
| + *exception = Var("The access code must be a string."); |
| + return Var(); |
| + } |
| + access_code = args[arg++].AsString(); |
| } |
| - std::string your_jid; |
| - if (!args[0].is_string()) { |
| - *exception = Var("your_jid must be a string."); |
| + if (args.size() != arg) { |
| + *exception = Var("Too many agruments passed to connect()."); |
| return Var(); |
| } |
| - your_jid = args[0].AsString(); |
| - std::string host_jid; |
| - if (!args[1].is_string()) { |
| - *exception = Var("host_jid must be a string."); |
| - return Var(); |
| - } |
| - host_jid = args[1].AsString(); |
| - |
| - std::string nonce; |
| - if (!args[2].is_string()) { |
| - *exception = Var("nonce must be a string."); |
| - return Var(); |
| + LogDebugInfo("Connecting to host."); |
| + if (sandboxed) { |
| + VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid |
| + << ", access_code: " << access_code; |
| + instance_->ConnectSandboxed(client_jid, host_jid, access_code); |
| + } else { |
| + ClientConfig config; |
| + config.host_jid = host_jid; |
| + config.username = username; |
| + config.auth_token = auth_token; |
| + config.nonce = access_code; |
| + VLOG(1) << "host_jid: " << host_jid << ", username: " << username |
| + << ", access_code: " << access_code; |
| + instance_->Connect(config); |
| } |
| - nonce = args[2].AsString(); |
| - |
| - VLOG(1) << "your_jid: " << your_jid << ", host_jid: " << host_jid |
| - << ", nonce: " << nonce; |
| - instance_->ConnectSandboxed(your_jid, host_jid, nonce); |
| return Var(); |
| } |
| @@ -453,6 +468,24 @@ Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args, |
| return Var(); |
| } |
| +Var ChromotingScriptableObject::DoSetSandboxed(const std::vector<Var>& args, |
| + Var* exception) { |
| + if (args.size() != 1) { |
| + *exception = Var("Usage: setSandboxed(sandboxed)"); |
|
Wez
2011/05/20 22:38:59
Why do we have a method for this, rather than sett
|
| + return Var(); |
| + } |
| + |
| + if (!args[0].is_bool()) { |
| + *exception = Var("sandboxed must be a boolean."); |
| + return Var(); |
| + } |
| + |
| + LogDebugInfo("Setting sandboxed."); |
| + int sandboxed_index = property_names_[kSandboxedAttribute]; |
| + properties_[sandboxed_index].attribute = args[0].AsBool(); |
| + return Var(); |
| +} |
| + |
| Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, |
| Var* exception) { |
| if (args.size() != 1) { |