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_MAC_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "chrome/browser/web_applications/web_app.h"
15 #include "extensions/common/manifest_handlers/file_handler_info.h"
21 // Whether to enable update and launch of app shims in tests. (Normally shims
22 // are never created or launched in tests). Note that update only creates
23 // internal shim bundles, i.e. it does not create new shims in ~/Applications.
24 extern bool g_app_shims_allow_update_and_launch_in_tests
;
28 // Returns the full path of the .app shim that would be created by
30 base::FilePath
GetAppInstallPath(const ShortcutInfo
& shortcut_info
);
32 // If necessary, launch the shortcut for an app.
33 void MaybeLaunchShortcut(const ShortcutInfo
& shortcut_info
);
35 // Rebuild the shortcut and relaunch it.
36 bool MaybeRebuildShortcut(const base::CommandLine
& command_line
);
38 // Creates a shortcut for a web application. The shortcut is a stub app
39 // that simply loads the browser framework and runs the given app.
40 class WebAppShortcutCreator
{
42 // Creates a new shortcut based on information in |shortcut_info|.
43 // A copy of the shortcut is placed in |app_data_dir|.
44 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle.
45 WebAppShortcutCreator(const base::FilePath
& app_data_dir
,
46 const ShortcutInfo
& shortcut_info
,
47 const extensions::FileHandlersInfo
& file_handlers_info
);
49 virtual ~WebAppShortcutCreator();
51 // Returns the base name for the shortcut.
52 base::FilePath
GetShortcutBasename() const;
54 // Returns a path to the Chrome Apps folder in the relevant applications
55 // folder. E.g. ~/Applications or /Applications.
56 virtual base::FilePath
GetApplicationsDirname() const;
58 // The full path to the app bundle under the relevant Applications folder.
59 base::FilePath
GetApplicationsShortcutPath() const;
61 // The full path to the app bundle under the profile folder.
62 base::FilePath
GetInternalShortcutPath() const;
64 bool CreateShortcuts(ShortcutCreationReason creation_reason
,
65 ShortcutLocations creation_locations
);
66 void DeleteShortcuts();
67 bool UpdateShortcuts();
70 // Returns a path to an app bundle with the given id. Or an empty path if no
71 // matching bundle was found.
72 // Protected and virtual so it can be mocked out for testing.
73 virtual base::FilePath
GetAppBundleById(const std::string
& bundle_id
) const;
75 // Show the bundle we just generated in the Finder.
76 virtual void RevealAppShimInFinder() const;
79 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, DeleteShortcuts
);
80 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateIcon
);
81 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateShortcuts
);
83 // Returns the bundle identifier to use for this app bundle.
84 std::string
GetBundleIdentifier() const;
86 // Returns the bundle identifier for the internal copy of the bundle.
87 std::string
GetInternalBundleIdentifier() const;
89 // Copies the app loader template into a temporary directory and fills in all
90 // relevant information.
91 bool BuildShortcut(const base::FilePath
& staging_path
) const;
93 // Builds a shortcut and copies it into the given destination folders.
94 // Returns with the number of successful copies. Returns on the first failure.
95 size_t CreateShortcutsIn(const std::vector
<base::FilePath
>& folders
) const;
97 // Updates the InfoPlist.string inside |app_path| with the display name for
99 bool UpdateDisplayName(const base::FilePath
& app_path
) const;
101 // Updates the bundle id of the internal copy of the app shim bundle.
102 bool UpdateInternalBundleIdentifier() const;
104 // Updates the plist inside |app_path| with information about the app.
105 bool UpdatePlist(const base::FilePath
& app_path
) const;
107 // Updates the icon for the shortcut.
108 bool UpdateIcon(const base::FilePath
& app_path
) const;
110 // Path to the data directory for this app. For example:
111 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
112 base::FilePath app_data_dir_
;
114 // Information about the app.
117 // The app's file handlers.
118 extensions::FileHandlersInfo file_handlers_info_
;
120 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreator
);
123 } // namespace web_app
125 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_