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" |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <shlobj.h> | 13 #include <shlobj.h> |
14 | 14 |
15 #include <limits> | 15 #include <limits> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/bind.h" | |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
21 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
22 #include "base/logging.h" | 23 #include "base/logging.h" |
23 #include "base/md5.h" | 24 #include "base/md5.h" |
24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
25 #include "base/memory/scoped_vector.h" | 26 #include "base/memory/scoped_vector.h" |
26 #include "base/path_service.h" | 27 #include "base/path_service.h" |
27 #include "base/string16.h" | 28 #include "base/string16.h" |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 const base::win::Version windows_version = base::win::GetVersion(); | 1153 const base::win::Version windows_version = base::win::GetVersion(); |
1153 | 1154 |
1154 if (windows_version >= base::win::VERSION_WIN8) | 1155 if (windows_version >= base::win::VERSION_WIN8) |
1155 return ProbeCurrentDefaultHandlers(protocols, num_protocols); | 1156 return ProbeCurrentDefaultHandlers(protocols, num_protocols); |
1156 else if (windows_version >= base::win::VERSION_VISTA) | 1157 else if (windows_version >= base::win::VERSION_VISTA) |
1157 return ProbeAppIsDefaultHandlers(protocols, num_protocols); | 1158 return ProbeAppIsDefaultHandlers(protocols, num_protocols); |
1158 | 1159 |
1159 return ProbeOpenCommandHandlers(protocols, num_protocols); | 1160 return ProbeOpenCommandHandlers(protocols, num_protocols); |
1160 } | 1161 } |
1161 | 1162 |
1162 // Removes shortcut at |shortcut_path| if it is a shortcut that points to | 1163 // (Windows 8+) Finds and stores an app shortcuts folder path in *|path|. |
1163 // |target_exe|. If |delete_folder| is true, deletes the parent folder of | 1164 // Returns true on success. |
1164 // the shortcut completely. Returns true if either the shortcut was deleted | 1165 bool GetAppShortcutsFolder(BrowserDistribution* dist, |
1165 // successfully or if the shortcut did not point to |target_exe|. | 1166 ShellUtil::ShellChange level, |
1166 bool MaybeRemoveShortcutAtPath(const base::FilePath& shortcut_path, | 1167 base::FilePath *path) { |
1167 const base::FilePath& target_exe, | 1168 DCHECK(path); |
1168 bool delete_folder) { | 1169 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN8); |
grt (UTC plus 2)
2013/05/01 16:33:43
DCHECK_GE
huangs
2013/05/01 17:42:09
Done.
| |
1169 base::FilePath target_path; | 1170 |
1170 if (!base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) | 1171 base::FilePath folder; |
1172 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &folder)) { | |
1173 LOG(ERROR) << "Could not get application shortcuts location."; | |
1171 return false; | 1174 return false; |
1172 | |
1173 if (InstallUtil::ProgramCompare(target_exe).EvaluatePath(target_path)) { | |
1174 // Unpin the shortcut if it was ever pinned by the user or the installer. | |
1175 VLOG(1) << "Trying to unpin " << shortcut_path.value(); | |
1176 if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) { | |
1177 VLOG(1) << shortcut_path.value() | |
1178 << " wasn't pinned (or the unpin failed)."; | |
1179 } | |
1180 if (delete_folder) | |
1181 return file_util::Delete(shortcut_path.DirName(), true); | |
1182 else | |
1183 return file_util::Delete(shortcut_path, false); | |
1184 } | 1175 } |
1185 | 1176 |
1186 // The shortcut at |shortcut_path| doesn't point to |target_exe|, act as if | 1177 folder = folder.Append( |
1187 // our shortcut had been deleted. | 1178 ShellUtil::GetBrowserModelId(dist, level == ShellUtil::CURRENT_USER)); |
1179 if (!file_util::DirectoryExists(folder)) { | |
1180 VLOG(1) << "No start screen shortcuts."; | |
1181 return false; | |
1182 } | |
1183 | |
1184 *path = folder; | |
1188 return true; | 1185 return true; |
1189 } | 1186 } |
1190 | 1187 |
1188 typedef base::Callback<bool(const base::FilePath&)> FileOperationCallback; | |
1189 | |
1190 // Shortcut operations for BatchShortcutAction(). | |
1191 | |
1192 bool ShortcutOpUnpin(const base::FilePath& shortcut_path) { | |
1193 VLOG(1) << "Trying to unpin " << shortcut_path.value(); | |
1194 if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) { | |
1195 VLOG(1) << shortcut_path.value() << " wasn't pinned (or the unpin failed)."; | |
1196 // No error, since shortcut might not be pinned. | |
1197 } | |
1198 return true; | |
1199 } | |
1200 | |
1201 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { | |
1202 bool ret = file_util::Delete(shortcut_path, false); | |
1203 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); | |
1204 return ret; | |
1205 } | |
1206 | |
1207 bool ShortcutOpSetTarget(const base::FilePath& target_path, | |
1208 const base::FilePath& shortcut_path) { | |
1209 base::win::ShortcutProperties shortcut_properties; | |
1210 shortcut_properties.set_target(target_path); | |
1211 shortcut_properties.set_working_dir(target_path.DirName()); | |
1212 bool ret = base::win::CreateOrUpdateShortcutLink( | |
1213 shortcut_path, shortcut_properties, base::win::SHORTCUT_REPLACE_EXISTING); | |
1214 LOG_IF(ERROR, !ret) << "Failed to retarget " << shortcut_path.value(); | |
1215 return ret; | |
1216 } | |
1217 | |
1218 // {|location|, |dist|, |level|} determine |shortcut_folder|. | |
1219 // Applies |shortcut_operation| to each shortcut in |shortcut_folder| that | |
1220 // targets |target_exe|. | |
1221 // Returns true if all operations are successful. All intended operations are | |
1222 // attempted even if failures occur. | |
1223 bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, | |
1224 ShellUtil::ShortcutLocation location, | |
1225 BrowserDistribution* dist, | |
1226 ShellUtil::ShellChange level, | |
1227 const base::FilePath& target_exe) { | |
1228 DCHECK(!shortcut_operation.is_null()); | |
1229 base::FilePath shortcut_folder; | |
1230 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | |
1231 LOG(WARNING) << "Cannot find path at location " << location; | |
1232 return false; | |
1233 } | |
1234 | |
1235 bool success = true; | |
1236 InstallUtil::ProgramCompare target_compare(target_exe); | |
1237 file_util::FileEnumerator enumerator( | |
1238 shortcut_folder, false, file_util::FileEnumerator::FILES, | |
1239 string16(L"*") + installer::kLnkExt); | |
1240 base::FilePath target_path; | |
1241 for (base::FilePath shortcut_path = enumerator.Next(); | |
1242 !shortcut_path.empty(); | |
1243 shortcut_path = enumerator.Next()) { | |
1244 if (base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) { | |
1245 if (target_compare.EvaluatePath(target_path) && | |
1246 !shortcut_operation.Run(shortcut_path)) { | |
1247 success = false; | |
1248 } | |
1249 } else { | |
1250 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); | |
1251 success = false; | |
1252 } | |
1253 } | |
1254 return success; | |
1255 } | |
1256 | |
1257 // Removes folder spsecified by {|location|, |dist|, |level|}. | |
1258 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, | |
grt (UTC plus 2)
2013/05/01 16:33:43
please explicitly whitelist the |location| values
huangs
2013/05/01 17:42:09
Done.
| |
1259 BrowserDistribution* dist, | |
1260 ShellUtil::ShellChange level) { | |
1261 base::FilePath shortcut_folder; | |
1262 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | |
1263 LOG(WARNING) << "Cannot find path at location " << location; | |
1264 return false; | |
1265 } | |
1266 if (!file_util::Delete(shortcut_folder, true)) { | |
1267 LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value(); | |
1268 return false; | |
1269 } | |
1270 return true; | |
1271 } | |
1272 | |
1191 } // namespace | 1273 } // namespace |
1192 | 1274 |
1193 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 1275 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
1194 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 1276 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
1195 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 1277 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
1196 const wchar_t* ShellUtil::kRegStartMenuInternet = | 1278 const wchar_t* ShellUtil::kRegStartMenuInternet = |
1197 L"Software\\Clients\\StartMenuInternet"; | 1279 L"Software\\Clients\\StartMenuInternet"; |
1198 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 1280 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
1199 const wchar_t* ShellUtil::kRegRegisteredApplications = | 1281 const wchar_t* ShellUtil::kRegRegisteredApplications = |
1200 L"Software\\RegisteredApplications"; | 1282 L"Software\\RegisteredApplications"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 1325 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
1244 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; | 1326 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; |
1245 | 1327 |
1246 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 1328 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
1247 const string16& chrome_exe, | 1329 const string16& chrome_exe, |
1248 const string16& suffix) { | 1330 const string16& suffix) { |
1249 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1331 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
1250 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1332 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
1251 } | 1333 } |
1252 | 1334 |
1335 bool ShellUtil::ShortcutLocationIsExpected( | |
grt (UTC plus 2)
2013/05/01 16:33:43
Expected -> Supported
huangs
2013/05/01 17:42:09
Done.
| |
1336 ShellUtil::ShortcutLocation location) { | |
1337 switch (location) { | |
1338 case SHORTCUT_LOCATION_DESKTOP: | |
1339 return true; | |
1340 case SHORTCUT_LOCATION_QUICK_LAUNCH: | |
1341 return true; | |
1342 case SHORTCUT_LOCATION_START_MENU: | |
1343 return base::win::GetVersion() < base::win::VERSION_WIN8; | |
grt (UTC plus 2)
2013/05/01 16:33:43
why?
huangs
2013/05/01 17:42:09
I thought Windows 8 does not have a Start Menu? Un
gab
2013/05/01 18:34:42
The Windows 8 start screen replaces the start menu
huangs
2013/05/01 19:22:22
Ah, good to know. Fortunately I removed, so no ext
| |
1344 case SHORTCUT_LOCATION_TASKBAR_PINS: | |
1345 return base::win::GetVersion() >= base::win::VERSION_WIN7; | |
1346 case SHORTCUT_LOCATION_APP_SHORTCUTS: | |
1347 return base::win::GetVersion() >= base::win::VERSION_WIN8; | |
1348 default: | |
1349 NOTREACHED(); | |
1350 return false; | |
1351 } | |
1352 } | |
1353 | |
1253 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, | 1354 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
1254 BrowserDistribution* dist, | 1355 BrowserDistribution* dist, |
1255 ShellChange level, | 1356 ShellChange level, |
1256 base::FilePath* path) { | 1357 base::FilePath* path) { |
1358 DCHECK(path); | |
1257 int dir_key = -1; | 1359 int dir_key = -1; |
1258 bool add_folder_for_dist = false; | 1360 bool add_folder_for_dist = false; |
1259 switch (location) { | 1361 switch (location) { |
1260 case SHORTCUT_LOCATION_DESKTOP: | 1362 case SHORTCUT_LOCATION_DESKTOP: |
1261 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : | 1363 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
1262 base::DIR_COMMON_DESKTOP; | 1364 base::DIR_COMMON_DESKTOP; |
1263 break; | 1365 break; |
1264 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1366 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
1265 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : | 1367 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : |
1266 base::DIR_DEFAULT_USER_QUICK_LAUNCH; | 1368 base::DIR_DEFAULT_USER_QUICK_LAUNCH; |
1267 break; | 1369 break; |
1268 case SHORTCUT_LOCATION_START_MENU: | 1370 case SHORTCUT_LOCATION_START_MENU: |
1269 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1371 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
1270 base::DIR_COMMON_START_MENU; | 1372 base::DIR_COMMON_START_MENU; |
1271 add_folder_for_dist = true; | 1373 add_folder_for_dist = true; |
1272 break; | 1374 break; |
1375 case SHORTCUT_LOCATION_TASKBAR_PINS: | |
1376 dir_key = base::DIR_TASKBAR_PINS; | |
1377 break; | |
1378 case SHORTCUT_LOCATION_APP_SHORTCUTS: | |
1379 return GetAppShortcutsFolder(dist, level, path); | |
1380 | |
1273 default: | 1381 default: |
1274 NOTREACHED(); | 1382 NOTREACHED(); |
1275 return false; | 1383 return false; |
1276 } | 1384 } |
1277 | 1385 |
1278 if (!PathService::Get(dir_key, path) || path->empty()) { | 1386 if (!PathService::Get(dir_key, path) || path->empty()) { |
1279 NOTREACHED() << dir_key; | 1387 NOTREACHED() << dir_key; |
1280 return false; | 1388 return false; |
1281 } | 1389 } |
1282 | 1390 |
1283 if (add_folder_for_dist) | 1391 if (add_folder_for_dist) |
1284 *path = path->Append(dist->GetAppShortCutName()); | 1392 *path = path->Append(dist->GetAppShortCutName()); |
1285 | 1393 |
1286 return true; | 1394 return true; |
1287 } | 1395 } |
1288 | 1396 |
1289 bool ShellUtil::CreateOrUpdateShortcut( | 1397 bool ShellUtil::CreateOrUpdateShortcut( |
1290 ShellUtil::ShortcutLocation location, | 1398 ShellUtil::ShortcutLocation location, |
grt (UTC plus 2)
2013/05/01 16:33:43
what does it mean to call this function with locat
huangs
2013/05/01 17:42:09
Oops, I was going to abandon the call to ShortcutL
| |
1291 BrowserDistribution* dist, | 1399 BrowserDistribution* dist, |
1292 const ShellUtil::ShortcutProperties& properties, | 1400 const ShellUtil::ShortcutProperties& properties, |
1293 ShellUtil::ShortcutOperation operation) { | 1401 ShellUtil::ShortcutOperation operation) { |
1402 if (!ShortcutLocationIsExpected(location)) | |
1403 return false; | |
1404 | |
1294 DCHECK(dist); | 1405 DCHECK(dist); |
1295 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1406 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
1296 DCHECK(!properties.pin_to_taskbar || | 1407 DCHECK(!properties.pin_to_taskbar || |
1297 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1408 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
1298 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1409 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
1299 | 1410 |
1300 base::FilePath user_shortcut_path; | 1411 base::FilePath user_shortcut_path; |
1301 base::FilePath system_shortcut_path; | 1412 base::FilePath system_shortcut_path; |
1302 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path) || | 1413 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path)) |
1303 system_shortcut_path.empty()) { | |
1304 NOTREACHED(); | |
1305 return false; | 1414 return false; |
1306 } | |
1307 | 1415 |
1308 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); | 1416 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); |
1309 system_shortcut_path = system_shortcut_path.Append(shortcut_name); | 1417 system_shortcut_path = system_shortcut_path.Append(shortcut_name); |
1310 | 1418 |
1311 base::FilePath* chosen_path; | 1419 base::FilePath* chosen_path; |
1312 bool should_install_shortcut = true; | 1420 bool should_install_shortcut = true; |
1313 if (properties.level == SYSTEM_LEVEL) { | 1421 if (properties.level == SYSTEM_LEVEL) { |
1314 // Install the system-level shortcut if requested. | 1422 // Install the system-level shortcut if requested. |
1315 chosen_path = &system_shortcut_path; | 1423 chosen_path = &system_shortcut_path; |
1316 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || | 1424 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || |
1317 !file_util::PathExists(system_shortcut_path)) { | 1425 !file_util::PathExists(system_shortcut_path)) { |
1318 // Otherwise install the user-level shortcut, unless the system-level | 1426 // Otherwise install the user-level shortcut, unless the system-level |
1319 // variant of this shortcut is present on the machine and |operation| states | 1427 // variant of this shortcut is present on the machine and |operation| states |
1320 // not to create a user-level shortcut in that case. | 1428 // not to create a user-level shortcut in that case. |
1321 if (!GetShortcutPath(location, dist, CURRENT_USER, &user_shortcut_path) || | 1429 if (!GetShortcutPath(location, dist, CURRENT_USER, &user_shortcut_path)) { |
1322 user_shortcut_path.empty()) { | |
1323 NOTREACHED(); | 1430 NOTREACHED(); |
1324 return false; | 1431 return false; |
1325 } | 1432 } |
1326 user_shortcut_path = user_shortcut_path.Append(shortcut_name); | 1433 user_shortcut_path = user_shortcut_path.Append(shortcut_name); |
1327 chosen_path = &user_shortcut_path; | 1434 chosen_path = &user_shortcut_path; |
1328 } else { | 1435 } else { |
1329 // Do not install any shortcut if we are told to install a user-level | 1436 // Do not install any shortcut if we are told to install a user-level |
1330 // shortcut, but the system-level variant of that shortcut is present. | 1437 // shortcut, but the system-level variant of that shortcut is present. |
1331 // Other actions (e.g., pinning) can still happen with respect to the | 1438 // Other actions (e.g., pinning) can still happen with respect to the |
1332 // existing system-level shortcut however. | 1439 // existing system-level shortcut however. |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1851 } else if (elevate_if_not_admin && | 1958 } else if (elevate_if_not_admin && |
1852 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1959 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1853 // Elevate to do the whole job | 1960 // Elevate to do the whole job |
1854 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 1961 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
1855 } else { | 1962 } else { |
1856 // Admin rights are required to register capabilities before Windows 8. | 1963 // Admin rights are required to register capabilities before Windows 8. |
1857 return false; | 1964 return false; |
1858 } | 1965 } |
1859 } | 1966 } |
1860 | 1967 |
1861 bool ShellUtil::RemoveShortcut(ShellUtil::ShortcutLocation location, | 1968 // static |
1862 BrowserDistribution* dist, | 1969 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
1863 const base::FilePath& target_exe, | 1970 BrowserDistribution* dist, |
1864 ShellChange level, | 1971 ShellChange level, |
1865 const string16* shortcut_name) { | 1972 const base::FilePath& target_exe) { |
1866 const bool delete_folder = (location == SHORTCUT_LOCATION_START_MENU); | 1973 if (!ShellUtil::ShortcutLocationIsExpected(location)) |
1974 return true; // Vacuous success. | |
1867 | 1975 |
1868 base::FilePath shortcut_folder; | 1976 switch (location) { |
1869 if (!GetShortcutPath(location, dist, level, &shortcut_folder) || | 1977 case SHORTCUT_LOCATION_START_MENU: // Falls through. |
1870 shortcut_folder.empty()) { | 1978 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
1871 NOTREACHED(); | 1979 return RemoveShortcutFolder(location, dist, level); |
1872 return false; | |
1873 } | |
1874 | 1980 |
1875 if (!delete_folder && !shortcut_name) { | 1981 case SHORTCUT_LOCATION_TASKBAR_PINS: |
1876 file_util::FileEnumerator enumerator(shortcut_folder, false, | 1982 return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, |
1877 file_util::FileEnumerator::FILES); | 1983 level, target_exe); |
1878 bool had_failures = false; | |
1879 for (base::FilePath path = enumerator.Next(); !path.empty(); | |
1880 path = enumerator.Next()) { | |
1881 if (path.Extension() != installer::kLnkExt) | |
1882 continue; | |
1883 | 1984 |
1884 if (!MaybeRemoveShortcutAtPath(path, target_exe, delete_folder)) | 1985 default: |
1885 had_failures = true; | 1986 return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, |
1886 } | 1987 level, target_exe); |
1887 return !had_failures; | |
1888 } | |
1889 | |
1890 const string16 shortcut_base_name( | |
1891 (shortcut_name ? *shortcut_name : dist->GetAppShortCutName()) + | |
1892 installer::kLnkExt); | |
1893 const base::FilePath shortcut_path( | |
1894 shortcut_folder.Append(shortcut_base_name)); | |
1895 if (!file_util::PathExists(shortcut_path)) | |
1896 return true; | |
1897 | |
1898 return MaybeRemoveShortcutAtPath(shortcut_path, target_exe, delete_folder); | |
1899 } | |
1900 | |
1901 void ShellUtil::RemoveTaskbarShortcuts(const string16& target_exe) { | |
1902 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
1903 return; | |
1904 | |
1905 base::FilePath taskbar_pins_path; | |
1906 if (!PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_path) || | |
1907 !file_util::PathExists(taskbar_pins_path)) { | |
1908 LOG(ERROR) << "Couldn't find path to taskbar pins."; | |
1909 return; | |
1910 } | |
1911 | |
1912 file_util::FileEnumerator shortcuts_enum( | |
1913 taskbar_pins_path, false, | |
1914 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | |
1915 | |
1916 base::FilePath target_path(target_exe); | |
1917 InstallUtil::ProgramCompare target_compare(target_path); | |
1918 for (base::FilePath shortcut_path = shortcuts_enum.Next(); | |
1919 !shortcut_path.empty(); | |
1920 shortcut_path = shortcuts_enum.Next()) { | |
1921 base::FilePath read_target; | |
1922 if (!base::win::ResolveShortcut(shortcut_path, &read_target, NULL)) { | |
1923 LOG(ERROR) << "Couldn't resolve shortcut at " << shortcut_path.value(); | |
1924 continue; | |
1925 } | |
1926 if (target_compare.EvaluatePath(read_target)) { | |
1927 // Unpin this shortcut if it points to |target_exe|. | |
1928 base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str()); | |
1929 } | |
1930 } | 1988 } |
1931 } | 1989 } |
1932 | 1990 |
1933 void ShellUtil::RemoveStartScreenShortcuts(BrowserDistribution* dist, | 1991 // static |
1934 const string16& target_exe) { | 1992 bool ShellUtil::RetargetShortcuts(ShellUtil::ShortcutLocation location, |
1935 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 1993 BrowserDistribution* dist, |
1936 return; | 1994 ShellChange level, |
1995 const base::FilePath& old_target_exe, | |
1996 const base::FilePath& new_target_exe) { | |
1997 if (!ShellUtil::ShortcutLocationIsExpected(location)) | |
1998 return true; // Vacuous success. | |
1937 | 1999 |
1938 base::FilePath app_shortcuts_path; | 2000 return BatchShortcutAction(base::Bind(&ShortcutOpSetTarget, new_target_exe), |
1939 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &app_shortcuts_path)) { | 2001 location, dist, level, old_target_exe); |
1940 LOG(ERROR) << "Could not get application shortcuts location to delete" | |
1941 << " start screen shortcuts."; | |
1942 return; | |
1943 } | |
1944 | |
1945 app_shortcuts_path = app_shortcuts_path.Append( | |
1946 GetBrowserModelId(dist, | |
1947 InstallUtil::IsPerUserInstall(target_exe.c_str()))); | |
1948 if (!file_util::DirectoryExists(app_shortcuts_path)) { | |
1949 VLOG(1) << "No start screen shortcuts to delete."; | |
1950 return; | |
1951 } | |
1952 | |
1953 VLOG(1) << "Removing start screen shortcuts from " | |
1954 << app_shortcuts_path.value(); | |
1955 if (!file_util::Delete(app_shortcuts_path, true)) { | |
1956 LOG(ERROR) << "Failed to remove start screen shortcuts from " | |
1957 << app_shortcuts_path.value(); | |
1958 } | |
1959 } | 2002 } |
1960 | 2003 |
1961 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 2004 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
1962 // Use a thread-safe cache for the user's suffix. | 2005 // Use a thread-safe cache for the user's suffix. |
1963 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 2006 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
1964 LAZY_INSTANCE_INITIALIZER; | 2007 LAZY_INSTANCE_INITIALIZER; |
1965 return suffix_instance.Get().GetSuffix(suffix); | 2008 return suffix_instance.Get().GetSuffix(suffix); |
1966 } | 2009 } |
1967 | 2010 |
1968 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 2011 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2018 // are any left...). | 2061 // are any left...). |
2019 if (free_bits >= 8 && next_byte_index < size) { | 2062 if (free_bits >= 8 && next_byte_index < size) { |
2020 free_bits -= 8; | 2063 free_bits -= 8; |
2021 bit_stream += bytes[next_byte_index++] << free_bits; | 2064 bit_stream += bytes[next_byte_index++] << free_bits; |
2022 } | 2065 } |
2023 } | 2066 } |
2024 | 2067 |
2025 DCHECK_EQ(ret.length(), encoded_length); | 2068 DCHECK_EQ(ret.length(), encoded_length); |
2026 return ret; | 2069 return ret; |
2027 } | 2070 } |
OLD | NEW |