diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 21:57:00 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 21:57:00 +0000 |
commit | d7eaf5753249cbb6e95441b07e00a6349c7afe89 (patch) | |
tree | 7d03c6ce6a182a52465ad4d8f410117c2430a6bf /chrome/common | |
parent | 92ac30171a8334bc1691096abccf004ed02d0d42 (diff) | |
download | chromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.zip chromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.tar.gz chromium_src-d7eaf5753249cbb6e95441b07e00a6349c7afe89.tar.bz2 |
PageActions can now specify multiple icons and switch between them
using optional parameters to enableForTab.
BUG=http://crbug.com/11906
TEST=None
Review URL: http://codereview.chromium.org/149046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/extension.cc | 43 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 2 | ||||
-rw-r--r-- | chrome/common/page_action.h | 34 |
3 files changed, 63 insertions, 16 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 33baff8..6bce681 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -55,6 +55,7 @@ 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::kIconPathKey = L"icon"; +const wchar_t* Extension::kIconPathsKey = L"icons"; const wchar_t* Extension::kJsKey = L"js"; const wchar_t* Extension::kMatchesKey = L"matches"; const wchar_t* Extension::kNameKey = L"name"; @@ -126,10 +127,12 @@ const char* Extension::kInvalidNameError = "Required value 'name' is missing or invalid."; const char* Extension::kInvalidPageActionError = "Invalid value for 'page_actions[*]'."; +const char* Extension::kInvalidPageActionIconPathError = + "Invalid value for 'page_actions[*].icons[*]'."; const char* Extension::kInvalidPageActionsListError = "Invalid value for 'page_actions'."; -const char* Extension::kInvalidPageActionIconPathError = - "Invalid value for 'page_actions[*].icon'."; +const char* Extension::kInvalidPageActionIconPathsError = + "Required value 'page_actions[*].icons' is missing or invalid."; const char* Extension::kInvalidPageActionIdError = "Required value 'id' is missing or invalid."; const char* Extension::kInvalidPageActionTypeValueError = @@ -398,15 +401,31 @@ PageAction* Extension::LoadPageActionHelper( scoped_ptr<PageAction> result(new PageAction()); result->set_extension_id(id()); - // Read the page action |icon|. - std::string icon; - if (!page_action->GetString(kIconPathKey, &icon)) { + ListValue* icons; + // Read the page action |icons|. + if (!page_action->HasKey(kIconPathsKey) || + !page_action->GetList(kIconPathsKey, &icons) || + icons->GetSize() == 0) { *error = ExtensionErrorUtils::FormatErrorMessage( - kInvalidPageActionIconPathError, IntToString(definition_index)); + kInvalidPageActionIconPathsError, IntToString(definition_index)); return NULL; } - FilePath icon_path = path_.AppendASCII(icon); - result->set_icon_path(icon_path); + + int icon_count = 0; + for (ListValue::const_iterator iter = icons->begin(); + iter != icons->end(); ++iter) { + FilePath::StringType path; + if (!(*iter)->GetAsString(&path) || path.empty()) { + *error = ExtensionErrorUtils::FormatErrorMessage( + kInvalidPageActionIconPathError, + IntToString(definition_index), IntToString(icon_count)); + return NULL; + } + + FilePath icon_path = path_.Append(path); + result->AddIconPath(icon_path); + ++icon_count; + } // Read the page action |id|. std::string id; @@ -504,7 +523,7 @@ FilePath Extension::GetResourcePath(const FilePath& extension_path, return ret_val; } -Extension::Extension(const FilePath& path) { +Extension::Extension(const FilePath& path) : is_theme_(false) { DCHECK(path.IsAbsolute()); location_ = INVALID; @@ -939,7 +958,11 @@ std::set<FilePath> Extension::GetBrowserImages() { for (PageActionMap::const_iterator it = page_actions().begin(); it != page_actions().end(); ++it) { - image_paths.insert(it->second->icon_path()); + const std::vector<FilePath>& icon_paths = it->second->icon_paths(); + for (std::vector<FilePath>::const_iterator iter = icon_paths.begin(); + iter != icon_paths.end(); ++iter) { + image_paths.insert(*iter); + } } return image_paths; diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index ec14b0b..1705e12 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -60,6 +60,7 @@ class Extension { static const wchar_t* kCssKey; static const wchar_t* kDescriptionKey; static const wchar_t* kIconPathKey; + static const wchar_t* kIconPathsKey; static const wchar_t* kJsKey; static const wchar_t* kMatchesKey; static const wchar_t* kNameKey; @@ -115,6 +116,7 @@ class Extension { static const char* kInvalidPageActionError; static const char* kInvalidPageActionsListError; static const char* kInvalidPageActionIconPathError; + static const char* kInvalidPageActionIconPathsError; static const char* kInvalidPageActionIdError; static const char* kInvalidPageActionTypeValueError; static const char* kInvalidPermissionsError; diff --git a/chrome/common/page_action.h b/chrome/common/page_action.h index d9ccfea..3331f8e 100644 --- a/chrome/common/page_action.h +++ b/chrome/common/page_action.h @@ -5,8 +5,9 @@ #ifndef CHROME_COMMON_PAGE_ACTION_H_ #define CHROME_COMMON_PAGE_ACTION_H_ -#include <string> #include <map> +#include <string> +#include <vector> #include "base/file_path.h" @@ -34,9 +35,9 @@ class PageAction { std::string name() const { return name_; } void set_name(const std::string& name) { name_ = name; } - FilePath icon_path() const { return icon_path_; } - void set_icon_path(const FilePath& icon_path) { - icon_path_ = icon_path; + const std::vector<FilePath>& icon_paths() const { return icon_paths_; } + void AddIconPath(const FilePath& icon_path) { + icon_paths_.push_back(icon_path); } private: @@ -53,10 +54,31 @@ class PageAction { // The name of the PageAction. std::string name_; - // The icon that represents the PageIcon. - FilePath icon_path_; + // The paths to the icons that this PageIcon can show. + std::vector<FilePath> icon_paths_; }; typedef std::map<std::string, PageAction*> PageActionMap; +// This class keeps track of what values each tab uses to override the default +// values of the PageAction. +class PageActionState { + public: + PageActionState(std::string title, int icon_index) + : title_(title), icon_index_(icon_index) { + } + + std::string title() const { return title_; } + int icon_index() const { return icon_index_; } + + private: + // The title to use. + std::string title_; + + // The icon to use. + int icon_index_; + + DISALLOW_COPY_AND_ASSIGN(PageActionState); +}; + #endif // CHROME_COMMON_PAGE_ACTION_H_ |