BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / create_application_shortcut_view.h
blob3952bb1ebb9f6b540919e3d2d66b32ae1298d6d8
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 "base/memory/scoped_ptr.h"
14 #include "chrome/browser/web_applications/web_app.h"
15 #include "extensions/common/manifest_handlers/file_handler_info.h"
16 #include "ui/views/controls/button/button.h"
17 #include "ui/views/window/dialog_delegate.h"
19 class FaviconDownloadHelper;
20 class GURL;
21 class Profile;
22 class SkBitmap;
24 namespace content {
25 class WebContents;
28 namespace extensions {
29 class Extension;
32 namespace views {
33 class Checkbox;
34 class Label;
37 // CreateShortcutViewCommon implements a dialog that asks user where to create
38 // the shortcut for given web app. There are two variants of this dialog:
39 // Shortcuts that load a URL in an app-like window, and shortcuts that load
40 // a chrome app (the kind you see under "apps" on the new tabs page) in an app
41 // window. These are implemented as subclasses of CreateShortcutViewCommon.
42 class CreateApplicationShortcutView : public views::DialogDelegateView,
43 public views::ButtonListener {
44 public:
45 enum DialogLayout {
46 // URL shortcuts have an info frame at the top with a thumbnail, title and
47 // description.
48 DIALOG_LAYOUT_URL_SHORTCUT,
50 // App shortcuts don't have an info frame, since they are launched from
51 // places where it's clear what app they are from.
52 DIALOG_LAYOUT_APP_SHORTCUT
55 explicit CreateApplicationShortcutView(Profile* profile);
56 ~CreateApplicationShortcutView() override;
58 // Initialize the controls on the dialog.
59 void InitControls(DialogLayout dialog_layout);
61 // Overridden from views::View:
62 gfx::Size GetPreferredSize() const override;
64 // Overridden from views::DialogDelegate:
65 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
66 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
67 ui::ModalType GetModalType() const override;
68 base::string16 GetWindowTitle() const override;
69 bool Accept() override;
71 // Overridden from views::ButtonListener:
72 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
74 protected:
75 // Adds a new check-box as a child to the view.
76 views::Checkbox* AddCheckbox(const base::string16& text, bool checked);
78 // Profile in which the shortcuts will be created.
79 Profile* profile_;
81 // UI elements on the dialog.
82 // May be NULL if we are not displaying the app's info.
83 views::View* app_info_;
84 views::Label* create_shortcuts_label_;
85 views::Checkbox* desktop_check_box_;
86 views::Checkbox* menu_check_box_;
87 views::Checkbox* quick_launch_check_box_;
89 // Target shortcut and file handler info.
90 scoped_ptr<web_app::ShortcutInfo> shortcut_info_;
91 extensions::FileHandlersInfo file_handlers_info_;
92 // If false, the shortcut will be created in the root level of the Start Menu.
93 bool create_in_chrome_apps_subdir_;
95 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView);
98 // Create an application shortcut pointing to a URL.
99 class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView {
100 public:
101 explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents);
102 ~CreateUrlApplicationShortcutView() override;
104 bool Accept() override;
106 private:
107 // Fetch the largest unprocessed icon.
108 // The first largest icon downloaded and decoded successfully will be used.
109 void FetchIcon();
111 // Favicon download callback.
112 void DidDownloadFavicon(
113 int requested_size,
114 int id,
115 int http_status_code,
116 const GURL& image_url,
117 const std::vector<SkBitmap>& bitmaps,
118 const std::vector<gfx::Size>& original_bitmap_sizes);
120 // The tab whose URL is being turned into an app.
121 content::WebContents* web_contents_;
123 // Pending app icon download tracked by us.
124 int pending_download_id_;
126 // Unprocessed icons from the WebApplicationInfo passed in.
127 web_app::IconInfoList unprocessed_icons_;
129 base::WeakPtrFactory<CreateUrlApplicationShortcutView> weak_ptr_factory_;
131 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView);
134 // Create an application shortcut pointing to a chrome application.
135 class CreateChromeApplicationShortcutView
136 : public CreateApplicationShortcutView {
137 public:
138 CreateChromeApplicationShortcutView(
139 Profile* profile,
140 const extensions::Extension* app,
141 const base::Callback<void(bool)>& close_callback);
142 ~CreateChromeApplicationShortcutView() override;
143 bool Accept() override;
144 bool Cancel() override;
146 private:
147 // Called when the app's ShortcutInfo (with icon) and FileHandlersInfo is
148 // loaded.
149 void OnAppInfoLoaded(scoped_ptr<web_app::ShortcutInfo> shortcut_info,
150 const extensions::FileHandlersInfo& file_handlers_info);
152 base::Callback<void(bool)> close_callback_;
154 base::WeakPtrFactory<CreateChromeApplicationShortcutView> weak_ptr_factory_;
156 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView);
159 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_