Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: chrome/browser/web_applications/web_app_win.cc

Issue 13864015: Move app launcher and chrome apps shortcut strings into the installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_app_id_fix
Patch Set: fix nits Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_win.h" 5 #include "chrome/browser/web_applications/web_app_win.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/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/shortcut.h" 18 #include "base/win/shortcut.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "chrome/browser/web_applications/web_app.h" 20 #include "chrome/browser/web_applications/web_app.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/installer/launcher_support/chrome_launcher_support.h" 22 #include "chrome/installer/util/browser_distribution.h"
23 #include "chrome/installer/util/shell_util.h"
23 #include "chrome/installer/util/util_constants.h" 24 #include "chrome/installer/util/util_constants.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "ui/gfx/icon_util.h" 26 #include "ui/gfx/icon_util.h"
26 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_family.h" 28 #include "ui/gfx/image/image_family.h"
28 29
29 namespace { 30 namespace {
30 31
31 const base::FilePath::CharType kIconChecksumFileExt[] = 32 const base::FilePath::CharType kIconChecksumFileExt[] =
32 FILE_PATH_LITERAL(".ico.md5"); 33 FILE_PATH_LITERAL(".ico.md5");
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 void GetShortcutLocationsAndDeleteShortcuts( 274 void GetShortcutLocationsAndDeleteShortcuts(
274 const base::FilePath& web_app_path, 275 const base::FilePath& web_app_path,
275 const base::FilePath& profile_path, 276 const base::FilePath& profile_path,
276 const string16& title, 277 const string16& title,
277 bool* was_pinned_to_taskbar, 278 bool* was_pinned_to_taskbar,
278 std::vector<base::FilePath>* shortcut_paths) { 279 std::vector<base::FilePath>* shortcut_paths) {
279 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 280 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
280 281
281 // Get all possible locations for shortcuts. 282 // Get all possible locations for shortcuts.
282 ShellIntegration::ShortcutLocations all_shortcut_locations; 283 ShellIntegration::ShortcutLocations all_shortcut_locations;
283 all_shortcut_locations.in_applications_menu = true;
284 all_shortcut_locations.in_quick_launch_bar = true; 284 all_shortcut_locations.in_quick_launch_bar = true;
285 all_shortcut_locations.on_desktop = true; 285 all_shortcut_locations.on_desktop = true;
286 // Delete shortcuts from the Chrome Apps subdirectory. 286 // Delete shortcuts from the Chrome Apps subdirectory.
287 // This matches the subdir name set by CreateApplicationShortcutView::Accept 287 // This matches the subdir name set by CreateApplicationShortcutView::Accept
288 // for Chrome apps (not URL apps, but this function does not apply for them). 288 // for Chrome apps (not URL apps, but this function does not apply for them).
289 all_shortcut_locations.applications_menu_subdir = 289 all_shortcut_locations.applications_menu_location =
290 web_app::GetAppShortcutsSubdirName(); 290 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
291 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths( 291 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths(
292 all_shortcut_locations); 292 all_shortcut_locations);
293 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 293 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
294 !web_app_path.empty()) { 294 !web_app_path.empty()) {
295 all_paths.push_back(web_app_path); 295 all_paths.push_back(web_app_path);
296 } 296 }
297 297
298 if (was_pinned_to_taskbar) { 298 if (was_pinned_to_taskbar) {
299 // Determine if there is a link to this app in the TaskBar pin directory. 299 // Determine if there is a link to this app in the TaskBar pin directory.
300 base::FilePath taskbar_pin_path; 300 base::FilePath taskbar_pin_path;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 void DeletePlatformShortcuts( 452 void DeletePlatformShortcuts(
453 const base::FilePath& web_app_path, 453 const base::FilePath& web_app_path,
454 const ShellIntegration::ShortcutInfo& shortcut_info) { 454 const ShellIntegration::ShortcutInfo& shortcut_info) {
455 GetShortcutLocationsAndDeleteShortcuts( 455 GetShortcutLocationsAndDeleteShortcuts(
456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL,
457 NULL); 457 NULL);
458 458
459 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 459 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
460 base::FilePath chrome_apps_dir; 460 base::FilePath chrome_apps_dir;
461 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { 461 if (ShellUtil::GetShortcutPath(
462 chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName()); 462 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
463 BrowserDistribution::GetDistribution(),
464 ShellUtil::CURRENT_USER,
465 &chrome_apps_dir)) {
463 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) 466 if (file_util::IsDirectoryEmpty(chrome_apps_dir))
464 base::DeleteFile(chrome_apps_dir, false); 467 base::DeleteFile(chrome_apps_dir, false);
465 } 468 }
466 } 469 }
467 470
468 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 471 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
469 GetShortcutLocationsAndDeleteShortcuts(base::FilePath(), profile_path, L"", 472 GetShortcutLocationsAndDeleteShortcuts(base::FilePath(), profile_path, L"",
470 NULL, NULL); 473 NULL, NULL);
471 474
472 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 475 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
473 base::FilePath chrome_apps_dir; 476 base::FilePath chrome_apps_dir;
474 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { 477 if (ShellUtil::GetShortcutPath(
475 chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName()); 478 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
479 BrowserDistribution::GetDistribution(),
480 ShellUtil::CURRENT_USER,
481 &chrome_apps_dir)) {
476 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) 482 if (file_util::IsDirectoryEmpty(chrome_apps_dir))
477 base::DeleteFile(chrome_apps_dir, false); 483 base::DeleteFile(chrome_apps_dir, false);
478 } 484 }
479 } 485 }
480 486
481 std::vector<base::FilePath> GetShortcutPaths( 487 std::vector<base::FilePath> GetShortcutPaths(
482 const ShellIntegration::ShortcutLocations& creation_locations) { 488 const ShellIntegration::ShortcutLocations& creation_locations) {
483 // Shortcut paths under which to create shortcuts. 489 // Shortcut paths under which to create shortcuts.
484 std::vector<base::FilePath> shortcut_paths; 490 std::vector<base::FilePath> shortcut_paths;
485 // Locations to add to shortcut_paths. 491 // Locations to add to shortcut_paths.
486 struct { 492 struct {
487 bool use_this_location; 493 bool use_this_location;
488 int location_id; 494 ShellUtil::ShortcutLocation location_id;
489 const wchar_t* subdir;
490 } locations[] = { 495 } locations[] = {
491 { 496 {
492 creation_locations.on_desktop, 497 creation_locations.on_desktop,
493 base::DIR_USER_DESKTOP, 498 ShellUtil::SHORTCUT_LOCATION_DESKTOP
494 NULL
495 }, { 499 }, {
496 creation_locations.in_applications_menu, 500 creation_locations.applications_menu_location ==
497 base::DIR_START_MENU, 501 ShellIntegration::APP_MENU_LOCATION_ROOT,
498 creation_locations.applications_menu_subdir.empty() ? NULL : 502 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT
499 creation_locations.applications_menu_subdir.c_str()
500 }, { 503 }, {
501 creation_locations.in_quick_launch_bar, 504 creation_locations.applications_menu_location ==
502 // For Win7, in_quick_launch_bar means pinning to taskbar. Use 505 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROME,
503 // base::PATH_START as a flag for this case. 506 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
504 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? 507 }, {
505 base::PATH_START : base::DIR_APP_DATA, 508 creation_locations.applications_menu_location ==
506 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? 509 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
507 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" 510 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
511 }, {
512 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to
513 // taskbar. This needs to be handled by callers.
514 creation_locations.in_quick_launch_bar &&
515 base::win::GetVersion() < base::win::VERSION_WIN7,
516 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
508 } 517 }
509 }; 518 };
519
520 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
510 // Populate shortcut_paths. 521 // Populate shortcut_paths.
511 for (int i = 0; i < arraysize(locations); ++i) { 522 for (int i = 0; i < arraysize(locations); ++i) {
512 if (locations[i].use_this_location) { 523 if (locations[i].use_this_location) {
513 base::FilePath path; 524 base::FilePath path;
514 525 if (!ShellUtil::GetShortcutPath(locations[i].location_id,
515 // Skip the Win7 case. 526 dist,
516 if (locations[i].location_id == base::PATH_START) 527 ShellUtil::CURRENT_USER,
517 continue; 528 &path)) {
518 529 NOTREACHED();
519 if (!PathService::Get(locations[i].location_id, &path)) {
520 continue; 530 continue;
521 } 531 }
522
523 if (locations[i].subdir != NULL)
524 path = path.Append(locations[i].subdir);
525 shortcut_paths.push_back(path); 532 shortcut_paths.push_back(path);
526 } 533 }
527 } 534 }
528 return shortcut_paths; 535 return shortcut_paths;
529 } 536 }
530 537
531 } // namespace internals 538 } // namespace internals
532 539
533 } // namespace web_app 540 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698