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/browser/extensions | |
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/browser/extensions')
5 files changed, 32 insertions, 9 deletions
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index 66bd9e3..d3ba09a 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -31,6 +31,18 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { std::string url; EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url)); + std::string title; + int icon_id = 0; + if (enable) { + // Both of those are optional. + if (action->HasKey(keys::kTitleKey)) + EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kTitleKey, &title)); + if (action->HasKey(keys::kIconIdKey)) { + EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kIconIdKey, + &icon_id)); + } + } + // Find the TabContents that contains this tab id. TabContents* contents = NULL; ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL); @@ -66,7 +78,7 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { } // Set visibility and broadcast notifications that the UI should be updated. - contents->SetPageActionEnabled(page_action, enable); + contents->SetPageActionEnabled(page_action, enable, title, icon_id); contents->NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); return true; diff --git a/chrome/browser/extensions/extension_page_actions_module_constants.cc b/chrome/browser/extensions/extension_page_actions_module_constants.cc index e58264b..2b54f1b 100755 --- a/chrome/browser/extensions/extension_page_actions_module_constants.cc +++ b/chrome/browser/extensions/extension_page_actions_module_constants.cc @@ -8,6 +8,8 @@ namespace extension_page_actions_module_constants { const wchar_t kTabIdKey[] = L"tabId"; const wchar_t kUrlKey[] = L"url"; +const wchar_t kTitleKey[] = L"title"; +const wchar_t kIconIdKey[] = L"iconId"; const char kNoExtensionError[] = "No extension with id: *."; const char kNoTabError[] = "No tab with id: *."; diff --git a/chrome/browser/extensions/extension_page_actions_module_constants.h b/chrome/browser/extensions/extension_page_actions_module_constants.h index bf28b9f..91db0d8 100755 --- a/chrome/browser/extensions/extension_page_actions_module_constants.h +++ b/chrome/browser/extensions/extension_page_actions_module_constants.h @@ -12,6 +12,8 @@ namespace extension_page_actions_module_constants { // Keys. extern const wchar_t kTabIdKey[]; extern const wchar_t kUrlKey[]; +extern const wchar_t kTitleKey[]; +extern const wchar_t kIconIdKey[]; // Error messages. extern const char kNoExtensionError[]; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index df59e04..b44c630 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -753,12 +753,16 @@ Extension* ExtensionsServiceBackend::LoadExtension( for (PageActionMap::const_iterator i(page_actions.begin()); i != page_actions.end(); ++i) { PageAction* page_action = i->second; - FilePath path = page_action->icon_path(); - if (!file_util::PathExists(path)) { - ReportExtensionLoadError(extension_path, - StringPrintf("Could not load icon '%s' for page action.", - WideToUTF8(path.ToWStringHack()).c_str())); - return NULL; + const std::vector<FilePath>& icon_paths = page_action->icon_paths(); + for (std::vector<FilePath>::const_iterator iter = icon_paths.begin(); + iter != icon_paths.end(); ++iter) { + FilePath path = *iter; + if (!file_util::PathExists(path)) { + ReportExtensionLoadError(extension_path, + StringPrintf("Could not load icon '%s' for page action.", + WideToUTF8(path.ToWStringHack()).c_str())); + return NULL; + } } } diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index b195151..3b75dcc 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -40,7 +40,7 @@ const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; -const char* const page_action = "kemkhnabegjkabakmlcaafgikalipenj"; +const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; @@ -654,7 +654,9 @@ TEST_F(ExtensionsServiceTest, CleanupOnStartup) { ASSERT_FALSE(file_util::PathExists(vers)); } -// Test installing extensions. +// Test installing extensions. This test tries to install few extensions using +// crx files. If you need to change those crx files, feel free to repackage +// them, throw away the key used and change the id's above. TEST_F(ExtensionsServiceTest, InstallExtension) { InitializeEmptyExtensionsService(); @@ -690,6 +692,7 @@ TEST_F(ExtensionsServiceTest, InstallExtension) { // Bad signature. path = extensions_path.AppendASCII("bad_signature.crx"); InstallExtension(path, false); + ValidatePrefKeyCount(pref_count); // 0-length extension file. path = extensions_path.AppendASCII("not_an_extension.crx"); |