Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / web_applications / web_app_mac.h
blobd9062f6830286c9ce102dc4182558f80d68e1f35
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_
8 #include <string>
9 #include <vector>
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"
18 namespace base {
19 class CommandLine;
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;
27 namespace web_app {
29 // Returns the full path of the .app shim that would be created by
30 // CreateShortcuts().
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 {
48 public:
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;
81 protected:
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;
87 private:
88 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, DeleteShortcuts);
89 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon);
90 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateShortcuts);
91 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest,
92 UpdateBookmarkAppShortcut);
94 // Returns the bundle identifier to use for this app bundle.
95 std::string GetBundleIdentifier() const;
97 // Returns the bundle identifier for the internal copy of the bundle.
98 std::string GetInternalBundleIdentifier() const;
100 // Copies the app loader template into a temporary directory and fills in all
101 // relevant information.
102 bool BuildShortcut(const base::FilePath& staging_path) const;
104 // Builds a shortcut and copies it into the given destination folders.
105 // Returns with the number of successful copies. Returns on the first failure.
106 size_t CreateShortcutsIn(const std::vector<base::FilePath>& folders) const;
108 // Updates the InfoPlist.string inside |app_path| with the display name for
109 // the app.
110 bool UpdateDisplayName(const base::FilePath& app_path) const;
112 // Updates the bundle id of the internal copy of the app shim bundle.
113 bool UpdateInternalBundleIdentifier() const;
115 // Updates the plist inside |app_path| with information about the app.
116 bool UpdatePlist(const base::FilePath& app_path) const;
118 // Updates the icon for the shortcut.
119 bool UpdateIcon(const base::FilePath& app_path) const;
121 // Path to the data directory for this app. For example:
122 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
123 base::FilePath app_data_dir_;
125 // Information about the app. Owned by the caller of the constructor.
126 const ShortcutInfo* info_;
128 // The app's file handlers.
129 extensions::FileHandlersInfo file_handlers_info_;
131 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreator);
134 } // namespace web_app
136 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_