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/memory/ref_counted.h" | |
16 #include "base/sequenced_task_runner_helpers.h" | |
15 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
17 #include "chrome/browser/shell_integration.h" | 19 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/common/web_application_info.h" | 20 #include "chrome/common/web_application_info.h" |
21 #include "content/public/browser/browser_thread.h" | |
19 | 22 |
20 class Profile; | 23 class Profile; |
21 | 24 |
22 namespace content { | 25 namespace content { |
23 class WebContents; | 26 class WebContents; |
24 } | 27 } |
25 | 28 |
26 namespace extensions { | 29 namespace extensions { |
27 class Extension; | 30 class Extension; |
28 } | 31 } |
29 | 32 |
30 namespace gfx { | 33 namespace gfx { |
31 class ImageFamily; | 34 class ImageFamily; |
32 } | 35 } |
33 | 36 |
34 // This namespace contains everything related to integrating Chrome apps into | 37 // This namespace contains everything related to integrating Chrome apps into |
35 // the OS. E.g. creating and updating shorcuts for apps, setting up file | 38 // the OS. E.g. creating and updating shorcuts for apps, setting up file |
36 // associations, etc. | 39 // associations, etc. |
37 namespace web_app { | 40 namespace web_app { |
38 | 41 |
39 // Represents the info required to create a shortcut for an app. | 42 // Represents the info required to create a shortcut for an app. |
40 struct ShortcutInfo { | 43 struct ShortcutInfo : public base::RefCountedThreadSafe< |
44 ShortcutInfo, | |
45 content::BrowserThread::DeleteOnUIThread> { | |
41 ShortcutInfo(); | 46 ShortcutInfo(); |
42 ~ShortcutInfo(); | |
43 | 47 |
44 GURL url; | 48 GURL url; |
45 // If |extension_id| is non-empty, this is short cut is to an extension-app | 49 // If |extension_id| is non-empty, this is short cut is to an extension-app |
46 // and the launch url will be detected at start-up. In this case, |url| | 50 // and the launch url will be detected at start-up. In this case, |url| |
47 // is still used to generate the app id (windows app id, not chrome app id). | 51 // is still used to generate the app id (windows app id, not chrome app id). |
48 std::string extension_id; | 52 std::string extension_id; |
49 bool is_platform_app = false; | 53 bool is_platform_app = false; |
50 bool from_bookmark = false; | 54 bool from_bookmark = false; |
51 base::string16 title; | 55 base::string16 title; |
52 base::string16 description; | 56 base::string16 description; |
53 base::FilePath extension_path; | 57 base::FilePath extension_path; |
54 gfx::ImageFamily favicon; | 58 gfx::ImageFamily favicon; |
55 base::FilePath profile_path; | 59 base::FilePath profile_path; |
56 std::string profile_name; | 60 std::string profile_name; |
57 std::string version_for_display; | 61 std::string version_for_display; |
58 | 62 |
59 private: | 63 private: |
64 friend struct content::BrowserThread::DeleteOnThread< | |
65 content::BrowserThread::UI>; | |
66 friend class base::DeleteHelper<ShortcutInfo>; | |
67 ~ShortcutInfo(); | |
68 | |
60 // ShortcutInfo must not be copied; generally it is passed around via | 69 // ShortcutInfo must not be copied; generally it is passed around via |
61 // scoped_ptrs. This is to allow passing ShortcutInfos between threads, | 70 // scoped_refptrs. This is to allow passing ShortcutInfos between threads, |
62 // despite ImageFamily having a non-thread-safe reference count. | 71 // despite ImageFamily having a non-thread-safe reference count. |
tapted
2017/02/28 23:30:06
I suggest moving this up to a class comment, with
tzik
2017/03/01 05:31:34
Acknowledged.
tzik
2017/03/01 05:32:30
Done.
| |
63 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo); | 72 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo); |
64 }; | 73 }; |
65 | 74 |
66 // This specifies a folder in the system applications menu (e.g the Start Menu | 75 // This specifies a folder in the system applications menu (e.g the Start Menu |
67 // on Windows). | 76 // on Windows). |
68 // | 77 // |
69 // These represent the applications menu root, the "Google Chrome" folder and | 78 // These represent the applications menu root, the "Google Chrome" folder and |
70 // the "Chrome Apps" folder respectively. | 79 // the "Chrome Apps" folder respectively. |
71 // | 80 // |
72 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the | 81 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the |
(...skipping 26 matching lines...) Expand all Loading... | |
99 }; | 108 }; |
100 | 109 |
101 // This encodes the cause of shortcut creation as the correct behavior in each | 110 // This encodes the cause of shortcut creation as the correct behavior in each |
102 // case is implementation specific. | 111 // case is implementation specific. |
103 enum ShortcutCreationReason { | 112 enum ShortcutCreationReason { |
104 SHORTCUT_CREATION_BY_USER, | 113 SHORTCUT_CREATION_BY_USER, |
105 SHORTCUT_CREATION_AUTOMATED, | 114 SHORTCUT_CREATION_AUTOMATED, |
106 }; | 115 }; |
107 | 116 |
108 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. | 117 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. |
109 typedef base::Callback<void(std::unique_ptr<ShortcutInfo>)> | 118 typedef base::Callback<void(scoped_refptr<ShortcutInfo>)> ShortcutInfoCallback; |
110 ShortcutInfoCallback; | |
111 | 119 |
112 #if defined(TOOLKIT_VIEWS) | 120 #if defined(TOOLKIT_VIEWS) |
113 // Extracts shortcut info of the given WebContents. | 121 // Extracts shortcut info of the given WebContents. |
114 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( | 122 scoped_refptr<ShortcutInfo> GetShortcutInfoForTab( |
115 content::WebContents* web_contents); | 123 content::WebContents* web_contents); |
116 #endif | 124 #endif |
117 | 125 |
118 // Updates web app shortcut of the WebContents. This function checks and | 126 // Updates web app shortcut of the WebContents. This function checks and |
119 // updates web app icon and shortcuts if needed. For icon, the check is based | 127 // updates web app icon and shortcuts if needed. For icon, the check is based |
120 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu | 128 // on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu |
121 // and quick launch (as well as pinned shortcut) for shortcut and only | 129 // and quick launch (as well as pinned shortcut) for shortcut and only |
122 // updates (recreates) them if they exits. | 130 // updates (recreates) them if they exits. |
123 void UpdateShortcutForTabContents(content::WebContents* web_contents); | 131 void UpdateShortcutForTabContents(content::WebContents* web_contents); |
124 | 132 |
125 std::unique_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( | 133 scoped_refptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( |
126 const extensions::Extension* app, | 134 const extensions::Extension* app, |
127 Profile* profile); | 135 Profile* profile); |
128 | 136 |
129 // Populates a ShortcutInfo for the given |extension| in |profile| and passes | 137 // Populates a ShortcutInfo for the given |extension| in |profile| and passes |
130 // it to |callback| after asynchronously loading all icon representations. | 138 // it to |callback| after asynchronously loading all icon representations. |
131 void GetShortcutInfoForApp(const extensions::Extension* extension, | 139 void GetShortcutInfoForApp(const extensions::Extension* extension, |
132 Profile* profile, | 140 Profile* profile, |
133 const ShortcutInfoCallback& callback); | 141 const ShortcutInfoCallback& callback); |
134 | 142 |
135 // Whether to create a shortcut for this type of extension. | 143 // Whether to create a shortcut for this type of extension. |
(...skipping 25 matching lines...) Expand all Loading... | |
161 std::string GenerateApplicationNameFromExtensionId(const std::string& id); | 169 std::string GenerateApplicationNameFromExtensionId(const std::string& id); |
162 | 170 |
163 // Extracts the extension id from the app name. | 171 // Extracts the extension id from the app name. |
164 std::string GetExtensionIdFromApplicationName(const std::string& app_name); | 172 std::string GetExtensionIdFromApplicationName(const std::string& app_name); |
165 | 173 |
166 // Create shortcuts for web application based on given shortcut data. | 174 // Create shortcuts for web application based on given shortcut data. |
167 // |shortcut_info| contains information about the shortcuts to create, and | 175 // |shortcut_info| contains information about the shortcuts to create, and |
168 // |locations| contains information about where to create them. | 176 // |locations| contains information about where to create them. |
169 void CreateShortcutsWithInfo(ShortcutCreationReason reason, | 177 void CreateShortcutsWithInfo(ShortcutCreationReason reason, |
170 const ShortcutLocations& locations, | 178 const ShortcutLocations& locations, |
171 std::unique_ptr<ShortcutInfo> shortcut_info); | 179 scoped_refptr<ShortcutInfo> shortcut_info); |
172 | 180 |
173 // Creates shortcuts for an app. This loads the app's icon from disk, and calls | 181 // Creates shortcuts for an app. This loads the app's icon from disk, and calls |
174 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's | 182 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's |
175 // icon loaded, you should use CreateShortcutsWithInfo() directly. | 183 // icon loaded, you should use CreateShortcutsWithInfo() directly. |
176 void CreateShortcuts(ShortcutCreationReason reason, | 184 void CreateShortcuts(ShortcutCreationReason reason, |
177 const ShortcutLocations& locations, | 185 const ShortcutLocations& locations, |
178 Profile* profile, | 186 Profile* profile, |
179 const extensions::Extension* app); | 187 const extensions::Extension* app); |
180 | 188 |
181 // Delete all shortcuts that have been created for the given profile and | 189 // Delete all shortcuts that have been created for the given profile and |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 std::vector<base::FilePath> GetShortcutPaths( | 230 std::vector<base::FilePath> GetShortcutPaths( |
223 const ShortcutLocations& creation_locations); | 231 const ShortcutLocations& creation_locations); |
224 #endif | 232 #endif |
225 | 233 |
226 // Implemented for each platform, does the platform specific parts of creating | 234 // Implemented for each platform, does the platform specific parts of creating |
227 // shortcuts. Used internally by CreateShortcuts methods. | 235 // shortcuts. Used internally by CreateShortcuts methods. |
228 // |shortcut_data_path| is where to store any resources created for the | 236 // |shortcut_data_path| is where to store any resources created for the |
229 // shortcut, and is also used as the UserDataDir for platform app shortcuts. | 237 // shortcut, and is also used as the UserDataDir for platform app shortcuts. |
230 // |shortcut_info| contains info about the shortcut to create, and | 238 // |shortcut_info| contains info about the shortcut to create, and |
231 // |creation_locations| contains information about where to create them. | 239 // |creation_locations| contains information about where to create them. |
232 bool CreatePlatformShortcuts( | 240 bool CreatePlatformShortcuts(const base::FilePath& shortcut_data_path, |
233 const base::FilePath& shortcut_data_path, | 241 scoped_refptr<ShortcutInfo> shortcut_info, |
234 std::unique_ptr<ShortcutInfo> shortcut_info, | 242 const ShortcutLocations& creation_locations, |
235 const ShortcutLocations& creation_locations, | 243 ShortcutCreationReason creation_reason); |
236 ShortcutCreationReason creation_reason); | |
237 | 244 |
238 // Delete all the shortcuts we have added for this extension. This is the | 245 // Delete all the shortcuts we have added for this extension. This is the |
239 // platform specific implementation of the DeleteAllShortcuts function, and | 246 // platform specific implementation of the DeleteAllShortcuts function, and |
240 // is executed on the FILE thread. | 247 // is executed on the FILE thread. |
241 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, | 248 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, |
242 std::unique_ptr<ShortcutInfo> shortcut_info); | 249 scoped_refptr<ShortcutInfo> shortcut_info); |
243 | 250 |
244 // Updates all the shortcuts we have added for this extension. This is the | 251 // Updates all the shortcuts we have added for this extension. This is the |
245 // platform specific implementation of the UpdateAllShortcuts function, and | 252 // platform specific implementation of the UpdateAllShortcuts function, and |
246 // is executed on the FILE thread. | 253 // is executed on the FILE thread. |
247 void UpdatePlatformShortcuts(const base::FilePath& shortcut_data_path, | 254 void UpdatePlatformShortcuts(const base::FilePath& shortcut_data_path, |
248 const base::string16& old_app_title, | 255 const base::string16& old_app_title, |
249 std::unique_ptr<ShortcutInfo> shortcut_info); | 256 scoped_refptr<ShortcutInfo> shortcut_info); |
250 | 257 |
251 // Delete all the shortcuts for an entire profile. | 258 // Delete all the shortcuts for an entire profile. |
252 // This is executed on the FILE thread. | 259 // This is executed on the FILE thread. |
253 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); | 260 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); |
254 | 261 |
255 // Sanitizes |name| and returns a version of it that is safe to use as an | 262 // Sanitizes |name| and returns a version of it that is safe to use as an |
256 // on-disk file name . | 263 // on-disk file name . |
257 base::FilePath GetSanitizedFileName(const base::string16& name); | 264 base::FilePath GetSanitizedFileName(const base::string16& name); |
258 | 265 |
259 } // namespace internals | 266 } // namespace internals |
260 | 267 |
261 } // namespace web_app | 268 } // namespace web_app |
262 | 269 |
263 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 270 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
OLD | NEW |