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 // Reveals app shim in Finder given a profile and app.
39 // Calls RevealAppShimInFinderForAppOnFileThread and schedules it
40 // on the FILE thread.
41 void RevealAppShimInFinderForApp(Profile
* profile
,
42 const extensions::Extension
* app
);
44 // Creates a shortcut for a web application. The shortcut is a stub app
45 // that simply loads the browser framework and runs the given app.
46 class WebAppShortcutCreator
{
48 // Creates a new shortcut based on information in |shortcut_info|.
49 // A copy of the shortcut is placed in |app_data_dir|.
50 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle.
51 WebAppShortcutCreator(const base::FilePath
& app_data_dir
,
52 const ShortcutInfo
& shortcut_info
,
53 const extensions::FileHandlersInfo
& file_handlers_info
);
55 virtual ~WebAppShortcutCreator();
57 // Returns the base name for the shortcut.
58 base::FilePath
GetShortcutBasename() const;
60 // Returns a path to the Chrome Apps folder in the relevant applications
61 // folder. E.g. ~/Applications or /Applications.
62 virtual base::FilePath
GetApplicationsDirname() const;
64 // The full path to the app bundle under the relevant Applications folder.
65 base::FilePath
GetApplicationsShortcutPath() const;
67 // The full path to the app bundle under the profile folder.
68 base::FilePath
GetInternalShortcutPath() const;
70 bool CreateShortcuts(ShortcutCreationReason creation_reason
,
71 ShortcutLocations creation_locations
);
72 void DeleteShortcuts();
73 bool UpdateShortcuts();
75 // Show the bundle we just generated in the Finder.
76 virtual void RevealAppShimInFinder() const;
79 // Returns a path to an app bundle with the given id. Or an empty path if no
80 // matching bundle was found.
81 // Protected and virtual so it can be mocked out for testing.
82 virtual base::FilePath
GetAppBundleById(const std::string
& bundle_id
) const;
85 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, DeleteShortcuts
);
86 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateIcon
);
87 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest
, UpdateShortcuts
);
89 // Returns the bundle identifier to use for this app bundle.
90 std::string
GetBundleIdentifier() const;
92 // Returns the bundle identifier for the internal copy of the bundle.
93 std::string
GetInternalBundleIdentifier() const;
95 // Copies the app loader template into a temporary directory and fills in all
96 // relevant information.
97 bool BuildShortcut(const base::FilePath
& staging_path
) const;
99 // Builds a shortcut and copies it into the given destination folders.
100 // Returns with the number of successful copies. Returns on the first failure.
101 size_t CreateShortcutsIn(const std::vector
<base::FilePath
>& folders
) const;
103 // Updates the InfoPlist.string inside |app_path| with the display name for
105 bool UpdateDisplayName(const base::FilePath
& app_path
) const;
107 // Updates the bundle id of the internal copy of the app shim bundle.
108 bool UpdateInternalBundleIdentifier() const;
110 // Updates the plist inside |app_path| with information about the app.
111 bool UpdatePlist(const base::FilePath
& app_path
) const;
113 // Updates the icon for the shortcut.
114 bool UpdateIcon(const base::FilePath
& app_path
) const;
116 // Path to the data directory for this app. For example:
117 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
118 base::FilePath app_data_dir_
;
120 // Information about the app.
123 // The app's file handlers.
124 extensions::FileHandlersInfo file_handlers_info_
;
126 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreator
);
129 } // namespace web_app
131 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_