| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/md5.h" | 12 #include "base/md5.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/win/shortcut.h" | 16 #include "base/win/shortcut.h" |
| 17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "ui/gfx/icon_util.h" | 21 #include "ui/gfx/icon_util.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const FilePath::CharType kIconChecksumFileExt[] = FILE_PATH_LITERAL(".ico.md5"); | 25 const FilePath::CharType kIconChecksumFileExt[] = FILE_PATH_LITERAL(".ico.md5"); |
| 25 | 26 |
| 26 // Calculates image checksum using MD5. | 27 // Calculates image checksum using MD5. |
| 27 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { | 28 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { |
| 28 DCHECK(digest); | 29 DCHECK(digest); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 218 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
| 218 | 219 |
| 219 // Creates an ico file to use with shortcut. | 220 // Creates an ico file to use with shortcut. |
| 220 FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( | 221 FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( |
| 221 FILE_PATH_LITERAL(".ico")); | 222 FILE_PATH_LITERAL(".ico")); |
| 222 if (!web_app::internals::CheckAndSaveIcon(icon_file, | 223 if (!web_app::internals::CheckAndSaveIcon(icon_file, |
| 223 *shortcut_info.favicon.ToSkBitmap())) { | 224 *shortcut_info.favicon.ToSkBitmap())) { |
| 224 return false; | 225 return false; |
| 225 } | 226 } |
| 226 | 227 |
| 227 FilePath chrome_exe; | 228 FilePath app_host_exe(chrome_launcher_support::GetAnyAppHostPath()); |
| 228 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 229 if (app_host_exe.empty()) |
| 229 return false; | 230 return false; |
| 230 | 231 |
| 231 // Working directory. | 232 // Working directory. |
| 232 FilePath chrome_folder(chrome_exe.DirName()); | 233 FilePath working_dir(app_host_exe.DirName()); |
| 233 | 234 |
| 234 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 235 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
| 235 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, | 236 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
| 236 shortcut_info.extension_id, shortcut_info.profile_path); | 237 shortcut_info.extension_id, shortcut_info.profile_path); |
| 237 | 238 |
| 238 // 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 |
| 239 // properly quoted for a Windows command line. The method on | 240 // properly quoted for a Windows command line. The method on |
| 240 // CommandLine should probably be renamed to better reflect that | 241 // CommandLine should probably be renamed to better reflect that |
| 241 // fact. | 242 // fact. |
| 242 string16 wide_switches(cmd_line.GetCommandLineString()); | 243 string16 wide_switches(cmd_line.GetCommandLineString()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 261 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); | 262 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); |
| 262 if (unique_number == -1) { | 263 if (unique_number == -1) { |
| 263 success = false; | 264 success = false; |
| 264 continue; | 265 continue; |
| 265 } else if (unique_number > 0) { | 266 } else if (unique_number > 0) { |
| 266 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( | 267 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( |
| 267 StringPrintf(" (%d)", unique_number)); | 268 StringPrintf(" (%d)", unique_number)); |
| 268 } | 269 } |
| 269 | 270 |
| 270 base::win::ShortcutProperties shortcut_properties; | 271 base::win::ShortcutProperties shortcut_properties; |
| 271 shortcut_properties.set_target(chrome_exe); | 272 shortcut_properties.set_target(app_host_exe); |
| 272 shortcut_properties.set_working_dir(chrome_folder); | 273 shortcut_properties.set_working_dir(working_dir); |
| 273 shortcut_properties.set_arguments(wide_switches); | 274 shortcut_properties.set_arguments(wide_switches); |
| 274 shortcut_properties.set_description(description); | 275 shortcut_properties.set_description(description); |
| 275 shortcut_properties.set_icon(icon_file, 0); | 276 shortcut_properties.set_icon(icon_file, 0); |
| 276 shortcut_properties.set_app_id(app_id); | 277 shortcut_properties.set_app_id(app_id); |
| 277 shortcut_properties.set_dual_mode(false); | 278 shortcut_properties.set_dual_mode(false); |
| 278 success = base::win::CreateOrUpdateShortcutLink( | 279 success = base::win::CreateOrUpdateShortcutLink( |
| 279 shortcut_file, shortcut_properties, | 280 shortcut_file, shortcut_properties, |
| 280 base::win::SHORTCUT_CREATE_ALWAYS) && success; | 281 base::win::SHORTCUT_CREATE_ALWAYS) && success; |
| 281 | 282 |
| 282 // 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. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // they are all unpinned. | 340 // they are all unpinned. |
| 340 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 341 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
| 341 file_util::Delete(*j, false); | 342 file_util::Delete(*j, false); |
| 342 } | 343 } |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 | 346 |
| 346 } // namespace internals | 347 } // namespace internals |
| 347 | 348 |
| 348 } // namespace web_app | 349 } // namespace web_app |
| OLD | NEW |