• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_ERROR_UI_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_UI_H_
7 
8 #include <vector>
9 
10 #include "base/macros.h"
11 #include "base/strings/string16.h"
12 
13 namespace content {
14 class BrowserContext;
15 }
16 
17 namespace extensions {
18 
19 class ExtensionSet;
20 
21 // This class encapsulates the UI we want to show users when certain events
22 // occur related to installed extensions.
23 class ExtensionErrorUI {
24  public:
25   class Delegate {
26    public:
27     // Get the BrowserContext associated with this UI.
28     virtual content::BrowserContext* GetContext() = 0;
29 
30     // Get the set of external extensions to warn the user about.
31     virtual const ExtensionSet& GetExternalExtensions() = 0;
32 
33     // Get the set of blacklisted extensions to warn the user about.
34     virtual const ExtensionSet& GetBlacklistedExtensions() = 0;
35 
36     // Handle the user clicking to get more details on the extension alert.
37     virtual void OnAlertDetails() = 0;
38 
39     // Handle the user clicking "accept" on the extension alert.
40     virtual void OnAlertAccept() = 0;
41 
42     // Handle the alert closing.
43     virtual void OnAlertClosed() = 0;
44   };
45 
46   static ExtensionErrorUI* Create(Delegate* delegate);
47 
48   virtual ~ExtensionErrorUI();
49 
50   // Shows the installation error in a bubble view. Should return true if a
51   // bubble is shown, false if one could not be shown.
52   virtual bool ShowErrorInBubbleView() = 0;
53 
54   // Shows the extension page. Called as a result of the user clicking more
55   // info and should be only called from the context of a callback
56   // (BubbleViewDidClose or BubbleViewAccept/CancelButtonPressed).
57   // It should use the same browser as where the bubble was shown.
58   virtual void ShowExtensions() = 0;
59 
60   // Closes the error UI. This will end up calling BubbleViewDidClose, possibly
61   // synchronously.
62   virtual void Close() = 0;
63 
64  protected:
65   explicit ExtensionErrorUI(Delegate* delegate);
66 
67   // Model methods for the bubble view.
68   base::string16 GetBubbleViewTitle();
69   std::vector<base::string16> GetBubbleViewMessages();
70   base::string16 GetBubbleViewAcceptButtonLabel();
71   base::string16 GetBubbleViewCancelButtonLabel();
72 
73   // Sub-classes should call this methods based on the actions taken by the user
74   // in the error bubble.
75   void BubbleViewDidClose();  // destroys |this|
76   void BubbleViewAcceptButtonPressed();
77   void BubbleViewCancelButtonPressed();
78 
79  private:
80   base::string16 GenerateMessage();
81 
82   Delegate* delegate_;
83 
84   base::string16 message_;  // Displayed in the body of the alert.
85 
86   DISALLOW_COPY_AND_ASSIGN(ExtensionErrorUI);
87 };
88 
89 }  // namespace extensions
90 
91 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_ERROR_UI_H_
92