- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / web_applications / web_app.h
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_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/files/file_path.h"
12 #include "base/strings/string16.h"
13 #include "build/build_config.h"
14 #include "chrome/browser/shell_integration.h"
15 #include "chrome/common/web_application_info.h"
16
17 namespace extensions {
18 class Extension;
19 }
20
21 namespace gfx {
22 class ImageFamily;
23 }
24
25 namespace web_app {
26
27 // This encodes the cause of shortcut creation as the correct behavior in each
28 // case is implementation specific.
29 enum ShortcutCreationReason {
30   SHORTCUT_CREATION_BY_USER,
31   SHORTCUT_CREATION_AUTOMATED,
32 };
33
34 // Gets the user data directory for given web app. The path for the directory is
35 // based on |extension_id|. If |extension_id| is empty then |url| is used
36 // to construct a unique ID.
37 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
38                                       const std::string& extension_id,
39                                       const GURL& url);
40
41 // Gets the user data directory to use for |extension| located inside
42 // |profile_path|.
43 base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
44                                       const extensions::Extension& extension);
45
46 // Compute a deterministic name based on data in the shortcut_info.
47 std::string GenerateApplicationNameFromInfo(
48     const ShellIntegration::ShortcutInfo& shortcut_info);
49
50 // Compute a deterministic name based on the URL. We use this pseudo name
51 // as a key to store window location per application URLs in Browser and
52 // as app id for BrowserWindow, shortcut and jump list.
53 std::string GenerateApplicationNameFromURL(const GURL& url);
54
55 // Compute a deterministic name based on an extension/apps's id.
56 std::string GenerateApplicationNameFromExtensionId(const std::string& id);
57
58 // Extracts the extension id from the app name.
59 std::string GetExtensionIdFromApplicationName(const std::string& app_name);
60
61 // Creates shortcuts for web application based on given shortcut data.
62 // |shortcut_info| contains information about the shortcuts to create, and
63 // |creation_locations| contains information about where to create them.
64 void CreateShortcuts(
65     const ShellIntegration::ShortcutInfo& shortcut_info,
66     const ShellIntegration::ShortcutLocations& creation_locations,
67     ShortcutCreationReason creation_reason);
68
69 // Delete all the shortcuts that have been created for the given
70 // |shortcut_data| in the profile with |profile_path|.
71 void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info);
72
73 // Updates shortcuts for web application based on given shortcut data. This
74 // refreshes existing shortcuts and their icons, but does not create new ones.
75 // |old_app_title| contains the title of the app prior to this update.
76 // |shortcut_info| contains information about the shortcuts to update.
77 void UpdateAllShortcuts(const string16& old_app_title,
78                         const ShellIntegration::ShortcutInfo& shortcut_info);
79
80 // Creates a shortcut. Must be called on the file thread. This is used to
81 // implement CreateShortcuts() above, and can also be used directly from the
82 // file thread. |shortcut_info| contains info about the shortcut to create, and
83 // |creation_locations| contains information about where to create them.
84 bool CreateShortcutsOnFileThread(
85     const ShellIntegration::ShortcutInfo& shortcut_info,
86     const ShellIntegration::ShortcutLocations& creation_locations,
87     ShortcutCreationReason creation_reason);
88
89 // Returns true if given url is a valid web app url.
90 bool IsValidUrl(const GURL& url);
91
92 #if defined(TOOLKIT_VIEWS)
93 // Extracts icons info from web app data. Take only square shaped icons and
94 // sort them from smallest to largest.
95 typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList;
96 void GetIconsInfo(const WebApplicationInfo& app_info,
97                   IconInfoList* icons);
98 #endif
99
100 #if defined(OS_LINUX)
101 // Windows that correspond to web apps need to have a deterministic (and
102 // different) WMClass than normal chrome windows so the window manager groups
103 // them as a separate application.
104 std::string GetWMClassFromAppName(std::string app_name);
105 #endif
106
107 // Gets the name of the Chrome Apps menu folder in which to place app shortcuts.
108 string16 GetAppShortcutsSubdirName();
109
110 namespace internals {
111
112 #if defined(OS_WIN)
113 std::vector<base::FilePath> GetShortcutPaths(
114     const ShellIntegration::ShortcutLocations& creation_locations);
115 #endif
116
117 // Implemented for each platform, does the platform specific parts of creating
118 // shortcuts. Used internally by CreateShortcutsOnFileThread.
119 // |shortcut_data_path| is where to store any resources created for the
120 // shortcut, and is also used as the UserDataDir for platform app shortcuts.
121 // |shortcut_info| contains info about the shortcut to create, and
122 // |creation_locations| contains information about where to create them.
123 bool CreatePlatformShortcuts(
124     const base::FilePath& shortcut_data_path,
125     const ShellIntegration::ShortcutInfo& shortcut_info,
126     const ShellIntegration::ShortcutLocations& creation_locations,
127     ShortcutCreationReason creation_reason);
128
129 // Delete all the shortcuts we have added for this extension. This is the
130 // platform specific implementation of the DeleteAllShortcuts function, and
131 // is executed on the FILE thread.
132 void DeletePlatformShortcuts(
133     const base::FilePath& shortcut_data_path,
134     const ShellIntegration::ShortcutInfo& shortcut_info);
135
136 // Updates all the shortcuts we have added for this extension. This is the
137 // platform specific implementation of the UpdateAllShortcuts function, and
138 // is executed on the FILE thread.
139 void UpdatePlatformShortcuts(
140     const base::FilePath& shortcut_data_path,
141     const string16& old_app_title,
142     const ShellIntegration::ShortcutInfo& shortcut_info);
143
144 // Delete all the shortcuts for an entire profile.
145 // This is executed on the FILE thread.
146 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path);
147
148 // Sanitizes |name| and returns a version of it that is safe to use as an
149 // on-disk file name .
150 base::FilePath GetSanitizedFileName(const string16& name);
151
152 }  // namespace internals
153
154 }  // namespace web_app
155
156 #endif  // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_