Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / extensions / extension_message_bubble_view.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_
7
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"
16
17 class Profile;
18 class BrowserActionsContainer;
19 class ToolbarView;
20
21 namespace views {
22 class Label;
23 class LabelButton;
24 class View;
25 }
26
27 namespace extensions {
28
29 class DevModeBubbleController;
30 class ExtensionMessageBubbleController;
31
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();
42
43   void MaybeShow(views::View* anchor_view);
44
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 };
52
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);
57
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);
62
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);
67
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);
72
73   // Starts or stops observing the BrowserActionsContainer, if necessary.
74   void MaybeObserve();
75   void MaybeStopObserving();
76
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);
82
83   // BrowserActionsContainer::Observer implementation.
84   virtual void OnBrowserActionsContainerAnimationEnded() OVERRIDE;
85   virtual void OnBrowserActionsContainerDestroyed() OVERRIDE;
86
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);
92
93   // Inform the ExtensionToolbarModel to highlight the appropriate extensions.
94   void HighlightExtensions();
95
96   // Shows the waiting bubbble, after highlighting the extensions.
97   void ShowHighlightingBubble();
98
99   // Finishes the process of showing the developer mode bubble.
100   void Finish();
101
102   // The associated profile.
103   Profile* profile_;
104
105   // The toolbar view that the ExtensionMessageBubbleViews will attach to.
106   ToolbarView* toolbar_view_;
107
108   // Whether or not we have shown the suspicious extensions bubble.
109   bool shown_suspicious_extensions_bubble_;
110
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_;
114
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_;
118
119   // Whether or not we have shown the developer mode extensions bubble.
120   bool shown_dev_mode_extensions_bubble_;
121
122   // Whether or not we are already observing the BrowserActionsContainer (so
123   // we don't add ourselves twice).
124   bool is_observing_;
125
126   // The current stage of showing the bubble.
127   Stage stage_;
128
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_;
132
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_;
136
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_;
140
141   DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleFactory);
142 };
143
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);
155
156   // ExtensionMessageBubble methods.
157   virtual void OnActionButtonClicked(const base::Closure& callback) OVERRIDE;
158   virtual void OnDismissButtonClicked(const base::Closure& callback) OVERRIDE;
159   virtual void OnLinkClicked(const base::Closure& callback) OVERRIDE;
160   virtual void Show() OVERRIDE;
161
162   // WidgetObserver methods.
163   virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
164
165  private:
166   virtual ~ExtensionMessageBubbleView();
167
168   void ShowBubble();
169
170   // views::BubbleDelegateView overrides:
171   virtual void Init() OVERRIDE;
172
173   // views::ButtonListener implementation.
174   virtual void ButtonPressed(views::Button* sender,
175                              const ui::Event& event) OVERRIDE;
176
177   // views::LinkListener implementation.
178   virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
179
180   // views::View implementation.
181   virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
182   virtual void ViewHierarchyChanged(const ViewHierarchyChangedDetails& details)
183       OVERRIDE;
184
185   // The controller for this bubble.
186   scoped_ptr<ExtensionMessageBubbleController> controller_;
187
188   // The view this bubble is anchored against.
189   views::View* anchor_view_;
190
191   // The headline, labels and buttons on the bubble.
192   views::Label* headline_;
193   views::Link* learn_more_;
194   views::LabelButton* action_button_;
195   views::LabelButton* dismiss_button_;
196
197   // All actions (link, button, esc) close the bubble, but we need to
198   // make sure we don't send dismiss if the link was clicked.
199   bool link_clicked_;
200   bool action_taken_;
201
202   // Callbacks into the controller.
203   base::Closure action_callback_;
204   base::Closure dismiss_callback_;
205   base::Closure link_callback_;
206
207   base::WeakPtrFactory<ExtensionMessageBubbleView> weak_factory_;
208
209   DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleView);
210 };
211
212 }  // namespace extensions
213
214 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_