Home | History | Annotate | Download | only in gtk
      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_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_
      6 #define CHROME_BROWSER_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/sequenced_task_runner_helpers.h"
     12 #include "chrome/browser/shell_integration.h"
     13 #include "content/public/browser/browser_thread.h"
     14 #include "ui/base/gtk/gtk_signal.h"
     15 #include "url/gurl.h"
     16 
     17 using content::BrowserThread;
     18 
     19 typedef struct _GdkPixbuf GdkPixbuf;
     20 typedef struct _GtkWidget GtkWidget;
     21 typedef struct _GtkWindow GtkWindow;
     22 
     23 class Profile;
     24 
     25 namespace content {
     26 class WebContents;
     27 }
     28 
     29 namespace extensions {
     30 class Extension;
     31 }
     32 
     33 namespace gfx {
     34 class ImageFamily;
     35 }
     36 
     37 class CreateApplicationShortcutsDialogGtk
     38     : public base::RefCountedThreadSafe<CreateApplicationShortcutsDialogGtk,
     39                                         BrowserThread::DeleteOnUIThread> {
     40  protected:
     41   explicit CreateApplicationShortcutsDialogGtk(GtkWindow* parent);
     42   virtual ~CreateApplicationShortcutsDialogGtk();
     43 
     44   CHROMEGTK_CALLBACK_1(CreateApplicationShortcutsDialogGtk, void,
     45                        OnCreateDialogResponse, int);
     46 
     47   CHROMEGTK_CALLBACK_1(CreateApplicationShortcutsDialogGtk, void,
     48                        OnErrorDialogResponse, int);
     49 
     50   CHROMEGTK_CALLBACK_0(CreateApplicationShortcutsDialogGtk, void,
     51                        OnToggleCheckbox);
     52 
     53   virtual void CreateDialogBox(GtkWindow* parent);
     54   virtual void CreateIconPixBuf(const gfx::ImageFamily& image);
     55 
     56   // This method is called after a shortcut is created.
     57   // Subclasses can override it to take some action at that time.
     58   virtual void OnCreatedShortcut(void) {}
     59 
     60   virtual void CreateDesktopShortcut(
     61       const ShellIntegration::ShortcutInfo& shortcut_info,
     62       const ShellIntegration::ShortcutLocations& creation_locations);
     63   virtual void ShowErrorDialog();
     64 
     65   GtkWindow* parent_;
     66 
     67   // UI elements.
     68   GtkWidget* desktop_checkbox_;
     69   GtkWidget* menu_checkbox_;
     70 
     71   // ShortcutInfo for the new shortcut.
     72   ShellIntegration::ShortcutInfo shortcut_info_;
     73   string16 shortcut_menu_subdir_;
     74 
     75   // Image associated with the site or app, scaled to the appropriate size to
     76   // display in the dialog box.
     77   GdkPixbuf* favicon_pixbuf_;
     78 
     79   // Dialog box that allows the user to create an application shortcut.
     80   GtkWidget* create_dialog_;
     81 
     82   // Dialog box that shows the error message.
     83   GtkWidget* error_dialog_;
     84 
     85  private:
     86   friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
     87   friend class base::DeleteHelper<CreateApplicationShortcutsDialogGtk>;
     88   DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutsDialogGtk);
     89 };
     90 
     91 class CreateWebApplicationShortcutsDialogGtk
     92     : public CreateApplicationShortcutsDialogGtk {
     93  public:
     94   // Displays the dialog box to create application shortcuts for |web_contents|.
     95   static void Show(GtkWindow* parent, content::WebContents* web_contents);
     96 
     97   CreateWebApplicationShortcutsDialogGtk(GtkWindow* parent,
     98                                          content::WebContents* web_contents);
     99 
    100   virtual void OnCreatedShortcut(void) OVERRIDE;
    101 
    102  protected:
    103   virtual ~CreateWebApplicationShortcutsDialogGtk() {}
    104 
    105  private:
    106   // WebContents for which the shortcut will be created.
    107   content::WebContents* web_contents_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(CreateWebApplicationShortcutsDialogGtk);
    110 };
    111 
    112 class CreateChromeApplicationShortcutsDialogGtk
    113   : public CreateApplicationShortcutsDialogGtk {
    114  public:
    115   // Displays the dialog box to create application shortcuts for |app|.
    116   static void Show(GtkWindow* parent, Profile* profile,
    117                    const extensions::Extension* app);
    118 
    119   CreateChromeApplicationShortcutsDialogGtk(GtkWindow* parent,
    120                                             Profile* profile,
    121                                             const extensions::Extension* app);
    122 
    123 
    124  protected:
    125   virtual ~CreateChromeApplicationShortcutsDialogGtk() {}
    126 
    127   virtual void CreateDesktopShortcut(
    128       const ShellIntegration::ShortcutInfo& shortcut_info,
    129       const ShellIntegration::ShortcutLocations& creation_locations) OVERRIDE;
    130 
    131  private:
    132   void OnShortcutInfoLoaded(
    133       const ShellIntegration::ShortcutInfo& shortcut_info);
    134 
    135  private:
    136   const extensions::Extension* app_;
    137   base::FilePath profile_path_;
    138   DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutsDialogGtk);
    139 };
    140 
    141 #endif  // CHROME_BROWSER_UI_GTK_CREATE_APPLICATION_SHORTCUTS_DIALOG_GTK_H_
    142