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

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

Powered by Google App Engine
This is Rietveld 408576698