Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / web_applications / web_app.h
bloba7d93fbeea64e1884a80acf54b894747ef0f496c
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_WEB_APPLICATIONS_WEB_APP_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/strings/string16.h"
14 #include "build/build_config.h"
15 #include "chrome/browser/shell_integration.h"
16 #include "chrome/common/web_application_info.h"
17 #include "extensions/common/manifest_handlers/file_handler_info.h"
19 class Profile;
21 namespace content {
22 class WebContents;
25 namespace extensions {
26 class Extension;
29 namespace gfx {
30 class ImageFamily;
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.
36 namespace web_app {
38 // Represents the info required to create a shortcut for an app.
39 struct ShortcutInfo {
40 ShortcutInfo();
41 ~ShortcutInfo();
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 std::string version_for_display;
58 // This specifies a folder in the system applications menu (e.g the Start Menu
59 // on Windows).
61 // These represent the applications menu root, the "Google Chrome" folder and
62 // the "Chrome Apps" folder respectively.
64 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the
65 // app with the OS (in order to give its windows shelf icons, and correct icons
66 // and titles), but the app should not show up in menus or search results.
68 // NB: On Linux, these locations may not be used by the window manager (e.g
69 // Unity and Gnome Shell).
70 enum ApplicationsMenuLocation {
71 APP_MENU_LOCATION_NONE,
72 APP_MENU_LOCATION_ROOT,
73 APP_MENU_LOCATION_SUBDIR_CHROME,
74 APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
75 APP_MENU_LOCATION_HIDDEN,
78 // Info about which locations to create app shortcuts in.
79 struct ShortcutLocations {
80 ShortcutLocations();
82 bool on_desktop;
84 ApplicationsMenuLocation applications_menu_location;
86 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
87 // this means "pin to taskbar". For Mac/Linux, this could be used for
88 // Mac dock or the gnome/kde application launcher. However, those are not
89 // implemented yet.
90 bool in_quick_launch_bar;
93 // This encodes the cause of shortcut creation as the correct behavior in each
94 // case is implementation specific.
95 enum ShortcutCreationReason {
96 SHORTCUT_CREATION_BY_USER,
97 SHORTCUT_CREATION_AUTOMATED,
100 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo.
101 typedef base::Callback<void(const ShortcutInfo&,
102 const extensions::FileHandlersInfo&)> InfoCallback;
104 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo.
105 typedef base::Callback<void(const ShortcutInfo&)> ShortcutInfoCallback;
107 #if defined(TOOLKIT_VIEWS)
108 // Extracts shortcut info of the given WebContents.
109 void GetShortcutInfoForTab(content::WebContents* web_contents,
110 ShortcutInfo* info);
111 #endif
113 // Updates web app shortcut of the WebContents. This function checks and
114 // updates web app icon and shortcuts if needed. For icon, the check is based
115 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu
116 // and quick launch (as well as pinned shortcut) for shortcut and only
117 // updates (recreates) them if they exits.
118 void UpdateShortcutForTabContents(content::WebContents* web_contents);
120 ShortcutInfo ShortcutInfoForExtensionAndProfile(
121 const extensions::Extension* app,
122 Profile* profile);
124 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in
125 // |profile| and passes them to |callback| after asynchronously loading all icon
126 // representations.
127 void GetInfoForApp(const extensions::Extension* extension,
128 Profile* profile,
129 const InfoCallback& callback);
131 // Populates a ShortcutInfo for the given |extension| in |profile| and passes
132 // it to |callback| after asynchronously loading all icon representations. This
133 // is equivalent to GetInfoForApp, but it throws away the FileHandlersInfo.
134 void GetShortcutInfoForApp(const extensions::Extension* extension,
135 Profile* profile,
136 const ShortcutInfoCallback& callback);
138 // Whether to create a shortcut for this type of extension.
139 bool ShouldCreateShortcutFor(web_app::ShortcutCreationReason reason,
140 Profile* profile,
141 const extensions::Extension* extension);
143 // Gets the user data directory for given web app. The path for the directory is
144 // based on |extension_id|. If |extension_id| is empty then |url| is used
145 // to construct a unique ID.
146 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
147 const std::string& extension_id,
148 const GURL& url);
150 // Gets the user data directory to use for |extension| located inside
151 // |profile_path|.
152 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
153 const extensions::Extension& extension);
155 // Compute a deterministic name based on data in the shortcut_info.
156 std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info);
158 // Compute a deterministic name based on the URL. We use this pseudo name
159 // as a key to store window location per application URLs in Browser and
160 // as app id for BrowserWindow, shortcut and jump list.
161 std::string GenerateApplicationNameFromURL(const GURL& url);
163 // Compute a deterministic name based on an extension/apps's id.
164 std::string GenerateApplicationNameFromExtensionId(const std::string& id);
166 // Extracts the extension id from the app name.
167 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
169 // Create shortcuts for web application based on given shortcut data.
170 // |shortcut_info| contains information about the shortcuts to create, and
171 // |locations| contains information about where to create them, while
172 // |file_handlers_info| contains information about the file handlers to create.
173 void CreateShortcutsWithInfo(
174 ShortcutCreationReason reason,
175 const ShortcutLocations& locations,
176 const ShortcutInfo& shortcut_info,
177 const extensions::FileHandlersInfo& file_handlers_info);
179 // Currently only called by app_list_service_mac to create a shim for the
180 // app launcher.
181 void CreateNonAppShortcut(const ShortcutLocations& locations,
182 const ShortcutInfo& shortcut_info);
184 // Creates shortcuts for an app. This loads the app's icon from disk, and calls
185 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's
186 // icon loaded, you should use CreateShortcutsWithInfo() directly.
187 void CreateShortcuts(ShortcutCreationReason reason,
188 const ShortcutLocations& locations,
189 Profile* profile,
190 const extensions::Extension* app);
192 // Delete all shortcuts that have been created for the given profile and
193 // extension.
194 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app);
196 // Updates shortcuts for web application based on given shortcut data. This
197 // refreshes existing shortcuts and their icons, but does not create new ones.
198 // |old_app_title| contains the title of the app prior to this update.
199 void UpdateAllShortcuts(const base::string16& old_app_title,
200 Profile* profile,
201 const extensions::Extension* app);
203 // Updates shortcuts for all apps in this profile. This is expected to be called
204 // on the UI thread.
205 void UpdateShortcutsForAllApps(Profile* profile,
206 const base::Closure& callback);
208 // Returns true if given url is a valid web app url.
209 bool IsValidUrl(const GURL& url);
211 #if defined(TOOLKIT_VIEWS)
212 // Extracts icons info from web app data. Take only square shaped icons and
213 // sort them from smallest to largest.
214 typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList;
215 void GetIconsInfo(const WebApplicationInfo& app_info, IconInfoList* icons);
216 #endif
218 #if defined(OS_LINUX)
219 // Windows that correspond to web apps need to have a deterministic (and
220 // different) WMClass than normal chrome windows so the window manager groups
221 // them as a separate application.
222 std::string GetWMClassFromAppName(std::string app_name);
223 #endif
225 namespace internals {
227 #if defined(OS_WIN)
228 // Returns the Windows user-level shortcut paths that are specified in
229 // |creation_locations|.
230 std::vector<base::FilePath> GetShortcutPaths(
231 const ShortcutLocations& creation_locations);
232 #endif
234 // Implemented for each platform, does the platform specific parts of creating
235 // shortcuts. Used internally by CreateShortcuts methods.
236 // |shortcut_data_path| is where to store any resources created for the
237 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
238 // |shortcut_info| contains info about the shortcut to create, and
239 // |creation_locations| contains information about where to create them.
240 bool CreatePlatformShortcuts(
241 const base::FilePath& shortcut_data_path,
242 const ShortcutInfo& shortcut_info,
243 const extensions::FileHandlersInfo& file_handlers_info,
244 const ShortcutLocations& creation_locations,
245 ShortcutCreationReason creation_reason);
247 // Delete all the shortcuts we have added for this extension. This is the
248 // platform specific implementation of the DeleteAllShortcuts function, and
249 // is executed on the FILE thread.
250 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path,
251 const ShortcutInfo& shortcut_info);
253 // Updates all the shortcuts we have added for this extension. This is the
254 // platform specific implementation of the UpdateAllShortcuts function, and
255 // is executed on the FILE thread.
256 void UpdatePlatformShortcuts(
257 const base::FilePath& shortcut_data_path,
258 const base::string16& old_app_title,
259 const ShortcutInfo& shortcut_info,
260 const extensions::FileHandlersInfo& file_handlers_info);
262 // Delete all the shortcuts for an entire profile.
263 // This is executed on the FILE thread.
264 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
266 // Sanitizes |name| and returns a version of it that is safe to use as an
267 // on-disk file name .
268 base::FilePath GetSanitizedFileName(const base::string16& name);
270 } // namespace internals
272 } // namespace web_app
274 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_