web_app_mac.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_path.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/string16.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/shell_integration.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __OBJC__
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSDictionary;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class NSString;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else  // __OBJC__
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSDictionary;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NSString;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // __OBJC__
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace web_app {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates a shortcut for a web application. The shortcut is a stub app
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that simply loads the browser framework and runs the given app.
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebAppShortcutCreator {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a new shortcut based on information in |shortcut_info|.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The shortcut stores its user data directory in |user_data_dir|.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebAppShortcutCreator(
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const FilePath& user_data_dir,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const ShellIntegration::ShortcutInfo& shortcut_info,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const string16& chrome_bundle_id);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebAppShortcutCreator();
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Copies the app launcher template into place and fills in all relevant
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // information.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CreateShortcut();
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a path to the app loader.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FilePath GetAppLoaderPath() const;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a path to the destination where the app should be written to.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual FilePath GetDestinationPath(const FilePath& app_file_name) const;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the plist inside |app_path| with information about the app.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool UpdatePlist(const FilePath& app_path) const;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the icon for the shortcut.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool UpdateIcon(const FilePath& app_path) const;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Path to the app's user data directory. For example:
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note, the user data directory is the parent of the profile directory.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FilePath user_data_dir_;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the bundle identifier to use for this app bundle.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |plist| is a dictionary containg a copy of the template plist file to
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be used for creating the app bundle.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSString* GetBundleIdentifier(NSDictionary* plist) const;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Show the bundle we just generated in the Finder.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RevealGeneratedBundleInFinder(
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const FilePath& generated_bundle) const;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Information about the app.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ShellIntegration::ShortcutInfo info_;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The CFBundleIdentifier of the Chrome browser bundle.
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  string16 chrome_bundle_id_;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace web_app
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_
81