summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications/web_app_mac.h
blob: 94331c4cba51d971c9316edd2e66941c7c48277c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_

#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/string16.h"
#include "chrome/browser/shell_integration.h"

#ifdef __OBJC__
@class NSDictionary;
@class NSString;
#else  // __OBJC__
class NSDictionary;
class NSString;
#endif  // __OBJC__

namespace web_app {

// Creates a shortcut for a web application. The shortcut is a stub app
// that simply loads the browser framework and runs the given app.
class WebAppShortcutCreator {
 public:
  // Creates a new shortcut based on information in |shortcut_info|.
  // The shortcut stores its user data directory in |user_data_dir|.
  // |chrome_bundle_id| is the CFBundleIdentifier of the Chrome browser bundle.
  WebAppShortcutCreator(
      const FilePath& user_data_dir,
      const ShellIntegration::ShortcutInfo& shortcut_info,
      const string16& chrome_bundle_id);

  virtual ~WebAppShortcutCreator();

  // Copies the app launcher template into place and fills in all relevant
  // information.
  bool CreateShortcut();

 protected:
  // Returns a path to the app loader.
  FilePath GetAppLoaderPath() const;

  // Returns a path to the destination where the app should be written to.
  virtual FilePath GetDestinationPath(const FilePath& app_file_name) const;

  // Updates the plist inside |app_path| with information about the app.
  bool UpdatePlist(const FilePath& app_path) const;

  // Updates the icon for the shortcut.
  bool UpdateIcon(const FilePath& app_path) const;

 private:
  FRIEND_TEST_ALL_PREFIXES(WebAppShortcutCreatorTest, UpdateIcon);

  // Path to the app's user data directory. For example:
  // ~/Library/Application Support/Chromium/Default/Web Applications/_crx_abc/
  // Note, the user data directory is the parent of the profile directory.
  FilePath user_data_dir_;

  // Returns the bundle identifier to use for this app bundle.
  // |plist| is a dictionary containg a copy of the template plist file to
  // be used for creating the app bundle.
  NSString* GetBundleIdentifier(NSDictionary* plist) const;

  // Show the bundle we just generated in the Finder.
  virtual void RevealGeneratedBundleInFinder(
      const FilePath& generated_bundle) const;

  // Information about the app.
  ShellIntegration::ShortcutInfo info_;

  // The CFBundleIdentifier of the Chrome browser bundle.
  string16 chrome_bundle_id_;
};

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_MAC_H_