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

Unified Diff: chrome/browser/ui/views/location_bar/page_action_image_view.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: . 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/browser/ui/views/location_bar/page_action_image_view.cc
diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.cc b/chrome/browser/ui/views/location_bar/page_action_image_view.cc
index b98d0d37a65dbb68f3dd3eb9eb80f277d3130940..7e9f6c59580a528ca9fde7273b899be2308605d0 100644
--- a/chrome/browser/ui/views/location_bar/page_action_image_view.cc
+++ b/chrome/browser/ui/views/location_bar/page_action_image_view.cc
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/api/commands/command_service_factory.h"
+#include "chrome/browser/extensions/extension_action_icon_factory.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
@@ -43,7 +44,6 @@ PageActionImageView::PageActionImageView(LocationBarView* owner,
: owner_(owner),
page_action_(page_action),
browser_(browser),
- ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
current_tab_id_(-1),
preview_enabled_(false),
popup_(NULL),
@@ -55,19 +55,7 @@ PageActionImageView::PageActionImageView(LocationBarView* owner,
GetExtensionById(page_action->extension_id(), false);
DCHECK(extension);
- // Load all the icons declared in the manifest. This is the contents of the
- // icons array, plus the default_icon property, if any.
- 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 i(icon_paths.begin());
- i != icon_paths.end(); ++i) {
- tracker_.LoadImage(extension, extension->GetResource(*i),
- gfx::Size(Extension::kPageActionIconMaxSize,
- Extension::kPageActionIconMaxSize),
- ImageLoadingTracker::DONT_CACHE);
- }
+ icon_factory_.reset(new ExtensionActionIconFactory(extension, this));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(
@@ -196,29 +184,6 @@ bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) {
return false;
}
-void PageActionImageView::OnImageLoaded(const gfx::Image& image,
- const std::string& extension_id,
- int index) {
- // We loaded icons()->size() icons, plus one extra if the page action had
- // a default icon.
- int total_icons = static_cast<int>(page_action_->icon_paths()->size());
- if (!page_action_->default_icon_path().empty())
- total_icons++;
- DCHECK(index < total_icons);
-
- // Map the index of the loaded image back to its name. If we ever get an
- // index greater than the number of icons, it must be the default icon.
- if (index < static_cast<int>(page_action_->icon_paths()->size()))
- page_action_->CacheIcon(page_action_->icon_paths()->at(index), image);
- else
- page_action_->CacheIcon(page_action_->default_icon_path(), image);
-
- // During object construction owner_ will be NULL.
- TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
- if (tab_contents)
- UpdateVisibility(tab_contents->web_contents(), current_url_);
-}
-
void PageActionImageView::ShowContextMenuForView(View* source,
const gfx::Point& point) {
const Extension* extension = owner_->profile()->GetExtensionService()->
@@ -270,7 +235,7 @@ void PageActionImageView::UpdateVisibility(WebContents* contents,
SetTooltipText(UTF8ToUTF16(tooltip_));
// Set the image.
- gfx::Image icon = page_action_->GetIcon(current_tab_id_);
+ gfx::Image icon = page_action_->GetIcon(current_tab_id_, icon_factory_.get());
if (!icon.IsEmpty())
SetImage(*icon.ToImageSkia());
@@ -289,17 +254,21 @@ void PageActionImageView::Observe(int type,
DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type);
const Extension* unloaded_extension =
content::Details<extensions::UnloadedExtensionInfo>(details)->extension;
- if (page_action_ == unloaded_extension ->page_action())
+ if (page_action_ == unloaded_extension->page_action())
owner_->UpdatePageActions();
}
-void PageActionImageView::OnIconChanged(
- const ExtensionAction::IconAnimation& animation) {
+void PageActionImageView::OnIconUpdated() {
TabContents* tab_contents = owner_->GetTabContents();
if (tab_contents)
UpdateVisibility(tab_contents->web_contents(), current_url_);
}
+void PageActionImageView::OnIconChanged(
+ const ExtensionAction::IconAnimation& animation) {
+ OnIconUpdated();
+}
+
void PageActionImageView::ShowPopupWithURL(const GURL& popup_url) {
bool popup_showing = popup_ != NULL;

Powered by Google App Engine
This is Rietveld 408576698