diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 21:53:19 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 21:53:19 +0000 |
commit | 25b3433897bab5e94dac9ab8a2f09b356792ab7d (patch) | |
tree | 50addd81b87cf947d52b489af4edeae4614013bc /chrome/common/extensions | |
parent | c333ede219e0e33b5df85f02bb9d261d7033c9c1 (diff) | |
download | chromium_src-25b3433897bab5e94dac9ab8a2f09b356792ab7d.zip chromium_src-25b3433897bab5e94dac9ab8a2f09b356792ab7d.tar.gz chromium_src-25b3433897bab5e94dac9ab8a2f09b356792ab7d.tar.bz2 |
Add this ability to install Extensions using preferences. Also known as: port the installation mechanism to other platforms.
We already have the ability to install extensions using a registry key. That works only on Windows so this new change adds the same but using preferences instead of the Registry. This will eventually allow us to pre-install certain extensions when we install Chrome.
BUG=12060
TEST=Covered by unit tests, but to test manually: close Chrome, open your Preferences file (in your profile) and add this (after substituting all <values> in elbow brackets):
"extensions": {
"settings": {
"<your_extension_id_lowercased>": {
"external_crx": "<path_to_crx>",
"external_version": "<crx version>"
}
},
},
... then start Chrome. Your extension should get installed.
Review URL: http://codereview.chromium.org/119195
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/extension.cc | 46 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 34 | ||||
-rw-r--r-- | chrome/common/extensions/extension_unpacker.cc | 13 |
3 files changed, 71 insertions, 22 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index f6a579b..c641afc 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -15,6 +15,10 @@ #include "chrome/common/extensions/user_script.h" #include "chrome/common/url_constants.h" +#if defined(OS_WIN) +#include "base/registry.h" +#endif + const char Extension::kManifestFilename[] = "manifest.json"; const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; @@ -142,6 +146,11 @@ const char* Extension::kInvalidThemeTintsError = const char* Extension::kThemesCannotContainExtensionsError = "A theme cannot contain extensions code."; +#if defined(OS_WIN) +const char* Extension::kExtensionRegistryPath = + "Software\\Google\\Chrome\\Extensions"; +#endif + const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes Extension::~Extension() { @@ -155,6 +164,24 @@ const std::string Extension::VersionString() const { } // static +bool Extension::IdIsValid(const std::string& id) { + // Verify that the id is legal. The id is a hex string of the SHA-1 hash of + // the public key. + std::vector<uint8> id_bytes; + if (!HexStringToBytes(id, &id_bytes) || id_bytes.size() != kIdSize) + return false; + + // We only support lowercase IDs, because IDs can be used as URL components + // (where GURL will lowercase it). + std::string temp = id; + StringToLowerASCII(temp); + if (temp != id) + return false; + + return true; +} + +// static GURL Extension::GetResourceURL(const GURL& extension_url, const std::string& relative_path) { DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); @@ -174,6 +201,19 @@ const PageAction* Extension::GetPageAction(std::string id) const { return it->second; } +Extension::Location Extension::ExternalExtensionInstallType( + std::string registry_path) { +#if defined(OS_WIN) + HKEY reg_root = HKEY_LOCAL_MACHINE; + RegKey key; + registry_path.append("\\"); + registry_path.append(id_); + if (key.Open(reg_root, ASCIIToWide(registry_path).c_str())) + return Extension::EXTERNAL_REGISTRY; +#endif + return Extension::EXTERNAL_PREF; +} + // Helper method that loads a UserScript object from a dictionary in the // content_script list of the manifest. bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, @@ -449,10 +489,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, // (where GURL will lowercase it). StringToLowerASCII(&id_); - // Verify that the id is legal. The id is a hex string of the SHA-1 hash of - // the public key. - std::vector<uint8> id_bytes; - if (!HexStringToBytes(id_, &id_bytes) || id_bytes.size() != kIdSize) { + // Verify that the id is legal. + if (!IdIsValid(id_)) { *error = kInvalidIdError; return false; } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 76f4b20..9b79f30 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -24,10 +24,17 @@ class Extension { // What an extension was loaded from. enum Location { INVALID, - INTERNAL, // A crx file from the internal Extensions directory. - EXTERNAL, // A crx file from an external directory (via eg the registry - // on Windows). - LOAD // --load-extension. + INTERNAL, // A crx file from the internal Extensions directory. + EXTERNAL_PREF, // A crx file from an external directory (via prefs). + EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the + // registry on Windows). + LOAD // --load-extension. + }; + + enum State { + DISABLED, + ENABLED, + KILLBIT, // Don't install/upgrade (applies to external extensions only). }; // An NPAPI plugin included in the extension. @@ -114,6 +121,10 @@ class Extension { static const char* kThemesCannotContainExtensionsError; static const char* kMissingFileError; +#if defined(OS_WIN) + static const char* kExtensionRegistryPath; +#endif + // The number of bytes in a legal id. static const size_t kIdSize; @@ -121,6 +132,15 @@ class Extension { explicit Extension(const FilePath& path); virtual ~Extension(); + // Checks to see if the extension has a valid ID. + static bool IdIsValid(const std::string& id); + + // Whether the |location| is external or not. + static inline bool IsExternalLocation(Location location) { + return location == Extension::EXTERNAL_PREF || + location == Extension::EXTERNAL_REGISTRY; + } + // Returns an absolute url to a resource inside of an extension. The // |extension_url| argument should be the url() from an Extension object. The // |relative_path| can be untrusted user input. The returned URL will either @@ -169,7 +189,11 @@ class Extension { // Retrieves a page action by |id|. const PageAction* GetPageAction(std::string id) const; - // Theme-related + // Returns the origin of this extension. This function takes a |registry_path| + // so that the registry location can be overwritten during testing. + Location ExternalExtensionInstallType(std::string registry_path); + + // Theme-related. DictionaryValue* GetThemeImages() const { return theme_images_.get(); } DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } diff --git a/chrome/common/extensions/extension_unpacker.cc b/chrome/common/extensions/extension_unpacker.cc index f98e875..916b048 100644 --- a/chrome/common/extensions/extension_unpacker.cc +++ b/chrome/common/extensions/extension_unpacker.cc @@ -41,19 +41,6 @@ struct ExtensionHeader { const size_t kZipHashBytes = 32; // SHA-256 const size_t kZipHashHexBytes = kZipHashBytes * 2; // Hex string is 2x size. -#if defined(OS_WIN) - -// Registry key where registry defined extension installers live. -const wchar_t kRegistryExtensions[] = L"Software\\Google\\Chrome\\Extensions"; - -// Registry value of of that key that defines the path to the .crx file. -const wchar_t kRegistryExtensionPath[] = L"path"; - -// Registry value of that key that defines the current version of the .crx file. -const wchar_t kRegistryExtensionVersion[] = L"version"; - -#endif - // A marker file to indicate that an extension was installed from an external // source. const char kExternalInstallFile[] = "EXTERNAL_INSTALL"; |