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

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: rework Created 7 years, 3 months 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.in_applications_menu_chrome_apps_subdir = true;
290 web_app::GetAppShortcutsSubdirName();
291 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths( 290 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths(
292 all_shortcut_locations); 291 all_shortcut_locations);
293 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 292 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
294 !web_app_path.empty()) { 293 !web_app_path.empty()) {
295 all_paths.push_back(web_app_path); 294 all_paths.push_back(web_app_path);
296 } 295 }
297 296
298 if (was_pinned_to_taskbar) { 297 if (was_pinned_to_taskbar) {
299 // Determine if there is a link to this app in the TaskBar pin directory. 298 // Determine if there is a link to this app in the TaskBar pin directory.
300 base::FilePath taskbar_pin_path; 299 base::FilePath taskbar_pin_path;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 450
452 void DeletePlatformShortcuts( 451 void DeletePlatformShortcuts(
453 const base::FilePath& web_app_path, 452 const base::FilePath& web_app_path,
454 const ShellIntegration::ShortcutInfo& shortcut_info) { 453 const ShellIntegration::ShortcutInfo& shortcut_info) {
455 GetShortcutLocationsAndDeleteShortcuts( 454 GetShortcutLocationsAndDeleteShortcuts(
456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 455 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL,
457 NULL); 456 NULL);
458 457
459 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 458 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
460 base::FilePath chrome_apps_dir; 459 base::FilePath chrome_apps_dir;
461 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { 460 if (ShellUtil::GetShortcutPath(
462 chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName()); 461 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
gab 2013/08/28 19:52:27 nit: indent 2 more spaces
calamity 2013/10/02 01:08:05 Done.
462 BrowserDistribution::GetDistribution(),
463 ShellUtil::CURRENT_USER,
464 &chrome_apps_dir)) {
463 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) 465 if (file_util::IsDirectoryEmpty(chrome_apps_dir))
464 base::DeleteFile(chrome_apps_dir, false); 466 base::DeleteFile(chrome_apps_dir, false);
465 } 467 }
466 } 468 }
467 469
468 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 470 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
469 GetShortcutLocationsAndDeleteShortcuts(base::FilePath(), profile_path, L"", 471 GetShortcutLocationsAndDeleteShortcuts(base::FilePath(), profile_path, L"",
470 NULL, NULL); 472 NULL, NULL);
471 473
472 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 474 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
473 base::FilePath chrome_apps_dir; 475 base::FilePath chrome_apps_dir;
474 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { 476 if (ShellUtil::GetShortcutPath(
475 chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName()); 477 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
gab 2013/08/28 19:52:27 nit: indent 2 more spaces
calamity 2013/10/02 01:08:05 Done.
478 BrowserDistribution::GetDistribution(),
479 ShellUtil::CURRENT_USER,
480 &chrome_apps_dir)) {
476 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) 481 if (file_util::IsDirectoryEmpty(chrome_apps_dir))
477 base::DeleteFile(chrome_apps_dir, false); 482 base::DeleteFile(chrome_apps_dir, false);
478 } 483 }
479 } 484 }
480 485
481 std::vector<base::FilePath> GetShortcutPaths( 486 std::vector<base::FilePath> GetShortcutPaths(
482 const ShellIntegration::ShortcutLocations& creation_locations) { 487 const ShellIntegration::ShortcutLocations& creation_locations) {
483 // Shortcut paths under which to create shortcuts. 488 // Shortcut paths under which to create shortcuts.
484 std::vector<base::FilePath> shortcut_paths; 489 std::vector<base::FilePath> shortcut_paths;
485 // Locations to add to shortcut_paths. 490 // Locations to add to shortcut_paths.
486 struct { 491 struct {
487 bool use_this_location; 492 bool use_this_location;
488 int location_id; 493 ShellUtil::ShortcutLocation location_id;
489 const wchar_t* subdir;
490 } locations[] = { 494 } locations[] = {
491 { 495 {
492 creation_locations.on_desktop, 496 creation_locations.on_desktop,
493 base::DIR_USER_DESKTOP, 497 ShellUtil::SHORTCUT_LOCATION_DESKTOP
494 NULL
495 }, { 498 }, {
496 creation_locations.in_applications_menu, 499 creation_locations.in_applications_menu_root,
497 base::DIR_START_MENU, 500 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT
498 creation_locations.applications_menu_subdir.empty() ? NULL :
499 creation_locations.applications_menu_subdir.c_str()
500 }, { 501 }, {
501 creation_locations.in_quick_launch_bar, 502 creation_locations.in_applications_menu_chrome_subdir,
502 // For Win7, in_quick_launch_bar means pinning to taskbar. Use 503 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
503 // base::PATH_START as a flag for this case. 504 }, {
504 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? 505 creation_locations.in_applications_menu_chrome_apps_subdir,
505 base::PATH_START : base::DIR_APP_DATA, 506 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
506 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? 507 }, {
507 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" 508 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to
509 // taskbar. This needs to be handled by callers.
510 creation_locations.in_quick_launch_bar &&
511 base::win::GetVersion() < base::win::VERSION_WIN7,
512 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
508 } 513 }
509 }; 514 };
515
516 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
510 // Populate shortcut_paths. 517 // Populate shortcut_paths.
511 for (int i = 0; i < arraysize(locations); ++i) { 518 for (int i = 0; i < arraysize(locations); ++i) {
512 if (locations[i].use_this_location) { 519 if (locations[i].use_this_location) {
513 base::FilePath path; 520 base::FilePath path;
514 521 if (!ShellUtil::GetShortcutPath(locations[i].location_id,
515 // Skip the Win7 case. 522 dist,
516 if (locations[i].location_id == base::PATH_START) 523 ShellUtil::CURRENT_USER,
517 continue; 524 &path)) {
518 525 NOTREACHED();
519 if (!PathService::Get(locations[i].location_id, &path)) {
520 continue; 526 continue;
521 } 527 }
522
523 if (locations[i].subdir != NULL)
524 path = path.Append(locations[i].subdir);
525 shortcut_paths.push_back(path); 528 shortcut_paths.push_back(path);
526 } 529 }
527 } 530 }
528 return shortcut_paths; 531 return shortcut_paths;
529 } 532 }
530 533
531 } // namespace internals 534 } // namespace internals
532 535
533 } // namespace web_app 536 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698