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

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

Issue 1217643002: Added HostListApl implementation to connect to legacy directory and GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcd-e2e
Patch Set: yet another rewrite of host merging logic Created 5 years, 5 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 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 * REST API for host-list management. 7 * REST API for host-list management.
8 */ 8 */
9 9
10 /** @suppress {duplicate} */ 10 /** @suppress {duplicate} */
11 var remoting = remoting || {}; 11 var remoting = remoting || {};
12 12
13 (function() { 13 (function() {
14 14
15 'use strict'; 15 'use strict';
16 16
17 /** 17 /**
18 * @constructor 18 * @constructor
19 * @implements {remoting.HostListApi} 19 * @implements {remoting.HostListApi}
20 */ 20 */
21 remoting.LegacyHostListApi = function() { 21 remoting.LegacyHostListApi = function() {
22 }; 22 };
23 23
24 /** @override */ 24 /** @override */
25 remoting.LegacyHostListApi.prototype.register = function( 25 remoting.LegacyHostListApi.prototype.register = function(
26 hostName, publicKey, hostClientId) { 26 hostName, publicKey, hostClientId) {
27 var newHostId = base.generateUuid(); 27 var newHostId = base.generateUuid();
28 return remoting.LegacyHostListApi.registerWithHostId(
29 newHostId, hostName, publicKey, hostClientId);
30 };
31
32 /**
33 * Registers a host with the Chromoting directory using a specified
34 * host ID, which should not be equal to the ID of any existing host.
35 *
36 * @param {string} newHostId The host ID of the new host.
37 * @param {string} hostName The user-visible name of the new host.
38 * @param {string} publicKey The public half of the host's key pair.
39 * @param {?string} hostClientId The OAuth2 client ID of the host.
40 * @return {!Promise<remoting.HostListApi.RegisterResult>}
41 */
42 remoting.LegacyHostListApi.registerWithHostId = function(
43 newHostId, hostName, publicKey, hostClientId) {
28 var newHostDetails = { data: { 44 var newHostDetails = { data: {
29 hostId: newHostId, 45 hostId: newHostId,
30 hostName: hostName, 46 hostName: hostName,
31 publicKey: publicKey 47 publicKey: publicKey
32 } }; 48 } };
33 49
34 return new remoting.Xhr({ 50 return new remoting.Xhr({
35 method: 'POST', 51 method: 'POST',
36 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', 52 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts',
37 urlParams: { 53 urlParams: {
38 hostClientId: hostClientId 54 hostClientId: hostClientId
39 }, 55 },
40 jsonContent: newHostDetails, 56 jsonContent: newHostDetails,
41 acceptJson: true, 57 acceptJson: true,
42 useIdentity: true 58 useIdentity: true
43 }).start().then(function(response) { 59 }).start().then(function(response) {
44 if (response.status == 200) { 60 if (response.status == 200) {
45 var result = /** @type {!Object} */ (response.getJson()); 61 var result = /** @type {!Object} */ (response.getJson());
46 var data = base.getObjectAttr(result, 'data'); 62 var data = base.getObjectAttr(result, 'data');
47 var authCode = base.getStringAttr(data, 'authorizationCode'); 63 var authCode = hostClientId ?
64 base.getStringAttr(data, 'authorizationCode') :
65 '';
48 return { 66 return {
49 authCode: authCode, 67 authCode: authCode,
50 email: '', 68 email: '',
51 hostId: newHostId 69 hostId: newHostId
52 }; 70 };
53 } else { 71 } else {
54 console.log( 72 console.log(
55 'Failed to register the host. Status: ' + response.status + 73 'Failed to register the host. Status: ' + response.status +
56 ' response: ' + response.getText()); 74 ' response: ' + response.getText());
57 throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED); 75 throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 208 }
191 } else if (xhrResponse.status == 404) { 209 } else if (xhrResponse.status == 404) {
192 throw new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE); 210 throw new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE);
193 } else { 211 } else {
194 throw remoting.Error.fromHttpStatus(xhrResponse.status); 212 throw remoting.Error.fromHttpStatus(xhrResponse.status);
195 } 213 }
196 }); 214 });
197 }; 215 };
198 216
199 })(); 217 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698