Chromium Code Reviews| Index: chrome/browser/extensions/component_loader.cc |
| diff --git a/chrome/browser/extensions/component_loader.cc b/chrome/browser/extensions/component_loader.cc |
| index 9c33be828570292ec369e3b3a286261b01b9d051..4a82b3aa594c9907e54bfbbabc1e5d52b5fdf9cf 100644 |
| --- a/chrome/browser/extensions/component_loader.cc |
| +++ b/chrome/browser/extensions/component_loader.cc |
| @@ -20,6 +20,7 @@ |
| #include "chrome/common/extensions/extension.h" |
| #include "chrome/common/extensions/extension_file_util.h" |
| #include "chrome/common/extensions/extension_manifest_constants.h" |
| +#include "chrome/common/extensions/feature_switch.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_source.h" |
| @@ -42,6 +43,35 @@ |
| namespace extensions { |
| +namespace { |
| + |
| +std::string GenerateId(const DictionaryValue* manifest, const FilePath& path) { |
| + if (manifest->HasKey(extension_manifest_keys::kPublicKey)) { |
| + std::string public_key; |
| + std::string public_key_bytes; |
| + std::string id; |
| + CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, |
| + &public_key)); |
| + CHECK(Extension::ParsePEMKeyBytes(public_key, &public_key_bytes)); |
| + CHECK(Extension::GenerateId(public_key_bytes, &id)); |
| + return id; |
| + } |
| + return Extension::GenerateIdForPath(path); |
|
Yoyo Zhou
2012/10/02 01:21:01
Is this a good idea? The path to a component exten
Aaron Boodman
2012/10/02 01:42:22
Good point, I reverted this bit.
|
| +} |
| + |
| +} // namespace |
| + |
| +ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( |
| + const DictionaryValue* manifest, const FilePath& directory) |
| + : manifest(manifest), |
| + root_directory(directory) { |
| + if (!root_directory.IsAbsolute()) { |
| + CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); |
| + root_directory = root_directory.Append(directory); |
| + } |
| + id = GenerateId(manifest, root_directory); |
| +} |
| + |
| ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, |
| PrefService* prefs, |
| PrefService* local_state) |
| @@ -59,6 +89,13 @@ ComponentLoader::~ComponentLoader() { |
| ClearAllRegistered(); |
| } |
| +const Extension* ComponentLoader::GetScriptBubble() const { |
| + if (script_bubble_id_.empty()) |
| + return NULL; |
| + |
| + return extension_service_->extensions()->GetByID(script_bubble_id_); |
| +} |
| + |
| void ComponentLoader::LoadAll() { |
| for (RegisteredComponentExtensions::iterator it = |
| component_extensions_.begin(); |
| @@ -90,9 +127,8 @@ void ComponentLoader::ClearAllRegistered() { |
| component_extensions_.clear(); |
| } |
| -const Extension* ComponentLoader::Add( |
| - int manifest_resource_id, |
| - const FilePath& root_directory) { |
| +std::string ComponentLoader::Add(int manifest_resource_id, |
| + const FilePath& root_directory) { |
| std::string manifest_contents = |
| ResourceBundle::GetSharedInstance().GetRawDataResource( |
| manifest_resource_id, |
| @@ -100,29 +136,30 @@ const Extension* ComponentLoader::Add( |
| return Add(manifest_contents, root_directory); |
| } |
| -const Extension* ComponentLoader::Add( |
| - const std::string& manifest_contents, |
| - const FilePath& root_directory) { |
| +std::string ComponentLoader::Add(const std::string& manifest_contents, |
| + const FilePath& root_directory) { |
| // The Value is kept for the lifetime of the ComponentLoader. This is |
| // required in case LoadAll() is called again. |
| DictionaryValue* manifest = ParseManifest(manifest_contents); |
| if (manifest) |
| return Add(manifest, root_directory); |
| - return NULL; |
| + return ""; |
| } |
| -const Extension* ComponentLoader::Add( |
| - const DictionaryValue* parsed_manifest, |
| - const FilePath& root_directory) { |
| - CHECK(!Exists(GenerateId(parsed_manifest))); |
| +std::string ComponentLoader::Add(const DictionaryValue* parsed_manifest, |
| + const FilePath& root_directory) { |
| ComponentExtensionInfo info(parsed_manifest, root_directory); |
| component_extensions_.push_back(info); |
| - if (extension_service_->is_ready()) |
| - return Load(info); |
| - return NULL; |
| + if (extension_service_->is_ready()) { |
|
Jeffrey Yasskin
2012/10/02 00:26:31
Comment why you need to handle the !is_ready() cas
Aaron Boodman
2012/10/02 01:28:52
Don't need to. Just simplified instead.
|
| + const Extension* extension = Load(info); |
| + if (extension) |
| + return extension->id(); |
| + return ""; |
| + } |
| + return info.id; |
| } |
| -const Extension* ComponentLoader::AddOrReplace(const FilePath& path) { |
| +std::string ComponentLoader::AddOrReplace(const FilePath& path) { |
| FilePath absolute_path = path; |
| file_util::AbsolutePath(&absolute_path); |
| std::string error; |
| @@ -133,7 +170,7 @@ const Extension* ComponentLoader::AddOrReplace(const FilePath& path) { |
| absolute_path.value() << "'. " << error; |
| return NULL; |
| } |
| - Remove(GenerateId(manifest.get())); |
| + Remove(GenerateId(manifest.get(), absolute_path)); |
| return Add(manifest.release(), absolute_path); |
| } |
| @@ -142,7 +179,7 @@ void ComponentLoader::Reload(const std::string& extension_id) { |
| for (RegisteredComponentExtensions::iterator it = |
| component_extensions_.begin(); it != component_extensions_.end(); |
| ++it) { |
| - if (GenerateId(it->manifest) == extension_id) { |
| + if (it->id == extension_id) { |
| Load(*it); |
| break; |
| } |
| @@ -152,22 +189,12 @@ void ComponentLoader::Reload(const std::string& extension_id) { |
| const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { |
| // TODO(abarth): We should REQUIRE_MODERN_MANIFEST_VERSION once we've updated |
| // our component extensions to the new manifest version. |
| - int flags = Extension::REQUIRE_KEY; |
| + int flags = Extension::NO_FLAGS; |
| std::string error; |
| - // Get the absolute path to the extension. |
| - FilePath absolute_path(info.root_directory); |
| - if (!absolute_path.IsAbsolute()) { |
| - if (PathService::Get(chrome::DIR_RESOURCES, &absolute_path)) { |
| - absolute_path = absolute_path.Append(info.root_directory); |
| - } else { |
| - NOTREACHED(); |
| - } |
| - } |
| - |
| scoped_refptr<const Extension> extension(Extension::Create( |
| - absolute_path, |
| + info.root_directory, |
| Extension::COMPONENT, |
| *info.manifest, |
| flags, |
| @@ -176,6 +203,7 @@ const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { |
| LOG(ERROR) << error; |
| return NULL; |
| } |
| + CHECK_EQ(info.id, extension->id()) << extension->name(); |
| extension_service_->AddExtension(extension); |
| return extension; |
| } |
| @@ -185,7 +213,7 @@ void ComponentLoader::Remove(const FilePath& root_directory) { |
| RegisteredComponentExtensions::iterator it = component_extensions_.begin(); |
| for (; it != component_extensions_.end(); ++it) { |
| if (it->root_directory == root_directory) { |
| - Remove(GenerateId(it->manifest)); |
| + Remove(GenerateId(it->manifest, root_directory)); |
| break; |
| } |
| } |
| @@ -194,7 +222,7 @@ void ComponentLoader::Remove(const FilePath& root_directory) { |
| void ComponentLoader::Remove(const std::string& id) { |
| RegisteredComponentExtensions::iterator it = component_extensions_.begin(); |
| for (; it != component_extensions_.end(); ++it) { |
| - if (GenerateId(it->manifest) == id) { |
| + if (it->id == id) { |
| delete it->manifest; |
| it = component_extensions_.erase(it); |
| if (extension_service_->is_ready()) |
| @@ -209,24 +237,11 @@ bool ComponentLoader::Exists(const std::string& id) const { |
| RegisteredComponentExtensions::const_iterator it = |
| component_extensions_.begin(); |
| for (; it != component_extensions_.end(); ++it) |
| - if (GenerateId(it->manifest) == id) |
| + if (it->id == id) |
| return true; |
| return false; |
| } |
| -std::string ComponentLoader::GenerateId(const DictionaryValue* manifest) { |
| - std::string public_key; |
| - std::string public_key_bytes; |
| - std::string id; |
| - if (!manifest->GetString( |
| - extension_manifest_keys::kPublicKey, &public_key) || |
| - !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) || |
| - !Extension::GenerateId(public_key_bytes, &id)) { |
| - return std::string(); |
| - } |
| - return id; |
| -} |
| - |
| void ComponentLoader::AddFileManagerExtension() { |
| #if defined(FILE_MANAGER_EXTENSION) |
| #ifndef NDEBUG |
| @@ -302,6 +317,14 @@ void ComponentLoader::AddChromeApp() { |
| #endif |
| } |
| +void ComponentLoader::AddScriptBubble() { |
| + if (FeatureSwitch::GetScriptBubble()->IsEnabled()) { |
| + script_bubble_id_ = |
| + Add(IDR_SCRIPT_BUBBLE_MANIFEST, |
| + FilePath(FILE_PATH_LITERAL("script_bubble"))); |
| + } |
| +} |
| + |
| void ComponentLoader::AddDefaultComponentExtensions() { |
| #if defined(OS_CHROMEOS) |
| if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) |
| @@ -380,6 +403,8 @@ void ComponentLoader::AddDefaultComponentExtensions() { |
| #if defined(USE_ASH) |
| AddChromeApp(); |
| #endif |
| + |
| + AddScriptBubble(); |
| } |
| void ComponentLoader::Observe( |