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

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

Powered by Google App Engine
This is Rietveld 408576698