Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_message_bubble_view.h
blobeadaf716feffa9861002ae7e6e6f9ead6abae0f6
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 ~ExtensionMessageBubbleFactory() override;
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 bubble for when there are extensions overriding the proxy (if we
64 // have not done so already). Returns true if we show the view (or start the
65 // process of doing so).
66 bool MaybeShowProxyOverrideExtensionsBubble(views::View* anchor_view);
68 // Shows the developer mode extensions bubble, if there are extensions running
69 // in developer mode and we have not done so already.
70 // Returns true if we show the view (or start the process).
71 bool MaybeShowDevModeExtensionsBubble(views::View* anchor_view);
73 // Starts or stops observing the BrowserActionsContainer, if necessary.
74 void MaybeObserve();
75 void MaybeStopObserving();
77 // Adds |profile| to the list of profiles that have been evaluated for showing
78 // a bubble. Handy for things that only want to check once per profile.
79 void RecordProfileCheck(Profile* profile);
80 // Returns false if this profile has been evaluated before.
81 bool IsInitialProfileCheck(Profile* profile);
83 // BrowserActionsContainer::Observer implementation.
84 void OnBrowserActionsContainerAnimationEnded() override;
85 void OnBrowserActionsContainerDestroyed() override;
87 // Sets the stage for highlighting extensions and then showing the bubble
88 // controlled by |controller|, anchored to |anchor_view|.
89 void PrepareToHighlightExtensions(
90 scoped_ptr<ExtensionMessageBubbleController> controller,
91 views::View* anchor_view);
93 // Inform the ExtensionToolbarModel to highlight the appropriate extensions.
94 void HighlightExtensions();
96 // Shows the waiting bubbble, after highlighting the extensions.
97 void ShowHighlightingBubble();
99 // Finishes the process of showing the developer mode bubble.
100 void Finish();
102 // The associated profile.
103 Profile* profile_;
105 // The toolbar view that the ExtensionMessageBubbleViews will attach to.
106 ToolbarView* toolbar_view_;
108 // Whether or not we have shown the suspicious extensions bubble.
109 bool shown_suspicious_extensions_bubble_;
111 // Whether or not we have shown the Settings API extensions bubble notifying
112 // the user about the startup pages being overridden.
113 bool shown_startup_override_extensions_bubble_;
115 // Whether or not we have shown the bubble notifying the user about the proxy
116 // being overridden.
117 bool shown_proxy_override_extensions_bubble_;
119 // Whether or not we have shown the developer mode extensions bubble.
120 bool shown_dev_mode_extensions_bubble_;
122 // Whether or not we are already observing the BrowserActionsContainer (so
123 // we don't add ourselves twice).
124 bool is_observing_;
126 // The current stage of showing the bubble.
127 Stage stage_;
129 // The BrowserActionsContainer for the profile. This will be NULL if the
130 // factory is not currently in the process of showing a bubble.
131 BrowserActionsContainer* container_;
133 // The default view to anchor the bubble to. This will be NULL if the factory
134 // is not currently in the process of showing a bubble.
135 views::View* anchor_view_;
137 // The controller to show a bubble for. This will be NULL if the factory is
138 // not currently in the process of showing a bubble.
139 scoped_ptr<ExtensionMessageBubbleController> controller_;
141 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleFactory);
144 // This is a class that implements the UI for the bubble showing which
145 // extensions look suspicious and have therefore been automatically disabled.
146 class ExtensionMessageBubbleView : public ExtensionMessageBubble,
147 public views::BubbleDelegateView,
148 public views::ButtonListener,
149 public views::LinkListener {
150 public:
151 ExtensionMessageBubbleView(
152 views::View* anchor_view,
153 views::BubbleBorder::Arrow arrow_location,
154 scoped_ptr<ExtensionMessageBubbleController> controller);
156 // ExtensionMessageBubble methods.
157 void OnActionButtonClicked(const base::Closure& callback) override;
158 void OnDismissButtonClicked(const base::Closure& callback) override;
159 void OnLinkClicked(const base::Closure& callback) override;
160 void Show() override;
162 // WidgetObserver methods.
163 void OnWidgetDestroying(views::Widget* widget) override;
165 private:
166 ~ExtensionMessageBubbleView() override;
168 void ShowBubble();
170 // views::BubbleDelegateView overrides:
171 void Init() override;
173 // views::ButtonListener implementation.
174 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
176 // views::LinkListener implementation.
177 void LinkClicked(views::Link* source, int event_flags) override;
179 // views::View implementation.
180 void GetAccessibleState(ui::AXViewState* state) override;
181 void ViewHierarchyChanged(
182 const ViewHierarchyChangedDetails& details) override;
184 // The controller for this bubble.
185 scoped_ptr<ExtensionMessageBubbleController> controller_;
187 // The view this bubble is anchored against.
188 views::View* anchor_view_;
190 // The headline, labels and buttons on the bubble.
191 views::Label* headline_;
192 views::Link* learn_more_;
193 views::LabelButton* action_button_;
194 views::LabelButton* dismiss_button_;
196 // All actions (link, button, esc) close the bubble, but we need to
197 // make sure we don't send dismiss if the link was clicked.
198 bool link_clicked_;
199 bool action_taken_;
201 // Callbacks into the controller.
202 base::Closure action_callback_;
203 base::Closure dismiss_callback_;
204 base::Closure link_callback_;
206 base::WeakPtrFactory<ExtensionMessageBubbleView> weak_factory_;
208 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleView);
211 } // namespace extensions
213 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_