summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-12 19:36:42 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-12 19:36:42 +0000
commit64a02b8056c86576428022859baadbb9a7b929f1 (patch)
treefba294d94f03345806aeb15f6a2fbb2d8fd652f6 /chrome/browser
parentaf05c6aa88661f7595b6a883667c352d51e66eb7 (diff)
downloadchromium_src-64a02b8056c86576428022859baadbb9a7b929f1.zip
chromium_src-64a02b8056c86576428022859baadbb9a7b929f1.tar.gz
chromium_src-64a02b8056c86576428022859baadbb9a7b929f1.tar.bz2
Add version to list of required fields. This is required prep work for extension installation.
Review URL: http://codereview.chromium.org/17320 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7887 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension.cc14
-rw-r--r--chrome/browser/extensions/extension.h8
-rw-r--r--chrome/browser/extensions/extension_unittest.cc9
3 files changed, 30 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc
index 3c5dff0..d93cacd 100644
--- a/chrome/browser/extensions/extension.cc
+++ b/chrome/browser/extensions/extension.cc
@@ -15,11 +15,12 @@ const wchar_t* Extension::kIdKey = L"id";
const wchar_t* Extension::kNameKey = L"name";
const wchar_t* Extension::kDescriptionKey = L"description";
const wchar_t* Extension::kContentScriptsKey = L"content_scripts";
+const wchar_t* Extension::kVersionKey = L"version";
const char* Extension::kInvalidManifestError =
"Manifest is missing or invalid.";
const char* Extension::kInvalidFormatVersionError =
- "Required key 'format_version' is missing or invalid";
+ "Required key 'format_version' is missing or invalid.";
const char* Extension::kInvalidIdError =
"Required key 'id' is missing or invalid.";
const char* Extension::kInvalidNameError =
@@ -30,6 +31,8 @@ const char* Extension::kInvalidContentScriptsListError =
"Invalid type for 'content_scripts' key.";
const char* Extension::kInvalidContentScriptError =
"Invalid type for content_scripts at index ";
+const char* Extension::kInvalidVersionError =
+ "Required key 'version' is missing or invalid.";
bool Extension::InitFromValue(const DictionaryValue& source,
std::string* error) {
@@ -47,6 +50,12 @@ bool Extension::InitFromValue(const DictionaryValue& source,
return false;
}
+ // Initialize version.
+ if (!source.GetString(kVersionKey, &version_)) {
+ *error = kInvalidVersionError;
+ return false;
+ }
+
// Initialize name.
if (!source.GetString(kNameKey, &name_)) {
*error = kInvalidNameError;
@@ -95,6 +104,9 @@ void Extension::CopyToValue(DictionaryValue* destination) {
// Copy id.
destination->SetString(kIdKey, id_);
+ // Copy version.
+ destination->SetString(kVersionKey, version_);
+
// Copy name.
destination->SetString(kNameKey, name_);
diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h
index ac6c671..2b2f775 100644
--- a/chrome/browser/extensions/extension.h
+++ b/chrome/browser/extensions/extension.h
@@ -30,6 +30,7 @@ class Extension {
static const wchar_t* kNameKey;
static const wchar_t* kDescriptionKey;
static const wchar_t* kContentScriptsKey;
+ static const wchar_t* kVersionKey;
// Error messages returned from InitFromValue().
static const char* kInvalidFormatVersionError;
@@ -39,6 +40,7 @@ class Extension {
static const char* kInvalidDescriptionError;
static const char* kInvalidContentScriptsListError;
static const char* kInvalidContentScriptError;
+ static const char* kInvalidVersionError;
// The path to the folder the extension is stored in.
const FilePath& path() const { return path_; }
@@ -51,6 +53,9 @@ class Extension {
// previous version's update key.
const std::string& id() const { return id_; }
+ // The version number for the extension.
+ const std::string& version() const { return version_; }
+
// A human-readable name of the extension.
const std::string& name() const { return name_; }
@@ -75,6 +80,9 @@ class Extension {
// The extension's ID.
std::string id_;
+ // The extension's version.
+ std::string version_;
+
// The extension's human-readable name.
std::string name_;
diff --git a/chrome/browser/extensions/extension_unittest.cc b/chrome/browser/extensions/extension_unittest.cc
index 7aa51a0..71812b9 100644
--- a/chrome/browser/extensions/extension_unittest.cc
+++ b/chrome/browser/extensions/extension_unittest.cc
@@ -28,6 +28,14 @@ TEST(ExtensionTest, InitFromValueInvalid) {
EXPECT_EQ(Extension::kInvalidIdError, error);
input_value.SetString(Extension::kIdKey, L"com.google.myextension");
+ // Test missing and invalid versions
+ EXPECT_FALSE(extension.InitFromValue(input_value, &error));
+ EXPECT_EQ(Extension::kInvalidVersionError, error);
+ input_value.SetInteger(Extension::kVersionKey, 42);
+ EXPECT_FALSE(extension.InitFromValue(input_value, &error));
+ EXPECT_EQ(Extension::kInvalidVersionError, error);
+ input_value.SetString(Extension::kVersionKey, L"1.0");
+
// Test missing and invalid names
EXPECT_FALSE(extension.InitFromValue(input_value, &error));
EXPECT_EQ(Extension::kInvalidNameError, error);
@@ -64,6 +72,7 @@ TEST(ExtensionTest, InitFromValueValid) {
// Test minimal extension
input_value.SetInteger(Extension::kFormatVersionKey, 1);
input_value.SetString(Extension::kIdKey, L"com.google.myextension");
+ input_value.SetString(Extension::kVersionKey, L"1.0");
input_value.SetString(Extension::kNameKey, L"my extension");
EXPECT_TRUE(extension.InitFromValue(input_value, &error));