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" | |
13 #include "base/macros.h" | 10 #include "base/macros.h" |
dominickn
2017/04/03 03:10:00
#include "base/callback.h"
tapted
2017/04/04 01:30:39
Done.
| |
11 #include "base/strings/string16.h" | |
dominickn
2017/04/03 03:10:00
#include "base/memory/weak_ptr.h"
tapted
2017/04/04 01:30:39
Done.
| |
14 #include "chrome/browser/web_applications/web_app.h" | 12 #include "chrome/browser/web_applications/web_app.h" |
15 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
16 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
17 | 15 |
18 class GURL; | |
19 class Profile; | 16 class Profile; |
20 class SkBitmap; | |
21 | |
22 namespace content { | |
23 class WebContents; | |
24 } | |
25 | 17 |
26 namespace extensions { | 18 namespace extensions { |
27 class Extension; | 19 class Extension; |
28 } | 20 } |
29 | 21 |
30 namespace views { | 22 namespace views { |
31 class Checkbox; | 23 class Checkbox; |
32 class Label; | 24 class Label; |
33 } | 25 } |
34 | 26 |
35 // CreateShortcutViewCommon implements a dialog that asks user where to create | 27 // Create an application shortcut pointing to a chrome application. |
36 // the shortcut for given web app. There are two variants of this dialog: | 28 class CreateChromeApplicationShortcutView : public views::DialogDelegateView, |
37 // Shortcuts that load a URL in an app-like window, and shortcuts that load | 29 public views::ButtonListener { |
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 { | |
42 public: | 30 public: |
43 enum DialogLayout { | 31 CreateChromeApplicationShortcutView( |
44 // URL shortcuts have an info frame at the top with a thumbnail, title and | 32 Profile* profile, |
45 // description. | 33 const extensions::Extension* app, |
46 DIALOG_LAYOUT_URL_SHORTCUT, | 34 const base::Callback<void(bool)>& close_callback); |
47 | 35 ~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 | 36 |
56 // Initialize the controls on the dialog. | 37 // Initialize the controls on the dialog. |
57 void InitControls(DialogLayout dialog_layout); | 38 void InitControls(); |
58 | 39 |
59 // Overridden from views::View: | 40 // Overridden from views::View: |
60 gfx::Size GetPreferredSize() const override; | 41 gfx::Size GetPreferredSize() const override; |
61 | 42 |
62 // Overridden from views::DialogDelegate: | 43 // Overridden from views::DialogDelegate: |
63 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 44 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
64 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 45 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
65 ui::ModalType GetModalType() const override; | 46 ui::ModalType GetModalType() const override; |
66 base::string16 GetWindowTitle() const override; | 47 base::string16 GetWindowTitle() const override; |
67 bool Accept() override; | 48 bool Accept() override; |
49 bool Cancel() override; | |
50 | |
51 private: | |
52 // Adds a new check-box as a child to the view. | |
53 views::Checkbox* AddCheckbox(const base::string16& text, bool checked); | |
54 | |
55 // Called when the app's ShortcutInfo (with icon) is loaded. | |
56 void OnAppInfoLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info); | |
68 | 57 |
69 // Overridden from views::ButtonListener: | 58 // Overridden from views::ButtonListener: |
70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 59 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
71 | 60 |
72 protected: | |
73 // Adds a new check-box as a child to the view. | |
74 views::Checkbox* AddCheckbox(const base::string16& text, bool checked); | |
75 | |
76 // Profile in which the shortcuts will be created. | 61 // Profile in which the shortcuts will be created. |
77 Profile* profile_; | 62 Profile* profile_; |
78 | 63 |
64 base::Callback<void(bool)> close_callback_; | |
65 | |
79 // UI elements on the dialog. | 66 // 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_; | 67 views::Label* create_shortcuts_label_; |
68 | |
69 // May be null if the platform doesn't support a particular location. | |
83 views::Checkbox* desktop_check_box_; | 70 views::Checkbox* desktop_check_box_; |
84 views::Checkbox* menu_check_box_; | 71 views::Checkbox* menu_check_box_; |
85 views::Checkbox* quick_launch_check_box_; | 72 views::Checkbox* quick_launch_check_box_; |
86 | 73 |
87 // Target shortcut and file handler info. | 74 // Target shortcut and file handler info. |
88 std::unique_ptr<web_app::ShortcutInfo> shortcut_info_; | 75 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 | 76 |
149 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; | 77 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; |
150 | 78 |
151 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); | 79 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); |
152 }; | 80 }; |
153 | 81 |
154 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ | 82 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ |
OLD | NEW |