OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | |
10 #include <vector> | |
11 | 9 |
12 #include "base/compiler_specific.h" | 10 #include "base/callback.h" |
13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" |
14 #include "chrome/browser/web_applications/web_app.h" | 14 #include "chrome/browser/web_applications/web_app.h" |
15 #include "ui/views/controls/button/button.h" | 15 #include "ui/views/controls/button/button.h" |
16 #include "ui/views/window/dialog_delegate.h" | 16 #include "ui/views/window/dialog_delegate.h" |
17 | 17 |
18 class GURL; | |
19 class Profile; | 18 class Profile; |
20 class SkBitmap; | |
21 | |
22 namespace content { | |
23 class WebContents; | |
24 } | |
25 | 19 |
26 namespace extensions { | 20 namespace extensions { |
27 class Extension; | 21 class Extension; |
28 } | 22 } |
29 | 23 |
30 namespace views { | 24 namespace views { |
31 class Checkbox; | 25 class Checkbox; |
32 class Label; | 26 class Label; |
33 } | 27 } |
34 | 28 |
35 // CreateShortcutViewCommon implements a dialog that asks user where to create | 29 // A dialog allowing the user to create a desktop shortcut pointing to Chrome |
36 // the shortcut for given web app. There are two variants of this dialog: | 30 // app. |
37 // Shortcuts that load a URL in an app-like window, and shortcuts that load | 31 class CreateChromeApplicationShortcutView : public views::DialogDelegateView, |
38 // a chrome app (the kind you see under "apps" on the new tabs page) in an app | 32 public views::ButtonListener { |
39 // window. These are implemented as subclasses of CreateShortcutViewCommon. | |
40 class CreateApplicationShortcutView : public views::DialogDelegateView, | |
41 public views::ButtonListener { | |
42 public: | 33 public: |
43 enum DialogLayout { | 34 CreateChromeApplicationShortcutView( |
44 // URL shortcuts have an info frame at the top with a thumbnail, title and | 35 Profile* profile, |
45 // description. | 36 const extensions::Extension* app, |
46 DIALOG_LAYOUT_URL_SHORTCUT, | 37 const base::Callback<void(bool)>& close_callback); |
47 | 38 ~CreateChromeApplicationShortcutView() override; |
48 // App shortcuts don't have an info frame, since they are launched from | |
49 // places where it's clear what app they are from. | |
50 DIALOG_LAYOUT_APP_SHORTCUT | |
51 }; | |
52 | |
53 explicit CreateApplicationShortcutView(Profile* profile); | |
54 ~CreateApplicationShortcutView() override; | |
55 | 39 |
56 // Initialize the controls on the dialog. | 40 // Initialize the controls on the dialog. |
57 void InitControls(DialogLayout dialog_layout); | 41 void InitControls(); |
58 | 42 |
59 // Overridden from views::View: | 43 // DialogDelegateView: |
60 gfx::Size GetPreferredSize() const override; | 44 gfx::Size GetPreferredSize() const override; |
61 | |
62 // Overridden from views::DialogDelegate: | |
63 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 45 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
64 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 46 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
65 ui::ModalType GetModalType() const override; | 47 ui::ModalType GetModalType() const override; |
66 base::string16 GetWindowTitle() const override; | 48 base::string16 GetWindowTitle() const override; |
67 bool Accept() override; | 49 bool Accept() override; |
| 50 bool Cancel() override; |
68 | 51 |
69 // Overridden from views::ButtonListener: | 52 // ButtonListener: |
70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 53 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
71 | 54 |
72 protected: | 55 private: |
73 // Adds a new check-box as a child to the view. | 56 // Adds a new check-box as a child to the view. |
74 views::Checkbox* AddCheckbox(const base::string16& text, bool checked); | 57 views::Checkbox* AddCheckbox(const base::string16& text, bool checked); |
75 | 58 |
| 59 // Called when the app's ShortcutInfo (with icon) is loaded. |
| 60 void OnAppInfoLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info); |
| 61 |
76 // Profile in which the shortcuts will be created. | 62 // Profile in which the shortcuts will be created. |
77 Profile* profile_; | 63 Profile* profile_; |
78 | 64 |
| 65 base::Callback<void(bool)> close_callback_; |
| 66 |
79 // UI elements on the dialog. | 67 // UI elements on the dialog. |
80 // May be NULL if we are not displaying the app's info. | |
81 views::View* app_info_; | |
82 views::Label* create_shortcuts_label_; | 68 views::Label* create_shortcuts_label_; |
| 69 |
| 70 // May be null if the platform doesn't support a particular location. |
83 views::Checkbox* desktop_check_box_; | 71 views::Checkbox* desktop_check_box_; |
84 views::Checkbox* menu_check_box_; | 72 views::Checkbox* menu_check_box_; |
85 views::Checkbox* quick_launch_check_box_; | 73 views::Checkbox* quick_launch_check_box_; |
86 | 74 |
87 // Target shortcut and file handler info. | 75 // Target shortcut and file handler info. |
88 std::unique_ptr<web_app::ShortcutInfo> shortcut_info_; | 76 std::unique_ptr<web_app::ShortcutInfo> shortcut_info_; |
89 // If false, the shortcut will be created in the root level of the Start Menu. | |
90 bool create_in_chrome_apps_subdir_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView); | |
93 }; | |
94 | |
95 // Create an application shortcut pointing to a URL. | |
96 class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView { | |
97 public: | |
98 explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents); | |
99 ~CreateUrlApplicationShortcutView() override; | |
100 | |
101 bool Accept() override; | |
102 | |
103 private: | |
104 // Fetch the largest unprocessed icon. | |
105 // The first largest icon downloaded and decoded successfully will be used. | |
106 void FetchIcon(); | |
107 | |
108 // Favicon download callback. | |
109 void DidDownloadFavicon( | |
110 int requested_size, | |
111 int id, | |
112 int http_status_code, | |
113 const GURL& image_url, | |
114 const std::vector<SkBitmap>& bitmaps, | |
115 const std::vector<gfx::Size>& original_bitmap_sizes); | |
116 | |
117 // The tab whose URL is being turned into an app. | |
118 content::WebContents* web_contents_; | |
119 | |
120 // Pending app icon download tracked by us. | |
121 int pending_download_id_; | |
122 | |
123 // Unprocessed icons from the WebApplicationInfo passed in. | |
124 web_app::IconInfoList unprocessed_icons_; | |
125 | |
126 base::WeakPtrFactory<CreateUrlApplicationShortcutView> weak_ptr_factory_; | |
127 | |
128 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView); | |
129 }; | |
130 | |
131 // Create an application shortcut pointing to a chrome application. | |
132 class CreateChromeApplicationShortcutView | |
133 : public CreateApplicationShortcutView { | |
134 public: | |
135 CreateChromeApplicationShortcutView( | |
136 Profile* profile, | |
137 const extensions::Extension* app, | |
138 const base::Callback<void(bool)>& close_callback); | |
139 ~CreateChromeApplicationShortcutView() override; | |
140 bool Accept() override; | |
141 bool Cancel() override; | |
142 | |
143 private: | |
144 // Called when the app's ShortcutInfo (with icon) is loaded. | |
145 void OnAppInfoLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info); | |
146 | |
147 base::Callback<void(bool)> close_callback_; | |
148 | 77 |
149 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; | 78 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; |
150 | 79 |
151 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); | 80 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); |
152 }; | 81 }; |
153 | 82 |
154 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ | 83 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ |
OLD | NEW |