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 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 } | 1310 } |
1311 | 1311 |
1312 | 1312 |
1313 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. | 1313 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. |
1314 // Otherwise do nothing. Returns true on success, including the vacuous case | 1314 // Otherwise do nothing. Returns true on success, including the vacuous case |
1315 // where no deletion occurred because directory is non-empty. | 1315 // where no deletion occurred because directory is non-empty. |
1316 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, | 1316 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, |
1317 BrowserDistribution* dist, | 1317 BrowserDistribution* dist, |
1318 ShellUtil::ShellChange level) { | 1318 ShellUtil::ShellChange level) { |
1319 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1319 // Explicitly whitelist locations, since accidental calls can be very harmful. |
1320 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && | 1320 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && |
| 1321 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && |
1321 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1322 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
1322 NOTREACHED(); | 1323 NOTREACHED(); |
1323 return false; | 1324 return false; |
1324 } | 1325 } |
1325 | 1326 |
1326 base::FilePath shortcut_folder; | 1327 base::FilePath shortcut_folder; |
1327 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1328 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
1328 LOG(WARNING) << "Cannot find path at location " << location; | 1329 LOG(WARNING) << "Cannot find path at location " << location; |
1329 return false; | 1330 return false; |
1330 } | 1331 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 1382 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
1382 const string16& chrome_exe, | 1383 const string16& chrome_exe, |
1383 const string16& suffix) { | 1384 const string16& suffix) { |
1384 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1385 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
1385 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1386 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
1386 } | 1387 } |
1387 | 1388 |
1388 bool ShellUtil::ShortcutLocationIsSupported( | 1389 bool ShellUtil::ShortcutLocationIsSupported( |
1389 ShellUtil::ShortcutLocation location) { | 1390 ShellUtil::ShortcutLocation location) { |
1390 switch (location) { | 1391 switch (location) { |
1391 case SHORTCUT_LOCATION_DESKTOP: | 1392 case SHORTCUT_LOCATION_DESKTOP: // Falls through. |
1392 return true; | 1393 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. |
1393 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1394 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. |
1394 return true; | 1395 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. |
1395 case SHORTCUT_LOCATION_START_MENU: | 1396 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
1396 return true; | 1397 return true; |
1397 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1398 case SHORTCUT_LOCATION_TASKBAR_PINS: |
1398 return base::win::GetVersion() >= base::win::VERSION_WIN7; | 1399 return base::win::GetVersion() >= base::win::VERSION_WIN7; |
1399 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1400 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
1400 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 1401 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
1401 default: | 1402 default: |
1402 NOTREACHED(); | 1403 NOTREACHED(); |
1403 return false; | 1404 return false; |
1404 } | 1405 } |
1405 } | 1406 } |
1406 | 1407 |
1407 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, | 1408 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
1408 BrowserDistribution* dist, | 1409 BrowserDistribution* dist, |
1409 ShellChange level, | 1410 ShellChange level, |
1410 base::FilePath* path) { | 1411 base::FilePath* path) { |
1411 DCHECK(path); | 1412 DCHECK(path); |
1412 int dir_key = -1; | 1413 int dir_key = -1; |
1413 bool add_folder_for_dist = false; | 1414 base::string16 folder_to_append; |
1414 switch (location) { | 1415 switch (location) { |
1415 case SHORTCUT_LOCATION_DESKTOP: | 1416 case SHORTCUT_LOCATION_DESKTOP: |
1416 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : | 1417 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
1417 base::DIR_COMMON_DESKTOP; | 1418 base::DIR_COMMON_DESKTOP; |
1418 break; | 1419 break; |
1419 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1420 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
1420 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : | 1421 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : |
1421 base::DIR_DEFAULT_USER_QUICK_LAUNCH; | 1422 base::DIR_DEFAULT_USER_QUICK_LAUNCH; |
1422 break; | 1423 break; |
1423 case SHORTCUT_LOCATION_START_MENU: | 1424 case SHORTCUT_LOCATION_START_MENU_ROOT: |
1424 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1425 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
1425 base::DIR_COMMON_START_MENU; | 1426 base::DIR_COMMON_START_MENU; |
1426 add_folder_for_dist = true; | 1427 break; |
| 1428 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: |
| 1429 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1430 base::DIR_COMMON_START_MENU; |
| 1431 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1432 BrowserDistribution::SUBFOLDER_CHROME); |
| 1433 break; |
| 1434 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1435 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1436 base::DIR_COMMON_START_MENU; |
| 1437 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1438 BrowserDistribution::SUBFOLDER_APPS); |
1427 break; | 1439 break; |
1428 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1440 case SHORTCUT_LOCATION_TASKBAR_PINS: |
1429 dir_key = base::DIR_TASKBAR_PINS; | 1441 dir_key = base::DIR_TASKBAR_PINS; |
1430 break; | 1442 break; |
1431 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1443 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
1432 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. | 1444 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. |
1433 return GetAppShortcutsFolder(dist, level, path); | 1445 return GetAppShortcutsFolder(dist, level, path); |
1434 | 1446 |
1435 default: | 1447 default: |
1436 NOTREACHED(); | 1448 NOTREACHED(); |
1437 return false; | 1449 return false; |
1438 } | 1450 } |
1439 | 1451 |
1440 if (!PathService::Get(dir_key, path) || path->empty()) { | 1452 if (!PathService::Get(dir_key, path) || path->empty()) { |
1441 NOTREACHED() << dir_key; | 1453 NOTREACHED() << dir_key; |
1442 return false; | 1454 return false; |
1443 } | 1455 } |
1444 | 1456 |
1445 if (add_folder_for_dist) { | 1457 if (!folder_to_append.empty()) |
1446 *path = path->Append(dist->GetStartMenuShortcutSubfolder( | 1458 *path = path->Append(folder_to_append); |
1447 BrowserDistribution::SUBFOLDER_CHROME)); | |
1448 } | |
1449 | 1459 |
1450 return true; | 1460 return true; |
1451 } | 1461 } |
1452 | 1462 |
1453 bool ShellUtil::CreateOrUpdateShortcut( | 1463 bool ShellUtil::CreateOrUpdateShortcut( |
1454 ShellUtil::ShortcutLocation location, | 1464 ShellUtil::ShortcutLocation location, |
1455 BrowserDistribution* dist, | 1465 BrowserDistribution* dist, |
1456 const ShellUtil::ShortcutProperties& properties, | 1466 const ShellUtil::ShortcutProperties& properties, |
1457 ShellUtil::ShortcutOperation operation) { | 1467 ShellUtil::ShortcutOperation operation) { |
1458 // Explicitly whitelist locations to which this is applicable. | 1468 // Explicitly whitelist locations to which this is applicable. |
1459 if (location != SHORTCUT_LOCATION_DESKTOP && | 1469 if (location != SHORTCUT_LOCATION_DESKTOP && |
1460 location != SHORTCUT_LOCATION_QUICK_LAUNCH && | 1470 location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
1461 location != SHORTCUT_LOCATION_START_MENU) { | 1471 location != SHORTCUT_LOCATION_START_MENU_ROOT && |
| 1472 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && |
| 1473 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { |
1462 NOTREACHED(); | 1474 NOTREACHED(); |
1463 return false; | 1475 return false; |
1464 } | 1476 } |
1465 | 1477 |
1466 DCHECK(dist); | 1478 DCHECK(dist); |
1467 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1479 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
1468 DCHECK(!properties.pin_to_taskbar || | 1480 DCHECK(!properties.pin_to_taskbar || |
1469 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1481 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
1470 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1482 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
1471 | 1483 |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 | 2055 |
2044 FilterTargetEq shortcut_filter(target_exe, false); | 2056 FilterTargetEq shortcut_filter(target_exe, false); |
2045 // Main operation to apply to each shortcut in the directory specified. | 2057 // Main operation to apply to each shortcut in the directory specified. |
2046 ShortcutOperationCallback shortcut_operation( | 2058 ShortcutOperationCallback shortcut_operation( |
2047 location == SHORTCUT_LOCATION_TASKBAR_PINS ? | 2059 location == SHORTCUT_LOCATION_TASKBAR_PINS ? |
2048 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete)); | 2060 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete)); |
2049 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2061 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
2050 shortcut_operation, location, dist, level); | 2062 shortcut_operation, location, dist, level); |
2051 // Remove chrome-specific shortcut folders if they are now empty. | 2063 // Remove chrome-specific shortcut folders if they are now empty. |
2052 if (success && | 2064 if (success && |
2053 (location == SHORTCUT_LOCATION_START_MENU || | 2065 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || |
| 2066 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || |
2054 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { | 2067 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { |
2055 success = RemoveShortcutFolderIfEmpty(location, dist, level); | 2068 success = RemoveShortcutFolderIfEmpty(location, dist, level); |
2056 } | 2069 } |
2057 return success; | 2070 return success; |
2058 } | 2071 } |
2059 | 2072 |
2060 // static | 2073 // static |
2061 bool ShellUtil::UpdateShortcutsWithArgs( | 2074 bool ShellUtil::UpdateShortcutsWithArgs( |
2062 ShellUtil::ShortcutLocation location, | 2075 ShellUtil::ShortcutLocation location, |
2063 BrowserDistribution* dist, | 2076 BrowserDistribution* dist, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 // are any left...). | 2147 // are any left...). |
2135 if (free_bits >= 8 && next_byte_index < size) { | 2148 if (free_bits >= 8 && next_byte_index < size) { |
2136 free_bits -= 8; | 2149 free_bits -= 8; |
2137 bit_stream += bytes[next_byte_index++] << free_bits; | 2150 bit_stream += bytes[next_byte_index++] << free_bits; |
2138 } | 2151 } |
2139 } | 2152 } |
2140 | 2153 |
2141 DCHECK_EQ(ret.length(), encoded_length); | 2154 DCHECK_EQ(ret.length(), encoded_length); |
2142 return ret; | 2155 return ret; |
2143 } | 2156 } |
OLD | NEW |