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

Side by Side Diff: remoting/webapp/crd/js/me2me_connect_flow.js

Issue 1054273002: [Webapp Refactor] Implements remoting.Activity. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** @suppress {duplicate} */ 5 /** @suppress {duplicate} */
6 var remoting = remoting || {}; 6 var remoting = remoting || {};
7 7
8 (function() { 8 (function() {
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** 12 /**
13 * @param {remoting.SessionConnector} sessionConnector 13 * @param {remoting.SessionConnector} sessionConnector
14 * @param {remoting.Host} host 14 * @param {remoting.Host} host
15 * 15 *
16 * @constructor 16 * @constructor
17 * @implements {remoting.ConnectFlow}
17 */ 18 */
18 remoting.Me2MeConnectFlow = function(sessionConnector, host) { 19 remoting.Me2MeConnectFlow = function(sessionConnector, host) {
19 /** @private */ 20 /** @private */
20 this.host_ = host; 21 this.host_ = host;
21 /** @private */ 22 /** @private */
22 this.connector_ = sessionConnector; 23 this.connector_ = sessionConnector;
24 /** @private */
25 this.pinDialog_ =
26 new remoting.PinDialog(document.getElementById('pin-dialog'), host);
27 /** @private */
28 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog(
29 document.getElementById('host-needs-update-dialog'), this.host_);
30 /** @private */
31 this.retryOnHostOffline_ = true;
23 }; 32 };
24 33
34 remoting.Me2MeConnectFlow.prototype.dispose = function() {};
35
25 remoting.Me2MeConnectFlow.prototype.start = function() { 36 remoting.Me2MeConnectFlow.prototype.start = function() {
26 var webappVersion = chrome.runtime.getManifest().version; 37 var webappVersion = chrome.runtime.getManifest().version;
27 var needsUpdateDialog = new remoting.HostNeedsUpdateDialog(
28 document.getElementById('host-needs-update-dialog'), this.host_);
29 var that = this; 38 var that = this;
30 39
31 needsUpdateDialog.showIfNecessary(webappVersion).then(function() { 40 this.hostUpdateDialog_.showIfNecessary(webappVersion).then(function() {
32 return that.host_.options.load(); 41 return that.host_.options.load();
33 }).then(function() { 42 }).then(function() {
34 that.connect_(); 43 that.connect_();
35 }).catch(function(/** remoting.Error */ error) { 44 }).catch(function(/** remoting.Error */ error) {
36 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { 45 if (error.hasTag(remoting.Error.Tag.CANCELLED)) {
37 remoting.setMode(remoting.AppMode.HOME); 46 remoting.setMode(remoting.AppMode.HOME);
38 } 47 }
39 }); 48 });
40 }; 49 };
41 50
42 /** @private */ 51 /** @private */
43 remoting.Me2MeConnectFlow.prototype.connect_ = function() { 52 remoting.Me2MeConnectFlow.prototype.connect_ = function() {
44 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 53 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
45 var host = this.host_; 54 var host = this.host_;
46 55
47 /** 56 /**
48 * @param {string} tokenUrl Token-issue URL received from the host. 57 * @param {string} tokenUrl Token-issue URL received from the host.
49 * @param {string} hostPublicKey Host public key (DER and Base64 encoded). 58 * @param {string} hostPublicKey Host public key (DER and Base64 encoded).
50 * @param {string} scope OAuth scope to request the token for. 59 * @param {string} scope OAuth scope to request the token for.
51 * @param {function(string, string):void} onThirdPartyTokenFetched Callback. 60 * @param {function(string, string):void} onThirdPartyTokenFetched Callback.
52 */ 61 */
53 var fetchThirdPartyToken = function( 62 var fetchThirdPartyToken = function(
54 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) { 63 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) {
55 var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher( 64 var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher(
56 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns, 65 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns,
57 onThirdPartyTokenFetched); 66 onThirdPartyTokenFetched);
58 thirdPartyTokenFetcher.fetchToken(); 67 thirdPartyTokenFetcher.fetchToken();
59 }; 68 };
60 69
70 var that = this;
61 /** 71 /**
62 * @param {boolean} supportsPairing 72 * @param {boolean} supportsPairing
63 * @param {function(string):void} onPinFetched 73 * @param {function(string):void} onPinFetched
64 */ 74 */
65 var requestPin = function(supportsPairing, onPinFetched) { 75 var requestPin = function(supportsPairing, onPinFetched) {
66 var pinDialog = 76 that.pinDialog_.show(supportsPairing).then(function(/** string */ pin) {
67 new remoting.PinDialog(document.getElementById('pin-dialog'), host);
68 pinDialog.show(supportsPairing).then(function(/** string */ pin) {
69 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 77 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
70 onPinFetched(pin); 78 onPinFetched(pin);
71 /** @type {boolean} */
72 remoting.pairingRequested = pinDialog.pairingRequested();
73 }).catch(function(/** remoting.Error */ error) { 79 }).catch(function(/** remoting.Error */ error) {
74 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED)); 80 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED));
75 remoting.setMode(remoting.AppMode.HOME); 81 remoting.setMode(remoting.AppMode.HOME);
76 }); 82 });
77 }; 83 };
78 84
79 var pairingInfo = host.options.pairingInfo; 85 var pairingInfo = host.options.pairingInfo;
80 this.connector_.connectMe2Me(host, requestPin, fetchThirdPartyToken, 86 this.connector_.connectMe2Me(host, requestPin, fetchThirdPartyToken,
81 pairingInfo.clientId, pairingInfo.sharedSecret); 87 pairingInfo.clientId, pairingInfo.sharedSecret);
82 }; 88 };
83 89
90 /**
91 * @param {!remoting.Error} error
92 */
93 remoting.Me2MeConnectFlow.prototype.onConnectionFailed = function(error) {
94 var that = this;
95 var onHostListRefresh = function(/** boolean */ success) {
96 if (success) {
97 that.connector_.retryConnectMe2Me(that.host_);
98 return;
99 }
100 that.onError(error);
101 };
102
103 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) &&
104 this.retryOnHostOffline_) {
105 this.retryOnHostOffline_ = false;
106
107 // The plugin will be re-created when the host finished refreshing
108 remoting.hostList.refresh(onHostListRefresh);
109 } else {
110 this.onError(error);
111 }
112 };
113
114 /**
115 * @param {!remoting.ConnectionInfo} connectionInfo
116 */
117 remoting.Me2MeConnectFlow.prototype.onConnected = function(connectionInfo) {
118 // Reset the refresh flag so that the next connection will retry if needed.
119 this.retryOnHostOffline_ = true;
120
121 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) {
122 this.connector_.registerProtocolExtension(
123 new remoting.CastExtensionHandler());
124 }
125 this.connector_.registerProtocolExtension(new remoting.GnubbyAuthHandler());
126 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin(),
127 this.connector_);
128 };
129
130 remoting.Me2MeConnectFlow.prototype.onDisconnected = function() {
131 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
132 };
133
134 /**
135 * @param {!remoting.Error} error
136 */
137 remoting.Me2MeConnectFlow.prototype.onError = function(error) {
138 this.retryOnHostOffline_ = true;
139 var errorDiv = document.getElementById('connect-error-message');
140 l10n.localizeElementFromTag(errorDiv, error.getTag());
141 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME);
142 };
84 143
85 /** 144 /**
86 * @param {HTMLElement} rootElement 145 * @param {HTMLElement} rootElement
87 * @param {remoting.Host} host 146 * @param {remoting.Host} host
88 * @constructor 147 * @constructor
89 */ 148 */
90 remoting.HostNeedsUpdateDialog = function(rootElement, host) { 149 remoting.HostNeedsUpdateDialog = function(rootElement, host) {
91 /** @private */ 150 /** @private */
92 this.host_ = host; 151 this.host_ = host;
93 /** @private */ 152 /** @private */
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 remoting.PinDialog.prototype.show = function(supportsPairing) { 241 remoting.PinDialog.prototype.show = function(supportsPairing) {
183 // Reset the UI. 242 // Reset the UI.
184 this.pairingCheckbox_.checked = false; 243 this.pairingCheckbox_.checked = false;
185 this.rootElement_.querySelector('.pairing-section').hidden = !supportsPairing; 244 this.rootElement_.querySelector('.pairing-section').hidden = !supportsPairing;
186 var message = this.rootElement_.querySelector('.pin-message'); 245 var message = this.rootElement_.querySelector('.pin-message');
187 l10n.localizeElement(message, this.host_.hostName); 246 l10n.localizeElement(message, this.host_.hostName);
188 this.pinInput_.value = ''; 247 this.pinInput_.value = '';
189 return this.dialog_.show(); 248 return this.dialog_.show();
190 }; 249 };
191 250
192 /** @return {boolean} */ 251 /**
193 remoting.PinDialog.prototype.pairingRequested = function() { 252 * @param {remoting.ClientPlugin} plugin
194 return this.pairingCheckbox_.checked; 253 * @param {remoting.SessionConnector} connector
254 */
255 remoting.PinDialog.prototype.requestPairingIfNecessary =
256 function(plugin, connector) {
257 if (this.pairingCheckbox_.checked) {
258 var that = this;
259 /**
260 * @param {string} clientId
261 * @param {string} sharedSecret
262 */
263 var onPairingComplete = function(clientId, sharedSecret) {
264 that.host_.options.pairingInfo.clientId = clientId;
265 that.host_.options.pairingInfo.sharedSecret = sharedSecret;
266 that.host_.options.save();
267 connector.updatePairingInfo(clientId, sharedSecret);
268 };
269
270 // Use the platform name as a proxy for the local computer name.
271 // TODO(jamiewalch): Use a descriptive name for the local computer, for
272 // example, its Chrome Sync name.
273 var clientName = '';
274 if (remoting.platformIsMac()) {
275 clientName = 'Mac';
276 } else if (remoting.platformIsWindows()) {
277 clientName = 'Windows';
278 } else if (remoting.platformIsChromeOS()) {
279 clientName = 'ChromeOS';
280 } else if (remoting.platformIsLinux()) {
281 clientName = 'Linux';
282 } else {
283 console.log('Unrecognized client platform. Using navigator.platform.');
284 clientName = navigator.platform;
285 }
286 plugin.requestPairing(clientName, onPairingComplete);
287 }
195 }; 288 };
196 289
197 })(); 290 })();
OLDNEW
« remoting/webapp/crd/js/desktop_remoting.js ('K') | « remoting/webapp/crd/js/it2me_connect_flow.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698