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_
11 #include "base/files/file_path.h"
12 #include "base/strings/string16.h"
13 #include "build/build_config.h"
14 #include "chrome/browser/shell_integration.h"
15 #include "chrome/common/web_application_info.h"
17 namespace extensions
{
27 // This encodes the cause of shortcut creation as the correct behavior in each
28 // case is implementation specific.
29 enum ShortcutCreationReason
{
30 SHORTCUT_CREATION_BY_USER
,
31 SHORTCUT_CREATION_AUTOMATED
,
34 // Gets the user data directory for given web app. The path for the directory is
35 // based on |extension_id|. If |extension_id| is empty then |url| is used
36 // to construct a unique ID.
37 base::FilePath
GetWebAppDataDirectory(const base::FilePath
& profile_path
,
38 const std::string
& extension_id
,
41 // Gets the user data directory to use for |extension| located inside
43 base::FilePath
GetWebAppDataDirectory(const base::FilePath
& profile_path
,
44 const extensions::Extension
& extension
);
46 // Compute a deterministic name based on data in the shortcut_info.
47 std::string
GenerateApplicationNameFromInfo(
48 const ShellIntegration::ShortcutInfo
& shortcut_info
);
50 // Compute a deterministic name based on the URL. We use this pseudo name
51 // as a key to store window location per application URLs in Browser and
52 // as app id for BrowserWindow, shortcut and jump list.
53 std::string
GenerateApplicationNameFromURL(const GURL
& url
);
55 // Compute a deterministic name based on an extension/apps's id.
56 std::string
GenerateApplicationNameFromExtensionId(const std::string
& id
);
58 // Extracts the extension id from the app name.
59 std::string
GetExtensionIdFromApplicationName(const std::string
& app_name
);
61 // Creates shortcuts for web application based on given shortcut data.
62 // |shortcut_info| contains information about the shortcuts to create, and
63 // |creation_locations| contains information about where to create them.
65 const ShellIntegration::ShortcutInfo
& shortcut_info
,
66 const ShellIntegration::ShortcutLocations
& creation_locations
,
67 ShortcutCreationReason creation_reason
);
69 // Delete all the shortcuts that have been created for the given
70 // |shortcut_data| in the profile with |profile_path|.
71 void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo
& shortcut_info
);
73 // Updates shortcuts for web application based on given shortcut data. This
74 // refreshes existing shortcuts and their icons, but does not create new ones.
75 // |old_app_title| contains the title of the app prior to this update.
76 // |shortcut_info| contains information about the shortcuts to update.
77 void UpdateAllShortcuts(const base::string16
& old_app_title
,
78 const ShellIntegration::ShortcutInfo
& shortcut_info
);
80 // Creates a shortcut. Must be called on the file thread. This is used to
81 // implement CreateShortcuts() above, and can also be used directly from the
82 // file thread. |shortcut_info| contains info about the shortcut to create, and
83 // |creation_locations| contains information about where to create them.
84 bool CreateShortcutsOnFileThread(
85 const ShellIntegration::ShortcutInfo
& shortcut_info
,
86 const ShellIntegration::ShortcutLocations
& creation_locations
,
87 ShortcutCreationReason creation_reason
);
89 // Returns true if given url is a valid web app url.
90 bool IsValidUrl(const GURL
& url
);
92 #if defined(TOOLKIT_VIEWS)
93 // Extracts icons info from web app data. Take only square shaped icons and
94 // sort them from smallest to largest.
95 typedef std::vector
<WebApplicationInfo::IconInfo
> IconInfoList
;
96 void GetIconsInfo(const WebApplicationInfo
& app_info
,
100 #if defined(OS_LINUX)
101 // Windows that correspond to web apps need to have a deterministic (and
102 // different) WMClass than normal chrome windows so the window manager groups
103 // them as a separate application.
104 std::string
GetWMClassFromAppName(std::string app_name
);
107 namespace internals
{
110 // Returns the Windows user-level shortcut paths that are specified in
111 // |creation_locations|.
112 std::vector
<base::FilePath
> GetShortcutPaths(
113 const ShellIntegration::ShortcutLocations
& creation_locations
);
116 // Implemented for each platform, does the platform specific parts of creating
117 // shortcuts. Used internally by CreateShortcutsOnFileThread.
118 // |shortcut_data_path| is where to store any resources created for the
119 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
120 // |shortcut_info| contains info about the shortcut to create, and
121 // |creation_locations| contains information about where to create them.
122 bool CreatePlatformShortcuts(
123 const base::FilePath
& shortcut_data_path
,
124 const ShellIntegration::ShortcutInfo
& shortcut_info
,
125 const ShellIntegration::ShortcutLocations
& creation_locations
,
126 ShortcutCreationReason creation_reason
);
128 // Delete all the shortcuts we have added for this extension. This is the
129 // platform specific implementation of the DeleteAllShortcuts function, and
130 // is executed on the FILE thread.
131 void DeletePlatformShortcuts(
132 const base::FilePath
& shortcut_data_path
,
133 const ShellIntegration::ShortcutInfo
& shortcut_info
);
135 // Updates all the shortcuts we have added for this extension. This is the
136 // platform specific implementation of the UpdateAllShortcuts function, and
137 // is executed on the FILE thread.
138 void UpdatePlatformShortcuts(
139 const base::FilePath
& shortcut_data_path
,
140 const base::string16
& old_app_title
,
141 const ShellIntegration::ShortcutInfo
& shortcut_info
);
143 // Delete all the shortcuts for an entire profile.
144 // This is executed on the FILE thread.
145 void DeleteAllShortcutsForProfile(const base::FilePath
& profile_path
);
147 // Sanitizes |name| and returns a version of it that is safe to use as an
148 // on-disk file name .
149 base::FilePath
GetSanitizedFileName(const base::string16
& name
);
151 } // namespace internals
153 } // namespace web_app
155 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_