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"
16 namespace extensions
{
19 class SuspiciousExtensionBubble
;
21 class ExtensionMessageBubbleController
{
23 // UMA histogram constants.
25 ACTION_LEARN_MORE
= 0,
28 ACTION_BOUNDARY
, // Must be the last value.
33 explicit Delegate(Profile
* profile
);
36 virtual bool ShouldIncludeExtension(const std::string
& extension_id
) = 0;
37 virtual void AcknowledgeExtension(
38 const std::string
& extension_id
,
39 BubbleAction action
) = 0;
40 virtual void PerformAction(const ExtensionIdList
& list
) = 0;
42 // Text for various UI labels shown in the bubble.
43 virtual base::string16
GetTitle() const = 0;
44 // Fetches the message to show in the body. |anchored_to_browser_action|
45 // will be true if the bubble is anchored against a specific extension
46 // icon, allowing the bubble to show a different message than when it is
47 // anchored against something else (e.g. show "This extension has..."
48 // instead of "An extension has...").
49 // |extension_count| is the number of extensions being referenced.
50 virtual base::string16
GetMessageBody(
51 bool anchored_to_browser_action
,
52 int extension_count
) const = 0;
53 virtual base::string16
GetOverflowText(
54 const base::string16
& overflow_count
) const = 0;
55 virtual base::string16
GetLearnMoreLabel() const;
56 virtual GURL
GetLearnMoreUrl() const = 0;
57 virtual base::string16
GetActionButtonLabel() const = 0;
58 virtual base::string16
GetDismissButtonLabel() const = 0;
60 // Whether to show a list of extensions in the bubble.
61 virtual bool ShouldShowExtensionList() const = 0;
63 // Returns true if the set of affected extensions should be highlighted in
65 virtual bool ShouldHighlightExtensions() const = 0;
67 // In some cases, we want the delegate only to handle a single extension
68 // and this sets which extension.
69 virtual void RestrictToSingleExtension(const std::string
& extension_id
);
71 // Record, through UMA, how many extensions were found.
72 virtual void LogExtensionCount(size_t count
) = 0;
73 virtual void LogAction(BubbleAction action
) = 0;
75 // Has the user acknowledged info about the extension the bubble reports.
76 virtual bool HasBubbleInfoBeenAcknowledged(const std::string
& extension_id
);
77 virtual void SetBubbleInfoBeenAcknowledged(const std::string
& extension_id
,
81 Profile
* profile() const;
83 std::string
get_acknowledged_flag_pref_name() const;
84 void set_acknowledged_flag_pref_name(std::string pref_name
);
87 // A weak pointer to the profile we are associated with. Not owned by us.
90 // Name for corresponding pref that keeps if the info the bubble contains
91 // was acknowledged by user.
92 std::string acknowledged_pref_name_
;
95 ExtensionMessageBubbleController(Delegate
* delegate
, Profile
* profile
);
96 virtual ~ExtensionMessageBubbleController();
98 Delegate
* delegate() const { return delegate_
.get(); }
100 // Obtains a list of all extensions (by name) the controller knows about.
101 std::vector
<base::string16
> GetExtensionList();
103 // Returns the list of all extensions to display in the bubble, including
104 // bullets and newlines. If the extension list should not be displayed,
105 // returns an empty string.
106 base::string16
GetExtensionListForDisplay();
108 // Obtains a list of all extensions (by id) the controller knows about.
109 const ExtensionIdList
& GetExtensionIdList();
111 // Whether to close the bubble when it loses focus.
112 virtual bool CloseOnDeactivate();
114 // Highlights the affected extensions if appropriate. Safe to call multiple
116 void HighlightExtensionsIfNecessary();
118 // Sets up the callbacks and shows the bubble.
119 virtual void Show(ExtensionMessageBubble
* bubble
);
121 // Callbacks from bubble. Declared virtual for testing purposes.
122 virtual void OnBubbleAction();
123 virtual void OnBubbleDismiss();
124 virtual void OnLinkClicked();
127 // Iterate over the known extensions and acknowledge each one.
128 void AcknowledgeExtensions();
130 // Get the data this class needs.
131 ExtensionIdList
* GetOrCreateExtensionList();
133 // Performs cleanup after the bubble closes.
136 // A weak pointer to the profile we are associated with. Not owned by us.
139 // The list of extensions found.
140 ExtensionIdList extension_list_
;
142 // The action the user took in the bubble.
143 BubbleAction user_action_
;
145 // Our delegate supplying information about what to show in the dialog.
146 scoped_ptr
<Delegate
> delegate_
;
148 // Whether this class has initialized.
151 // Whether or not the bubble is highlighting extensions.
154 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleController
);
157 } // namespace extensions
159 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_