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" 14a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/web_applications/web_app.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __OBJC__ 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSDictionary; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSString; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else // __OBJC__ 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSDictionary; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSString; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // __OBJC__ 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace web_app { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns the full path of the .app shim that would be created by 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// web_app::CreateShortcuts(). 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)base::FilePath GetAppInstallPath( 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const ShellIntegration::ShortcutInfo& shortcut_info); 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// If necessary, launch the shortcut for an app. 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void MaybeLaunchShortcut(const ShellIntegration::ShortcutInfo& shortcut_info); 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates a shortcut for a web application. The shortcut is a stub app 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that simply loads the browser framework and runs the given app. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebAppShortcutCreator { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a new shortcut based on information in |shortcut_info|. 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // A copy of the shortcut is placed in |app_data_path|. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebAppShortcutCreator( 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const base::FilePath& app_data_path, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ShellIntegration::ShortcutInfo& shortcut_info, 44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::string& chrome_bundle_id); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~WebAppShortcutCreator(); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the base name for the shortcut. 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath GetShortcutName() const; 50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns a path to the Chrome Apps folder in the relevant applications 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // folder. E.g. ~/Applications or /Applications. 53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetDestinationPath() const; 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) bool CreateShortcuts(ShortcutCreationReason creation_reason); 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void DeleteShortcuts(); 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool UpdateShortcuts(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a path to the app loader. 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath GetAppLoaderPath() const; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the plist inside |app_path| with information about the app. 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool UpdatePlist(const base::FilePath& app_path) const; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the icon for the shortcut. 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool UpdateIcon(const base::FilePath& app_path) const; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns a path to an app bundle with the given id. Or an empty path if no 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // matching bundle was found. 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Protected and virtual so it can be mocked out for testing. 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetAppBundleById(const std::string& bundle_id) const; 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 75558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, DeleteShortcuts); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon); 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateShortcuts); 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Copies the app loader template into a temporary directory and fills in all 80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // relevant information. 81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool BuildShortcut(const base::FilePath& staging_path) const; 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Builds a shortcut and copies it into the given destination folders. 84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns with the number of successful copies. Returns on the first failure. 85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch size_t CreateShortcutsIn(const std::vector<base::FilePath>& folders) const; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Updates the InfoPlist.string inside |app_path| with the display name for 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // the app. 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool UpdateDisplayName(const base::FilePath& app_path) const; 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Updates the bundle id of the internal copy of the app shim bundle. 92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool UpdateInternalBundleIdentifier() const; 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the bundle identifier to use for this app bundle. 95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string GetBundleIdentifier() const; 96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the bundle identifier for the internal copy of the bundle. 98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string GetInternalBundleIdentifier() const; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Show the bundle we just generated in the Finder. 101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void RevealAppShimInFinder() const; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Path to the data directory for this app. For example: 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/ 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::FilePath app_data_path_; 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Information about the app. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShellIntegration::ShortcutInfo info_; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The CFBundleIdentifier of the Chrome browser bundle. 111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string chrome_bundle_id_; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace web_app 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_ 117