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

Side by Side Diff: chrome/browser/ui/views/location_bar/page_action_image_view.cc

Issue 10806058: Move icon fallbacks into ExtensionAction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move the icon cache inside ExtensionAction. 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 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/location_bar/page_action_image_view.h" 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.h"
9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h"
10 #include "chrome/browser/extensions/extension_context_menu_model.h" 10 #include "chrome/browser/extensions/extension_context_menu_model.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 int index) { 174 int index) {
175 // We loaded icons()->size() icons, plus one extra if the page action had 175 // We loaded icons()->size() icons, plus one extra if the page action had
176 // a default icon. 176 // a default icon.
177 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 177 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
178 if (!page_action_->default_icon_path().empty()) 178 if (!page_action_->default_icon_path().empty())
179 total_icons++; 179 total_icons++;
180 DCHECK(index < total_icons); 180 DCHECK(index < total_icons);
181 181
182 // Map the index of the loaded image back to its name. If we ever get an 182 // Map the index of the loaded image back to its name. If we ever get an
183 // index greater than the number of icons, it must be the default icon. 183 // index greater than the number of icons, it must be the default icon.
184 if (!image.IsEmpty()) { 184 if (index < static_cast<int>(page_action_->icon_paths()->size()))
185 const SkBitmap* bitmap = image.ToSkBitmap(); 185 page_action_->CacheIcon(page_action_->icon_paths()->at(index), image);
186 if (index < static_cast<int>(page_action_->icon_paths()->size())) 186 else
187 page_action_icons_[page_action_->icon_paths()->at(index)] = *bitmap; 187 page_action_->CacheIcon(page_action_->default_icon_path(), image);
188 else
189 page_action_icons_[page_action_->default_icon_path()] = *bitmap;
190 }
191 188
192 // During object construction owner_ will be NULL. 189 // During object construction owner_ will be NULL.
193 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; 190 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
194 if (tab_contents) 191 if (tab_contents)
195 UpdateVisibility(tab_contents->web_contents(), current_url_); 192 UpdateVisibility(tab_contents->web_contents(), current_url_);
196 } 193 }
197 194
198 void PageActionImageView::ShowContextMenuForView(View* source, 195 void PageActionImageView::ShowContextMenuForView(View* source,
199 const gfx::Point& point) { 196 const gfx::Point& point) {
200 const Extension* extension = owner_->profile()->GetExtensionService()-> 197 const Extension* extension = owner_->profile()->GetExtensionService()->
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) { 236 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
240 SetVisible(false); 237 SetVisible(false);
241 return; 238 return;
242 } 239 }
243 240
244 // Set the tooltip. 241 // Set the tooltip.
245 tooltip_ = page_action_->GetTitle(current_tab_id_); 242 tooltip_ = page_action_->GetTitle(current_tab_id_);
246 SetTooltipText(UTF8ToUTF16(tooltip_)); 243 SetTooltipText(UTF8ToUTF16(tooltip_));
247 244
248 // Set the image. 245 // Set the image.
249 // It can come from three places. In descending order of priority: 246 gfx::Image icon = page_action_->GetIcon(current_tab_id_);
250 // - The developer can set it dynamically by path or bitmap. It will be in 247 if (!icon.IsEmpty()) {
251 // page_action_->GetIcon(). 248 SetImage(*icon.ToImageSkia());
252 // - The developer can set it dynamically by index. It will be in
253 // page_action_->GetIconIndex().
254 // - It can be set in the manifest by path. It will be in
255 // page_action_->default_icon_path().
256
257 // First look for a dynamically set bitmap.
258 SkBitmap icon = page_action_->GetIcon(current_tab_id_);
259 if (icon.isNull()) {
260 int icon_index = page_action_->GetIconIndex(current_tab_id_);
261 std::string icon_path = (icon_index < 0) ?
262 page_action_->default_icon_path() :
263 page_action_->icon_paths()->at(icon_index);
264 if (!icon_path.empty()) {
265 PageActionMap::iterator iter = page_action_icons_.find(icon_path);
266 if (iter != page_action_icons_.end())
267 icon = iter->second;
268 }
269 }
270
271 if (!icon.isNull()) {
272 const ExtensionAction::IconAnimation* icon_animation =
273 scoped_icon_animation_observer_.icon_animation();
274 if (icon_animation)
275 icon = icon_animation->Apply(icon);
276 SetImage(icon);
277 } 249 }
278 250
279 SetVisible(true); 251 SetVisible(true);
280 } 252 }
281 253
282 void PageActionImageView::OnWidgetClosing(views::Widget* widget) { 254 void PageActionImageView::OnWidgetClosing(views::Widget* widget) {
283 DCHECK_EQ(popup_->GetWidget(), widget); 255 DCHECK_EQ(popup_->GetWidget(), widget);
284 popup_->GetWidget()->RemoveObserver(this); 256 popup_->GetWidget()->RemoveObserver(this);
285 popup_ = NULL; 257 popup_ = NULL;
286 } 258 }
(...skipping 29 matching lines...) Expand all
316 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 288 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
317 289
318 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); 290 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location);
319 popup_->GetWidget()->AddObserver(this); 291 popup_->GetWidget()->AddObserver(this);
320 } 292 }
321 293
322 void PageActionImageView::HidePopup() { 294 void PageActionImageView::HidePopup() {
323 if (popup_) 295 if (popup_)
324 popup_->GetWidget()->Close(); 296 popup_->GetWidget()->Close();
325 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698