OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Creates a directory with with the unpacked contents of the remoting webapp. | 6 """Creates a directory with with the unpacked contents of the remoting webapp. |
7 | 7 |
8 The directory will contain a copy-of or a link-to to all remoting webapp | 8 The directory will contain a copy-of or a link-to to all remoting webapp |
9 resources. This includes HTML/JS and any plugin binaries. The script also | 9 resources. This includes HTML/JS and any plugin binaries. The script also |
10 massages resulting files appropriately with host plugin data. Finally, | 10 massages resulting files appropriately with host plugin data. Finally, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 service_environment, use_gcd): | 113 service_environment, use_gcd): |
114 """Does the main work of building the webapp directory and zipfile. | 114 """Does the main work of building the webapp directory and zipfile. |
115 | 115 |
116 Args: | 116 Args: |
117 buildtype: the type of build ("Official", "Release" or "Dev"). | 117 buildtype: the type of build ("Official", "Release" or "Dev"). |
118 destination: A string with path to directory where the webapp will be | 118 destination: A string with path to directory where the webapp will be |
119 written. | 119 written. |
120 zipfile: A string with path to the zipfile to create containing the | 120 zipfile: A string with path to the zipfile to create containing the |
121 contents of |destination|. | 121 contents of |destination|. |
122 manifest_template: jinja2 template file for manifest. | 122 manifest_template: jinja2 template file for manifest. |
123 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). | 123 webapp_type: webapp type: |
| 124 For DesktopRemoting: "v1", "v2" or "v2_pnacl" |
| 125 For AppRemoting: "app_remoting" or "shared_module" |
124 appid: A string with the Remoting Application Id (only used for app | 126 appid: A string with the Remoting Application Id (only used for app |
125 remoting webapps). If supplied, it defaults to using the | 127 remoting webapps). If supplied, it defaults to using the |
126 test API server. | 128 test API server. |
127 app_client_id: The OAuth2 client ID for the webapp. | 129 app_client_id: The OAuth2 client ID for the webapp. |
128 app_name: A string with the name of the application. | 130 app_name: A string with the name of the application. |
129 app_description: A string with the description of the application. | 131 app_description: A string with the description of the application. |
130 app_capabilities: A set of strings naming the capabilities that should be | 132 app_capabilities: A set of strings naming the capabilities that should be |
131 enabled for this application. | 133 enabled for this application. |
132 manifest_key: The manifest key for the webapp. | 134 manifest_key: The manifest key for the webapp. |
133 files: An array of strings listing the paths for resources to include | 135 files: An array of strings listing the paths for resources to include |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 os.path.split(current_locale)[1]) | 207 os.path.split(current_locale)[1]) |
206 os.mkdir(destination_dir, 0775) | 208 os.mkdir(destination_dir, 0775) |
207 shutil.copy2(current_locale, destination_file) | 209 shutil.copy2(current_locale, destination_file) |
208 elif extension == '.pak': | 210 elif extension == '.pak': |
209 destination_file = os.path.join(remoting_locales, | 211 destination_file = os.path.join(remoting_locales, |
210 os.path.split(current_locale)[1]) | 212 os.path.split(current_locale)[1]) |
211 shutil.copy2(current_locale, destination_file) | 213 shutil.copy2(current_locale, destination_file) |
212 else: | 214 else: |
213 raise Exception('Unknown extension: ' + current_locale) | 215 raise Exception('Unknown extension: ' + current_locale) |
214 | 216 |
| 217 is_app_remoting_webapp = webapp_type == 'app_remoting' |
| 218 is_app_remoting_shared_module = webapp_type == 'shared_module' |
| 219 is_app_remoting = is_app_remoting_webapp or is_app_remoting_shared_module |
| 220 is_prod_service_environment = service_environment == 'vendor' or \ |
| 221 service_environment == 'prod' or \ |
| 222 service_environment == 'prod-testing' |
| 223 is_desktop_remoting = not is_app_remoting |
| 224 |
215 # Set client plugin type. | 225 # Set client plugin type. |
216 # TODO(wez): Use 'native' in app_remoting until b/17441659 is resolved. | 226 # TODO(wez): Use 'native' in app_remoting until b/17441659 is resolved. |
217 client_plugin = 'pnacl' if webapp_type == 'v2_pnacl' else 'native' | 227 if not is_app_remoting_webapp: |
218 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 228 client_plugin = 'pnacl' if webapp_type == 'v2_pnacl' else 'native' |
219 "'CLIENT_PLUGIN_TYPE'", "'" + client_plugin + "'") | 229 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
| 230 "'CLIENT_PLUGIN_TYPE'", "'" + client_plugin + "'") |
220 | 231 |
221 # Allow host names for google services/apis to be overriden via env vars. | 232 # Allow host names for google services/apis to be overriden via env vars. |
222 oauth2AccountsHost = os.environ.get( | 233 oauth2AccountsHost = os.environ.get( |
223 'OAUTH2_ACCOUNTS_HOST', 'https://accounts.google.com') | 234 'OAUTH2_ACCOUNTS_HOST', 'https://accounts.google.com') |
224 oauth2ApiHost = os.environ.get( | 235 oauth2ApiHost = os.environ.get( |
225 'OAUTH2_API_HOST', 'https://www.googleapis.com') | 236 'OAUTH2_API_HOST', 'https://www.googleapis.com') |
226 directoryApiHost = os.environ.get( | 237 directoryApiHost = os.environ.get( |
227 'DIRECTORY_API_HOST', 'https://www.googleapis.com') | 238 'DIRECTORY_API_HOST', 'https://www.googleapis.com') |
228 | 239 |
229 is_app_remoting_webapp = webapp_type == 'app_remoting' | 240 if is_app_remoting: |
230 is_prod_service_environment = service_environment == 'vendor' or \ | |
231 service_environment == 'prod' or \ | |
232 service_environment == 'prod-testing' | |
233 if is_app_remoting_webapp: | |
234 appRemotingApiHost = os.environ.get( | 241 appRemotingApiHost = os.environ.get( |
235 'APP_REMOTING_API_HOST', None) | 242 'APP_REMOTING_API_HOST', None) |
236 appRemotingApplicationId = os.environ.get( | 243 appRemotingApplicationId = os.environ.get( |
237 'APP_REMOTING_APPLICATION_ID', None) | 244 'APP_REMOTING_APPLICATION_ID', None) |
238 | 245 |
239 # Release/Official builds are special because they are what we will upload | 246 # Release/Official builds are special because they are what we will upload |
240 # to the web store. The checks below will validate that prod builds are | 247 # to the web store. The checks below will validate that prod builds are |
241 # being generated correctly (no overrides) and with the correct buildtype. | 248 # being generated correctly (no overrides) and with the correct buildtype. |
242 # They also verify that folks are not accidentally building dev/test/staging | 249 # They also verify that folks are not accidentally building dev/test/staging |
243 # apps for release (no impersonation) instead of dev. | 250 # apps for release (no impersonation) instead of dev. |
244 if is_prod_service_environment and buildtype == 'Dev': | 251 if is_prod_service_environment and buildtype == 'Dev': |
245 raise Exception("Prod environment cannot be built for 'dev' builds") | 252 raise Exception("Prod environment cannot be built for 'dev' builds") |
246 | 253 |
247 if buildtype != 'Dev': | 254 if buildtype != 'Dev': |
248 if not is_prod_service_environment: | 255 if not is_prod_service_environment: |
249 raise Exception('Invalid service_environment targeted for ' | 256 raise Exception('Invalid service_environment targeted for ' |
250 + buildtype + ': ' + service_environment) | 257 + buildtype + ': ' + service_environment) |
251 if appid != None: | 258 if appid != None: |
252 raise Exception('Cannot pass in an appid for ' | 259 raise Exception('Cannot pass in an appid for ' |
253 + buildtype + ' builds: ' + service_environment) | 260 + buildtype + ' builds: ' + service_environment) |
254 if appRemotingApiHost != None: | 261 if appRemotingApiHost != None: |
255 raise Exception('Cannot set APP_REMOTING_API_HOST env var for ' | 262 raise Exception('Cannot set APP_REMOTING_API_HOST env var for ' |
256 + buildtype + ' builds') | 263 + buildtype + ' builds') |
257 if appRemotingApplicationId != None: | 264 if appRemotingApplicationId != None: |
258 raise Exception('Cannot set APP_REMOTING_APPLICATION_ID env var for ' | 265 raise Exception('Cannot set APP_REMOTING_APPLICATION_ID env var for ' |
259 + buildtype + ' builds') | 266 + buildtype + ' builds') |
260 | 267 |
261 # If an Application ID was set (either from service_environment variable or | 268 # If an Application ID was set (either from service_environment variable or |
262 # from a command line argument), hardcode it, otherwise get it at runtime. | 269 # from a command line argument), hardcode it, otherwise get it at runtime. |
263 effectiveAppId = appRemotingApplicationId or appid | 270 if is_app_remoting_webapp: |
264 if effectiveAppId: | 271 effectiveAppId = appRemotingApplicationId or appid |
265 appRemotingApplicationId = "'" + effectiveAppId + "'" | 272 if effectiveAppId: |
266 else: | 273 appRemotingApplicationId = "'" + effectiveAppId + "'" |
267 appRemotingApplicationId = "chrome.i18n.getMessage('@@extension_id')" | 274 else: |
268 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 275 appRemotingApplicationId = "chrome.i18n.getMessage('@@extension_id')" |
269 "'APP_REMOTING_APPLICATION_ID'", appRemotingApplicationId) | 276 findAndReplace(os.path.join(destination, 'arv_main.js'), |
| 277 "'APP_REMOTING_APPLICATION_ID'", appRemotingApplicationId) |
270 | 278 |
271 oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2' | 279 oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2' |
272 oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2' | 280 oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2' |
273 directoryApiBaseUrl = directoryApiHost + '/chromoting/v1' | 281 directoryApiBaseUrl = directoryApiHost + '/chromoting/v1' |
274 | 282 |
275 if is_app_remoting_webapp: | 283 if is_app_remoting: |
276 # Set the apiary endpoint and then set the endpoint version | 284 # Set the apiary endpoint and then set the endpoint version |
277 if not appRemotingApiHost: | 285 if not appRemotingApiHost: |
278 if is_prod_service_environment: | 286 if is_prod_service_environment: |
279 appRemotingApiHost = 'https://www.googleapis.com' | 287 appRemotingApiHost = 'https://www.googleapis.com' |
280 else: | 288 else: |
281 appRemotingApiHost = 'https://www-googleapis-test.sandbox.google.com' | 289 appRemotingApiHost = 'https://www-googleapis-test.sandbox.google.com' |
282 | 290 |
283 if service_environment == 'dev': | 291 # TODO(garykac) Currently, the shared module is always set up for the |
| 292 # dev service_environment. Update build so that the dev environment can |
| 293 # be controlled by the app stub rather than hard-coded into the shared |
| 294 # module. |
| 295 if service_environment == 'dev' or is_app_remoting_shared_module: |
284 appRemotingServicePath = '/appremoting/v1beta1_dev' | 296 appRemotingServicePath = '/appremoting/v1beta1_dev' |
285 elif service_environment == 'test': | 297 elif service_environment == 'test': |
286 appRemotingServicePath = '/appremoting/v1beta1' | 298 appRemotingServicePath = '/appremoting/v1beta1' |
287 elif service_environment == 'staging': | 299 elif service_environment == 'staging': |
288 appRemotingServicePath = '/appremoting/v1beta1_staging' | 300 appRemotingServicePath = '/appremoting/v1beta1_staging' |
289 elif service_environment == 'vendor': | 301 elif service_environment == 'vendor': |
290 appRemotingServicePath = '/appremoting/v1beta1_vendor' | 302 appRemotingServicePath = '/appremoting/v1beta1_vendor' |
291 elif service_environment == 'prod': | 303 elif service_environment == 'prod': |
292 appRemotingServicePath = '/appremoting/v1beta1' | 304 appRemotingServicePath = '/appremoting/v1beta1' |
293 elif service_environment == 'prod-testing': | 305 elif service_environment == 'prod-testing': |
294 appRemotingServicePath = '/appremoting/v1beta1_prod_testing' | 306 appRemotingServicePath = '/appremoting/v1beta1_prod_testing' |
295 else: | 307 else: |
296 raise Exception('Unknown service environment: ' + service_environment) | 308 raise Exception('Unknown service environment: ' + service_environment) |
297 appRemotingApiBaseUrl = appRemotingApiHost + appRemotingServicePath | 309 appRemotingApiBaseUrl = appRemotingApiHost + appRemotingServicePath |
298 else: | 310 else: |
299 appRemotingApiBaseUrl = '' | 311 appRemotingApiBaseUrl = '' |
300 | 312 |
301 replaceBool(destination, 'USE_GCD', use_gcd) | 313 # TODO(garykac) replaceString (et al.) implictly update plugin_settings.js, |
302 replaceString(destination, 'OAUTH2_BASE_URL', oauth2BaseUrl) | 314 # which doesn't exist for the app stub. We need to move app-specific |
303 replaceString(destination, 'OAUTH2_API_BASE_URL', oauth2ApiBaseUrl) | 315 # AppRemoting options into arv_main.js. |
304 replaceString(destination, 'DIRECTORY_API_BASE_URL', directoryApiBaseUrl) | 316 if not is_app_remoting_webapp: |
305 if is_app_remoting_webapp: | 317 replaceBool(destination, 'USE_GCD', use_gcd) |
306 replaceString(destination, 'APP_REMOTING_API_BASE_URL', | 318 replaceString(destination, 'OAUTH2_BASE_URL', oauth2BaseUrl) |
307 appRemotingApiBaseUrl) | 319 replaceString(destination, 'OAUTH2_API_BASE_URL', oauth2ApiBaseUrl) |
| 320 replaceString(destination, 'DIRECTORY_API_BASE_URL', directoryApiBaseUrl) |
| 321 if is_app_remoting: |
| 322 replaceString(destination, 'APP_REMOTING_API_BASE_URL', |
| 323 appRemotingApiBaseUrl) |
308 | 324 |
309 # Substitute hosts in the manifest's CSP list. | 325 # Substitute hosts in the manifest's CSP list. |
310 # Ensure we list the API host only once if it's the same for multiple APIs. | 326 # Ensure we list the API host only once if it's the same for multiple APIs. |
311 googleApiHosts = ' '.join(set([oauth2ApiHost, directoryApiHost])) | 327 googleApiHosts = ' '.join(set([oauth2ApiHost, directoryApiHost])) |
312 | 328 |
313 # WCS and the OAuth trampoline are both hosted on talkgadget. Split them into | 329 # WCS and the OAuth trampoline are both hosted on talkgadget. Split them into |
314 # separate suffix/prefix variables to allow for wildcards in manifest.json. | 330 # separate suffix/prefix variables to allow for wildcards in manifest.json. |
315 talkGadgetHostSuffix = os.environ.get( | 331 talkGadgetHostSuffix = os.environ.get( |
316 'TALK_GADGET_HOST_SUFFIX', 'talkgadget.google.com') | 332 'TALK_GADGET_HOST_SUFFIX', 'talkgadget.google.com') |
317 talkGadgetHostPrefix = os.environ.get( | 333 talkGadgetHostPrefix = os.environ.get( |
(...skipping 17 matching lines...) Expand all Loading... |
335 oauth2RedirectBaseUrlJson = oauth2RedirectHostJson + oauth2RedirectPath | 351 oauth2RedirectBaseUrlJson = oauth2RedirectHostJson + oauth2RedirectPath |
336 if buildtype == 'Official': | 352 if buildtype == 'Official': |
337 oauth2RedirectUrlJs = ("'" + oauth2RedirectBaseUrlJs + | 353 oauth2RedirectUrlJs = ("'" + oauth2RedirectBaseUrlJs + |
338 "/rel/' + chrome.i18n.getMessage('@@extension_id')") | 354 "/rel/' + chrome.i18n.getMessage('@@extension_id')") |
339 oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/rel/*' | 355 oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/rel/*' |
340 else: | 356 else: |
341 oauth2RedirectUrlJs = "'" + oauth2RedirectBaseUrlJs + "/dev'" | 357 oauth2RedirectUrlJs = "'" + oauth2RedirectBaseUrlJs + "/dev'" |
342 oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/dev*' | 358 oauth2RedirectUrlJson = oauth2RedirectBaseUrlJson + '/dev*' |
343 thirdPartyAuthUrlJs = oauth2RedirectBaseUrlJs + '/thirdpartyauth' | 359 thirdPartyAuthUrlJs = oauth2RedirectBaseUrlJs + '/thirdpartyauth' |
344 thirdPartyAuthUrlJson = oauth2RedirectBaseUrlJson + '/thirdpartyauth*' | 360 thirdPartyAuthUrlJson = oauth2RedirectBaseUrlJson + '/thirdpartyauth*' |
345 replaceString(destination, 'TALK_GADGET_URL', talkGadgetBaseUrl) | 361 xmppServer = os.environ.get('XMPP_SERVER', 'talk.google.com:443') |
346 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | |
347 "'OAUTH2_REDIRECT_URL'", oauth2RedirectUrlJs) | |
348 | 362 |
349 # Configure xmpp server and directory bot settings in the plugin. | 363 if not is_app_remoting_webapp: |
350 replaceBool( | 364 replaceString(destination, 'TALK_GADGET_URL', talkGadgetBaseUrl) |
351 destination, 'XMPP_SERVER_USE_TLS', | 365 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
352 getenvBool('XMPP_SERVER_USE_TLS', True)) | 366 "'OAUTH2_REDIRECT_URL'", oauth2RedirectUrlJs) |
353 xmppServer = os.environ.get('XMPP_SERVER', 'talk.google.com:443') | 367 |
354 replaceString(destination, 'XMPP_SERVER', xmppServer) | 368 # Configure xmpp server and directory bot settings in the plugin. |
355 replaceString(destination, 'DIRECTORY_BOT_JID', | 369 replaceBool( |
356 os.environ.get('DIRECTORY_BOT_JID', | 370 destination, 'XMPP_SERVER_USE_TLS', |
357 'remoting@bot.talk.google.com')) | 371 getenvBool('XMPP_SERVER_USE_TLS', True)) |
358 replaceString(destination, 'THIRD_PARTY_AUTH_REDIRECT_URL', | 372 replaceString(destination, 'XMPP_SERVER', xmppServer) |
359 thirdPartyAuthUrlJs) | 373 replaceString(destination, 'DIRECTORY_BOT_JID', |
| 374 os.environ.get('DIRECTORY_BOT_JID', |
| 375 'remoting@bot.talk.google.com')) |
| 376 replaceString(destination, 'THIRD_PARTY_AUTH_REDIRECT_URL', |
| 377 thirdPartyAuthUrlJs) |
360 | 378 |
361 # Set the correct API keys. | 379 # Set the correct API keys. |
362 # For overriding the client ID/secret via env vars, see google_api_keys.py. | 380 # For overriding the client ID/secret via env vars, see google_api_keys.py. |
363 apiClientId = google_api_keys.GetClientID('REMOTING') | 381 apiClientId = google_api_keys.GetClientID('REMOTING') |
364 apiClientSecret = google_api_keys.GetClientSecret('REMOTING') | 382 apiClientSecret = google_api_keys.GetClientSecret('REMOTING') |
365 apiKey = google_api_keys.GetAPIKeyRemoting() | 383 apiKey = google_api_keys.GetAPIKeyRemoting() |
366 | 384 |
367 if is_app_remoting_webapp and buildtype != 'Dev': | 385 if is_app_remoting_webapp and buildtype != 'Dev': |
368 if not app_client_id: | 386 if not app_client_id: |
369 raise Exception('Invalid app_client_id passed in: "' + | 387 raise Exception('Invalid app_client_id passed in: "' + |
370 app_client_id + '"') | 388 app_client_id + '"') |
371 apiClientIdV2 = app_client_id + '.apps.googleusercontent.com' | 389 apiClientIdV2 = app_client_id + '.apps.googleusercontent.com' |
372 else: | 390 else: |
373 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API') | 391 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API') |
374 | 392 |
375 replaceString(destination, 'API_CLIENT_ID', apiClientId) | 393 if not is_app_remoting_webapp: |
376 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) | 394 replaceString(destination, 'API_CLIENT_ID', apiClientId) |
377 replaceString(destination, 'API_KEY', apiKey) | 395 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) |
| 396 replaceString(destination, 'API_KEY', apiKey) |
378 | 397 |
379 # Write the application capabilities. | 398 # Write the application capabilities. |
380 appCapabilities = ','.join( | 399 if is_app_remoting_webapp: |
381 ['remoting.ClientSession.Capability.' + x for x in app_capabilities]) | 400 appCapabilities = ','.join( |
382 findAndReplace(os.path.join(destination, 'app_capabilities.js'), | 401 ['remoting.ClientSession.Capability.' + x for x in app_capabilities]) |
383 "'APPLICATION_CAPABILITIES'", appCapabilities) | 402 findAndReplace(os.path.join(destination, 'arv_main.js'), |
| 403 "'APPLICATION_CAPABILITIES'", appCapabilities) |
384 | 404 |
385 # Use a consistent extension id for dev builds. | 405 # Use a consistent extension id for dev builds. |
386 # AppRemoting builds always use the dev app id - the correct app id gets | 406 # AppRemoting builds always use the dev app id - the correct app id gets |
387 # written into the manifest later. | 407 # written into the manifest later. |
388 if is_app_remoting_webapp: | 408 if is_app_remoting_webapp: |
389 if buildtype != 'Dev': | 409 if buildtype != 'Dev': |
390 if not manifest_key: | 410 if not manifest_key: |
391 raise Exception('Invalid manifest_key passed in: "' + | 411 raise Exception('Invalid manifest_key passed in: "' + |
392 manifest_key + '"') | 412 manifest_key + '"') |
393 manifestKey = '"key": "' + manifest_key + '",' | 413 manifestKey = '"key": "' + manifest_key + '",' |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 parser.add_argument('--use_gcd', choices=['0', '1'], default='0') | 478 parser.add_argument('--use_gcd', choices=['0', '1'], default='0') |
459 | 479 |
460 args = parser.parse_args() | 480 args = parser.parse_args() |
461 args.use_gcd = (args.use_gcd != '0') | 481 args.use_gcd = (args.use_gcd != '0') |
462 args.app_capabilities = set(args.app_capabilities) | 482 args.app_capabilities = set(args.app_capabilities) |
463 return buildWebApp(**vars(args)) | 483 return buildWebApp(**vars(args)) |
464 | 484 |
465 | 485 |
466 if __name__ == '__main__': | 486 if __name__ == '__main__': |
467 sys.exit(main()) | 487 sys.exit(main()) |
OLD | NEW |