OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 6 #define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/shell_integration.h" | 14 #include "chrome/browser/shell_integration.h" |
15 #include "chrome/common/web_apps.h" | 15 #include "chrome/common/web_apps.h" |
16 | 16 |
| 17 class Extension; |
| 18 |
17 namespace web_app { | 19 namespace web_app { |
18 | 20 |
| 21 // Gets the user data directory for given web app. The path for the directory is |
| 22 // based on |extension_id|. If |extension_id| is empty then |url| is used |
| 23 // to construct a unique ID. |
| 24 FilePath GetWebAppDataDirectory(const FilePath& profile_path, |
| 25 const std::string& extension_id, |
| 26 const GURL& url); |
| 27 |
| 28 // Gets the user data directory to use for |extension| located inside |
| 29 // |profile_path|. |
| 30 FilePath GetWebAppDataDirectory(const FilePath& profile_path, |
| 31 const Extension& extension); |
| 32 |
19 // Compute a deterministic name based on data in the shortcut_info. | 33 // Compute a deterministic name based on data in the shortcut_info. |
20 std::string GenerateApplicationNameFromInfo( | 34 std::string GenerateApplicationNameFromInfo( |
21 const ShellIntegration::ShortcutInfo& shortcut_info); | 35 const ShellIntegration::ShortcutInfo& shortcut_info); |
22 | 36 |
23 // Compute a deterministic name based on the URL. We use this pseudo name | 37 // Compute a deterministic name based on the URL. We use this pseudo name |
24 // as a key to store window location per application URLs in Browser and | 38 // as a key to store window location per application URLs in Browser and |
25 // as app id for BrowserWindow, shortcut and jump list. | 39 // as app id for BrowserWindow, shortcut and jump list. |
26 std::string GenerateApplicationNameFromURL(const GURL& url); | 40 std::string GenerateApplicationNameFromURL(const GURL& url); |
27 | 41 |
28 // Compute a deterministic name based on an extension/apps's id. | 42 // Compute a deterministic name based on an extension/apps's id. |
29 std::string GenerateApplicationNameFromExtensionId(const std::string& id); | 43 std::string GenerateApplicationNameFromExtensionId(const std::string& id); |
30 | 44 |
31 // Extracts the extension id from the app name. | 45 // Extracts the extension id from the app name. |
32 std::string GetExtensionIdFromApplicationName(const std::string& app_name); | 46 std::string GetExtensionIdFromApplicationName(const std::string& app_name); |
33 | 47 |
34 // Creates a shortcut for web application based on given shortcut data. | 48 // Creates a shortcut for web application based on given shortcut data. |
35 // |profile_path| is used as root directory for persisted data such as icon. | 49 // |profile_path| is used as root directory for persisted data such as icon. |
36 // Directory layout is similar to what Gears has, i.e. an web application's | 50 // Directory layout is similar to what Gears has, i.e. an web application's |
37 // file is stored under "#/host_name/scheme_port", where '#' is the | 51 // file is stored under "#/host_name/scheme_port", where '#' is the |
38 // |root_dir|. A crx based app uses a directory named _crx_<app id>. | 52 // |root_dir|. A crx based app uses a directory named _crx_<app id>. |
39 void CreateShortcut( | 53 void CreateShortcut( |
40 const FilePath& profile_path, | 54 const FilePath& profile_path, |
41 const ShellIntegration::ShortcutInfo& shortcut_info); | 55 const ShellIntegration::ShortcutInfo& shortcut_info); |
42 | 56 |
43 // Returns true if given url is a valid web app url. | 57 // Returns true if given url is a valid web app url. |
44 bool IsValidUrl(const GURL& url); | 58 bool IsValidUrl(const GURL& url); |
45 | 59 |
46 // Returns data dir for web apps for given profile path. | |
47 FilePath GetDataDir(const FilePath& profile_path); | |
48 | |
49 #if defined(TOOLKIT_VIEWS) | 60 #if defined(TOOLKIT_VIEWS) |
50 // Extracts icons info from web app data. Take only square shaped icons and | 61 // Extracts icons info from web app data. Take only square shaped icons and |
51 // sort them from smallest to largest. | 62 // sort them from smallest to largest. |
52 typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList; | 63 typedef std::vector<WebApplicationInfo::IconInfo> IconInfoList; |
53 void GetIconsInfo(const WebApplicationInfo& app_info, | 64 void GetIconsInfo(const WebApplicationInfo& app_info, |
54 IconInfoList* icons); | 65 IconInfoList* icons); |
55 #endif | 66 #endif |
56 | 67 |
57 #if defined(TOOLKIT_USES_GTK) | 68 #if defined(TOOLKIT_USES_GTK) |
58 // GTK+ windows that correspond to web apps need to have a deterministic (and | 69 // GTK+ windows that correspond to web apps need to have a deterministic (and |
59 // different) WMClass than normal chrome windows so the window manager groups | 70 // different) WMClass than normal chrome windows so the window manager groups |
60 // them as a separate application. | 71 // them as a separate application. |
61 std::string GetWMClassFromAppName(std::string app_name); | 72 std::string GetWMClassFromAppName(std::string app_name); |
62 #endif | 73 #endif |
63 | 74 |
64 namespace internals { | 75 namespace internals { |
65 | 76 |
66 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
67 bool CheckAndSaveIcon(const FilePath& icon_file, const SkBitmap& image); | 78 bool CheckAndSaveIcon(const FilePath& icon_file, const SkBitmap& image); |
68 #endif | 79 #endif |
69 | 80 |
70 FilePath GetWebAppDataDirectory(const FilePath& root_dir, | |
71 const ShellIntegration::ShortcutInfo& info); | |
72 | |
73 // Does the actual job of creating a shortcut (see CreateShortcut() above). | 81 // Does the actual job of creating a shortcut (see CreateShortcut() above). |
74 // This must be called on the file thread. | 82 // This must be called on the file thread. |
75 void CreateShortcutTask(const FilePath& web_app_path, | 83 void CreateShortcutTask(const FilePath& web_app_path, |
76 const FilePath& profile_path, | 84 const FilePath& profile_path, |
77 const ShellIntegration::ShortcutInfo& shortcut_info); | 85 const ShellIntegration::ShortcutInfo& shortcut_info); |
78 | 86 |
79 // Sanitizes |name| and returns a version of it that is safe to use as an | 87 // Sanitizes |name| and returns a version of it that is safe to use as an |
80 // on-disk file name . | 88 // on-disk file name . |
81 FilePath GetSanitizedFileName(const string16& name); | 89 FilePath GetSanitizedFileName(const string16& name); |
82 | 90 |
83 } // namespace internals | 91 } // namespace internals |
84 | 92 |
85 } // namespace web_app | 93 } // namespace web_app |
86 | 94 |
87 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ | 95 #endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_H_ |
OLD | NEW |