Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 13864015: Move app launcher and chrome apps shortcut strings into the installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_app_id_fix
Patch Set: rework Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 } 1300 }
1301 1301
1302 1302
1303 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. 1303 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it.
1304 // Otherwise do nothing. Returns true on success, including the vacuous case 1304 // Otherwise do nothing. Returns true on success, including the vacuous case
1305 // where no deletion occurred because directory is non-empty. 1305 // where no deletion occurred because directory is non-empty.
1306 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, 1306 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
1307 BrowserDistribution* dist, 1307 BrowserDistribution* dist,
1308 ShellUtil::ShellChange level) { 1308 ShellUtil::ShellChange level) {
1309 // Explicitly whitelist locations, since accidental calls can be very harmful. 1309 // Explicitly whitelist locations, since accidental calls can be very harmful.
1310 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && 1310 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
1311 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR &&
1311 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { 1312 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) {
1312 NOTREACHED(); 1313 NOTREACHED();
1313 return false; 1314 return false;
1314 } 1315 }
1315 1316
1316 base::FilePath shortcut_folder; 1317 base::FilePath shortcut_folder;
1317 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { 1318 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) {
1318 LOG(WARNING) << "Cannot find path at location " << location; 1319 LOG(WARNING) << "Cannot find path at location " << location;
1319 return false; 1320 return false;
1320 } 1321 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 return QuickIsChromeRegistered(dist, chrome_exe, suffix, 1390 return QuickIsChromeRegistered(dist, chrome_exe, suffix,
1390 CONFIRM_SHELL_REGISTRATION_IN_HKLM); 1391 CONFIRM_SHELL_REGISTRATION_IN_HKLM);
1391 } 1392 }
1392 1393
1393 bool ShellUtil::ShortcutLocationIsSupported( 1394 bool ShellUtil::ShortcutLocationIsSupported(
1394 ShellUtil::ShortcutLocation location) { 1395 ShellUtil::ShortcutLocation location) {
1395 switch (location) { 1396 switch (location) {
1396 case SHORTCUT_LOCATION_DESKTOP: 1397 case SHORTCUT_LOCATION_DESKTOP:
1397 return true; 1398 return true;
1398 case SHORTCUT_LOCATION_QUICK_LAUNCH: 1399 case SHORTCUT_LOCATION_QUICK_LAUNCH:
1399 return true; 1400 return true;
gab 2013/08/28 19:52:27 Also collapse above two cases into the same case.
1400 case SHORTCUT_LOCATION_START_MENU: 1401 case SHORTCUT_LOCATION_START_MENU_ROOT:
gab 2013/08/28 19:52:27 Add explicit comment after falling through case st
calamity 2013/10/02 01:08:05 Done.
1402 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
1403 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1401 return true; 1404 return true;
1402 case SHORTCUT_LOCATION_TASKBAR_PINS: 1405 case SHORTCUT_LOCATION_TASKBAR_PINS:
1403 return base::win::GetVersion() >= base::win::VERSION_WIN7; 1406 return base::win::GetVersion() >= base::win::VERSION_WIN7;
1404 case SHORTCUT_LOCATION_APP_SHORTCUTS: 1407 case SHORTCUT_LOCATION_APP_SHORTCUTS:
1405 return base::win::GetVersion() >= base::win::VERSION_WIN8; 1408 return base::win::GetVersion() >= base::win::VERSION_WIN8;
1406 default: 1409 default:
1407 NOTREACHED(); 1410 NOTREACHED();
1408 return false; 1411 return false;
1409 } 1412 }
1410 } 1413 }
1411 1414
1412 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, 1415 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location,
1413 BrowserDistribution* dist, 1416 BrowserDistribution* dist,
1414 ShellChange level, 1417 ShellChange level,
1415 base::FilePath* path) { 1418 base::FilePath* path) {
1416 DCHECK(path); 1419 DCHECK(path);
1417 int dir_key = -1; 1420 int dir_key = -1;
1418 bool add_folder_for_dist = false; 1421 base::string16 folder_to_append;
1419 switch (location) { 1422 switch (location) {
1420 case SHORTCUT_LOCATION_DESKTOP: 1423 case SHORTCUT_LOCATION_DESKTOP:
1421 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : 1424 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP :
1422 base::DIR_COMMON_DESKTOP; 1425 base::DIR_COMMON_DESKTOP;
1423 break; 1426 break;
1424 case SHORTCUT_LOCATION_QUICK_LAUNCH: 1427 case SHORTCUT_LOCATION_QUICK_LAUNCH:
1425 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : 1428 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH :
1426 base::DIR_DEFAULT_USER_QUICK_LAUNCH; 1429 base::DIR_DEFAULT_USER_QUICK_LAUNCH;
1427 break; 1430 break;
1428 case SHORTCUT_LOCATION_START_MENU: 1431 case SHORTCUT_LOCATION_START_MENU_ROOT:
1429 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : 1432 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1430 base::DIR_COMMON_START_MENU; 1433 base::DIR_COMMON_START_MENU;
1431 add_folder_for_dist = true; 1434 break;
1435 case SHORTCUT_LOCATION_START_MENU_CHROME_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_CHROME);
1440 break;
1441 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1442 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1443 base::DIR_COMMON_START_MENU;
1444 folder_to_append = dist->GetStartMenuShortcutSubfolder(
1445 BrowserDistribution::SUBFOLDER_APPS);
1432 break; 1446 break;
1433 case SHORTCUT_LOCATION_TASKBAR_PINS: 1447 case SHORTCUT_LOCATION_TASKBAR_PINS:
1434 dir_key = base::DIR_TASKBAR_PINS; 1448 dir_key = base::DIR_TASKBAR_PINS;
1435 break; 1449 break;
1436 case SHORTCUT_LOCATION_APP_SHORTCUTS: 1450 case SHORTCUT_LOCATION_APP_SHORTCUTS:
1437 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. 1451 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win.
1438 return GetAppShortcutsFolder(dist, level, path); 1452 return GetAppShortcutsFolder(dist, level, path);
1439 1453
1440 default: 1454 default:
1441 NOTREACHED(); 1455 NOTREACHED();
1442 return false; 1456 return false;
1443 } 1457 }
1444 1458
1445 if (!PathService::Get(dir_key, path) || path->empty()) { 1459 if (!PathService::Get(dir_key, path) || path->empty()) {
1446 NOTREACHED() << dir_key; 1460 NOTREACHED() << dir_key;
1447 return false; 1461 return false;
1448 } 1462 }
1449 1463
1450 if (add_folder_for_dist) { 1464 if (!folder_to_append.empty())
1451 *path = path->Append(dist->GetStartMenuShortcutSubfolder( 1465 *path = path->Append(folder_to_append);
1452 BrowserDistribution::SUBFOLDER_CHROME));
1453 }
1454 1466
1455 return true; 1467 return true;
1456 } 1468 }
1457 1469
1458 bool ShellUtil::CreateOrUpdateShortcut( 1470 bool ShellUtil::CreateOrUpdateShortcut(
1459 ShellUtil::ShortcutLocation location, 1471 ShellUtil::ShortcutLocation location,
1460 BrowserDistribution* dist, 1472 BrowserDistribution* dist,
1461 const ShellUtil::ShortcutProperties& properties, 1473 const ShellUtil::ShortcutProperties& properties,
1462 ShellUtil::ShortcutOperation operation) { 1474 ShellUtil::ShortcutOperation operation) {
1463 // Explicitly whitelist locations to which this is applicable. 1475 // Explicitly whitelist locations to which this is applicable.
1464 if (location != SHORTCUT_LOCATION_DESKTOP && 1476 if (location != SHORTCUT_LOCATION_DESKTOP &&
1465 location != SHORTCUT_LOCATION_QUICK_LAUNCH && 1477 location != SHORTCUT_LOCATION_QUICK_LAUNCH &&
1466 location != SHORTCUT_LOCATION_START_MENU) { 1478 location != SHORTCUT_LOCATION_START_MENU_ROOT &&
1479 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
1480 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) {
1467 NOTREACHED(); 1481 NOTREACHED();
1468 return false; 1482 return false;
1469 } 1483 }
1470 1484
1471 DCHECK(dist); 1485 DCHECK(dist);
1472 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. 1486 // |pin_to_taskbar| is only acknowledged when first creating the shortcut.
1473 DCHECK(!properties.pin_to_taskbar || 1487 DCHECK(!properties.pin_to_taskbar ||
1474 operation == SHELL_SHORTCUT_CREATE_ALWAYS || 1488 operation == SHELL_SHORTCUT_CREATE_ALWAYS ||
1475 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); 1489 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL);
1476 1490
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 2058
2045 FilterTargetEq shortcut_filter(target_exe); 2059 FilterTargetEq shortcut_filter(target_exe);
2046 // Main operation to apply to each shortcut in the directory specified. 2060 // Main operation to apply to each shortcut in the directory specified.
2047 ShortcutOperationCallback shortcut_operation( 2061 ShortcutOperationCallback shortcut_operation(
2048 location == SHORTCUT_LOCATION_TASKBAR_PINS ? 2062 location == SHORTCUT_LOCATION_TASKBAR_PINS ?
2049 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete)); 2063 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete));
2050 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2064 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2051 shortcut_operation, location, dist, level); 2065 shortcut_operation, location, dist, level);
2052 // Remove chrome-specific shortcut folders if they are now empty. 2066 // Remove chrome-specific shortcut folders if they are now empty.
2053 if (success && 2067 if (success &&
2054 (location == SHORTCUT_LOCATION_START_MENU || 2068 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR ||
2069 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
2055 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2070 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2056 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2071 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2057 } 2072 }
2058 return success; 2073 return success;
2059 } 2074 }
2060 2075
2061 // static 2076 // static
2062 bool ShellUtil::UpdateShortcuts( 2077 bool ShellUtil::UpdateShortcuts(
2063 ShellUtil::ShortcutLocation location, 2078 ShellUtil::ShortcutLocation location,
2064 BrowserDistribution* dist, 2079 BrowserDistribution* dist,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 // are any left...). 2150 // are any left...).
2136 if (free_bits >= 8 && next_byte_index < size) { 2151 if (free_bits >= 8 && next_byte_index < size) {
2137 free_bits -= 8; 2152 free_bits -= 8;
2138 bit_stream += bytes[next_byte_index++] << free_bits; 2153 bit_stream += bytes[next_byte_index++] << free_bits;
2139 } 2154 }
2140 } 2155 }
2141 2156
2142 DCHECK_EQ(ret.length(), encoded_length); 2157 DCHECK_EQ(ret.length(), encoded_length);
2143 return ret; 2158 return ret;
2144 } 2159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698