From 6275de5043c03bb01065b38e3fc4b5c245562f15 Mon Sep 17 00:00:00 2001 From: jamiewalch Date: Wed, 17 Jun 2015 16:25:34 -0700 Subject: [PATCH] Add support for custom license templates. This allows products that are built from the Chromium source to include third-party license attribution, even if they cannot link directly to chrome://credits. Chrome apps such as Chromoting, for example, fall into this category, for example. BUG=499478 Review URL: https://codereview.chromium.org/1178323002 Cr-Commit-Position: refs/heads/master@{#334957} --- remoting/app_remoting_webapp_build.gypi | 1 + remoting/app_remoting_webapp_files.gypi | 1 + remoting/remoting_client.gypi | 28 +++++++++ remoting/remoting_webapp.gypi | 1 + remoting/remoting_webapp_files.gypi | 10 ++++ remoting/webapp/BUILD.gn | 25 ++++++++ .../app_remoting/js/application_context_menu.js | 17 ++++++ remoting/webapp/base/html/credits.css | 67 ++++++++++++++++++++++ remoting/webapp/base/html/credits.tmpl | 16 ++++++ remoting/webapp/base/html/credits_entry.tmpl | 9 +++ remoting/webapp/base/html/main.css | 2 +- remoting/webapp/base/js/credits.js | 19 ++++++ remoting/webapp/build_template.gni | 2 + remoting/webapp/crd/html/toolbar.html | 1 + remoting/webapp/crd/html/ui_header.html | 1 + remoting/webapp/crd/html/window_frame.html | 2 + remoting/webapp/crd/js/feedback.js | 32 ++++++++--- remoting/webapp/files.gni | 11 +++- tools/licenses.py | 49 +++++++++------- 19 files changed, 265 insertions(+), 29 deletions(-) create mode 100644 remoting/webapp/base/html/credits.css create mode 100644 remoting/webapp/base/html/credits.tmpl create mode 100644 remoting/webapp/base/html/credits_entry.tmpl create mode 100644 remoting/webapp/base/js/credits.js diff --git a/remoting/app_remoting_webapp_build.gypi b/remoting/app_remoting_webapp_build.gypi index bc6ffa6b662d..9117e4f5efbf 100644 --- a/remoting/app_remoting_webapp_build.gypi +++ b/remoting/app_remoting_webapp_build.gypi @@ -46,6 +46,7 @@ '<(SHARED_INTERMEDIATE_DIR)/>(_target_name)/message_window.html', '<(SHARED_INTERMEDIATE_DIR)/>(_target_name)/wcs_sandbox.html', '<(SHARED_INTERMEDIATE_DIR)/>(_target_name)/feedback_consent.html', + '<(SHARED_INTERMEDIATE_DIR)/remoting/credits.html', ], 'ar_webapp_files': [ '<@(ar_app_specific_files)', diff --git a/remoting/app_remoting_webapp_files.gypi b/remoting/app_remoting_webapp_files.gypi index fc5686d3ba19..4d976d4cf0a7 100644 --- a/remoting/app_remoting_webapp_files.gypi +++ b/remoting/app_remoting_webapp_files.gypi @@ -94,6 +94,7 @@ '<@(remoting_webapp_wcs_sandbox_html_js_files)', # Referenced from the manifest. '<@(ar_background_js_files)', + 'webapp/base/js/credits.js', ], # Files that contain localizable strings. diff --git a/remoting/remoting_client.gypi b/remoting/remoting_client.gypi index bef823d39303..d3d23fcf4624 100644 --- a/remoting/remoting_client.gypi +++ b/remoting/remoting_client.gypi @@ -125,10 +125,38 @@ }, # end of target 'remoting_webapp_html' { + # GN version: //remoting/webapp:credits + 'target_name': 'remoting_credits', + 'type': 'none', + 'actions': [ + { + 'action_name': 'Build remoting credits', + 'inputs': [ + '../tools/licenses.py', + 'webapp/base/html/credits.tmpl', + 'webapp/base/html/credits_entry.tmpl', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/remoting/credits.html', + ], + 'hard_dependency': 1, + 'action': ['python', + '../tools/licenses.py', + 'credits', + '<(SHARED_INTERMEDIATE_DIR)/remoting/credits.html', + '--file-template', 'webapp/base/html/credits.tmpl', + '--entry-template', 'webapp/base/html/credits_entry.tmpl', + + ], + }, + ], + }, + { # GN version: //remoting/webapp:webapp 'target_name': 'remoting_webapp', 'type': 'none', 'dependencies': [ + 'remoting_credits', 'remoting_webapp_v1', ], 'conditions': [ diff --git a/remoting/remoting_webapp.gypi b/remoting/remoting_webapp.gypi index 9d5a72a0eb3e..ca56648540f1 100644 --- a/remoting/remoting_webapp.gypi +++ b/remoting/remoting_webapp.gypi @@ -11,6 +11,7 @@ 'main_html_file%': '<(SHARED_INTERMEDIATE_DIR)/remoting/main.html', 'generated_html_files': [ '<(SHARED_INTERMEDIATE_DIR)/remoting/background.html', + '<(SHARED_INTERMEDIATE_DIR)/remoting/credits.html', '<(SHARED_INTERMEDIATE_DIR)/remoting/message_window.html', '<(SHARED_INTERMEDIATE_DIR)/remoting/wcs_sandbox.html', ], diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index 3657d33471e6..abae97741e4f 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -444,6 +444,14 @@ ], # + # All the JavaScript files required by credits.html + # + + 'remoting_webapp_credits_html_all_js_files': [ + 'webapp/base/js/credits.js', + ], + + # # Complete webapp JS and resource files. # @@ -461,6 +469,7 @@ 'remoting_webapp_crd_js_files': [ '<@(remoting_webapp_shared_js_files)', '<@(remoting_webapp_crd_main_html_all_js_files)', + '<@(remoting_webapp_credits_html_all_js_files)', ], 'remoting_webapp_info_files': [ @@ -492,6 +501,7 @@ 'resources/reload.webp', 'resources/tick.webp', 'webapp/base/html/connection_stats.css', + 'webapp/base/html/credits.css', 'webapp/base/html/main.css', 'webapp/base/html/message_window.css', 'webapp/base/resources/open_sans.css', diff --git a/remoting/webapp/BUILD.gn b/remoting/webapp/BUILD.gn index e3e79664f704..43b26a3f0884 100644 --- a/remoting/webapp/BUILD.gn +++ b/remoting/webapp/BUILD.gn @@ -11,6 +11,7 @@ group("webapp") { deps = [ ":webapp_v1", ":ar_sample_app", + ":credits", ] if (enable_nacl) { @@ -45,3 +46,27 @@ app_remoting_webapp("ar_sample_app") { app_capabilities = [ "GOOGLE_DRIVE" ] manifest_key = "remotingdevbuild" } + +# GYP version: remoting/remoting_client:remoting_credits +action("credits") { + about_credits_file = "$target_gen_dir/credits.html" + script = "//tools/licenses.py" + + inputs = [ + "base/html/credits.tmpl", + "base/html/credits_entry.tmpl", + ] + + outputs = [ + about_credits_file, + ] + + args = [ + "credits", + rebase_path(about_credits_file, root_build_dir), + "--file-template", + rebase_path("base/html/credits.tmpl", root_build_dir), + "--entry-template", + rebase_path("base/html/credits_entry.tmpl", root_build_dir), + ] +} diff --git a/remoting/webapp/app_remoting/js/application_context_menu.js b/remoting/webapp/app_remoting/js/application_context_menu.js index 8d158246f09e..26051a0c9045 100644 --- a/remoting/webapp/app_remoting/js/application_context_menu.js +++ b/remoting/webapp/app_remoting/js/application_context_menu.js @@ -37,6 +37,10 @@ remoting.ApplicationContextMenu = function(adapter, plugin, clientSession, remoting.ApplicationContextMenu.kShowStatsId, l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'), true); + this.adapter_.create( + remoting.ApplicationContextMenu.kShowCreditsId, + l10n.getTranslationOrError(/*i18n-content*/'CREDITS'), + true); // TODO(kelvinp):Unhook this event on shutdown. this.adapter_.addListener(this.onClicked_.bind(this)); @@ -118,6 +122,16 @@ remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) { case remoting.ApplicationContextMenu.kShowStatsId: this.stats_.show(info.checked); break; + + case remoting.ApplicationContextMenu.kShowCreditsId: + chrome.app.window.create( + 'credits.html', + { + 'width': 800, + 'height': 600, + 'id' : 'remoting-credits' + }); + break; } }; @@ -127,3 +141,6 @@ remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback'; /** @type {string} */ remoting.ApplicationContextMenu.kShowStatsId = 'show-stats'; + +/** @type {string} */ +remoting.ApplicationContextMenu.kShowCreditsId = 'show-credits'; diff --git a/remoting/webapp/base/html/credits.css b/remoting/webapp/base/html/credits.css new file mode 100644 index 000000000000..c61b09d4681f --- /dev/null +++ b/remoting/webapp/base/html/credits.css @@ -0,0 +1,67 @@ +/* Copyright (c) 2012 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. + */ + +body { + overflow: auto; +} + +.page-title { + font-size: 164%; + font-weight: bold; +} + +.entries { + margin: 8px; +} + +.product { + background-color: #c3d9ff; + border-radius: 5px; + margin-top: 16px; + overflow: auto; + padding: 2px; +} + +.product .title { + float: left; + font-size: 110%; + font-weight: bold; + margin: 3px; +} + +.product .homepage { + float: right; + margin: 3px; + text-align: right; +} + +.product .homepage::after { + content: " - "; +} + +.product .toggle-licence { + float: right; + margin: 3px; + text-align: right; +} + +.licence { + background-color: #e8eef7; + border-radius: 3px; + clear: both; + padding: 16px; +} + +.toggle-licence.hide-licence ~ .licence { + display: none; +}; + +.licence h3 { + margin-top: 0; +} + +.licence pre { + white-space: pre-wrap; +} diff --git a/remoting/webapp/base/html/credits.tmpl b/remoting/webapp/base/html/credits.tmpl new file mode 100644 index 000000000000..836ebc67a8ac --- /dev/null +++ b/remoting/webapp/base/html/credits.tmpl @@ -0,0 +1,16 @@ + + + + + Credits + + + + + +
+
Credits
+ {{entries}} +
+ + diff --git a/remoting/webapp/base/html/credits_entry.tmpl b/remoting/webapp/base/html/credits_entry.tmpl new file mode 100644 index 000000000000..f30eb194e1ba --- /dev/null +++ b/remoting/webapp/base/html/credits_entry.tmpl @@ -0,0 +1,9 @@ +
+{{name}} +show license +homepage +
+
{{license}}
+
+
+ diff --git a/remoting/webapp/base/html/main.css b/remoting/webapp/base/html/main.css index c089e1ff69d1..172e0a4df1e4 100644 --- a/remoting/webapp/base/html/main.css +++ b/remoting/webapp/base/html/main.css @@ -4,7 +4,7 @@ */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, -blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, +blockquote, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, button { diff --git a/remoting/webapp/base/js/credits.js b/remoting/webapp/base/js/credits.js new file mode 100644 index 000000000000..cab5653b8d70 --- /dev/null +++ b/remoting/webapp/base/js/credits.js @@ -0,0 +1,19 @@ +// 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. + +(function() { + +'use strict'; + +/** @param {Event} event */ +function onClick(event) { + var element = /** @type {HTMLElement} */ (event.target); + if (element.classList.contains('toggle-licence')) { + element.classList.toggle('hide-licence'); + } +} + +document.addEventListener('click', onClick, false); + +})(); diff --git a/remoting/webapp/build_template.gni b/remoting/webapp/build_template.gni index 0eff3e642ea2..8c970840bd6a 100644 --- a/remoting/webapp/build_template.gni +++ b/remoting/webapp/build_template.gni @@ -186,6 +186,7 @@ template("desktop_remoting_webapp") { message_window_html_output, wcs_sandbox_html_output, main_html_output, + "$target_gen_dir/credits.html", ] # Create a file that contains a list of all the resource files needed @@ -324,6 +325,7 @@ template("app_remoting_webapp") { message_window_html_output, wcs_sandbox_html_output, main_html_output, + "$target_gen_dir/credits.html", ] ar_webapp_files = diff --git a/remoting/webapp/crd/html/toolbar.html b/remoting/webapp/crd/html/toolbar.html index ed2a1fa389d8..0a948964504d 100644 --- a/remoting/webapp/crd/html/toolbar.html +++ b/remoting/webapp/crd/html/toolbar.html @@ -64,6 +64,7 @@ found in the LICENSE file. diff --git a/remoting/webapp/crd/html/ui_header.html b/remoting/webapp/crd/html/ui_header.html index 86eb68f61add..45595ab2ab3a 100644 --- a/remoting/webapp/crd/html/ui_header.html +++ b/remoting/webapp/crd/html/ui_header.html @@ -22,6 +22,7 @@ found in the LICENSE file. diff --git a/remoting/webapp/crd/html/window_frame.html b/remoting/webapp/crd/html/window_frame.html index 4cddc9504a8c..1729abb6d381 100644 --- a/remoting/webapp/crd/html/window_frame.html +++ b/remoting/webapp/crd/html/window_frame.html @@ -35,6 +35,8 @@ found in the LICENSE file. i18n-content="HELP"> + = 35) { - feedbackButton.addEventListener('click', - remoting.sendFeedback_, - false); + feedbackButton.addEventListener('click', sendFeedback, false); } else { feedbackButton.hidden = true; } }; +function showHelp() { + window.open('https://support.google.com/chrome/answer/1649523'); +}; + +function showCredits() { + chrome.app.window.create( + 'credits.html', + { + 'width': 800, + 'height': 600, + 'id' : 'remoting-credits' + }); +}; + /** * Pass the current version of Chrome Remote Desktop to the Google Feedback * extension and instruct it to show the feedback dialog. */ -remoting.sendFeedback_ = function() { +function sendFeedback() { var message = { requestFeedback: true, feedbackInfo: { @@ -51,3 +67,5 @@ remoting.sendFeedback_ = function() { var kFeedbackExtensionId = 'gfdkimpbcpahaombhbimeihdjnejgicl'; chrome.runtime.sendMessage(kFeedbackExtensionId, message, function() {}); }; + +})(); diff --git a/remoting/webapp/files.gni b/remoting/webapp/files.gni index 7e77289ddb4c..39bc081b99bf 100644 --- a/remoting/webapp/files.gni +++ b/remoting/webapp/files.gni @@ -434,12 +434,19 @@ remoting_webapp_message_window_html_all_js_files = remoting_webapp_message_window_html_js_files + [ "base/js/base.js" ] # +# All the JavaScript files required by credits.html +# + +remoting_webapp_credits_html_all_js_files = [ "base/js/credits.js" ] + +# # DesktopRemoting webapp JS and resource files. # # All the JavaScript files that are shared by webapps. remoting_webapp_shared_js_files = remoting_webapp_shared_main_html_js_files + remoting_webapp_background_html_js_files + + remoting_webapp_credits_html_all_js_files + remoting_webapp_message_window_html_js_files + remoting_webapp_wcs_sandbox_html_js_files + # JS files referenced in manifest.json. @@ -478,6 +485,7 @@ remoting_webapp_resource_files = [ "../resources/reload.webp", "../resources/tick.webp", "base/html/connection_stats.css", + "base/html/credits.css", "base/html/main.css", "base/html/message_window.css", "base/resources/open_sans.css", @@ -608,7 +616,8 @@ ar_background_js_files = [ ar_all_js_files = ar_main_js_files + ar_feedback_consent_html_js_files + remoting_webapp_message_window_html_js_files + - remoting_webapp_wcs_sandbox_html_js_files + ar_background_js_files + remoting_webapp_wcs_sandbox_html_js_files + ar_background_js_files + + remoting_webapp_credits_html_all_js_files # Files that contain localizable strings. app_remoting_webapp_localizable_files = diff --git a/tools/licenses.py b/tools/licenses.py index 6b8311a228dd..1bbb3d0af8ee 100755 --- a/tools/licenses.py +++ b/tools/licenses.py @@ -15,6 +15,7 @@ Commands: (You can also import this as a module.) """ +import argparse import cgi import os import sys @@ -422,13 +423,9 @@ def ScanThirdPartyDirs(root=None): return len(errors) == 0 -def GenerateCredits(): +def GenerateCredits(file_template_file, entry_template_file, output_file): """Generate about:credits.""" - if len(sys.argv) not in (2, 3): - print 'usage: licenses.py credits [output_file]' - return False - def EvaluateTemplate(template, env, escape=True): """Expand a template with variables like {{foo}} using a dictionary of expansions.""" @@ -441,8 +438,15 @@ def GenerateCredits(): root = os.path.join(os.path.dirname(__file__), '..') third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS, root) - entry_template = open(os.path.join(root, 'chrome', 'browser', 'resources', - 'about_credits_entry.tmpl'), 'rb').read() + if not file_template_file: + file_template_file = os.path.join(root, 'chrome', 'browser', + 'resources', 'about_credits.tmpl') + if not entry_template_file: + entry_template_file = os.path.join(root, 'chrome', 'browser', + 'resources', + 'about_credits_entry.tmpl') + + entry_template = open(entry_template_file).read() entries = [] for path in third_party_dirs: try: @@ -465,32 +469,37 @@ def GenerateCredits(): entries.sort(key=lambda entry: (entry['name'], entry['content'])) entries_contents = '\n'.join([entry['content'] for entry in entries]) - file_template = open(os.path.join(root, 'chrome', 'browser', 'resources', - 'about_credits.tmpl'), 'rb').read() + file_template = open(file_template_file).read() template_contents = "" template_contents += EvaluateTemplate(file_template, {'entries': entries_contents}, escape=False) - if len(sys.argv) == 3: - with open(sys.argv[2], 'w') as output_file: - output_file.write(template_contents) - elif len(sys.argv) == 2: + if output_file: + with open(output_file, 'w') as output: + output.write(template_contents) + else: print template_contents return True def main(): - command = 'help' - if len(sys.argv) > 1: - command = sys.argv[1] - - if command == 'scan': + parser = argparse.ArgumentParser() + parser.add_argument('--file-template', + help='Template HTML to use for the license page.') + parser.add_argument('--entry-template', + help='Template HTML to use for each license.') + parser.add_argument('command', choices=['help', 'scan', 'credits']) + parser.add_argument('output_file', nargs='?') + args = parser.parse_args() + + if args.command == 'scan': if not ScanThirdPartyDirs(): return 1 - elif command == 'credits': - if not GenerateCredits(): + elif args.command == 'credits': + if not GenerateCredits(args.file_template, args.entry_template, + args.output_file): return 1 else: print __doc__ -- 2.11.4.GIT