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

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

Issue 1008003002: [Webapp Refactor] Implements Me2MeConnectFlow as an object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/host.js ('k') | remoting/webapp/crd/js/session_connector_impl.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
14 * @param {remoting.Host} host
15 *
16 * @constructor
17 */
18 remoting.Me2MeConnectFlow = function(sessionConnector, host) {
19 /** @private */
20 this.host_ = host;
21 /** @private */
22 this.connector_ = sessionConnector;
23 };
24
25 remoting.Me2MeConnectFlow.prototype.start = function() {
26 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;
30
31 needsUpdateDialog.showIfNecessary(webappVersion).then(function() {
32 return that.host_.options.load();
33 }).then(function() {
34 that.connect_();
35 }).catch(function(/** remoting.Error */ error) {
36 if (error.hasTag(remoting.Error.Tag.CANCELLED)) {
37 remoting.setMode(remoting.AppMode.HOME);
38 }
39 });
40 };
41
42 /** @private */
43 remoting.Me2MeConnectFlow.prototype.connect_ = function() {
44 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
45 var host = this.host_;
46
47 /**
48 * @param {string} tokenUrl Token-issue URL received from the host.
49 * @param {string} hostPublicKey Host public key (DER and Base64 encoded).
50 * @param {string} scope OAuth scope to request the token for.
51 * @param {function(string, string):void} onThirdPartyTokenFetched Callback.
52 */
53 var fetchThirdPartyToken = function(
54 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) {
55 var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher(
56 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns,
57 onThirdPartyTokenFetched);
58 thirdPartyTokenFetcher.fetchToken();
59 };
60
61 /**
62 * @param {boolean} supportsPairing
63 * @param {function(string):void} onPinFetched
64 */
65 var requestPin = function(supportsPairing, onPinFetched) {
66 var pinDialog =
67 new remoting.PinDialog(document.getElementById('pin-dialog'), host);
68 pinDialog.show(supportsPairing).then(function(/** string */ pin) {
69 onPinFetched(pin);
70 /** @type {boolean} */
71 remoting.pairingRequested = pinDialog.pairingRequested();
72 });
73 };
74
75 var pairingInfo = host.options.pairingInfo;
76 this.connector_.connectMe2Me(host, requestPin, fetchThirdPartyToken,
77 pairingInfo.clientId, pairingInfo.sharedSecret);
78 };
79
80
81 /**
13 * @param {HTMLElement} rootElement 82 * @param {HTMLElement} rootElement
14 * @param {remoting.Host} host 83 * @param {remoting.Host} host
15 * @constructor 84 * @constructor
16 */ 85 */
17 remoting.HostNeedsUpdateDialog = function(rootElement, host) { 86 remoting.HostNeedsUpdateDialog = function(rootElement, host) {
18 /** @private */ 87 /** @private */
19 this.host_ = host; 88 this.host_ = host;
20 /** @private */ 89 /** @private */
21 this.rootElement_ = rootElement; 90 this.rootElement_ = rootElement;
22 /** @private {base.Deferred} */ 91 /** @private {base.Deferred} */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 /** @private {base.Disposables} */ 160 /** @private {base.Disposables} */
92 this.eventHooks_ = null; 161 this.eventHooks_ = null;
93 /** @private */ 162 /** @private */
94 this.pairingCheckbox_ = rootElement.querySelector('.pairing-checkbox'); 163 this.pairingCheckbox_ = rootElement.querySelector('.pairing-checkbox');
95 /** @private */ 164 /** @private */
96 this.pinInput_ = rootElement.querySelector('.pin-inputField'); 165 this.pinInput_ = rootElement.querySelector('.pin-inputField');
97 /** @private */ 166 /** @private */
98 this.host_ = host; 167 this.host_ = host;
99 }; 168 };
100 169
170
101 /** 171 /**
102 * @param {boolean} supportsPairing 172 * @param {boolean} supportsPairing
103 * @return {Promise<string>} Promise that resolves with the PIN or rejects with 173 * @return {Promise<string>} Promise that resolves with the PIN or rejects with
104 * |remoting.Error.CANCELLED| if the user cancels the connection. 174 * |remoting.Error.CANCELLED| if the user cancels the connection.
105 */ 175 */
106 remoting.PinDialog.prototype.show = function(supportsPairing) { 176 remoting.PinDialog.prototype.show = function(supportsPairing) {
107 var cancel = this.rootElement_.querySelector('.cancel-button'); 177 var cancel = this.rootElement_.querySelector('.cancel-button');
108 var form = this.rootElement_.querySelector('form'); 178 var form = this.rootElement_.querySelector('form');
109 var onCancel = this.createClickHandler_(this.onCancel_.bind(this)); 179 var onCancel = this.createClickHandler_(this.onCancel_.bind(this));
110 var onConnect = this.createClickHandler_(this.onConnect_.bind(this)); 180 var onConnect = this.createClickHandler_(this.onConnect_.bind(this));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); 231 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
162 }; 232 };
163 233
164 /** @private */ 234 /** @private */
165 remoting.PinDialog.prototype.onCancel_ = function() { 235 remoting.PinDialog.prototype.onCancel_ = function() {
166 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); 236 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED));
167 remoting.setMode(remoting.AppMode.HOME); 237 remoting.setMode(remoting.AppMode.HOME);
168 }; 238 };
169 239
170 })(); 240 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host.js ('k') | remoting/webapp/crd/js/session_connector_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698