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 "base/memory/scoped_ptr.h"
15 #include "chrome/browser/web_applications/web_app.h"
16 #include "extensions/common/manifest_handlers/file_handler_info.h"
22 // Whether to enable update and launch of app shims in tests. (Normally shims
23 // are never created or launched in tests). Note that update only creates
24 // internal shim bundles, i.e. it does not create new shims in ~/Applications.
25 extern bool g_app_shims_allow_update_and_launch_in_tests
;
29 // Returns the full path of the .app shim that would be created by
31 base::FilePath
GetAppInstallPath(const ShortcutInfo
& shortcut_info
);
33 // If necessary, launch the shortcut for an app.
34 void MaybeLaunchShortcut(scoped_ptr
<ShortcutInfo
> shortcut_info
);
36 // Rebuild the shortcut and relaunch it.
37 bool MaybeRebuildShortcut(const base::CommandLine
& command_line
);
39 // Reveals app shim in Finder given a profile and app.
40 // Calls RevealAppShimInFinderForAppOnFileThread and schedules it
41 // on the FILE thread.
42 void RevealAppShimInFinderForApp(Profile
* profile
,
43 const extensions::Extension
* app
);
45 // Creates a shortcut for a web application. The shortcut is a stub app
46 // that simply loads the browser framework and runs the given app.
47 class WebAppShortcutCreator
{
49 // Creates a new shortcut based on information in |shortcut_info|.
50 // A copy of the shortcut is placed in |app_data_dir|.
51 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle.
52 // Retains the pointer |shortcut_info|; the ShortcutInfo object must outlive
53 // the WebAppShortcutCreator.
54 WebAppShortcutCreator(const base::FilePath
& app_data_dir
,
55 const ShortcutInfo
* shortcut_info
,
56 const extensions::FileHandlersInfo
& file_handlers_info
);
58 virtual ~WebAppShortcutCreator();
60 // Returns the base name for the shortcut.
61 base::FilePath
GetShortcutBasename() const;
63 // Returns a path to the Chrome Apps folder in the relevant applications
64 // folder. E.g. ~/Applications or /Applications.
65 virtual base::FilePath
GetApplicationsDirname() const;
67 // The full path to the app bundle under the relevant Applications folder.
68 base::FilePath
GetApplicationsShortcutPath() const;
70 // The full path to the app bundle under the profile folder.
71 base::FilePath
GetInternalShortcutPath() const;
73 bool CreateShortcuts(ShortcutCreationReason creation_reason
,
74 ShortcutLocations creation_locations
);
75 void DeleteShortcuts();
76 bool UpdateShortcuts();
78 // Show the bundle we just generated in the Finder.
79 virtual void RevealAppShimInFinder() const;
82 // Returns a path to an app bundle with the given id. Or an empty path if no
83 // matching bundle was found.
84 // Protected and virtual so it can be mocked out for testing.
85 virtual base::FilePath
GetAppBundleById(const std::string
& bundle_id
) const;
88 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, DeleteShortcuts
);
89 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateIcon
);
90 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateShortcuts
);
92 // Returns the bundle identifier to use for this app bundle.
93 std::string
GetBundleIdentifier() const;
95 // Returns the bundle identifier for the internal copy of the bundle.
96 std::string
GetInternalBundleIdentifier() const;
98 // Copies the app loader template into a temporary directory and fills in all
99 // relevant information.
100 bool BuildShortcut(const base::FilePath
& staging_path
) const;
102 // Builds a shortcut and copies it into the given destination folders.
103 // Returns with the number of successful copies. Returns on the first failure.
104 size_t CreateShortcutsIn(const std::vector
<base::FilePath
>& folders
) const;
106 // Updates the InfoPlist.string inside |app_path| with the display name for
108 bool UpdateDisplayName(const base::FilePath
& app_path
) const;
110 // Updates the bundle id of the internal copy of the app shim bundle.
111 bool UpdateInternalBundleIdentifier() const;
113 // Updates the plist inside |app_path| with information about the app.
114 bool UpdatePlist(const base::FilePath
& app_path
) const;
116 // Updates the icon for the shortcut.
117 bool UpdateIcon(const base::FilePath
& app_path
) const;
119 // Path to the data directory for this app. For example:
120 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
121 base::FilePath app_data_dir_
;
123 // Information about the app. Owned by the caller of the constructor.
124 const ShortcutInfo
* info_
;
126 // The app's file handlers.
127 extensions::FileHandlersInfo file_handlers_info_
;
129 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreator
);
132 } // namespace web_app
134 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_