Remove keyboard_ui.css and manifest_keyboard.json
[chromium-blink-merge.git] / chrome / browser / extensions / extension_message_bubble_controller.h
blob6d6e803f31e62cef15abc6b1dbec3bf7e7f0cc09
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_
8 #include <string>
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"
13 class Browser;
14 class Profile;
16 namespace extensions {
18 class ExtensionPrefs;
19 class SuspiciousExtensionBubble;
21 class ExtensionMessageBubbleController {
22 public:
23 // UMA histogram constants.
24 enum BubbleAction {
25 ACTION_LEARN_MORE = 0,
26 ACTION_EXECUTE,
27 ACTION_DISMISS,
28 ACTION_BOUNDARY, // Must be the last value.
31 class Delegate {
32 public:
33 explicit Delegate(Profile* profile);
34 virtual ~Delegate();
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
64 // the toolbar.
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,
78 bool value);
80 protected:
81 Profile* profile() const;
83 std::string get_acknowledged_flag_pref_name() const;
84 void set_acknowledged_flag_pref_name(std::string pref_name);
86 private:
87 // A weak pointer to the profile we are associated with. Not owned by us.
88 Profile* profile_;
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
115 // times.
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();
126 private:
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.
134 void OnClose();
136 // A weak pointer to the profile we are associated with. Not owned by us.
137 Profile* profile_;
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.
149 bool initialized_;
151 // Whether or not the bubble is highlighting extensions.
152 bool did_highlight_;
154 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleController);
157 } // namespace extensions
159 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_