Commit e3f3047d authored by garykac@chromium.org's avatar garykac@chromium.org

Add separate nonce version of connect calls to ChromotingScriptableObject.

BUG=none
TEST=manual


Review URL: http://codereview.chromium.org/7042022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86573 0039d316-1c4b-4281-b951-d872f2087c98
parent 70c4776c
...@@ -54,8 +54,7 @@ function registerConnection() { ...@@ -54,8 +54,7 @@ function registerConnection() {
var clientjid = xhr.responseText; var clientjid = xhr.responseText;
chromoting.plugin.sendIq = sendIq; chromoting.plugin.sendIq = sendIq;
// TODO:(jamiewalch): Pass in the correct nonce. chromoting.plugin.connect(chromoting.hostjid, clientjid);
chromoting.plugin.connectSandboxed(clientjid, chromoting.hostjid);
// TODO(ajwong): This should just be feedIq(); // TODO(ajwong): This should just be feedIq();
window.setTimeout(feedIq, 1000); window.setTimeout(feedIq, 1000);
} else { } else {
...@@ -132,9 +131,8 @@ function init() { ...@@ -132,9 +131,8 @@ function init() {
if (chromoting.connectMethod == "sandboxed") { if (chromoting.connectMethod == "sandboxed") {
registerConnection(); registerConnection();
} else { } else {
// TODO:(jamiewalch): Pass in the correct nonce. plugin.connectUnsandboxed(chromoting.hostjid, chromoting.username,
plugin.connect(chromoting.username, chromoting.hostjid, chromoting.talkToken);
chromoting.talkToken, '');
} }
} else { } else {
addToDebugLog('ERROR: chromoting plugin not loaded'); addToDebugLog('ERROR: chromoting plugin not loaded');
......
...@@ -85,8 +85,8 @@ void ChromotingScriptableObject::Init() { ...@@ -85,8 +85,8 @@ void ChromotingScriptableObject::Init() {
AddAttribute(kRoundTripLatencyAttribute, Var()); AddAttribute(kRoundTripLatencyAttribute, Var());
AddMethod("connect", &ChromotingScriptableObject::DoConnect); AddMethod("connect", &ChromotingScriptableObject::DoConnect);
AddMethod("connectSandboxed", AddMethod("connectUnsandboxed",
&ChromotingScriptableObject::DoConnectSandboxed); &ChromotingScriptableObject::DoConnectUnsandboxed);
AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect);
AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin);
AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit);
...@@ -327,79 +327,100 @@ void ChromotingScriptableObject::SendIq(const std::string& message_xml) { ...@@ -327,79 +327,100 @@ void ChromotingScriptableObject::SendIq(const std::string& message_xml) {
cb.Call(Var(), Var(message_xml), &exception); cb.Call(Var(), Var(message_xml), &exception);
if (!exception.is_undefined()) 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 ChromotingScriptableObject::DoConnect(const std::vector<Var>& args,
Var* exception) { Var* exception) {
if (args.size() != 4) { // Parameter order is:
*exception = Var("Usage: connect(username, host_jid, auth_token)"); // host_jid
// client_jid
// access_code (optional)
unsigned int arg = 0;
if (!args[arg].is_string()) {
*exception = Var("The host_jid must be a string.");
return Var(); return Var();
} }
std::string host_jid = args[arg++].AsString();
ClientConfig config; if (!args[arg].is_string()) {
*exception = Var("The client_jid must be a string.");
if (!args[0].is_string()) {
*exception = Var("The username must be a string.");
return Var(); return Var();
} }
config.username = args[0].AsString(); std::string client_jid = args[arg++].AsString();
if (!args[1].is_string()) { std::string access_code;
*exception = Var("The host_jid must be a string."); if (args.size() > arg) {
if (!args[arg].is_string()) {
*exception = Var("The access code must be a string.");
return Var(); return Var();
} }
config.host_jid = args[1].AsString(); access_code = args[arg++].AsString();
if (!args[2].is_string()) {
*exception = Var("The auth_token must be a string.");
return Var();
} }
config.auth_token = args[2].AsString();
if (!args[3].is_string()) { if (args.size() != arg) {
*exception = Var("nonce must be a string."); *exception = Var("Too many agruments passed to connect().");
return Var(); return Var();
} }
config.nonce = args[3].AsString();
LogDebugInfo("Connecting to host."); LogDebugInfo("Connecting to host.");
instance_->Connect(config); VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid
<< ", access_code: " << access_code;
instance_->ConnectSandboxed(client_jid, host_jid, access_code);
return Var(); return Var();
} }
Var ChromotingScriptableObject::DoConnectSandboxed( Var ChromotingScriptableObject::DoConnectUnsandboxed(
const std::vector<Var>& args, Var* exception) { const std::vector<Var>& args,
if (args.size() != 3) { Var* exception) {
*exception = Var("Usage: connectSandboxed(your_jid, host_jid, nonce)"); // Parameter order is:
// host_jid
// username
// xmpp_token
// access_code (optional)
unsigned int arg = 0;
if (!args[arg].is_string()) {
*exception = Var("The host_jid must be a string.");
return Var();
}
std::string host_jid = args[arg++].AsString();
if (!args[arg].is_string()) {
*exception = Var("The username must be a string.");
return Var(); return Var();
} }
std::string username = args[arg++].AsString();
std::string your_jid; if (!args[arg].is_string()) {
if (!args[0].is_string()) { *exception = Var("The auth_token must be a string.");
*exception = Var("your_jid must be a string.");
return Var(); return Var();
} }
your_jid = args[0].AsString(); std::string auth_token = args[arg++].AsString();
std::string host_jid; std::string access_code;
if (!args[1].is_string()) { if (args.size() > arg) {
*exception = Var("host_jid must be a string."); if (!args[arg].is_string()) {
*exception = Var("The access code must be a string.");
return Var(); return Var();
} }
host_jid = args[1].AsString(); access_code = args[arg++].AsString();
}
std::string nonce; if (args.size() != arg) {
if (!args[2].is_string()) { *exception = Var("Too many agruments passed to connect().");
*exception = Var("nonce must be a string.");
return Var(); return Var();
} }
nonce = args[2].AsString();
VLOG(1) << "your_jid: " << your_jid << ", host_jid: " << host_jid LogDebugInfo("Connecting to host.");
<< ", nonce: " << nonce; ClientConfig config;
instance_->ConnectSandboxed(your_jid, host_jid, nonce); 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);
return Var(); return Var();
} }
......
...@@ -74,12 +74,16 @@ ...@@ -74,12 +74,16 @@
// //
// // Methods for establishing a Chromoting connection. // // Methods for establishing a Chromoting connection.
// // // //
// // Either use connect() or connectSandboxed(), not both. If using // // When using the sandboxed versions, sendIq must be set and responses to
// // connectSandboxed(), sendIq must be set, and responses to calls on // // calls on sendIq must be piped back into onIq().
// // sendIq must be piped back into onIq(). // void connect(string host_jid, string client_jid,
// void connect(string username, string host_jid, string auth_token, // optional string access_code);
// string nonce); // // Non-sandboxed version used for debugging/testing.
// void connectSandboxed(string your_jid, string host_jid, string nonce); // // TODO(garykac): Remove this version once we no longer need it.
// void connectUnsandboxed(string host_jid, string username,
// string xmpp_token, optional string access_code);
//
// // Terminating a Chromoting connection.
// void disconnect(); // void disconnect();
// //
// // Method for submitting login information. // // Method for submitting login information.
...@@ -193,7 +197,7 @@ class ChromotingScriptableObject ...@@ -193,7 +197,7 @@ class ChromotingScriptableObject
void SignalDesktopSizeChange(); void SignalDesktopSizeChange();
pp::Var DoConnect(const std::vector<pp::Var>& args, pp::Var* exception); pp::Var DoConnect(const std::vector<pp::Var>& args, pp::Var* exception);
pp::Var DoConnectSandboxed(const std::vector<pp::Var>& args, pp::Var DoConnectUnsandboxed(const std::vector<pp::Var>& args,
pp::Var* exception); pp::Var* exception);
pp::Var DoDisconnect(const std::vector<pp::Var>& args, pp::Var* exception); pp::Var DoDisconnect(const std::vector<pp::Var>& args, pp::Var* exception);
......
...@@ -55,7 +55,7 @@ function registerConnection() { ...@@ -55,7 +55,7 @@ function registerConnection() {
var clientjid = xhr.responseText; var clientjid = xhr.responseText;
remoting.plugin.sendIq = sendIq; remoting.plugin.sendIq = sendIq;
remoting.plugin.connectSandboxed(clientjid, remoting.hostjid, remoting.plugin.connect(remoting.hostjid, clientjid,
remoting.accessCode); remoting.accessCode);
// TODO(ajwong): This should just be feedIq(); // TODO(ajwong): This should just be feedIq();
window.setTimeout(feedIq, 1000); window.setTimeout(feedIq, 1000);
...@@ -123,7 +123,7 @@ function init() { ...@@ -123,7 +123,7 @@ function init() {
if (remoting.connectMethod == 'sandboxed') { if (remoting.connectMethod == 'sandboxed') {
registerConnection(); registerConnection();
} else { } else {
plugin.connect(remoting.username, remoting.hostjid, plugin.connectUnsandboxed(remoting.hostjid, remoting.username,
remoting.xmppAuthToken, remoting.accessCode); remoting.xmppAuthToken, remoting.accessCode);
} }
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment