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 <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 if (!web_app::internals::CheckAndSaveIcon(icon_file, | 222 if (!web_app::internals::CheckAndSaveIcon(icon_file, |
223 *shortcut_info.favicon.ToSkBitmap())) { | 223 *shortcut_info.favicon.ToSkBitmap())) { |
224 return false; | 224 return false; |
225 } | 225 } |
226 | 226 |
227 FilePath chrome_exe; | 227 FilePath chrome_exe; |
228 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 228 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
229 return false; | 229 return false; |
230 | 230 |
231 // Working directory. | 231 // Working directory. |
232 FilePath chrome_folder = chrome_exe.DirName(); | 232 FilePath chrome_folder(chrome_exe.DirName()); |
233 | 233 |
234 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 234 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
235 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, | 235 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
236 shortcut_info.extension_id, shortcut_info.is_platform_app, | 236 shortcut_info.extension_id, shortcut_info.is_platform_app, |
237 shortcut_info.profile_path); | 237 shortcut_info.profile_path); |
238 | 238 |
239 // TODO(evan): we rely on the fact that command_line_string() is | 239 // TODO(evan): we rely on the fact that command_line_string() is |
240 // properly quoted for a Windows command line. The method on | 240 // properly quoted for a Windows command line. The method on |
241 // CommandLine should probably be renamed to better reflect that | 241 // CommandLine should probably be renamed to better reflect that |
242 // fact. | 242 // fact. |
243 string16 wide_switches(cmd_line.GetCommandLineString()); | 243 string16 wide_switches(cmd_line.GetCommandLineString()); |
244 | 244 |
245 // Sanitize description | 245 // Sanitize description |
246 string16 description = shortcut_info.description; | 246 string16 description = shortcut_info.description; |
247 if (description.length() >= MAX_PATH) | 247 if (description.length() >= MAX_PATH) |
248 description.resize(MAX_PATH - 1); | 248 description.resize(MAX_PATH - 1); |
249 | 249 |
250 // Generates app id from web app url and profile path. | 250 // Generates app id from web app url and profile path. |
251 std::string app_name = | 251 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); |
252 web_app::GenerateApplicationNameFromInfo(shortcut_info); | 252 string16 app_id(ShellIntegration::GetAppModelIdForProfile( |
253 string16 app_id = ShellIntegration::GetAppModelIdForProfile( | 253 UTF8ToUTF16(app_name), shortcut_info.profile_path)); |
254 UTF8ToUTF16(app_name), shortcut_info.profile_path); | |
255 | 254 |
256 FilePath shortcut_to_pin; | 255 FilePath shortcut_to_pin; |
257 bool success = true; | 256 bool success = true; |
258 for (size_t i = 0; i < shortcut_paths.size(); ++i) { | 257 for (size_t i = 0; i < shortcut_paths.size(); ++i) { |
259 FilePath shortcut_file = shortcut_paths[i].Append(file_name). | 258 FilePath shortcut_file = shortcut_paths[i].Append(file_name). |
260 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); | 259 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); |
261 | 260 |
262 int unique_number = | 261 int unique_number = |
263 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); | 262 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); |
264 if (unique_number == -1) { | 263 if (unique_number == -1) { |
265 success = false; | 264 success = false; |
266 continue; | 265 continue; |
267 } else if (unique_number > 0) { | 266 } else if (unique_number > 0) { |
268 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( | 267 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( |
269 StringPrintf(" (%d)", unique_number)); | 268 StringPrintf(" (%d)", unique_number)); |
270 } | 269 } |
271 | 270 |
| 271 file_util::ShortcutProperties shortcut_properties; |
| 272 shortcut_properties.set_target(chrome_exe.value()); |
| 273 shortcut_properties.set_working_dir(chrome_folder.value()); |
| 274 shortcut_properties.set_arguments(wide_switches); |
| 275 shortcut_properties.set_description(description); |
| 276 shortcut_properties.set_icon(icon_file.value(), 0); |
| 277 shortcut_properties.set_app_id(app_id); |
| 278 shortcut_properties.set_dual_mode(false); |
272 success = file_util::CreateOrUpdateShortcutLink( | 279 success = file_util::CreateOrUpdateShortcutLink( |
273 chrome_exe.value().c_str(), | 280 shortcut_file.value(), shortcut_properties, |
274 shortcut_file.value().c_str(), | |
275 chrome_folder.value().c_str(), | |
276 wide_switches.c_str(), | |
277 description.c_str(), | |
278 icon_file.value().c_str(), | |
279 0, | |
280 app_id.c_str(), | |
281 file_util::SHORTCUT_CREATE_ALWAYS) && success; | 281 file_util::SHORTCUT_CREATE_ALWAYS) && success; |
282 | 282 |
283 // Any shortcut would work for the pinning. We use the first one. | 283 // Any shortcut would work for the pinning. We use the first one. |
284 if (success && pin_to_taskbar && shortcut_to_pin.empty()) | 284 if (success && pin_to_taskbar && shortcut_to_pin.empty()) |
285 shortcut_to_pin = shortcut_file; | 285 shortcut_to_pin = shortcut_file; |
286 } | 286 } |
287 | 287 |
288 if (success && pin_to_taskbar) { | 288 if (success && pin_to_taskbar) { |
289 if (!shortcut_to_pin.empty()) { | 289 if (!shortcut_to_pin.empty()) { |
290 success &= file_util::TaskbarPinShortcutLink( | 290 success &= file_util::TaskbarPinShortcutLink( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // they are all unpinned. | 323 // they are all unpinned. |
324 file_util::TaskbarUnpinShortcutLink(j->value().c_str()); | 324 file_util::TaskbarUnpinShortcutLink(j->value().c_str()); |
325 file_util::Delete(*j, false); | 325 file_util::Delete(*j, false); |
326 } | 326 } |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 } // namespace internals | 330 } // namespace internals |
331 | 331 |
332 } // namespace web_app | 332 } // namespace web_app |
OLD | NEW |