summaryrefslogtreecommitdiffstats
path: root/remoting/webapp
diff options
context:
space:
mode:
authorlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 23:43:00 +0000
committerlambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 23:43:00 +0000
commit5f37610ffe6c89e9efd19f95825d2c03507d5e34 (patch)
treec3cbd49ab618d9af642489381c233419169f75f1 /remoting/webapp
parentb5d4a2a0f2a3d3173f6361bcf0eba5673d23125b (diff)
downloadchromium_src-5f37610ffe6c89e9efd19f95825d2c03507d5e34.zip
chromium_src-5f37610ffe6c89e9efd19f95825d2c03507d5e34.tar.gz
chromium_src-5f37610ffe6c89e9efd19f95825d2c03507d5e34.tar.bz2
Remoting webapp: Add onError param to HostNativeMessaging.initialize()
This makes the method consistent with the other methods of HostNativeMessaging, and allows future flexibility to define error codes, instead of just passing a boolean to onDone(). BUG=249970 TEST=Verify host setup flow, with and without native messaging. Review URL: https://chromiumcodereview.appspot.com/17465007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r--remoting/webapp/host_dispatcher.js30
-rw-r--r--remoting/webapp/host_native_messaging.js17
2 files changed, 26 insertions, 21 deletions
diff --git a/remoting/webapp/host_dispatcher.js b/remoting/webapp/host_dispatcher.js
index 7841eb6..c05cf3f 100644
--- a/remoting/webapp/host_dispatcher.js
+++ b/remoting/webapp/host_dispatcher.js
@@ -43,24 +43,28 @@ remoting.HostDispatcher = function(createPluginCallback) {
/** @type {Array.<function()>} */
this.pendingRequests_ = [];
- /** @param {boolean} success */
- var onNativeMessagingInit = function(success) {
- if (success) {
- console.log('Native Messaging supported.');
- that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING;
- } else {
- console.log('Native Messaging unsupported, falling back to NPAPI.');
- that.npapiHost_ = createPluginCallback();
- that.state_ = remoting.HostDispatcher.State.NPAPI;
- }
- // Send pending requests.
+ function sendPendingRequests() {
for (var i = 0; i < that.pendingRequests_.length; i++) {
that.pendingRequests_[i]();
}
that.pendingRequests_ = null;
- };
+ }
+
+ function onNativeMessagingInit() {
+ console.log('Native Messaging supported.');
+ that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING;
+ sendPendingRequests();
+ }
+
+ function onNativeMessagingFailed(error) {
+ console.log('Native Messaging unsupported, falling back to NPAPI.');
+ that.npapiHost_ = createPluginCallback();
+ that.state_ = remoting.HostDispatcher.State.NPAPI;
+ sendPendingRequests();
+ }
- this.nativeMessagingHost_.initialize(onNativeMessagingInit);
+ this.nativeMessagingHost_.initialize(onNativeMessagingInit,
+ onNativeMessagingFailed);
};
/** @enum {number} */
diff --git a/remoting/webapp/host_native_messaging.js b/remoting/webapp/host_native_messaging.js
index fd6372c..3da45c3 100644
--- a/remoting/webapp/host_native_messaging.js
+++ b/remoting/webapp/host_native_messaging.js
@@ -56,14 +56,15 @@ remoting.HostNativeMessaging.PendingReply = function(type, callback, onError) {
* 'hello' messages. If Native Messaging is not available or the host
* process is not installed, this returns false to the callback.
*
- * @param {function(boolean): void} onDone Called with the result of
- * initialization.
+ * @param {function(): void} onDone Called after successful initialization.
+ * @param {function(remoting.Error): void} onError Called if initialization
+ * failed.
* @return {void} Nothing.
*/
-remoting.HostNativeMessaging.prototype.initialize = function(onDone) {
+remoting.HostNativeMessaging.prototype.initialize = function(onDone, onError) {
if (!chrome.runtime.connectNative) {
console.log('Native Messaging API not available');
- onDone(false);
+ onError(remoting.Error.UNEXPECTED);
return;
}
@@ -73,7 +74,7 @@ remoting.HostNativeMessaging.prototype.initialize = function(onDone) {
var majorVersion = navigator.appVersion.match('Chrome/(\\d+)\.')[1];
if (!majorVersion || majorVersion <= 26) {
console.log('Native Messaging not supported on this version of Chrome');
- onDone(false);
+ onError(remoting.Error.UNEXPECTED);
return;
}
@@ -82,12 +83,12 @@ remoting.HostNativeMessaging.prototype.initialize = function(onDone) {
'com.google.chrome.remote_desktop');
this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this));
this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this));
- this.postMessage_({type: 'hello'}, onDone.bind(null, true),
- onDone.bind(null, false));
+ this.postMessage_({type: 'hello'}, onDone,
+ onError.bind(null, remoting.Error.UNEXPECTED));
} catch (err) {
console.log('Native Messaging initialization failed: ',
/** @type {*} */ (err));
- onDone(false);
+ onError(remoting.Error.UNEXPECTED);
return;
}
};