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

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

Issue 11418043: Remove TabContents from OmniboxEditController and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros Created 8 years, 1 month 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.h" 10 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_icon_factory.h" 11 #include "chrome/browser/extensions/extension_action_icon_factory.h"
12 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
13 #include "chrome/browser/extensions/extension_context_menu_model.h" 13 #include "chrome/browser/extensions/extension_context_menu_model.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/location_bar_controller.h" 16 #include "chrome/browser/extensions/location_bar_controller.h"
17 #include "chrome/browser/extensions/tab_helper.h" 17 #include "chrome/browser/extensions/tab_helper.h"
18 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/sessions/session_id.h" 20 #include "chrome/browser/sessions/session_id.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents.h"
23 #include "chrome/browser/ui/views/frame/browser_view.h" 22 #include "chrome/browser/ui/views/frame/browser_view.h"
24 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
25 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" 24 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
26 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
27 #include "chrome/common/extensions/extension_manifest_constants.h" 26 #include "chrome/common/extensions/extension_manifest_constants.h"
28 #include "chrome/common/extensions/extension_resource.h" 27 #include "chrome/common/extensions/extension_resource.h"
29 #include "ui/base/accessibility/accessible_view_state.h" 28 #include "ui/base/accessibility/accessible_view_state.h"
30 #include "ui/base/events/event.h" 29 #include "ui/base/events/event.h"
31 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
32 #include "ui/views/controls/menu/menu_item_view.h" 31 #include "ui/views/controls/menu/menu_item_view.h"
33 #include "ui/views/controls/menu/menu_model_adapter.h" 32 #include "ui/views/controls/menu/menu_model_adapter.h"
34 #include "ui/views/controls/menu/menu_runner.h" 33 #include "ui/views/controls/menu/menu_runner.h"
35 34
36 using content::WebContents; 35 using content::WebContents;
37 using extensions::LocationBarController; 36 using extensions::LocationBarController;
38 using extensions::Extension; 37 using extensions::Extension;
39 38
40 PageActionImageView::PageActionImageView(LocationBarView* owner, 39 PageActionImageView::PageActionImageView(LocationBarView* owner,
41 ExtensionAction* page_action, 40 ExtensionAction* page_action,
42 Browser* browser) 41 Browser* browser)
43 : owner_(owner), 42 : owner_(owner),
44 page_action_(page_action), 43 page_action_(page_action),
45 browser_(browser), 44 browser_(browser),
46 current_tab_id_(-1), 45 current_tab_id_(-1),
47 preview_enabled_(false), 46 preview_enabled_(false),
48 popup_(NULL), 47 popup_(NULL),
49 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( 48 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_(
50 page_action->GetIconAnimation( 49 page_action->GetIconAnimation(
51 SessionID::IdForTab(owner->GetTabContents()->web_contents())), 50 SessionID::IdForTab(owner->GetWebContents())),
52 this)) { 51 this)) {
53 const Extension* extension = owner_->profile()->GetExtensionService()-> 52 const Extension* extension = owner_->profile()->GetExtensionService()->
54 GetExtensionById(page_action->extension_id(), false); 53 GetExtensionById(page_action->extension_id(), false);
55 DCHECK(extension); 54 DCHECK(extension);
56 55
57 icon_factory_.reset( 56 icon_factory_.reset(
58 new ExtensionActionIconFactory(extension, page_action, this)); 57 new ExtensionActionIconFactory(extension, page_action, this));
59 58
60 set_accessibility_focusable(true); 59 set_accessibility_focusable(true);
61 set_context_menu_controller(this); 60 set_context_menu_controller(this);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 104 }
106 } 105 }
107 106
108 if (popup_) 107 if (popup_)
109 popup_->GetWidget()->RemoveObserver(this); 108 popup_->GetWidget()->RemoveObserver(this);
110 HidePopup(); 109 HidePopup();
111 } 110 }
112 111
113 void PageActionImageView::ExecuteAction( 112 void PageActionImageView::ExecuteAction(
114 ExtensionPopup::ShowAction show_action) { 113 ExtensionPopup::ShowAction show_action) {
115 TabContents* tab_contents = owner_->GetTabContents(); 114 WebContents* web_contents = owner_->GetWebContents();
116 if (!tab_contents) 115 if (!web_contents)
117 return; 116 return;
118 117
119 extensions::TabHelper* extensions_tab_helper = 118 extensions::TabHelper* extensions_tab_helper =
120 extensions::TabHelper::FromWebContents(tab_contents->web_contents()); 119 extensions::TabHelper::FromWebContents(web_contents);
121 LocationBarController* controller = 120 LocationBarController* controller =
122 extensions_tab_helper->location_bar_controller(); 121 extensions_tab_helper->location_bar_controller();
123 122
124 switch (controller->OnClicked(page_action_->extension_id(), 1)) { 123 switch (controller->OnClicked(page_action_->extension_id(), 1)) {
125 case LocationBarController::ACTION_NONE: 124 case LocationBarController::ACTION_NONE:
126 break; 125 break;
127 126
128 case LocationBarController::ACTION_SHOW_POPUP: 127 case LocationBarController::ACTION_SHOW_POPUP:
129 ShowPopupWithURL(page_action_->GetPopupUrl(current_tab_id_), show_action); 128 ShowPopupWithURL(page_action_->GetPopupUrl(current_tab_id_), show_action);
130 break; 129 break;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT); 240 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT);
242 } 241 }
243 242
244 void PageActionImageView::OnWidgetClosing(views::Widget* widget) { 243 void PageActionImageView::OnWidgetClosing(views::Widget* widget) {
245 DCHECK_EQ(popup_->GetWidget(), widget); 244 DCHECK_EQ(popup_->GetWidget(), widget);
246 popup_->GetWidget()->RemoveObserver(this); 245 popup_->GetWidget()->RemoveObserver(this);
247 popup_ = NULL; 246 popup_ = NULL;
248 } 247 }
249 248
250 void PageActionImageView::OnIconUpdated() { 249 void PageActionImageView::OnIconUpdated() {
251 TabContents* tab_contents = owner_->GetTabContents(); 250 WebContents* web_contents = owner_->GetWebContents();
252 if (tab_contents) 251 if (web_contents)
253 UpdateVisibility(tab_contents->web_contents(), current_url_); 252 UpdateVisibility(web_contents, current_url_);
254 } 253 }
255 254
256 void PageActionImageView::OnIconChanged() { 255 void PageActionImageView::OnIconChanged() {
257 OnIconUpdated(); 256 OnIconUpdated();
258 } 257 }
259 258
260 void PageActionImageView::PaintChildren(gfx::Canvas* canvas) { 259 void PageActionImageView::PaintChildren(gfx::Canvas* canvas) {
261 View::PaintChildren(canvas); 260 View::PaintChildren(canvas);
262 if (current_tab_id_ >= 0) 261 if (current_tab_id_ >= 0)
263 page_action_->PaintBadge(canvas, GetLocalBounds(), current_tab_id_); 262 page_action_->PaintBadge(canvas, GetLocalBounds(), current_tab_id_);
(...skipping 16 matching lines...) Expand all
280 279
281 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location, 280 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location,
282 show_action); 281 show_action);
283 popup_->GetWidget()->AddObserver(this); 282 popup_->GetWidget()->AddObserver(this);
284 } 283 }
285 284
286 void PageActionImageView::HidePopup() { 285 void PageActionImageView::HidePopup() {
287 if (popup_) 286 if (popup_)
288 popup_->GetWidget()->Close(); 287 popup_->GetWidget()->Close();
289 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698