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

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

Issue 232223003: Windows chromoting host installation via the NPAPI plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** @constructor */ 10 /** @constructor */
11 remoting.HostController = function() { 11 remoting.HostController = function() {
12 /** @return {remoting.HostPlugin} */ 12 this.hostDispatcher_ = this.createDispatcher_();
13 var createPluginForMe2Me = function() {
14 /** @type {HTMLElement} @private */
15 var container = document.getElementById('daemon-plugin-container');
16 return remoting.createNpapiPlugin(container);
17 };
18
19 /** @type {remoting.HostDispatcher} @private */
20 this.hostDispatcher_ = new remoting.HostDispatcher(createPluginForMe2Me);
21
22 /** @param {string} version */
23 var printVersion = function(version) {
24 if (version == '') {
25 console.log('Host not installed.');
26 } else {
27 console.log('Host version: ' + version);
28 }
29 };
30
31 this.hostDispatcher_.getDaemonVersion(printVersion, function() {
32 console.log('Host version not available.');
33 });
34 }; 13 };
35 14
36 // Note that the values in the enums below are copied from 15 // Note that the values in the enums below are copied from
37 // daemon_controller.h and must be kept in sync. 16 // daemon_controller.h and must be kept in sync.
38 /** @enum {number} */ 17 /** @enum {number} */
39 remoting.HostController.State = { 18 remoting.HostController.State = {
40 NOT_IMPLEMENTED: -1, 19 NOT_IMPLEMENTED: -1,
41 NOT_INSTALLED: 0, 20 NOT_INSTALLED: 0,
42 INSTALLING: 1, 21 INSTALLING: 1,
43 STOPPED: 2, 22 STOPPED: 2,
(...skipping 27 matching lines...) Expand all
71 * @return {remoting.HostController.AsyncResult} The result enum value. 50 * @return {remoting.HostController.AsyncResult} The result enum value.
72 */ 51 */
73 remoting.HostController.AsyncResult.fromString = function(result) { 52 remoting.HostController.AsyncResult.fromString = function(result) {
74 if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) { 53 if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) {
75 throw "Invalid HostController.AsyncResult: " + result; 54 throw "Invalid HostController.AsyncResult: " + result;
76 } 55 }
77 return remoting.HostController.AsyncResult[result]; 56 return remoting.HostController.AsyncResult[result];
78 } 57 }
79 58
80 /** 59 /**
60 * @return {remoting.HostDispatcher}
61 * @private
62 */
63 remoting.HostController.prototype.createDispatcher_ = function() {
64 /** @return {remoting.HostPlugin} */
65 var createPluginForMe2Me = function() {
66 /** @type {HTMLElement} @private */
67 var container = document.getElementById('daemon-plugin-container');
68 return remoting.createNpapiPlugin(container);
69 };
70
71 /** @type {remoting.HostDispatcher} @private */
72 var hostDispatcher = new remoting.HostDispatcher(createPluginForMe2Me);
73
74 /** @param {string} version */
75 var printVersion = function(version) {
76 if (version == '') {
77 console.log('Host not installed.');
78 } else {
79 console.log('Host version: ' + version);
80 }
81 };
82
83 hostDispatcher.getDaemonVersion(printVersion, function() {
84 console.log('Host version not available.');
85 });
86
87 return hostDispatcher;
88 };
89
90 /**
81 * Set of features for which hasFeature() can be used to test. 91 * Set of features for which hasFeature() can be used to test.
82 * 92 *
83 * @enum {string} 93 * @enum {string}
84 */ 94 */
85 remoting.HostController.Feature = { 95 remoting.HostController.Feature = {
86 PAIRING_REGISTRY: 'pairingRegistry', 96 PAIRING_REGISTRY: 'pairingRegistry',
87 OAUTH_CLIENT: 'oauthClient' 97 OAUTH_CLIENT: 'oauthClient'
88 }; 98 };
89 99
90 /** 100 /**
(...skipping 11 matching lines...) Expand all
102 * @param {function(boolean, boolean, boolean):void} onDone Callback to be 112 * @param {function(boolean, boolean, boolean):void} onDone Callback to be
103 * called when done. 113 * called when done.
104 * @param {function(remoting.Error):void} onError Callback to be called on 114 * @param {function(remoting.Error):void} onError Callback to be called on
105 * error. 115 * error.
106 */ 116 */
107 remoting.HostController.prototype.getConsent = function(onDone, onError) { 117 remoting.HostController.prototype.getConsent = function(onDone, onError) {
108 this.hostDispatcher_.getUsageStatsConsent(onDone, onError); 118 this.hostDispatcher_.getUsageStatsConsent(onDone, onError);
109 }; 119 };
110 120
111 /** 121 /**
122 * @param {function(remoting.HostController.AsyncResult):void} onDone
123 * @param {function(remoting.Error):void} onError
124 * @return {void}
125 */
126 remoting.HostController.prototype.installHost = function(onDone, onError) {
127 this.hostDispatcher_.installHost(onDone, onError);
128 };
129
130 /**
112 * Registers and starts the host. 131 * Registers and starts the host.
113 * 132 *
114 * @param {string} hostPin Host PIN. 133 * @param {string} hostPin Host PIN.
115 * @param {boolean} consent The user's consent to crash dump reporting. 134 * @param {boolean} consent The user's consent to crash dump reporting.
116 * @param {function():void} onDone Callback to be called when done. 135 * @param {function():void} onDone Callback to be called when done.
117 * @param {function(remoting.Error):void} onError Callback to be called on 136 * @param {function(remoting.Error):void} onError Callback to be called on
118 * error. 137 * error.
119 * @return {void} Nothing. 138 * @return {void} Nothing.
120 */ 139 */
121 remoting.HostController.prototype.start = function(hostPin, consent, onDone, 140 remoting.HostController.prototype.start = function(hostPin, consent, onDone,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 337
319 /** 338 /**
320 * @param {string} hostName 339 * @param {string} hostName
321 * @return {void} Nothing. 340 * @return {void} Nothing.
322 */ 341 */
323 function startWithHostname(hostName) { 342 function startWithHostname(hostName) {
324 that.hostDispatcher_.generateKeyPair(onKeyGenerated.bind(null, hostName), 343 that.hostDispatcher_.generateKeyPair(onKeyGenerated.bind(null, hostName),
325 onError); 344 onError);
326 } 345 }
327 346
328 this.hostDispatcher_.getHostName(startWithHostname, onError); 347 /** @param {remoting.HostController.AsyncResult} asyncResult */
348 var onHostInstalled = function(asyncResult) {
349 if (asyncResult == remoting.HostController.AsyncResult.OK) {
350 // Now that the host is installed, we need to get a new dispatcher that
351 // dispatches to the NM host instead of the NPAPI plugin.
352 console.log('Recreating the host dispatcher.');
353 that.hostDispatcher_ = that.createDispatcher_();
354 that.hostDispatcher_.getHostName(startWithHostname, onError);
355 } else if (asyncResult == remoting.HostController.AsyncResult.CANCELLED) {
356 onError(remoting.Error.CANCELLED);
357 } else {
358 onError(remoting.Error.UNEXPECTED);
359 }
360 }
361
362 // Perform the installation step here on Windows.
363 if (navigator.platform == 'Win32') {
364 this.installHost(onHostInstalled, onError);
365 } else {
366 this.hostDispatcher_.getHostName(startWithHostname, onError);
367 }
329 }; 368 };
330 369
331 /** 370 /**
332 * Stop the daemon process. 371 * Stop the daemon process.
333 * @param {function():void} onDone Callback to be called when done. 372 * @param {function():void} onDone Callback to be called when done.
334 * @param {function(remoting.Error):void} onError Callback to be called on 373 * @param {function(remoting.Error):void} onError Callback to be called on
335 * error. 374 * error.
336 * @return {void} Nothing. 375 * @return {void} Nothing.
337 */ 376 */
338 remoting.HostController.prototype.stop = function(onDone, onError) { 377 remoting.HostController.prototype.stop = function(onDone, onError) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 /** 534 /**
496 * Returns true if the NPAPI plugin is being used. 535 * Returns true if the NPAPI plugin is being used.
497 * @return {boolean} 536 * @return {boolean}
498 */ 537 */
499 remoting.HostController.prototype.usingNpapiPlugin = function() { 538 remoting.HostController.prototype.usingNpapiPlugin = function() {
500 return this.hostDispatcher_.usingNpapiPlugin(); 539 return this.hostDispatcher_.usingNpapiPlugin();
501 } 540 }
502 541
503 /** @type {remoting.HostController} */ 542 /** @type {remoting.HostController} */
504 remoting.hostController = null; 543 remoting.hostController = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698