ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / web_applications / web_app.h
blob0b201acb000192a3c8fe6d929ac38ecdd42c31b9
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;
57 // This specifies a folder in the system applications menu (e.g the Start Menu
58 // on Windows).
60 // These represent the applications menu root, the "Google Chrome" folder and
61 // the "Chrome Apps" folder respectively.
63 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the
64 // app with the OS (in order to give its windows shelf icons, and correct icons
65 // and titles), but the app should not show up in menus or search results.
67 // NB: On Linux, these locations may not be used by the window manager (e.g
68 // Unity and Gnome Shell).
69 enum ApplicationsMenuLocation {
70 APP_MENU_LOCATION_NONE,
71 APP_MENU_LOCATION_ROOT,
72 APP_MENU_LOCATION_SUBDIR_CHROME,
73 APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
74 APP_MENU_LOCATION_HIDDEN,
77 // Info about which locations to create app shortcuts in.
78 struct ShortcutLocations {
79 ShortcutLocations();
81 bool on_desktop;
83 ApplicationsMenuLocation applications_menu_location;
85 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
86 // this means "pin to taskbar". For Mac/Linux, this could be used for
87 // Mac dock or the gnome/kde application launcher. However, those are not
88 // implemented yet.
89 bool in_quick_launch_bar;
92 // This encodes the cause of shortcut creation as the correct behavior in each
93 // case is implementation specific.
94 enum ShortcutCreationReason {
95 SHORTCUT_CREATION_BY_USER,
96 SHORTCUT_CREATION_AUTOMATED,
99 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo.
100 typedef base::Callback<void(const ShortcutInfo&,
101 const extensions::FileHandlersInfo&)> InfoCallback;
103 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo.
104 typedef base::Callback<void(const ShortcutInfo&)> ShortcutInfoCallback;
106 #if defined(TOOLKIT_VIEWS)
107 // Extracts shortcut info of the given WebContents.
108 void GetShortcutInfoForTab(content::WebContents* web_contents,
109 ShortcutInfo* info);
110 #endif
112 // Updates web app shortcut of the WebContents. This function checks and
113 // updates web app icon and shortcuts if needed. For icon, the check is based
114 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu
115 // and quick launch (as well as pinned shortcut) for shortcut and only
116 // updates (recreates) them if they exits.
117 void UpdateShortcutForTabContents(content::WebContents* web_contents);
119 ShortcutInfo ShortcutInfoForExtensionAndProfile(
120 const extensions::Extension* app,
121 Profile* profile);
123 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in
124 // |profile| and passes them to |callback| after asynchronously loading all icon
125 // representations.
126 void GetInfoForApp(const extensions::Extension* extension,
127 Profile* profile,
128 const InfoCallback& callback);
130 // Populates a ShortcutInfo for the given |extension| in |profile| and passes
131 // it to |callback| after asynchronously loading all icon representations. This
132 // is equivalent to GetInfoForApp, but it throws away the FileHandlersInfo.
133 void GetShortcutInfoForApp(const extensions::Extension* extension,
134 Profile* profile,
135 const ShortcutInfoCallback& callback);
137 // Whether to create a shortcut for this type of extension.
138 bool ShouldCreateShortcutFor(web_app::ShortcutCreationReason reason,
139 Profile* profile,
140 const extensions::Extension* extension);
142 // Gets the user data directory for given web app. The path for the directory is
143 // based on |extension_id|. If |extension_id| is empty then |url| is used
144 // to construct a unique ID.
145 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
146 const std::string& extension_id,
147 const GURL& url);
149 // Gets the user data directory to use for |extension| located inside
150 // |profile_path|.
151 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
152 const extensions::Extension& extension);
154 // Compute a deterministic name based on data in the shortcut_info.
155 std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info);
157 // Compute a deterministic name based on the URL. We use this pseudo name
158 // as a key to store window location per application URLs in Browser and
159 // as app id for BrowserWindow, shortcut and jump list.
160 std::string GenerateApplicationNameFromURL(const GURL& url);
162 // Compute a deterministic name based on an extension/apps's id.
163 std::string GenerateApplicationNameFromExtensionId(const std::string& id);
165 // Extracts the extension id from the app name.
166 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
168 // Create shortcuts for web application based on given shortcut data.
169 // |shortcut_info| contains information about the shortcuts to create, and
170 // |locations| contains information about where to create them, while
171 // |file_handlers_info| contains information about the file handlers to create.
172 void CreateShortcutsWithInfo(
173 ShortcutCreationReason reason,
174 const ShortcutLocations& locations,
175 const ShortcutInfo& shortcut_info,
176 const extensions::FileHandlersInfo& file_handlers_info);
178 // Currently only called by app_list_service_mac to create a shim for the
179 // app launcher.
180 void CreateNonAppShortcut(const ShortcutLocations& locations,
181 const ShortcutInfo& shortcut_info);
183 // Creates shortcuts for an app. This loads the app's icon from disk, and calls
184 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's
185 // icon loaded, you should use CreateShortcutsWithInfo() directly.
186 void CreateShortcuts(ShortcutCreationReason reason,
187 const ShortcutLocations& locations,
188 Profile* profile,
189 const extensions::Extension* app);
191 // Delete all shortcuts that have been created for the given profile and
192 // extension.
193 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app);
195 // Updates shortcuts for web application based on given shortcut data. This
196 // refreshes existing shortcuts and their icons, but does not create new ones.
197 // |old_app_title| contains the title of the app prior to this update.
198 void UpdateAllShortcuts(const base::string16& old_app_title,
199 Profile* profile,
200 const extensions::Extension* app);
202 // Updates shortcuts for all apps in this profile. This is expected to be called
203 // on the UI thread.
204 void UpdateShortcutsForAllApps(Profile* profile,
205 const base::Closure& callback);
207 // Returns true if given url is a valid web app url.
208 bool IsValidUrl(const GURL& url);
210 #if defined(TOOLKIT_VIEWS)
211 // Extracts icons info from web app data. Take only square shaped icons and
212 // sort them from smallest to largest.
213 typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList;
214 void GetIconsInfo(const WebApplicationInfo& app_info, IconInfoList* icons);
215 #endif
217 #if defined(OS_LINUX)
218 // Windows that correspond to web apps need to have a deterministic (and
219 // different) WMClass than normal chrome windows so the window manager groups
220 // them as a separate application.
221 std::string GetWMClassFromAppName(std::string app_name);
222 #endif
224 namespace internals {
226 #if defined(OS_WIN)
227 // Returns the Windows user-level shortcut paths that are specified in
228 // |creation_locations|.
229 std::vector<base::FilePath> GetShortcutPaths(
230 const ShortcutLocations& creation_locations);
231 #endif
233 // Implemented for each platform, does the platform specific parts of creating
234 // shortcuts. Used internally by CreateShortcuts methods.
235 // |shortcut_data_path| is where to store any resources created for the
236 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
237 // |shortcut_info| contains info about the shortcut to create, and
238 // |creation_locations| contains information about where to create them.
239 bool CreatePlatformShortcuts(
240 const base::FilePath& shortcut_data_path,
241 const ShortcutInfo& shortcut_info,
242 const extensions::FileHandlersInfo& file_handlers_info,
243 const ShortcutLocations& creation_locations,
244 ShortcutCreationReason creation_reason);
246 // Delete all the shortcuts we have added for this extension. This is the
247 // platform specific implementation of the DeleteAllShortcuts function, and
248 // is executed on the FILE thread.
249 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path,
250 const ShortcutInfo& shortcut_info);
252 // Updates all the shortcuts we have added for this extension. This is the
253 // platform specific implementation of the UpdateAllShortcuts function, and
254 // is executed on the FILE thread.
255 void UpdatePlatformShortcuts(
256 const base::FilePath& shortcut_data_path,
257 const base::string16& old_app_title,
258 const ShortcutInfo& shortcut_info,
259 const extensions::FileHandlersInfo& file_handlers_info);
261 // Delete all the shortcuts for an entire profile.
262 // This is executed on the FILE thread.
263 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
265 // Sanitizes |name| and returns a version of it that is safe to use as an
266 // on-disk file name .
267 base::FilePath GetSanitizedFileName(const base::string16& name);
269 } // namespace internals
271 } // namespace web_app
273 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_