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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/me2me_connect_flow.js
diff --git a/remoting/webapp/crd/js/me2me_connect_flow.js b/remoting/webapp/crd/js/me2me_connect_flow.js
index 6c52febebf14200fb64a50ea746b60c153cf2162..40b94c1e1b4efb36f52351bd1865b8c740e92db3 100644
--- a/remoting/webapp/crd/js/me2me_connect_flow.js
+++ b/remoting/webapp/crd/js/me2me_connect_flow.js
@@ -10,6 +10,75 @@ var remoting = remoting || {};
'use strict';
/**
+ * @param {remoting.SessionConnector} sessionConnector
+ * @param {remoting.Host} host
+ *
+ * @constructor
+ */
+remoting.Me2MeConnectFlow = function(sessionConnector, host) {
+ /** @private */
+ this.host_ = host;
+ /** @private */
+ this.connector_ = sessionConnector;
+};
+
+remoting.Me2MeConnectFlow.prototype.start = function() {
+ var webappVersion = chrome.runtime.getManifest().version;
+ var needsUpdateDialog = new remoting.HostNeedsUpdateDialog(
+ document.getElementById('host-needs-update-dialog'), this.host_);
+ var that = this;
+
+ needsUpdateDialog.showIfNecessary(webappVersion).then(function() {
+ return that.host_.options.load();
+ }).then(function() {
+ that.connect_();
+ }).catch(function(/** remoting.Error */ error) {
+ if (error.hasTag(remoting.Error.Tag.CANCELLED)) {
+ remoting.setMode(remoting.AppMode.HOME);
+ }
+ });
+};
+
+/** @private */
+remoting.Me2MeConnectFlow.prototype.connect_ = function() {
+ remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
+ var host = this.host_;
+
+ /**
+ * @param {string} tokenUrl Token-issue URL received from the host.
+ * @param {string} hostPublicKey Host public key (DER and Base64 encoded).
+ * @param {string} scope OAuth scope to request the token for.
+ * @param {function(string, string):void} onThirdPartyTokenFetched Callback.
+ */
+ var fetchThirdPartyToken = function(
+ tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) {
+ var thirdPartyTokenFetcher = new remoting.ThirdPartyTokenFetcher(
+ tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns,
+ onThirdPartyTokenFetched);
+ thirdPartyTokenFetcher.fetchToken();
+ };
+
+ /**
+ * @param {boolean} supportsPairing
+ * @param {function(string):void} onPinFetched
+ */
+ var requestPin = function(supportsPairing, onPinFetched) {
+ var pinDialog =
+ new remoting.PinDialog(document.getElementById('pin-dialog'), host);
+ pinDialog.show(supportsPairing).then(function(/** string */ pin) {
+ onPinFetched(pin);
+ /** @type {boolean} */
+ remoting.pairingRequested = pinDialog.pairingRequested();
+ });
+ };
+
+ var pairingInfo = host.options.pairingInfo;
+ this.connector_.connectMe2Me(host, requestPin, fetchThirdPartyToken,
+ pairingInfo.clientId, pairingInfo.sharedSecret);
+};
+
+
+/**
* @param {HTMLElement} rootElement
* @param {remoting.Host} host
* @constructor
@@ -98,6 +167,7 @@ remoting.PinDialog = function(rootElement, host) {
this.host_ = host;
};
+
/**
* @param {boolean} supportsPairing
* @return {Promise<string>} Promise that resolves with the PIN or rejects with
« 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