| OLD | NEW |
| 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 * Functions related to the 'client screen' for Chromoting. | 7 * Functions related to the 'client screen' for Chromoting. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Initiate an IT2Me connection. | 16 * Initiate an IT2Me connection. |
| 17 */ | 17 */ |
| 18 remoting.connectIT2Me = function() { | 18 remoting.connectIT2Me = function() { |
| 19 var connector = remoting.app.getSessionConnector(); | 19 var connector = remoting.app.getSessionConnector(); |
| 20 var accessCode = document.getElementById('access-code-entry').value; | 20 var accessCode = document.getElementById('access-code-entry').value; |
| 21 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 21 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 22 remoting.It2MeConnectFlow.start(connector, accessCode). | 22 remoting.It2MeConnectFlow.start(connector, accessCode).catch( |
| 23 catch(function(/** !remoting.Error */ reason){ | 23 function(/** remoting.Error */ reason){ |
| 24 var errorDiv = document.getElementById('connect-error-message'); | 24 var errorDiv = document.getElementById('connect-error-message'); |
| 25 l10n.localizeElementFromTag(errorDiv, reason.getTag()); | 25 l10n.localizeElementFromTag(errorDiv, reason.getTag()); |
| 26 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 26 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); |
| 27 }); | 27 }); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Entry-point for Me2Me connections, handling showing of the host-upgrade nag | 31 * Entry-point for Me2Me connections, handling showing of the host-upgrade nag |
| 32 * dialog if necessary. | 32 * dialog if necessary. |
| 33 * | 33 * |
| 34 * @param {string} hostId The unique id of the host. | 34 * @param {string} hostId The unique id of the host. |
| 35 * @return {void} Nothing. | 35 * @return {void} Nothing. |
| 36 */ | 36 */ |
| 37 remoting.connectMe2Me = function(hostId) { | 37 remoting.connectMe2Me = function(hostId) { |
| 38 var host = remoting.hostList.getHostForId(hostId); | 38 var host = remoting.hostList.getHostForId(hostId); |
| 39 if (!host) { | |
| 40 remoting.app.onError(new remoting.Error( | |
| 41 remoting.Error.Tag.HOST_IS_OFFLINE)); | |
| 42 return; | |
| 43 } | |
| 44 var webappVersion = chrome.runtime.getManifest().version; | |
| 45 var needsUpdateDialog = new remoting.HostNeedsUpdateDialog( | |
| 46 document.getElementById('host-needs-update-dialog'), host); | |
| 47 | |
| 48 needsUpdateDialog.showIfNecessary(webappVersion).then(function() { | |
| 49 remoting.connectMe2MeHostVersionAcknowledged_(host); | |
| 50 }).catch(function(/** remoting.Error */ error) { | |
| 51 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { | |
| 52 remoting.setMode(remoting.AppMode.HOME); | |
| 53 } | |
| 54 }); | |
| 55 }; | |
| 56 | |
| 57 /** | |
| 58 * Shows PIN entry screen localized to include the host name, and registers | |
| 59 * a host-specific one-shot event handler for the form submission. | |
| 60 * | |
| 61 * @param {remoting.Host} host The Me2Me host to which to connect. | |
| 62 * @return {void} Nothing. | |
| 63 */ | |
| 64 remoting.connectMe2MeHostVersionAcknowledged_ = function(host) { | |
| 65 /** @type {remoting.SessionConnector} */ | |
| 66 var connector = remoting.app.getSessionConnector(); | 39 var connector = remoting.app.getSessionConnector(); |
| 67 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 40 var flow = new remoting.Me2MeConnectFlow(connector, host); |
| 68 | 41 flow.start(); |
| 69 /** | 42 }; |
| 70 * @param {string} tokenUrl Token-issue URL received from the host. | |
| 71 * @param {string} hostPublicKey Host public key (DER and Base64 encoded). | |
| 72 * @param {string} scope OAuth scope to request the token for. | |
| 73 * @param {function(string, string):void} onThirdPartyTokenFetched Callback. | |
| 74 */ | |
| 75 var fetchThirdPartyToken = function( | |
| 76 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { | |
| 77 var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher( | |
| 78 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns, | |
| 79 onThirdPartyTokenFetched); | |
| 80 thirdPartyTokenFetcher.fetchToken(); | |
| 81 }; | |
| 82 | |
| 83 /** | |
| 84 * @param {boolean} supportsPairing | |
| 85 * @param {function(string):void} onPinFetched | |
| 86 */ | |
| 87 var requestPin = function(supportsPairing, onPinFetched) { | |
| 88 var pinDialog = | |
| 89 new remoting.PinDialog(document.getElementById('pin-dialog'), host); | |
| 90 pinDialog.show(supportsPairing).then(function(/** string */ pin) { | |
| 91 onPinFetched(pin); | |
| 92 /** @type {boolean} */ | |
| 93 remoting.pairingRequested = pinDialog.pairingRequested(); | |
| 94 }); | |
| 95 }; | |
| 96 | |
| 97 /** @param {Object} settings */ | |
| 98 var connectMe2MeHostSettingsRetrieved = function(settings) { | |
| 99 /** @type {string} */ | |
| 100 var clientId = ''; | |
| 101 /** @type {string} */ | |
| 102 var sharedSecret = ''; | |
| 103 var pairingInfo = /** @type {Object} */ (settings['pairingInfo']); | |
| 104 if (pairingInfo) { | |
| 105 clientId = /** @type {string} */ (pairingInfo['clientId']); | |
| 106 sharedSecret = /** @type {string} */ (pairingInfo['sharedSecret']); | |
| 107 } | |
| 108 connector.connectMe2Me(host, requestPin, fetchThirdPartyToken, | |
| 109 clientId, sharedSecret); | |
| 110 } | |
| 111 | |
| 112 remoting.HostSettings.load(host.hostId, connectMe2MeHostSettingsRetrieved); | |
| 113 }; | |
| OLD | NEW |