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