Commit 12564e89 authored by garykac's avatar garykac Committed by Commit bot

[Chromoting] Add ability to enable/disable GDrive support per-app in gyp.

Since not all AppRemoting apps will want or need GDrive support to be
enabled, we need to be able to control which apps enable this feature.

This cl adds 'app_features' to the AppRemoting gyp targets and passes
the list of features into the build_webapp script (so the manifest can
have the correct oauth scopes) and the webapp.

Also, because the 'cast' capability was "in the way" for these changes,
it has been converted into a feature as well (default: disabled).

BUG=

Review URL: https://codereview.chromium.org/895523004

Cr-Commit-Position: refs/heads/master@{#314408}
parent 4e911e45
...@@ -69,10 +69,12 @@ ...@@ -69,10 +69,12 @@
'targets': [ 'targets': [
{ {
# Sample AppRemoting app.
'target_name': 'ar_sample_app', 'target_name': 'ar_sample_app',
'app_id': 'ljacajndfccfgnfohlgkdphmbnpkjflk', 'app_id': 'ljacajndfccfgnfohlgkdphmbnpkjflk',
'app_name': 'App Remoting Client', 'app_name': 'App Remoting Client',
'app_description': 'App Remoting client', 'app_description': 'App Remoting client',
'app_capabilities': ['GOOGLE_DRIVE'],
}, },
], # end of targets ], # end of targets
} }
...@@ -122,6 +122,8 @@ ...@@ -122,6 +122,8 @@
'<(remoting_app_name)', '<(remoting_app_name)',
'--app_description', '--app_description',
'<(remoting_app_description)', '<(remoting_app_description)',
'--app_capabilities',
'>@(_app_capabilities)',
'--service_environment', '--service_environment',
'<@(ar_service_environment)', '<@(ar_service_environment)',
], ],
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
], ],
# Remoting core JavaScript files. # Remoting core JavaScript files.
'remoting_webapp_js_core_files': [ 'remoting_webapp_js_core_files': [
'webapp/base/js/app_capabilities.js',
'webapp/base/js/application.js', 'webapp/base/js/application.js',
'webapp/base/js/base.js', 'webapp/base/js/base.js',
'webapp/base/js/ipc.js', 'webapp/base/js/ipc.js',
......
...@@ -213,19 +213,6 @@ remoting.AppRemoting.prototype.getDefaultRemapKeys = function() { ...@@ -213,19 +213,6 @@ remoting.AppRemoting.prototype.getDefaultRemapKeys = function() {
return ''; return '';
}; };
/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.AppRemoting.prototype.getRequiredCapabilities = function() {
return [
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS,
remoting.ClientSession.Capability.VIDEO_RECORDER,
remoting.ClientSession.Capability.GOOGLE_DRIVE
];
};
/** /**
* Called when a new session has been connected. * Called when a new session has been connected.
* *
......
...@@ -11,7 +11,7 @@ var remoting = remoting || {}; ...@@ -11,7 +11,7 @@ var remoting = remoting || {};
* Entry point ('load' handler) for App Remoting webapp. * Entry point ('load' handler) for App Remoting webapp.
*/ */
remoting.startAppRemoting = function() { remoting.startAppRemoting = function() {
remoting.app = new remoting.Application(); remoting.app = new remoting.Application(remoting.app_capabilities());
var app_remoting = new remoting.AppRemoting(remoting.app); var app_remoting = new remoting.AppRemoting(remoting.app);
remoting.app.start(); remoting.app.start();
}; };
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
"oauth2": { "oauth2": {
"client_id": "{{ REMOTING_IDENTITY_API_CLIENT_ID }}", "client_id": "{{ REMOTING_IDENTITY_API_CLIENT_ID }}",
"scopes": [ "scopes": [
"https://www.googleapis.com/auth/appremoting.runapplication https://www.googleapis.com/auth/googletalk https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile https://docs.google.com/feeds/ https://www.googleapis.com/auth/drive" "https://www.googleapis.com/auth/appremoting.runapplication https://www.googleapis.com/auth/googletalk https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile {{ OAUTH_GDRIVE_SCOPE }}"
] ]
}, },
"sandbox": { "sandbox": {
......
// Copyright 2015 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.
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* Note that this needs to be a function because it gets expanded at
* compile-time into remoting.ClientSession.Capability enums and these
* are not guaranteed to be present yet when this file is loaded.
* @return {Array.<remoting.ClientSession.Capability>}
*/
remoting.app_capabilities = function() {
return ['APPLICATION_CAPABILITIES'];
}
...@@ -13,15 +13,22 @@ ...@@ -13,15 +13,22 @@
var remoting = remoting || {}; var remoting = remoting || {};
/** /**
* @param {Array.<string>} app_capabilities Array of application capabilities.
* @constructor * @constructor
*/ */
remoting.Application = function() { remoting.Application = function(app_capabilities) {
/** /**
* @type {remoting.Application.Delegate} * @type {remoting.Application.Delegate}
* @private * @private
*/ */
this.delegate_ = null; this.delegate_ = null;
/**
* @type {Array.<string>}
* @private
*/
this.app_capabilities_ = app_capabilities;
/** /**
* @type {remoting.SessionConnector} * @type {remoting.SessionConnector}
* @private * @private
...@@ -37,6 +44,30 @@ remoting.Application.prototype.setDelegate = function(appDelegate) { ...@@ -37,6 +44,30 @@ remoting.Application.prototype.setDelegate = function(appDelegate) {
this.delegate_ = appDelegate; this.delegate_ = appDelegate;
}; };
/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.Application.prototype.getRequiredCapabilities_ = function() {
var capabilities = [
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS,
remoting.ClientSession.Capability.VIDEO_RECORDER
];
// Append the app-specific capabilities.
capabilities.push.apply(capabilities, this.app_capabilities_);
return capabilities;
};
/**
* @param {remoting.ClientSession.Capability} capability
* @return {boolean}
*/
remoting.Application.prototype.hasCapability = function(capability) {
var capabilities = remoting.app.getRequiredCapabilities_();
return capabilities.indexOf(capability) != -1;
};
/** /**
* Initialize the application and register all event handlers. After this * Initialize the application and register all event handlers. After this
* is called, the app is running and waiting for user events. * is called, the app is running and waiting for user events.
...@@ -153,7 +184,7 @@ remoting.Application.prototype.getSessionConnector = function() { ...@@ -153,7 +184,7 @@ remoting.Application.prototype.getSessionConnector = function() {
this.onError.bind(this), this.onError.bind(this),
this.onExtensionMessage.bind(this), this.onExtensionMessage.bind(this),
this.onConnectionFailed.bind(this), this.onConnectionFailed.bind(this),
this.delegate_.getRequiredCapabilities(), this.getRequiredCapabilities_(),
this.delegate_.getDefaultRemapKeys()); this.delegate_.getDefaultRemapKeys());
} }
return this.session_connector_; return this.session_connector_;
...@@ -179,12 +210,6 @@ remoting.Application.Delegate.prototype.init = function(connector) {}; ...@@ -179,12 +210,6 @@ remoting.Application.Delegate.prototype.init = function(connector) {};
*/ */
remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {}; remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {};
/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.Application.Delegate.prototype.getRequiredCapabilities = function() {};
/** /**
* Called when a new session has been connected. * Called when a new session has been connected.
* *
......
...@@ -75,10 +75,9 @@ def processJinjaTemplate(input_file, include_paths, output_file, context): ...@@ -75,10 +75,9 @@ def processJinjaTemplate(input_file, include_paths, output_file, context):
rendered = template.render(context) rendered = template.render(context)
io.open(output_file, 'w', encoding='utf-8').write(rendered) io.open(output_file, 'w', encoding='utf-8').write(rendered)
def buildWebApp(buildtype, version, destination, zip_path, def buildWebApp(buildtype, version, destination, zip_path,
manifest_template, webapp_type, app_id, app_name, manifest_template, webapp_type, app_id, app_name,
app_description, files, locales, jinja_paths, app_description, app_capabilities, files, locales, jinja_paths,
service_environment): service_environment):
"""Does the main work of building the webapp directory and zipfile. """Does the main work of building the webapp directory and zipfile.
...@@ -95,6 +94,8 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -95,6 +94,8 @@ def buildWebApp(buildtype, version, destination, zip_path,
test API server. test API server.
app_name: A string with the name of the application. app_name: A string with the name of the application.
app_description: A string with the description of the application. app_description: A string with the description of the application.
app_capabilities: A set of strings naming the capabilities that should be
enabled for this application.
files: An array of strings listing the paths for resources to include files: An array of strings listing the paths for resources to include
in this webapp. in this webapp.
locales: An array of strings listing locales, which are copied, along locales: An array of strings listing locales, which are copied, along
...@@ -316,6 +317,12 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -316,6 +317,12 @@ def buildWebApp(buildtype, version, destination, zip_path,
replaceString(destination, 'API_CLIENT_ID', apiClientId) replaceString(destination, 'API_CLIENT_ID', apiClientId)
replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret)
# Write the application capabilities.
appCapabilities = ','.join(
['remoting.ClientSession.Capability.' + x for x in app_capabilities])
findAndReplace(os.path.join(destination, 'app_capabilities.js'),
"'APPLICATION_CAPABILITIES'", appCapabilities)
# Use a consistent extension id for dev builds. # Use a consistent extension id for dev builds.
# AppRemoting builds always use the dev app id - the correct app id gets # AppRemoting builds always use the dev app id - the correct app id gets
# written into the manifest later. # written into the manifest later.
...@@ -342,7 +349,11 @@ def buildWebApp(buildtype, version, destination, zip_path, ...@@ -342,7 +349,11 @@ def buildWebApp(buildtype, version, destination, zip_path,
'GOOGLE_API_HOSTS': googleApiHosts, 'GOOGLE_API_HOSTS': googleApiHosts,
'APP_NAME': app_name, 'APP_NAME': app_name,
'APP_DESCRIPTION': app_description, 'APP_DESCRIPTION': app_description,
'OAUTH_GDRIVE_SCOPE': '',
} }
if 'GOOGLE_DRIVE' in app_capabilities:
context['OAUTH_GDRIVE_SCOPE'] = ('https://docs.google.com/feeds/ '
'https://www.googleapis.com/auth/drive')
processJinjaTemplate(manifest_template, processJinjaTemplate(manifest_template,
jinja_paths, jinja_paths,
os.path.join(destination, 'manifest.json'), os.path.join(destination, 'manifest.json'),
...@@ -361,6 +372,7 @@ def main(): ...@@ -361,6 +372,7 @@ def main():
'<webapp_type> <other files...> ' '<webapp_type> <other files...> '
'--app_name <name> ' '--app_name <name> '
'--app_description <description> ' '--app_description <description> '
'--app_capabilities <capabilities...> '
'[--appid <appid>] ' '[--appid <appid>] '
'[--locales <locales...>] ' '[--locales <locales...>] '
'[--jinja_paths <paths...>] ' '[--jinja_paths <paths...>] '
...@@ -374,6 +386,7 @@ def main(): ...@@ -374,6 +386,7 @@ def main():
app_id = None app_id = None
app_name = None app_name = None
app_description = None app_description = None
app_capabilities = set([])
service_environment = '' service_environment = ''
for arg in sys.argv[7:]: for arg in sys.argv[7:]:
...@@ -382,6 +395,7 @@ def main(): ...@@ -382,6 +395,7 @@ def main():
'--appid', '--appid',
'--app_name', '--app_name',
'--app_description', '--app_description',
'--app_capabilities',
'--service_environment']: '--service_environment']:
arg_type = arg arg_type = arg
elif arg_type == '--locales': elif arg_type == '--locales':
...@@ -397,6 +411,8 @@ def main(): ...@@ -397,6 +411,8 @@ def main():
elif arg_type == '--app_description': elif arg_type == '--app_description':
app_description = arg app_description = arg
arg_type = '' arg_type = ''
elif arg_type == '--app_capabilities':
app_capabilities.add(arg)
elif arg_type == '--service_environment': elif arg_type == '--service_environment':
service_environment = arg service_environment = arg
arg_type = '' arg_type = ''
...@@ -405,8 +421,8 @@ def main(): ...@@ -405,8 +421,8 @@ def main():
return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4],
sys.argv[5], sys.argv[6], app_id, app_name, sys.argv[5], sys.argv[6], app_id, app_name,
app_description, files, locales, jinja_paths, app_description, app_capabilities, files, locales,
service_environment) jinja_paths, service_environment)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -31,13 +31,6 @@ var remoting = remoting || {}; ...@@ -31,13 +31,6 @@ var remoting = remoting || {};
*/ */
remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000;
/**
* True if Cast capability is supported.
*
* @type {boolean}
*/
remoting.enableCast = false;
/** /**
* True to enable mouse lock. * True to enable mouse lock.
* This is currently disabled because the current client plugin does not * This is currently disabled because the current client plugin does not
...@@ -1677,7 +1670,8 @@ remoting.ClientSession.prototype.processCastExtensionMessage_ = function(data) { ...@@ -1677,7 +1670,8 @@ remoting.ClientSession.prototype.processCastExtensionMessage_ = function(data) {
* @private * @private
*/ */
remoting.ClientSession.prototype.createCastExtensionHandler_ = function() { remoting.ClientSession.prototype.createCastExtensionHandler_ = function() {
if (remoting.enableCast && this.mode_ == remoting.ClientSession.Mode.ME2ME) { if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST) &&
this.mode_ == remoting.ClientSession.Mode.ME2ME) {
this.castExtensionHandler_ = new remoting.CastExtensionHandler(this); this.castExtensionHandler_ = new remoting.CastExtensionHandler(this);
} }
}; };
......
...@@ -200,7 +200,7 @@ remoting.startDesktopRemotingForTesting = function() { ...@@ -200,7 +200,7 @@ remoting.startDesktopRemotingForTesting = function() {
remoting.startDesktopRemoting = function() { remoting.startDesktopRemoting = function() {
remoting.app = new remoting.Application(); remoting.app = new remoting.Application(remoting.app_capabilities());
var desktop_remoting = new remoting.DesktopRemoting(remoting.app); var desktop_remoting = new remoting.DesktopRemoting(remoting.app);
remoting.app.start(); remoting.app.start();
}; };
......
...@@ -155,21 +155,6 @@ remoting.DesktopRemoting.prototype.getDefaultRemapKeys = function() { ...@@ -155,21 +155,6 @@ remoting.DesktopRemoting.prototype.getDefaultRemapKeys = function() {
return remapKeys; return remapKeys;
}; };
/**
* @return {Array.<string>} A list of |ClientSession.Capability|s required
* by this application.
*/
remoting.DesktopRemoting.prototype.getRequiredCapabilities = function() {
return [
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION,
remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS,
remoting.ClientSession.Capability.VIDEO_RECORDER,
// TODO(aiguha): Add this capability based on a gyp/command-line flag,
// rather than by default.
remoting.ClientSession.Capability.CAST
];
};
/** /**
* Called when a new session has been connected. * Called when a new session has been connected.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment