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/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 | 18 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 112 } |
112 | 113 |
113 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { | 114 std::string GetExtensionIdFromApplicationName(const std::string& app_name) { |
114 std::string prefix(kCrxAppPrefix); | 115 std::string prefix(kCrxAppPrefix); |
115 if (app_name.substr(0, prefix.length()) != prefix) | 116 if (app_name.substr(0, prefix.length()) != prefix) |
116 return std::string(); | 117 return std::string(); |
117 return app_name.substr(prefix.length()); | 118 return app_name.substr(prefix.length()); |
118 } | 119 } |
119 | 120 |
120 void CreateShortcut( | 121 void CreateShortcut( |
121 const FilePath& data_dir, | 122 const FilePath& profile_path, |
122 const ShellIntegration::ShortcutInfo& shortcut_info) { | 123 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 |
123 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
124 BrowserThread::FILE, | 127 BrowserThread::FILE, |
125 FROM_HERE, | 128 FROM_HERE, |
126 base::Bind(&internals::CreateShortcutTask, | 129 base::Bind(base::IgnoreResult(&CreateShortcutOnFileThread), |
127 GetWebAppDataDirectory( | 130 profile_path, |
128 data_dir, | |
129 shortcut_info.extension_id, | |
130 shortcut_info.url), | |
131 data_dir, | |
132 shortcut_info)); | 131 shortcut_info)); |
133 } | 132 } |
134 | 133 |
| 134 bool CreateShortcutOnFileThread( |
| 135 const FilePath& profile_path, |
| 136 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 138 |
| 139 FilePath shortcut_data_dir = GetWebAppDataDirectory( |
| 140 profile_path, shortcut_info.extension_id, shortcut_info.url); |
| 141 // Ensure shortcut_data_dir exists |
| 142 if (!file_util::PathExists(shortcut_data_dir) && |
| 143 !file_util::CreateDirectory(shortcut_data_dir)) { |
| 144 return false; |
| 145 } |
| 146 return internals::CreatePlatformShortcut( |
| 147 shortcut_data_dir, profile_path, shortcut_info); |
| 148 } |
| 149 |
135 bool IsValidUrl(const GURL& url) { | 150 bool IsValidUrl(const GURL& url) { |
136 static const char* const kValidUrlSchemes[] = { | 151 static const char* const kValidUrlSchemes[] = { |
137 chrome::kFileScheme, | 152 chrome::kFileScheme, |
138 chrome::kFileSystemScheme, | 153 chrome::kFileSystemScheme, |
139 chrome::kFtpScheme, | 154 chrome::kFtpScheme, |
140 chrome::kHttpScheme, | 155 chrome::kHttpScheme, |
141 chrome::kHttpsScheme, | 156 chrome::kHttpsScheme, |
142 chrome::kExtensionScheme, | 157 chrome::kExtensionScheme, |
143 }; | 158 }; |
144 | 159 |
(...skipping 24 matching lines...) Expand all Loading... |
169 | 184 |
170 #if defined(TOOLKIT_GTK) | 185 #if defined(TOOLKIT_GTK) |
171 std::string GetWMClassFromAppName(std::string app_name) { | 186 std::string GetWMClassFromAppName(std::string app_name) { |
172 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 187 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
173 TrimString(app_name, "_", &app_name); | 188 TrimString(app_name, "_", &app_name); |
174 return app_name; | 189 return app_name; |
175 } | 190 } |
176 #endif | 191 #endif |
177 | 192 |
178 } // namespace web_app | 193 } // namespace web_app |
OLD | NEW |