Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10623)

Unified Diff: chrome/common/extensions/extension_file_util.cc

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cocoa Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension_file_util.cc
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index 7b92b93bb6336ccf153094917e87e9113893edd7..4f1dbb6f0432b38b9c35233f2ea8e2ba8ccaa194 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.cc
@@ -35,6 +35,54 @@ using extensions::Extension;
namespace errors = extension_manifest_errors;
+namespace {
+
+bool ValidateExtensionIconSet(const ExtensionIconSet* icon_set,
+ const Extension* extension,
+ int error_message_id,
+ std::string* error) {
+ for (ExtensionIconSet::IconMap::const_iterator iter = icon_set->map().begin();
+ iter != icon_set->map().end();
+ ++iter) {
+ const FilePath path = extension->GetResource(iter->second).GetFilePath();
+ if (!extension_file_util::ValidateFilePath(path)) {
+ *error = l10n_util::GetStringFUTF8(error_message_id,
+ UTF8ToUTF16(iter->second));
+ return false;
+ }
+ }
+ return true;
+}
+
+bool ValidateExtensionActionIcons(const Extension* extension,
+ const ExtensionAction* action,
+ int error_message_id,
+ std::string* error) {
+ if (!action)
+ return true;
+
+ // Validate default icon set.
+ const ExtensionIconSet* default_icon = action->default_icon();
+ // Default icon may not be set.
+ if (default_icon &&
+ !ValidateExtensionIconSet(default_icon, extension, error_message_id,
+ error)) {
+ return false;
+ }
+
+ // Validate page action icons's icon sets.
+ const std::vector<const ExtensionIconSet*>& page_action_icons =
+ action->page_action_icons();
+ for (size_t icon = 0; icon < page_action_icons.size(); ++icon) {
+ const ExtensionIconSet* icon_set = page_action_icons[icon];
+ if (!ValidateExtensionIconSet(icon_set, extension, error_message_id, error))
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
namespace extension_file_util {
// Validates locale info. Doesn't check if messages.json files are valid.
@@ -320,40 +368,14 @@ bool ValidateExtension(const Extension* extension,
}
}
- // Validate icon location and icon file size for page actions.
- ExtensionAction* page_action = extension->page_action();
- if (page_action) {
- std::vector<std::string> icon_paths(*page_action->icon_paths());
- if (!page_action->default_icon_path().empty())
- icon_paths.push_back(page_action->default_icon_path());
- for (std::vector<std::string>::iterator iter = icon_paths.begin();
- iter != icon_paths.end(); ++iter) {
- const FilePath path = extension->GetResource(*iter).GetFilePath();
- if (!ValidateFilePath(path)) {
- *error =
- l10n_util::GetStringFUTF8(
- IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED,
- UTF8ToUTF16(*iter));
- return false;
- }
- }
+ if (!ValidateExtensionActionIcons(extension, extension->page_action(),
+ IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, error)) {
+ return false;
}
- // Validate icon location and icon file size for browser actions.
- // Note: browser actions don't use the icon_paths().
- ExtensionAction* browser_action = extension->browser_action();
- if (browser_action) {
- std::string path = browser_action->default_icon_path();
- if (!path.empty()) {
- const FilePath file_path = extension->GetResource(path).GetFilePath();
- if (!ValidateFilePath(file_path)) {
- *error =
- l10n_util::GetStringFUTF8(
- IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED,
- UTF8ToUTF16(path));
- return false;
- }
- }
+ if (!ValidateExtensionActionIcons(extension, extension->browser_action(),
+ IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) {
+ return false;
}
// Validate that background scripts exist.

Powered by Google App Engine
This is Rietveld 408576698