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

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

Issue 396063003: Fix HostDaemonFacade to handle the case when NM host is not installed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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_controller.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 daemon via Native Messaging. 7 * Class to communicate with the host daemon via Native Messaging.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 25 matching lines...) Expand all
36 36
37 /** @type {Array.<remoting.HostController.Feature>} @private */ 37 /** @type {Array.<remoting.HostController.Feature>} @private */
38 this.supportedFeatures_ = []; 38 this.supportedFeatures_ = [];
39 39
40 /** @type {Array.<function(boolean):void>} @private */ 40 /** @type {Array.<function(boolean):void>} @private */
41 this.afterInitializationTasks_ = []; 41 this.afterInitializationTasks_ = [];
42 42
43 /** @private */ 43 /** @private */
44 this.initializationFinished_ = false; 44 this.initializationFinished_ = false;
45 45
46 /** @type {remoting.Error} @private */
47 this.error_ = remoting.Error.NONE;
48
46 try { 49 try {
47 this.port_ = chrome.runtime.connectNative( 50 this.port_ = chrome.runtime.connectNative(
48 'com.google.chrome.remote_desktop'); 51 'com.google.chrome.remote_desktop');
49 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); 52 this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this));
50 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this)); 53 this.port_.onDisconnect.addListener(this.onDisconnect_.bind(this));
51 this.postMessage_({type: 'hello'}, 54 this.postMessage_({type: 'hello'},
52 this.onInitialized_.bind(this, true), 55 this.onInitialized_.bind(this, true),
53 this.onInitialized_.bind(this, false)); 56 this.onInitialized_.bind(this, false));
54 } catch (err) { 57 } catch (err) {
55 console.log('Native Messaging initialization failed: ', 58 console.log('Native Messaging initialization failed: ',
(...skipping 17 matching lines...) Expand all
73 this.onError = onError; 76 this.onError = onError;
74 }; 77 };
75 78
76 /** 79 /**
77 * @param {boolean} success 80 * @param {boolean} success
78 * @return {void} Nothing. 81 * @return {void} Nothing.
79 * @private 82 * @private
80 */ 83 */
81 remoting.HostDaemonFacade.prototype.onInitialized_ = function(success) { 84 remoting.HostDaemonFacade.prototype.onInitialized_ = function(success) {
82 this.initializationFinished_ = true; 85 this.initializationFinished_ = true;
83 if (!success) {
84 this.port_ = null;
85 }
86
87 var afterInitializationTasks = this.afterInitializationTasks_; 86 var afterInitializationTasks = this.afterInitializationTasks_;
88 this.afterInitializationTasks_ = []; 87 this.afterInitializationTasks_ = [];
89 for (var id in afterInitializationTasks) { 88 for (var id in afterInitializationTasks) {
90 afterInitializationTasks[/** @type {number} */(id)](success); 89 afterInitializationTasks[/** @type {number} */(id)](success);
91 } 90 }
92 }; 91 };
93 92
94 /** 93 /**
95 * @param {remoting.HostController.Feature} feature The feature to test for. 94 * @param {remoting.HostController.Feature} feature The feature to test for.
96 * @param {function(boolean):void} onDone Callback to return result. 95 * @param {function(boolean):void} onDone Callback to return result.
(...skipping 24 matching lines...) Expand all
121 * @param {{type: string}} message The message to post. 120 * @param {{type: string}} message The message to post.
122 * @param {function(...):void} onDone The callback, if any, to be triggered 121 * @param {function(...):void} onDone The callback, if any, to be triggered
123 * on response. 122 * on response.
124 * @param {function(remoting.Error):void} onError Callback to call on error. 123 * @param {function(remoting.Error):void} onError Callback to call on error.
125 * @return {void} Nothing. 124 * @return {void} Nothing.
126 * @private 125 * @private
127 */ 126 */
128 remoting.HostDaemonFacade.prototype.postMessage_ = 127 remoting.HostDaemonFacade.prototype.postMessage_ =
129 function(message, onDone, onError) { 128 function(message, onDone, onError) {
130 if (!this.port_) { 129 if (!this.port_) {
131 onError(remoting.Error.UNEXPECTED); 130 onError(this.error_);
132 return; 131 return;
133 } 132 }
134 var id = this.nextId_++; 133 var id = this.nextId_++;
135 message['id'] = id; 134 message['id'] = id;
136 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply( 135 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply(
137 message.type + 'Response', onDone, onError); 136 message.type + 'Response', onDone, onError);
138 this.port_.postMessage(message); 137 this.port_.postMessage(message);
139 }; 138 };
140 139
141 /** 140 /**
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 272 }
274 }; 273 };
275 274
276 /** 275 /**
277 * @return {void} Nothing. 276 * @return {void} Nothing.
278 * @private 277 * @private
279 */ 278 */
280 remoting.HostDaemonFacade.prototype.onDisconnect_ = function() { 279 remoting.HostDaemonFacade.prototype.onDisconnect_ = function() {
281 console.error('Native Message port disconnected'); 280 console.error('Native Message port disconnected');
282 281
282 this.port_ = null;
283
284 // If initialization hasn't finished then assume that the port was
285 // disconnected because Native Messaging host is not installed.
286 this.error_ = this.initializationFinished_ ? remoting.Error.UNEXPECTED :
287 remoting.Error.MISSING_PLUGIN;
288
283 // Notify the error-handlers of any requests that are still outstanding. 289 // Notify the error-handlers of any requests that are still outstanding.
284 var pendingReplies = this.pendingReplies_; 290 var pendingReplies = this.pendingReplies_;
285 this.pendingReplies_ = {}; 291 this.pendingReplies_ = {};
286
287 for (var id in pendingReplies) { 292 for (var id in pendingReplies) {
288 pendingReplies[/** @type {number} */(id)].onError( 293 pendingReplies[/** @type {number} */(id)].onError(this.error_);
289 remoting.Error.UNEXPECTED);
290 } 294 }
291 } 295 }
292 296
293 /** 297 /**
294 * Gets local hostname. 298 * Gets local hostname.
295 * 299 *
296 * @param {function(string):void} onDone Callback to return result. 300 * @param {function(string):void} onDone Callback to return result.
297 * @param {function(remoting.Error):void} onError Callback to call on error. 301 * @param {function(remoting.Error):void} onError Callback to call on error.
298 * @return {void} Nothing. 302 * @return {void} Nothing.
299 */ 303 */
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 onDone(this.version_); 389 onDone(this.version_);
386 } else { 390 } else {
387 /** @type remoting.HostDaemonFacade */ 391 /** @type remoting.HostDaemonFacade */
388 var that = this; 392 var that = this;
389 this.afterInitializationTasks_.push( 393 this.afterInitializationTasks_.push(
390 /** @param {boolean} success */ 394 /** @param {boolean} success */
391 function(success) { 395 function(success) {
392 if (success) { 396 if (success) {
393 onDone(that.version_); 397 onDone(that.version_);
394 } else { 398 } else {
395 onError(remoting.Error.UNEXPECTED); 399 onError(that.error_);
396 } 400 }
397 }); 401 });
398 } 402 }
399 }; 403 };
400 404
401 /** 405 /**
402 * Get the user's consent to crash reporting. The consent flags are passed to 406 * Get the user's consent to crash reporting. The consent flags are passed to
403 * the callback as booleans: supported, allowed, set-by-policy. 407 * the callback as booleans: supported, allowed, set-by-policy.
404 * 408 *
405 * @param {function(boolean, boolean, boolean):void} onDone Callback to return 409 * @param {function(boolean, boolean, boolean):void} onDone Callback to return
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 * @param {function(remoting.Error):void} onError Callback to call on error. 518 * @param {function(remoting.Error):void} onError Callback to call on error.
515 * @return {void} Nothing. 519 * @return {void} Nothing.
516 */ 520 */
517 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = 521 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode =
518 function(authorizationCode, onDone, onError) { 522 function(authorizationCode, onDone, onError) {
519 this.postMessage_({ 523 this.postMessage_({
520 type: 'getCredentialsFromAuthCode', 524 type: 'getCredentialsFromAuthCode',
521 authorizationCode: authorizationCode 525 authorizationCode: authorizationCode
522 }, onDone, onError); 526 }, onDone, onError);
523 }; 527 };
OLDNEW
« no previous file with comments | « remoting/webapp/host_controller.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698