web_app_mac.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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. 4 5#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 6#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 7 8#include "base/files/file_path.h" 9#include "base/gtest_prod_util.h" 10#include "base/string16.h" 11#include "chrome/browser/shell_integration.h" 12 13#ifdef __OBJC__ 14@class NSDictionary; 15@class NSString; 16#else // __OBJC__ 17class NSDictionary; 18class NSString; 19#endif // __OBJC__ 20 21namespace web_app { 22 23// Returns the full path of the .app shim that would be created by 24// web_app::CreateShortcuts(). 25base::FilePath GetAppInstallPath( 26 const ShellIntegration::ShortcutInfo& shortcut_info); 27 28// Creates a shortcut for a web application. The shortcut is a stub app 29// that simply loads the browser framework and runs the given app. 30class WebAppShortcutCreator { 31 public: 32 // Creates a new shortcut based on information in |shortcut_info|. 33 // The shortcut stores its user data directory in |user_data_dir|. 34 // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle. 35 WebAppShortcutCreator( 36 const base::FilePath& user_data_dir, 37 const ShellIntegration::ShortcutInfo& shortcut_info, 38 const string16& chrome_bundle_id); 39 40 virtual ~WebAppShortcutCreator(); 41 42 // Returns a path to the destination where the app should be written to. 43 base::FilePath GetShortcutPath() const; 44 45 // Copies the app launcher template into place and fills in all relevant 46 // information. 47 bool CreateShortcut(); 48 49 protected: 50 // Returns a path to the app loader. 51 base::FilePath GetAppLoaderPath() const; 52 53 // Returns a path to the destination where the app should be written to. 54 virtual base::FilePath GetDestinationPath() const; 55 56 // Updates the plist inside |app_path| with information about the app. 57 bool UpdatePlist(const base::FilePath& app_path) const; 58 59 // Updates the icon for the shortcut. 60 bool UpdateIcon(const base::FilePath& app_path) const; 61 62 private: 63 FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon); 64 65 // Path to the app's user data directory. For example: 66 // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/ 67 // Note, the user data directory is the parent of the profile directory. 68 base::FilePath user_data_dir_; 69 70 // Returns the bundle identifier to use for this app bundle. 71 // |plist| is a dictionary containg a copy of the template plist file to 72 // be used for creating the app bundle. 73 NSString* GetBundleIdentifier(NSDictionary* plist) const; 74 75 // Show the bundle we just generated in the Finder. 76 virtual void RevealGeneratedBundleInFinder( 77 const base::FilePath& generated_bundle) const; 78 79 // Information about the app. 80 ShellIntegration::ShortcutInfo info_; 81 82 // The CFBundleIdentifier of the Chrome browser bundle. 83 string16 chrome_bundle_id_; 84}; 85 86} // namespace web_app 87 88#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 89