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 <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 "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 20 #include "chrome/installer/util/browser_distribution.h" | |
| 21 #include "chrome/installer/util/shell_util.h" | |
| 20 #include "chrome/installer/util/util_constants.h" | 22 #include "chrome/installer/util/util_constants.h" |
| 21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 22 #include "ui/gfx/icon_util.h" | 24 #include "ui/gfx/icon_util.h" |
| 23 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 24 #include "ui/gfx/image/image_family.h" | 26 #include "ui/gfx/image/image_family.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 const base::FilePath::CharType kIconChecksumFileExt[] = | 30 const base::FilePath::CharType kIconChecksumFileExt[] = |
| 29 FILE_PATH_LITERAL(".ico.md5"); | 31 FILE_PATH_LITERAL(".ico.md5"); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 void DeletePlatformShortcuts( | 278 void DeletePlatformShortcuts( |
| 277 const base::FilePath& web_app_path, | 279 const base::FilePath& web_app_path, |
| 278 const ShellIntegration::ShortcutInfo& shortcut_info) { | 280 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 279 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 281 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 280 | 282 |
| 281 // Get all possible locations for shortcuts. | 283 // Get all possible locations for shortcuts. |
| 282 ShellIntegration::ShortcutLocations all_shortcut_locations; | 284 ShellIntegration::ShortcutLocations all_shortcut_locations; |
| 283 all_shortcut_locations.in_applications_menu = true; | 285 all_shortcut_locations.in_applications_menu = true; |
| 284 all_shortcut_locations.in_quick_launch_bar = true; | 286 all_shortcut_locations.in_quick_launch_bar = true; |
| 285 all_shortcut_locations.on_desktop = true; | 287 all_shortcut_locations.on_desktop = true; |
| 286 std::vector<base::FilePath> shortcut_paths = GetShortcutPaths( | 288 std::vector<base::FilePath> shortcut_paths = |
| 287 all_shortcut_locations); | 289 GetShortcutPaths(all_shortcut_locations); |
| 288 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 290 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
| 289 shortcut_paths.push_back(web_app_path); | 291 shortcut_paths.push_back(web_app_path); |
| 290 | 292 |
| 291 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); | 293 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); |
| 292 i != shortcut_paths.end(); ++i) { | 294 i != shortcut_paths.end(); ++i) { |
| 293 std::vector<base::FilePath> shortcut_files = | 295 std::vector<base::FilePath> shortcut_files = |
| 294 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, | 296 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, |
| 295 shortcut_info.title); | 297 shortcut_info.title); |
| 296 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); | 298 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); |
| 297 j != shortcut_files.end(); ++j) { | 299 j != shortcut_files.end(); ++j) { |
| 298 // Any shortcut could have been pinned, either by chrome or the user, so | 300 // Any shortcut could have been pinned, either by chrome or the user, so |
| 299 // they are all unpinned. | 301 // they are all unpinned. |
| 300 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 302 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
| 301 file_util::Delete(*j, false); | 303 file_util::Delete(*j, false); |
| 302 } | 304 } |
| 303 } | 305 } |
| 304 } | 306 } |
| 305 | 307 |
| 306 std::vector<base::FilePath> GetShortcutPaths( | 308 std::vector<base::FilePath> GetShortcutPaths( |
| 307 const ShellIntegration::ShortcutLocations& creation_locations) { | 309 const ShellIntegration::ShortcutLocations& creation_locations) { |
| 308 // Shortcut paths under which to create shortcuts. | 310 // Shortcut paths under which to create shortcuts. |
| 309 std::vector<base::FilePath> shortcut_paths; | 311 std::vector<base::FilePath> shortcut_paths; |
| 310 // Locations to add to shortcut_paths. | 312 // Locations to add to shortcut_paths. |
| 311 struct { | 313 struct { |
| 312 bool use_this_location; | 314 bool use_this_location; |
| 313 int location_id; | 315 ShellUtil::ShortcutLocation location_id; |
| 314 const wchar_t* subdir; | 316 const wchar_t* subdir; |
| 315 } locations[] = { | 317 } locations[] = { |
| 316 { | 318 { |
| 317 creation_locations.on_desktop, | 319 creation_locations.on_desktop, |
| 318 base::DIR_USER_DESKTOP, | 320 ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
| 319 NULL | 321 NULL |
| 320 }, { | 322 }, { |
| 321 creation_locations.in_applications_menu, | 323 creation_locations.in_applications_menu, |
| 322 base::DIR_START_MENU, | 324 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
|
gab
2013/04/29 21:34:44
This will already return the StartMenu/Google Chro
calamity
2013/04/30 08:11:28
Done.
| |
| 323 creation_locations.applications_menu_subdir.empty() ? NULL : | 325 creation_locations.applications_menu_subdir.empty() ? NULL : |
| 324 creation_locations.applications_menu_subdir.c_str() | 326 creation_locations.applications_menu_subdir.c_str() |
| 325 }, { | 327 }, { |
| 326 creation_locations.in_quick_launch_bar, | 328 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to |
| 327 // For Win7, in_quick_launch_bar means pinning to taskbar. Use | 329 // taskbar. This needs to be handled by callers. |
| 328 // base::PATH_START as a flag for this case. | 330 creation_locations.in_quick_launch_bar && |
| 329 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 331 base::win::GetVersion() < base::win::VERSION_WIN7, |
| 330 base::PATH_START : base::DIR_APP_DATA, | 332 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
| 331 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 333 NULL |
| 332 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | |
| 333 } | 334 } |
| 334 }; | 335 }; |
| 336 | |
| 337 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 335 // Populate shortcut_paths. | 338 // Populate shortcut_paths. |
| 336 for (int i = 0; i < arraysize(locations); ++i) { | 339 for (int i = 0; i < arraysize(locations); ++i) { |
| 337 if (locations[i].use_this_location) { | 340 if (locations[i].use_this_location) { |
| 338 base::FilePath path; | 341 base::FilePath path; |
| 339 | 342 |
| 340 // Skip the Win7 case. | 343 if (!ShellUtil::GetShortcutPath(locations[i].location_id, |
| 341 if (locations[i].location_id == base::PATH_START) | 344 dist, |
| 342 continue; | 345 ShellUtil::CURRENT_USER, |
| 343 | 346 &path)) { |
| 344 if (!PathService::Get(locations[i].location_id, &path)) { | 347 NOTREACHED(); |
| 345 continue; | 348 continue; |
| 346 } | 349 } |
| 347 | 350 |
| 348 if (locations[i].subdir != NULL) | 351 if (locations[i].subdir != NULL) |
| 349 path = path.Append(locations[i].subdir); | 352 path = path.Append(locations[i].subdir); |
| 350 shortcut_paths.push_back(path); | 353 shortcut_paths.push_back(path); |
| 351 } | 354 } |
| 352 } | 355 } |
| 353 return shortcut_paths; | 356 return shortcut_paths; |
| 354 } | 357 } |
| 355 | 358 |
| 356 } // namespace internals | 359 } // namespace internals |
| 357 | 360 |
| 358 } // namespace web_app | 361 } // namespace web_app |
| OLD | NEW |