Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/ui/views/create_application_shortcut_view.h

Issue 5273004: Add "create Application Shortcut" to the app menu on NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase for commit. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "chrome/browser/extensions/image_loading_tracker.h"
11 #include "chrome/browser/web_applications/web_app.h" 12 #include "chrome/browser/web_applications/web_app.h"
12 #include "views/controls/label.h" 13 #include "views/controls/label.h"
13 #include "views/view.h" 14 #include "views/view.h"
14 #include "views/window/dialog_delegate.h" 15 #include "views/window/dialog_delegate.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 17
17 namespace views { 18 namespace views {
18 class Checkbox; 19 class Checkbox;
19 class Label; 20 class Label;
20 class Window; 21 class Window;
21 }; // namespace views 22 }; // namespace views
22 23
24 class Extension;
23 class MessageLoop; 25 class MessageLoop;
24 class Profile; 26 class Profile;
25 class TabContents; 27 class TabContents;
26 28
27 // CreateShortcutView implements a dialog that asks user where to create 29 // CreateShortcutViewCommon implements a dialog that asks user where to create
28 // the shortcut for given web app. 30 // the shortcut for given web app. There are two variants of this dialog:
31 // Shortcuts that load a URL in an app-like window, and shortcuts that load
32 // a chrome app (the kind you see under "apps" on the new tabs page) in an app
33 // window. These are implemented as subclasses of CreateShortcutViewCommon.
29 class CreateApplicationShortcutView : public views::View, 34 class CreateApplicationShortcutView : public views::View,
30 public views::DialogDelegate, 35 public views::DialogDelegate,
31 public views::ButtonListener { 36 public views::ButtonListener {
32 public: 37 public:
33 explicit CreateApplicationShortcutView(TabContents* tab_contents); 38 explicit CreateApplicationShortcutView(Profile* profile);
34 virtual ~CreateApplicationShortcutView(); 39 virtual ~CreateApplicationShortcutView();
35 40
36 // Initialize the controls on the dialog. 41 // Initialize the controls on the dialog.
37 void Init(); 42 void InitControls();
38 43
39 // Overridden from views::View: 44 // Overridden from views::View:
40 virtual gfx::Size GetPreferredSize(); 45 virtual gfx::Size GetPreferredSize();
41 46
42 // Overridden from views::DialogDelegate: 47 // Overridden from views::DialogDelegate:
43 virtual std::wstring GetDialogButtonLabel( 48 virtual std::wstring GetDialogButtonLabel(
44 MessageBoxFlags::DialogButton button) const; 49 MessageBoxFlags::DialogButton button) const;
45 virtual bool IsDialogButtonEnabled( 50 virtual bool IsDialogButtonEnabled(
46 MessageBoxFlags::DialogButton button) const; 51 MessageBoxFlags::DialogButton button) const;
47 virtual bool CanResize() const; 52 virtual bool CanResize() const;
48 virtual bool CanMaximize() const; 53 virtual bool CanMaximize() const;
49 virtual bool IsAlwaysOnTop() const; 54 virtual bool IsAlwaysOnTop() const;
50 virtual bool HasAlwaysOnTopMenu() const; 55 virtual bool HasAlwaysOnTopMenu() const;
51 virtual bool IsModal() const; 56 virtual bool IsModal() const;
52 virtual std::wstring GetWindowTitle() const; 57 virtual std::wstring GetWindowTitle() const;
53 virtual bool Accept(); 58 virtual bool Accept();
54 virtual views::View* GetContentsView(); 59 virtual views::View* GetContentsView();
55 60
56 // Overridden from views::ButtonListener: 61 // Overridden from views::ButtonListener:
57 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 62 virtual void ButtonPressed(views::Button* sender, const views::Event& event);
58 63
59 private: 64 protected:
60 // Adds a new check-box as a child to the view. 65 // Adds a new check-box as a child to the view.
61 views::Checkbox* AddCheckbox(const std::wstring& text, bool checked); 66 views::Checkbox* AddCheckbox(const std::wstring& text, bool checked);
62 67
63 // Fetch the largest unprocessed icon. 68 // Profile in which the shortcuts will be created.
64 // The first largest icon downloaded and decoded successfully will be used. 69 Profile* profile_;
65 void FetchIcon();
66
67 // Callback of icon download.
68 void OnIconDownloaded(bool errored, const SkBitmap& image);
69
70 // TabContents of the page that we want to create shortcut.
71 TabContents* tab_contents_;
72 70
73 // UI elements on the dialog. 71 // UI elements on the dialog.
74 views::View* app_info_; 72 views::View* app_info_;
75 views::Label* create_shortcuts_label_; 73 views::Label* create_shortcuts_label_;
76 views::Checkbox* desktop_check_box_; 74 views::Checkbox* desktop_check_box_;
77 views::Checkbox* menu_check_box_; 75 views::Checkbox* menu_check_box_;
78 views::Checkbox* quick_launch_check_box_; 76 views::Checkbox* quick_launch_check_box_;
79 77
80 // Target shortcut info. 78 // Target shortcut info.
81 ShellIntegration::ShortcutInfo shortcut_info_; 79 ShellIntegration::ShortcutInfo shortcut_info_;
82 80
83 // Unprocessed icons from the WebApplicationInfo passed in. 81 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView);
84 web_app::IconInfoList unprocessed_icons_; 82 };
83
84 // Create an application shortcut pointing to a URL.
85 class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView {
86 public:
87 explicit CreateUrlApplicationShortcutView(TabContents* tab_contents);
88 virtual ~CreateUrlApplicationShortcutView();
89
90 virtual bool Accept();
91
92 private:
93 // Fetch the largest unprocessed icon.
94 // The first largest icon downloaded and decoded successfully will be used.
95 void FetchIcon();
96
97 // Callback of icon download.
98 void OnIconDownloaded(bool errored, const SkBitmap& image);
99
100 // The tab whose URL is being turned into an app.
101 TabContents* tab_contents_;
85 102
86 // Pending app icon download tracked by us. 103 // Pending app icon download tracked by us.
87 class IconDownloadCallbackFunctor; 104 class IconDownloadCallbackFunctor;
88 IconDownloadCallbackFunctor* pending_download_; 105 IconDownloadCallbackFunctor* pending_download_;
89 106
90 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView); 107 // Unprocessed icons from the WebApplicationInfo passed in.
108 web_app::IconInfoList unprocessed_icons_;
109
110 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView);
91 }; 111 };
92 112
113 // Create an application shortcut pointing to a chrome application.
114 class CreateChromeApplicationShortcutView
115 : public CreateApplicationShortcutView,
116 public ImageLoadingTracker::Observer {
117 public:
118 explicit CreateChromeApplicationShortcutView(Profile* profile,
119 const Extension* app);
120 virtual ~CreateChromeApplicationShortcutView();
121
122 // Implement ImageLoadingTracker::Observer. |tracker_| is used to
123 // load the app's icon. This method recieves the icon, and adds
124 // it to the "Create Shortcut" dailog box.
125 virtual void OnImageLoaded(SkBitmap* image,
126 ExtensionResource resource,
127 int index);
128
129 private:
130 const Extension* app_;
131 ImageLoadingTracker tracker_;
132
133 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView);
134 };
135
136
93 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 137 #endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_dialogs.h ('k') | chrome/browser/ui/views/create_application_shortcut_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698