Commit 0bfd2410 authored by dtseng@chromium.org's avatar dtseng@chromium.org

Provide script/gypi support for manifest generation

This provides a gypi action including well-defined variables, a python script, and a first client in ChromeVox (main and guest).

This generation code was born out of necessity as ChromeVox evolves and requires a varying set of manifests depending on such factors as compression strategy, debug/release builds, Chrome webstore releases, and ChromeVox next (version).

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272781 0039d316-1c4b-4281-b951-d872f2087c98
parent e0f4c0c8
...@@ -295,10 +295,6 @@ ...@@ -295,10 +295,6 @@
<include name="IDR_CROSH_BUILTIN_MANIFEST" file="resources\chromeos\crosh_builtin\manifest.json" type="BINDATA" /> <include name="IDR_CROSH_BUILTIN_MANIFEST" file="resources\chromeos\crosh_builtin\manifest.json" type="BINDATA" />
<include name="IDR_CRYPTOHOME_HTML" file="resources\chromeos\cryptohome.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_CRYPTOHOME_HTML" file="resources\chromeos\cryptohome.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_CRYPTOHOME_JS" file="resources\chromeos\cryptohome.js" type="BINDATA" /> <include name="IDR_CRYPTOHOME_JS" file="resources\chromeos\cryptohome.js" type="BINDATA" />
<!-- manifest file of ChromeVox accessibility extension -->
<include name="IDR_CHROMEVOX_MANIFEST" file="resources\chromeos\chromevox\manifest.json" type="BINDATA" />
<include name="IDR_CHROMEVOX2_MANIFEST" file="resources\chromeos\chromevox2\manifest.json" type="BINDATA" />
<include name="IDR_CHROMEVOX_GUEST_MANIFEST" file="resources\chromeos\chromevox\manifest_guest.json" type="BINDATA" />
<!-- manifest file of Connectivity Diagnostics app --> <!-- manifest file of Connectivity Diagnostics app -->
<include name="IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST" file="resources\chromeos\connectivity_diagnostics\manifest.json" type="BINDATA" /> <include name="IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST" file="resources\chromeos\connectivity_diagnostics\manifest.json" type="BINDATA" />
<include name="IDR_CONNECTIVITY_DIAGNOSTICS_LAUNCHER_MANIFEST" file="resources\chromeos\connectivity_diagnostics_launcher\manifest.json" type="BINDATA" /> <include name="IDR_CONNECTIVITY_DIAGNOSTICS_LAUNCHER_MANIFEST" file="resources\chromeos\connectivity_diagnostics_launcher\manifest.json" type="BINDATA" />
......
...@@ -329,15 +329,23 @@ void ComponentLoader::AddNetworkSpeechSynthesisExtension() { ...@@ -329,15 +329,23 @@ void ComponentLoader::AddNetworkSpeechSynthesisExtension() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
std::string ComponentLoader::AddChromeVoxExtension() { std::string ComponentLoader::AddChromeVoxExtension() {
base::FilePath chromevox_path;
PathService::Get(chrome::DIR_RESOURCES, &chromevox_path);
chromevox_path =
chromevox_path.Append(extension_misc::kChromeVoxExtensionPath);
const CommandLine* command_line = CommandLine::ForCurrentProcess(); const CommandLine* command_line = CommandLine::ForCurrentProcess();
int idr = command_line->HasSwitch(chromeos::switches::kGuestSession) ? const char* manifest_filename =
IDR_CHROMEVOX_GUEST_MANIFEST : IDR_CHROMEVOX_MANIFEST; command_line->HasSwitch(chromeos::switches::kGuestSession) ?
extension_misc::kChromeVoxGuestManifestFilename :
extension_misc::kChromeVoxManifestFilename;
std::string error;
scoped_ptr<base::DictionaryValue> manifest(
file_util::LoadManifest(chromevox_path, manifest_filename, &error));
CHECK(manifest) << error;
// TODO(dtseng): Guest mode manifest for ChromeVox Next pending work to return Add(manifest.release(), chromevox_path);
// generate manifests.
if (command_line->HasSwitch(chromeos::switches::kEnableChromeVoxNext))
idr = IDR_CHROMEVOX2_MANIFEST;
return Add(idr, base::FilePath(extension_misc::kChromeVoxExtensionPath));
} }
std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() { std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
'content_script_loader_file': 'chromevox/injected/loader.js', 'content_script_loader_file': 'chromevox/injected/loader.js',
'options_script_loader_file': 'chromevox/background/options_loader.js', 'options_script_loader_file': 'chromevox/background/options_loader.js',
'kbexplorer_loader_file': 'chromevox/background/kbexplorer_loader.js', 'kbexplorer_loader_file': 'chromevox/background/kbexplorer_loader.js',
'template_manifest_path': 'manifest.json.jinja2',
}, },
'targets': [ 'targets': [
{ {
...@@ -31,6 +32,8 @@ ...@@ -31,6 +32,8 @@
'dependencies': [ 'dependencies': [
'chromevox_assets', 'chromevox_assets',
'chromevox_static_files', 'chromevox_static_files',
'chromevox_manifest',
'chromevox_guest_manifest',
'chromevox_strings', 'chromevox_strings',
'chromevox_uncompiled_js_files', 'chromevox_uncompiled_js_files',
'<(chromevox_third_party_dir)/chromevox.gyp:chromevox_third_party_resources', '<(chromevox_third_party_dir)/chromevox.gyp:chromevox_third_party_resources',
...@@ -63,6 +66,23 @@ ...@@ -63,6 +66,23 @@
'chromevox_assets.gypi', 'chromevox_assets.gypi',
], ],
}, },
{
'target_name': 'chromevox_manifest',
'type': 'none',
'variables': {
'output_manifest_path': '<(chromevox_dest_dir)/manifest.json',
},
'includes': [ 'generate_manifest.gypi', ],
},
{
'target_name': 'chromevox_guest_manifest',
'type': 'none',
'variables': {
'output_manifest_path': '<(chromevox_dest_dir)/manifest_guest.json',
'is_guest_manifest': 1,
},
'includes': [ 'generate_manifest.gypi', ],
},
{ {
'target_name': 'chromevox_static_files', 'target_name': 'chromevox_static_files',
'type': 'none', 'type': 'none',
......
# 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.
# Generates an output manifest based on a Jinja2 templated manifest.
# Include this file inside of your target to generate a manifest.
# The following variables must be set before including this file:
#
# template_manifest_path: a valid Jinja2 file path.
# output_manifest_path: file path for the resulting manifest.
#
# The following variable is optional:
#
# is_guest_manifest: 1 or 0; generates a manifest usable while in guest mode.
{
'actions': [
{
'action_name': 'generate_manifest',
'message': 'Generate manifest for <(_target_name)',
'variables': {
'is_guest_manifest%': 0,
},
'inputs': [
'tools/generate_manifest.py',
'<(template_manifest_path)',
],
'outputs': [
'<(output_manifest_path)'
],
'action': [
'python',
'tools/generate_manifest.py',
'-o', '<(output_manifest_path)',
'-g', '<(is_guest_manifest)',
'<(template_manifest_path)'
],
},
],
}
{ {
// NOTE: Keep two json files in this directory in sync. The only difference
// should be incognito:split in Guest mode version.
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDltVl1k15pjRzuZfMc3B69inxwm2bZeZ2O8/zFO+NluHnBm3GJ3fzdOoFGJd+M16I8p7zxxQyHeDMfWYASyCeB8XnUEDKjqNLQfCnncsANzHsYoEbYj2nEUML2P13b9q+AAvpCBpAJ4cZp81e9n1y/vbSXHE4385cgkKueItzikQIDAQAB", "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDltVl1k15pjRzuZfMc3B69inxwm2bZeZ2O8/zFO+NluHnBm3GJ3fzdOoFGJd+M16I8p7zxxQyHeDMfWYASyCeB8XnUEDKjqNLQfCnncsANzHsYoEbYj2nEUML2P13b9q+AAvpCBpAJ4cZp81e9n1y/vbSXHE4385cgkKueItzikQIDAQAB",
"manifest_version": 2, "manifest_version": 2,
"name": "ChromeVox", "name": "ChromeVox",
"version": "1.0", "version": "1.0",
"description": "ChromeVox - Giving Voice to Chrome.", "description": "ChromeVox - Giving Voice to Chrome.",
{% if is_guest_manifest == '1' %}
"incognito": "split",
{% endif %}
"background": { "background": {
"page": "chromevox/background/background.html" "page": "chromevox/background/background.html"
}, },
......
{
// NOTE: Keep two json files in this directory in sync. The only difference
// should be incognito:split in Guest mode version.
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDltVl1k15pjRzuZfMc3B69inxwm2bZeZ2O8/zFO+NluHnBm3GJ3fzdOoFGJd+M16I8p7zxxQyHeDMfWYASyCeB8XnUEDKjqNLQfCnncsANzHsYoEbYj2nEUML2P13b9q+AAvpCBpAJ4cZp81e9n1y/vbSXHE4385cgkKueItzikQIDAQAB",
"manifest_version": 2,
"name": "ChromeVox",
"version": "1.0",
"description": "ChromeVox - Giving Voice to Chrome.",
"incognito": "split",
"background": {
"page": "chromevox/background/background.html"
},
"permissions": [
"accessibilityPrivate",
"automation",
"bookmarks",
"tabs",
"experimental",
"history",
"tts",
"systemPrivate",
"brailleDisplayPrivate",
"commandLinePrivate",
"<all_urls>"
],
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"exclude_globs": [ "chrome-extension://mndnfokpggljbaajbnioimlmbfngpief/chromevox/background/background.html" ],
"all_frames": true,
"js": [
"chromeVoxChromePageScript.js"
]
}
],
"web_accessible_resources": [
"chromevox/injected/api.js",
"chromevox/injected/api_util.js",
"chromevox/injected/mathjax.js",
"chromevox/injected/mathjax_external_util.js"
],
"default_locale": "en"
}
#!/usr/bin/env python
# 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.
import json
import io
import optparse
import os
import sys
jinja2_path = os.path.normpath(os.path.join(os.path.abspath(__file__),
*[os.path.pardir] * 7 + ['third_party']))
nom_path = os.path.normpath(os.path.join(os.path.abspath(__file__),
*[os.path.pardir] * 7 + ['tools/json_comment_eater']))
sys.path.insert(0, jinja2_path)
sys.path.insert(0, nom_path)
import jinja2
from json_comment_eater import Nom
'''Generate an extension manifest based on a template.'''
def processJinjaTemplate(input_file, output_file, context):
(template_path, template_name) = os.path.split(input_file)
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
template = env.get_template(template_name)
rendered = template.render(context)
rendered_without_comments = Nom(rendered)
# Simply for validation.
json.loads(rendered_without_comments)
with io.open(output_file, 'w', encoding='utf-8') as manifest_file:
manifest_file.write(rendered_without_comments)
def main():
parser = optparse.OptionParser(description=__doc__)
parser.usage = '%prog [options] <template_manifest_path>'
parser.add_option(
'-o', '--output_manifest', action='store', metavar='OUTPUT_MANIFEST',
help='File to place generated manifest')
parser.add_option(
'-g', '--is_guest_manifest', action='store', metavar='GUEST_MANIFEST',
help='Generate a guest mode capable manifest')
options, args = parser.parse_args()
if len(args) != 1:
print >>sys.stderr, 'Expected exactly one argument'
sys.exit(1)
processJinjaTemplate(args[0], options.output_manifest, parser.values.__dict__)
if __name__ == '__main__':
main()
...@@ -137,6 +137,8 @@ const char kPlatformAppLaunchHistogram[] = "Apps.AppLaunch"; ...@@ -137,6 +137,8 @@ const char kPlatformAppLaunchHistogram[] = "Apps.AppLaunch";
const char kChromeVoxExtensionId[] = const char kChromeVoxExtensionId[] =
"mndnfokpggljbaajbnioimlmbfngpief"; "mndnfokpggljbaajbnioimlmbfngpief";
const char kChromeVoxExtensionPath[] = "chromeos/chromevox"; const char kChromeVoxExtensionPath[] = "chromeos/chromevox";
const char kChromeVoxManifestFilename[] = "manifest.json";
const char kChromeVoxGuestManifestFilename[] = "manifest_guest.json";
const char kBrailleImeExtensionId[] = const char kBrailleImeExtensionId[] =
"jddehjeebkoimngcbdkaahpobgicbffp"; "jddehjeebkoimngcbdkaahpobgicbffp";
const char kBrailleImeExtensionPath[] = const char kBrailleImeExtensionPath[] =
......
...@@ -245,6 +245,10 @@ extern const char kChromeVoxExtensionId[]; ...@@ -245,6 +245,10 @@ extern const char kChromeVoxExtensionId[];
// Path to preinstalled ChromeVox screen reader extension (relative to // Path to preinstalled ChromeVox screen reader extension (relative to
// |chrome::DIR_RESOURCES|). // |chrome::DIR_RESOURCES|).
extern const char kChromeVoxExtensionPath[]; extern const char kChromeVoxExtensionPath[];
// Name of ChromeVox manifest file.
extern const char kChromeVoxManifestFilename[];
// Name of ChromeVox guest manifest file.
extern const char kChromeVoxGuestManifestFilename[];
// Extension id, path (relative to |chrome::DIR_RESOURCES|) and IME engine // Extension id, path (relative to |chrome::DIR_RESOURCES|) and IME engine
// id for the builtin-in Braille IME extension. // id for the builtin-in Braille IME extension.
extern const char kBrailleImeExtensionId[]; extern const char kBrailleImeExtensionId[];
......
...@@ -155,7 +155,14 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path, ...@@ -155,7 +155,14 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
base::DictionaryValue* LoadManifest(const base::FilePath& extension_path, base::DictionaryValue* LoadManifest(const base::FilePath& extension_path,
std::string* error) { std::string* error) {
base::FilePath manifest_path = extension_path.Append(kManifestFilename); return LoadManifest(extension_path, kManifestFilename, error);
}
base::DictionaryValue* LoadManifest(
const base::FilePath& extension_path,
const base::FilePath::CharType* manifest_filename,
std::string* error) {
base::FilePath manifest_path = extension_path.Append(manifest_filename);
if (!base::PathExists(manifest_path)) { if (!base::PathExists(manifest_path)) {
*error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE);
return NULL; return NULL;
......
...@@ -61,6 +61,12 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root, ...@@ -61,6 +61,12 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root,
base::DictionaryValue* LoadManifest(const base::FilePath& extension_root, base::DictionaryValue* LoadManifest(const base::FilePath& extension_root,
std::string* error); std::string* error);
// Convenience overload for specifying a manifest filename.
base::DictionaryValue* LoadManifest(
const base::FilePath& extension_root,
const base::FilePath::CharType* manifest_filename,
std::string* error);
// Returns true if the given extension object is valid and consistent. // Returns true if the given extension object is valid and consistent.
// May also append a series of warning messages to |warnings|, but they // May also append a series of warning messages to |warnings|, but they
// should not prevent the extension from running. // should not prevent the extension from running.
......
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