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;
41 virtual void OnClose() {}
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 virtual base::string16
GetMessageBody(
51 bool anchored_to_browser_action
) const = 0;
52 virtual base::string16
GetOverflowText(
53 const base::string16
& overflow_count
) const = 0;
54 virtual base::string16
GetLearnMoreLabel() const;
55 virtual GURL
GetLearnMoreUrl() const = 0;
56 virtual base::string16
GetActionButtonLabel() const = 0;
57 virtual base::string16
GetDismissButtonLabel() const = 0;
59 // Whether to show a list of extensions in the bubble.
60 virtual bool ShouldShowExtensionList() const = 0;
62 // In some cases, we want the delegate only to handle a single extension
63 // and this sets which extension.
64 virtual void RestrictToSingleExtension(const std::string
& extension_id
);
66 // Record, through UMA, how many extensions were found.
67 virtual void LogExtensionCount(size_t count
) = 0;
68 virtual void LogAction(BubbleAction action
) = 0;
70 // Has the user acknowledged info about the extension the bubble reports.
71 virtual bool HasBubbleInfoBeenAcknowledged(const std::string
& extension_id
);
72 virtual void SetBubbleInfoBeenAcknowledged(const std::string
& extension_id
,
76 Profile
* profile() const;
78 std::string
get_acknowledged_flag_pref_name() const;
79 void set_acknowledged_flag_pref_name(std::string pref_name
);
82 // A weak pointer to the profile we are associated with. Not owned by us.
85 // Name for corresponding pref that keeps if the info the bubble contains
86 // was acknowledged by user.
87 std::string acknowledged_pref_name_
;
90 ExtensionMessageBubbleController(Delegate
* delegate
, Profile
* profile
);
91 virtual ~ExtensionMessageBubbleController();
93 Delegate
* delegate() const { return delegate_
.get(); }
95 // Obtains a list of all extensions (by name) the controller knows about.
96 std::vector
<base::string16
> GetExtensionList();
98 // Obtains a list of all extensions (by id) the controller knows about.
99 const ExtensionIdList
& GetExtensionIdList();
101 // Whether to close the bubble when it loses focus.
102 virtual bool CloseOnDeactivate();
104 // Sets up the callbacks and shows the bubble.
105 virtual void Show(ExtensionMessageBubble
* bubble
);
107 // Callbacks from bubble. Declared virtual for testing purposes.
108 virtual void OnBubbleAction();
109 virtual void OnBubbleDismiss();
110 virtual void OnLinkClicked();
113 // Iterate over the known extensions and acknowledge each one.
114 void AcknowledgeExtensions();
116 // Get the data this class needs.
117 ExtensionIdList
* GetOrCreateExtensionList();
119 // A weak pointer to the profile we are associated with. Not owned by us.
122 // The list of extensions found.
123 ExtensionIdList extension_list_
;
125 // The action the user took in the bubble.
126 BubbleAction user_action_
;
128 // Our delegate supplying information about what to show in the dialog.
129 scoped_ptr
<Delegate
> delegate_
;
131 // Whether this class has initialized.
134 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleController
);
137 } // namespace extensions
139 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_