web_app_mac.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <vector> 9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h" 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/shell_integration.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __OBJC__ 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSDictionary; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSString; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else // __OBJC__ 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSDictionary; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSString; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // __OBJC__ 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace web_app { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns the full path of the .app shim that would be created by 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// web_app::CreateShortcuts(). 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)base::FilePath GetAppInstallPath( 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const ShellIntegration::ShortcutInfo& shortcut_info); 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// If necessary, launch the shortcut for an app. 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void MaybeLaunchShortcut(const ShellIntegration::ShortcutInfo& shortcut_info); 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates a shortcut for a web application. The shortcut is a stub app 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that simply loads the browser framework and runs the given app. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebAppShortcutCreator { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a new shortcut based on information in |shortcut_info|. 387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // A copy of the shortcut is placed in |app_data_path|. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebAppShortcutCreator( 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const base::FilePath& app_data_path, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellIntegration::ShortcutInfo& shortcut_info, 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::string& chrome_bundle_id); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~WebAppShortcutCreator(); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the base name for the shortcut. 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath GetShortcutName() const; 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns a path to the Chrome Apps folder in the relevant applications 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // folder. E.g. ~/Applications or /Applications. 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetDestinationPath() const; 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool CreateShortcuts(); 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void DeleteShortcuts(); 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool UpdateShortcuts(); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a path to the app loader. 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath GetAppLoaderPath() const; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the plist inside |app_path| with information about the app. 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool UpdatePlist(const base::FilePath& app_path) const; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the icon for the shortcut. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool UpdateIcon(const base::FilePath& app_path) const; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns a path to an app bundle with the given id. Or an empty path if no 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // matching bundle was found. 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Protected and virtual so it can be mocked out for testing. 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetAppBundleById(const std::string& bundle_id) const; 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon); 75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateShortcuts); 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Copies the app loader template into a temporary directory and fills in all 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // relevant information. 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool BuildShortcut(const base::FilePath& staging_path) const; 80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Builds a shortcut and copies it into the given destination folders. 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns with the number of successful copies. Returns on the first failure. 83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch size_t CreateShortcutsIn(const std::vector<base::FilePath>& folders) const; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Updates the InfoPlist.string inside |app_path| with the display name for 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // the app. 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool UpdateDisplayName(const base::FilePath& app_path) const; 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Updates the bundle id of the internal copy of the app shim bundle. 90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool UpdateInternalBundleIdentifier() const; 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the bundle identifier to use for this app bundle. 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string GetBundleIdentifier() const; 94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the bundle identifier for the internal copy of the bundle. 96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string GetInternalBundleIdentifier() const; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Show the bundle we just generated in the Finder. 99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void RevealAppShimInFinder() const; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Path to the data directory for this app. For example: 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/ 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::FilePath app_data_path_; 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Information about the app. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellIntegration::ShortcutInfo info_; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The CFBundleIdentifier of the Chrome browser bundle. 109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string chrome_bundle_id_; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace web_app 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 115