create_application_shortcut_view.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/compiler_specific.h" 13#include "chrome/browser/web_applications/web_app.h" 14#include "ui/views/controls/button/button.h" 15#include "ui/views/window/dialog_delegate.h" 16 17class FaviconDownloadHelper; 18class GURL; 19class Profile; 20class SkBitmap; 21 22namespace content { 23class WebContents; 24} 25 26namespace extensions { 27class Extension; 28} 29 30namespace views { 31class Checkbox; 32class Label; 33} 34 35// CreateShortcutViewCommon implements a dialog that asks user where to create 36// the shortcut for given web app. There are two variants of this dialog: 37// Shortcuts that load a URL in an app-like window, and shortcuts that load 38// a chrome app (the kind you see under "apps" on the new tabs page) in an app 39// window. These are implemented as subclasses of CreateShortcutViewCommon. 40class CreateApplicationShortcutView : public views::DialogDelegateView, 41 public views::ButtonListener { 42 public: 43 explicit CreateApplicationShortcutView(Profile* profile); 44 virtual ~CreateApplicationShortcutView(); 45 46 // Initialize the controls on the dialog. 47 void InitControls(); 48 49 // Overridden from views::View: 50 virtual gfx::Size GetPreferredSize() OVERRIDE; 51 52 // Overridden from views::DialogDelegate: 53 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; 54 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; 55 virtual bool CanResize() const OVERRIDE; 56 virtual bool CanMaximize() const OVERRIDE; 57 virtual ui::ModalType GetModalType() const OVERRIDE; 58 virtual string16 GetWindowTitle() const OVERRIDE; 59 virtual bool Accept() OVERRIDE; 60 61 // Overridden from views::ButtonListener: 62 virtual void ButtonPressed(views::Button* sender, 63 const ui::Event& event) OVERRIDE; 64 65 protected: 66 // Adds a new check-box as a child to the view. 67 views::Checkbox* AddCheckbox(const string16& text, bool checked); 68 69 // Profile in which the shortcuts will be created. 70 Profile* profile_; 71 72 // UI elements on the dialog. 73 views::View* app_info_; 74 views::Label* create_shortcuts_label_; 75 views::Checkbox* desktop_check_box_; 76 views::Checkbox* menu_check_box_; 77 views::Checkbox* quick_launch_check_box_; 78 79 // Target shortcut info. 80 ShellIntegration::ShortcutInfo shortcut_info_; 81 string16 shortcut_menu_subdir_; 82 83 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView); 84}; 85 86// Create an application shortcut pointing to a URL. 87class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView { 88 public: 89 explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents); 90 virtual ~CreateUrlApplicationShortcutView(); 91 92 virtual bool Accept() OVERRIDE; 93 94 private: 95 // Fetch the largest unprocessed icon. 96 // The first largest icon downloaded and decoded successfully will be used. 97 void FetchIcon(); 98 99 // Favicon download callback. 100 void DidDownloadFavicon( 101 int id, 102 int http_status_code, 103 const GURL& image_url, 104 int requested_size, 105 const std::vector<SkBitmap>& bitmaps); 106 107 // The tab whose URL is being turned into an app. 108 content::WebContents* web_contents_; 109 110 // Pending app icon download tracked by us. 111 int pending_download_id_; 112 113 // Unprocessed icons from the WebApplicationInfo passed in. 114 web_app::IconInfoList unprocessed_icons_; 115 116 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView); 117}; 118 119// Create an application shortcut pointing to a chrome application. 120class CreateChromeApplicationShortcutView 121 : public CreateApplicationShortcutView { 122 public: 123 CreateChromeApplicationShortcutView(Profile* profile, 124 const extensions::Extension* app); 125 virtual ~CreateChromeApplicationShortcutView(); 126 127 private: 128 void OnShortcutInfoLoaded( 129 const ShellIntegration::ShortcutInfo& shortcut_info); 130 131 const extensions::Extension* app_; 132 133 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; 134 135 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); 136}; 137 138#endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 139