| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/shell_integration.h" | 16 #include "chrome/browser/shell_integration.h" |
| 16 #include "chrome/common/web_application_info.h" | 17 #include "chrome/common/web_application_info.h" |
| 17 #include "extensions/common/manifest_handlers/file_handler_info.h" | 18 #include "extensions/common/manifest_handlers/file_handler_info.h" |
| 18 | 19 |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class WebContents; | 23 class WebContents; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 // is still used to generate the app id (windows app id, not chrome app id). | 47 // is still used to generate the app id (windows app id, not chrome app id). |
| 47 std::string extension_id; | 48 std::string extension_id; |
| 48 bool is_platform_app; | 49 bool is_platform_app; |
| 49 base::string16 title; | 50 base::string16 title; |
| 50 base::string16 description; | 51 base::string16 description; |
| 51 base::FilePath extension_path; | 52 base::FilePath extension_path; |
| 52 gfx::ImageFamily favicon; | 53 gfx::ImageFamily favicon; |
| 53 base::FilePath profile_path; | 54 base::FilePath profile_path; |
| 54 std::string profile_name; | 55 std::string profile_name; |
| 55 std::string version_for_display; | 56 std::string version_for_display; |
| 57 |
| 58 private: |
| 59 // ShortcutInfo must not be copied; generally it is passed around via |
| 60 // scoped_ptrs. This is to allow passing ShortcutInfos between threads, |
| 61 // despite ImageFamily having a non-thread-safe reference count. |
| 62 DISALLOW_COPY_AND_ASSIGN(ShortcutInfo); |
| 56 }; | 63 }; |
| 57 | 64 |
| 58 // This specifies a folder in the system applications menu (e.g the Start Menu | 65 // This specifies a folder in the system applications menu (e.g the Start Menu |
| 59 // on Windows). | 66 // on Windows). |
| 60 // | 67 // |
| 61 // These represent the applications menu root, the "Google Chrome" folder and | 68 // These represent the applications menu root, the "Google Chrome" folder and |
| 62 // the "Chrome Apps" folder respectively. | 69 // the "Chrome Apps" folder respectively. |
| 63 // | 70 // |
| 64 // APP_MENU_LOCATION_HIDDEN specifies a shortcut that is used to register the | 71 // 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 | 72 // app with the OS (in order to give its windows shelf icons, and correct icons |
| (...skipping 25 matching lines...) Expand all Loading... |
| 91 }; | 98 }; |
| 92 | 99 |
| 93 // This encodes the cause of shortcut creation as the correct behavior in each | 100 // This encodes the cause of shortcut creation as the correct behavior in each |
| 94 // case is implementation specific. | 101 // case is implementation specific. |
| 95 enum ShortcutCreationReason { | 102 enum ShortcutCreationReason { |
| 96 SHORTCUT_CREATION_BY_USER, | 103 SHORTCUT_CREATION_BY_USER, |
| 97 SHORTCUT_CREATION_AUTOMATED, | 104 SHORTCUT_CREATION_AUTOMATED, |
| 98 }; | 105 }; |
| 99 | 106 |
| 100 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo. | 107 // Called by GetInfoForApp after fetching the ShortcutInfo and FileHandlersInfo. |
| 101 typedef base::Callback<void(const ShortcutInfo&, | 108 typedef base::Callback<void(scoped_ptr<ShortcutInfo>, |
| 102 const extensions::FileHandlersInfo&)> InfoCallback; | 109 const extensions::FileHandlersInfo&)> InfoCallback; |
| 103 | 110 |
| 104 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. | 111 // Called by GetShortcutInfoForApp after fetching the ShortcutInfo. |
| 105 typedef base::Callback<void(const ShortcutInfo&)> ShortcutInfoCallback; | 112 typedef base::Callback<void(scoped_ptr<ShortcutInfo>)> ShortcutInfoCallback; |
| 106 | 113 |
| 107 #if defined(TOOLKIT_VIEWS) | 114 #if defined(TOOLKIT_VIEWS) |
| 108 // Extracts shortcut info of the given WebContents. | 115 // Extracts shortcut info of the given WebContents. |
| 109 void GetShortcutInfoForTab(content::WebContents* web_contents, | 116 scoped_ptr<ShortcutInfo> GetShortcutInfoForTab( |
| 110 ShortcutInfo* info); | 117 content::WebContents* web_contents); |
| 111 #endif | 118 #endif |
| 112 | 119 |
| 113 // Updates web app shortcut of the WebContents. This function checks and | 120 // 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 | 121 // 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 | 122 // 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 | 123 // and quick launch (as well as pinned shortcut) for shortcut and only |
| 117 // updates (recreates) them if they exits. | 124 // updates (recreates) them if they exits. |
| 118 void UpdateShortcutForTabContents(content::WebContents* web_contents); | 125 void UpdateShortcutForTabContents(content::WebContents* web_contents); |
| 119 | 126 |
| 120 ShortcutInfo ShortcutInfoForExtensionAndProfile( | 127 scoped_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile( |
| 121 const extensions::Extension* app, | 128 const extensions::Extension* app, |
| 122 Profile* profile); | 129 Profile* profile); |
| 123 | 130 |
| 124 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in | 131 // Populates a ShortcutInfo and FileHandlersInfo for the given |extension| in |
| 125 // |profile| and passes them to |callback| after asynchronously loading all icon | 132 // |profile| and passes them to |callback| after asynchronously loading all icon |
| 126 // representations. | 133 // representations. |
| 127 void GetInfoForApp(const extensions::Extension* extension, | 134 void GetInfoForApp(const extensions::Extension* extension, |
| 128 Profile* profile, | 135 Profile* profile, |
| 129 const InfoCallback& callback); | 136 const InfoCallback& callback); |
| 130 | 137 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Extracts the extension id from the app name. | 173 // Extracts the extension id from the app name. |
| 167 std::string GetExtensionIdFromApplicationName(const std::string& app_name); | 174 std::string GetExtensionIdFromApplicationName(const std::string& app_name); |
| 168 | 175 |
| 169 // Create shortcuts for web application based on given shortcut data. | 176 // Create shortcuts for web application based on given shortcut data. |
| 170 // |shortcut_info| contains information about the shortcuts to create, and | 177 // |shortcut_info| contains information about the shortcuts to create, and |
| 171 // |locations| contains information about where to create them, while | 178 // |locations| contains information about where to create them, while |
| 172 // |file_handlers_info| contains information about the file handlers to create. | 179 // |file_handlers_info| contains information about the file handlers to create. |
| 173 void CreateShortcutsWithInfo( | 180 void CreateShortcutsWithInfo( |
| 174 ShortcutCreationReason reason, | 181 ShortcutCreationReason reason, |
| 175 const ShortcutLocations& locations, | 182 const ShortcutLocations& locations, |
| 176 const ShortcutInfo& shortcut_info, | 183 scoped_ptr<ShortcutInfo> shortcut_info, |
| 177 const extensions::FileHandlersInfo& file_handlers_info); | 184 const extensions::FileHandlersInfo& file_handlers_info); |
| 178 | 185 |
| 179 // Currently only called by app_list_service_mac to create a shim for the | 186 // Currently only called by app_list_service_mac to create a shim for the |
| 180 // app launcher. | 187 // app launcher. |
| 181 void CreateNonAppShortcut(const ShortcutLocations& locations, | 188 void CreateNonAppShortcut(const ShortcutLocations& locations, |
| 182 const ShortcutInfo& shortcut_info); | 189 scoped_ptr<ShortcutInfo> shortcut_info); |
| 183 | 190 |
| 184 // Creates shortcuts for an app. This loads the app's icon from disk, and calls | 191 // 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 | 192 // CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the app's |
| 186 // icon loaded, you should use CreateShortcutsWithInfo() directly. | 193 // icon loaded, you should use CreateShortcutsWithInfo() directly. |
| 187 void CreateShortcuts(ShortcutCreationReason reason, | 194 void CreateShortcuts(ShortcutCreationReason reason, |
| 188 const ShortcutLocations& locations, | 195 const ShortcutLocations& locations, |
| 189 Profile* profile, | 196 Profile* profile, |
| 190 const extensions::Extension* app); | 197 const extensions::Extension* app); |
| 191 | 198 |
| 192 // Delete all shortcuts that have been created for the given profile and | 199 // Delete all shortcuts that have been created for the given profile and |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 #endif | 239 #endif |
| 233 | 240 |
| 234 // Implemented for each platform, does the platform specific parts of creating | 241 // Implemented for each platform, does the platform specific parts of creating |
| 235 // shortcuts. Used internally by CreateShortcuts methods. | 242 // shortcuts. Used internally by CreateShortcuts methods. |
| 236 // |shortcut_data_path| is where to store any resources created for the | 243 // |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. | 244 // shortcut, and is also used as the UserDataDir for platform app shortcuts. |
| 238 // |shortcut_info| contains info about the shortcut to create, and | 245 // |shortcut_info| contains info about the shortcut to create, and |
| 239 // |creation_locations| contains information about where to create them. | 246 // |creation_locations| contains information about where to create them. |
| 240 bool CreatePlatformShortcuts( | 247 bool CreatePlatformShortcuts( |
| 241 const base::FilePath& shortcut_data_path, | 248 const base::FilePath& shortcut_data_path, |
| 242 const ShortcutInfo& shortcut_info, | 249 scoped_ptr<ShortcutInfo> shortcut_info, |
| 243 const extensions::FileHandlersInfo& file_handlers_info, | 250 const extensions::FileHandlersInfo& file_handlers_info, |
| 244 const ShortcutLocations& creation_locations, | 251 const ShortcutLocations& creation_locations, |
| 245 ShortcutCreationReason creation_reason); | 252 ShortcutCreationReason creation_reason); |
| 246 | 253 |
| 247 // Delete all the shortcuts we have added for this extension. This is the | 254 // Delete all the shortcuts we have added for this extension. This is the |
| 248 // platform specific implementation of the DeleteAllShortcuts function, and | 255 // platform specific implementation of the DeleteAllShortcuts function, and |
| 249 // is executed on the FILE thread. | 256 // is executed on the FILE thread. |
| 250 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, | 257 void DeletePlatformShortcuts(const base::FilePath& shortcut_data_path, |
| 251 const ShortcutInfo& shortcut_info); | 258 scoped_ptr<ShortcutInfo> shortcut_info); |
| 252 | 259 |
| 253 // Updates all the shortcuts we have added for this extension. This is the | 260 // Updates all the shortcuts we have added for this extension. This is the |
| 254 // platform specific implementation of the UpdateAllShortcuts function, and | 261 // platform specific implementation of the UpdateAllShortcuts function, and |
| 255 // is executed on the FILE thread. | 262 // is executed on the FILE thread. |
| 256 void UpdatePlatformShortcuts( | 263 void UpdatePlatformShortcuts( |
| 257 const base::FilePath& shortcut_data_path, | 264 const base::FilePath& shortcut_data_path, |
| 258 const base::string16& old_app_title, | 265 const base::string16& old_app_title, |
| 259 const ShortcutInfo& shortcut_info, | 266 scoped_ptr<ShortcutInfo> shortcut_info, |
| 260 const extensions::FileHandlersInfo& file_handlers_info); | 267 const extensions::FileHandlersInfo& file_handlers_info); |
| 261 | 268 |
| 262 // Delete all the shortcuts for an entire profile. | 269 // Delete all the shortcuts for an entire profile. |
| 263 // This is executed on the FILE thread. | 270 // This is executed on the FILE thread. |
| 264 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); | 271 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path); |
| 265 | 272 |
| 266 // Sanitizes |name| and returns a version of it that is safe to use as an | 273 // Sanitizes |name| and returns a version of it that is safe to use as an |
| 267 // on-disk file name . | 274 // on-disk file name . |
| 268 base::FilePath GetSanitizedFileName(const base::string16& name); | 275 base::FilePath GetSanitizedFileName(const base::string16& name); |
| 269 | 276 |
| 270 } // namespace internals | 277 } // namespace internals |
| 271 | 278 |
| 272 } // namespace web_app | 279 } // namespace web_app |
| 273 | 280 |
| 274 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 281 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
| OLD | NEW |