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

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 8502033: Add Windows desktop shortcut for multiple profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file defines functions that integrate Chrome in Windows shell. These 5 // This file defines functions that integrate Chrome in Windows shell. These
6 // functions can be used by Chrome as well as Chrome installer. All of the 6 // functions can be used by Chrome as well as Chrome installer. All of the
7 // work is done by the local functions defined in anonymous namespace in 7 // work is done by the local functions defined in anonymous namespace in
8 // this class. 8 // this class.
9 9
10 #include "chrome/installer/util/shell_util.h" 10 #include "chrome/installer/util/shell_util.h"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); 538 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin();
539 itr != entries.end() && !cleanup_needed; ++itr) { 539 itr != entries.end() && !cleanup_needed; ++itr) {
540 cleanup_needed = (*itr)->NameExistsInHKLM(); 540 cleanup_needed = (*itr)->NameExistsInHKLM();
541 } 541 }
542 return cleanup_needed; 542 return cleanup_needed;
543 } 543 }
544 544
545 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, 545 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist,
546 const std::wstring& chrome_exe, 546 const std::wstring& chrome_exe,
547 const std::wstring& description, 547 const std::wstring& description,
548 const std::wstring& appended_name,
549 const std::wstring& arguments,
548 ShellChange shell_change, 550 ShellChange shell_change,
549 bool alternate, 551 bool alternate,
550 bool create_new) { 552 bool create_new) {
551 std::wstring shortcut_name; 553 std::wstring shortcut_name;
552 if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, alternate)) 554 if (!ShellUtil::GetChromeShortcutName(dist, alternate, appended_name,
555 &shortcut_name))
553 return false; 556 return false;
554 557
555 bool ret = false; 558 bool ret = false;
556 if (shell_change == ShellUtil::CURRENT_USER) { 559 if (shell_change == ShellUtil::CURRENT_USER) {
557 FilePath shortcut_path; 560 FilePath shortcut_path;
558 // We do not want to create a desktop shortcut to Chrome in the current 561 // We do not want to create a desktop shortcut to Chrome in the current
559 // user's desktop folder if there is already one in the "All Users" 562 // user's desktop folder if there is already one in the "All Users"
560 // desktop folder. 563 // desktop folder.
561 bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path); 564 bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path);
562 FilePath shortcut = shortcut_path.Append(shortcut_name); 565 FilePath shortcut = shortcut_path.Append(shortcut_name);
563 if (!got_system_desktop || !file_util::PathExists(shortcut)) { 566 if (!got_system_desktop || !file_util::PathExists(shortcut)) {
564 // Either we couldn't query the "All Users" Desktop folder or there's 567 // Either we couldn't query the "All Users" Desktop folder or there's
565 // nothing in it, so let's continue. 568 // nothing in it, so let's continue.
566 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { 569 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) {
567 shortcut = shortcut_path.Append(shortcut_name); 570 shortcut = shortcut_path.Append(shortcut_name);
568 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, 571 ret = ShellUtil::UpdateChromeShortcut(dist,
572 chrome_exe,
569 shortcut.value(), 573 shortcut.value(),
570 description, create_new); 574 arguments,
575 description,
576 create_new);
571 } 577 }
572 } 578 }
573 } else if (shell_change == ShellUtil::SYSTEM_LEVEL) { 579 } else if (shell_change == ShellUtil::SYSTEM_LEVEL) {
574 FilePath shortcut_path; 580 FilePath shortcut_path;
575 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { 581 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) {
576 FilePath shortcut = shortcut_path.Append(shortcut_name); 582 FilePath shortcut = shortcut_path.Append(shortcut_name);
577 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, 583 ret = ShellUtil::UpdateChromeShortcut(dist,
584 chrome_exe,
578 shortcut.value(), 585 shortcut.value(),
579 description, create_new); 586 arguments,
587 description,
588 create_new);
580 } 589 }
581 } else { 590 } else {
582 NOTREACHED(); 591 NOTREACHED();
583 } 592 }
584 return ret; 593 return ret;
585 } 594 }
586 595
587 bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, 596 bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist,
588 const std::wstring& chrome_exe, 597 const std::wstring& chrome_exe,
589 int shell_change, 598 int shell_change,
590 bool create_new) { 599 bool create_new) {
591 std::wstring shortcut_name; 600 std::wstring shortcut_name;
592 if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)) 601 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name))
593 return false; 602 return false;
594 603
595 bool ret = true; 604 bool ret = true;
596 // First create shortcut for the current user. 605 // First create shortcut for the current user.
597 if (shell_change & ShellUtil::CURRENT_USER) { 606 if (shell_change & ShellUtil::CURRENT_USER) {
598 std::wstring user_ql_path; 607 std::wstring user_ql_path;
599 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { 608 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) {
600 file_util::AppendToPath(&user_ql_path, shortcut_name); 609 file_util::AppendToPath(&user_ql_path, shortcut_name);
601 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, user_ql_path, 610 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, user_ql_path,
602 L"", create_new); 611 L"", L"", create_new);
603 } else { 612 } else {
604 ret = false; 613 ret = false;
605 } 614 }
606 } 615 }
607 616
608 // Add a shortcut to Default User's profile so that all new user profiles 617 // Add a shortcut to Default User's profile so that all new user profiles
609 // get it. 618 // get it.
610 if (shell_change & ShellUtil::SYSTEM_LEVEL) { 619 if (shell_change & ShellUtil::SYSTEM_LEVEL) {
611 std::wstring default_ql_path; 620 std::wstring default_ql_path;
612 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { 621 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) {
613 file_util::AppendToPath(&default_ql_path, shortcut_name); 622 file_util::AppendToPath(&default_ql_path, shortcut_name);
614 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, default_ql_path, 623 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, default_ql_path,
615 L"", create_new) && ret; 624 L"", L"", create_new) && ret;
616 } else { 625 } else {
617 ret = false; 626 ret = false;
618 } 627 }
619 } 628 }
620 629
621 return ret; 630 return ret;
622 } 631 }
623 632
624 std::wstring ShellUtil::GetChromeIcon(BrowserDistribution* dist, 633 std::wstring ShellUtil::GetChromeIcon(BrowserDistribution* dist,
625 const std::wstring& chrome_exe) { 634 const std::wstring& chrome_exe) {
626 std::wstring chrome_icon(chrome_exe); 635 std::wstring chrome_icon(chrome_exe);
627 chrome_icon.append(L","); 636 chrome_icon.append(L",");
628 chrome_icon.append(base::IntToString16(dist->GetIconIndex())); 637 chrome_icon.append(base::IntToString16(dist->GetIconIndex()));
629 return chrome_icon; 638 return chrome_icon;
630 } 639 }
631 640
632 std::wstring ShellUtil::GetChromeShellOpenCmd(const std::wstring& chrome_exe) { 641 std::wstring ShellUtil::GetChromeShellOpenCmd(const std::wstring& chrome_exe) {
633 return L"\"" + chrome_exe + L"\" -- \"%1\""; 642 return L"\"" + chrome_exe + L"\" -- \"%1\"";
634 } 643 }
635 644
636 bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist, 645 bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist,
637 std::wstring* shortcut, bool alternate) { 646 bool alternate,
647 const std::wstring& appended_name,
648 std::wstring* shortcut) {
638 shortcut->assign(alternate ? dist->GetAlternateApplicationName() : 649 shortcut->assign(alternate ? dist->GetAlternateApplicationName() :
639 dist->GetAppShortCutName()); 650 dist->GetAppShortCutName());
651 if (!appended_name.empty()) {
652 shortcut->append(L" (");
653 shortcut->append(appended_name);
654 shortcut->append(L")");
655 }
640 shortcut->append(L".lnk"); 656 shortcut->append(L".lnk");
641 return true; 657 return true;
642 } 658 }
643 659
644 bool ShellUtil::GetDesktopPath(bool system_level, FilePath* path) { 660 bool ShellUtil::GetDesktopPath(bool system_level, FilePath* path) {
645 wchar_t desktop[MAX_PATH]; 661 wchar_t desktop[MAX_PATH];
646 int dir = system_level ? CSIDL_COMMON_DESKTOPDIRECTORY : 662 int dir = system_level ? CSIDL_COMMON_DESKTOPDIRECTORY :
647 CSIDL_DESKTOPDIRECTORY; 663 CSIDL_DESKTOPDIRECTORY;
648 if (FAILED(SHGetFolderPath(NULL, dir, NULL, SHGFP_TYPE_CURRENT, desktop))) 664 if (FAILED(SHGetFolderPath(NULL, dir, NULL, SHGFP_TYPE_CURRENT, desktop)))
649 return false; 665 return false;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 } else { 963 } else {
948 // we need admin rights to register our capability. If we don't 964 // we need admin rights to register our capability. If we don't
949 // have them and can't elevate, give up. 965 // have them and can't elevate, give up.
950 return false; 966 return false;
951 } 967 }
952 } 968 }
953 969
954 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, 970 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist,
955 int shell_change, bool alternate) { 971 int shell_change, bool alternate) {
956 std::wstring shortcut_name; 972 std::wstring shortcut_name;
957 if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, alternate)) 973 if (!ShellUtil::GetChromeShortcutName(dist, alternate, L"",
974 &shortcut_name))
958 return false; 975 return false;
959 976
960 bool ret = true; 977 bool ret = true;
961 if (shell_change & ShellUtil::CURRENT_USER) { 978 if (shell_change & ShellUtil::CURRENT_USER) {
962 FilePath shortcut_path; 979 FilePath shortcut_path;
963 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { 980 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) {
964 FilePath shortcut = shortcut_path.Append(shortcut_name); 981 FilePath shortcut = shortcut_path.Append(shortcut_name);
965 ret = file_util::Delete(shortcut, false); 982 ret = file_util::Delete(shortcut, false);
966 } else { 983 } else {
967 ret = false; 984 ret = false;
968 } 985 }
969 } 986 }
970 987
971 if (shell_change & ShellUtil::SYSTEM_LEVEL) { 988 if (shell_change & ShellUtil::SYSTEM_LEVEL) {
972 FilePath shortcut_path; 989 FilePath shortcut_path;
973 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { 990 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) {
974 FilePath shortcut = shortcut_path.Append(shortcut_name); 991 FilePath shortcut = shortcut_path.Append(shortcut_name);
975 ret = file_util::Delete(shortcut, false) && ret; 992 ret = file_util::Delete(shortcut, false) && ret;
976 } else { 993 } else {
977 ret = false; 994 ret = false;
978 } 995 }
979 } 996 }
980 return ret; 997 return ret;
981 } 998 }
982 999
1000 bool ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames(
1001 const std::vector<std::wstring>& appended_names) {
1002 FilePath shortcut_path;
1003 bool ret = true;
1004 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) {
1005 for (std::vector<std::wstring>::const_iterator it =
1006 appended_names.begin();
1007 it != appended_names.end();
1008 ++it) {
1009 FilePath delete_shortcut = shortcut_path.Append(*it);
1010 ret = ret && file_util::Delete(delete_shortcut, false);
1011 }
1012 } else {
1013 ret = false;
1014 }
1015 return ret;
1016 }
1017
983 bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, 1018 bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist,
984 int shell_change) { 1019 int shell_change) {
985 std::wstring shortcut_name; 1020 std::wstring shortcut_name;
986 if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)) 1021 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name))
987 return false; 1022 return false;
988 1023
989 bool ret = true; 1024 bool ret = true;
990 // First remove shortcut for the current user. 1025 // First remove shortcut for the current user.
991 if (shell_change & ShellUtil::CURRENT_USER) { 1026 if (shell_change & ShellUtil::CURRENT_USER) {
992 std::wstring user_ql_path; 1027 std::wstring user_ql_path;
993 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { 1028 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) {
994 file_util::AppendToPath(&user_ql_path, shortcut_name); 1029 file_util::AppendToPath(&user_ql_path, shortcut_name);
995 ret = file_util::Delete(user_ql_path, false); 1030 ret = file_util::Delete(user_ql_path, false);
996 } else { 1031 } else {
(...skipping 11 matching lines...) Expand all
1008 ret = false; 1043 ret = false;
1009 } 1044 }
1010 } 1045 }
1011 1046
1012 return ret; 1047 return ret;
1013 } 1048 }
1014 1049
1015 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, 1050 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist,
1016 const std::wstring& chrome_exe, 1051 const std::wstring& chrome_exe,
1017 const std::wstring& shortcut, 1052 const std::wstring& shortcut,
1053 const std::wstring& arguments,
1018 const std::wstring& description, 1054 const std::wstring& description,
1019 bool create_new) { 1055 bool create_new) {
1020 std::wstring chrome_path = FilePath(chrome_exe).DirName().value(); 1056 std::wstring chrome_path = FilePath(chrome_exe).DirName().value();
1021 1057
1022 FilePath prefs_path(chrome_path); 1058 FilePath prefs_path(chrome_path);
1023 prefs_path = prefs_path.AppendASCII(installer::kDefaultMasterPrefs); 1059 prefs_path = prefs_path.AppendASCII(installer::kDefaultMasterPrefs);
1024 installer::MasterPreferences prefs(prefs_path); 1060 installer::MasterPreferences prefs(prefs_path);
1025 int icon_index = dist->GetIconIndex(); 1061 int icon_index = dist->GetIconIndex();
1026 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, 1062 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex,
1027 &icon_index); 1063 &icon_index);
1028 if (create_new) { 1064 if (create_new) {
1029 return file_util::CreateShortcutLink( 1065 return file_util::CreateShortcutLink(
1030 chrome_exe.c_str(), // target 1066 chrome_exe.c_str(), // target
1031 shortcut.c_str(), // shortcut 1067 shortcut.c_str(), // shortcut
1032 chrome_path.c_str(), // working dir 1068 chrome_path.c_str(), // working dir
1033 NULL, // arguments 1069 arguments.c_str(), // arguments
1034 description.c_str(), // description 1070 description.c_str(), // description
1035 chrome_exe.c_str(), // icon file 1071 chrome_exe.c_str(), // icon file
1036 icon_index, // icon index 1072 icon_index, // icon index
1037 dist->GetBrowserAppId().c_str()); // app id 1073 dist->GetBrowserAppId().c_str()); // app id
1038 } else { 1074 } else {
1039 return file_util::UpdateShortcutLink( 1075 return file_util::UpdateShortcutLink(
1040 chrome_exe.c_str(), // target 1076 chrome_exe.c_str(), // target
1041 shortcut.c_str(), // shortcut 1077 shortcut.c_str(), // shortcut
1042 chrome_path.c_str(), // working dir 1078 chrome_path.c_str(), // working dir
1043 NULL, // arguments 1079 arguments.c_str(), // arguments
1044 description.c_str(), // description 1080 description.c_str(), // description
1045 chrome_exe.c_str(), // icon file 1081 chrome_exe.c_str(), // icon file
1046 icon_index, // icon index 1082 icon_index, // icon index
1047 dist->GetBrowserAppId().c_str()); // app id 1083 dist->GetBrowserAppId().c_str()); // app id
1048 } 1084 }
1049 } 1085 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698