summaryrefslogtreecommitdiffstats
path: root/remoting/webapp/host_dispatcher.js
diff options
context:
space:
mode:
authorlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 14:17:45 +0000
committerlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 14:17:45 +0000
commit2b4f940f736ed129706eac31142640559e6fe841 (patch)
tree327adca5ddeb3832f3f6342f4aee76735eaec80c /remoting/webapp/host_dispatcher.js
parentf80e0be6cbc72de3f1d0794b2472e0f48f688da7 (diff)
downloadchromium_src-2b4f940f736ed129706eac31142640559e6fe841.zip
chromium_src-2b4f940f736ed129706eac31142640559e6fe841.tar.gz
chromium_src-2b4f940f736ed129706eac31142640559e6fe841.tar.bz2
Add support for pairing-registry APIs to host_dispatcher.js.
BUG=156182 Review URL: https://chromiumcodereview.appspot.com/19116006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp/host_dispatcher.js')
-rw-r--r--remoting/webapp/host_dispatcher.js96
1 files changed, 94 insertions, 2 deletions
diff --git a/remoting/webapp/host_dispatcher.js b/remoting/webapp/host_dispatcher.js
index 7ac0d93..7b81c0e 100644
--- a/remoting/webapp/host_dispatcher.js
+++ b/remoting/webapp/host_dispatcher.js
@@ -5,7 +5,7 @@
/**
* @fileoverview
* This class provides an interface between the HostController and either the
- * NativeMessaging Host or the Host NPAPI plugin, depending on whether
+ * NativeMessaging Host or the Host NPAPI plugin, depending on whether or not
* NativeMessaging is supported. Since the test for NativeMessaging support is
* asynchronous, this class stores any requests on a queue, pending the result
* of the test.
@@ -338,4 +338,96 @@ remoting.HostDispatcher.prototype.getDaemonState = function(callback, onError) {
}
break;
}
-}
+};
+
+/**
+ * @param {function(Array.<remoting.PairedClient>):void} callback
+ * @param {function(remoting.Error):void} onError
+ * @return {void}
+ */
+remoting.HostDispatcher.prototype.getPairedClients = function(callback,
+ onError) {
+ /**
+ * Converts the JSON string from the NPAPI plugin to Array.<PairedClient>, to
+ * pass to |callback|.
+ * @param {string} pairedClientsJson
+ * @return {void}
+ */
+ function callbackForNpapi(pairedClientsJson) {
+ var pairedClients = remoting.PairedClient.convertToPairedClientArray(
+ jsonParseSafe(pairedClientsJson));
+ if (pairedClients != null) {
+ callback(pairedClients);
+ } else {
+ onError(remoting.Error.UNEXPECTED);
+ }
+ }
+
+ switch (this.state_) {
+ case remoting.HostDispatcher.State.UNKNOWN:
+ this.pendingRequests_.push(
+ this.getPairedClients.bind(this, callback, onError));
+ break;
+ case remoting.HostDispatcher.State.NATIVE_MESSAGING:
+ this.nativeMessagingHost_.getPairedClients(callback, onError);
+ break;
+ case remoting.HostDispatcher.State.NPAPI:
+ try {
+ this.npapiHost_.getPairedClients(callbackForNpapi);
+ } catch (err) {
+ onError(remoting.Error.MISSING_PLUGIN);
+ }
+ break;
+ }
+};
+
+/**
+ * @param {function(boolean):void} onDone
+ * @param {function(remoting.Error):void} onError
+ * @return {void}
+ */
+remoting.HostDispatcher.prototype.clearPairedClients =
+ function(onDone, onError) {
+ switch (this.state_) {
+ case remoting.HostDispatcher.State.UNKNOWN:
+ this.pendingRequests_.push(
+ this.clearPairedClients.bind(this, onDone, onError));
+ break;
+ case remoting.HostDispatcher.State.NATIVE_MESSAGING:
+ this.nativeMessagingHost_.clearPairedClients(onDone, onError);
+ break;
+ case remoting.HostDispatcher.State.NPAPI:
+ try {
+ this.npapiHost_.clearPairedClients(onDone);
+ } catch (err) {
+ onError(remoting.Error.MISSING_PLUGIN);
+ }
+ break;
+ }
+};
+
+/**
+ * @param {string} client
+ * @param {function(boolean):void} onDone
+ * @param {function(remoting.Error):void} onError
+ * @return {void}
+ */
+remoting.HostDispatcher.prototype.deletePairedClient =
+ function(client, onDone, onError) {
+ switch (this.state_) {
+ case remoting.HostDispatcher.State.UNKNOWN:
+ this.pendingRequests_.push(
+ this.deletePairedClient.bind(this, client, onDone, onError));
+ break;
+ case remoting.HostDispatcher.State.NATIVE_MESSAGING:
+ this.nativeMessagingHost_.deletePairedClient(client, onDone, onError);
+ break;
+ case remoting.HostDispatcher.State.NPAPI:
+ try {
+ this.npapiHost_.deletePairedClient(client, onDone);
+ } catch (err) {
+ onError(remoting.Error.MISSING_PLUGIN);
+ }
+ break;
+ }
+};