diff options
-rwxr-xr-x | google_apis/google_api_keys.py | 6 | ||||
-rw-r--r-- | remoting/remoting_webapp_files.gypi | 1 | ||||
-rwxr-xr-x | remoting/webapp/build-webapp.py | 2 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_controller.js | 10 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_controller_unittest.js | 4 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_list.js | 13 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_list_api.js | 48 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_list_api_gcd_impl.js | 81 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_list_api_impl.js | 3 | ||||
-rw-r--r-- | remoting/webapp/crd/js/mock_host_list_api.js | 22 | ||||
-rw-r--r-- | remoting/webapp/crd/js/plugin_settings.js | 2 |
11 files changed, 163 insertions, 29 deletions
diff --git a/google_apis/google_api_keys.py b/google_apis/google_api_keys.py index 94170ea..ef40ff5 100755 --- a/google_apis/google_api_keys.py +++ b/google_apis/google_api_keys.py @@ -70,6 +70,11 @@ def GetAPIKey(): return _GetToken('GOOGLE_API_KEY') +def GetAPIKeyRemoting(): + """Returns the simple API key.""" + return _GetToken('GOOGLE_API_KEY_REMOTING') + + def GetClientID(client_name): """Returns the OAuth 2.0 client ID for the client of the given name.""" return _GetToken('GOOGLE_CLIENT_ID_%s' % client_name) @@ -82,6 +87,7 @@ def GetClientSecret(client_name): if __name__ == "__main__": print 'GOOGLE_API_KEY=%s' % GetAPIKey() + print 'GOOGLE_API_KEY_REMOTING=%s' % GetAPIKeyRemoting() print 'GOOGLE_CLIENT_ID_MAIN=%s' % GetClientID('MAIN') print 'GOOGLE_CLIENT_SECRET_MAIN=%s' % GetClientSecret('MAIN') print 'GOOGLE_CLIENT_ID_CLOUD_PRINT=%s' % GetClientID('CLOUD_PRINT') diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index 77515ff..494bbde 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -216,6 +216,7 @@ 'remoting_webapp_js_host_display_files': [ 'webapp/crd/js/host_list.js', 'webapp/crd/js/host_list_api.js', + 'webapp/crd/js/host_list_api_gcd_impl.js', 'webapp/crd/js/host_list_api_impl.js', 'webapp/crd/js/host_table_entry.js', 'webapp/crd/js/local_host_section.js', diff --git a/remoting/webapp/build-webapp.py b/remoting/webapp/build-webapp.py index 86c1cd9..9ed59d8 100755 --- a/remoting/webapp/build-webapp.py +++ b/remoting/webapp/build-webapp.py @@ -362,6 +362,7 @@ def buildWebApp(buildtype, version, destination, zip_path, # For overriding the client ID/secret via env vars, see google_api_keys.py. apiClientId = google_api_keys.GetClientID('REMOTING') apiClientSecret = google_api_keys.GetClientSecret('REMOTING') + apiKey = google_api_keys.GetAPIKeyRemoting() if is_app_remoting_webapp and buildtype != 'Dev': if not app_client_id: @@ -373,6 +374,7 @@ def buildWebApp(buildtype, version, destination, zip_path, replaceString(destination, 'API_CLIENT_ID', apiClientId) replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) + replaceString(destination, 'API_KEY', apiKey) # Write the application capabilities. appCapabilities = ','.join( diff --git a/remoting/webapp/crd/js/host_controller.js b/remoting/webapp/crd/js/host_controller.js index 8df1614..b801572 100644 --- a/remoting/webapp/crd/js/host_controller.js +++ b/remoting/webapp/crd/js/host_controller.js @@ -182,21 +182,21 @@ remoting.HostController.prototype.start = function(hostPin, consent) { var hostName = /** @type {string} */ (a[1]); var keyPair = /** @type {remoting.KeyPair} */ (a[2]); - return remoting.hostListApi.register( + return remoting.HostListApi.getInstance().register( newHostId, hostName, keyPair.publicKey, hostClientId); - }).then(function(/** string */ authCode) { + }).then(function(/** string */ result) { hostRegistered = true; - return authCode; + return result; }); // Get XMPP creditials. var xmppCredsPromise = authCodePromise.then(function(authCode) { if (authCode) { - // Use auth code supplied by registry. + // Use auth code supplied by Chromoting registry. return that.hostDaemonFacade_.getCredentialsFromAuthCode(authCode); } else { // No authorization code returned, use regular Chrome - // identitial credential flow. + // identity credential flow. return remoting.identity.getEmail().then(function(/** string */ email) { return { userEmail: email, diff --git a/remoting/webapp/crd/js/host_controller_unittest.js b/remoting/webapp/crd/js/host_controller_unittest.js index daa41d8..d586130 100644 --- a/remoting/webapp/crd/js/host_controller_unittest.js +++ b/remoting/webapp/crd/js/host_controller_unittest.js @@ -82,7 +82,7 @@ QUnit.module('host_controller', { remoting.identity = new remoting.Identity(); mockHostListApi = new remoting.MockHostListApi; mockHostListApi.registerResult = FAKE_AUTH_CODE; - remoting.hostListApi = mockHostListApi; + remoting.HostListApi.setInstance(mockHostListApi); base.debug.assert(remoting.oauth2 === null); remoting.oauth2 = new remoting.OAuth2(); base.debug.assert(remoting.hostList === null); @@ -173,7 +173,7 @@ QUnit.module('host_controller', { remoting.hostList = null; remoting.oauth2 = null; chromeMocks.restore(); - remoting.hostListApi = null; + remoting.HostListApi.setInstance(null); remoting.identity = null; } }); diff --git a/remoting/webapp/crd/js/host_list.js b/remoting/webapp/crd/js/host_list.js index 1678464..1262cd8 100644 --- a/remoting/webapp/crd/js/host_list.js +++ b/remoting/webapp/crd/js/host_list.js @@ -152,7 +152,7 @@ remoting.HostList.prototype.refresh = function(onDone) { that.lastError_ = error; onDone(false); }; - remoting.hostListApi.get().then(function(hosts) { + remoting.HostListApi.getInstance().get().then(function(hosts) { onDone(that.onHostListResponse_(hosts)); }).catch( remoting.Error.handler(onError) @@ -306,7 +306,7 @@ remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { if (index != -1) { this.hostTableEntries_.splice(index, 1); } - remoting.hostListApi.remove(hostTableEntry.host.hostId). + remoting.HostListApi.getInstance().remove(hostTableEntry.host.hostId). catch(this.onError_); }; @@ -324,9 +324,10 @@ remoting.HostList.prototype.renameHost = function(hostTableEntry) { } this.save_(); - remoting.hostListApi.put(hostTableEntry.host.hostId, - hostTableEntry.host.hostName, - hostTableEntry.host.publicKey). + var hostListApi = remoting.HostListApi.getInstance(); + hostListApi.put(hostTableEntry.host.hostId, + hostTableEntry.host.hostName, + hostTableEntry.host.publicKey). catch(this.onError_); }; @@ -348,7 +349,7 @@ remoting.HostList.prototype.unregisterHostById = function(hostId, opt_onDone) { return; } - remoting.hostListApi.remove(hostId). + remoting.HostListApi.getInstance().remove(hostId). then(function() { that.refresh(function() { that.display(); diff --git a/remoting/webapp/crd/js/host_list_api.js b/remoting/webapp/crd/js/host_list_api.js index 9b63ccb..4e6cd72 100644 --- a/remoting/webapp/crd/js/host_list_api.js +++ b/remoting/webapp/crd/js/host_list_api.js @@ -7,23 +7,30 @@ * API for host-list management. */ -'use strict'; - /** @suppress {duplicate} */ var remoting = remoting || {}; +(function() { + +'use strict'; + /** @interface */ remoting.HostListApi = function() { }; /** - * @param {string} newHostId - * @param {string} hostName - * @param {string} publicKey - * @param {?string} hostClientId + * Registers a new host with the host registry service (either the + * Chromoting registry or GCD). + * + * @param {string} newHostId The ID of the new host to register. + * @param {string} hostName The user-visible name of the new host. + * @param {string} publicKey The public half of the host's key pair. + * @param {string} hostClientId The OAuth2 client ID of the host. * @return {!Promise<string>} An OAuth2 auth code or the empty string. */ -remoting.HostListApi.prototype.register; +remoting.HostListApi.prototype.register = function( + newHostId, hostName, publicKey, hostClientId) { +}; /** * Fetch the list of hosts for a user. @@ -53,3 +60,30 @@ remoting.HostListApi.prototype.put = */ remoting.HostListApi.prototype.remove = function(hostId) { }; + +/** + * @private {remoting.HostListApi} + */ +var instance = null; + +/** + * @return {!remoting.HostListApi} + */ +remoting.HostListApi.getInstance = function() { + if (instance == null) { + instance = remoting.settings.USE_GCD ? + new remoting.HostListApiGcdImpl() : + new remoting.HostListApiImpl(); + } + return instance; +}; + +/** + * For testing. + * @param {remoting.HostListApi} newInstance + */ +remoting.HostListApi.setInstance = function(newInstance) { + instance = newInstance; +}; + +})(); diff --git a/remoting/webapp/crd/js/host_list_api_gcd_impl.js b/remoting/webapp/crd/js/host_list_api_gcd_impl.js new file mode 100644 index 0000000..02db52e --- /dev/null +++ b/remoting/webapp/crd/js/host_list_api_gcd_impl.js @@ -0,0 +1,81 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * @fileoverview + * REST API for host-list management. + */ + +/** @suppress {duplicate} */ +var remoting = remoting || {}; + +(function() { + +'use strict'; + +/** + * @constructor + * @implements {remoting.HostListApi} + */ +remoting.HostListApiGcdImpl = function() { + this.gcd_ = new remoting.gcd.Client({ + apiKey: remoting.settings.GOOGLE_API_KEY + }); +}; + +/** @override */ +remoting.HostListApiGcdImpl.prototype.register = function( + newHostId, hostName, publicKey, hostClientId) { + var self = this; + var deviceDraft = { + channel: { + supportedType: 'xmpp' + }, + deviceKind: 'vendor', + name: newHostId, + displayName: hostName, + state: { + 'publicKey': publicKey + } + }; + + return /** @type {!Promise<string>} */ ( + this.gcd_.insertRegistrationTicket(). + then(function(ticket) { + return self.gcd_.patchRegistrationTicket( + ticket.id, deviceDraft, hostClientId); + }). + then(function(/**remoting.gcd.RegistrationTicket*/ ticket) { + return self.gcd_.finalizeRegistrationTicket(ticket.id); + }). + then(function(/**remoting.gcd.RegistrationTicket*/ ticket) { + return ticket.robotAccountAuthorizationCode; + }). + catch(function(error) { + console.error('Error registering device with GCD: ' + error); + throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED); + })); +}; + +/** @override */ +remoting.HostListApiGcdImpl.prototype.get = function() { + // TODO(jrw) + this.gcd_.listDevices(); + return Promise.resolve([]); +}; + +/** @override */ +remoting.HostListApiGcdImpl.prototype.put = + function(hostId, hostName, hostPublicKey) { + // TODO(jrw) + throw new Error('Not implemented'); +}; + +/** @override */ +remoting.HostListApiGcdImpl.prototype.remove = function(hostId) { + // TODO(jrw) + throw new Error('Not implemented'); +}; + +})(); diff --git a/remoting/webapp/crd/js/host_list_api_impl.js b/remoting/webapp/crd/js/host_list_api_impl.js index 9cfff10..542e3f0 100644 --- a/remoting/webapp/crd/js/host_list_api_impl.js +++ b/remoting/webapp/crd/js/host_list_api_impl.js @@ -159,7 +159,4 @@ remoting.HostListApiImpl.defaultResponse_ = function(opt_ignoreErrors) { return result; }; -/** @type {remoting.HostListApi} */ -remoting.hostListApi = new remoting.HostListApiImpl(); - })(); diff --git a/remoting/webapp/crd/js/mock_host_list_api.js b/remoting/webapp/crd/js/mock_host_list_api.js index b21462d..1d9b151 100644 --- a/remoting/webapp/crd/js/mock_host_list_api.js +++ b/remoting/webapp/crd/js/mock_host_list_api.js @@ -52,7 +52,9 @@ remoting.MockHostListApi.prototype.register = function( newHostId, hostName, publicKey, hostClientId) { if (this.registerResult === null) { return Promise.reject( - new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED)); + new remoting.Error( + remoting.Error.Tag.REGISTRATION_FAILED, + 'MockHostListApi.register')); } else { return Promise.resolve(this.registerResult); } @@ -61,13 +63,18 @@ remoting.MockHostListApi.prototype.register = function( /** @override */ remoting.MockHostListApi.prototype.get = function() { var that = this; - new Promise(function(resolve, reject) { + return new Promise(function(resolve, reject) { remoting.mockIdentity.validateTokenAndCall( resolve, remoting.Error.handler(reject), [that.hosts]); }); }; -/** @override */ +/** + * @override + * @param {string} hostId + * @param {string} hostName + * @param {string} hostPublicKey + */ remoting.MockHostListApi.prototype.put = function(hostId, hostName, hostPublicKey) { /** @type {remoting.MockHostListApi} */ @@ -91,7 +98,10 @@ remoting.MockHostListApi.prototype.put = }); }; -/** @override */ +/** + * @override + * @param {string} hostId + */ remoting.MockHostListApi.prototype.remove = function(hostId) { /** @type {remoting.MockHostListApi} */ var that = this; @@ -116,6 +126,6 @@ remoting.MockHostListApi.prototype.remove = function(hostId) { * @param {boolean} active */ remoting.MockHostListApi.setActive = function(active) { - remoting.hostListApi = active ? new remoting.MockHostListApi() - : new remoting.HostListApiImpl(); + remoting.HostListApi.setInstance( + active ? new remoting.MockHostListApi() : null); }; diff --git a/remoting/webapp/crd/js/plugin_settings.js b/remoting/webapp/crd/js/plugin_settings.js index bbc4df8..a4b56d2 100644 --- a/remoting/webapp/crd/js/plugin_settings.js +++ b/remoting/webapp/crd/js/plugin_settings.js @@ -23,6 +23,8 @@ remoting.Settings = function() {}; remoting.Settings.prototype.OAUTH2_CLIENT_ID = 'API_CLIENT_ID'; /** @type {string} API client secret.*/ remoting.Settings.prototype.OAUTH2_CLIENT_SECRET = 'API_CLIENT_SECRET'; +/** @type {string} Google API Key.*/ +remoting.Settings.prototype.GOOGLE_API_KEY = 'API_KEY'; /** @type {string} Base URL for OAuth2 authentication. */ remoting.Settings.prototype.OAUTH2_BASE_URL = 'OAUTH2_BASE_URL'; |