[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / page_action_image_view.h
blob89348a2244faebbb7a03714c77c9585a29477e24
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/extensions/extension_action.h"
13 #include "chrome/browser/extensions/extension_action_icon_factory.h"
14 #include "chrome/browser/extensions/extension_context_menu_model.h"
15 #include "chrome/browser/ui/views/extensions/extension_popup.h"
16 #include "ui/views/context_menu_controller.h"
17 #include "ui/views/controls/image_view.h"
18 #include "ui/views/widget/widget_observer.h"
20 class Browser;
21 class LocationBarView;
23 namespace content {
24 class WebContents;
26 namespace views {
27 class MenuRunner;
30 // PageActionImageView is used by the LocationBarView to display the icon for a
31 // given PageAction and notify the extension when the icon is clicked.
32 class PageActionImageView : public views::ImageView,
33 public ExtensionContextMenuModel::PopupDelegate,
34 public views::WidgetObserver,
35 public views::ContextMenuController,
36 public ExtensionActionIconFactory::Observer {
37 public:
38 PageActionImageView(LocationBarView* owner,
39 ExtensionAction* page_action,
40 Browser* browser);
41 virtual ~PageActionImageView();
43 ExtensionAction* page_action() { return page_action_; }
45 int current_tab_id() { return current_tab_id_; }
47 void set_preview_enabled(bool preview_enabled) {
48 preview_enabled_ = preview_enabled;
51 // Overridden from views::View:
52 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
55 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
57 // Overridden from ExtensionContextMenuModel::Delegate
58 virtual void InspectPopup(ExtensionAction* action) OVERRIDE;
60 // Overridden from views::WidgetObserver:
61 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
63 // Overridden from views::ContextMenuController.
64 virtual void ShowContextMenuForView(View* source,
65 const gfx::Point& point,
66 ui::MenuSourceType source_type) OVERRIDE;
68 // Overriden from ExtensionActionIconFactory::Observer.
69 virtual void OnIconUpdated() OVERRIDE;
71 // Overridden from ui::AcceleratorTarget:
72 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
73 virtual bool CanHandleAccelerators() const OVERRIDE;
75 // Called to notify the PageAction that it should determine whether to be
76 // visible or hidden. |contents| is the WebContents that is active, |url| is
77 // the current page URL.
78 void UpdateVisibility(content::WebContents* contents, const GURL& url);
80 // Either notify listeners or show a popup depending on the page action.
81 void ExecuteAction(ExtensionPopup::ShowAction show_action);
83 private:
84 // Overridden from View.
85 virtual void PaintChildren(gfx::Canvas* canvas,
86 const views::CullSet& cull_set) OVERRIDE;
88 // Shows the popup, with the given URL.
89 void ShowPopupWithURL(const GURL& popup_url,
90 ExtensionPopup::ShowAction show_action);
92 // Hides the active popup, if there is one.
93 void HidePopup();
95 // The location bar view that owns us.
96 LocationBarView* owner_;
98 // The PageAction that this view represents. The PageAction is not owned by
99 // us, it resides in the extension of this particular profile.
100 ExtensionAction* page_action_;
102 // The corresponding browser.
103 Browser* browser_;
105 // The object that will be used to get the page action icon for us.
106 // It may load the icon asynchronously (in which case the initial icon
107 // returned by the factory will be transparent), so we have to observe it for
108 // updates to the icon.
109 scoped_ptr<ExtensionActionIconFactory> icon_factory_;
111 // The tab id we are currently showing the icon for.
112 int current_tab_id_;
114 // The URL we are currently showing the icon for.
115 GURL current_url_;
117 // The string to show for a tooltip;
118 std::string tooltip_;
120 // This is used for post-install visual feedback. The page_action icon is
121 // briefly shown even if it hasn't been enabled by its extension.
122 bool preview_enabled_;
124 // The current popup and the button it came from. NULL if no popup.
125 ExtensionPopup* popup_;
127 // The extension command accelerator this page action is listening for (to
128 // show the popup).
129 scoped_ptr<ui::Accelerator> page_action_keybinding_;
131 scoped_ptr<views::MenuRunner> menu_runner_;
133 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView);
136 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_