Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / create_application_shortcut_view.h
blobd97a9e6e35327cf55803919143aa5c11b627150f
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "chrome/browser/web_applications/web_app.h"
14 #include "extensions/common/manifest_handlers/file_handler_info.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/window/dialog_delegate.h"
18 class FaviconDownloadHelper;
19 class GURL;
20 class Profile;
21 class SkBitmap;
23 namespace content {
24 class WebContents;
27 namespace extensions {
28 class Extension;
31 namespace views {
32 class Checkbox;
33 class Label;
36 // CreateShortcutViewCommon implements a dialog that asks user where to create
37 // the shortcut for given web app. There are two variants of this dialog:
38 // Shortcuts that load a URL in an app-like window, and shortcuts that load
39 // a chrome app (the kind you see under "apps" on the new tabs page) in an app
40 // window. These are implemented as subclasses of CreateShortcutViewCommon.
41 class CreateApplicationShortcutView : public views::DialogDelegateView,
42 public views::ButtonListener {
43 public:
44 enum DialogLayout {
45 // URL shortcuts have an info frame at the top with a thumbnail, title and
46 // description.
47 DIALOG_LAYOUT_URL_SHORTCUT,
49 // App shortcuts don't have an info frame, since they are launched from
50 // places where it's clear what app they are from.
51 DIALOG_LAYOUT_APP_SHORTCUT
54 explicit CreateApplicationShortcutView(Profile* profile);
55 ~CreateApplicationShortcutView() override;
57 // Initialize the controls on the dialog.
58 void InitControls(DialogLayout dialog_layout);
60 // Overridden from views::View:
61 gfx::Size GetPreferredSize() const override;
63 // Overridden from views::DialogDelegate:
64 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
65 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
66 ui::ModalType GetModalType() const override;
67 base::string16 GetWindowTitle() const override;
68 bool Accept() override;
70 // Overridden from views::ButtonListener:
71 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
73 protected:
74 // Adds a new check-box as a child to the view.
75 views::Checkbox* AddCheckbox(const base::string16& text, bool checked);
77 // Profile in which the shortcuts will be created.
78 Profile* profile_;
80 // UI elements on the dialog.
81 // May be NULL if we are not displaying the app's info.
82 views::View* app_info_;
83 views::Label* create_shortcuts_label_;
84 views::Checkbox* desktop_check_box_;
85 views::Checkbox* menu_check_box_;
86 views::Checkbox* quick_launch_check_box_;
88 // Target shortcut and file handler info.
89 web_app::ShortcutInfo shortcut_info_;
90 extensions::FileHandlersInfo file_handlers_info_;
91 // If false, the shortcut will be created in the root level of the Start Menu.
92 bool create_in_chrome_apps_subdir_;
94 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView);
97 // Create an application shortcut pointing to a URL.
98 class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView {
99 public:
100 explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents);
101 ~CreateUrlApplicationShortcutView() override;
103 bool Accept() override;
105 private:
106 // Fetch the largest unprocessed icon.
107 // The first largest icon downloaded and decoded successfully will be used.
108 void FetchIcon();
110 // Favicon download callback.
111 void DidDownloadFavicon(
112 int requested_size,
113 int id,
114 int http_status_code,
115 const GURL& image_url,
116 const std::vector<SkBitmap>& bitmaps,
117 const std::vector<gfx::Size>& original_bitmap_sizes);
119 // The tab whose URL is being turned into an app.
120 content::WebContents* web_contents_;
122 // Pending app icon download tracked by us.
123 int pending_download_id_;
125 // Unprocessed icons from the WebApplicationInfo passed in.
126 web_app::IconInfoList unprocessed_icons_;
128 base::WeakPtrFactory<CreateUrlApplicationShortcutView> weak_ptr_factory_;
130 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView);
133 // Create an application shortcut pointing to a chrome application.
134 class CreateChromeApplicationShortcutView
135 : public CreateApplicationShortcutView {
136 public:
137 CreateChromeApplicationShortcutView(
138 Profile* profile,
139 const extensions::Extension* app,
140 const base::Callback<void(bool)>& close_callback);
141 ~CreateChromeApplicationShortcutView() override;
142 bool Accept() override;
143 bool Cancel() override;
145 private:
146 // Called when the app's ShortcutInfo (with icon) and FileHandlersInfo is
147 // loaded.
148 void OnAppInfoLoaded(const web_app::ShortcutInfo& shortcut_info,
149 const extensions::FileHandlersInfo& file_handlers_info);
151 base::Callback<void(bool)> close_callback_;
153 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_;
155 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView);
158 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_