Chromium Code Reviews| 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)) { | |
|
sail
2012/04/12 15:06:29
is this really necessary? on the Mac the data dire
benwells
2012/04/13 01:48:48
Yes, some files are put in this folder at shortcut
sail
2012/04/13 01:59:14
ok
| |
| 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::kFtpScheme, | 153 chrome::kFtpScheme, |
| 139 chrome::kHttpScheme, | 154 chrome::kHttpScheme, |
| 140 chrome::kHttpsScheme, | 155 chrome::kHttpsScheme, |
| 141 chrome::kExtensionScheme, | 156 chrome::kExtensionScheme, |
| 142 }; | 157 }; |
| 143 | 158 |
| 144 for (size_t i = 0; i < arraysize(kValidUrlSchemes); ++i) { | 159 for (size_t i = 0; i < arraysize(kValidUrlSchemes); ++i) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 168 | 183 |
| 169 #if defined(TOOLKIT_USES_GTK) | 184 #if defined(TOOLKIT_USES_GTK) |
| 170 std::string GetWMClassFromAppName(std::string app_name) { | 185 std::string GetWMClassFromAppName(std::string app_name) { |
| 171 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); | 186 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
| 172 TrimString(app_name, "_", &app_name); | 187 TrimString(app_name, "_", &app_name); |
| 173 return app_name; | 188 return app_name; |
| 174 } | 189 } |
| 175 #endif | 190 #endif |
| 176 | 191 |
| 177 } // namespace web_app | 192 } // namespace web_app |
| OLD | NEW |