diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-31 04:21:45 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-31 04:21:45 +0000 |
commit | 0b3449662125083d13138cbab1ec039c9e9fddc4 (patch) | |
tree | 8503ed6f529f991dd4870999a14f6229adda0c7f /chrome/browser/extensions/extension.cc | |
parent | 49a14a8af7d0186c0c6de56271dffdf54643b5fd (diff) | |
download | chromium_src-0b3449662125083d13138cbab1ec039c9e9fddc4.zip chromium_src-0b3449662125083d13138cbab1ec039c9e9fddc4.tar.gz chromium_src-0b3449662125083d13138cbab1ec039c9e9fddc4.tar.bz2 |
Make the "id" key for extension manifests optional in
--load-extension mode. This makes this mode more convenient, and
should lead to less copy-and-paste of extension IDs.
Also, remove the "format_version" key. This is basically
duplicated in the code that checks the version number of the crx
file format. And if we ever really need a format version for the
manifest, we can always add it later.
Review URL: http://codereview.chromium.org/56044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12837 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension.cc')
-rw-r--r-- | chrome/browser/extensions/extension.cc | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index 57fbbbc..d8ab403 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -18,7 +18,6 @@ const char Extension::kManifestFilename[] = "manifest.json"; const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; const wchar_t* Extension::kCssKey = L"css"; const wchar_t* Extension::kDescriptionKey = L"description"; -const wchar_t* Extension::kFormatVersionKey = L"format_version"; const wchar_t* Extension::kIdKey = L"id"; const wchar_t* Extension::kJsKey = L"js"; const wchar_t* Extension::kMatchesKey = L"matches"; @@ -48,8 +47,6 @@ const char* Extension::kInvalidCssListError = "Required value 'content_scripts[*].css is invalid."; const char* Extension::kInvalidDescriptionError = "Invalid value for 'description'."; -const char* Extension::kInvalidFormatVersionError = - "Required value 'format_version' is missing or invalid."; const char* Extension::kInvalidIdError = "Required value 'id' is missing or invalid."; const char* Extension::kInvalidJsError = @@ -106,6 +103,21 @@ Extension::Extension(const Extension& rhs) theme_paths_(rhs.theme_paths_) { } +const GURL& Extension::url() { + if (!extension_url_.is_valid()) + extension_url_ = GURL(std::string(chrome::kExtensionScheme) + + chrome::kStandardSchemeSeparator + id_ + "/"); + + return extension_url_; +} + +void Extension::set_id(const std::string& id) { + id_ = id; + + // Reset url_ so that it gets reinitialized next time. + extension_url_ = GURL(); +} + const std::string Extension::VersionString() const { return version_->GetString(); } @@ -325,36 +337,27 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, bool Extension::InitFromValue(const DictionaryValue& source, std::string* error) { - // Check format version. - int format_version = 0; - if (!source.GetInteger(kFormatVersionKey, &format_version) || - static_cast<uint32>(format_version) != kExpectedFormatVersion) { - *error = kInvalidFormatVersionError; - return false; - } - - // Initialize id. - if (!source.GetString(kIdKey, &id_)) { - *error = kInvalidIdError; - return false; - } + // Initialize id. The ID is not required here because we don't require IDs for + // extensions used with --load-extension. + if (source.HasKey(kIdKey)) { + if (!source.GetString(kIdKey, &id_)) { + *error = kInvalidIdError; + return false; + } - // Normalize the string to lowercase, so it can be used as an URL component - // (where GURL will lowercase it). - StringToLowerASCII(&id_); + // Normalize the string to lowercase, so it can be used as an URL component + // (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) { - *error = kInvalidIdError; - return false; + // 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) { + *error = kInvalidIdError; + return false; + } } - // Initialize URL. - extension_url_ = GURL(std::string(chrome::kExtensionScheme) + - chrome::kStandardSchemeSeparator + id_ + "/"); - // Initialize version. std::string version_str; if (!source.GetString(kVersionKey, &version_str)) { |