• 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_UNINSTALL_DIALOG_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "ui/gfx/image/image_skia.h"
15 
16 class Browser;
17 class Profile;
18 
19 namespace base {
20 class MessageLoop;
21 }
22 
23 namespace gfx {
24 class Image;
25 }
26 
27 namespace extensions {
28 class Extension;
29 
30 class ExtensionUninstallDialog
31     : public content::NotificationObserver,
32       public base::SupportsWeakPtr<ExtensionUninstallDialog> {
33  public:
34   class Delegate {
35    public:
36     // We call this method to signal that the uninstallation should continue.
37     virtual void ExtensionUninstallAccepted() = 0;
38 
39     // We call this method to signal that the uninstallation should stop.
40     virtual void ExtensionUninstallCanceled() = 0;
41 
42    protected:
~Delegate()43     virtual ~Delegate() {}
44   };
45 
46   // Creates a platform specific implementation of ExtensionUninstallDialog.
47   // |profile| and |delegate| can never be NULL.
48   // |browser| can be NULL only for Ash when this is used with the applist
49   // window.
50   static ExtensionUninstallDialog* Create(Profile* profile,
51                                           Browser* browser,
52                                           Delegate* delegate);
53 
54   virtual ~ExtensionUninstallDialog();
55 
56   // This is called to verify whether the uninstallation should proceed.
57   // Starts the process of showing a confirmation UI, which is split into two.
58   // 1) Set off a 'load icon' task.
59   // 2) Handle the load icon response and show the UI (OnImageLoaded).
60   void ConfirmUninstall(const Extension* extension);
61 
62   // This shows the same dialog as above, except it also shows which extension
63   // triggered the dialog by calling chrome.management.uninstall API.
64   void ConfirmProgrammaticUninstall(const Extension* extension,
65                                     const Extension* triggering_extension);
66 
67   std::string GetHeadingText();
68 
69  protected:
70   // Constructor used by the derived classes.
71   ExtensionUninstallDialog(Profile* profile,
72                            Browser* browser,
73                            Delegate* delegate);
74 
75   Profile* const profile_;
76 
77   Browser* browser_;
78 
79   // The delegate we will call Accepted/Canceled on after confirmation dialog.
80   Delegate* delegate_;
81 
82   // The extension we are showing the dialog for.
83   const Extension* extension_;
84 
85   // The extension triggering the dialog if the dialog was shown by
86   // chrome.management.uninstall.
87   const Extension* triggering_extension_;
88 
89   // The extensions icon.
90   gfx::ImageSkia icon_;
91 
92  private:
93   // Sets the icon that will be used in the dialog. If |icon| contains an empty
94   // image, then we use a default icon instead.
95   void SetIcon(const gfx::Image& image);
96 
97   void OnImageLoaded(const std::string& extension_id, const gfx::Image& image);
98 
99   // content::NotificationObserver implementation.
100   virtual void Observe(int type,
101                        const content::NotificationSource& source,
102                        const content::NotificationDetails& details) OVERRIDE;
103 
104   // Displays the prompt. This should only be called after loading the icon.
105   // The implementations of this method are platform-specific.
106   virtual void Show() = 0;
107 
108   // Keeps track of whether we're still waiting for an image to load before
109   // we show the dialog.
110   enum State {
111     kImageIsLoading,  // Image is loading asynchronously.
112     kDialogIsShowing, // Dialog is shown after image is loaded.
113     kBrowserIsClosing // Browser is closed while image is still loading.
114   };
115   State state_;
116 
117   base::MessageLoop* ui_loop_;
118 
119   content::NotificationRegistrar registrar_;
120 
121   DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog);
122 };
123 
124 }  // namespace extensions
125 
126 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_
127