OLD | NEW |
---|---|
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 Loading... | |
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 */ | |
62 remoting.HostController.prototype.createDispatcher = function() { | |
Jamie
2014/04/10 18:29:32
If this is private, please append _ to the name an
weitao
2014/04/10 21:33:47
Done.
| |
63 /** @return {remoting.HostPlugin} */ | |
64 var createPluginForMe2Me = function() { | |
65 /** @type {HTMLElement} @private */ | |
66 var container = document.getElementById('daemon-plugin-container'); | |
67 return remoting.createNpapiPlugin(container); | |
68 }; | |
69 | |
70 /** @type {remoting.HostDispatcher} @private */ | |
71 var hostDispatcher = new remoting.HostDispatcher(createPluginForMe2Me); | |
72 | |
73 /** @param {string} version */ | |
74 var printVersion = function(version) { | |
75 if (version == '') { | |
76 console.log('Host not installed.'); | |
77 } else { | |
78 console.log('Host version: ' + version); | |
79 } | |
80 }; | |
81 | |
82 hostDispatcher.getDaemonVersion(printVersion, function() { | |
83 console.log('Host version not available.'); | |
84 }); | |
85 | |
86 return hostDispatcher; | |
87 }; | |
88 | |
89 /** | |
81 * Set of features for which hasFeature() can be used to test. | 90 * Set of features for which hasFeature() can be used to test. |
82 * | 91 * |
83 * @enum {string} | 92 * @enum {string} |
84 */ | 93 */ |
85 remoting.HostController.Feature = { | 94 remoting.HostController.Feature = { |
86 PAIRING_REGISTRY: 'pairingRegistry', | 95 PAIRING_REGISTRY: 'pairingRegistry', |
87 OAUTH_CLIENT: 'oauthClient' | 96 OAUTH_CLIENT: 'oauthClient' |
88 }; | 97 }; |
89 | 98 |
90 /** | 99 /** |
(...skipping 11 matching lines...) Expand all Loading... | |
102 * @param {function(boolean, boolean, boolean):void} onDone Callback to be | 111 * @param {function(boolean, boolean, boolean):void} onDone Callback to be |
103 * called when done. | 112 * called when done. |
104 * @param {function(remoting.Error):void} onError Callback to be called on | 113 * @param {function(remoting.Error):void} onError Callback to be called on |
105 * error. | 114 * error. |
106 */ | 115 */ |
107 remoting.HostController.prototype.getConsent = function(onDone, onError) { | 116 remoting.HostController.prototype.getConsent = function(onDone, onError) { |
108 this.hostDispatcher_.getUsageStatsConsent(onDone, onError); | 117 this.hostDispatcher_.getUsageStatsConsent(onDone, onError); |
109 }; | 118 }; |
110 | 119 |
111 /** | 120 /** |
121 * @param {function(remoting.HostController.AsyncResult):void} onDone | |
122 * @param {function(remoting.Error):void} onError | |
123 * @return {void} | |
124 */ | |
125 remoting.HostController.prototype.installHost = function(onDone, onError) { | |
126 this.hostDispatcher_.installHost(onDone, onError); | |
127 }; | |
128 | |
129 /** | |
112 * Registers and starts the host. | 130 * Registers and starts the host. |
113 * | 131 * |
114 * @param {string} hostPin Host PIN. | 132 * @param {string} hostPin Host PIN. |
115 * @param {boolean} consent The user's consent to crash dump reporting. | 133 * @param {boolean} consent The user's consent to crash dump reporting. |
116 * @param {function():void} onDone Callback to be called when done. | 134 * @param {function():void} onDone Callback to be called when done. |
117 * @param {function(remoting.Error):void} onError Callback to be called on | 135 * @param {function(remoting.Error):void} onError Callback to be called on |
118 * error. | 136 * error. |
119 * @return {void} Nothing. | 137 * @return {void} Nothing. |
120 */ | 138 */ |
121 remoting.HostController.prototype.start = function(hostPin, consent, onDone, | 139 remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 | 336 |
319 /** | 337 /** |
320 * @param {string} hostName | 338 * @param {string} hostName |
321 * @return {void} Nothing. | 339 * @return {void} Nothing. |
322 */ | 340 */ |
323 function startWithHostname(hostName) { | 341 function startWithHostname(hostName) { |
324 that.hostDispatcher_.generateKeyPair(onKeyGenerated.bind(null, hostName), | 342 that.hostDispatcher_.generateKeyPair(onKeyGenerated.bind(null, hostName), |
325 onError); | 343 onError); |
326 } | 344 } |
327 | 345 |
328 this.hostDispatcher_.getHostName(startWithHostname, onError); | 346 /** @param {remoting.HostController.AsyncResult} asyncResult */ |
347 var onHostInstalled = function(asyncResult) { | |
348 if (asyncResult == remoting.HostController.AsyncResult.OK) { | |
349 console.log('Recreating the host dispatcher.'); | |
350 that.hostDispatcher_ = that.createDispatcher(); | |
Jamie
2014/04/10 18:29:32
This is done in the ctor; does it need to be done
weitao
2014/04/10 21:33:47
Yes. Now that the host is installed, we need to ge
| |
351 that.hostDispatcher_.getHostName(startWithHostname, onError); | |
352 } else if (asyncResult == remoting.HostController.AsyncResult.CANCELLED) { | |
353 onError(remoting.Error.CANCELLED); | |
354 } else { | |
355 onError(remoting.Error.UNEXPECTED); | |
356 } | |
357 } | |
358 | |
359 // Perform the installation step here on Windows. | |
360 if (navigator.platform == 'Win32') { | |
361 this.installHost(onHostInstalled, onError); | |
362 } else { | |
363 this.hostDispatcher_.getHostName(startWithHostname, onError); | |
364 } | |
329 }; | 365 }; |
330 | 366 |
331 /** | 367 /** |
332 * Stop the daemon process. | 368 * Stop the daemon process. |
333 * @param {function():void} onDone Callback to be called when done. | 369 * @param {function():void} onDone Callback to be called when done. |
334 * @param {function(remoting.Error):void} onError Callback to be called on | 370 * @param {function(remoting.Error):void} onError Callback to be called on |
335 * error. | 371 * error. |
336 * @return {void} Nothing. | 372 * @return {void} Nothing. |
337 */ | 373 */ |
338 remoting.HostController.prototype.stop = function(onDone, onError) { | 374 remoting.HostController.prototype.stop = function(onDone, onError) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 /** | 531 /** |
496 * Returns true if the NPAPI plugin is being used. | 532 * Returns true if the NPAPI plugin is being used. |
497 * @return {boolean} | 533 * @return {boolean} |
498 */ | 534 */ |
499 remoting.HostController.prototype.usingNpapiPlugin = function() { | 535 remoting.HostController.prototype.usingNpapiPlugin = function() { |
500 return this.hostDispatcher_.usingNpapiPlugin(); | 536 return this.hostDispatcher_.usingNpapiPlugin(); |
501 } | 537 } |
502 | 538 |
503 /** @type {remoting.HostController} */ | 539 /** @type {remoting.HostController} */ |
504 remoting.hostController = null; | 540 remoting.hostController = null; |
OLD | NEW |