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

Side by Side Diff: chrome/browser/ui/views/infobars/extension_infobar.cc

Issue 9500007: Views: Update ImageLoadingTracker::Observer subclasses (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/infobars/extension_infobar.h" 5 #include "chrome/browser/ui/views/infobars/extension_infobar.h"
6 6
7 #include "chrome/browser/extensions/extension_context_menu_model.h" 7 #include "chrome/browser/extensions/extension_context_menu_model.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_infobar_delegate.h" 9 #include "chrome/browser/extensions/extension_infobar_delegate.h"
10 #include "chrome/browser/platform_util.h" 10 #include "chrome/browser/platform_util.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h" 11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_icon_set.h" 13 #include "chrome/common/extensions/extension_icon_set.h"
14 #include "chrome/common/extensions/extension_resource.h" 14 #include "chrome/common/extensions/extension_resource.h"
15 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 #include "ui/base/animation/slide_animation.h" 16 #include "ui/base/animation/slide_animation.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
19 #include "ui/gfx/image/image.h"
19 #include "ui/views/controls/button/menu_button.h" 20 #include "ui/views/controls/button/menu_button.h"
20 #include "ui/views/controls/menu/menu_item_view.h" 21 #include "ui/views/controls/menu/menu_item_view.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 // ExtensionInfoBarDelegate ---------------------------------------------------- 24 // ExtensionInfoBarDelegate ----------------------------------------------------
24 25
25 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { 26 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) {
26 return new ExtensionInfoBar(browser_, owner, this); 27 return new ExtensionInfoBar(browser_, owner, this);
27 } 28 }
28 29
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // the close button is the last child. 87 // the close button is the last child.
87 InfoBarView::ViewHierarchyChanged(is_add, parent, child); 88 InfoBarView::ViewHierarchyChanged(is_add, parent, child);
88 89
89 // This must happen after adding all children because it can trigger layout, 90 // This must happen after adding all children because it can trigger layout,
90 // which assumes that particular children (e.g. the close button) have already 91 // which assumes that particular children (e.g. the close button) have already
91 // been added. 92 // been added.
92 const Extension* extension = extension_host->extension(); 93 const Extension* extension = extension_host->extension();
93 ExtensionIconSet::Icons image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; 94 ExtensionIconSet::Icons image_size = ExtensionIconSet::EXTENSION_ICON_BITTY;
94 ExtensionResource icon_resource = extension->GetIconResource( 95 ExtensionResource icon_resource = extension->GetIconResource(
95 image_size, ExtensionIconSet::MATCH_EXACTLY); 96 image_size, ExtensionIconSet::MATCH_EXACTLY);
96 if (!icon_resource.relative_path().empty()) { 97 tracker_.LoadImage(extension, icon_resource,
sky 2012/02/29 15:44:05 Did you remove this because ImageTracker takes car
97 tracker_.LoadImage(extension, icon_resource, 98 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE);
98 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE);
99 } else {
100 OnImageLoaded(NULL, icon_resource, 0);
101 }
102 } 99 }
103 100
104 int ExtensionInfoBar::ContentMinimumWidth() const { 101 int ExtensionInfoBar::ContentMinimumWidth() const {
105 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; 102 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin;
106 } 103 }
107 104
108 void ExtensionInfoBar::OnImageLoaded(SkBitmap* image, 105 void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image,
109 const ExtensionResource& resource, 106 const std::string& extension_id,
110 int index) { 107 int index) {
111 if (!GetDelegate()) 108 if (!GetDelegate())
112 return; // The delegate can go away while we asynchronously load images. 109 return; // The delegate can go away while we asynchronously load images.
113 110
114 SkBitmap* icon = image; 111 const SkBitmap* icon = NULL;
115 // Fall back on the default extension icon on failure. 112 // Fall back on the default extension icon on failure.
116 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 113 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
117 if (!image || image->empty()) 114 if (image.IsEmpty())
118 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); 115 icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
116 else
117 icon = image.ToSkBitmap();
119 118
120 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW); 119 SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW);
121 120
122 int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; 121 int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY;
123 // The margin between the extension icon and the drop-down arrow bitmap. 122 // The margin between the extension icon and the drop-down arrow bitmap.
124 static const int kDropArrowLeftMargin = 3; 123 static const int kDropArrowLeftMargin = 3;
125 scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia( 124 scoped_ptr<gfx::CanvasSkia> canvas(new gfx::CanvasSkia(
126 gfx::Size(image_size + kDropArrowLeftMargin + drop_image->width(), 125 gfx::Size(image_size + kDropArrowLeftMargin + drop_image->width(),
127 image_size), 126 image_size),
128 false)); 127 false));
(...skipping 20 matching lines...) Expand all
149 148
150 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = 149 scoped_refptr<ExtensionContextMenuModel> options_menu_contents =
151 new ExtensionContextMenuModel(extension, browser_, NULL); 150 new ExtensionContextMenuModel(extension, browser_, NULL);
152 DCHECK_EQ(source, menu_); 151 DCHECK_EQ(source, menu_);
153 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); 152 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT);
154 } 153 }
155 154
156 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { 155 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() {
157 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; 156 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL;
158 } 157 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/extension_infobar.h ('k') | chrome/browser/ui/views/location_bar/page_action_image_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698