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_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_
9 #include "chrome/browser/extensions/extension_message_bubble.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
11 #include "extensions/common/extension.h"
14 class ExtensionService
;
17 namespace extensions
{
20 class ExtensionRegistry
;
22 class ExtensionMessageBubbleController
{
24 // UMA histogram constants.
26 ACTION_LEARN_MORE
= 0,
29 ACTION_BOUNDARY
, // Must be the last value.
34 explicit Delegate(Profile
* profile
);
37 virtual bool ShouldIncludeExtension(const std::string
& extension_id
) = 0;
38 virtual void AcknowledgeExtension(
39 const std::string
& extension_id
,
40 BubbleAction action
) = 0;
41 virtual void PerformAction(const ExtensionIdList
& list
) = 0;
43 // Text for various UI labels shown in the bubble.
44 virtual base::string16
GetTitle() const = 0;
45 // Fetches the message to show in the body. |anchored_to_browser_action|
46 // will be true if the bubble is anchored against a specific extension
47 // icon, allowing the bubble to show a different message than when it is
48 // anchored against something else (e.g. show "This extension has..."
49 // instead of "An extension has...").
50 // |extension_count| is the number of extensions being referenced.
51 virtual base::string16
GetMessageBody(
52 bool anchored_to_browser_action
,
53 int extension_count
) const = 0;
54 virtual base::string16
GetOverflowText(
55 const base::string16
& overflow_count
) const = 0;
56 virtual base::string16
GetLearnMoreLabel() const;
57 virtual GURL
GetLearnMoreUrl() const = 0;
58 virtual base::string16
GetActionButtonLabel() const = 0;
59 virtual base::string16
GetDismissButtonLabel() const = 0;
61 // Whether to show a list of extensions in the bubble.
62 virtual bool ShouldShowExtensionList() const = 0;
64 // Returns true if the set of affected extensions should be highlighted in
66 virtual bool ShouldHighlightExtensions() const = 0;
68 // In some cases, we want the delegate only to handle a single extension
69 // and this sets which extension.
70 virtual void RestrictToSingleExtension(const std::string
& extension_id
);
72 // Record, through UMA, how many extensions were found.
73 virtual void LogExtensionCount(size_t count
) = 0;
74 virtual void LogAction(BubbleAction action
) = 0;
76 // Has the user acknowledged info about the extension the bubble reports.
77 virtual bool HasBubbleInfoBeenAcknowledged(const std::string
& extension_id
);
78 virtual void SetBubbleInfoBeenAcknowledged(const std::string
& extension_id
,
82 Profile
* profile() { return profile_
; }
83 ExtensionService
* service() { return service_
; }
84 const ExtensionRegistry
* registry() const { return registry_
; }
86 std::string
get_acknowledged_flag_pref_name() const;
87 void set_acknowledged_flag_pref_name(std::string pref_name
);
90 // A weak pointer to the profile we are associated with. Not owned by us.
93 // The extension service associated with the profile.
94 ExtensionService
* service_
;
96 // The extension registry associated with the profile.
97 ExtensionRegistry
* registry_
;
99 // Name for corresponding pref that keeps if the info the bubble contains
100 // was acknowledged by user.
101 std::string acknowledged_pref_name_
;
103 DISALLOW_COPY_AND_ASSIGN(Delegate
);
106 ExtensionMessageBubbleController(Delegate
* delegate
, Browser
* browser
);
107 virtual ~ExtensionMessageBubbleController();
109 Delegate
* delegate() const { return delegate_
.get(); }
112 // Obtains a list of all extensions (by name) the controller knows about.
113 std::vector
<base::string16
> GetExtensionList();
115 // Returns the list of all extensions to display in the bubble, including
116 // bullets and newlines. If the extension list should not be displayed,
117 // returns an empty string.
118 base::string16
GetExtensionListForDisplay();
120 // Obtains a list of all extensions (by id) the controller knows about.
121 const ExtensionIdList
& GetExtensionIdList();
123 // Whether to close the bubble when it loses focus.
124 virtual bool CloseOnDeactivate();
126 // Highlights the affected extensions if appropriate. Safe to call multiple
128 void HighlightExtensionsIfNecessary();
130 // Sets up the callbacks and shows the bubble.
131 virtual void Show(ExtensionMessageBubble
* bubble
);
133 // Callbacks from bubble. Declared virtual for testing purposes.
134 virtual void OnBubbleAction();
135 virtual void OnBubbleDismiss();
136 virtual void OnLinkClicked();
138 static void set_should_ignore_learn_more_for_testing(
139 bool should_ignore_learn_more
);
142 // Iterate over the known extensions and acknowledge each one.
143 void AcknowledgeExtensions();
145 // Get the data this class needs.
146 ExtensionIdList
* GetOrCreateExtensionList();
148 // Performs cleanup after the bubble closes.
151 // A weak pointer to the Browser we are associated with. Not owned by us.
154 // The list of extensions found.
155 ExtensionIdList extension_list_
;
157 // The action the user took in the bubble.
158 BubbleAction user_action_
;
160 // Our delegate supplying information about what to show in the dialog.
161 scoped_ptr
<Delegate
> delegate_
;
163 // Whether this class has initialized.
166 // Whether or not the bubble is highlighting extensions.
169 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleController
);
172 } // namespace extensions
174 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_