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