OLD | NEW |
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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/shell_integration.h" | 17 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/common/web_application_info.h" | 18 #include "chrome/common/web_application_info.h" |
19 #include "extensions/common/manifest_handlers/file_handler_info.h" | |
20 | 19 |
21 class Profile; | 20 class Profile; |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 class WebContents; | 23 class WebContents; |
25 } | 24 } |
26 | 25 |
27 namespace extensions { | 26 namespace extensions { |
28 class Extension; | 27 class Extension; |
29 } | 28 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 bool in_quick_launch_bar; | 98 bool in_quick_launch_bar; |
100 }; | 99 }; |
101 | 100 |
102 // This encodes the cause of shortcut creation as the correct behavior in each | 101 // This encodes the cause of shortcut creation as the correct behavior in each |
103 // case is implementation specific. | 102 // case is implementation specific. |
104 enum ShortcutCreationReason { | 103 enum ShortcutCreationReason { |
105 SHORTCUT_CREATION_BY_USER, | 104 SHORTCUT_CREATION_BY_USER, |
106 SHORTCUT_CREATION_AUTOMATED, | 105 SHORTCUT_CREATION_AUTOMATED, |
107 }; | 106 }; |
108 | 107 |
109 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo. | |
110 typedef base::Callback<void(std::unique_ptr<ShortcutInfo>, | |
111 const extensions::FileHandlersInfo&)> | |
112 InfoCallback; | |
113 | |
114 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. | 108 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. |
115 typedef base::Callback<void(std::unique_ptr<ShortcutInfo>)> | 109 typedef base::Callback<void(std::unique_ptr<ShortcutInfo>)> |
116 ShortcutInfoCallback; | 110 ShortcutInfoCallback; |
117 | 111 |
118 #if defined(TOOLKIT_VIEWS) | 112 #if defined(TOOLKIT_VIEWS) |
119 // Extracts shortcut info of the given WebContents. | 113 // Extracts shortcut info of the given WebContents. |
120 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( | 114 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( |
121 content::WebContents* web_contents); | 115 content::WebContents* web_contents); |
122 #endif | 116 #endif |
123 | 117 |
124 // Updates web app shortcut of the WebContents. This function checks and | 118 // Updates web app shortcut of the WebContents. This function checks and |
125 // updates web app icon and shortcuts if needed. For icon, the check is based | 119 // updates web app icon and shortcuts if needed. For icon, the check is based |
126 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu | 120 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu |
127 // and quick launch (as well as pinned shortcut) for shortcut and only | 121 // and quick launch (as well as pinned shortcut) for shortcut and only |
128 // updates (recreates) them if they exits. | 122 // updates (recreates) them if they exits. |
129 void UpdateShortcutForTabContents(content::WebContents* web_contents); | 123 void UpdateShortcutForTabContents(content::WebContents* web_contents); |
130 | 124 |
131 std::unique_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( | 125 std::unique_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( |
132 const extensions::Extension* app, | 126 const extensions::Extension* app, |
133 Profile* profile); | 127 Profile* profile); |
134 | 128 |
135 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in | |
136 // |profile| and passes them to |callback| after asynchronously loading all icon | |
137 // representations. | |
138 void GetInfoForApp(const extensions::Extension* extension, | |
139 Profile* profile, | |
140 const InfoCallback& callback); | |
141 | |
142 // Populates a ShortcutInfo for the given |extension| in |profile| and passes | 129 // Populates a ShortcutInfo for the given |extension| in |profile| and passes |
143 // it to |callback| after asynchronously loading all icon representations. This | 130 // it to |callback| after asynchronously loading all icon representations. |
144 // is equivalent to GetInfoForApp, but it throws away the FileHandlersInfo. | |
145 void GetShortcutInfoForApp(const extensions::Extension* extension, | 131 void GetShortcutInfoForApp(const extensions::Extension* extension, |
146 Profile* profile, | 132 Profile* profile, |
147 const ShortcutInfoCallback& callback); | 133 const ShortcutInfoCallback& callback); |
148 | 134 |
149 // Whether to create a shortcut for this type of extension. | 135 // Whether to create a shortcut for this type of extension. |
150 bool ShouldCreateShortcutFor(web_app::ShortcutCreationReason reason, | 136 bool ShouldCreateShortcutFor(web_app::ShortcutCreationReason reason, |
151 Profile* profile, | 137 Profile* profile, |
152 const extensions::Extension* extension); | 138 const extensions::Extension* extension); |
153 | 139 |
154 // Gets the user data directory for given web app. The path for the directory is | 140 // Gets the user data directory for given web app. The path for the directory is |
(...skipping 17 matching lines...) Expand all Loading... |
172 std::string GenerateApplicationNameFromURL(const GURL& url); | 158 std::string GenerateApplicationNameFromURL(const GURL& url); |
173 | 159 |
174 // Compute a deterministic name based on an extension/apps's id. | 160 // Compute a deterministic name based on an extension/apps's id. |
175 std::string GenerateApplicationNameFromExtensionId(const std::string& id); | 161 std::string GenerateApplicationNameFromExtensionId(const std::string& id); |
176 | 162 |
177 // Extracts the extension id from the app name. | 163 // Extracts the extension id from the app name. |
178 std::string GetExtensionIdFromApplicationName(const std::string& app_name); | 164 std::string GetExtensionIdFromApplicationName(const std::string& app_name); |
179 | 165 |
180 // Create shortcuts for web application based on given shortcut data. | 166 // Create shortcuts for web application based on given shortcut data. |
181 // |shortcut_info| contains information about the shortcuts to create, and | 167 // |shortcut_info| contains information about the shortcuts to create, and |
182 // |locations| contains information about where to create them, while | 168 // |locations| contains information about where to create them. |
183 // |file_handlers_info| contains information about the file handlers to create. | 169 void CreateShortcutsWithInfo(ShortcutCreationReason reason, |
184 void CreateShortcutsWithInfo( | 170 const ShortcutLocations& locations, |
185 ShortcutCreationReason reason, | 171 std::unique_ptr<ShortcutInfo> shortcut_info); |
186 const ShortcutLocations& locations, | |
187 std::unique_ptr<ShortcutInfo> shortcut_info, | |
188 const extensions::FileHandlersInfo& file_handlers_info); | |
189 | 172 |
190 // Creates shortcuts for an app. This loads the app's icon from disk, and calls | 173 // Creates shortcuts for an app. This loads the app's icon from disk, and calls |
191 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's | 174 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's |
192 // icon loaded, you should use CreateShortcutsWithInfo() directly. | 175 // icon loaded, you should use CreateShortcutsWithInfo() directly. |
193 void CreateShortcuts(ShortcutCreationReason reason, | 176 void CreateShortcuts(ShortcutCreationReason reason, |
194 const ShortcutLocations& locations, | 177 const ShortcutLocations& locations, |
195 Profile* profile, | 178 Profile* profile, |
196 const extensions::Extension* app); | 179 const extensions::Extension* app); |
197 | 180 |
198 // Delete all shortcuts that have been created for the given profile and | 181 // Delete all shortcuts that have been created for the given profile and |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 225 |
243 // Implemented for each platform, does the platform specific parts of creating | 226 // Implemented for each platform, does the platform specific parts of creating |
244 // shortcuts. Used internally by CreateShortcuts methods. | 227 // shortcuts. Used internally by CreateShortcuts methods. |
245 // |shortcut_data_path| is where to store any resources created for the | 228 // |shortcut_data_path| is where to store any resources created for the |
246 // shortcut, and is also used as the UserDataDir for platform app shortcuts. | 229 // shortcut, and is also used as the UserDataDir for platform app shortcuts. |
247 // |shortcut_info| contains info about the shortcut to create, and | 230 // |shortcut_info| contains info about the shortcut to create, and |
248 // |creation_locations| contains information about where to create them. | 231 // |creation_locations| contains information about where to create them. |
249 bool CreatePlatformShortcuts( | 232 bool CreatePlatformShortcuts( |
250 const base::FilePath& shortcut_data_path, | 233 const base::FilePath& shortcut_data_path, |
251 std::unique_ptr<ShortcutInfo> shortcut_info, | 234 std::unique_ptr<ShortcutInfo> shortcut_info, |
252 const extensions::FileHandlersInfo& file_handlers_info, | |
253 const ShortcutLocations& creation_locations, | 235 const ShortcutLocations& creation_locations, |
254 ShortcutCreationReason creation_reason); | 236 ShortcutCreationReason creation_reason); |
255 | 237 |
256 // Delete all the shortcuts we have added for this extension. This is the | 238 // Delete all the shortcuts we have added for this extension. This is the |
257 // platform specific implementation of the DeleteAllShortcuts function, and | 239 // platform specific implementation of the DeleteAllShortcuts function, and |
258 // is executed on the FILE thread. | 240 // is executed on the FILE thread. |
259 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, | 241 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, |
260 std::unique_ptr<ShortcutInfo> shortcut_info); | 242 std::unique_ptr<ShortcutInfo> shortcut_info); |
261 | 243 |
262 // Updates all the shortcuts we have added for this extension. This is the | 244 // Updates all the shortcuts we have added for this extension. This is the |
263 // platform specific implementation of the UpdateAllShortcuts function, and | 245 // platform specific implementation of the UpdateAllShortcuts function, and |
264 // is executed on the FILE thread. | 246 // is executed on the FILE thread. |
265 void UpdatePlatformShortcuts( | 247 void UpdatePlatformShortcuts(const base::FilePath& shortcut_data_path, |
266 const base::FilePath& shortcut_data_path, | 248 const base::string16& old_app_title, |
267 const base::string16& old_app_title, | 249 std::unique_ptr<ShortcutInfo> shortcut_info); |
268 std::unique_ptr<ShortcutInfo> shortcut_info, | |
269 const extensions::FileHandlersInfo& file_handlers_info); | |
270 | 250 |
271 // Delete all the shortcuts for an entire profile. | 251 // Delete all the shortcuts for an entire profile. |
272 // This is executed on the FILE thread. | 252 // This is executed on the FILE thread. |
273 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); | 253 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); |
274 | 254 |
275 // Sanitizes |name| and returns a version of it that is safe to use as an | 255 // Sanitizes |name| and returns a version of it that is safe to use as an |
276 // on-disk file name . | 256 // on-disk file name . |
277 base::FilePath GetSanitizedFileName(const base::string16& name); | 257 base::FilePath GetSanitizedFileName(const base::string16& name); |
278 | 258 |
279 } // namespace internals | 259 } // namespace internals |
280 | 260 |
281 } // namespace web_app | 261 } // namespace web_app |
282 | 262 |
283 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 263 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
OLD | NEW |