summaryrefslogtreecommitdiffstats
path: root/remoting/webapp
diff options
context:
space:
mode:
authorlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 06:51:02 +0000
committerlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 06:51:02 +0000
commit7e5a3b7da21f756b5b093ec73ba84d72aace80d8 (patch)
tree0250497a69371e9c8b2788e3be3c1963d2efbfd2 /remoting/webapp
parent51a2478710c9b2beda273832f2e4f4c825aa279a (diff)
downloadchromium_src-7e5a3b7da21f756b5b093ec73ba84d72aace80d8.zip
chromium_src-7e5a3b7da21f756b5b093ec73ba84d72aace80d8.tar.gz
chromium_src-7e5a3b7da21f756b5b093ec73ba84d72aace80d8.tar.bz2
Make NPAPI Me2Me interface return results via callback parameters.
This is to aid migration to Native Messaging, where the web-app will need to pass callbacks to receive all information asynchronously from the Native Messaging host. BUG=173509 TEST=register, start and connect to a host, change PIN, 0 jscompile errors Review URL: https://chromiumcodereview.appspot.com/12089099 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r--remoting/webapp/host_controller.js87
-rw-r--r--remoting/webapp/host_plugin_proto.js12
2 files changed, 67 insertions, 32 deletions
diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js
index 4612ee6..83c9844 100644
--- a/remoting/webapp/host_controller.js
+++ b/remoting/webapp/host_controller.js
@@ -91,6 +91,7 @@ remoting.HostController.prototype.getConsent = function(callback) {
/**
* Registers and starts the host.
+ *
* @param {string} hostPin Host PIN.
* @param {boolean} consent The user's consent to crash dump reporting.
* @param {function(remoting.HostController.AsyncResult):void} callback
@@ -100,7 +101,6 @@ remoting.HostController.prototype.getConsent = function(callback) {
remoting.HostController.prototype.start = function(hostPin, consent, callback) {
/** @type {remoting.HostController} */
var that = this;
- var hostName = this.plugin_.getHostName();
/** @return {string} */
function generateUuid() {
@@ -134,28 +134,18 @@ remoting.HostController.prototype.start = function(hostPin, consent, callback) {
callback(result);
};
- /** @param {string} publicKey
- * @param {string} privateKey
- * @param {XMLHttpRequest} xhr */
- function onRegistered(publicKey, privateKey, xhr) {
+ /**
+ * @param {string} hostName
+ * @param {string} publicKey
+ * @param {string} privateKey
+ * @param {XMLHttpRequest} xhr
+ */
+ function onRegistered(hostName, publicKey, privateKey, xhr) {
var success = (xhr.status == 200);
if (success) {
- var hostSecretHash =
- that.plugin_.getPinHash(newHostId, hostPin);
- var hostConfig = JSON.stringify({
- xmpp_login: remoting.identity.getCachedEmail(),
- oauth_refresh_token: remoting.oauth2.exportRefreshToken(),
- host_id: newHostId,
- host_name: hostName,
- host_secret_hash: hostSecretHash,
- private_key: privateKey
- });
- /** @param {remoting.HostController.AsyncResult} result */
- var onStartDaemon = function(result) {
- onStarted(callback, result, hostName, publicKey);
- };
- that.plugin_.startDaemon(hostConfig, consent, onStartDaemon);
+ that.plugin_.getPinHash(newHostId, hostPin, startHostWithHash.bind(
+ null, hostName, publicKey, privateKey, xhr));
} else {
console.log('Failed to register the host. Status: ' + xhr.status +
' response: ' + xhr.responseText);
@@ -164,11 +154,36 @@ remoting.HostController.prototype.start = function(hostPin, consent, callback) {
};
/**
+ * @param {string} hostName
+ * @param {string} publicKey
+ * @param {string} privateKey
+ * @param {XMLHttpRequest} xhr
+ * @param {string} hostSecretHash
+ */
+ function startHostWithHash(hostName, publicKey, privateKey, xhr,
+ hostSecretHash) {
+ var hostConfig = JSON.stringify({
+ xmpp_login: remoting.identity.getCachedEmail(),
+ oauth_refresh_token: remoting.oauth2.exportRefreshToken(),
+ host_id: newHostId,
+ host_name: hostName,
+ host_secret_hash: hostSecretHash,
+ private_key: privateKey
+ });
+ /** @param {remoting.HostController.AsyncResult} result */
+ var onStartDaemon = function(result) {
+ onStarted(callback, result, hostName, publicKey);
+ };
+ that.plugin_.startDaemon(hostConfig, consent, onStartDaemon);
+ }
+
+ /**
+ * @param {string} hostName
* @param {string} privateKey
* @param {string} publicKey
* @param {string} oauthToken
*/
- function doRegisterHost(privateKey, publicKey, oauthToken) {
+ function doRegisterHost(hostName, privateKey, publicKey, oauthToken) {
var headers = {
'Authorization': 'OAuth ' + oauthToken,
'Content-type' : 'application/json; charset=UTF-8'
@@ -182,18 +197,21 @@ remoting.HostController.prototype.start = function(hostPin, consent, callback) {
remoting.xhr.post(
remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/',
/** @param {XMLHttpRequest} xhr */
- function (xhr) { onRegistered(publicKey, privateKey, xhr); },
+ function (xhr) { onRegistered(hostName, publicKey, privateKey, xhr); },
JSON.stringify(newHostDetails),
headers);
};
- /** @param {string} privateKey
- * @param {string} publicKey */
- function onKeyGenerated(privateKey, publicKey) {
+ /**
+ * @param {string} hostName
+ * @param {string} privateKey
+ * @param {string} publicKey
+ */
+ function onKeyGenerated(hostName, privateKey, publicKey) {
remoting.identity.callWithToken(
/** @param {string} oauthToken */
function(oauthToken) {
- doRegisterHost(privateKey, publicKey, oauthToken);
+ doRegisterHost(hostName, privateKey, publicKey, oauthToken);
},
/** @param {remoting.Error} error */
function(error) {
@@ -202,7 +220,15 @@ remoting.HostController.prototype.start = function(hostPin, consent, callback) {
});
};
- this.plugin_.generateKeyPair(onKeyGenerated);
+ /**
+ * @param {string} hostName
+ * @return {void} Nothing.
+ */
+ function startWithHostname(hostName) {
+ that.plugin_.generateKeyPair(onKeyGenerated.bind(null, hostName));
+ }
+
+ this.plugin_.getHostName(startWithHostname);
};
/**
@@ -270,8 +296,13 @@ remoting.HostController.prototype.updatePin = function(newPin, callback) {
return;
}
var hostId = config['host_id'];
+ that.plugin_.getPinHash(hostId, newPin, updateDaemonConfigWithHash);
+ };
+
+ /** @param {string} pinHash */
+ function updateDaemonConfigWithHash(pinHash) {
var newConfig = JSON.stringify({
- host_secret_hash: that.plugin_.getPinHash(hostId, newPin)
+ host_secret_hash: pinHash
});
that.plugin_.updateDaemonConfig(newConfig, callback);
};
diff --git a/remoting/webapp/host_plugin_proto.js b/remoting/webapp/host_plugin_proto.js
index fd4255e..0074fa6 100644
--- a/remoting/webapp/host_plugin_proto.js
+++ b/remoting/webapp/host_plugin_proto.js
@@ -25,13 +25,17 @@ remoting.HostPlugin.prototype.disconnect = function() {};
* @return {void} Nothing. */
remoting.HostPlugin.prototype.localize = function(callback) {};
-/** @return {string} Local hostname. */
-remoting.HostPlugin.prototype.getHostName = function() {};
+/** @param {function(string):void} callback Callback to be called with the
+ * local hostname.
+ * @return {void} Nothing. */
+remoting.HostPlugin.prototype.getHostName = function(callback) {};
/** @param {string} hostId The host ID.
* @param {string} pin The PIN.
- * @return {string} The hash encoded with Base64. */
-remoting.HostPlugin.prototype.getPinHash = function(hostId, pin) {};
+ * @param {function(string):void} callback Callback to be called with the hash
+ * encoded with Base64.
+ * @return {void} Nothing. */
+remoting.HostPlugin.prototype.getPinHash = function(hostId, pin, callback) {};
/** @param {function(string, string):void} callback Callback to be called
* after new key is generated.