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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 964 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
965 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; | 965 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; |
966 | 966 |
967 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 967 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
968 const string16& chrome_exe, | 968 const string16& chrome_exe, |
969 const string16& suffix) { | 969 const string16& suffix) { |
970 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 970 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
971 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 971 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
972 } | 972 } |
973 | 973 |
974 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 974 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
975 const string16& chrome_exe, | 975 bool system_level, |
976 const string16& description, | 976 FilePath* path) { |
977 const string16& appended_name, | 977 switch (location) { |
978 const string16& arguments, | 978 case ShellUtil::SHORTCUT_DESKTOP: { |
979 const string16& icon_path, | 979 wchar_t desktop[MAX_PATH]; |
980 int icon_index, | 980 int dir = system_level ? CSIDL_COMMON_DESKTOPDIRECTORY : |
981 ShellChange shell_change, | 981 CSIDL_DESKTOPDIRECTORY; |
982 uint32 options) { | 982 if (FAILED(SHGetFolderPath(NULL, dir, NULL, SHGFP_TYPE_CURRENT, desktop))) |
983 string16 shortcut_name; | 983 return false; |
984 bool alternate = (options & ShellUtil::SHORTCUT_ALTERNATE) != 0; | 984 *path = FilePath(desktop); |
985 if (!ShellUtil::GetChromeShortcutName(dist, alternate, appended_name, | 985 break; |
986 &shortcut_name)) | 986 } |
987 return false; | 987 case ShellUtil::SHORTCUT_QUICK_LAUNCH: { |
988 | 988 if (system_level) { |
989 bool ret = false; | 989 wchar_t qlaunch[MAX_PATH]; |
990 if (shell_change == ShellUtil::CURRENT_USER) { | 990 // We are accessing GetDefaultUserProfileDirectory this way so that we |
991 FilePath shortcut_path; | 991 // do not have to declare dependency to Userenv.lib for chrome.exe |
992 // We do not want to create a desktop shortcut to Chrome in the current | 992 typedef BOOL (WINAPI *PROFILE_FUNC)(LPWSTR, LPDWORD); |
993 // user's desktop folder if there is already one in the "All Users" | 993 HMODULE module = LoadLibrary(L"Userenv.dll"); |
994 // desktop folder. | 994 PROFILE_FUNC p = reinterpret_cast<PROFILE_FUNC>(GetProcAddress(module, |
995 bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path); | 995 "GetDefaultUserProfileDirectoryW")); |
996 FilePath shortcut = shortcut_path.Append(shortcut_name); | 996 DWORD size = _countof(qlaunch); |
997 if (!got_system_desktop || !file_util::PathExists(shortcut)) { | 997 if ((p == NULL) || ((p)(qlaunch, &size) != TRUE)) |
998 // Either we couldn't query the "All Users" Desktop folder or there's | 998 return false; |
999 // nothing in it, so let's continue. | 999 *path = FilePath(qlaunch); |
1000 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | 1000 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1001 shortcut = shortcut_path.Append(shortcut_name); | 1001 *path = path->AppendASCII("AppData"); |
1002 ret = ShellUtil::UpdateChromeShortcut(dist, | 1002 *path = path->AppendASCII("Roaming"); |
1003 chrome_exe, | 1003 } else { |
1004 shortcut.value(), | 1004 *path = path->AppendASCII("Application Data"); |
robertshield
2012/08/22 21:39:07
This doesn't look like the right way of getting th
| |
1005 arguments, | 1005 } |
1006 description, | 1006 } else { |
1007 icon_path, | 1007 if (!PathService::Get(base::DIR_APP_DATA, path)) { |
1008 icon_index, | 1008 return false; |
1009 options); | 1009 } |
1010 } | 1010 } |
1011 *path = path->AppendASCII("Microsoft"); | |
1012 *path = path->AppendASCII("Internet Explorer"); | |
1013 *path = path->AppendASCII("Quick Launch"); | |
robertshield
2012/08/22 21:39:07
Same comment about not hard-coding paths. Doing th
| |
1014 break; | |
1011 } | 1015 } |
1012 } else if (shell_change == ShellUtil::SYSTEM_LEVEL) { | 1016 case ShellUtil::SHORTCUT_START_MENU: |
1013 FilePath shortcut_path; | 1017 case ShellUtil::SHORTCUT_START_MENU_UNINSTALL: { |
1014 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { | 1018 int dir = system_level ? base::DIR_COMMON_START_MENU : |
1015 FilePath shortcut = shortcut_path.Append(shortcut_name); | 1019 base::DIR_START_MENU; |
1016 ret = ShellUtil::UpdateChromeShortcut(dist, | 1020 if (!PathService::Get(dir, path)) |
1017 chrome_exe, | 1021 return false; |
1018 shortcut.value(), | 1022 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
1019 arguments, | 1023 *path = path->Append(dist->GetAppShortCutName()); |
1020 description, | 1024 break; |
1021 icon_path, | |
1022 icon_index, | |
1023 options); | |
1024 } | 1025 } |
1025 } else { | 1026 default: { |
1026 NOTREACHED(); | 1027 NOTREACHED(); |
1028 return false; | |
1029 } | |
1027 } | 1030 } |
1028 return ret; | 1031 return true; |
1029 } | 1032 } |
1030 | 1033 |
1031 bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, | 1034 FilePath ShellUtil::DetermineShortcutPathToCreateFromOptions( |
1032 const string16& chrome_exe, | 1035 const FilePath& user_level_shortcut, |
1033 int shell_change, | 1036 const FilePath& system_level_shortcut, |
1034 uint32 options) { | 1037 uint32 options) { |
1038 if (options & ShellUtil::SHORTCUT_SYSTEM_LEVEL) { | |
1039 // Install the system-level shortcut if requested. | |
1040 DCHECK(!system_level_shortcut.empty()); | |
1041 return system_level_shortcut; | |
1042 } else if (system_level_shortcut.empty() || | |
1043 !file_util::PathExists(system_level_shortcut)){ | |
1044 // Otherwise install the user-level shortcut, but do so iff no system-level | |
1045 // shortcut is present. | |
1046 DCHECK(!user_level_shortcut.empty()); | |
1047 return user_level_shortcut; | |
1048 } else { | |
1049 // Do not install anything if the system-level shortcut is present, but we | |
1050 // are told to install the user-level shortcut. | |
1051 return FilePath(); | |
1052 } | |
1053 } | |
1054 | |
1055 bool ShellUtil::CreateOrUpdateChromeShortcut( | |
1056 ShellUtil::ShortcutLocation location, | |
1057 BrowserDistribution* dist, | |
1058 const string16& exe_path, | |
1059 const string16& description, | |
1060 const string16& appended_name, | |
1061 const string16& arguments, | |
1062 const string16& icon_path, | |
1063 int icon_index, | |
1064 uint32 options) { | |
1035 string16 shortcut_name; | 1065 string16 shortcut_name; |
1036 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) | 1066 const bool alternate = ((options & ShellUtil::SHORTCUT_ALTERNATE) != 0 && |
1067 location == SHORTCUT_DESKTOP); | |
1068 if (!ShellUtil::GetChromeShortcutName(location, dist, alternate, | |
1069 appended_name, &shortcut_name)) { | |
1037 return false; | 1070 return false; |
1071 } | |
1038 | 1072 |
1039 bool ret = true; | 1073 FilePath user_shortcut_path; |
1040 // First create shortcut for the current user. | 1074 FilePath system_shortcut_path; |
1041 if (shell_change & ShellUtil::CURRENT_USER) { | 1075 if (!GetShortcutPath(location, false, &user_shortcut_path)) |
1042 FilePath user_ql_path; | 1076 user_shortcut_path.clear(); |
1043 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { | 1077 if (!GetShortcutPath(location, true, &system_shortcut_path)) |
1044 user_ql_path = user_ql_path.Append(shortcut_name); | 1078 system_shortcut_path.clear(); |
1045 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, | 1079 |
1046 user_ql_path.value(), | 1080 FilePath path_to_create(DetermineShortcutPathToCreateFromOptions( |
1047 L"", L"", chrome_exe, | 1081 user_shortcut_path, system_shortcut_path, options)); |
1048 dist->GetIconIndex(), | 1082 |
1049 options); | 1083 // No shortcut needs to be created/updated. |
1050 } else { | 1084 if (path_to_create.empty()) |
1051 ret = false; | 1085 return true; |
1086 | |
1087 // Make sure the parent directories exist. | |
1088 if ((options & SHORTCUT_CREATE_ALWAYS) && | |
1089 !file_util::CreateDirectory(path_to_create.DirName())) { | |
1090 NOTREACHED(); | |
1091 return false; | |
1092 } | |
1093 | |
1094 string16 app_id; | |
1095 FilePath exe_dir(FilePath(exe_path).DirName()); | |
1096 // Set the |app_id| and |icon_index| correctly if this is a shortcut to | |
1097 // chrome.exe. | |
1098 if (exe_path.find(installer::kChromeExe) != string16::npos) { | |
1099 app_id.assign(GetBrowserModelId(dist, exe_path)); | |
1100 | |
1101 installer::MasterPreferences prefs( | |
1102 exe_dir.AppendASCII(installer::kDefaultMasterPrefs)); | |
1103 if (InstallUtil::ProgramCompare(FilePath(exe_path)).Evaluate(icon_path)) { | |
1104 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | |
1105 &icon_index); | |
1052 } | 1106 } |
1053 } | 1107 } |
1054 | 1108 |
1055 // Add a shortcut to Default User's profile so that all new user profiles | 1109 bool ret = file_util::CreateOrUpdateShortcutLink( |
1056 // get it. | 1110 exe_path.c_str(), path_to_create.value().c_str(), |
1057 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | 1111 exe_dir.value().c_str(), arguments.c_str(), description.c_str(), |
1058 FilePath default_ql_path; | 1112 icon_path.c_str(), icon_index, app_id.c_str(), |
1059 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { | 1113 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
1060 default_ql_path = default_ql_path.Append(shortcut_name); | 1114 |
1061 ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, | 1115 if (ret && (options & SHORTCUT_PIN_TO_TASKBAR) && |
1062 default_ql_path.value(), | 1116 (options & SHORTCUT_CREATE_ALWAYS) && |
1063 L"", L"", chrome_exe, | 1117 base::win::GetVersion() >= base::win::VERSION_WIN7) { |
1064 dist->GetIconIndex(), | 1118 ret = file_util::TaskbarPinShortcutLink(path_to_create.value().c_str()); |
1065 options) && ret; | |
1066 } else { | |
1067 ret = false; | |
1068 } | |
1069 } | 1119 } |
1070 | 1120 |
1071 return ret; | 1121 return ret; |
1072 } | 1122 } |
1073 | 1123 |
1074 string16 ShellUtil::GetChromeIcon(BrowserDistribution* dist, | 1124 string16 ShellUtil::GetChromeIcon(BrowserDistribution* dist, |
1075 const string16& chrome_exe) { | 1125 const string16& chrome_exe) { |
1076 string16 chrome_icon(chrome_exe); | 1126 string16 chrome_icon(chrome_exe); |
1077 chrome_icon.append(L","); | 1127 chrome_icon.append(L","); |
1078 chrome_icon.append(base::IntToString16(dist->GetIconIndex())); | 1128 chrome_icon.append(base::IntToString16(dist->GetIconIndex())); |
1079 return chrome_icon; | 1129 return chrome_icon; |
1080 } | 1130 } |
1081 | 1131 |
1082 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { | 1132 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { |
1083 return L"\"" + chrome_exe + L"\" -- \"%1\""; | 1133 return L"\"" + chrome_exe + L"\" -- \"%1\""; |
1084 } | 1134 } |
1085 | 1135 |
1086 string16 ShellUtil::GetChromeDelegateCommand(const string16& chrome_exe) { | 1136 string16 ShellUtil::GetChromeDelegateCommand(const string16& chrome_exe) { |
1087 return L"\"" + chrome_exe + L"\" -- %*"; | 1137 return L"\"" + chrome_exe + L"\" -- %*"; |
1088 } | 1138 } |
1089 | 1139 |
1090 bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist, | 1140 bool ShellUtil::GetChromeShortcutName(ShellUtil::ShortcutLocation location, |
1141 BrowserDistribution* dist, | |
1091 bool alternate, | 1142 bool alternate, |
1092 const string16& appended_name, | 1143 const string16& appended_name, |
1093 string16* shortcut) { | 1144 string16* shortcut) { |
1094 shortcut->assign(alternate ? dist->GetAlternateApplicationName() : | 1145 // Only the Desktop shortcut can use the alternate name. |
1095 dist->GetAppShortCutName()); | 1146 DCHECK(!alternate || location == SHORTCUT_DESKTOP); |
1147 | |
1148 switch (location) { | |
1149 case SHORTCUT_DESKTOP: | |
1150 shortcut->assign(alternate ? dist->GetAlternateApplicationName() : | |
1151 dist->GetAppShortCutName()); | |
1152 break; | |
1153 case SHORTCUT_QUICK_LAUNCH: | |
1154 case SHORTCUT_START_MENU: | |
1155 shortcut->assign(dist->GetAppShortCutName()); | |
1156 break; | |
1157 case SHORTCUT_START_MENU_UNINSTALL: | |
1158 shortcut->assign(dist->GetUninstallLinkName()); | |
1159 break; | |
1160 default: | |
1161 NOTREACHED(); | |
1162 shortcut->clear(); | |
1163 return false; | |
1164 } | |
1165 | |
1096 if (!appended_name.empty()) { | 1166 if (!appended_name.empty()) { |
1097 shortcut->append(L" ("); | 1167 shortcut->append(L" ("); |
1098 shortcut->append(appended_name); | 1168 shortcut->append(appended_name); |
1099 shortcut->append(L")"); | 1169 shortcut->append(L")"); |
1100 } | 1170 } |
1101 shortcut->append(L".lnk"); | 1171 shortcut->append(L".lnk"); |
1102 return true; | 1172 return true; |
1103 } | 1173 } |
1104 | 1174 |
1105 bool ShellUtil::GetDesktopPath(bool system_level, FilePath* path) { | |
1106 wchar_t desktop[MAX_PATH]; | |
1107 int dir = system_level ? CSIDL_COMMON_DESKTOPDIRECTORY : | |
1108 CSIDL_DESKTOPDIRECTORY; | |
1109 if (FAILED(SHGetFolderPath(NULL, dir, NULL, SHGFP_TYPE_CURRENT, desktop))) | |
1110 return false; | |
1111 *path = FilePath(desktop); | |
1112 return true; | |
1113 } | |
1114 | |
1115 bool ShellUtil::GetQuickLaunchPath(bool system_level, FilePath* path) { | |
1116 if (system_level) { | |
1117 wchar_t qlaunch[MAX_PATH]; | |
1118 // We are accessing GetDefaultUserProfileDirectory this way so that we do | |
1119 // not have to declare dependency to Userenv.lib for chrome.exe | |
1120 typedef BOOL (WINAPI *PROFILE_FUNC)(LPWSTR, LPDWORD); | |
1121 HMODULE module = LoadLibrary(L"Userenv.dll"); | |
1122 PROFILE_FUNC p = reinterpret_cast<PROFILE_FUNC>(GetProcAddress(module, | |
1123 "GetDefaultUserProfileDirectoryW")); | |
1124 DWORD size = _countof(qlaunch); | |
1125 if ((p == NULL) || ((p)(qlaunch, &size) != TRUE)) | |
1126 return false; | |
1127 *path = FilePath(qlaunch); | |
1128 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
1129 *path = path->AppendASCII("AppData"); | |
1130 *path = path->AppendASCII("Roaming"); | |
1131 } else { | |
1132 *path = path->AppendASCII("Application Data"); | |
1133 } | |
1134 } else { | |
1135 if (!PathService::Get(base::DIR_APP_DATA, path)) { | |
1136 return false; | |
1137 } | |
1138 } | |
1139 *path = path->AppendASCII("Microsoft"); | |
1140 *path = path->AppendASCII("Internet Explorer"); | |
1141 *path = path->AppendASCII("Quick Launch"); | |
1142 return true; | |
1143 } | |
1144 | |
1145 void ShellUtil::GetRegisteredBrowsers( | 1175 void ShellUtil::GetRegisteredBrowsers( |
1146 BrowserDistribution* dist, | 1176 BrowserDistribution* dist, |
1147 std::map<string16, string16>* browsers) { | 1177 std::map<string16, string16>* browsers) { |
1148 DCHECK(dist); | 1178 DCHECK(dist); |
1149 DCHECK(browsers); | 1179 DCHECK(browsers); |
1150 | 1180 |
1151 const string16 base_key(ShellUtil::kRegStartMenuInternet); | 1181 const string16 base_key(ShellUtil::kRegStartMenuInternet); |
1152 string16 client_path; | 1182 string16 client_path; |
1153 RegKey key; | 1183 RegKey key; |
1154 string16 name; | 1184 string16 name; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 } else if (elevate_if_not_admin && | 1565 } else if (elevate_if_not_admin && |
1536 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1566 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1537 // Elevate to do the whole job | 1567 // Elevate to do the whole job |
1538 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 1568 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
1539 } else { | 1569 } else { |
1540 // Admin rights are required to register capabilities before Windows 8. | 1570 // Admin rights are required to register capabilities before Windows 8. |
1541 return false; | 1571 return false; |
1542 } | 1572 } |
1543 } | 1573 } |
1544 | 1574 |
1545 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, | 1575 bool ShellUtil::RemoveChromeShortcut(ShellUtil::ShortcutLocation location, |
1546 int shell_change, uint32 options) { | 1576 BrowserDistribution* dist, |
1547 // Only SHORTCUT_ALTERNATE is a valid option for this function. | 1577 uint32 options) { |
1548 DCHECK(!options || options == ShellUtil::SHORTCUT_ALTERNATE); | |
1549 | |
1550 string16 shortcut_name; | 1578 string16 shortcut_name; |
1551 bool alternate = (options & ShellUtil::SHORTCUT_ALTERNATE) != 0; | 1579 bool alternate = (options & ShellUtil::SHORTCUT_ALTERNATE) != 0 && |
1552 if (!ShellUtil::GetChromeShortcutName(dist, alternate, L"", | 1580 location == SHORTCUT_DESKTOP; |
1581 if (!ShellUtil::GetChromeShortcutName(location, dist, alternate, string16(), | |
1553 &shortcut_name)) | 1582 &shortcut_name)) |
1554 return false; | 1583 return false; |
1555 | 1584 |
1556 bool ret = true; | 1585 bool ret = true; |
1557 if (shell_change & ShellUtil::CURRENT_USER) { | 1586 |
1558 FilePath shortcut_path; | 1587 // Always delete the user-level shortcut. |
1559 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | 1588 FilePath user_shortcut_path; |
1560 FilePath shortcut = shortcut_path.Append(shortcut_name); | 1589 if (GetShortcutPath(location, false, &user_shortcut_path)) { |
1561 ret = file_util::Delete(shortcut, false); | 1590 user_shortcut_path = user_shortcut_path.Append(shortcut_name); |
1591 ret = file_util::Delete(user_shortcut_path, false); | |
1592 } else { | |
1593 ret = false; | |
1594 } | |
1595 | |
1596 // Delete the system-level shortcut if requested. | |
1597 if (options & ShellUtil::SHORTCUT_SYSTEM_LEVEL) { | |
1598 FilePath system_shortcut_path; | |
1599 if (GetShortcutPath(location, true, &system_shortcut_path)) { | |
1600 system_shortcut_path = system_shortcut_path.Append(shortcut_name); | |
1601 ret = ret && file_util::Delete(system_shortcut_path, false); | |
robertshield
2012/08/22 21:39:07
if ret is already false, the Delete operation is n
| |
1562 } else { | 1602 } else { |
1563 ret = false; | 1603 ret = false; |
1564 } | 1604 } |
1565 } | |
1566 | |
1567 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | |
1568 FilePath shortcut_path; | |
1569 if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { | |
1570 FilePath shortcut = shortcut_path.Append(shortcut_name); | |
1571 ret = file_util::Delete(shortcut, false) && ret; | |
1572 } else { | |
1573 ret = false; | |
1574 } | |
1575 } | 1605 } |
1576 return ret; | 1606 return ret; |
1577 } | 1607 } |
1578 | 1608 |
1579 bool ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( | 1609 bool ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( |
1580 const std::vector<string16>& appended_names) { | 1610 const std::vector<string16>& appended_names) { |
1581 FilePath shortcut_path; | 1611 FilePath shortcut_path; |
1582 bool ret = true; | 1612 bool ret = true; |
1583 if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { | 1613 if (GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, false, &shortcut_path)) { |
1584 for (std::vector<string16>::const_iterator it = | 1614 for (std::vector<string16>::const_iterator it = appended_names.begin(); |
1585 appended_names.begin(); | 1615 it != appended_names.end(); ++it) { |
1586 it != appended_names.end(); | |
1587 ++it) { | |
1588 FilePath delete_shortcut = shortcut_path.Append(*it); | 1616 FilePath delete_shortcut = shortcut_path.Append(*it); |
1589 ret = ret && file_util::Delete(delete_shortcut, false); | 1617 ret = ret && file_util::Delete(delete_shortcut, false); |
1590 } | 1618 } |
1591 } else { | 1619 } else { |
1592 ret = false; | 1620 ret = false; |
1593 } | 1621 } |
1594 return ret; | 1622 return ret; |
1595 } | 1623 } |
1596 | 1624 |
1597 bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, | |
1598 int shell_change) { | |
1599 string16 shortcut_name; | |
1600 if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) | |
1601 return false; | |
1602 | |
1603 bool ret = true; | |
1604 // First remove shortcut for the current user. | |
1605 if (shell_change & ShellUtil::CURRENT_USER) { | |
1606 FilePath user_ql_path; | |
1607 if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { | |
1608 user_ql_path = user_ql_path.Append(shortcut_name); | |
1609 ret = file_util::Delete(user_ql_path, false); | |
1610 } else { | |
1611 ret = false; | |
1612 } | |
1613 } | |
1614 | |
1615 // Delete shortcut in Default User's profile | |
1616 if (shell_change & ShellUtil::SYSTEM_LEVEL) { | |
1617 FilePath default_ql_path; | |
1618 if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { | |
1619 default_ql_path = default_ql_path.Append(shortcut_name); | |
1620 ret = file_util::Delete(default_ql_path, false) && ret; | |
1621 } else { | |
1622 ret = false; | |
1623 } | |
1624 } | |
1625 | |
1626 return ret; | |
1627 } | |
1628 | |
1629 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, | |
1630 const string16& chrome_exe, | |
1631 const string16& shortcut, | |
1632 const string16& arguments, | |
1633 const string16& description, | |
1634 const string16& icon_path, | |
1635 int icon_index, | |
1636 uint32 options) { | |
1637 const FilePath chrome_path(FilePath(chrome_exe).DirName()); | |
1638 | |
1639 installer::MasterPreferences prefs( | |
1640 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); | |
1641 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { | |
1642 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | |
1643 &icon_index); | |
1644 } | |
1645 | |
1646 const string16 app_id(GetBrowserModelId(dist, chrome_exe)); | |
1647 | |
1648 return file_util::CreateOrUpdateShortcutLink( | |
1649 chrome_exe.c_str(), | |
1650 shortcut.c_str(), | |
1651 chrome_path.value().c_str(), | |
1652 arguments.c_str(), | |
1653 description.c_str(), | |
1654 icon_path.c_str(), | |
1655 icon_index, | |
1656 app_id.c_str(), | |
1657 ConvertShellUtilShortcutOptionsToFileUtil(options)); | |
1658 } | |
1659 | |
1660 ShellUtil::VerifyShortcutStatus ShellUtil::VerifyChromeShortcut( | 1625 ShellUtil::VerifyShortcutStatus ShellUtil::VerifyChromeShortcut( |
1661 const string16& exe_path, const string16& shortcut, | 1626 const string16& exe_path, const string16& shortcut, |
1662 const string16& description, int icon_index) { | 1627 const string16& description, int icon_index) { |
1663 base::win::ScopedComPtr<IShellLink> i_shell_link; | 1628 base::win::ScopedComPtr<IShellLink> i_shell_link; |
1664 base::win::ScopedComPtr<IPersistFile> i_persist_file; | 1629 base::win::ScopedComPtr<IPersistFile> i_persist_file; |
1665 wchar_t long_path[MAX_PATH] = {0}; | 1630 wchar_t long_path[MAX_PATH] = {0}; |
1666 wchar_t short_path[MAX_PATH] = {0}; | 1631 wchar_t short_path[MAX_PATH] = {0}; |
1667 wchar_t file_path[MAX_PATH] = {0}; | 1632 wchar_t file_path[MAX_PATH] = {0}; |
1668 wchar_t icon_path[MAX_PATH] = {0}; | 1633 wchar_t icon_path[MAX_PATH] = {0}; |
1669 wchar_t desc[MAX_PATH] = {0}; | 1634 wchar_t desc[MAX_PATH] = {0}; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1756 // are any left...). | 1721 // are any left...). |
1757 if (free_bits >= 8 && next_byte_index < size) { | 1722 if (free_bits >= 8 && next_byte_index < size) { |
1758 free_bits -= 8; | 1723 free_bits -= 8; |
1759 bit_stream += bytes[next_byte_index++] << free_bits; | 1724 bit_stream += bytes[next_byte_index++] << free_bits; |
1760 } | 1725 } |
1761 } | 1726 } |
1762 | 1727 |
1763 DCHECK_EQ(ret.length(), encoded_length); | 1728 DCHECK_EQ(ret.length(), encoded_length); |
1764 return ret; | 1729 return ret; |
1765 } | 1730 } |
OLD | NEW |