| 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_MAC_H_ | 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ |
| 6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ | 6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 10 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 11 #include "chrome/browser/shell_integration.h" | 13 #include "chrome/browser/shell_integration.h" |
| 12 | 14 |
| 13 #ifdef __OBJC__ | 15 #ifdef __OBJC__ |
| 14 @class NSDictionary; | 16 @class NSDictionary; |
| 15 @class NSString; | 17 @class NSString; |
| 16 #else // __OBJC__ | 18 #else // __OBJC__ |
| 17 class NSDictionary; | 19 class NSDictionary; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 31 // Creates a shortcut for a web application. The shortcut is a stub app | 33 // Creates a shortcut for a web application. The shortcut is a stub app |
| 32 // that simply loads the browser framework and runs the given app. | 34 // that simply loads the browser framework and runs the given app. |
| 33 class WebAppShortcutCreator { | 35 class WebAppShortcutCreator { |
| 34 public: | 36 public: |
| 35 // Creates a new shortcut based on information in |shortcut_info|. | 37 // Creates a new shortcut based on information in |shortcut_info|. |
| 36 // A copy of the shortcut is placed in |app_data_path|. | 38 // A copy of the shortcut is placed in |app_data_path|. |
| 37 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle. | 39 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle. |
| 38 WebAppShortcutCreator( | 40 WebAppShortcutCreator( |
| 39 const base::FilePath& app_data_path, | 41 const base::FilePath& app_data_path, |
| 40 const ShellIntegration::ShortcutInfo& shortcut_info, | 42 const ShellIntegration::ShortcutInfo& shortcut_info, |
| 41 const string16& chrome_bundle_id); | 43 const std::string& chrome_bundle_id); |
| 42 | 44 |
| 43 virtual ~WebAppShortcutCreator(); | 45 virtual ~WebAppShortcutCreator(); |
| 44 | 46 |
| 45 // Returns a path to the destination where the app should be written to. | 47 // Returns the base name for the shortcut. |
| 46 base::FilePath GetShortcutPath() const; | 48 base::FilePath GetShortcutName() const; |
| 47 | 49 |
| 48 // Copies the app launcher template into place and fills in all relevant | 50 // Returns a path to the Chrome Apps folder in the relevant applications |
| 49 // information. | 51 // folder. E.g. ~/Applications or /Applications. |
| 50 bool CreateShortcut(); | 52 virtual base::FilePath GetDestinationPath() const; |
| 53 |
| 54 bool CreateShortcuts(); |
| 55 void DeleteShortcuts(); |
| 56 bool UpdateShortcuts(); |
| 51 | 57 |
| 52 protected: | 58 protected: |
| 53 // Returns a path to the app loader. | 59 // Returns a path to the app loader. |
| 54 base::FilePath GetAppLoaderPath() const; | 60 base::FilePath GetAppLoaderPath() const; |
| 55 | 61 |
| 56 // Returns a path to the destination where the app should be written to. | |
| 57 virtual base::FilePath GetDestinationPath() const; | |
| 58 | |
| 59 // Updates the plist inside |app_path| with information about the app. | 62 // Updates the plist inside |app_path| with information about the app. |
| 60 bool UpdatePlist(const base::FilePath& app_path) const; | 63 bool UpdatePlist(const base::FilePath& app_path) const; |
| 61 | 64 |
| 62 // Updates the icon for the shortcut. | 65 // Updates the icon for the shortcut. |
| 63 bool UpdateIcon(const base::FilePath& app_path) const; | 66 bool UpdateIcon(const base::FilePath& app_path) const; |
| 64 | 67 |
| 68 // Returns a path to an app bundle with the given id. Or an empty path if no |
| 69 // matching bundle was found. |
| 70 // Protected and virtual so it can be mocked out for testing. |
| 71 virtual base::FilePath GetAppBundleById(const std::string& bundle_id) const; |
| 72 |
| 65 private: | 73 private: |
| 66 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon); | 74 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon); |
| 75 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateShortcuts); |
| 76 |
| 77 // Copies the app loader template into a temporary directory and fills in all |
| 78 // relevant information. |
| 79 bool BuildShortcut(const base::FilePath& staging_path) const; |
| 80 |
| 81 // Builds a shortcut and copies it into the given destination folders. |
| 82 // Returns with the number of successful copies. Returns on the first failure. |
| 83 size_t CreateShortcutsIn(const std::vector<base::FilePath>& folders) const; |
| 67 | 84 |
| 68 // Updates the InfoPlist.string inside |app_path| with the display name for | 85 // Updates the InfoPlist.string inside |app_path| with the display name for |
| 69 // the app. | 86 // the app. |
| 70 bool UpdateDisplayName(const base::FilePath& app_path) const; | 87 bool UpdateDisplayName(const base::FilePath& app_path) const; |
| 71 | 88 |
| 89 // Updates the bundle id of the internal copy of the app shim bundle. |
| 90 bool UpdateInternalBundleIdentifier() const; |
| 91 |
| 72 // Returns the bundle identifier to use for this app bundle. | 92 // Returns the bundle identifier to use for this app bundle. |
| 73 // |plist| is a dictionary containg a copy of the template plist file to | 93 std::string GetBundleIdentifier() const; |
| 74 // be used for creating the app bundle. | 94 |
| 75 NSString* GetBundleIdentifier(NSDictionary* plist) const; | 95 // Returns the bundle identifier for the internal copy of the bundle. |
| 96 std::string GetInternalBundleIdentifier() const; |
| 76 | 97 |
| 77 // Show the bundle we just generated in the Finder. | 98 // Show the bundle we just generated in the Finder. |
| 78 virtual void RevealGeneratedBundleInFinder( | 99 virtual void RevealAppShimInFinder() const; |
| 79 const base::FilePath& generated_bundle) const; | |
| 80 | 100 |
| 81 // Path to the data directory for this app. For example: | 101 // Path to the data directory for this app. For example: |
| 82 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/ | 102 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/ |
| 83 base::FilePath app_data_path_; | 103 base::FilePath app_data_path_; |
| 84 | 104 |
| 85 // Information about the app. | 105 // Information about the app. |
| 86 ShellIntegration::ShortcutInfo info_; | 106 ShellIntegration::ShortcutInfo info_; |
| 87 | 107 |
| 88 // The CFBundleIdentifier of the Chrome browser bundle. | 108 // The CFBundleIdentifier of the Chrome browser bundle. |
| 89 string16 chrome_bundle_id_; | 109 std::string chrome_bundle_id_; |
| 90 }; | 110 }; |
| 91 | 111 |
| 92 } // namespace web_app | 112 } // namespace web_app |
| 93 | 113 |
| 94 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ | 114 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ |
| OLD | NEW |