diff options
author | mtytel@chromium.org <mtytel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 01:34:15 +0000 |
---|---|---|
committer | mtytel@chromium.org <mtytel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-24 01:34:15 +0000 |
commit | e3c0bc2ff182bfe27448b3ad590e91f6f9626f1c (patch) | |
tree | 06f394bc5aea2c911d2c44cb1a31dd1cec2c23f1 | |
parent | bc95a82163a28b9bf5b17685321a9bf8d6b55113 (diff) | |
download | chromium_src-e3c0bc2ff182bfe27448b3ad590e91f6f9626f1c.zip chromium_src-e3c0bc2ff182bfe27448b3ad590e91f6f9626f1c.tar.gz chromium_src-e3c0bc2ff182bfe27448b3ad590e91f6f9626f1c.tar.bz2 |
Support for 512px and 256px icons in extensions
BUG=63406
TEST=Install an extension with only a 256x256 or 512x512 icon
Review URL: http://codereview.chromium.org/9025034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123391 0039d316-1c4b-4281-b951-d872f2087c98
32 files changed, 284 insertions, 153 deletions
diff --git a/chrome/browser/background/background_application_list_model.cc b/chrome/browser/background/background_application_list_model.cc index d7d4740..cc05fc5 100644 --- a/chrome/browser/background/background_application_list_model.cc +++ b/chrome/browser/background/background_application_list_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,6 +18,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_resource.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" @@ -60,7 +61,7 @@ class BackgroundApplicationListModel::Application // Uses the FILE thread to request this extension's icon, sized // appropriately. - void RequestIcon(Extension::Icons size); + void RequestIcon(ExtensionIconSet::Icons size); const Extension* extension_; scoped_ptr<SkBitmap> icon_; @@ -138,7 +139,7 @@ void BackgroundApplicationListModel::Application::OnImageLoaded( } void BackgroundApplicationListModel::Application::RequestIcon( - Extension::Icons size) { + ExtensionIconSet::Icons size) { ExtensionResource resource = extension_->GetIconResource( size, ExtensionIconSet::MATCH_BIGGER); tracker_.LoadImage(extension_, resource, gfx::Size(size, size), @@ -189,7 +190,7 @@ void BackgroundApplicationListModel::AssociateApplicationData( application = new Application(this, extension); applications_[extension->id()] = application; Update(); - application->RequestIcon(Extension::EXTENSION_ICON_BITTY); + application->RequestIcon(ExtensionIconSet::EXTENSION_ICON_BITTY); } } diff --git a/chrome/browser/background/background_application_list_model.h b/chrome/browser/background/background_application_list_model.h index 44248c8..8e7b798 100644 --- a/chrome/browser/background/background_application_list_model.h +++ b/chrome/browser/background/background_application_list_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -55,7 +55,8 @@ class BackgroundApplicationListModel : public content::NotificationObserver { // // NOTE: The model manages the SkBitmap result, that is it "owns" the memory, // releasing it if the associated background application is unloaded. - // NOTE: All icons are currently sized as Extension::EXTENSION_ICON_BITTY. + // NOTE: All icons are currently sized as + // ExtensionIconSet::EXTENSION_ICON_BITTY. const SkBitmap* GetIcon(const Extension* extension); // Return the position of |extension| within this list model. diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc index b90d52c..39969c3 100644 --- a/chrome/browser/background/background_contents_service.cc +++ b/chrome/browser/background/background_contents_service.cc @@ -26,6 +26,7 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_service.h" @@ -105,7 +106,7 @@ void ShowBalloon(const Extension* extension, Profile* profile) { IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, UTF8ToUTF16(extension->name())); string16 content_url = DesktopNotificationService::CreateDataUrl( - extension->GetIconURL(Extension::EXTENSION_ICON_SMALLISH, + extension->GetIconURL(ExtensionIconSet::EXTENSION_ICON_SMALLISH, ExtensionIconSet::MATCH_BIGGER), string16(), message, WebKit::WebTextDirectionDefault); Notification notification( diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc index 4c6be59..e7bce3b 100644 --- a/chrome/browser/chromeos/offline/offline_load_page.cc +++ b/chrome/browser/chromeos/offline/offline_load_page.cc @@ -20,6 +20,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" @@ -140,8 +141,8 @@ void OfflineLoadPage::GetAppOfflineStrings( DictionaryValue* strings) const { strings->SetString("title", app->name()); - GURL icon_url = app->GetIconURL(Extension::EXTENSION_ICON_LARGE, - ExtensionIconSet::MATCH_EXACTLY); + GURL icon_url = app->GetIconURL(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER); if (icon_url.is_empty()) { strings->SetString("display_icon", "none"); strings->SetString("icon", string16()); diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 4b923e9..a3edce8 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -25,6 +25,7 @@ #include "chrome/browser/extensions/convert_web_app.h" #include "chrome/browser/extensions/default_apps_trial.h" #include "chrome/browser/extensions/extension_error_reporter.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/permissions_updater.h" #include "chrome/browser/shell_integration.h" @@ -361,7 +362,9 @@ void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir, } if (client_) { - Extension::DecodeIcon(extension_.get(), Extension::EXTENSION_ICON_LARGE, + Extension::DecodeIcon(extension_.get(), + ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER, &install_icon_); } diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc index 1f77679..aaf7aab 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.cc +++ b/chrome/browser/extensions/extension_file_browser_private_api.cc @@ -30,6 +30,7 @@ #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/file_browser_handler.h" #include "chrome/common/pref_names.h" #include "content/browser/renderer_host/render_view_host.h" @@ -678,7 +679,7 @@ bool GetFileTasksFileBrowserFunction::RunImpl() { // manifest instead of the default extension icon. GURL icon = ExtensionIconSource::GetIconURL(extension, - Extension::EXTENSION_ICON_BITTY, + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER, false, NULL); // grayscale task->SetString("iconUrl", icon.spec()); diff --git a/chrome/browser/extensions/extension_icon_manager.cc b/chrome/browser/extensions/extension_icon_manager.cc index 8e3e396..298ab22 100644 --- a/chrome/browser/extensions/extension_icon_manager.cc +++ b/chrome/browser/extensions/extension_icon_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -48,7 +48,7 @@ ExtensionIconManager::~ExtensionIconManager() { void ExtensionIconManager::LoadIcon(const Extension* extension) { ExtensionResource icon_resource = extension->GetIconResource( - Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER); + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER); if (!icon_resource.extension_root().empty()) { // Insert into pending_icons_ first because LoadImage can call us back // synchronously if the image is already cached. diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 1ae8529..268a239 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -416,8 +416,8 @@ void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { // Load the image asynchronously. For the response, check OnImageLoaded. prompt_type_ = prompt_type; ExtensionResource image = - extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, - ExtensionIconSet::MATCH_EXACTLY); + extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER); tracker_.LoadImage(extension_, image, gfx::Size(kIconSize, kIconSize), ImageLoadingTracker::DONT_CACHE); diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc index 7233585..7d50a04 100644 --- a/chrome/browser/extensions/extension_management_api.cc +++ b/chrome/browser/extensions/extension_management_api.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -81,10 +81,10 @@ static DictionaryValue* CreateExtensionInfo(const Extension& extension, const ExtensionIconSet::IconMap& icons = extension.icons().map(); if (!icons.empty()) { ListValue* icon_list = new ListValue(); - std::map<int, std::string>::const_iterator icon_iter; + std::map<ExtensionIconSet::Icons, std::string>::const_iterator icon_iter; for (icon_iter = icons.begin(); icon_iter != icons.end(); ++icon_iter) { DictionaryValue* icon_info = new DictionaryValue(); - Extension::Icons size = static_cast<Extension::Icons>(icon_iter->first); + ExtensionIconSet::Icons size = icon_iter->first; GURL url = ExtensionIconSource::GetIconURL( &extension, size, ExtensionIconSet::MATCH_EXACTLY, false, NULL); icon_info->SetInteger(keys::kSizeKey, icon_iter->first); diff --git a/chrome/browser/extensions/extension_tab_helper.cc b/chrome/browser/extensions/extension_tab_helper.cc index 1b4b4a4..6ec0221 100644 --- a/chrome/browser/extensions/extension_tab_helper.cc +++ b/chrome/browser/extensions/extension_tab_helper.cc @@ -241,10 +241,10 @@ void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { extension_app_image_loader_.reset(new ImageLoadingTracker(this)); extension_app_image_loader_->LoadImage( extension, - extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, + extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, ExtensionIconSet::MATCH_EXACTLY), - gfx::Size(Extension::EXTENSION_ICON_SMALLISH, - Extension::EXTENSION_ICON_SMALLISH), + gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, + ExtensionIconSet::EXTENSION_ICON_SMALLISH), ImageLoadingTracker::CACHE); } else { extension_app_image_loader_.reset(NULL); diff --git a/chrome/browser/extensions/extension_uninstall_dialog.cc b/chrome/browser/extensions/extension_uninstall_dialog.cc index d5bed37..d3044d7 100644 --- a/chrome/browser/extensions/extension_uninstall_dialog.cc +++ b/chrome/browser/extensions/extension_uninstall_dialog.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -33,8 +33,8 @@ void ExtensionUninstallDialog::ConfirmUninstall(const Extension* extension) { extension_ = extension; ExtensionResource image = - extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, - ExtensionIconSet::MATCH_EXACTLY); + extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER); // Load the image asynchronously. The response will be sent to OnImageLoaded. tracker_.LoadImage(extension_, image, gfx::Size(kIconSize, kIconSize), diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index c74c433..a1f48b2 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -77,7 +77,7 @@ class ExtensionWebUIImageLoadingTracker : public ImageLoadingTracker::Observer { void Init() { if (extension_) { ExtensionResource icon_resource = - extension_->GetIconResource(Extension::EXTENSION_ICON_BITTY, + extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); tracker_.LoadImage(extension_, icon_resource, diff --git a/chrome/browser/extensions/image_loading_tracker_unittest.cc b/chrome/browser/extensions/image_loading_tracker_unittest.cc index 5bdb118..820bde0 100644 --- a/chrome/browser/extensions/image_loading_tracker_unittest.cc +++ b/chrome/browser/extensions/image_loading_tracker_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -102,10 +102,10 @@ TEST_F(ImageLoadingTrackerTest, Cache) { ASSERT_TRUE(extension.get() != NULL); ExtensionResource image_resource = - extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, + extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, ExtensionIconSet::MATCH_EXACTLY); - gfx::Size max_size(Extension::EXTENSION_ICON_SMALLISH, - Extension::EXTENSION_ICON_SMALLISH); + gfx::Size max_size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, + ExtensionIconSet::EXTENSION_ICON_SMALLISH); ImageLoadingTracker loader(static_cast<ImageLoadingTracker::Observer*>(this)); loader.LoadImage(extension.get(), image_resource, @@ -121,13 +121,13 @@ TEST_F(ImageLoadingTrackerTest, Cache) { EXPECT_EQ(1, image_loaded_count()); // Check that the image was loaded. - EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, image_.width()); // The image should be cached in the Extension. EXPECT_TRUE(extension->HasCachedImage(image_resource, max_size)); // Make sure the image is in the extension. - EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, extension->GetCachedImage(image_resource, max_size).width()); // Ask the tracker for the image again, this should call us back immediately. @@ -139,7 +139,7 @@ TEST_F(ImageLoadingTrackerTest, Cache) { EXPECT_EQ(1, image_loaded_count()); // Check that the image was loaded. - EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, image_.width()); } // Tests deleting an extension while waiting for the image to load doesn't cause @@ -149,13 +149,13 @@ TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) { ASSERT_TRUE(extension.get() != NULL); ExtensionResource image_resource = - extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, + extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, ExtensionIconSet::MATCH_EXACTLY); ImageLoadingTracker loader(static_cast<ImageLoadingTracker::Observer*>(this)); loader.LoadImage(extension.get(), image_resource, - gfx::Size(Extension::EXTENSION_ICON_SMALLISH, - Extension::EXTENSION_ICON_SMALLISH), + gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, + ExtensionIconSet::EXTENSION_ICON_SMALLISH), ImageLoadingTracker::CACHE); // The image isn't cached, so we should not have received notification. @@ -180,5 +180,5 @@ TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) { EXPECT_EQ(1, image_loaded_count()); // Check that the image was loaded. - EXPECT_EQ(Extension::EXTENSION_ICON_SMALLISH, image_.width()); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, image_.width()); } diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm index a3d40a5..f3353ec 100644 --- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm @@ -69,12 +69,13 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver, // Load the Extension's icon image. void LoadIcon() { const Extension* extension = delegate_->extension_host()->extension(); - ExtensionResource icon_resource = extension->GetIconResource( - Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); + ExtensionResource icon_resource = + extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_BITTY, + ExtensionIconSet::MATCH_EXACTLY); if (!icon_resource.relative_path().empty()) { tracker_.LoadImage(extension, icon_resource, - gfx::Size(Extension::EXTENSION_ICON_BITTY, - Extension::EXTENSION_ICON_BITTY), + gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, + ExtensionIconSet::EXTENSION_ICON_BITTY), ImageLoadingTracker::DONT_CACHE); } else { OnImageLoaded(NULL, icon_resource, 0); @@ -100,7 +101,7 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver, SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); - const int image_size = Extension::EXTENSION_ICON_BITTY; + const int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; scoped_ptr<gfx::CanvasSkia> canvas( new gfx::CanvasSkia( gfx::Size(image_size + kDropArrowLeftMarginPx + drop_image->width(), diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc index d405107..4251b18 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc @@ -77,7 +77,7 @@ void ExtensionInfoBarGtk::OnImageLoaded( SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); - int image_size = Extension::EXTENSION_ICON_BITTY; + int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; // The margin between the extension icon and the drop-down arrow bitmap. static const int kDropArrowLeftMargin = 3; scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia( @@ -109,12 +109,12 @@ void ExtensionInfoBarGtk::BuildWidgets() { // Start loading the image for the menu button. const Extension* extension = delegate_->extension_host()->extension(); ExtensionResource icon_resource = extension->GetIconResource( - Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); if (!icon_resource.relative_path().empty()) { // Create a tracker to load the image. It will report back on OnImageLoaded. tracker_.LoadImage(extension, icon_resource, - gfx::Size(Extension::EXTENSION_ICON_BITTY, - Extension::EXTENSION_ICON_BITTY), + gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, + ExtensionIconSet::EXTENSION_ICON_BITTY), ImageLoadingTracker::DONT_CACHE); } else { OnImageLoaded(NULL, icon_resource, 0); diff --git a/chrome/browser/ui/views/aura/app_list/extension_app_item.cc b/chrome/browser/ui/views/aura/app_list/extension_app_item.cc index a93ad1b..3abb60a 100644 --- a/chrome/browser/ui/views/aura/app_list/extension_app_item.cc +++ b/chrome/browser/ui/views/aura/app_list/extension_app_item.cc @@ -86,8 +86,7 @@ const Extension* ExtensionAppItem::GetExtension() const { void ExtensionAppItem::LoadImage(const Extension* extension) { ExtensionResource icon = extension->GetIconResource( - ash::AppListItemView::kIconSize, - ExtensionIconSet::MATCH_BIGGER); + ash::AppListItemView::kIconSize, ExtensionIconSet::MATCH_BIGGER); if (icon.relative_path().empty()) { LoadDefaultImage(); return; diff --git a/chrome/browser/ui/views/aura/launcher/launcher_icon_loader.cc b/chrome/browser/ui/views/aura/launcher/launcher_icon_loader.cc index 1d7020c..0d82d21 100644 --- a/chrome/browser/ui/views/aura/launcher/launcher_icon_loader.cc +++ b/chrome/browser/ui/views/aura/launcher/launcher_icon_loader.cc @@ -44,10 +44,10 @@ void LauncherIconLoader::FetchImage(const std::string& id) { map_[image_loader_->next_id()] = id; image_loader_->LoadImage( extension, - extension->GetIconResource(Extension::EXTENSION_ICON_SMALL, + extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL, ExtensionIconSet::MATCH_BIGGER), - gfx::Size(Extension::EXTENSION_ICON_SMALL, - Extension::EXTENSION_ICON_SMALL), + gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL, + ExtensionIconSet::EXTENSION_ICON_SMALL), ImageLoadingTracker::CACHE); } diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index 343bbd1..db272a9 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -90,7 +90,7 @@ void ExtensionInfoBar::ViewHierarchyChanged(bool is_add, // which assumes that particular children (e.g. the close button) have already // been added. const Extension* extension = extension_host->extension(); - int image_size = Extension::EXTENSION_ICON_BITTY; + ExtensionIconSet::Icons image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; ExtensionResource icon_resource = extension->GetIconResource( image_size, ExtensionIconSet::MATCH_EXACTLY); if (!icon_resource.relative_path().empty()) { @@ -119,7 +119,7 @@ void ExtensionInfoBar::OnImageLoaded(SkBitmap* image, SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); - int image_size = Extension::EXTENSION_ICON_BITTY; + int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; // The margin between the extension icon and the drop-down arrow bitmap. static const int kDropArrowLeftMargin = 3; scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia( diff --git a/chrome/browser/ui/webui/extensions/extension_activity_ui.cc b/chrome/browser/ui/webui/extensions/extension_activity_ui.cc index dbcb6fa..1b8c517 100644 --- a/chrome/browser/ui/webui/extensions/extension_activity_ui.cc +++ b/chrome/browser/ui/webui/extensions/extension_activity_ui.cc @@ -69,7 +69,7 @@ void ExtensionActivityUI::HandleRequestExtensionData( GURL icon = ExtensionIconSource::GetIconURL(extension_, - Extension::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::EXTENSION_ICON_MEDIUM, ExtensionIconSet::MATCH_BIGGER, false, NULL); diff --git a/chrome/browser/ui/webui/extensions/extension_icon_source.cc b/chrome/browser/ui/webui/extensions/extension_icon_source.cc index 802dbe8..0aa3066 100644 --- a/chrome/browser/ui/webui/extensions/extension_icon_source.cc +++ b/chrome/browser/ui/webui/extensions/extension_icon_source.cc @@ -62,7 +62,7 @@ struct ExtensionIconSource::ExtensionIconRequest { int request_id; const Extension* extension; bool grayscale; - Extension::Icons size; + int size; ExtensionIconSet::MatchType match; }; @@ -73,7 +73,7 @@ ExtensionIconSource::~ExtensionIconSource() { // static GURL ExtensionIconSource::GetIconURL(const Extension* extension, - Extension::Icons icon_size, + int icon_size, ExtensionIconSet::MatchType match, bool grayscale, bool* exists) { @@ -139,7 +139,7 @@ void ExtensionIconSource::LoadIconFailed(int request_id) { ExtensionResource icon = request->extension->GetIconResource(request->size, request->match); - if (request->size == Extension::EXTENSION_ICON_BITTY) + if (request->size == ExtensionIconSet::EXTENSION_ICON_BITTY) LoadFaviconImage(request_id); else LoadDefaultImage(request_id); @@ -300,14 +300,9 @@ bool ExtensionIconSource::ParseData(const std::string& path, std::string match_param = path_parts.at(2); match_param = match_param.substr(0, match_param.find('?')); - // The icon size and match types are encoded as string representations of - // their enum values, so to get the enum back, we read the string as an int - // and then cast to the enum. - Extension::Icons size; - int size_num; - if (!base::StringToInt(size_param, &size_num)) + int size; + if (!base::StringToInt(size_param, &size)) return false; - size = static_cast<Extension::Icons>(size_num); if (size <= 0) return false; @@ -344,7 +339,7 @@ void ExtensionIconSource::SendDefaultResponse(int request_id) { void ExtensionIconSource::SetData(int request_id, const Extension* extension, bool grayscale, - Extension::Icons size, + int size, ExtensionIconSet::MatchType match) { ExtensionIconRequest* request = new ExtensionIconRequest(); request->request_id = request_id; diff --git a/chrome/browser/ui/webui/extensions/extension_icon_source.h b/chrome/browser/ui/webui/extensions/extension_icon_source.h index c17c018..d790748c 100644 --- a/chrome/browser/ui/webui/extensions/extension_icon_source.h +++ b/chrome/browser/ui/webui/extensions/extension_icon_source.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,7 +13,7 @@ #include "chrome/browser/extensions/image_loading_tracker.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" -#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "third_party/skia/include/core/SkBitmap.h" class ExtensionIconSet; @@ -51,13 +51,13 @@ class ExtensionIconSource : public ChromeURLDataManager::DataSource, explicit ExtensionIconSource(Profile* profile); virtual ~ExtensionIconSource(); - // Gets the URL of the |extension| icon in the given |size|, falling back + // Gets the URL of the |extension| icon in the given |icon_size|, falling back // based on the |match| type. If |grayscale|, the URL will be for the // desaturated version of the icon. |exists|, if non-NULL, will be set to true // if the icon exists; false if it will lead to a default or not-present // image. static GURL GetIconURL(const Extension* extension, - Extension::Icons icon_size, + int icon_size, ExtensionIconSet::MatchType match, bool grayscale, bool* exists); @@ -138,7 +138,7 @@ class ExtensionIconSource : public ChromeURLDataManager::DataSource, void SetData(int request_id, const Extension* extension, bool grayscale, - Extension::Icons size, + int size, ExtensionIconSet::MatchType match); // Returns the ExtensionIconRequest for the given |request_id|. diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 3c0513d..2b98929 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -108,13 +108,13 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension, // Instead of setting grayscale here, we do it in apps_page.js. GURL icon_big = ExtensionIconSource::GetIconURL(extension, - Extension::EXTENSION_ICON_LARGE, - ExtensionIconSet::MATCH_EXACTLY, + ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER, false, &icon_big_exists); bool icon_small_exists = true; GURL icon_small = ExtensionIconSource::GetIconURL(extension, - Extension::EXTENSION_ICON_BITTY, + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER, false, &icon_small_exists); diff --git a/chrome/browser/ui/webui/options/extension_settings_handler.cc b/chrome/browser/ui/webui/options/extension_settings_handler.cc index a23106f..128afb9 100644 --- a/chrome/browser/ui/webui/options/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/options/extension_settings_handler.cc @@ -29,6 +29,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_view_type.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" @@ -653,7 +654,7 @@ DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( DictionaryValue* extension_data = new DictionaryValue(); GURL icon = ExtensionIconSource::GetIconURL(extension, - Extension::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::EXTENSION_ICON_MEDIUM, ExtensionIconSet::MATCH_BIGGER, !enabled, NULL); extension_data->SetString("id", extension->id()); diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index af01d31..3ea6fc2 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -191,14 +191,6 @@ const size_t Extension::kIdSize = 16; const char Extension::kMimeType[] = "application/x-chrome-extension"; -const int Extension::kIconSizes[] = { - EXTENSION_ICON_LARGE, - EXTENSION_ICON_MEDIUM, - EXTENSION_ICON_SMALL, - EXTENSION_ICON_SMALLISH, - EXTENSION_ICON_BITTY -}; - const int Extension::kPageActionIconMaxSize = 19; const int Extension::kBrowserActionIconMaxSize = 19; @@ -1536,16 +1528,25 @@ bool Extension::FormatPEMForFileOutput(const std::string& input, // static void Extension::DecodeIcon(const Extension* extension, - Icons icon_size, + ExtensionIconSet::Icons preferred_icon_size, + ExtensionIconSet::MatchType match_type, + scoped_ptr<SkBitmap>* result) { + std::string path = extension->icons().Get(preferred_icon_size, match_type); + ExtensionIconSet::Icons size = extension->icons().GetIconSizeFromPath(path); + ExtensionResource icon_resource = extension->GetResource(path); + DecodeIconFromPath(icon_resource.GetFilePath(), size, result); +} + +// static +void Extension::DecodeIcon(const Extension* extension, + ExtensionIconSet::Icons icon_size, scoped_ptr<SkBitmap>* result) { - FilePath icon_path = extension->GetIconResource( - icon_size, ExtensionIconSet::MATCH_EXACTLY).GetFilePath(); - DecodeIconFromPath(icon_path, icon_size, result); + DecodeIcon(extension, icon_size, ExtensionIconSet::MATCH_EXACTLY, result); } // static void Extension::DecodeIconFromPath(const FilePath& icon_path, - Icons icon_size, + ExtensionIconSet::Icons icon_size, scoped_ptr<SkBitmap>* result) { if (icon_path.empty()) return; @@ -1850,8 +1851,8 @@ bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, return false; } - for (size_t i = 0; i < arraysize(kIconSizes); ++i) { - std::string key = base::IntToString(kIconSizes[i]); + for (size_t i = 0; i < ExtensionIconSet::kNumIconSizes; ++i) { + std::string key = base::IntToString(ExtensionIconSet::kIconSizes[i]); if (icons_value->HasKey(key)) { std::string icon_path; if (!icons_value->GetString(key, &icon_path)) { @@ -1869,7 +1870,7 @@ bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, return false; } - icons_.Add(kIconSizes[i], icon_path); + icons_.Add(ExtensionIconSet::kIconSizes[i], icon_path); } } } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 0ecfdf8..234407c 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -90,16 +90,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> { NEW_INSTALL }; - // NOTE: If you change this list, you should also change kIconSizes in the cc - // file. - enum Icons { - EXTENSION_ICON_LARGE = 128, - EXTENSION_ICON_MEDIUM = 48, - EXTENSION_ICON_SMALL = 32, - EXTENSION_ICON_SMALLISH = 24, - EXTENSION_ICON_BITTY = 16, - }; - // Do not change the order of entries or remove entries in this list // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. enum Type { @@ -248,9 +238,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // its install source should be set to GetHigherPriorityLocation(A, B). static Location GetHigherPriorityLocation(Location loc1, Location loc2); - // Icon sizes used by the extension system. - static const int kIconSizes[]; - // Max size (both dimensions) for browser and page actions. static const int kPageActionIconMaxSize; static const int kBrowserActionIconMaxSize; @@ -377,12 +364,21 @@ class Extension : public base::RefCountedThreadSafe<Extension> { std::string* output, bool is_public); + // Given an extension, icon size and match type, read a valid icon if present + // and decode it into result. In the browser process, this will DCHECK if not + // called on the file thread. To easily load extension images on the UI + // thread, see ImageLoadingTracker. + static void DecodeIcon(const Extension* extension, + ExtensionIconSet::Icons icon_size, + ExtensionIconSet::MatchType match_type, + scoped_ptr<SkBitmap>* result); + // Given an extension and icon size, read it if present and decode it into // result. In the browser process, this will DCHECK if not called on the // file thread. To easily load extension images on the UI thread, see // ImageLoadingTracker. static void DecodeIcon(const Extension* extension, - Icons icon_size, + ExtensionIconSet::Icons icon_size, scoped_ptr<SkBitmap>* result); // Given an icon_path and icon size, read it if present and decode it into @@ -390,7 +386,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // file thread. To easily load extension images on the UI thread, see // ImageLoadingTracker. static void DecodeIconFromPath(const FilePath& icon_path, - Icons icon_size, + ExtensionIconSet::Icons icon_size, scoped_ptr<SkBitmap>* result); // Returns the default extension/app icon (for extensions or apps that don't diff --git a/chrome/common/extensions/extension_icon_set.cc b/chrome/common/extensions/extension_icon_set.cc index 590abb0..588d0546 100644 --- a/chrome/common/extensions/extension_icon_set.cc +++ b/chrome/common/extensions/extension_icon_set.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,11 +10,24 @@ ExtensionIconSet::ExtensionIconSet() {} ExtensionIconSet::~ExtensionIconSet() {} +const ExtensionIconSet::Icons ExtensionIconSet::kIconSizes[] = { + EXTENSION_ICON_GIGANTOR, + EXTENSION_ICON_EXTRA_LARGE, + EXTENSION_ICON_LARGE, + EXTENSION_ICON_MEDIUM, + EXTENSION_ICON_SMALL, + EXTENSION_ICON_SMALLISH, + EXTENSION_ICON_BITTY +}; + +const size_t ExtensionIconSet::kNumIconSizes = + arraysize(ExtensionIconSet::kIconSizes); + void ExtensionIconSet::Clear() { map_.clear(); } -void ExtensionIconSet::Add(int size, const std::string& path) { +void ExtensionIconSet::Add(Icons size, const std::string& path) { DCHECK(!path.empty() && path[0] != '/'); map_[size] = path; } @@ -23,7 +36,7 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const { // The searches for MATCH_BIGGER and MATCH_SMALLER below rely on the fact that // std::map is sorted. This is per the spec, so it should be safe to rely on. if (match_type == MATCH_EXACTLY) { - IconMap::const_iterator result = map_.find(size); + IconMap::const_iterator result = map_.find(static_cast<Icons>(size)); return result == map_.end() ? std::string() : result->second; } else if (match_type == MATCH_SMALLER) { IconMap::const_reverse_iterator result = map_.rend(); @@ -50,8 +63,13 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const { } bool ExtensionIconSet::ContainsPath(const std::string& path) const { + return GetIconSizeFromPath(path) != EXTENSION_ICON_INVALID; +} + +ExtensionIconSet::Icons ExtensionIconSet::GetIconSizeFromPath( + const std::string& path) const { if (path.empty()) - return false; + return EXTENSION_ICON_INVALID; DCHECK(path[0] != '/') << "ExtensionIconSet stores icon paths without leading slash."; @@ -59,8 +77,8 @@ bool ExtensionIconSet::ContainsPath(const std::string& path) const { for (IconMap::const_iterator iter = map_.begin(); iter != map_.end(); ++iter) { if (iter->second == path) - return true; + return iter->first; } - return false; + return EXTENSION_ICON_INVALID; } diff --git a/chrome/common/extensions/extension_icon_set.h b/chrome/common/extensions/extension_icon_set.h index 7fe80c5..5134276 100644 --- a/chrome/common/extensions/extension_icon_set.h +++ b/chrome/common/extensions/extension_icon_set.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,11 +12,37 @@ // Represents the set of icons for an extension. class ExtensionIconSet { public: + // NOTE: If you change this list, you should also change kIconSizes in the cc + // file. + enum Icons { + EXTENSION_ICON_GIGANTOR = 512, + EXTENSION_ICON_EXTRA_LARGE = 256, + EXTENSION_ICON_LARGE = 128, + EXTENSION_ICON_MEDIUM = 48, + EXTENSION_ICON_SMALL = 32, + EXTENSION_ICON_SMALLISH = 24, + EXTENSION_ICON_BITTY = 16, + EXTENSION_ICON_INVALID = 0, + }; + + // Get an icon from the set, optionally falling back to a smaller or bigger + // size. MatchType is exclusive (do not OR them together). + enum MatchType { + MATCH_EXACTLY, + MATCH_BIGGER, + MATCH_SMALLER + }; + + // Access to the underlying map from icon size->path. + typedef std::map<Icons, std::string> IconMap; + + // Icon sizes used by the extension system. + static const Icons kIconSizes[]; + static const size_t kNumIconSizes; + ExtensionIconSet(); ~ExtensionIconSet(); - // Access to the underlying map from icon size->path. - typedef std::map<int, std::string> IconMap; const IconMap& map() const { return map_; } // Remove all icons from the set. @@ -24,20 +50,16 @@ class ExtensionIconSet { // Add an icon to the set. If the specified size is already present, it is // overwritten. - void Add(int size, const std::string& path); + void Add(Icons size, const std::string& path); - // Get an icon from the set, optionally falling back to a smaller or bigger - // size. MatchType is exclusive (do not OR them together). - enum MatchType { - MATCH_EXACTLY, - MATCH_BIGGER, - MATCH_SMALLER - }; std::string Get(int size, MatchType match_type) const; // Returns true if the set contains the specified path. bool ContainsPath(const std::string& path) const; + // Returns icon size if the set contains the specified path or 0 if not found. + Icons GetIconSizeFromPath(const std::string& path) const; + private: IconMap map_; }; diff --git a/chrome/common/extensions/extension_icon_set_unittest.cc b/chrome/common/extensions/extension_icon_set_unittest.cc index 9bd1ec5..433e0c8 100644 --- a/chrome/common/extensions/extension_icon_set_unittest.cc +++ b/chrome/common/extensions/extension_icon_set_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,38 +8,53 @@ TEST(ExtensionIconSet, Basic) { ExtensionIconSet icons; - EXPECT_EQ("", icons.Get(42, ExtensionIconSet::MATCH_EXACTLY)); - EXPECT_EQ("", icons.Get(42, ExtensionIconSet::MATCH_BIGGER)); - EXPECT_EQ("", icons.Get(42, ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_SMALLER)); EXPECT_TRUE(icons.map().empty()); - icons.Add(42, "42.png"); - EXPECT_EQ("42.png", icons.Get(42, ExtensionIconSet::MATCH_EXACTLY)); - EXPECT_EQ("42.png", icons.Get(42, ExtensionIconSet::MATCH_BIGGER)); - EXPECT_EQ("42.png", icons.Get(42, ExtensionIconSet::MATCH_SMALLER)); - EXPECT_EQ("42.png", icons.Get(41, ExtensionIconSet::MATCH_BIGGER)); - EXPECT_EQ("42.png", icons.Get(43, ExtensionIconSet::MATCH_SMALLER)); - EXPECT_EQ("", icons.Get(41, ExtensionIconSet::MATCH_SMALLER)); - EXPECT_EQ("", icons.Get(43, ExtensionIconSet::MATCH_BIGGER)); - - icons.Add(38, "38.png"); - icons.Add(40, "40.png"); - icons.Add(44, "44.png"); - icons.Add(46, "46.png"); - - EXPECT_EQ("", icons.Get(41, ExtensionIconSet::MATCH_EXACTLY)); - EXPECT_EQ("40.png", icons.Get(41, ExtensionIconSet::MATCH_SMALLER)); - EXPECT_EQ("42.png", icons.Get(41, ExtensionIconSet::MATCH_BIGGER)); - EXPECT_EQ("", icons.Get(37, ExtensionIconSet::MATCH_SMALLER)); - EXPECT_EQ("", icons.Get(47, ExtensionIconSet::MATCH_BIGGER)); + icons.Add(ExtensionIconSet::EXTENSION_ICON_LARGE, "large.png"); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_BIGGER)); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_LARGE, + ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_BIGGER)); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_EXTRA_LARGE, + ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("large.png", icons.Get(0, ExtensionIconSet::MATCH_BIGGER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_EXTRA_LARGE, + ExtensionIconSet::MATCH_BIGGER)); + + icons.Add(ExtensionIconSet::EXTENSION_ICON_SMALLISH, "smallish.png"); + icons.Add(ExtensionIconSet::EXTENSION_ICON_SMALL, "small.png"); + icons.Add(ExtensionIconSet::EXTENSION_ICON_EXTRA_LARGE, "extra_large.png"); + + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("small.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("large.png", icons.Get(ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_BIGGER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_BITTY, + ExtensionIconSet::MATCH_SMALLER)); + EXPECT_EQ("", icons.Get(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, + ExtensionIconSet::MATCH_BIGGER)); } TEST(ExtensionIconSet, Values) { ExtensionIconSet icons; EXPECT_FALSE(icons.ContainsPath("foo")); - icons.Add(1, "foo"); - icons.Add(2, "bar"); + icons.Add(ExtensionIconSet::EXTENSION_ICON_BITTY, "foo"); + icons.Add(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, "bar"); EXPECT_TRUE(icons.ContainsPath("foo")); EXPECT_TRUE(icons.ContainsPath("bar")); @@ -49,3 +64,25 @@ TEST(ExtensionIconSet, Values) { icons.Clear(); EXPECT_FALSE(icons.ContainsPath("foo")); } + +TEST(ExtensionIconSet, FindSize) { + ExtensionIconSet icons; + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_INVALID, + icons.GetIconSizeFromPath("foo")); + + icons.Add(ExtensionIconSet::EXTENSION_ICON_BITTY, "foo"); + icons.Add(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, "bar"); + + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY, + icons.GetIconSizeFromPath("foo")); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, + icons.GetIconSizeFromPath("bar")); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_INVALID, + icons.GetIconSizeFromPath("baz")); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_INVALID, + icons.GetIconSizeFromPath("")); + + icons.Clear(); + EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_INVALID, + icons.GetIconSizeFromPath("foo")); +} diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc index 60763a0..74f8271 100644 --- a/chrome/common/extensions/extension_manifests_unittest.cc +++ b/chrome/common/extensions/extension_manifests_unittest.cc @@ -612,10 +612,42 @@ TEST_F(ExtensionManifestTest, AllowUnrecognizedPermissions) { TEST_F(ExtensionManifestTest, NormalizeIconPaths) { scoped_refptr<Extension> extension( LoadAndExpectSuccess("normalize_icon_paths.json")); - EXPECT_EQ("16.png", - extension->icons().Get(16, ExtensionIconSet::MATCH_EXACTLY)); - EXPECT_EQ("48.png", - extension->icons().Get(48, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("16.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("48.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_EXACTLY)); +} + +TEST_F(ExtensionManifestTest, InvalidIconSizes) { + scoped_refptr<Extension> extension( + LoadAndExpectSuccess("init_ignored_icon_size.json")); + EXPECT_EQ("", extension->icons().Get( + static_cast<ExtensionIconSet::Icons>(300), + ExtensionIconSet::MATCH_EXACTLY)); +} + +TEST_F(ExtensionManifestTest, ValidIconSizes) { + scoped_refptr<Extension> extension( + LoadAndExpectSuccess("init_valid_icon_size.json")); + EXPECT_EQ("16.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("24.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_SMALLISH, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("32.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_SMALL, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("48.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_MEDIUM, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("128.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_LARGE, ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("256.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_EXTRA_LARGE, + ExtensionIconSet::MATCH_EXACTLY)); + EXPECT_EQ("512.png", extension->icons().Get( + ExtensionIconSet::EXTENSION_ICON_GIGANTOR, + ExtensionIconSet::MATCH_EXACTLY)); } TEST_F(ExtensionManifestTest, DisallowMultipleUISurfaces) { diff --git a/chrome/renderer/localized_error.cc b/chrome/renderer/localized_error.cc index 889266c..0ca5f1e 100644 --- a/chrome/renderer/localized_error.cc +++ b/chrome/renderer/localized_error.cc @@ -10,6 +10,7 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_set.h" #include "content/public/renderer/render_thread.h" #include "googleurl/src/gurl.h" @@ -694,7 +695,7 @@ void LocalizedError::GetAppErrorStrings( error_strings->SetString("title", app->name()); error_strings->SetString("icon", - app->GetIconURL(Extension::EXTENSION_ICON_LARGE, + app->GetIconURL(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, ExtensionIconSet::MATCH_SMALLER).spec()); error_strings->SetString("name", app->name()); error_strings->SetString("msg", diff --git a/chrome/test/data/extensions/manifest_tests/init_ignored_icon_size.json b/chrome/test/data/extensions/manifest_tests/init_ignored_icon_size.json new file mode 100644 index 0000000..98d79b4 --- /dev/null +++ b/chrome/test/data/extensions/manifest_tests/init_ignored_icon_size.json @@ -0,0 +1,7 @@ +{ + "name": "my extension", + "version": "1.0.0.0", + "icons": { + "300": "300.png" + } +} diff --git a/chrome/test/data/extensions/manifest_tests/init_valid_icon_size.json b/chrome/test/data/extensions/manifest_tests/init_valid_icon_size.json new file mode 100644 index 0000000..bc0fc30 --- /dev/null +++ b/chrome/test/data/extensions/manifest_tests/init_valid_icon_size.json @@ -0,0 +1,13 @@ +{ + "name": "my extension", + "version": "1.0.0.0", + "icons": { + "16": "16.png", + "24": "24.png", + "32": "32.png", + "48": "48.png", + "128": "128.png", + "256": "256.png", + "512": "512.png" + } +} |