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

Side by Side Diff: chrome/browser/web_applications/web_app.h

Issue 231673005: Move ShortcutInfo, ShortcutLocations from ShellIntegration to web_app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windws Created 6 years, 8 months 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) 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_WEB_APPLICATIONS_WEB_APP_H_ 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 namespace extensions { 24 namespace extensions {
25 class Extension; 25 class Extension;
26 } 26 }
27 27
28 namespace gfx { 28 namespace gfx {
29 class ImageFamily; 29 class ImageFamily;
30 } 30 }
31 31
32 namespace web_app { 32 namespace web_app {
calamity 2014/04/14 04:23:01 It would be good to have a comment summarizing wha
jackhou1 2014/04/14 05:49:19 Done.
33 33
34 struct ShortcutInfo {
calamity 2014/04/14 04:23:01 Comment for this struct, noting that it represents
jackhou1 2014/04/14 05:49:19 Done.
35 ShortcutInfo();
36 ~ShortcutInfo();
37
38 GURL url;
39 // If |extension_id| is non-empty, this is short cut is to an extension-app
40 // and the launch url will be detected at start-up. In this case, |url|
41 // is still used to generate the app id (windows app id, not chrome app id).
42 std::string extension_id;
43 bool is_platform_app;
44 base::string16 title;
45 base::string16 description;
46 base::FilePath extension_path;
47 gfx::ImageFamily favicon;
48 base::FilePath profile_path;
49 std::string profile_name;
50 };
51
52 // This specifies a folder in the system applications menu (e.g the Start Menu
53 // on Windows).
54 //
55 // These represent the applications menu root, the "Google Chrome" folder and
56 // the "Chrome Apps" folder respectively.
57 //
58 // NB: On Linux, these locations may not be used by the window manager (e.g
59 // Unity and Gnome Shell).
60 enum ApplicationsMenuLocation {
61 APP_MENU_LOCATION_NONE,
62 APP_MENU_LOCATION_ROOT,
63 APP_MENU_LOCATION_SUBDIR_CHROME,
64 APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
65 };
66
67 // Info about which locations to create app shortcuts in.
68 struct ShortcutLocations {
69 ShortcutLocations();
70
71 bool on_desktop;
72
73 ApplicationsMenuLocation applications_menu_location;
74
75 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
76 // this means "pin to taskbar". For Mac/Linux, this could be used for
77 // Mac dock or the gnome/kde application launcher. However, those are not
78 // implemented yet.
79 bool in_quick_launch_bar;
80
81 #if defined(OS_POSIX)
82 // For Linux, this refers to a shortcut which the system knows about (for
83 // the purpose of identifying windows and giving them the correct
84 // title/icon), but which does not show up in menus or search results.
85 // Ignored if applications_menu_location is not APP_MENU_LOCATION_NONE.
86 bool hidden;
87 #endif
88 };
89
34 // This encodes the cause of shortcut creation as the correct behavior in each 90 // This encodes the cause of shortcut creation as the correct behavior in each
35 // case is implementation specific. 91 // case is implementation specific.
36 enum ShortcutCreationReason { 92 enum ShortcutCreationReason {
37 SHORTCUT_CREATION_BY_USER, 93 SHORTCUT_CREATION_BY_USER,
38 SHORTCUT_CREATION_AUTOMATED, 94 SHORTCUT_CREATION_AUTOMATED,
39 }; 95 };
40 96
41 typedef base::Callback<void(const ShellIntegration::ShortcutInfo&)> 97 typedef base::Callback<void(const web_app::ShortcutInfo&)>
42 ShortcutInfoCallback; 98 ShortcutInfoCallback;
43 99
44 // Extracts shortcut info of the given WebContents. 100 // Extracts shortcut info of the given WebContents.
45 void GetShortcutInfoForTab(content::WebContents* web_contents, 101 void GetShortcutInfoForTab(content::WebContents* web_contents,
46 ShellIntegration::ShortcutInfo* info); 102 web_app::ShortcutInfo* info);
47 103
48 // Updates web app shortcut of the WebContents. This function checks and 104 // Updates web app shortcut of the WebContents. This function checks and
49 // updates web app icon and shortcuts if needed. For icon, the check is based 105 // updates web app icon and shortcuts if needed. For icon, the check is based
50 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu 106 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu
51 // and quick launch (as well as pinned shortcut) for shortcut and only 107 // and quick launch (as well as pinned shortcut) for shortcut and only
52 // updates (recreates) them if they exits. 108 // updates (recreates) them if they exits.
53 void UpdateShortcutForTabContents(content::WebContents* web_contents); 109 void UpdateShortcutForTabContents(content::WebContents* web_contents);
54 110
55 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( 111 web_app::ShortcutInfo ShortcutInfoForExtensionAndProfile(
56 const extensions::Extension* app, 112 const extensions::Extension* app,
57 Profile* profile); 113 Profile* profile);
58 114
59 // Fetches the icon for |extension| and calls |callback| with shortcut info 115 // Fetches the icon for |extension| and calls |callback| with shortcut info
60 // filled out as by UpdateShortcutInfoForApp. 116 // filled out as by UpdateShortcutInfoForApp.
61 void UpdateShortcutInfoAndIconForApp( 117 void UpdateShortcutInfoAndIconForApp(
62 const extensions::Extension* extension, 118 const extensions::Extension* extension,
63 Profile* profile, 119 Profile* profile,
64 const ShortcutInfoCallback& callback); 120 const ShortcutInfoCallback& callback);
65 121
66 // Gets the user data directory for given web app. The path for the directory is 122 // Gets the user data directory for given web app. The path for the directory is
67 // based on |extension_id|. If |extension_id| is empty then |url| is used 123 // based on |extension_id|. If |extension_id| is empty then |url| is used
68 // to construct a unique ID. 124 // to construct a unique ID.
69 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, 125 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
70 const std::string& extension_id, 126 const std::string& extension_id,
71 const GURL& url); 127 const GURL& url);
72 128
73 // Gets the user data directory to use for |extension| located inside 129 // Gets the user data directory to use for |extension| located inside
74 // |profile_path|. 130 // |profile_path|.
75 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path, 131 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
76 const extensions::Extension& extension); 132 const extensions::Extension& extension);
77 133
78 // Compute a deterministic name based on data in the shortcut_info. 134 // Compute a deterministic name based on data in the shortcut_info.
79 std::string GenerateApplicationNameFromInfo( 135 std::string GenerateApplicationNameFromInfo(
80 const ShellIntegration::ShortcutInfo& shortcut_info); 136 const web_app::ShortcutInfo& shortcut_info);
81 137
82 // Compute a deterministic name based on the URL. We use this pseudo name 138 // Compute a deterministic name based on the URL. We use this pseudo name
83 // as a key to store window location per application URLs in Browser and 139 // as a key to store window location per application URLs in Browser and
84 // as app id for BrowserWindow, shortcut and jump list. 140 // as app id for BrowserWindow, shortcut and jump list.
85 std::string GenerateApplicationNameFromURL(const GURL& url); 141 std::string GenerateApplicationNameFromURL(const GURL& url);
86 142
87 // Compute a deterministic name based on an extension/apps's id. 143 // Compute a deterministic name based on an extension/apps's id.
88 std::string GenerateApplicationNameFromExtensionId(const std::string& id); 144 std::string GenerateApplicationNameFromExtensionId(const std::string& id);
89 145
90 // Extracts the extension id from the app name. 146 // Extracts the extension id from the app name.
91 std::string GetExtensionIdFromApplicationName(const std::string& app_name); 147 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
92 148
93 // Create shortcuts for web application based on given shortcut data. 149 // Create shortcuts for web application based on given shortcut data.
94 // |shortcut_info| contains information about the shortcuts to create, and 150 // |shortcut_info| contains information about the shortcuts to create, and
95 // |creation_locations| contains information about where to create them. 151 // |creation_locations| contains information about where to create them.
96 void CreateShortcutsForShortcutInfo( 152 void CreateShortcutsForShortcutInfo(
97 web_app::ShortcutCreationReason reason, 153 web_app::ShortcutCreationReason reason,
98 const ShellIntegration::ShortcutLocations& locations, 154 const web_app::ShortcutLocations& locations,
99 const ShellIntegration::ShortcutInfo& shortcut_info); 155 const web_app::ShortcutInfo& shortcut_info);
100 156
101 // Creates shortcuts for an app. 157 // Creates shortcuts for an app.
102 void CreateShortcuts( 158 void CreateShortcuts(
103 ShortcutCreationReason reason, 159 ShortcutCreationReason reason,
104 const ShellIntegration::ShortcutLocations& locations, 160 const web_app::ShortcutLocations& locations,
105 Profile* profile, 161 Profile* profile,
106 const extensions::Extension* app); 162 const extensions::Extension* app);
107 163
108 // Delete all shortcuts that have been created for the given profile and 164 // Delete all shortcuts that have been created for the given profile and
109 // extension. 165 // extension.
110 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app); 166 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app);
111 167
112 // Updates shortcuts for web application based on given shortcut data. This 168 // Updates shortcuts for web application based on given shortcut data. This
113 // refreshes existing shortcuts and their icons, but does not create new ones. 169 // refreshes existing shortcuts and their icons, but does not create new ones.
114 // |old_app_title| contains the title of the app prior to this update. 170 // |old_app_title| contains the title of the app prior to this update.
(...skipping 18 matching lines...) Expand all
133 // them as a separate application. 189 // them as a separate application.
134 std::string GetWMClassFromAppName(std::string app_name); 190 std::string GetWMClassFromAppName(std::string app_name);
135 #endif 191 #endif
136 192
137 namespace internals { 193 namespace internals {
138 194
139 #if defined(OS_WIN) 195 #if defined(OS_WIN)
140 // Returns the Windows user-level shortcut paths that are specified in 196 // Returns the Windows user-level shortcut paths that are specified in
141 // |creation_locations|. 197 // |creation_locations|.
142 std::vector<base::FilePath> GetShortcutPaths( 198 std::vector<base::FilePath> GetShortcutPaths(
143 const ShellIntegration::ShortcutLocations& creation_locations); 199 const web_app::ShortcutLocations& creation_locations);
144 #endif 200 #endif
145 201
146 // Creates a shortcut. Must be called on the file thread. This is used to 202 // Creates a shortcut. Must be called on the file thread. This is used to
147 // implement CreateShortcuts() above, and can also be used directly from the 203 // implement CreateShortcuts() above, and can also be used directly from the
148 // file thread. |shortcut_info| contains info about the shortcut to create, and 204 // file thread. |shortcut_info| contains info about the shortcut to create, and
149 // |creation_locations| contains information about where to create them. 205 // |creation_locations| contains information about where to create them.
150 bool CreateShortcutsOnFileThread( 206 bool CreateShortcutsOnFileThread(
151 ShortcutCreationReason reason, 207 ShortcutCreationReason reason,
152 const ShellIntegration::ShortcutLocations& locations, 208 const web_app::ShortcutLocations& locations,
153 const ShellIntegration::ShortcutInfo& shortcut_info); 209 const web_app::ShortcutInfo& shortcut_info);
154 210
155 // Implemented for each platform, does the platform specific parts of creating 211 // Implemented for each platform, does the platform specific parts of creating
156 // shortcuts. Used internally by CreateShortcutsOnFileThread. 212 // shortcuts. Used internally by CreateShortcutsOnFileThread.
157 // |shortcut_data_path| is where to store any resources created for the 213 // |shortcut_data_path| is where to store any resources created for the
158 // shortcut, and is also used as the UserDataDir for platform app shortcuts. 214 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
159 // |shortcut_info| contains info about the shortcut to create, and 215 // |shortcut_info| contains info about the shortcut to create, and
160 // |creation_locations| contains information about where to create them. 216 // |creation_locations| contains information about where to create them.
161 bool CreatePlatformShortcuts( 217 bool CreatePlatformShortcuts(
162 const base::FilePath& shortcut_data_path, 218 const base::FilePath& shortcut_data_path,
163 const ShellIntegration::ShortcutInfo& shortcut_info, 219 const web_app::ShortcutInfo& shortcut_info,
164 const ShellIntegration::ShortcutLocations& creation_locations, 220 const web_app::ShortcutLocations& creation_locations,
165 ShortcutCreationReason creation_reason); 221 ShortcutCreationReason creation_reason);
166 222
167 // Delete all the shortcuts we have added for this extension. This is the 223 // Delete all the shortcuts we have added for this extension. This is the
168 // platform specific implementation of the DeleteAllShortcuts function, and 224 // platform specific implementation of the DeleteAllShortcuts function, and
169 // is executed on the FILE thread. 225 // is executed on the FILE thread.
170 void DeletePlatformShortcuts( 226 void DeletePlatformShortcuts(
171 const base::FilePath& shortcut_data_path, 227 const base::FilePath& shortcut_data_path,
172 const ShellIntegration::ShortcutInfo& shortcut_info); 228 const web_app::ShortcutInfo& shortcut_info);
173 229
174 // Updates all the shortcuts we have added for this extension. This is the 230 // Updates all the shortcuts we have added for this extension. This is the
175 // platform specific implementation of the UpdateAllShortcuts function, and 231 // platform specific implementation of the UpdateAllShortcuts function, and
176 // is executed on the FILE thread. 232 // is executed on the FILE thread.
177 void UpdatePlatformShortcuts( 233 void UpdatePlatformShortcuts(
178 const base::FilePath& shortcut_data_path, 234 const base::FilePath& shortcut_data_path,
179 const base::string16& old_app_title, 235 const base::string16& old_app_title,
180 const ShellIntegration::ShortcutInfo& shortcut_info); 236 const web_app::ShortcutInfo& shortcut_info);
181 237
182 // Delete all the shortcuts for an entire profile. 238 // Delete all the shortcuts for an entire profile.
183 // This is executed on the FILE thread. 239 // This is executed on the FILE thread.
184 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); 240 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
185 241
186 // Sanitizes |name| and returns a version of it that is safe to use as an 242 // Sanitizes |name| and returns a version of it that is safe to use as an
187 // on-disk file name . 243 // on-disk file name .
188 base::FilePath GetSanitizedFileName(const base::string16& name); 244 base::FilePath GetSanitizedFileName(const base::string16& name);
189 245
190 } // namespace internals 246 } // namespace internals
191 247
192 } // namespace web_app 248 } // namespace web_app
193 249
194 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ 250 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698