[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_message_bubble_view.h
blobc615c18e40658de3a3598a2f5afe154e1f92a472
1 // Copyright (c) 2013 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_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/extensions/extension_message_bubble.h"
12 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h"
13 #include "ui/views/bubble/bubble_delegate.h"
14 #include "ui/views/controls/button/button.h"
15 #include "ui/views/controls/link_listener.h"
17 class Profile;
18 class BrowserActionsContainer;
19 class ToolbarView;
21 namespace views {
22 class Label;
23 class LabelButton;
24 class View;
27 namespace extensions {
29 class DevModeBubbleController;
30 class ExtensionMessageBubbleController;
32 // Create and show ExtensionMessageBubbles for either extensions that look
33 // suspicious and have therefore been disabled, or for extensions that are
34 // running in developer mode that we want to warn the user about.
35 // Calling MaybeShow() will show one of the bubbles, if there is cause to (we
36 // don't show both in order to avoid spamminess). The suspicious extensions
37 // bubble takes priority over the developer mode extensions bubble.
38 class ExtensionMessageBubbleFactory : public BrowserActionsContainerObserver {
39 public:
40 ExtensionMessageBubbleFactory(Profile* profile, ToolbarView* toolbar_view);
41 virtual ~ExtensionMessageBubbleFactory();
43 void MaybeShow(views::View* anchor_view);
45 private:
46 // The stage of showing the developer mode extensions bubble. STAGE_START
47 // corresponds to the beginning of the process, when nothing has been done.
48 // STAGE_HIGHLIGHTED indicates that the toolbar should be highlighting
49 // dangerous extensions. STAGE_COMPLETE means that the process should be
50 // ended.
51 enum Stage { STAGE_START, STAGE_HIGHLIGHTED, STAGE_COMPLETE };
53 // Shows the suspicious extensions bubble, if there are suspicious extensions
54 // and we have not done so already.
55 // Returns true if we have show the view.
56 bool MaybeShowSuspiciousExtensionsBubble(views::View* anchor_view);
58 // Shows the settings API extensions bubble, if there are extensions
59 // overriding the startup pages and we have not done so already.
60 // Returns true if we show the view (or start the process).
61 bool MaybeShowStartupOverrideExtensionsBubble(views::View* anchor_view);
63 // Shows the developer mode extensions bubble, if there are extensions running
64 // in developer mode and we have not done so already.
65 // Returns true if we show the view (or start the process).
66 bool MaybeShowDevModeExtensionsBubble(views::View* anchor_view);
68 // Starts or stops observing the BrowserActionsContainer, if necessary.
69 void MaybeObserve();
70 void MaybeStopObserving();
72 // Adds |profile| to the list of profiles that have been evaluated for showing
73 // a bubble. Handy for things that only want to check once per profile.
74 void RecordProfileCheck(Profile* profile);
75 // Returns false if this profile has been evaluated before.
76 bool IsInitialProfileCheck(Profile* profile);
78 // BrowserActionsContainer::Observer implementation.
79 virtual void OnBrowserActionsContainerAnimationEnded() OVERRIDE;
80 virtual void OnBrowserActionsContainerDestroyed() OVERRIDE;
82 // Inform the ExtensionToolbarModel to highlight the appropriate extensions.
83 void HighlightDevModeExtensions();
85 // Shows the developer mode bubble, after highlighting the extensions.
86 void ShowDevModeBubble();
88 // Finishes the process of showing the developer mode bubble.
89 void Finish();
91 // The associated profile.
92 Profile* profile_;
94 // The toolbar view that the ExtensionMessageBubbleViews will attach to.
95 ToolbarView* toolbar_view_;
97 // Whether or not we have shown the suspicious extensions bubble.
98 bool shown_suspicious_extensions_bubble_;
100 // Whether or not we have shown the Settings API extensions bubble notifying
101 // the user about the startup pages being overridden.
102 bool shown_startup_override_extensions_bubble_;
104 // Whether or not we have shown the developer mode extensions bubble.
105 bool shown_dev_mode_extensions_bubble_;
107 // Whether or not we are already observing the BrowserActionsContainer (so
108 // we don't add ourselves twice).
109 bool is_observing_;
111 // The current stage of showing the bubble.
112 Stage stage_;
114 // The BrowserActionsContainer for the profile. This will be NULL if the
115 // factory is not currently in the process of showing a bubble.
116 BrowserActionsContainer* container_;
118 // The default view to anchor the bubble to. This will be NULL if the factory
119 // is not currently in the process of showing a bubble.
120 views::View* anchor_view_;
122 // The DevModeBubbleController to use. This will be NULL if the factory is not
123 // currently in the process of showing a bubble.
124 scoped_ptr<DevModeBubbleController> controller_;
126 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleFactory);
129 // This is a class that implements the UI for the bubble showing which
130 // extensions look suspicious and have therefore been automatically disabled.
131 class ExtensionMessageBubbleView : public ExtensionMessageBubble,
132 public views::BubbleDelegateView,
133 public views::ButtonListener,
134 public views::LinkListener {
135 public:
136 ExtensionMessageBubbleView(
137 views::View* anchor_view,
138 views::BubbleBorder::Arrow arrow_location,
139 scoped_ptr<ExtensionMessageBubbleController> controller);
141 // ExtensionMessageBubble methods.
142 virtual void OnActionButtonClicked(const base::Closure& callback) OVERRIDE;
143 virtual void OnDismissButtonClicked(const base::Closure& callback) OVERRIDE;
144 virtual void OnLinkClicked(const base::Closure& callback) OVERRIDE;
145 virtual void Show() OVERRIDE;
147 // WidgetObserver methods.
148 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
150 private:
151 virtual ~ExtensionMessageBubbleView();
153 void ShowBubble();
155 // views::BubbleDelegateView overrides:
156 virtual void Init() OVERRIDE;
158 // views::ButtonListener implementation.
159 virtual void ButtonPressed(views::Button* sender,
160 const ui::Event& event) OVERRIDE;
162 // views::LinkListener implementation.
163 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
165 // views::View implementation.
166 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
167 virtual void ViewHierarchyChanged(const ViewHierarchyChangedDetails& details)
168 OVERRIDE;
170 base::WeakPtrFactory<ExtensionMessageBubbleView> weak_factory_;
172 // The controller for this bubble.
173 scoped_ptr<ExtensionMessageBubbleController> controller_;
175 // The headline, labels and buttons on the bubble.
176 views::Label* headline_;
177 views::Link* learn_more_;
178 views::LabelButton* action_button_;
179 views::LabelButton* dismiss_button_;
181 // All actions (link, button, esc) close the bubble, but we need to
182 // make sure we don't send dismiss if the link was clicked.
183 bool link_clicked_;
184 bool action_taken_;
186 // Callbacks into the controller.
187 base::Closure action_callback_;
188 base::Closure dismiss_callback_;
189 base::Closure link_callback_;
191 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleView);
194 } // namespace extensions
196 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_