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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_
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"
17 class FaviconDownloadHelper
;
26 namespace extensions
{
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.
40 class CreateApplicationShortcutView
: public views::DialogDelegateView
,
41 public views::ButtonListener
{
43 explicit CreateApplicationShortcutView(Profile
* profile
);
44 virtual ~CreateApplicationShortcutView();
46 // Initialize the controls on the dialog.
49 // Overridden from views::View:
50 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
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 ui::ModalType
GetModalType() const OVERRIDE
;
56 virtual string16
GetWindowTitle() const OVERRIDE
;
57 virtual bool Accept() OVERRIDE
;
59 // Overridden from views::ButtonListener:
60 virtual void ButtonPressed(views::Button
* sender
,
61 const ui::Event
& event
) OVERRIDE
;
64 // Adds a new check-box as a child to the view.
65 views::Checkbox
* AddCheckbox(const string16
& text
, bool checked
);
67 // Profile in which the shortcuts will be created.
70 // UI elements on the dialog.
71 views::View
* app_info_
;
72 views::Label
* create_shortcuts_label_
;
73 views::Checkbox
* desktop_check_box_
;
74 views::Checkbox
* menu_check_box_
;
75 views::Checkbox
* quick_launch_check_box_
;
77 // Target shortcut info.
78 ShellIntegration::ShortcutInfo shortcut_info_
;
79 string16 shortcut_menu_subdir_
;
81 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView
);
84 // Create an application shortcut pointing to a URL.
85 class CreateUrlApplicationShortcutView
: public CreateApplicationShortcutView
{
87 explicit CreateUrlApplicationShortcutView(content::WebContents
* web_contents
);
88 virtual ~CreateUrlApplicationShortcutView();
90 virtual bool Accept() OVERRIDE
;
93 // Fetch the largest unprocessed icon.
94 // The first largest icon downloaded and decoded successfully will be used.
97 // Favicon download callback.
98 void DidDownloadFavicon(
100 int http_status_code
,
101 const GURL
& image_url
,
103 const std::vector
<SkBitmap
>& bitmaps
);
105 // The tab whose URL is being turned into an app.
106 content::WebContents
* web_contents_
;
108 // Pending app icon download tracked by us.
109 int pending_download_id_
;
111 // Unprocessed icons from the WebApplicationInfo passed in.
112 web_app::IconInfoList unprocessed_icons_
;
114 base::WeakPtrFactory
<CreateUrlApplicationShortcutView
> weak_ptr_factory_
;
116 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView
);
119 // Create an application shortcut pointing to a chrome application.
120 class CreateChromeApplicationShortcutView
121 : public CreateApplicationShortcutView
{
123 CreateChromeApplicationShortcutView(
125 const extensions::Extension
* app
,
126 const base::Closure
& close_callback
);
127 virtual ~CreateChromeApplicationShortcutView();
128 virtual bool Accept() OVERRIDE
;
129 virtual bool Cancel() OVERRIDE
;
132 void OnShortcutInfoLoaded(
133 const ShellIntegration::ShortcutInfo
& shortcut_info
);
135 const extensions::Extension
* app_
;
136 base::Closure close_callback_
;
138 base::WeakPtrFactory
<CreateChromeApplicationShortcutView
> weak_ptr_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView
);
143 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_