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

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

Issue 1289333005: Change shortcut install location to non-subdir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some 'git cl format' changes Created 5 years, 1 month 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 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 } 1537 }
1538 1538
1539 1539
1540 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. 1540 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it.
1541 // Otherwise do nothing. Returns true on success, including the vacuous case 1541 // Otherwise do nothing. Returns true on success, including the vacuous case
1542 // where no deletion occurred because directory is non-empty. 1542 // where no deletion occurred because directory is non-empty.
1543 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, 1543 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
1544 BrowserDistribution* dist, 1544 BrowserDistribution* dist,
1545 ShellUtil::ShellChange level) { 1545 ShellUtil::ShellChange level) {
1546 // Explicitly whitelist locations, since accidental calls can be very harmful. 1546 // Explicitly whitelist locations, since accidental calls can be very harmful.
1547 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && 1547 if (location !=
1548 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED &&
1548 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && 1549 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR &&
1549 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { 1550 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) {
1550 NOTREACHED(); 1551 NOTREACHED();
1551 return false; 1552 return false;
1552 } 1553 }
1553 1554
1554 base::FilePath shortcut_folder; 1555 base::FilePath shortcut_folder;
1555 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { 1556 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) {
1556 LOG(WARNING) << "Cannot find path at location " << location; 1557 LOG(WARNING) << "Cannot find path at location " << location;
1557 return false; 1558 return false;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 ShellUtil::ShortcutProperties::~ShortcutProperties() { 1617 ShellUtil::ShortcutProperties::~ShortcutProperties() {
1617 } 1618 }
1618 1619
1619 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, 1620 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist,
1620 const base::FilePath& chrome_exe, 1621 const base::FilePath& chrome_exe,
1621 const base::string16& suffix) { 1622 const base::string16& suffix) {
1622 return QuickIsChromeRegistered(dist, chrome_exe, suffix, 1623 return QuickIsChromeRegistered(dist, chrome_exe, suffix,
1623 CONFIRM_SHELL_REGISTRATION_IN_HKLM); 1624 CONFIRM_SHELL_REGISTRATION_IN_HKLM);
1624 } 1625 }
1625 1626
1626 bool ShellUtil::ShortcutLocationIsSupported( 1627 bool ShellUtil::ShortcutLocationIsSupported(ShortcutLocation location) {
1627 ShellUtil::ShortcutLocation location) {
1628 switch (location) { 1628 switch (location) {
1629 case SHORTCUT_LOCATION_DESKTOP: // Falls through. 1629 case SHORTCUT_LOCATION_DESKTOP: // Falls through.
1630 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. 1630 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through.
1631 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. 1631 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through.
1632 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. 1632 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: // Falls through.
1633 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: 1633 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1634 return true; 1634 return true;
1635 case SHORTCUT_LOCATION_TASKBAR_PINS: 1635 case SHORTCUT_LOCATION_TASKBAR_PINS:
1636 return base::win::GetVersion() >= base::win::VERSION_WIN7; 1636 return base::win::GetVersion() >= base::win::VERSION_WIN7;
1637 case SHORTCUT_LOCATION_APP_SHORTCUTS: 1637 case SHORTCUT_LOCATION_APP_SHORTCUTS:
1638 return base::win::GetVersion() >= base::win::VERSION_WIN8; 1638 return base::win::GetVersion() >= base::win::VERSION_WIN8;
1639 default: 1639 default:
1640 NOTREACHED(); 1640 NOTREACHED();
1641 return false; 1641 return false;
1642 } 1642 }
1643 } 1643 }
1644 1644
1645 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, 1645 bool ShellUtil::GetShortcutPath(ShortcutLocation location,
1646 BrowserDistribution* dist, 1646 BrowserDistribution* dist,
1647 ShellChange level, 1647 ShellChange level,
1648 base::FilePath* path) { 1648 base::FilePath* path) {
1649 DCHECK(path); 1649 DCHECK(path);
1650 int dir_key = -1; 1650 int dir_key = -1;
1651 base::string16 folder_to_append; 1651 base::string16 folder_to_append;
1652 switch (location) { 1652 switch (location) {
1653 case SHORTCUT_LOCATION_DESKTOP: 1653 case SHORTCUT_LOCATION_DESKTOP:
1654 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : 1654 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP :
1655 base::DIR_COMMON_DESKTOP; 1655 base::DIR_COMMON_DESKTOP;
1656 break; 1656 break;
1657 case SHORTCUT_LOCATION_QUICK_LAUNCH: 1657 case SHORTCUT_LOCATION_QUICK_LAUNCH:
1658 // There is no support for a system-level Quick Launch shortcut. 1658 // There is no support for a system-level Quick Launch shortcut.
1659 DCHECK_EQ(level, CURRENT_USER); 1659 DCHECK_EQ(level, CURRENT_USER);
1660 dir_key = base::DIR_USER_QUICK_LAUNCH; 1660 dir_key = base::DIR_USER_QUICK_LAUNCH;
1661 break; 1661 break;
1662 case SHORTCUT_LOCATION_START_MENU_ROOT: 1662 case SHORTCUT_LOCATION_START_MENU_ROOT:
1663 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : 1663 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1664 base::DIR_COMMON_START_MENU; 1664 base::DIR_COMMON_START_MENU;
1665 break; 1665 break;
1666 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: 1666 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED:
1667 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : 1667 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1668 base::DIR_COMMON_START_MENU; 1668 base::DIR_COMMON_START_MENU;
1669 folder_to_append = dist->GetStartMenuShortcutSubfolder( 1669 folder_to_append = dist->GetStartMenuShortcutSubfolder(
1670 BrowserDistribution::SUBFOLDER_CHROME); 1670 BrowserDistribution::SUBFOLDER_CHROME);
1671 break; 1671 break;
1672 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: 1672 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1673 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : 1673 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1674 base::DIR_COMMON_START_MENU; 1674 base::DIR_COMMON_START_MENU;
1675 folder_to_append = dist->GetStartMenuShortcutSubfolder( 1675 folder_to_append = dist->GetStartMenuShortcutSubfolder(
1676 BrowserDistribution::SUBFOLDER_APPS); 1676 BrowserDistribution::SUBFOLDER_APPS);
(...skipping 14 matching lines...) Expand all
1691 NOTREACHED() << dir_key; 1691 NOTREACHED() << dir_key;
1692 return false; 1692 return false;
1693 } 1693 }
1694 1694
1695 if (!folder_to_append.empty()) 1695 if (!folder_to_append.empty())
1696 *path = path->Append(folder_to_append); 1696 *path = path->Append(folder_to_append);
1697 1697
1698 return true; 1698 return true;
1699 } 1699 }
1700 1700
1701 bool ShellUtil::MoveExistingShortcut(ShortcutLocation old_location,
1702 ShortcutLocation new_location,
1703 BrowserDistribution* dist,
1704 const ShortcutProperties& properties) {
1705 // Explicitly whitelist locations to which this is applicable.
1706 if (old_location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED ||
1707 new_location != SHORTCUT_LOCATION_START_MENU_ROOT) {
1708 NOTREACHED();
1709 return false;
1710 }
1711
1712 base::string16 shortcut_name(
1713 ExtractShortcutNameFromProperties(dist, properties));
1714
1715 base::FilePath old_shortcut_path;
1716 base::FilePath new_shortcut_path;
1717 GetShortcutPath(old_location, dist, properties.level, &old_shortcut_path);
1718 GetShortcutPath(new_location, dist, properties.level, &new_shortcut_path);
1719 old_shortcut_path = old_shortcut_path.Append(shortcut_name);
1720 new_shortcut_path = new_shortcut_path.Append(shortcut_name);
1721
1722 bool result = base::Move(old_shortcut_path, new_shortcut_path);
1723 RemoveShortcutFolderIfEmpty(old_location, dist, properties.level);
1724 return result;
1725 }
1726
1701 bool ShellUtil::CreateOrUpdateShortcut( 1727 bool ShellUtil::CreateOrUpdateShortcut(
1702 ShellUtil::ShortcutLocation location, 1728 ShortcutLocation location,
1703 BrowserDistribution* dist, 1729 BrowserDistribution* dist,
1704 const ShellUtil::ShortcutProperties& properties, 1730 const ShortcutProperties& properties,
1705 ShellUtil::ShortcutOperation operation) { 1731 ShortcutOperation operation) {
1706 // Explicitly whitelist locations to which this is applicable. 1732 // Explicitly whitelist locations to which this is applicable.
1707 if (location != SHORTCUT_LOCATION_DESKTOP && 1733 if (location != SHORTCUT_LOCATION_DESKTOP &&
1708 location != SHORTCUT_LOCATION_QUICK_LAUNCH && 1734 location != SHORTCUT_LOCATION_QUICK_LAUNCH &&
1709 location != SHORTCUT_LOCATION_START_MENU_ROOT && 1735 location != SHORTCUT_LOCATION_START_MENU_ROOT &&
1710 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && 1736 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED &&
1711 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { 1737 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) {
1712 NOTREACHED(); 1738 NOTREACHED();
1713 return false; 1739 return false;
1714 } 1740 }
1715 1741
1716 DCHECK(dist); 1742 DCHECK(dist);
1717 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. 1743 // |pin_to_taskbar| is only acknowledged when first creating the shortcut.
1718 DCHECK(!properties.pin_to_taskbar || 1744 DCHECK(!properties.pin_to_taskbar ||
1719 operation == SHELL_SHORTCUT_CREATE_ALWAYS || 1745 operation == SHELL_SHORTCUT_CREATE_ALWAYS ||
1720 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); 1746 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 const base::FilePath& chrome_exe) { 1835 const base::FilePath& chrome_exe) {
1810 return L"\"" + chrome_exe.value() + L"\" -- %*"; 1836 return L"\"" + chrome_exe.value() + L"\" -- %*";
1811 } 1837 }
1812 1838
1813 void ShellUtil::GetRegisteredBrowsers( 1839 void ShellUtil::GetRegisteredBrowsers(
1814 BrowserDistribution* dist, 1840 BrowserDistribution* dist,
1815 std::map<base::string16, base::string16>* browsers) { 1841 std::map<base::string16, base::string16>* browsers) {
1816 DCHECK(dist); 1842 DCHECK(dist);
1817 DCHECK(browsers); 1843 DCHECK(browsers);
1818 1844
1819 const base::string16 base_key(ShellUtil::kRegStartMenuInternet); 1845 const base::string16 base_key(kRegStartMenuInternet);
1820 base::string16 client_path; 1846 base::string16 client_path;
1821 RegKey key; 1847 RegKey key;
1822 base::string16 name; 1848 base::string16 name;
1823 base::string16 command; 1849 base::string16 command;
1824 1850
1825 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ. 1851 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ.
1826 // Look in HKCU second to override any identical values found in HKLM. 1852 // Look in HKCU second to override any identical values found in HKLM.
1827 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; 1853 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
1828 for (int i = 0; i < arraysize(roots); ++i) { 1854 for (int i = 0; i < arraysize(roots); ++i) {
1829 const HKEY root = roots[i]; 1855 const HKEY root = roots[i];
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 // No spaces are allowed in the AppUserModelId according to MSDN. 1975 // No spaces are allowed in the AppUserModelId according to MSDN.
1950 base::ReplaceChars(app_id, base::ASCIIToUTF16(" "), base::ASCIIToUTF16("_"), 1976 base::ReplaceChars(app_id, base::ASCIIToUTF16(" "), base::ASCIIToUTF16("_"),
1951 &app_id); 1977 &app_id);
1952 return app_id; 1978 return app_id;
1953 } 1979 }
1954 1980
1955 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() { 1981 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() {
1956 base::FilePath app_path; 1982 base::FilePath app_path;
1957 if (!PathService::Get(base::FILE_EXE, &app_path)) { 1983 if (!PathService::Get(base::FILE_EXE, &app_path)) {
1958 NOTREACHED(); 1984 NOTREACHED();
1959 return ShellUtil::UNKNOWN_DEFAULT; 1985 return UNKNOWN_DEFAULT;
1960 } 1986 }
1961 1987
1962 return GetChromeDefaultStateFromPath(app_path); 1988 return GetChromeDefaultStateFromPath(app_path);
1963 } 1989 }
1964 1990
1965 ShellUtil::DefaultState ShellUtil::GetChromeDefaultStateFromPath( 1991 ShellUtil::DefaultState ShellUtil::GetChromeDefaultStateFromPath(
1966 const base::FilePath& chrome_exe) { 1992 const base::FilePath& chrome_exe) {
1967 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 1993 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
1968 if (distribution->GetDefaultBrowserControlPolicy() == 1994 if (distribution->GetDefaultBrowserControlPolicy() ==
1969 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { 1995 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) {
(...skipping 22 matching lines...) Expand all
1992 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { 2018 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) {
1993 return NOT_DEFAULT; 2019 return NOT_DEFAULT;
1994 } 2020 }
1995 2021
1996 if (protocol.empty()) 2022 if (protocol.empty())
1997 return UNKNOWN_DEFAULT; 2023 return UNKNOWN_DEFAULT;
1998 2024
1999 base::FilePath chrome_exe; 2025 base::FilePath chrome_exe;
2000 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 2026 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
2001 NOTREACHED(); 2027 NOTREACHED();
2002 return ShellUtil::UNKNOWN_DEFAULT; 2028 return UNKNOWN_DEFAULT;
2003 } 2029 }
2004 2030
2005 const wchar_t* const protocols[] = { protocol.c_str() }; 2031 const wchar_t* const protocols[] = { protocol.c_str() };
2006 return ProbeProtocolHandlers(chrome_exe, 2032 return ProbeProtocolHandlers(chrome_exe,
2007 protocols, 2033 protocols,
2008 arraysize(protocols)); 2034 arraysize(protocols));
2009 } 2035 }
2010 2036
2011 // static 2037 // static
2012 bool ShellUtil::CanMakeChromeDefaultUnattended() { 2038 bool ShellUtil::CanMakeChromeDefaultUnattended() {
2013 return base::win::GetVersion() < base::win::VERSION_WIN8; 2039 return base::win::GetVersion() < base::win::VERSION_WIN8;
2014 } 2040 }
2015 2041
2016 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 2042 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
2017 int shell_change, 2043 int shell_change,
2018 const base::FilePath& chrome_exe, 2044 const base::FilePath& chrome_exe,
2019 bool elevate_if_not_admin) { 2045 bool elevate_if_not_admin) {
2020 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); 2046 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin());
2021 2047
2022 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 2048 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
2023 if (distribution->GetDefaultBrowserControlPolicy() != 2049 if (distribution->GetDefaultBrowserControlPolicy() !=
2024 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 2050 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
2025 return false; 2051 return false;
2026 } 2052 }
2027 2053
2028 // Windows 8 does not permit making a browser default just like that. 2054 // Windows 8 does not permit making a browser default just like that.
2029 // This process needs to be routed through the system's UI. Use 2055 // This process needs to be routed through the system's UI. Use
2030 // ShowMakeChromeDefaultSystemUI instead (below). 2056 // ShowMakeChromeDefaultSystemUI instead (below).
2031 if (!CanMakeChromeDefaultUnattended()) { 2057 if (!CanMakeChromeDefaultUnattended()) {
2032 return false; 2058 return false;
2033 } 2059 }
2034 2060
2035 if (!ShellUtil::RegisterChromeBrowser( 2061 if (!RegisterChromeBrowser(
2036 dist, chrome_exe, base::string16(), elevate_if_not_admin)) { 2062 dist, chrome_exe, base::string16(), elevate_if_not_admin)) {
2037 return false; 2063 return false;
2038 } 2064 }
2039 2065
2040 bool ret = true; 2066 bool ret = true;
2041 // First use the new "recommended" way on Vista to make Chrome default 2067 // First use the new "recommended" way on Vista to make Chrome default
2042 // browser. 2068 // browser.
2043 base::string16 app_name = GetApplicationName(dist, chrome_exe); 2069 base::string16 app_name = GetApplicationName(dist, chrome_exe);
2044 2070
2045 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 2071 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
2046 // On Windows Vista and Win7 we still can set ourselves via the 2072 // On Windows Vista and Win7 we still can set ourselves via the
2047 // the IApplicationAssociationRegistration interface. 2073 // the IApplicationAssociationRegistration interface.
2048 VLOG(1) << "Registering Chrome as default browser on Vista."; 2074 VLOG(1) << "Registering Chrome as default browser on Vista.";
2049 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 2075 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
2050 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 2076 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
2051 NULL, CLSCTX_INPROC); 2077 NULL, CLSCTX_INPROC);
2052 if (SUCCEEDED(hr)) { 2078 if (SUCCEEDED(hr)) {
2053 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 2079 for (int i = 0; kBrowserProtocolAssociations[i] != NULL; i++) {
2054 hr = pAAR->SetAppAsDefault(app_name.c_str(), 2080 hr = pAAR->SetAppAsDefault(app_name.c_str(),
2055 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); 2081 kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
2056 if (!SUCCEEDED(hr)) { 2082 if (!SUCCEEDED(hr)) {
2057 ret = false; 2083 ret = false;
2058 LOG(ERROR) << "Failed to register as default for protocol " 2084 LOG(ERROR) << "Failed to register as default for protocol "
2059 << ShellUtil::kBrowserProtocolAssociations[i] 2085 << kBrowserProtocolAssociations[i]
2060 << " (" << hr << ")"; 2086 << " (" << hr << ")";
2061 } 2087 }
2062 } 2088 }
2063 2089
2064 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { 2090 for (int i = 0; kDefaultFileAssociations[i] != NULL; i++) {
2065 hr = pAAR->SetAppAsDefault(app_name.c_str(), 2091 hr = pAAR->SetAppAsDefault(app_name.c_str(),
2066 ShellUtil::kDefaultFileAssociations[i], AT_FILEEXTENSION); 2092 kDefaultFileAssociations[i], AT_FILEEXTENSION);
2067 if (!SUCCEEDED(hr)) { 2093 if (!SUCCEEDED(hr)) {
2068 ret = false; 2094 ret = false;
2069 LOG(ERROR) << "Failed to register as default for file extension " 2095 LOG(ERROR) << "Failed to register as default for file extension "
2070 << ShellUtil::kDefaultFileAssociations[i] 2096 << kDefaultFileAssociations[i]
2071 << " (" << hr << ")"; 2097 << " (" << hr << ")";
2072 } 2098 }
2073 } 2099 }
2074 } 2100 }
2075 } 2101 }
2076 2102
2077 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe)) 2103 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe))
2078 ret = false; 2104 ret = false;
2079 2105
2080 // Send Windows notification event so that it can update icons for 2106 // Send Windows notification event so that it can update icons for
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 base::win::GetVersion() >= base::win::VERSION_VISTA) { 2369 base::win::GetVersion() >= base::win::VERSION_VISTA) {
2344 // Elevate to do the whole job 2370 // Elevate to do the whole job
2345 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); 2371 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol);
2346 } else { 2372 } else {
2347 // Admin rights are required to register capabilities before Windows 8. 2373 // Admin rights are required to register capabilities before Windows 8.
2348 return false; 2374 return false;
2349 } 2375 }
2350 } 2376 }
2351 2377
2352 // static 2378 // static
2353 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, 2379 bool ShellUtil::RemoveShortcuts(ShortcutLocation location,
2354 BrowserDistribution* dist, 2380 BrowserDistribution* dist,
2355 ShellChange level, 2381 ShellChange level,
2356 const base::FilePath& target_exe) { 2382 const base::FilePath& target_exe) {
2357 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2383 if (!ShortcutLocationIsSupported(location))
2358 return true; // Vacuous success. 2384 return true; // Vacuous success.
2359 2385
2360 FilterTargetEq shortcut_filter(target_exe, false); 2386 FilterTargetEq shortcut_filter(target_exe, false);
2361 // Main operation to apply to each shortcut in the directory specified. 2387 // Main operation to apply to each shortcut in the directory specified.
2362 ShortcutOperationCallback shortcut_operation( 2388 ShortcutOperationCallback shortcut_operation(
2363 location == SHORTCUT_LOCATION_TASKBAR_PINS 2389 location == SHORTCUT_LOCATION_TASKBAR_PINS
2364 ? base::Bind(&ShortcutOpUnpinFromTaskbar) 2390 ? base::Bind(&ShortcutOpUnpinFromTaskbar)
2365 : base::Bind(&ShortcutOpDelete)); 2391 : base::Bind(&ShortcutOpDelete));
2366 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2392 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2367 shortcut_operation, location, dist, level, 2393 shortcut_operation, location, dist, level,
2368 NULL); 2394 NULL);
2369 // Remove chrome-specific shortcut folders if they are now empty. 2395 // Remove chrome-specific shortcut folders if they are now empty.
2370 if (success && 2396 if (success &&
2371 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || 2397 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED ||
2372 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || 2398 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
2373 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2399 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2374 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2400 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2375 } 2401 }
2376 return success; 2402 return success;
2377 } 2403 }
2378 2404
2379 // static 2405 // static
2380 bool ShellUtil::RetargetShortcutsWithArgs( 2406 bool ShellUtil::RetargetShortcutsWithArgs(
2381 ShellUtil::ShortcutLocation location, 2407 ShortcutLocation location,
2382 BrowserDistribution* dist, 2408 BrowserDistribution* dist,
2383 ShellChange level, 2409 ShellChange level,
2384 const base::FilePath& old_target_exe, 2410 const base::FilePath& old_target_exe,
2385 const base::FilePath& new_target_exe) { 2411 const base::FilePath& new_target_exe) {
2386 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2412 if (!ShortcutLocationIsSupported(location))
2387 return true; // Vacuous success. 2413 return true; // Vacuous success.
2388 2414
2389 FilterTargetEq shortcut_filter(old_target_exe, true); 2415 FilterTargetEq shortcut_filter(old_target_exe, true);
2390 ShortcutOperationCallback shortcut_operation( 2416 ShortcutOperationCallback shortcut_operation(
2391 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); 2417 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe));
2392 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2418 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2393 shortcut_operation, location, dist, level, NULL); 2419 shortcut_operation, location, dist, level, NULL);
2394 } 2420 }
2395 2421
2396 // static 2422 // static
2397 bool ShellUtil::ShortcutListMaybeRemoveUnknownArgs( 2423 bool ShellUtil::ShortcutListMaybeRemoveUnknownArgs(
2398 ShellUtil::ShortcutLocation location, 2424 ShortcutLocation location,
2399 BrowserDistribution* dist, 2425 BrowserDistribution* dist,
2400 ShellChange level, 2426 ShellChange level,
2401 const base::FilePath& chrome_exe, 2427 const base::FilePath& chrome_exe,
2402 bool do_removal, 2428 bool do_removal,
2403 const scoped_refptr<SharedCancellationFlag>& cancel, 2429 const scoped_refptr<SharedCancellationFlag>& cancel,
2404 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts) { 2430 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts) {
2405 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2431 if (!ShortcutLocationIsSupported(location))
2406 return false; 2432 return false;
2407 DCHECK(dist); 2433 DCHECK(dist);
2408 FilterTargetEq shortcut_filter(chrome_exe, true); 2434 FilterTargetEq shortcut_filter(chrome_exe, true);
2409 ShortcutOperationCallback shortcut_operation( 2435 ShortcutOperationCallback shortcut_operation(
2410 base::Bind(&ShortcutOpListOrRemoveUnknownArgs, do_removal, shortcuts)); 2436 base::Bind(&ShortcutOpListOrRemoveUnknownArgs, do_removal, shortcuts));
2411 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2437 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2412 shortcut_operation, location, dist, level, cancel); 2438 shortcut_operation, location, dist, level, cancel);
2413 } 2439 }
2414 2440
2415 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { 2441 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 RegistryEntry::GetAppDefaultRegistrationEntries( 2543 RegistryEntry::GetAppDefaultRegistrationEntries(
2518 prog_id, ext, false, &entries); 2544 prog_id, ext, false, &entries);
2519 } 2545 }
2520 2546
2521 return AddRegistryEntries(HKEY_CURRENT_USER, entries); 2547 return AddRegistryEntries(HKEY_CURRENT_USER, entries);
2522 } 2548 }
2523 2549
2524 // static 2550 // static
2525 bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) { 2551 bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) {
2526 // Delete the key HKEY_CURRENT_USER\Software\Classes\PROGID. 2552 // Delete the key HKEY_CURRENT_USER\Software\Classes\PROGID.
2527 base::string16 key_path(ShellUtil::kRegClasses); 2553 base::string16 key_path(kRegClasses);
2528 key_path.push_back(base::FilePath::kSeparators[0]); 2554 key_path.push_back(base::FilePath::kSeparators[0]);
2529 key_path.append(prog_id); 2555 key_path.append(prog_id);
2530 return InstallUtil::DeleteRegistryKey( 2556 return InstallUtil::DeleteRegistryKey(
2531 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); 2557 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default);
2532 2558
2533 // TODO(mgiuca): Remove the extension association entries. This requires that 2559 // TODO(mgiuca): Remove the extension association entries. This requires that
2534 // the extensions associated with a particular prog_id are stored in that 2560 // the extensions associated with a particular prog_id are stored in that
2535 // prog_id's key. 2561 // prog_id's key.
2536 } 2562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698