Chromium Code Reviews| 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 // Create an application shortcut pointing to a chrome application. |
|
Peter Kasting
2017/04/04 02:31:49
Nit: Maybe "A dialog allowing the user to create a
tapted
2017/04/04 06:48:39
Done.
| |
| 36 // the shortcut for given web app. There are two variants of this dialog: | 30 class CreateChromeApplicationShortcutView : public views::DialogDelegateView, |
| 37 // Shortcuts that load a URL in an app-like window, and shortcuts that load | 31 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: | 32 public: |
| 43 enum DialogLayout { | 33 CreateChromeApplicationShortcutView( |
| 44 // URL shortcuts have an info frame at the top with a thumbnail, title and | 34 Profile* profile, |
| 45 // description. | 35 const extensions::Extension* app, |
| 46 DIALOG_LAYOUT_URL_SHORTCUT, | 36 const base::Callback<void(bool)>& close_callback); |
| 47 | 37 ~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 | 38 |
| 56 // Initialize the controls on the dialog. | 39 // Initialize the controls on the dialog. |
| 57 void InitControls(DialogLayout dialog_layout); | 40 void InitControls(); |
| 58 | 41 |
| 59 // Overridden from views::View: | 42 // Overridden from views::View: |
|
Peter Kasting
2017/04/04 02:31:49
Nit: Combine these two lists as the DialogDelegate
tapted
2017/04/04 06:48:39
Done.
| |
| 60 gfx::Size GetPreferredSize() const override; | 43 gfx::Size GetPreferredSize() const override; |
| 61 | 44 |
| 62 // Overridden from views::DialogDelegate: | 45 // Overridden from views::DialogDelegate: |
| 63 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 46 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
| 64 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | 47 bool IsDialogButtonEnabled(ui::DialogButton button) const override; |
| 65 ui::ModalType GetModalType() const override; | 48 ui::ModalType GetModalType() const override; |
| 66 base::string16 GetWindowTitle() const override; | 49 base::string16 GetWindowTitle() const override; |
| 67 bool Accept() override; | 50 bool Accept() override; |
| 51 bool Cancel() override; | |
| 52 | |
| 53 private: | |
| 54 // Adds a new check-box as a child to the view. | |
| 55 views::Checkbox* AddCheckbox(const base::string16& text, bool checked); | |
| 56 | |
| 57 // Called when the app's ShortcutInfo (with icon) is loaded. | |
| 58 void OnAppInfoLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info); | |
| 68 | 59 |
| 69 // Overridden from views::ButtonListener: | 60 // Overridden from views::ButtonListener: |
|
Peter Kasting
2017/04/04 02:31:49
Nit: Leave in public section since base class decl
tapted
2017/04/04 06:48:39
Done.
| |
| 70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 61 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 71 | 62 |
| 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. | 63 // Profile in which the shortcuts will be created. |
| 77 Profile* profile_; | 64 Profile* profile_; |
| 78 | 65 |
| 66 base::Callback<void(bool)> close_callback_; | |
| 67 | |
| 79 // UI elements on the dialog. | 68 // 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_; | 69 views::Label* create_shortcuts_label_; |
| 70 | |
| 71 // May be null if the platform doesn't support a particular location. | |
| 83 views::Checkbox* desktop_check_box_; | 72 views::Checkbox* desktop_check_box_; |
| 84 views::Checkbox* menu_check_box_; | 73 views::Checkbox* menu_check_box_; |
| 85 views::Checkbox* quick_launch_check_box_; | 74 views::Checkbox* quick_launch_check_box_; |
| 86 | 75 |
| 87 // Target shortcut and file handler info. | 76 // Target shortcut and file handler info. |
| 88 std::unique_ptr<web_app::ShortcutInfo> shortcut_info_; | 77 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 | 78 |
| 149 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; | 79 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_; |
| 150 | 80 |
| 151 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); | 81 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); |
| 152 }; | 82 }; |
| 153 | 83 |
| 154 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ | 84 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ |
| OLD | NEW |