summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 03:41:22 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 03:41:22 +0000
commit1219891f3dc1531183969a157aeacbea7e296f2f (patch)
treec87ece76c1dc0c8e90a63d4ff165bef74da0955a /chrome
parent5c87288b5c019bb8bb728c5e213a38ec1917bab5 (diff)
downloadchromium_src-1219891f3dc1531183969a157aeacbea7e296f2f.zip
chromium_src-1219891f3dc1531183969a157aeacbea7e296f2f.tar.gz
chromium_src-1219891f3dc1531183969a157aeacbea7e296f2f.tar.bz2
Validate that extension resources exist.
BUG=11678 TEST=Make a theme with bad references to images and try to install it. Or just verify that the InstallTheme unit_test passes. Review URL: http://codereview.chromium.org/119137 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17708 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extensions_service.cc23
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc8
-rw-r--r--chrome/test/data/extensions/theme_missing_image.crxbin0 -> 68408 bytes
3 files changed, 28 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 16a7c1a..4d0f4f5 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -544,7 +544,28 @@ Extension* ExtensionsServiceBackend::LoadExtension(
else
extension->set_location(Extension::INTERNAL);
- // TODO(glen): Add theme resource validation here. http://crbug.com/11678
+ // Theme resource validation.
+ if (extension->IsTheme()) {
+ DictionaryValue* images_value = extension->GetThemeImages();
+ DictionaryValue::key_iterator iter = images_value->begin_keys();
+ while (iter != images_value->end_keys()) {
+ std::string val;
+ if (images_value->GetString(*iter, &val)) {
+ FilePath image_path = extension->path().AppendASCII(val);
+ if (!file_util::PathExists(image_path)) {
+ ReportExtensionLoadError(extension_path,
+ StringPrintf("Could not load '%s' for theme.",
+ WideToUTF8(image_path.ToWStringHack()).c_str()));
+ return NULL;
+ }
+ }
+ ++iter;
+ }
+
+ // Themes cannot contain other extension types.
+ return extension.release();
+ }
+
// Validate that claimed script resources actually exist.
for (size_t i = 0; i < extension->content_scripts().size(); ++i) {
const UserScript& script = extension->content_scripts()[i];
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index f6016ce..e59a627 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -153,14 +153,14 @@ class ExtensionsServiceTest
// Themes aren't loaded.
if (is_theme)
EXPECT_EQ(0u, loaded_.size()) << path.value();
- else
+ else
EXPECT_EQ(1u, loaded_.size()) << path.value();
EXPECT_EQ(0u, errors.size()) << path.value();
EXPECT_EQ(total_successes_, service_->extensions()->size()) <<
path.value();
if (loaded_.size() > 0) {
- EXPECT_TRUE(service_->GetExtensionByID(loaded_[0]->id())) <<
+ EXPECT_TRUE(service_->GetExtensionByID(loaded_[0]->id())) <<
path.value();
}
for (std::vector<std::string>::iterator err = errors.begin();
@@ -388,6 +388,10 @@ TEST_F(ExtensionsServiceTest, InstallTheme) {
// A theme with extension elements.
path = extensions_path.AppendASCII("theme_with_extension.crx");
TestInstallTheme(path, false);
+
+ // A theme with image resources missing (misspelt path).
+ path = extensions_path.AppendASCII("theme_missing_image.crx");
+ TestInstallTheme(path, false);
}
// Test that when an extension version is reinstalled, nothing happens.
diff --git a/chrome/test/data/extensions/theme_missing_image.crx b/chrome/test/data/extensions/theme_missing_image.crx
new file mode 100644
index 0000000..f8ee133d
--- /dev/null
+++ b/chrome/test/data/extensions/theme_missing_image.crx
Binary files differ