• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_
7 
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"
12 
13 class Browser;
14 class Profile;
15 
16 namespace extensions {
17 
18 class ExtensionPrefs;
19 class SuspiciousExtensionBubble;
20 
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.
29   };
30 
31   class Delegate {
32    public:
33     Delegate();
34     virtual ~Delegate();
35 
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;
OnClose()41     virtual void OnClose() {}
42 
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 = 0;
55     virtual GURL GetLearnMoreUrl() const = 0;
56     virtual base::string16 GetActionButtonLabel() const = 0;
57     virtual base::string16 GetDismissButtonLabel() const = 0;
58 
59     // Whether to show a list of extensions in the bubble.
60     virtual bool ShouldShowExtensionList() const = 0;
61 
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);
65 
66     // Record, through UMA, how many extensions were found.
67     virtual void LogExtensionCount(size_t count) = 0;
68     virtual void LogAction(BubbleAction action) = 0;
69   };
70 
71   ExtensionMessageBubbleController(Delegate* delegate, Profile* profile);
72   virtual ~ExtensionMessageBubbleController();
73 
delegate()74   Delegate* delegate() const { return delegate_.get(); }
75 
76   // Obtains a list of all extensions (by name) the controller knows about.
77   std::vector<base::string16> GetExtensionList();
78 
79   // Obtains a list of all extensions (by id) the controller knows about.
80   const ExtensionIdList& GetExtensionIdList();
81 
82   // Whether to close the bubble when it loses focus.
83   virtual bool CloseOnDeactivate();
84 
85   // Sets up the callbacks and shows the bubble.
86   virtual void Show(ExtensionMessageBubble* bubble);
87 
88   // Callbacks from bubble. Declared virtual for testing purposes.
89   virtual void OnBubbleAction();
90   virtual void OnBubbleDismiss();
91   virtual void OnLinkClicked();
92 
93  private:
94   // Iterate over the known extensions and acknowledge each one.
95   void AcknowledgeExtensions();
96 
97   // Get the data this class needs.
98   ExtensionIdList* GetOrCreateExtensionList();
99 
100   // A weak pointer to the profile we are associated with. Not owned by us.
101   Profile* profile_;
102 
103   // The list of extensions found.
104   ExtensionIdList extension_list_;
105 
106   // The action the user took in the bubble.
107   BubbleAction user_action_;
108 
109   // Our delegate supplying information about what to show in the dialog.
110   scoped_ptr<Delegate> delegate_;
111 
112   // Whether this class has initialized.
113   bool initialized_;
114 
115   DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleController);
116 };
117 
118 }  // namespace extensions
119 
120 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_BUBBLE_CONTROLLER_H_
121