OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ |
7 | 7 |
| 8 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/extensions/extension_message_bubble.h" | 11 #include "chrome/browser/extensions/extension_message_bubble.h" |
| 12 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
11 #include "ui/views/bubble/bubble_delegate.h" | 13 #include "ui/views/bubble/bubble_delegate.h" |
12 #include "ui/views/controls/button/button.h" | 14 #include "ui/views/controls/button/button.h" |
13 #include "ui/views/controls/link_listener.h" | 15 #include "ui/views/controls/link_listener.h" |
14 | 16 |
15 class Profile; | 17 class Profile; |
| 18 class BrowserActionsContainer; |
| 19 class ToolbarView; |
16 | 20 |
17 namespace views { | 21 namespace views { |
18 class Label; | 22 class Label; |
19 class LabelButton; | 23 class LabelButton; |
20 class View; | 24 class View; |
21 } | 25 } |
22 | 26 |
23 namespace extensions { | 27 namespace extensions { |
24 | 28 |
| 29 class DevModeBubbleController; |
25 class ExtensionMessageBubbleController; | 30 class ExtensionMessageBubbleController; |
26 | 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 ~ExtensionMessageBubbleFactory() override; |
| 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 void OnBrowserActionsContainerAnimationEnded() override; |
| 85 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 |
27 // This is a class that implements the UI for the bubble showing which | 144 // This is a class that implements the UI for the bubble showing which |
28 // extensions look suspicious and have therefore been automatically disabled. | 145 // extensions look suspicious and have therefore been automatically disabled. |
29 class ExtensionMessageBubbleView : public ExtensionMessageBubble, | 146 class ExtensionMessageBubbleView : public ExtensionMessageBubble, |
30 public views::BubbleDelegateView, | 147 public views::BubbleDelegateView, |
31 public views::ButtonListener, | 148 public views::ButtonListener, |
32 public views::LinkListener { | 149 public views::LinkListener { |
33 public: | 150 public: |
34 ExtensionMessageBubbleView( | 151 ExtensionMessageBubbleView( |
35 views::View* anchor_view, | 152 views::View* anchor_view, |
36 views::BubbleBorder::Arrow arrow_location, | 153 views::BubbleBorder::Arrow arrow_location, |
37 scoped_ptr<ExtensionMessageBubbleController> controller); | 154 scoped_ptr<ExtensionMessageBubbleController> controller); |
38 | 155 |
39 // ExtensionMessageBubble methods. | 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; |
40 void Show() override; | 160 void Show() override; |
41 | 161 |
42 // WidgetObserver methods. | 162 // WidgetObserver methods. |
43 void OnWidgetDestroying(views::Widget* widget) override; | 163 void OnWidgetDestroying(views::Widget* widget) override; |
44 | 164 |
45 private: | 165 private: |
46 ~ExtensionMessageBubbleView() override; | 166 ~ExtensionMessageBubbleView() override; |
47 | 167 |
48 void ShowBubble(); | 168 void ShowBubble(); |
49 | 169 |
(...skipping 21 matching lines...) Expand all Loading... |
71 views::Label* headline_; | 191 views::Label* headline_; |
72 views::Link* learn_more_; | 192 views::Link* learn_more_; |
73 views::LabelButton* action_button_; | 193 views::LabelButton* action_button_; |
74 views::LabelButton* dismiss_button_; | 194 views::LabelButton* dismiss_button_; |
75 | 195 |
76 // All actions (link, button, esc) close the bubble, but we need to | 196 // All actions (link, button, esc) close the bubble, but we need to |
77 // make sure we don't send dismiss if the link was clicked. | 197 // make sure we don't send dismiss if the link was clicked. |
78 bool link_clicked_; | 198 bool link_clicked_; |
79 bool action_taken_; | 199 bool action_taken_; |
80 | 200 |
| 201 // Callbacks into the controller. |
| 202 base::Closure action_callback_; |
| 203 base::Closure dismiss_callback_; |
| 204 base::Closure link_callback_; |
| 205 |
81 base::WeakPtrFactory<ExtensionMessageBubbleView> weak_factory_; | 206 base::WeakPtrFactory<ExtensionMessageBubbleView> weak_factory_; |
82 | 207 |
83 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleView); | 208 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleView); |
84 }; | 209 }; |
85 | 210 |
86 } // namespace extensions | 211 } // namespace extensions |
87 | 212 |
88 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ | 213 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_VIEW_H_ |
OLD | NEW |