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