Allow packaging accessibility extension from chromecast build
Make changes to build files to allow packaging chromevox from chromecast builds. Need to split out chromevox and common deps from deps that will only build for chromeos. Also add the ability to specify a manifest file using the FileUtil::LoadExtension method instead of assuming 'manifest.json' hard coded constant. Bug: None Test: Test case, Local chromecast build Change-Id: Id4e5ac0cbb80241536a2e7e3cf48a71dd5f1124a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112573 Reviewed-by: Mike Pinkerton <pinkerton@chromium.org> Reviewed-by: David Tseng <dtseng@chromium.org> Commit-Queue: Randy Rossi <rmrossi@chromium.org> Cr-Commit-Position: refs/heads/master@{#754093}
This commit is contained in:
BUILD.gn
chrome/browser/resources/chromeos/accessibility
chromecast/browser/extensions
extensions/common
4
BUILD.gn
4
BUILD.gn
@ -666,9 +666,7 @@ group("gn_all") {
|
||||
deps += [ "//chromecast:cast_shell" ]
|
||||
}
|
||||
if (enable_extensions && use_aura) {
|
||||
deps += [
|
||||
"//chrome/browser/resources/chromeos/accessibility/chromevox:build",
|
||||
]
|
||||
deps += [ "//chrome/browser/resources/chromeos/accessibility:build" ]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import("//chrome/common/features.gni")
|
||||
import("//chromecast/chromecast.gni")
|
||||
import("strings/accessibility_strings.gni")
|
||||
|
||||
assert(is_chromeos)
|
||||
assert(is_chromeos || is_chromecast)
|
||||
|
||||
accessibility_out_dir = "$root_out_dir/resources/chromeos/accessibility/"
|
||||
|
||||
@ -16,16 +16,20 @@ group("build") {
|
||||
":accessibility_strings",
|
||||
":chromevox_guest_manifest",
|
||||
":chromevox_manifest",
|
||||
":select_to_speak_guest_manifest",
|
||||
":select_to_speak_manifest",
|
||||
":switch_access_guest_manifest",
|
||||
":switch_access_manifest",
|
||||
"autoclick:build",
|
||||
"chromevox:build",
|
||||
"common:build",
|
||||
"select_to_speak:build",
|
||||
"switch_access:build",
|
||||
]
|
||||
if (is_chromeos) {
|
||||
deps += [
|
||||
":select_to_speak_guest_manifest",
|
||||
":select_to_speak_manifest",
|
||||
":switch_access_guest_manifest",
|
||||
":switch_access_manifest",
|
||||
"autoclick:build",
|
||||
"select_to_speak:build",
|
||||
"switch_access:build",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
template("manifest") {
|
||||
@ -99,11 +103,13 @@ accessibility_strings("accessibility_strings") {
|
||||
|
||||
group("browser_tests") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"autoclick:browser_tests",
|
||||
"chromevox:browser_tests",
|
||||
"common:browser_tests",
|
||||
"select_to_speak:browser_tests",
|
||||
"switch_access:browser_tests",
|
||||
]
|
||||
if (is_chromeos) {
|
||||
deps = [
|
||||
"autoclick:browser_tests",
|
||||
"chromevox:browser_tests",
|
||||
"common:browser_tests",
|
||||
"select_to_speak:browser_tests",
|
||||
"switch_access:browser_tests",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import("//chrome/test/base/js2gtest.gni")
|
||||
import("//testing/test.gni")
|
||||
import("//third_party/closure_compiler/compile_js.gni")
|
||||
|
||||
assert(is_chromeos)
|
||||
assert(is_chromeos || is_chromecast)
|
||||
|
||||
accessibility_common_out_dir =
|
||||
"$root_out_dir/resources/chromeos/accessibility/common"
|
||||
@ -111,12 +111,14 @@ js2gtest("accessibility_tests") {
|
||||
"../chromevox/testing/mock_feedback.js",
|
||||
]
|
||||
|
||||
# The test base classes generate C++ code with these deps.
|
||||
deps = [
|
||||
"//ash",
|
||||
"//base",
|
||||
"//chrome/browser/chromeos",
|
||||
"//chrome/common",
|
||||
]
|
||||
if (is_chromeos) {
|
||||
# The test base classes generate C++ code with these deps.
|
||||
deps = [
|
||||
"//ash",
|
||||
"//base",
|
||||
"//chrome/browser/chromeos",
|
||||
"//chrome/common",
|
||||
]
|
||||
}
|
||||
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
|
||||
}
|
||||
|
@ -109,14 +109,21 @@ const Extension* CastExtensionSystem::LoadExtensionByManifest(
|
||||
|
||||
const Extension* CastExtensionSystem::LoadExtension(
|
||||
const base::FilePath& extension_dir) {
|
||||
return LoadExtension(kManifestFilename, extension_dir);
|
||||
}
|
||||
|
||||
const Extension* CastExtensionSystem::LoadExtension(
|
||||
const base::FilePath::CharType* manifest_file,
|
||||
const base::FilePath& extension_dir) {
|
||||
// cast_shell only supports unpacked extensions.
|
||||
// NOTE: If you add packed extension support consider removing the flag
|
||||
// FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks.
|
||||
CHECK(base::DirectoryExists(extension_dir)) << extension_dir.AsUTF8Unsafe();
|
||||
int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
|
||||
std::string load_error;
|
||||
scoped_refptr<Extension> extension = file_util::LoadExtension(
|
||||
extension_dir, Manifest::COMPONENT, load_flags, &load_error);
|
||||
scoped_refptr<Extension> extension =
|
||||
file_util::LoadExtension(extension_dir, manifest_file, std::string(),
|
||||
Manifest::COMPONENT, load_flags, &load_error);
|
||||
if (!extension.get()) {
|
||||
LOG(ERROR) << "Loading extension at " << extension_dir.value()
|
||||
<< " failed with: " << load_error;
|
||||
|
@ -8,16 +8,13 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/one_shot_event.h"
|
||||
#include "extensions/browser/extension_registrar.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
}
|
||||
@ -38,6 +35,11 @@ class CastExtensionSystem : public ExtensionSystem,
|
||||
// success, or nullptr otherwise.
|
||||
const Extension* LoadExtension(const base::FilePath& extension_dir);
|
||||
|
||||
// Loads an unpacked extension from a manifest file with the provided
|
||||
// dir. Returns the extension on success, or nullptr otherwise.
|
||||
const Extension* LoadExtension(const base::FilePath::CharType* manifest_file,
|
||||
const base::FilePath& extension_dir);
|
||||
|
||||
// Load an extension from the contents of a manifest file.
|
||||
const Extension* LoadExtensionByManifest(const std::string& manifest);
|
||||
|
||||
|
@ -196,7 +196,8 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
|
||||
Manifest::Location location,
|
||||
int flags,
|
||||
std::string* error) {
|
||||
return LoadExtension(extension_path, std::string(), location, flags, error);
|
||||
return LoadExtension(extension_path, nullptr, std::string(), location, flags,
|
||||
error);
|
||||
}
|
||||
|
||||
scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
|
||||
@ -204,8 +205,23 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_path,
|
||||
Manifest::Location location,
|
||||
int flags,
|
||||
std::string* error) {
|
||||
std::unique_ptr<base::DictionaryValue> manifest =
|
||||
LoadManifest(extension_path, error);
|
||||
return LoadExtension(extension_path, nullptr, extension_id, location, flags,
|
||||
error);
|
||||
}
|
||||
|
||||
scoped_refptr<Extension> LoadExtension(
|
||||
const base::FilePath& extension_path,
|
||||
const base::FilePath::CharType* manifest_file,
|
||||
const std::string& extension_id,
|
||||
Manifest::Location location,
|
||||
int flags,
|
||||
std::string* error) {
|
||||
std::unique_ptr<base::DictionaryValue> manifest;
|
||||
if (!manifest_file) {
|
||||
manifest = LoadManifest(extension_path, error);
|
||||
} else {
|
||||
manifest = LoadManifest(extension_path, manifest_file, error);
|
||||
}
|
||||
if (!manifest.get())
|
||||
return nullptr;
|
||||
|
||||
|
@ -46,8 +46,9 @@ base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir,
|
||||
void UninstallExtension(const base::FilePath& extensions_dir,
|
||||
const std::string& id);
|
||||
|
||||
// Loads and validates an extension from the specified directory. Returns NULL
|
||||
// on failure, with a description of the error in |error|.
|
||||
// Loads and validates an extension from the specified directory. Uses
|
||||
// the default manifest filename. Returns nullptr on failure, with a
|
||||
// description of the error in |error|.
|
||||
scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root,
|
||||
Manifest::Location location,
|
||||
int flags,
|
||||
@ -60,6 +61,17 @@ scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root,
|
||||
int flags,
|
||||
std::string* error);
|
||||
|
||||
// The same as LoadExtension except use the provided |manifest_file| and
|
||||
// |extension_id|. If manifest_file is not specified, uses the default
|
||||
// manifest filename.
|
||||
scoped_refptr<Extension> LoadExtension(
|
||||
const base::FilePath& extension_root,
|
||||
const base::FilePath::CharType* manifest_file,
|
||||
const std::string& extension_id,
|
||||
Manifest::Location location,
|
||||
int flags,
|
||||
std::string* error);
|
||||
|
||||
// Loads an extension manifest from the specified directory. Returns NULL
|
||||
// on failure, with a description of the error in |error|.
|
||||
std::unique_ptr<base::DictionaryValue> LoadManifest(
|
||||
|
@ -41,6 +41,10 @@ const char manifest_content[] =
|
||||
" \"manifest_version\": 2\n"
|
||||
"}\n";
|
||||
|
||||
const char kCustomManifest[] = "custom_manifest.json";
|
||||
const base::FilePath::CharType kCustomManifestFilename[] =
|
||||
FILE_PATH_LITERAL("custom_manifest.json");
|
||||
|
||||
scoped_refptr<Extension> LoadExtensionManifest(
|
||||
const base::DictionaryValue& manifest,
|
||||
const base::FilePath& manifest_dir,
|
||||
@ -510,6 +514,33 @@ TEST_F(FileUtilTest, WarnOnPrivateKey) {
|
||||
"extension includes the key file.*ext_root.a_key.pem"));
|
||||
}
|
||||
|
||||
// Specify a file other than manifest.json
|
||||
TEST_F(FileUtilTest, SpecifyManifestFile) {
|
||||
base::ScopedTempDir temp;
|
||||
ASSERT_TRUE(temp.CreateUniqueTempDir());
|
||||
|
||||
base::FilePath ext_path = temp.GetPath().AppendASCII("ext_root");
|
||||
ASSERT_TRUE(base::CreateDirectory(ext_path));
|
||||
|
||||
const char manifest[] =
|
||||
"{\n"
|
||||
" \"name\": \"Test Extension\",\n"
|
||||
" \"version\": \"1.0\",\n"
|
||||
" \"manifest_version\": 2,\n"
|
||||
" \"description\": \"The first extension that I made.\"\n"
|
||||
"}\n";
|
||||
ASSERT_EQ(static_cast<int>(strlen(manifest)),
|
||||
base::WriteFile(ext_path.AppendASCII(kCustomManifest), manifest,
|
||||
strlen(manifest)));
|
||||
|
||||
std::string error;
|
||||
scoped_refptr<Extension> extension(file_util::LoadExtension(
|
||||
ext_path, kCustomManifestFilename, "the_id", Manifest::EXTERNAL_PREF,
|
||||
Extension::NO_FLAGS, &error));
|
||||
ASSERT_TRUE(extension.get()) << error;
|
||||
ASSERT_EQ(0u, extension->install_warnings().size());
|
||||
}
|
||||
|
||||
// Try to install an extension with a zero-length icon file.
|
||||
TEST_F(FileUtilTest, CheckZeroLengthAndMissingIconFile) {
|
||||
base::FilePath install_dir;
|
||||
|
Reference in New Issue
Block a user