| 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 */ |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 */ | 96 */ |
| 97 remoting.HostController.prototype.hasFeature = function(feature, callback) { | 97 remoting.HostController.prototype.hasFeature = function(feature, callback) { |
| 98 // TODO(rmsousa): This could synchronously return a boolean, provided it were | 98 // TODO(rmsousa): This could synchronously return a boolean, provided it were |
| 99 // only called after native messaging is completely initialized. | 99 // only called after native messaging is completely initialized. |
| 100 this.hostDaemonFacade_.hasFeature(feature, callback); | 100 this.hostDaemonFacade_.hasFeature(feature, callback); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @param {function(boolean, boolean, boolean):void} onDone Callback to be | 104 * @param {function(boolean, boolean, boolean):void} onDone Callback to be |
| 105 * called when done. | 105 * called when done. |
| 106 * @param {function(remoting.Error):void} onError Callback to be called on | 106 * @param {function(!remoting.Error):void} onError Callback to be called on |
| 107 * error. | 107 * error. |
| 108 */ | 108 */ |
| 109 remoting.HostController.prototype.getConsent = function(onDone, onError) { | 109 remoting.HostController.prototype.getConsent = function(onDone, onError) { |
| 110 this.hostDaemonFacade_.getUsageStatsConsent(onDone, onError); | 110 this.hostDaemonFacade_.getUsageStatsConsent(onDone, onError); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * Registers and starts the host. | 114 * Registers and starts the host. |
| 115 * | 115 * |
| 116 * @param {string} hostPin Host PIN. | 116 * @param {string} hostPin Host PIN. |
| 117 * @param {boolean} consent The user's consent to crash dump reporting. | 117 * @param {boolean} consent The user's consent to crash dump reporting. |
| 118 * @param {function():void} onDone Callback to be called when done. | 118 * @param {function():void} onDone Callback to be called when done. |
| 119 * @param {function(remoting.Error):void} onError Callback to be called on | 119 * @param {function(!remoting.Error):void} onError Callback to be called on |
| 120 * error. | 120 * error. |
| 121 * @return {void} Nothing. | 121 * @return {void} Nothing. |
| 122 */ | 122 */ |
| 123 remoting.HostController.prototype.start = function(hostPin, consent, onDone, | 123 remoting.HostController.prototype.start = function(hostPin, consent, onDone, |
| 124 onError) { | 124 onError) { |
| 125 /** @type {remoting.HostController} */ | 125 /** @type {remoting.HostController} */ |
| 126 var that = this; | 126 var that = this; |
| 127 | 127 |
| 128 /** @return {string} */ | 128 /** @return {string} */ |
| 129 function generateUuid() { | 129 function generateUuid() { |
| 130 var random = new Uint16Array(8); | 130 var random = new Uint16Array(8); |
| 131 window.crypto.getRandomValues(random); | 131 window.crypto.getRandomValues(random); |
| 132 /** @type {Array<string>} */ | 132 /** @type {Array<string>} */ |
| 133 var e = new Array(); | 133 var e = new Array(); |
| 134 for (var i = 0; i < 8; i++) { | 134 for (var i = 0; i < 8; i++) { |
| 135 e[i] = (/** @type {number} */ (random[i]) + 0x10000). | 135 e[i] = (/** @type {number} */ (random[i]) + 0x10000). |
| 136 toString(16).substring(1); | 136 toString(16).substring(1); |
| 137 } | 137 } |
| 138 return e[0] + e[1] + '-' + e[2] + '-' + e[3] + '-' + | 138 return e[0] + e[1] + '-' + e[2] + '-' + e[3] + '-' + |
| 139 e[4] + '-' + e[5] + e[6] + e[7]; | 139 e[4] + '-' + e[5] + e[6] + e[7]; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 var newHostId = generateUuid(); | 142 var newHostId = generateUuid(); |
| 143 | 143 |
| 144 /** @param {remoting.Error} error */ | 144 /** @param {!remoting.Error} error */ |
| 145 function onStartError(error) { | 145 function onStartError(error) { |
| 146 // Unregister the host if we failed to start it. | 146 // Unregister the host if we failed to start it. |
| 147 remoting.HostList.unregisterHostById(newHostId); | 147 remoting.HostList.unregisterHostById(newHostId); |
| 148 onError(error); | 148 onError(error); |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * @param {string} hostName | 152 * @param {string} hostName |
| 153 * @param {string} publicKey | 153 * @param {string} publicKey |
| 154 * @param {remoting.HostController.AsyncResult} result | 154 * @param {remoting.HostController.AsyncResult} result |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 that.hostDaemonFacade_.generateKeyPair(onKeyGenerated.bind(null, hostName), | 345 that.hostDaemonFacade_.generateKeyPair(onKeyGenerated.bind(null, hostName), |
| 346 onError); | 346 onError); |
| 347 } | 347 } |
| 348 | 348 |
| 349 this.hostDaemonFacade_.getHostName(startWithHostname, onError); | 349 this.hostDaemonFacade_.getHostName(startWithHostname, onError); |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * Stop the daemon process. | 353 * Stop the daemon process. |
| 354 * @param {function():void} onDone Callback to be called when done. | 354 * @param {function():void} onDone Callback to be called when done. |
| 355 * @param {function(remoting.Error):void} onError Callback to be called on | 355 * @param {function(!remoting.Error):void} onError Callback to be called on |
| 356 * error. | 356 * error. |
| 357 * @return {void} Nothing. | 357 * @return {void} Nothing. |
| 358 */ | 358 */ |
| 359 remoting.HostController.prototype.stop = function(onDone, onError) { | 359 remoting.HostController.prototype.stop = function(onDone, onError) { |
| 360 /** @type {remoting.HostController} */ | 360 /** @type {remoting.HostController} */ |
| 361 var that = this; | 361 var that = this; |
| 362 | 362 |
| 363 /** @param {string?} hostId The host id of the local host. */ | 363 /** @param {string?} hostId The host id of the local host. */ |
| 364 function unregisterHost(hostId) { | 364 function unregisterHost(hostId) { |
| 365 if (hostId) { | 365 if (hostId) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 389 * @return {boolean} True if it is valid. | 389 * @return {boolean} True if it is valid. |
| 390 */ | 390 */ |
| 391 function isHostConfigValid_(config) { | 391 function isHostConfigValid_(config) { |
| 392 return !!config && typeof config['host_id'] == 'string' && | 392 return !!config && typeof config['host_id'] == 'string' && |
| 393 typeof config['xmpp_login'] == 'string'; | 393 typeof config['xmpp_login'] == 'string'; |
| 394 } | 394 } |
| 395 | 395 |
| 396 /** | 396 /** |
| 397 * @param {string} newPin The new PIN to set | 397 * @param {string} newPin The new PIN to set |
| 398 * @param {function():void} onDone Callback to be called when done. | 398 * @param {function():void} onDone Callback to be called when done. |
| 399 * @param {function(remoting.Error):void} onError Callback to be called on | 399 * @param {function(!remoting.Error):void} onError Callback to be called on |
| 400 * error. | 400 * error. |
| 401 * @return {void} Nothing. | 401 * @return {void} Nothing. |
| 402 */ | 402 */ |
| 403 remoting.HostController.prototype.updatePin = function(newPin, onDone, | 403 remoting.HostController.prototype.updatePin = function(newPin, onDone, |
| 404 onError) { | 404 onError) { |
| 405 /** @type {remoting.HostController} */ | 405 /** @type {remoting.HostController} */ |
| 406 var that = this; | 406 var that = this; |
| 407 | 407 |
| 408 /** @param {remoting.HostController.AsyncResult} result */ | 408 /** @param {remoting.HostController.AsyncResult} result */ |
| 409 function onConfigUpdated(result) { | 409 function onConfigUpdated(result) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 this.hostDaemonFacade_.getDaemonConfig(onConfig, onError); | 442 this.hostDaemonFacade_.getDaemonConfig(onConfig, onError); |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 /** | 445 /** |
| 446 * Get the state of the local host. | 446 * Get the state of the local host. |
| 447 * | 447 * |
| 448 * @param {function(remoting.HostController.State):void} onDone Completion | 448 * @param {function(remoting.HostController.State):void} onDone Completion |
| 449 * callback. | 449 * callback. |
| 450 */ | 450 */ |
| 451 remoting.HostController.prototype.getLocalHostState = function(onDone) { | 451 remoting.HostController.prototype.getLocalHostState = function(onDone) { |
| 452 /** @param {remoting.Error} error */ | 452 /** @param {!remoting.Error} error */ |
| 453 function onError(error) { | 453 function onError(error) { |
| 454 onDone((error == remoting.Error.MISSING_PLUGIN) ? | 454 onDone((error.tag == remoting.Error.Tag.MISSING_PLUGIN) ? |
| 455 remoting.HostController.State.NOT_INSTALLED : | 455 remoting.HostController.State.NOT_INSTALLED : |
| 456 remoting.HostController.State.UNKNOWN); | 456 remoting.HostController.State.UNKNOWN); |
| 457 } | 457 } |
| 458 this.hostDaemonFacade_.getDaemonState(onDone, onError); | 458 this.hostDaemonFacade_.getDaemonState(onDone, onError); |
| 459 }; | 459 }; |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * Get the id of the local host, or null if it is not registered. | 462 * Get the id of the local host, or null if it is not registered. |
| 463 * | 463 * |
| 464 * @param {function(string?):void} onDone Completion callback. | 464 * @param {function(string?):void} onDone Completion callback. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 477 | 477 |
| 478 this.hostDaemonFacade_.getDaemonConfig(onConfig, function(error) { | 478 this.hostDaemonFacade_.getDaemonConfig(onConfig, function(error) { |
| 479 onDone(null); | 479 onDone(null); |
| 480 }); | 480 }); |
| 481 }; | 481 }; |
| 482 | 482 |
| 483 /** | 483 /** |
| 484 * Fetch the list of paired clients for this host. | 484 * Fetch the list of paired clients for this host. |
| 485 * | 485 * |
| 486 * @param {function(Array<remoting.PairedClient>):void} onDone | 486 * @param {function(Array<remoting.PairedClient>):void} onDone |
| 487 * @param {function(remoting.Error):void} onError | 487 * @param {function(!remoting.Error):void} onError |
| 488 * @return {void} | 488 * @return {void} |
| 489 */ | 489 */ |
| 490 remoting.HostController.prototype.getPairedClients = function(onDone, | 490 remoting.HostController.prototype.getPairedClients = function(onDone, |
| 491 onError) { | 491 onError) { |
| 492 this.hostDaemonFacade_.getPairedClients(onDone, onError); | 492 this.hostDaemonFacade_.getPairedClients(onDone, onError); |
| 493 }; | 493 }; |
| 494 | 494 |
| 495 /** | 495 /** |
| 496 * Delete a single paired client. | 496 * Delete a single paired client. |
| 497 * | 497 * |
| 498 * @param {string} client The client id of the pairing to delete. | 498 * @param {string} client The client id of the pairing to delete. |
| 499 * @param {function():void} onDone Completion callback. | 499 * @param {function():void} onDone Completion callback. |
| 500 * @param {function(remoting.Error):void} onError Error callback. | 500 * @param {function(!remoting.Error):void} onError Error callback. |
| 501 * @return {void} | 501 * @return {void} |
| 502 */ | 502 */ |
| 503 remoting.HostController.prototype.deletePairedClient = function( | 503 remoting.HostController.prototype.deletePairedClient = function( |
| 504 client, onDone, onError) { | 504 client, onDone, onError) { |
| 505 this.hostDaemonFacade_.deletePairedClient(client, onDone, onError); | 505 this.hostDaemonFacade_.deletePairedClient(client, onDone, onError); |
| 506 }; | 506 }; |
| 507 | 507 |
| 508 /** | 508 /** |
| 509 * Delete all paired clients. | 509 * Delete all paired clients. |
| 510 * | 510 * |
| 511 * @param {function():void} onDone Completion callback. | 511 * @param {function():void} onDone Completion callback. |
| 512 * @param {function(remoting.Error):void} onError Error callback. | 512 * @param {function(!remoting.Error):void} onError Error callback. |
| 513 * @return {void} | 513 * @return {void} |
| 514 */ | 514 */ |
| 515 remoting.HostController.prototype.clearPairedClients = function( | 515 remoting.HostController.prototype.clearPairedClients = function( |
| 516 onDone, onError) { | 516 onDone, onError) { |
| 517 this.hostDaemonFacade_.clearPairedClients(onDone, onError); | 517 this.hostDaemonFacade_.clearPairedClients(onDone, onError); |
| 518 }; | 518 }; |
| 519 | 519 |
| 520 /** | 520 /** |
| 521 * Gets the host owner's base JID, used by the host for client authorization. | 521 * Gets the host owner's base JID, used by the host for client authorization. |
| 522 * In most cases this is the same as the owner's email address, but for | 522 * In most cases this is the same as the owner's email address, but for |
| 523 * non-Gmail accounts, it may be different. | 523 * non-Gmail accounts, it may be different. |
| 524 * | 524 * |
| 525 * @private | 525 * @private |
| 526 * @param {function(string): void} onSuccess | 526 * @param {function(string): void} onSuccess |
| 527 * @param {function(remoting.Error): void} onError | 527 * @param {function(!remoting.Error): void} onError |
| 528 */ | 528 */ |
| 529 remoting.HostController.prototype.getClientBaseJid_ = function( | 529 remoting.HostController.prototype.getClientBaseJid_ = function( |
| 530 onSuccess, onError) { | 530 onSuccess, onError) { |
| 531 /** @type {remoting.SignalStrategy} */ | 531 /** @type {remoting.SignalStrategy} */ |
| 532 var signalStrategy = null; | 532 var signalStrategy = null; |
| 533 | 533 |
| 534 /** @param {remoting.SignalStrategy.State} state */ | 534 /** @param {remoting.SignalStrategy.State} state */ |
| 535 var onState = function(state) { | 535 var onState = function(state) { |
| 536 switch (state) { | 536 switch (state) { |
| 537 case remoting.SignalStrategy.State.CONNECTED: | 537 case remoting.SignalStrategy.State.CONNECTED: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 568 signalStrategy.connect( | 568 signalStrategy.connect( |
| 569 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); | 569 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); |
| 570 } | 570 } |
| 571 | 571 |
| 572 remoting.identity.getToken().then( | 572 remoting.identity.getToken().then( |
| 573 connectSignalingWithToken, remoting.Error.handler(onError)); | 573 connectSignalingWithToken, remoting.Error.handler(onError)); |
| 574 }; | 574 }; |
| 575 | 575 |
| 576 /** @type {remoting.HostController} */ | 576 /** @type {remoting.HostController} */ |
| 577 remoting.hostController = null; | 577 remoting.hostController = null; |
| OLD | NEW |