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 #include "chrome/browser/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace { | 21 namespace { |
22 | 22 |
23 #if defined(TOOLKIT_VIEWS) | 23 #if defined(TOOLKIT_VIEWS) |
24 // Predicator for sorting images from largest to smallest. | 24 // Predicator for sorting images from largest to smallest. |
25 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, | 25 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, |
26 const WebApplicationInfo::IconInfo& right) { | 26 const WebApplicationInfo::IconInfo& right) { |
27 return left.width < right.width; | 27 return left.width < right.width; |
28 } | 28 } |
29 #endif | 29 #endif |
30 | 30 |
| 31 void DeleteShortcutsOnFileThread( |
| 32 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 34 |
| 35 FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| 36 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); |
| 37 return web_app::internals::DeletePlatformShortcuts( |
| 38 shortcut_data_dir, shortcut_info); |
| 39 } |
| 40 |
31 } // namespace | 41 } // namespace |
32 | 42 |
33 namespace web_app { | 43 namespace web_app { |
34 | 44 |
35 // The following string is used to build the directory name for | 45 // The following string is used to build the directory name for |
36 // shortcuts to chrome applications (the kind which are installed | 46 // shortcuts to chrome applications (the kind which are installed |
37 // from a CRX). Application shortcuts to URLs use the {host}_{path} | 47 // from a CRX). Application shortcuts to URLs use the {host}_{path} |
38 // for the name of this directory. Hosts can't include an underscore. | 48 // for the name of this directory. Hosts can't include an underscore. |
39 // By starting this string with an underscore, we ensure that there | 49 // By starting this string with an underscore, we ensure that there |
40 // are no naming conflicts. | 50 // are no naming conflicts. |
41 static const char* kCrxAppPrefix = "_crx_"; | 51 static const char* kCrxAppPrefix = "_crx_"; |
42 | 52 |
43 namespace internals { | 53 namespace internals { |
44 | 54 |
45 FilePath GetSanitizedFileName(const string16& name) { | 55 FilePath GetSanitizedFileName(const string16& name) { |
46 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
47 string16 file_name = name; | 57 string16 file_name = name; |
48 #else | 58 #else |
49 std::string file_name = UTF16ToUTF8(name); | 59 std::string file_name = UTF16ToUTF8(name); |
50 #endif | 60 #endif |
51 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); | 61 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); |
52 return FilePath(file_name); | 62 return FilePath(file_name); |
53 } | 63 } |
54 | 64 |
55 } // namespace internals | 65 } // namespace internals |
56 | 66 |
57 FilePath GetWebAppDataDirectory(const FilePath& profile_path, | 67 FilePath GetWebAppDataDirectory(const FilePath& profile_path, |
58 const std::string& extension_id, | 68 const std::string& extension_id, |
59 const GURL& url) { | 69 const GURL& url) { |
| 70 DCHECK(!profile_path.empty()); |
60 FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname)); | 71 FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname)); |
61 | 72 |
62 if (!extension_id.empty()) { | 73 if (!extension_id.empty()) { |
63 return app_data_dir.AppendASCII( | 74 return app_data_dir.AppendASCII( |
64 GenerateApplicationNameFromExtensionId(extension_id)); | 75 GenerateApplicationNameFromExtensionId(extension_id)); |
65 } | 76 } |
66 | 77 |
67 std::string host(url.host()); | 78 std::string host(url.host()); |
68 std::string scheme(url.has_scheme() ? url.scheme() : "http"); | 79 std::string scheme(url.has_scheme() ? url.scheme() : "http"); |
69 std::string port(url.has_port() ? url.port() : "80"); | 80 std::string port(url.has_port() ? url.port() : "80"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return t; | 122 return t; |
112 } | 123 } |
113 | 124 |
114 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { | 125 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { |
115 std::string prefix(kCrxAppPrefix); | 126 std::string prefix(kCrxAppPrefix); |
116 if (app_name.substr(0, prefix.length()) != prefix) | 127 if (app_name.substr(0, prefix.length()) != prefix) |
117 return std::string(); | 128 return std::string(); |
118 return app_name.substr(prefix.length()); | 129 return app_name.substr(prefix.length()); |
119 } | 130 } |
120 | 131 |
121 void CreateShortcut( | 132 void CreateShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) { |
122 const FilePath& profile_path, | |
123 const ShellIntegration::ShortcutInfo& shortcut_info) { | |
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
125 | 134 |
126 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
127 BrowserThread::FILE, | 136 BrowserThread::FILE, |
128 FROM_HERE, | 137 FROM_HERE, |
129 base::Bind(base::IgnoreResult(&CreateShortcutOnFileThread), | 138 base::Bind(base::IgnoreResult(&CreateShortcutsOnFileThread), |
130 profile_path, shortcut_info)); | 139 shortcut_info)); |
131 } | 140 } |
132 | 141 |
133 void DeleteAllShortcuts(const FilePath& profile_path, | 142 void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) { |
134 const std::string& extension_id) { | |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
136 | 144 |
137 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
138 BrowserThread::FILE, | 146 BrowserThread::FILE, |
139 FROM_HERE, | 147 FROM_HERE, |
140 base::Bind(&internals::DeletePlatformShortcuts, profile_path, | 148 base::Bind(&DeleteShortcutsOnFileThread, shortcut_info)); |
141 extension_id)); | |
142 } | 149 } |
143 | 150 |
144 bool CreateShortcutOnFileThread( | 151 bool CreateShortcutsOnFileThread( |
145 const FilePath& profile_path, | |
146 const ShellIntegration::ShortcutInfo& shortcut_info) { | 152 const ShellIntegration::ShortcutInfo& shortcut_info) { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
148 | 154 |
149 FilePath shortcut_data_dir = GetWebAppDataDirectory( | 155 FilePath shortcut_data_dir = GetWebAppDataDirectory( |
150 profile_path, shortcut_info.extension_id, shortcut_info.url); | 156 shortcut_info.profile_path, shortcut_info.extension_id, |
151 return internals::CreatePlatformShortcut( | 157 shortcut_info.url); |
152 shortcut_data_dir, profile_path, shortcut_info); | 158 return internals::CreatePlatformShortcuts(shortcut_data_dir, shortcut_info); |
153 } | 159 } |
154 | 160 |
155 bool IsValidUrl(const GURL& url) { | 161 bool IsValidUrl(const GURL& url) { |
156 static const char* const kValidUrlSchemes[] = { | 162 static const char* const kValidUrlSchemes[] = { |
157 chrome::kFileScheme, | 163 chrome::kFileScheme, |
158 chrome::kFileSystemScheme, | 164 chrome::kFileSystemScheme, |
159 chrome::kFtpScheme, | 165 chrome::kFtpScheme, |
160 chrome::kHttpScheme, | 166 chrome::kHttpScheme, |
161 chrome::kHttpsScheme, | 167 chrome::kHttpsScheme, |
162 chrome::kExtensionScheme, | 168 chrome::kExtensionScheme, |
(...skipping 26 matching lines...) Expand all Loading... |
189 | 195 |
190 #if defined(TOOLKIT_GTK) | 196 #if defined(TOOLKIT_GTK) |
191 std::string GetWMClassFromAppName(std::string app_name) { | 197 std::string GetWMClassFromAppName(std::string app_name) { |
192 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 198 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
193 TrimString(app_name, "_", &app_name); | 199 TrimString(app_name, "_", &app_name); |
194 return app_name; | 200 return app_name; |
195 } | 201 } |
196 #endif | 202 #endif |
197 | 203 |
198 } // namespace web_app | 204 } // namespace web_app |
OLD | NEW |