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

Side by Side 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: disable unittest on android Created 8 years, 3 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_action_icon_factory.h"
10 #include "chrome/browser/extensions/extension_context_menu_model.h" 11 #include "chrome/browser/extensions/extension_context_menu_model.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/extensions/location_bar_controller.h" 14 #include "chrome/browser/extensions/location_bar_controller.h"
14 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/platform_util.h" 16 #include "chrome/browser/platform_util.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/sessions/session_id.h" 18 #include "chrome/browser/sessions/session_id.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
(...skipping 16 matching lines...) Expand all
36 using content::WebContents; 37 using content::WebContents;
37 using extensions::LocationBarController; 38 using extensions::LocationBarController;
38 using extensions::Extension; 39 using extensions::Extension;
39 40
40 PageActionImageView::PageActionImageView(LocationBarView* owner, 41 PageActionImageView::PageActionImageView(LocationBarView* owner,
41 ExtensionAction* page_action, 42 ExtensionAction* page_action,
42 Browser* browser) 43 Browser* browser)
43 : owner_(owner), 44 : owner_(owner),
44 page_action_(page_action), 45 page_action_(page_action),
45 browser_(browser), 46 browser_(browser),
46 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
47 current_tab_id_(-1), 47 current_tab_id_(-1),
48 preview_enabled_(false), 48 preview_enabled_(false),
49 popup_(NULL), 49 popup_(NULL),
50 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( 50 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_(
51 page_action->GetIconAnimation( 51 page_action->GetIconAnimation(
52 SessionID::IdForTab(owner->GetTabContents()->web_contents())), 52 SessionID::IdForTab(owner->GetTabContents()->web_contents())),
53 this)) { 53 this)) {
54 const Extension* extension = owner_->profile()->GetExtensionService()-> 54 const Extension* extension = owner_->profile()->GetExtensionService()->
55 GetExtensionById(page_action->extension_id(), false); 55 GetExtensionById(page_action->extension_id(), false);
56 DCHECK(extension); 56 DCHECK(extension);
57 57
58 std::string path = page_action_->default_icon_path(); 58 icon_factory_.reset(
59 if (!path.empty()) { 59 new ExtensionActionIconFactory(extension, page_action, this));
60 tracker_.LoadImage(extension, extension->GetResource(path),
61 gfx::Size(Extension::kPageActionIconMaxSize,
62 Extension::kPageActionIconMaxSize),
63 ImageLoadingTracker::DONT_CACHE);
64 }
65 60
66 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 61 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
67 content::Source<Profile>( 62 content::Source<Profile>(
68 owner_->profile()->GetOriginalProfile())); 63 owner_->profile()->GetOriginalProfile()));
69 64
70 set_accessibility_focusable(true); 65 set_accessibility_focusable(true);
71 set_context_menu_controller(this); 66 set_context_menu_controller(this);
72 67
73 extensions::CommandService* command_service = 68 extensions::CommandService* command_service =
74 extensions::CommandServiceFactory::GetForProfile( 69 extensions::CommandServiceFactory::GetForProfile(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 176
182 bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) { 177 bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) {
183 if (event.key_code() == ui::VKEY_SPACE || 178 if (event.key_code() == ui::VKEY_SPACE ||
184 event.key_code() == ui::VKEY_RETURN) { 179 event.key_code() == ui::VKEY_RETURN) {
185 ExecuteAction(ExtensionPopup::SHOW); 180 ExecuteAction(ExtensionPopup::SHOW);
186 return true; 181 return true;
187 } 182 }
188 return false; 183 return false;
189 } 184 }
190 185
191 void PageActionImageView::OnImageLoaded(const gfx::Image& image,
192 const std::string& extension_id,
193 int index) {
194 page_action_->CacheIcon(image);
195
196 // During object construction owner_ will be NULL.
197 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
198 if (tab_contents)
199 UpdateVisibility(tab_contents->web_contents(), current_url_);
200 }
201
202 void PageActionImageView::ShowContextMenuForView(View* source, 186 void PageActionImageView::ShowContextMenuForView(View* source,
203 const gfx::Point& point) { 187 const gfx::Point& point) {
204 const Extension* extension = owner_->profile()->GetExtensionService()-> 188 const Extension* extension = owner_->profile()->GetExtensionService()->
205 GetExtensionById(page_action()->extension_id(), false); 189 GetExtensionById(page_action()->extension_id(), false);
206 if (!extension->ShowConfigureContextMenus()) 190 if (!extension->ShowConfigureContextMenus())
207 return; 191 return;
208 192
209 scoped_refptr<ExtensionContextMenuModel> context_menu_model( 193 scoped_refptr<ExtensionContextMenuModel> context_menu_model(
210 new ExtensionContextMenuModel(extension, browser_, this)); 194 new ExtensionContextMenuModel(extension, browser_, this));
211 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); 195 views::MenuModelAdapter menu_model_adapter(context_menu_model.get());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) { 228 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
245 SetVisible(false); 229 SetVisible(false);
246 return; 230 return;
247 } 231 }
248 232
249 // Set the tooltip. 233 // Set the tooltip.
250 tooltip_ = page_action_->GetTitle(current_tab_id_); 234 tooltip_ = page_action_->GetTitle(current_tab_id_);
251 SetTooltipText(UTF8ToUTF16(tooltip_)); 235 SetTooltipText(UTF8ToUTF16(tooltip_));
252 236
253 // Set the image. 237 // Set the image.
254 gfx::Image icon = page_action_->GetIcon(current_tab_id_); 238 gfx::Image icon = icon_factory_->GetIcon(current_tab_id_);
255 if (!icon.IsEmpty()) 239 if (!icon.IsEmpty())
256 SetImage(*icon.ToImageSkia()); 240 SetImage(*icon.ToImageSkia());
257 241
258 SetVisible(true); 242 SetVisible(true);
259 } 243 }
260 244
261 void PageActionImageView::InspectPopup(ExtensionAction* action) { 245 void PageActionImageView::InspectPopup(ExtensionAction* action) {
262 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT); 246 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT);
263 } 247 }
264 248
265 void PageActionImageView::OnWidgetClosing(views::Widget* widget) { 249 void PageActionImageView::OnWidgetClosing(views::Widget* widget) {
266 DCHECK_EQ(popup_->GetWidget(), widget); 250 DCHECK_EQ(popup_->GetWidget(), widget);
267 popup_->GetWidget()->RemoveObserver(this); 251 popup_->GetWidget()->RemoveObserver(this);
268 popup_ = NULL; 252 popup_ = NULL;
269 } 253 }
270 254
271 void PageActionImageView::Observe(int type, 255 void PageActionImageView::Observe(int type,
272 const content::NotificationSource& source, 256 const content::NotificationSource& source,
273 const content::NotificationDetails& details) { 257 const content::NotificationDetails& details) {
274 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); 258 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type);
275 const Extension* unloaded_extension = 259 const Extension* unloaded_extension =
276 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; 260 content::Details<extensions::UnloadedExtensionInfo>(details)->extension;
277 if (page_action_ == unloaded_extension ->page_action()) 261 if (page_action_ == unloaded_extension->page_action())
278 owner_->UpdatePageActions(); 262 owner_->UpdatePageActions();
279 } 263 }
280 264
281 void PageActionImageView::OnIconChanged() { 265 void PageActionImageView::OnIconUpdated() {
282 TabContents* tab_contents = owner_->GetTabContents(); 266 TabContents* tab_contents = owner_->GetTabContents();
283 if (tab_contents) 267 if (tab_contents)
284 UpdateVisibility(tab_contents->web_contents(), current_url_); 268 UpdateVisibility(tab_contents->web_contents(), current_url_);
285 } 269 }
286 270
271 void PageActionImageView::OnIconChanged() {
272 OnIconUpdated();
273 }
274
287 void PageActionImageView::ShowPopupWithURL( 275 void PageActionImageView::ShowPopupWithURL(
288 const GURL& popup_url, 276 const GURL& popup_url,
289 ExtensionPopup::ShowAction show_action) { 277 ExtensionPopup::ShowAction show_action) {
290 bool popup_showing = popup_ != NULL; 278 bool popup_showing = popup_ != NULL;
291 279
292 // Always hide the current popup. Only one popup at a time. 280 // Always hide the current popup. Only one popup at a time.
293 HidePopup(); 281 HidePopup();
294 282
295 // If we were already showing, then treat this click as a dismiss. 283 // If we were already showing, then treat this click as a dismiss.
296 if (popup_showing) 284 if (popup_showing)
297 return; 285 return;
298 286
299 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? 287 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ?
300 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 288 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
301 289
302 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location, 290 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location,
303 show_action); 291 show_action);
304 popup_->GetWidget()->AddObserver(this); 292 popup_->GetWidget()->AddObserver(this);
305 } 293 }
306 294
307 void PageActionImageView::HidePopup() { 295 void PageActionImageView::HidePopup() {
308 if (popup_) 296 if (popup_)
309 popup_->GetWidget()->Close(); 297 popup_->GetWidget()->Close();
310 } 298 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/page_action_image_view.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698