Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: remoting/webapp/host_native_messaging.js

Issue 17465007: Remoting webapp: Add onError param to HostNativeMessaging.initialize() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/webapp/host_dispatcher.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class to communicate with the Host components via Native Messaging. 7 * Class to communicate with the Host components via Native Messaging.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 this.type = type; 49 this.type = type;
50 this.callback = callback; 50 this.callback = callback;
51 this.onError = onError; 51 this.onError = onError;
52 }; 52 };
53 53
54 /** 54 /**
55 * Sets up connection to the Native Messaging host process and exchanges 55 * Sets up connection to the Native Messaging host process and exchanges
56 * 'hello' messages. If Native Messaging is not available or the host 56 * 'hello' messages. If Native Messaging is not available or the host
57 * process is not installed, this returns false to the callback. 57 * process is not installed, this returns false to the callback.
58 * 58 *
59 * @param {function(boolean): void} onDone Called with the result of 59 * @param {function(): void} onDone Called after successful initialization.
60 * initialization. 60 * @param {function(remoting.Error): void} onError Called if initialization
61 * failed.
61 * @return {void} Nothing. 62 * @return {void} Nothing.
62 */ 63 */
63 remoting.HostNativeMessaging.prototype.initialize = function(onDone) { 64 remoting.HostNativeMessaging.prototype.initialize = function(onDone, onError) {
64 if (!chrome.runtime.connectNative) { 65 if (!chrome.runtime.connectNative) {
65 console.log('Native Messaging API not available'); 66 console.log('Native Messaging API not available');
66 onDone(false); 67 onError(remoting.Error.UNEXPECTED);
67 return; 68 return;
68 } 69 }
69 70
70 // NativeMessaging API exists on Chrome 26.xxx but fails to notify 71 // NativeMessaging API exists on Chrome 26.xxx but fails to notify
71 // onDisconnect in the case where the Host components are not installed. Need 72 // onDisconnect in the case where the Host components are not installed. Need
72 // to blacklist these versions of Chrome. 73 // to blacklist these versions of Chrome.
73 var majorVersion = navigator.appVersion.match('Chrome/(\\d+)\.')[1]; 74 var majorVersion = navigator.appVersion.match('Chrome/(\\d+)\.')[1];
74 if (!majorVersion || majorVersion <= 26) { 75 if (!majorVersion || majorVersion <= 26) {
75 console.log('Native Messaging not supported on this version of Chrome'); 76 console.log('Native Messaging not supported on this version of Chrome');
76 onDone(false); 77 onError(remoting.Error.UNEXPECTED);
77 return; 78 return;
78 } 79 }
79 80
80 try { 81 try {
81 this.port_ = chrome.runtime.connectNative( 82 this.port_ = chrome.runtime.connectNative(
82 'com.google.chrome.remote_desktop'); 83 'com.google.chrome.remote_desktop');
83 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); 84 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this));
84 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this)); 85 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this));
85 this.postMessage_({type: 'hello'}, onDone.bind(null, true), 86 this.postMessage_({type: 'hello'}, onDone,
86 onDone.bind(null, false)); 87 onError.bind(null, remoting.Error.UNEXPECTED));
87 } catch (err) { 88 } catch (err) {
88 console.log('Native Messaging initialization failed: ', 89 console.log('Native Messaging initialization failed: ',
89 /** @type {*} */ (err)); 90 /** @type {*} */ (err));
90 onDone(false); 91 onError(remoting.Error.UNEXPECTED);
91 return; 92 return;
92 } 93 }
93 }; 94 };
94 95
95 /** 96 /**
96 * Verifies that |object| is of type |type|, logging an error if not. 97 * Verifies that |object| is of type |type|, logging an error if not.
97 * 98 *
98 * @param {string} name Name of the object, to be included in the error log. 99 * @param {string} name Name of the object, to be included in the error log.
99 * @param {*} object Object to test. 100 * @param {*} object Object to test.
100 * @param {string} type Expected type of the object. 101 * @param {string} type Expected type of the object.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 * @param {function(remoting.Error):void} onError Callback to be triggered 537 * @param {function(remoting.Error):void} onError Callback to be triggered
537 * on error. 538 * on error.
538 */ 539 */
539 remoting.HostNativeMessaging.prototype.deletePairedClient = 540 remoting.HostNativeMessaging.prototype.deletePairedClient =
540 function(client, onDone, onError) { 541 function(client, onDone, onError) {
541 this.postMessage_({ 542 this.postMessage_({
542 type: 'deletePairedClient', 543 type: 'deletePairedClient',
543 clientId: client 544 clientId: client
544 }, onDone, onError); 545 }, onDone, onError);
545 } 546 }
OLDNEW
« no previous file with comments | « remoting/webapp/host_dispatcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698