Chromium Code Reviews| Index: chrome/common/extensions/extension.cc |
| diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc |
| index 3ff9843eb462429db98bf39d2ac0b76ab7b43e92..38d0ecbc6187f3daf560f29ff734845fdeba27f3 100644 |
| --- a/chrome/common/extensions/extension.cc |
| +++ b/chrome/common/extensions/extension.cc |
| @@ -130,6 +130,40 @@ static void ConvertHexadecimalToIDAlphabet(std::string* id) { |
| } |
| } |
| +// Loads icon paths defined in dictionary |icons_value| into ExtensionIconSet |
| +// |icons|. |icons_value| is a dictionary value {icon size -> icon path}. Icons |
| +// in |icons_value| whose size is not in |icon_sizes| will be ignored. |
| +// Returns success. If load fails, |error| will be set. |
| +bool LoadIconsFromDictionary(const DictionaryValue* icons_value, |
| + const int* icon_sizes, |
| + size_t num_icon_sizes, |
| + ExtensionIconSet* icons, |
| + string16* error) { |
| + DCHECK(icons); |
| + for (size_t i = 0; i < num_icon_sizes; ++i) { |
| + std::string key = base::IntToString(icon_sizes[i]); |
| + if (icons_value->HasKey(key)) { |
| + std::string icon_path; |
| + if (!icons_value->GetString(key, &icon_path)) { |
| + *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| + errors::kInvalidIconPath, key); |
| + return false; |
| + } |
| + |
| + if (!icon_path.empty() && icon_path[0] == '/') |
| + icon_path = icon_path.substr(1); |
| + |
| + if (icon_path.empty()) { |
| + *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| + errors::kInvalidIconPath, key); |
| + return false; |
| + } |
| + icons->Add(icon_sizes[i], icon_path); |
| + } |
| + } |
| + return true; |
| +} |
| + |
| // A singleton object containing global data needed by the extension objects. |
| class ExtensionConfig { |
| public: |
| @@ -813,7 +847,9 @@ scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper( |
| return scoped_ptr<ExtensionAction>(); |
| } |
| - result->icon_paths()->push_back(path); |
| + scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
| + icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path); |
| + result->AddPageActionIcon(icon_set.Pass()); |
| } |
| } |
| @@ -827,16 +863,34 @@ scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper( |
| } |
| } |
| - std::string default_icon; |
| // Read the page action |default_icon| (optional). |
| + // The |default_icon| value can be either dictionary {icon size -> icon path} |
| + // or non empty string value. |
| if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { |
| - if (!extension_action->GetString(keys::kPageActionDefaultIcon, |
| - &default_icon) || |
| - default_icon.empty()) { |
| + const DictionaryValue* icons_value = NULL; |
| + std::string default_icon; |
| + if (extension_action->GetDictionary(keys::kPageActionDefaultIcon, |
| + &icons_value)) { |
| + scoped_ptr<ExtensionIconSet> default_icons(new ExtensionIconSet()); |
| + if (!LoadIconsFromDictionary(icons_value, |
| + extension_misc::kExtensionActionIconSizes, |
| + extension_misc::kNumExtensionActionIconSizes, |
| + default_icons.get(), |
| + error)) { |
| + return scoped_ptr<ExtensionAction>(); |
| + } |
| + |
| + result->set_default_icon(default_icons.Pass()); |
| + } else if (extension_action->GetString(keys::kPageActionDefaultIcon, |
| + &default_icon) && |
| + !default_icon.empty()) { |
| + scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
| + icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon); |
| + result->set_default_icon(icon_set.Pass()); |
| + } else { |
| *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
| return scoped_ptr<ExtensionAction>(); |
| } |
| - result->set_default_icon_path(default_icon); |
| } |
| // Read the page action title from |default_title| if present, |name| if not |
| @@ -1364,28 +1418,11 @@ bool Extension::LoadIcons(string16* error) { |
| return false; |
| } |
| - for (size_t i = 0; i < extension_misc::kNumExtensionIconSizes; ++i) { |
| - std::string key = base::IntToString(extension_misc::kExtensionIconSizes[i]); |
| - if (icons_value->HasKey(key)) { |
| - std::string icon_path; |
| - if (!icons_value->GetString(key, &icon_path)) { |
| - *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| - errors::kInvalidIconPath, key); |
| - return false; |
| - } |
| - |
| - if (!icon_path.empty() && icon_path[0] == '/') |
| - icon_path = icon_path.substr(1); |
| - |
| - if (icon_path.empty()) { |
| - *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| - errors::kInvalidIconPath, key); |
| - return false; |
| - } |
| - icons_.Add(extension_misc::kExtensionIconSizes[i], icon_path); |
| - } |
| - } |
| - return true; |
| + return LoadIconsFromDictionary(icons_value, |
| + extension_misc::kExtensionIconSizes, |
| + extension_misc::kNumExtensionIconSizes, |
| + &icons_, |
| + error); |
| } |
| bool Extension::LoadCommands(string16* error) { |
| @@ -2282,20 +2319,26 @@ bool Extension::LoadScriptBadge(string16* error) { |
| } |
| script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name()); |
| - if (!script_badge_->default_icon_path().empty()) { |
| + if (script_badge_->default_icon()) { |
| install_warnings_.push_back( |
| InstallWarning(InstallWarning::FORMAT_TEXT, |
| errors::kScriptBadgeIconIgnored)); |
| } |
| - std::string icon16_path = icons().Get(extension_misc::EXTENSION_ICON_BITTY, |
| - ExtensionIconSet::MATCH_EXACTLY); |
| - if (!icon16_path.empty()) { |
| - script_badge_->set_default_icon_path(icon16_path); |
| + |
| + scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
| + |
| + for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) { |
| + std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i], |
| + ExtensionIconSet::MATCH_EXACTLY); |
| + if (!path.empty()) { |
| + icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path); |
| + } |
| + } |
| + |
| + if (!icon_set->map().empty()) { |
| + script_badge_->set_default_icon(icon_set.Pass()); |
| } else { |
| - script_badge_->SetIcon( |
| - ExtensionAction::kDefaultTabId, |
| - ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| - IDR_EXTENSIONS_FAVICON)); |
| + script_badge_->set_default_icon(scoped_ptr<ExtensionIconSet>().Pass()); |
|
Jeffrey Yasskin
2012/09/13 00:23:36
You shouldn't need .Pass() on this line. Temporary
tbarzic
2012/09/13 02:01:01
Done.
|
| } |
| return true; |
| @@ -3115,19 +3158,29 @@ std::set<FilePath> Extension::GetBrowserImages() const { |
| // Page action icons. |
| if (page_action()) { |
| - std::vector<std::string>* icon_paths = page_action()->icon_paths(); |
| - for (std::vector<std::string>::iterator iter = icon_paths->begin(); |
| - iter != icon_paths->end(); ++iter) { |
| - image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); |
| + const std::vector<const ExtensionIconSet*>& page_action_icons = |
| + page_action()->page_action_icons(); |
| + for (size_t icon = 0; icon < page_action_icons.size(); icon++) { |
| + for (ExtensionIconSet::IconMap::const_iterator iter = |
| + page_action_icons[icon]->map().begin(); |
| + iter != page_action_icons[icon]->map().end(); |
| + ++iter) { |
| + image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| + } |
| } |
| } |
| // Browser action icons. |
| if (browser_action()) { |
| - std::vector<std::string>* icon_paths = browser_action()->icon_paths(); |
| - for (std::vector<std::string>::iterator iter = icon_paths->begin(); |
| - iter != icon_paths->end(); ++iter) { |
| - image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); |
| + const std::vector<const ExtensionIconSet*>& page_action_icons = |
| + browser_action()->page_action_icons(); |
| + for (size_t icon = 0; icon < page_action_icons.size(); icon++) { |
| + for (ExtensionIconSet::IconMap::const_iterator iter = |
| + page_action_icons[icon]->map().begin(); |
| + iter != page_action_icons[icon]->map().end(); |
| + ++iter) { |
| + image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| + } |
| } |
| } |