33e6c3b1069f2a3521039ff4032acd090fb093bc
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_uninstall_dialog.h
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/weak_ptr.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/native_widget_types.h"
13
14 class Profile;
15
16 namespace base {
17 class MessageLoop;
18 }
19
20 namespace gfx {
21 class Image;
22 }
23
24 namespace extensions {
25 class Extension;
26
27 class ExtensionUninstallDialog
28     : public base::SupportsWeakPtr<ExtensionUninstallDialog> {
29  public:
30   class Delegate {
31    public:
32     // We call this method to signal that the uninstallation should continue.
33     virtual void ExtensionUninstallAccepted() = 0;
34
35     // We call this method to signal that the uninstallation should stop.
36     virtual void ExtensionUninstallCanceled() = 0;
37
38    protected:
39     virtual ~Delegate() {}
40   };
41
42   // Creates a platform specific implementation of ExtensionUninstallDialog. The
43   // dialog will be modal to |parent|, or a non-modal dialog if |parent| is
44   // NULL.
45   static ExtensionUninstallDialog* Create(Profile* profile,
46                                           gfx::NativeWindow parent,
47                                           Delegate* delegate);
48
49   virtual ~ExtensionUninstallDialog();
50
51   // This is called to verify whether the uninstallation should proceed.
52   // Starts the process of showing a confirmation UI, which is split into two.
53   // 1) Set off a 'load icon' task.
54   // 2) Handle the load icon response and show the UI (OnImageLoaded).
55   void ConfirmUninstall(const Extension* extension);
56
57   // This shows the same dialog as above, except it also shows which extension
58   // triggered the dialog by calling chrome.management.uninstall API.
59   void ConfirmProgrammaticUninstall(const Extension* extension,
60                                     const Extension* triggering_extension);
61
62   std::string GetHeadingText();
63
64  protected:
65   // Constructor used by the derived classes.
66   ExtensionUninstallDialog(Profile* profile,
67                            gfx::NativeWindow parent,
68                            Delegate* delegate);
69
70   // TODO(sashab): Remove protected members: crbug.com/397395
71   Profile* const profile_;
72
73   // TODO(sashab): Investigate lifetime issue of this window variable:
74   // crbug.com/397396
75   gfx::NativeWindow parent_;
76
77   // The delegate we will call Accepted/Canceled on after confirmation dialog.
78   Delegate* delegate_;
79
80   // The extension we are showing the dialog for.
81   const Extension* extension_;
82
83   // The extension triggering the dialog if the dialog was shown by
84   // chrome.management.uninstall.
85   const Extension* triggering_extension_;
86
87   // The extensions icon.
88   gfx::ImageSkia icon_;
89
90  private:
91   // Sets the icon that will be used in the dialog. If |icon| contains an empty
92   // image, then we use a default icon instead.
93   void SetIcon(const gfx::Image& image);
94
95   void OnImageLoaded(const std::string& extension_id, const gfx::Image& image);
96
97   // Displays the prompt. This should only be called after loading the icon.
98   // The implementations of this method are platform-specific.
99   virtual void Show() = 0;
100
101   base::MessageLoop* ui_loop_;
102
103   DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog);
104 };
105
106 }  // namespace extensions
107
108 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_UNINSTALL_DIALOG_H_