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