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

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

Issue 1054273002: [Webapp Refactor] Implements remoting.Activity. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo 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.Activity}
17 */ 18 */
18 remoting.Me2MeConnectFlow = function(sessionConnector, host) { 19 remoting.Me2MeActivity = 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
25 remoting.Me2MeConnectFlow.prototype.start = function() { 34 remoting.Me2MeActivity.prototype.dispose = function() {};
35
36 remoting.Me2MeActivity.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.Me2MeActivity.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.Me2MeActivity.prototype.onConnectionFailed = function(error) {
94 var that = this;
95 var onHostListRefresh = function(/** boolean */ success) {
96 if (success) {
97 // Get the host from the hostList for the refreshed JID.
98 var host = remoting.hostList.getHostForId(that.host_.hostId);
99 that.connector_.retryConnectMe2Me(host);
100 return;
101 }
102 that.onError(error);
103 };
104
105 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) &&
106 this.retryOnHostOffline_) {
107 this.retryOnHostOffline_ = false;
108
109 // The plugin will be re-created when the host finished refreshing
110 remoting.hostList.refresh(onHostListRefresh);
111 } else {
112 this.onError(error);
113 }
114 };
115
116 /**
117 * @param {!remoting.ConnectionInfo} connectionInfo
118 */
119 remoting.Me2MeActivity.prototype.onConnected = function(connectionInfo) {
120 // Reset the refresh flag so that the next connection will retry if needed.
121 this.retryOnHostOffline_ = true;
122
123 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) {
124 this.connector_.registerProtocolExtension(
125 new remoting.CastExtensionHandler());
126 }
127 this.connector_.registerProtocolExtension(new remoting.GnubbyAuthHandler());
128 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin(),
129 this.connector_);
130 };
131
132 remoting.Me2MeActivity.prototype.onDisconnected = function() {
133 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
134 };
135
136 /**
137 * @param {!remoting.Error} error
138 */
139 remoting.Me2MeActivity.prototype.onError = function(error) {
140 this.retryOnHostOffline_ = true;
141 var errorDiv = document.getElementById('connect-error-message');
142 l10n.localizeElementFromTag(errorDiv, error.getTag());
143 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME);
144 };
84 145
85 /** 146 /**
86 * @param {HTMLElement} rootElement 147 * @param {HTMLElement} rootElement
87 * @param {remoting.Host} host 148 * @param {remoting.Host} host
88 * @constructor 149 * @constructor
89 */ 150 */
90 remoting.HostNeedsUpdateDialog = function(rootElement, host) { 151 remoting.HostNeedsUpdateDialog = function(rootElement, host) {
91 /** @private */ 152 /** @private */
92 this.host_ = host; 153 this.host_ = host;
93 /** @private */ 154 /** @private */
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 remoting.PinDialog.prototype.show = function(supportsPairing) { 243 remoting.PinDialog.prototype.show = function(supportsPairing) {
183 // Reset the UI. 244 // Reset the UI.
184 this.pairingCheckbox_.checked = false; 245 this.pairingCheckbox_.checked = false;
185 this.rootElement_.querySelector('.pairing-section').hidden = !supportsPairing; 246 this.rootElement_.querySelector('.pairing-section').hidden = !supportsPairing;
186 var message = this.rootElement_.querySelector('.pin-message'); 247 var message = this.rootElement_.querySelector('.pin-message');
187 l10n.localizeElement(message, this.host_.hostName); 248 l10n.localizeElement(message, this.host_.hostName);
188 this.pinInput_.value = ''; 249 this.pinInput_.value = '';
189 return this.dialog_.show(); 250 return this.dialog_.show();
190 }; 251 };
191 252
192 /** @return {boolean} */ 253 /**
193 remoting.PinDialog.prototype.pairingRequested = function() { 254 * @param {remoting.ClientPlugin} plugin
194 return this.pairingCheckbox_.checked; 255 * @param {remoting.SessionConnector} connector
256 */
257 remoting.PinDialog.prototype.requestPairingIfNecessary =
258 function(plugin, connector) {
259 if (this.pairingCheckbox_.checked) {
260 var that = this;
261 /**
262 * @param {string} clientId
263 * @param {string} sharedSecret
264 */
265 var onPairingComplete = function(clientId, sharedSecret) {
266 that.host_.options.pairingInfo.clientId = clientId;
267 that.host_.options.pairingInfo.sharedSecret = sharedSecret;
268 that.host_.options.save();
269 connector.updatePairingInfo(clientId, sharedSecret);
270 };
271
272 // Use the platform name as a proxy for the local computer name.
273 // TODO(jamiewalch): Use a descriptive name for the local computer, for
274 // example, its Chrome Sync name.
275 var clientName = '';
276 if (remoting.platformIsMac()) {
277 clientName = 'Mac';
278 } else if (remoting.platformIsWindows()) {
279 clientName = 'Windows';
280 } else if (remoting.platformIsChromeOS()) {
281 clientName = 'ChromeOS';
282 } else if (remoting.platformIsLinux()) {
283 clientName = 'Linux';
284 } else {
285 console.log('Unrecognized client platform. Using navigator.platform.');
286 clientName = navigator.platform;
287 }
288 plugin.requestPairing(clientName, onPairingComplete);
289 }
195 }; 290 };
196 291
197 })(); 292 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/it2me_connect_flow.js ('k') | remoting/webapp/crd/js/me2me_connect_flow.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698