1 // Copyright (c) 2011 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_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_ 7 #pragma once 8 9 #include "base/basictypes.h" 10 #include "base/memory/ref_counted.h" 11 #include "chrome/browser/extensions/image_loading_tracker.h" 12 #include "chrome/browser/shell_integration.h" 13 #include "content/browser/browser_thread.h" 14 #include "googleurl/src/gurl.h" 15 #include "ui/base/gtk/gtk_signal.h" 16 17 typedef struct _GdkPixbuf GdkPixbuf; 18 typedef struct _GtkWidget GtkWidget; 19 typedef struct _GtkWindow GtkWindow; 20 21 class Extension; 22 class TabContents; 23 class TabContentsWrapper; 24 25 class CreateApplicationShortcutsDialogGtk 26 : public base::RefCountedThreadSafe<CreateApplicationShortcutsDialogGtk, 27 BrowserThread::DeleteOnUIThread> { 28 protected: 29 explicit CreateApplicationShortcutsDialogGtk(GtkWindow* parent); 30 virtual ~CreateApplicationShortcutsDialogGtk(); 31 32 CHROMEGTK_CALLBACK_1(CreateApplicationShortcutsDialogGtk, void, 33 OnCreateDialogResponse, int); 34 35 CHROMEGTK_CALLBACK_1(CreateApplicationShortcutsDialogGtk, void, 36 OnErrorDialogResponse, int); 37 38 CHROMEGTK_CALLBACK_0(CreateApplicationShortcutsDialogGtk, void, 39 OnToggleCheckbox); 40 41 virtual void CreateDialogBox(GtkWindow* parent); 42 virtual void CreateIconPixBuf(const SkBitmap& bitmap); 43 44 // This method is called after a shortcut is created. 45 // Subclasses can override it to take some action at that time. OnCreatedShortcut(void)46 virtual void OnCreatedShortcut(void) {} 47 48 void CreateDesktopShortcut( 49 const ShellIntegration::ShortcutInfo& shortcut_info); 50 void ShowErrorDialog(); 51 52 GtkWindow* parent_; 53 54 // UI elements. 55 GtkWidget* desktop_checkbox_; 56 GtkWidget* menu_checkbox_; 57 58 // ShortcutInfo for the new shortcut. 59 ShellIntegration::ShortcutInfo shortcut_info_; 60 61 // Image associated with the site. 62 GdkPixbuf* favicon_pixbuf_; 63 64 // Dialog box that allows the user to create an application shortcut. 65 GtkWidget* create_dialog_; 66 67 // Dialog box that shows the error message. 68 GtkWidget* error_dialog_; 69 70 private: 71 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 72 friend class DeleteTask<CreateApplicationShortcutsDialogGtk>; 73 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutsDialogGtk); 74 }; 75 76 class CreateWebApplicationShortcutsDialogGtk 77 : public CreateApplicationShortcutsDialogGtk { 78 public: 79 // Displays the dialog box to create application shortcuts for |tab_contents|. 80 static void Show(GtkWindow* parent, TabContentsWrapper* tab_contents); 81 82 CreateWebApplicationShortcutsDialogGtk(GtkWindow* parent, 83 TabContentsWrapper* tab_contents); 84 virtual ~CreateWebApplicationShortcutsDialogGtk() {} 85 86 virtual void OnCreatedShortcut(void); 87 88 private: 89 90 // TabContentsWrapper for which the shortcut will be created. 91 TabContentsWrapper* tab_contents_; 92 93 DISALLOW_COPY_AND_ASSIGN(CreateWebApplicationShortcutsDialogGtk); 94 }; 95 96 class CreateChromeApplicationShortcutsDialogGtk 97 : public CreateApplicationShortcutsDialogGtk, 98 public ImageLoadingTracker::Observer { 99 public: 100 // Displays the dialog box to create application shortcuts for |app|. 101 static void Show(GtkWindow* parent, const Extension* app); 102 103 explicit CreateChromeApplicationShortcutsDialogGtk(GtkWindow* parent, 104 const Extension* app); 105 virtual ~CreateChromeApplicationShortcutsDialogGtk() {} 106 107 // Implement ImageLoadingTracker::Observer. |tracker_| is used to 108 // load the app's icon. This method recieves the icon, and adds 109 // it to the "Create Shortcut" dailog box. 110 virtual void OnImageLoaded(SkBitmap* image, 111 const ExtensionResource& resource, 112 int index); 113 114 private: 115 const Extension* app_; 116 ImageLoadingTracker tracker_; 117 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutsDialogGtk); 118 }; 119 120 #endif // CHROME_BROWSER_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_ 121