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 // 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 28 matching lines...) Expand all Loading... |
39 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/installer/util/browser_distribution.h" | 40 #include "chrome/installer/util/browser_distribution.h" |
41 #include "chrome/installer/util/install_util.h" | 41 #include "chrome/installer/util/install_util.h" |
42 #include "chrome/installer/util/master_preferences.h" | 42 #include "chrome/installer/util/master_preferences.h" |
43 #include "chrome/installer/util/master_preferences_constants.h" | 43 #include "chrome/installer/util/master_preferences_constants.h" |
44 | 44 |
45 using base::win::RegKey; | 45 using base::win::RegKey; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
| 49 typedef ShellUtil::ChromeShortcutProperties ChromeShortcutProperties; |
| 50 |
49 // An enum used to tell QuickIsChromeRegistered() which level of registration | 51 // An enum used to tell QuickIsChromeRegistered() which level of registration |
50 // the caller wants to confirm. | 52 // the caller wants to confirm. |
51 enum RegistrationConfirmationLevel { | 53 enum RegistrationConfirmationLevel { |
52 // Only look for Chrome's ProgIds. | 54 // Only look for Chrome's ProgIds. |
53 // This is sufficient when we are trying to determine the suffix of the | 55 // This is sufficient when we are trying to determine the suffix of the |
54 // currently running Chrome as shell integration registrations might not be | 56 // currently running Chrome as shell integration registrations might not be |
55 // present. | 57 // present. |
56 CONFIRM_PROGID_REGISTRATION = 0, | 58 CONFIRM_PROGID_REGISTRATION = 0, |
57 // Confirm that Chrome is fully integrated with Windows (i.e. registered with | 59 // Confirm that Chrome is fully integrated with Windows (i.e. registered with |
58 // Defaut Programs). These registrations can be in HKCU as of Windows 8. | 60 // Defaut Programs). These registrations can be in HKCU as of Windows 8. |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 &entries); | 932 &entries); |
931 // Change the default protocol handler for current user. | 933 // Change the default protocol handler for current user. |
932 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 934 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
933 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 935 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
934 return false; | 936 return false; |
935 } | 937 } |
936 | 938 |
937 return true; | 939 return true; |
938 } | 940 } |
939 | 941 |
| 942 // Returns |properties.shortcut_name| if the property is set, otherwise it |
| 943 // returns dist->GetAppShortcutName(). In any case, it makes sure the |
| 944 // return value is suffixed with ".lnk". |
| 945 string16 ExtractShortcutNameFromProperties( |
| 946 BrowserDistribution* dist, |
| 947 const ChromeShortcutProperties& properties) { |
| 948 DCHECK(dist); |
| 949 string16 shortcut_name; |
| 950 if (properties.has_shortcut_name()) |
| 951 shortcut_name = properties.shortcut_name; |
| 952 else |
| 953 shortcut_name = dist->GetAppShortCutName(); |
| 954 |
| 955 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) |
| 956 shortcut_name.append(installer::kLnkExt); |
| 957 |
| 958 return shortcut_name; |
| 959 } |
| 960 |
| 961 // Returns a ShortcutProperties struct containing the properties to set on the |
| 962 // shortcut based on the provided ChromeShortcutProperties. If |operation| is |
| 963 // to create, some properties might be given a default if not set in |
| 964 // |properties| (see individual setters in ChromeShortcutProperties for |
| 965 // details). |
| 966 base::win::ShortcutProperties GetShortcutPropertiesFromChromeShortcutProperties( |
| 967 BrowserDistribution* dist, |
| 968 const ChromeShortcutProperties& properties, |
| 969 base::win::ShortcutOperation operation) { |
| 970 bool create = (operation == base::win::SHORTCUT_CREATE_ALWAYS || |
| 971 operation == base::win::SHORTCUT_REPLACE_EXISTING); |
| 972 // |chrome_exe| is mandatory when creating the shortcut. |
| 973 DCHECK(!create || properties.has_chrome_exe()); |
| 974 |
| 975 base::win::ShortcutProperties shortcut_properties; |
| 976 |
| 977 if (properties.has_chrome_exe()) { |
| 978 shortcut_properties.set_target(properties.chrome_exe); |
| 979 DCHECK(!properties.chrome_exe.DirName().empty()); |
| 980 shortcut_properties.set_working_dir(properties.chrome_exe.DirName()); |
| 981 } |
| 982 |
| 983 if (properties.has_arguments()) |
| 984 shortcut_properties.set_arguments(properties.arguments); |
| 985 |
| 986 if (properties.has_description()) |
| 987 shortcut_properties.set_description(properties.description); |
| 988 else if (create) |
| 989 shortcut_properties.set_description(dist->GetAppDescription()); |
| 990 |
| 991 if (properties.has_icon()) { |
| 992 shortcut_properties.set_icon(properties.icon, 0); |
| 993 } else if (create) { |
| 994 int icon_index = dist->GetIconIndex(); |
| 995 installer::MasterPreferences prefs( |
| 996 properties.chrome_exe.DirName().AppendASCII( |
| 997 installer::kDefaultMasterPrefs)); |
| 998 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, |
| 999 &icon_index); |
| 1000 shortcut_properties.set_icon(properties.chrome_exe, icon_index); |
| 1001 } |
| 1002 |
| 1003 if (properties.has_app_id()) { |
| 1004 shortcut_properties.set_app_id(properties.app_id); |
| 1005 } else if (create) { |
| 1006 bool is_per_user_install = |
| 1007 InstallUtil::IsPerUserInstall(properties.chrome_exe.value().c_str()); |
| 1008 shortcut_properties.set_app_id( |
| 1009 ShellUtil::GetBrowserModelId(dist, is_per_user_install)); |
| 1010 } |
| 1011 |
| 1012 if (properties.has_dual_mode()) |
| 1013 shortcut_properties.set_dual_mode(properties.dual_mode); |
| 1014 |
| 1015 return shortcut_properties; |
| 1016 } |
| 1017 |
940 } // namespace | 1018 } // namespace |
941 | 1019 |
942 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 1020 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
943 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 1021 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
944 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 1022 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
945 const wchar_t* ShellUtil::kRegStartMenuInternet = | 1023 const wchar_t* ShellUtil::kRegStartMenuInternet = |
946 L"Software\\Clients\\StartMenuInternet"; | 1024 L"Software\\Clients\\StartMenuInternet"; |
947 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 1025 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
948 const wchar_t* ShellUtil::kRegRegisteredApplications = | 1026 const wchar_t* ShellUtil::kRegRegisteredApplications = |
949 L"Software\\RegisteredApplications"; | 1027 L"Software\\RegisteredApplications"; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 1063 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
986 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; | 1064 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; |
987 | 1065 |
988 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 1066 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
989 const string16& chrome_exe, | 1067 const string16& chrome_exe, |
990 const string16& suffix) { | 1068 const string16& suffix) { |
991 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1069 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
992 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1070 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
993 } | 1071 } |
994 | 1072 |
995 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 1073 bool ShellUtil::GetShortcutPath(ChromeShortcutLocation location, |
996 const string16& chrome_exe, | 1074 BrowserDistribution* dist, |
997 const string16& description, | 1075 ShellChange level, |
998 const string16& appended_name, | 1076 FilePath* path) { |
999 const string16& arguments, | 1077 int dir_key = -1; |
1000 const string16& icon_path, | 1078 bool add_folder_for_dist = false; |
1001 int icon_index, | 1079 switch (location) { |
1002 ShellChange shell_change, | 1080 case SHORTCUT_DESKTOP: |
1003 uint32 options) { | 1081 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
1004 string16 shortcut_name; | 1082 base::DIR_COMMON_DESKTOP; |
1005 bool alternate = (options & ShellUtil::SHORTCUT_ALTERNATE) != 0; | 1083 break; |
1006 if (!ShellUtil::GetChromeShortcutName(dist, alternate, appended_name, | 1084 case SHORTCUT_QUICK_LAUNCH: |
1007 &shortcut_name)) | 1085 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : |
| 1086 base::DIR_DEFAULT_USER_QUICK_LAUNCH; |
| 1087 break; |
| 1088 case SHORTCUT_START_MENU: |
| 1089 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1090 base::DIR_COMMON_START_MENU; |
| 1091 add_folder_for_dist = true; |
| 1092 break; |
| 1093 default: |
| 1094 NOTREACHED(); |
| 1095 return false; |
| 1096 } |
| 1097 |
| 1098 if (!PathService::Get(dir_key, path) || path->empty()) { |
| 1099 NOTREACHED() << dir_key; |
1008 return false; | 1100 return false; |
| 1101 } |
1009 | 1102 |
1010 bool ret = false; | 1103 if (add_folder_for_dist) |
1011 if (shell_change == ShellUtil::CURRENT_USER) { | 1104 *path = path->Append(dist->GetAppShortCutName()); |
1012 FilePath shortcut_path; | 1105 |
1013 // We do not want to create a desktop shortcut to Chrome in the current | 1106 return true; |
1014 // user's desktop folder if there is already one in the "All Users" | |
1015 // desktop folder. | |
1016 bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path); | |
1017 FilePath shortcut = shortcut_path.Append(shortcut_name); | |
1018 if (!got_system_desktop || !file_util::PathExists(shortcut)) { | |
1019 // Either we couldn't query the "All Users" Desktop folder or there's | |
1020 // nothing in it, so let's continue. | |
1021 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | |
1022 shortcut = shortcut_path.Append(shortcut_name); | |
1023 ret = ShellUtil::UpdateChromeShortcut(dist, | |
1024 chrome_exe, | |
1025 shortcut.value(), | |
1026 arguments, | |
1027 description, | |
1028 icon_path, | |
1029 icon_index, | |
1030 options); | |
1031 } | |
1032 } | |
1033 } else if (shell_change == ShellUtil::SYSTEM_LEVEL) { | |
1034 FilePath shortcut_path; | |
1035 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { | |
1036 FilePath shortcut = shortcut_path.Append(shortcut_name); | |
1037 ret = ShellUtil::UpdateChromeShortcut(dist, | |
1038 chrome_exe, | |
1039 shortcut.value(), | |
1040 arguments, | |
1041 description, | |
1042 icon_path, | |
1043 icon_index, | |
1044 options); | |
1045 } | |
1046 } else { | |
1047 NOTREACHED(); | |
1048 } | |
1049 return ret; | |
1050 } | 1107 } |
1051 | 1108 |
1052 bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, | 1109 bool ShellUtil::CreateOrUpdateChromeShortcut( |
1053 const string16& chrome_exe, | 1110 ShellUtil::ChromeShortcutLocation location, |
1054 int shell_change, | 1111 BrowserDistribution* dist, |
1055 uint32 options) { | 1112 const ChromeShortcutProperties& properties, |
1056 string16 shortcut_name; | 1113 ChromeShortcutOperation operation) { |
1057 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) | 1114 DCHECK(dist); |
| 1115 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
| 1116 DCHECK(!properties.pin_to_taskbar || |
| 1117 operation == base::win::SHORTCUT_CREATE_ALWAYS); |
| 1118 |
| 1119 FilePath user_shortcut_path; |
| 1120 FilePath system_shortcut_path; |
| 1121 if (!GetShortcutPath(location, dist, CURRENT_USER, &user_shortcut_path) || |
| 1122 !GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path) || |
| 1123 user_shortcut_path.empty() || |
| 1124 system_shortcut_path.empty()) { |
| 1125 NOTREACHED(); |
1058 return false; | 1126 return false; |
| 1127 } |
1059 | 1128 |
1060 bool ret = true; | 1129 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); |
1061 // First create shortcut for the current user. | 1130 user_shortcut_path = user_shortcut_path.Append(shortcut_name); |
1062 if (shell_change & ShellUtil::CURRENT_USER) { | 1131 system_shortcut_path = system_shortcut_path.Append(shortcut_name); |
1063 FilePath user_ql_path; | 1132 |
1064 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { | 1133 FilePath *chosen_path; |
1065 user_ql_path = user_ql_path.Append(shortcut_name); | 1134 if (properties.level == SYSTEM_LEVEL) { |
1066 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, | 1135 // Install the system-level shortcut if requested. |
1067 user_ql_path.value(), | 1136 chosen_path = &system_shortcut_path; |
1068 L"", L"", chrome_exe, | 1137 } else if (operation != SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || |
1069 dist->GetIconIndex(), | 1138 !file_util::PathExists(system_shortcut_path)){ |
1070 options); | 1139 // Otherwise install the user-level shortcut, unless the system-level |
1071 } else { | 1140 // variant of this shortcut is present on the machine and |operation| states |
1072 ret = false; | 1141 // not to create a user-level shortcut in that case. |
| 1142 chosen_path = &user_shortcut_path; |
| 1143 } else { |
| 1144 // Do not install anything if we are told to install a user-level shortcut, |
| 1145 // but the system-level variant of that shortcut is present. |
| 1146 chosen_path = &FilePath(); |
| 1147 } |
| 1148 |
| 1149 // No shortcut needs to be created/updated. |
| 1150 if (chosen_path->empty()) |
| 1151 return true; |
| 1152 |
| 1153 // Make sure the parent directories exist when creating the shortcut. |
| 1154 if (operation == SHORTCUT_CREATE_ALWAYS && |
| 1155 !file_util::CreateDirectory(chosen_path->DirName())) { |
| 1156 NOTREACHED(); |
| 1157 return false; |
| 1158 } |
| 1159 |
| 1160 base::win::ShortcutOperation shortcut_operation = |
| 1161 (operation == SHORTCUT_UPDATE_EXISTING ? |
| 1162 base::win::SHORTCUT_UPDATE_EXISTING : |
| 1163 (operation == SHORTCUT_REPLACE_EXISTING ? |
| 1164 base::win::SHORTCUT_REPLACE_EXISTING : |
| 1165 base::win::SHORTCUT_CREATE_ALWAYS)); |
| 1166 base::win::ShortcutProperties shortcut_properties( |
| 1167 GetShortcutPropertiesFromChromeShortcutProperties(dist, properties, |
| 1168 shortcut_operation)); |
| 1169 bool ret = base::win::CreateOrUpdateShortcutLink( |
| 1170 *chosen_path, shortcut_properties, shortcut_operation); |
| 1171 |
| 1172 if (ret && operation == SHORTCUT_CREATE_ALWAYS && properties.pin_to_taskbar && |
| 1173 base::win::GetVersion() >= base::win::VERSION_WIN7) { |
| 1174 ret = base::win::TaskbarPinShortcutLink(chosen_path->value().c_str()); |
| 1175 if (!ret) { |
| 1176 LOG(ERROR) << "The shorcut at " << chosen_path->value() |
| 1177 << " was created, but the taskbar pin failed."; |
1073 } | 1178 } |
1074 } | 1179 } |
1075 | 1180 |
1076 // Add a shortcut to Default User's profile so that all new user profiles | |
1077 // get it. | |
1078 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | |
1079 FilePath default_ql_path; | |
1080 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { | |
1081 default_ql_path = default_ql_path.Append(shortcut_name); | |
1082 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, | |
1083 default_ql_path.value(), | |
1084 L"", L"", chrome_exe, | |
1085 dist->GetIconIndex(), | |
1086 options) && ret; | |
1087 } else { | |
1088 ret = false; | |
1089 } | |
1090 } | |
1091 | |
1092 return ret; | 1181 return ret; |
1093 } | 1182 } |
1094 | 1183 |
1095 string16 ShellUtil::GetChromeIcon(BrowserDistribution* dist, | 1184 string16 ShellUtil::GetChromeIcon(BrowserDistribution* dist, |
1096 const string16& chrome_exe) { | 1185 const string16& chrome_exe) { |
1097 string16 chrome_icon(chrome_exe); | 1186 string16 chrome_icon(chrome_exe); |
1098 chrome_icon.append(L","); | 1187 chrome_icon.append(L","); |
1099 chrome_icon.append(base::IntToString16(dist->GetIconIndex())); | 1188 chrome_icon.append(base::IntToString16(dist->GetIconIndex())); |
1100 return chrome_icon; | 1189 return chrome_icon; |
1101 } | 1190 } |
1102 | 1191 |
1103 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { | 1192 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { |
1104 return L"\"" + chrome_exe + L"\" -- \"%1\""; | 1193 return L"\"" + chrome_exe + L"\" -- \"%1\""; |
1105 } | 1194 } |
1106 | 1195 |
1107 string16 ShellUtil::GetChromeDelegateCommand(const string16& chrome_exe) { | 1196 string16 ShellUtil::GetChromeDelegateCommand(const string16& chrome_exe) { |
1108 return L"\"" + chrome_exe + L"\" -- %*"; | 1197 return L"\"" + chrome_exe + L"\" -- %*"; |
1109 } | 1198 } |
1110 | 1199 |
1111 bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist, | |
1112 bool alternate, | |
1113 const string16& appended_name, | |
1114 string16* shortcut) { | |
1115 shortcut->assign(alternate ? dist->GetAlternateApplicationName() : | |
1116 dist->GetAppShortCutName()); | |
1117 if (!appended_name.empty()) { | |
1118 shortcut->append(L" ("); | |
1119 shortcut->append(appended_name); | |
1120 shortcut->append(L")"); | |
1121 } | |
1122 shortcut->append(L".lnk"); | |
1123 return true; | |
1124 } | |
1125 | |
1126 bool ShellUtil::GetDesktopPath(bool system_level, FilePath* path) { | |
1127 int dir_key = system_level ? base::DIR_COMMON_DESKTOP : | |
1128 base::DIR_USER_DESKTOP; | |
1129 return PathService::Get(dir_key, path); | |
1130 } | |
1131 | |
1132 bool ShellUtil::GetQuickLaunchPath(bool system_level, FilePath* path) { | |
1133 int dir_key = system_level ? base::DIR_DEFAULT_USER_QUICK_LAUNCH : | |
1134 base::DIR_USER_QUICK_LAUNCH; | |
1135 return PathService::Get(dir_key, path); | |
1136 } | |
1137 | |
1138 void ShellUtil::GetRegisteredBrowsers( | 1200 void ShellUtil::GetRegisteredBrowsers( |
1139 BrowserDistribution* dist, | 1201 BrowserDistribution* dist, |
1140 std::map<string16, string16>* browsers) { | 1202 std::map<string16, string16>* browsers) { |
1141 DCHECK(dist); | 1203 DCHECK(dist); |
1142 DCHECK(browsers); | 1204 DCHECK(browsers); |
1143 | 1205 |
1144 const string16 base_key(ShellUtil::kRegStartMenuInternet); | 1206 const string16 base_key(ShellUtil::kRegStartMenuInternet); |
1145 string16 client_path; | 1207 string16 client_path; |
1146 RegKey key; | 1208 RegKey key; |
1147 string16 name; | 1209 string16 name; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 } else if (elevate_if_not_admin && | 1606 } else if (elevate_if_not_admin && |
1545 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1607 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1546 // Elevate to do the whole job | 1608 // Elevate to do the whole job |
1547 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 1609 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
1548 } else { | 1610 } else { |
1549 // Admin rights are required to register capabilities before Windows 8. | 1611 // Admin rights are required to register capabilities before Windows 8. |
1550 return false; | 1612 return false; |
1551 } | 1613 } |
1552 } | 1614 } |
1553 | 1615 |
1554 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, | 1616 bool ShellUtil::RemoveChromeShortcut( |
1555 int shell_change, uint32 options) { | 1617 ChromeShortcutLocation location, |
1556 // Only SHORTCUT_ALTERNATE is a valid option for this function. | 1618 BrowserDistribution* dist, |
1557 DCHECK(!options || options == ShellUtil::SHORTCUT_ALTERNATE); | 1619 ShellChange level, |
| 1620 const string16* shortcut_name) { |
| 1621 bool delete_folder = (location == SHORTCUT_START_MENU); |
1558 | 1622 |
1559 string16 shortcut_name; | 1623 FilePath shortcut_folder; |
1560 bool alternate = (options & ShellUtil::SHORTCUT_ALTERNATE) != 0; | 1624 if (!GetShortcutPath(location, dist, level, &shortcut_folder) || |
1561 if (!ShellUtil::GetChromeShortcutName(dist, alternate, L"", | 1625 shortcut_folder.empty()) { |
1562 &shortcut_name)) | 1626 NOTREACHED(); |
1563 return false; | 1627 return false; |
1564 | |
1565 bool ret = true; | |
1566 if (shell_change & ShellUtil::CURRENT_USER) { | |
1567 FilePath shortcut_path; | |
1568 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | |
1569 FilePath shortcut = shortcut_path.Append(shortcut_name); | |
1570 ret = file_util::Delete(shortcut, false); | |
1571 } else { | |
1572 ret = false; | |
1573 } | |
1574 } | 1628 } |
1575 | 1629 |
1576 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | 1630 string16 shortcut_base_name( |
1577 FilePath shortcut_path; | 1631 (shortcut_name ? *shortcut_name : dist->GetAppShortCutName()) + |
1578 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { | 1632 installer::kLnkExt); |
1579 FilePath shortcut = shortcut_path.Append(shortcut_name); | 1633 FilePath shortcut_path(shortcut_folder.Append(shortcut_base_name)); |
1580 ret = file_util::Delete(shortcut, false) && ret; | |
1581 } else { | |
1582 ret = false; | |
1583 } | |
1584 } | |
1585 return ret; | |
1586 } | |
1587 | 1634 |
1588 bool ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 1635 // Unpin the shortcut if it was ever pinned by the user or the installer. |
1589 const std::vector<string16>& appended_names) { | 1636 VLOG(1) << "Trying to unpin " << shortcut_path.value(); |
1590 FilePath shortcut_path; | 1637 if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) |
1591 bool ret = true; | 1638 VLOG(1) << shortcut_path.value() << " wasn't pinned (or the unpin failed)."; |
1592 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | |
1593 for (std::vector<string16>::const_iterator it = | |
1594 appended_names.begin(); | |
1595 it != appended_names.end(); | |
1596 ++it) { | |
1597 FilePath delete_shortcut = shortcut_path.Append(*it); | |
1598 ret = ret && file_util::Delete(delete_shortcut, false); | |
1599 } | |
1600 } else { | |
1601 ret = false; | |
1602 } | |
1603 return ret; | |
1604 } | |
1605 | 1639 |
1606 bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, | 1640 if (delete_folder) |
1607 int shell_change) { | 1641 return file_util::Delete(shortcut_folder, true); |
1608 string16 shortcut_name; | 1642 else |
1609 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) | 1643 return file_util::Delete(shortcut_path, false); |
1610 return false; | |
1611 | |
1612 bool ret = true; | |
1613 // First remove shortcut for the current user. | |
1614 if (shell_change & ShellUtil::CURRENT_USER) { | |
1615 FilePath user_ql_path; | |
1616 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { | |
1617 user_ql_path = user_ql_path.Append(shortcut_name); | |
1618 ret = file_util::Delete(user_ql_path, false); | |
1619 } else { | |
1620 ret = false; | |
1621 } | |
1622 } | |
1623 | |
1624 // Delete shortcut in Default User's profile | |
1625 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | |
1626 FilePath default_ql_path; | |
1627 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { | |
1628 default_ql_path = default_ql_path.Append(shortcut_name); | |
1629 ret = file_util::Delete(default_ql_path, false) && ret; | |
1630 } else { | |
1631 ret = false; | |
1632 } | |
1633 } | |
1634 | |
1635 return ret; | |
1636 } | 1644 } |
1637 | 1645 |
1638 void ShellUtil::RemoveChromeStartScreenShortcuts(BrowserDistribution* dist, | 1646 void ShellUtil::RemoveChromeStartScreenShortcuts(BrowserDistribution* dist, |
1639 const string16& chrome_exe) { | 1647 const string16& chrome_exe) { |
1640 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 1648 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
1641 return; | 1649 return; |
1642 | 1650 |
1643 FilePath app_shortcuts_path; | 1651 FilePath app_shortcuts_path; |
1644 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &app_shortcuts_path)) { | 1652 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &app_shortcuts_path)) { |
1645 LOG(ERROR) << "Could not get application shortcuts location to delete" | 1653 LOG(ERROR) << "Could not get application shortcuts location to delete" |
(...skipping 10 matching lines...) Expand all Loading... |
1656 } | 1664 } |
1657 | 1665 |
1658 VLOG(1) << "Removing start screen shortcuts from " | 1666 VLOG(1) << "Removing start screen shortcuts from " |
1659 << app_shortcuts_path.value(); | 1667 << app_shortcuts_path.value(); |
1660 if (!file_util::Delete(app_shortcuts_path, true)) { | 1668 if (!file_util::Delete(app_shortcuts_path, true)) { |
1661 LOG(ERROR) << "Failed to remove start screen shortcuts from " | 1669 LOG(ERROR) << "Failed to remove start screen shortcuts from " |
1662 << app_shortcuts_path.value(); | 1670 << app_shortcuts_path.value(); |
1663 } | 1671 } |
1664 } | 1672 } |
1665 | 1673 |
1666 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, | |
1667 const string16& chrome_exe, | |
1668 const string16& shortcut, | |
1669 const string16& arguments, | |
1670 const string16& description, | |
1671 const string16& icon_path, | |
1672 int icon_index, | |
1673 uint32 options) { | |
1674 const FilePath chrome_path(FilePath(chrome_exe).DirName()); | |
1675 | |
1676 installer::MasterPreferences prefs( | |
1677 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); | |
1678 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { | |
1679 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | |
1680 &icon_index); | |
1681 } | |
1682 | |
1683 const string16 app_id( | |
1684 GetBrowserModelId(dist, | |
1685 InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); | |
1686 const bool is_dual_mode = ((options & ShellUtil::SHORTCUT_DUAL_MODE) != 0); | |
1687 const base::win::ShortcutOperation operation = | |
1688 (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0 ? | |
1689 base::win::SHORTCUT_CREATE_ALWAYS : | |
1690 base::win::SHORTCUT_UPDATE_EXISTING; | |
1691 | |
1692 // TODO(gab): The shell_util interface will also be refactored in an upcoming | |
1693 // CL to use a ShortcutProperties like interface for its shortcut methods. | |
1694 base::win::ShortcutProperties shortcut_properties; | |
1695 shortcut_properties.set_target(FilePath(chrome_exe)); | |
1696 shortcut_properties.set_working_dir(chrome_path); | |
1697 shortcut_properties.set_arguments(arguments); | |
1698 shortcut_properties.set_description(description); | |
1699 shortcut_properties.set_icon(FilePath(icon_path), icon_index); | |
1700 shortcut_properties.set_app_id(app_id); | |
1701 shortcut_properties.set_dual_mode(is_dual_mode); | |
1702 return base::win::CreateOrUpdateShortcutLink( | |
1703 FilePath(shortcut), shortcut_properties, operation); | |
1704 } | |
1705 | |
1706 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 1674 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
1707 // Use a thread-safe cache for the user's suffix. | 1675 // Use a thread-safe cache for the user's suffix. |
1708 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 1676 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
1709 LAZY_INSTANCE_INITIALIZER; | 1677 LAZY_INSTANCE_INITIALIZER; |
1710 return suffix_instance.Get().GetSuffix(suffix); | 1678 return suffix_instance.Get().GetSuffix(suffix); |
1711 } | 1679 } |
1712 | 1680 |
1713 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 1681 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
1714 wchar_t user_name[256]; | 1682 wchar_t user_name[256]; |
1715 DWORD size = arraysize(user_name); | 1683 DWORD size = arraysize(user_name); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 // are any left...). | 1731 // are any left...). |
1764 if (free_bits >= 8 && next_byte_index < size) { | 1732 if (free_bits >= 8 && next_byte_index < size) { |
1765 free_bits -= 8; | 1733 free_bits -= 8; |
1766 bit_stream += bytes[next_byte_index++] << free_bits; | 1734 bit_stream += bytes[next_byte_index++] << free_bits; |
1767 } | 1735 } |
1768 } | 1736 } |
1769 | 1737 |
1770 DCHECK_EQ(ret.length(), encoded_length); | 1738 DCHECK_EQ(ret.length(), encoded_length); |
1771 return ret; | 1739 return ret; |
1772 } | 1740 } |
OLD | NEW |