| 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 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 | 1571 |
| 1572 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. | 1572 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. |
| 1573 // Otherwise do nothing. Returns true on success, including the vacuous case | 1573 // Otherwise do nothing. Returns true on success, including the vacuous case |
| 1574 // where no deletion occurred because directory is non-empty. | 1574 // where no deletion occurred because directory is non-empty. |
| 1575 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, | 1575 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, |
| 1576 BrowserDistribution* dist, | 1576 BrowserDistribution* dist, |
| 1577 ShellUtil::ShellChange level) { | 1577 ShellUtil::ShellChange level) { |
| 1578 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1578 // Explicitly whitelist locations, since accidental calls can be very harmful. |
| 1579 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1579 if (location != |
| 1580 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && |
| 1580 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && | 1581 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && |
| 1581 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1582 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
| 1582 NOTREACHED(); | 1583 NOTREACHED(); |
| 1583 return false; | 1584 return false; |
| 1584 } | 1585 } |
| 1585 | 1586 |
| 1586 base::FilePath shortcut_folder; | 1587 base::FilePath shortcut_folder; |
| 1587 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1588 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
| 1588 LOG(WARNING) << "Cannot find path at location " << location; | 1589 LOG(WARNING) << "Cannot find path at location " << location; |
| 1589 return false; | 1590 return false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 ShellUtil::ShortcutProperties::~ShortcutProperties() { | 1649 ShellUtil::ShortcutProperties::~ShortcutProperties() { |
| 1649 } | 1650 } |
| 1650 | 1651 |
| 1651 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 1652 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
| 1652 const base::FilePath& chrome_exe, | 1653 const base::FilePath& chrome_exe, |
| 1653 const base::string16& suffix) { | 1654 const base::string16& suffix) { |
| 1654 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1655 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 1655 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1656 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
| 1656 } | 1657 } |
| 1657 | 1658 |
| 1658 bool ShellUtil::ShortcutLocationIsSupported( | 1659 bool ShellUtil::ShortcutLocationIsSupported(ShortcutLocation location) { |
| 1659 ShellUtil::ShortcutLocation location) { | |
| 1660 switch (location) { | 1660 switch (location) { |
| 1661 case SHORTCUT_LOCATION_DESKTOP: // Falls through. | 1661 case SHORTCUT_LOCATION_DESKTOP: // Falls through. |
| 1662 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. | 1662 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. |
| 1663 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. | 1663 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. |
| 1664 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. | 1664 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: // Falls through. |
| 1665 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1665 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1666 return true; | 1666 return true; |
| 1667 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1667 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1668 return base::win::GetVersion() >= base::win::VERSION_WIN7; | 1668 return base::win::GetVersion() >= base::win::VERSION_WIN7; |
| 1669 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1669 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1670 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 1670 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 1671 default: | 1671 default: |
| 1672 NOTREACHED(); | 1672 NOTREACHED(); |
| 1673 return false; | 1673 return false; |
| 1674 } | 1674 } |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, | 1677 bool ShellUtil::GetShortcutPath(ShortcutLocation location, |
| 1678 BrowserDistribution* dist, | 1678 BrowserDistribution* dist, |
| 1679 ShellChange level, | 1679 ShellChange level, |
| 1680 base::FilePath* path) { | 1680 base::FilePath* path) { |
| 1681 DCHECK(path); | 1681 DCHECK(path); |
| 1682 int dir_key = -1; | 1682 int dir_key = -1; |
| 1683 base::string16 folder_to_append; | 1683 base::string16 folder_to_append; |
| 1684 switch (location) { | 1684 switch (location) { |
| 1685 case SHORTCUT_LOCATION_DESKTOP: | 1685 case SHORTCUT_LOCATION_DESKTOP: |
| 1686 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : | 1686 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
| 1687 base::DIR_COMMON_DESKTOP; | 1687 base::DIR_COMMON_DESKTOP; |
| 1688 break; | 1688 break; |
| 1689 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1689 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
| 1690 // There is no support for a system-level Quick Launch shortcut. | 1690 // There is no support for a system-level Quick Launch shortcut. |
| 1691 DCHECK_EQ(level, CURRENT_USER); | 1691 DCHECK_EQ(level, CURRENT_USER); |
| 1692 dir_key = base::DIR_USER_QUICK_LAUNCH; | 1692 dir_key = base::DIR_USER_QUICK_LAUNCH; |
| 1693 break; | 1693 break; |
| 1694 case SHORTCUT_LOCATION_START_MENU_ROOT: | 1694 case SHORTCUT_LOCATION_START_MENU_ROOT: |
| 1695 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1695 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1696 base::DIR_COMMON_START_MENU; | 1696 base::DIR_COMMON_START_MENU; |
| 1697 break; | 1697 break; |
| 1698 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | 1698 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: |
| 1699 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1699 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1700 base::DIR_COMMON_START_MENU; | 1700 base::DIR_COMMON_START_MENU; |
| 1701 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1701 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1702 BrowserDistribution::SUBFOLDER_CHROME); | 1702 BrowserDistribution::SUBFOLDER_CHROME); |
| 1703 break; | 1703 break; |
| 1704 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1704 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1705 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1705 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1706 base::DIR_COMMON_START_MENU; | 1706 base::DIR_COMMON_START_MENU; |
| 1707 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1707 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1708 BrowserDistribution::SUBFOLDER_APPS); | 1708 BrowserDistribution::SUBFOLDER_APPS); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1723 NOTREACHED() << dir_key; | 1723 NOTREACHED() << dir_key; |
| 1724 return false; | 1724 return false; |
| 1725 } | 1725 } |
| 1726 | 1726 |
| 1727 if (!folder_to_append.empty()) | 1727 if (!folder_to_append.empty()) |
| 1728 *path = path->Append(folder_to_append); | 1728 *path = path->Append(folder_to_append); |
| 1729 | 1729 |
| 1730 return true; | 1730 return true; |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 bool ShellUtil::CreateOrUpdateShortcut( | 1733 bool ShellUtil::MoveExistingShortcut(ShortcutLocation old_location, |
| 1734 ShellUtil::ShortcutLocation location, | 1734 ShortcutLocation new_location, |
| 1735 BrowserDistribution* dist, | 1735 BrowserDistribution* dist, |
| 1736 const ShellUtil::ShortcutProperties& properties, | 1736 const ShortcutProperties& properties) { |
| 1737 ShellUtil::ShortcutOperation operation) { | 1737 // Explicitly whitelist locations to which this is applicable. |
| 1738 if (old_location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || |
| 1739 new_location != SHORTCUT_LOCATION_START_MENU_ROOT) { |
| 1740 NOTREACHED(); |
| 1741 return false; |
| 1742 } |
| 1743 |
| 1744 base::string16 shortcut_name( |
| 1745 ExtractShortcutNameFromProperties(dist, properties)); |
| 1746 |
| 1747 base::FilePath old_shortcut_path; |
| 1748 base::FilePath new_shortcut_path; |
| 1749 GetShortcutPath(old_location, dist, properties.level, &old_shortcut_path); |
| 1750 GetShortcutPath(new_location, dist, properties.level, &new_shortcut_path); |
| 1751 old_shortcut_path = old_shortcut_path.Append(shortcut_name); |
| 1752 new_shortcut_path = new_shortcut_path.Append(shortcut_name); |
| 1753 |
| 1754 bool result = base::Move(old_shortcut_path, new_shortcut_path); |
| 1755 RemoveShortcutFolderIfEmpty(old_location, dist, properties.level); |
| 1756 return result; |
| 1757 } |
| 1758 |
| 1759 bool ShellUtil::CreateOrUpdateShortcut(ShortcutLocation location, |
| 1760 BrowserDistribution* dist, |
| 1761 const ShortcutProperties& properties, |
| 1762 ShortcutOperation operation) { |
| 1738 // Explicitly whitelist locations to which this is applicable. | 1763 // Explicitly whitelist locations to which this is applicable. |
| 1739 if (location != SHORTCUT_LOCATION_DESKTOP && | 1764 if (location != SHORTCUT_LOCATION_DESKTOP && |
| 1740 location != SHORTCUT_LOCATION_QUICK_LAUNCH && | 1765 location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
| 1741 location != SHORTCUT_LOCATION_START_MENU_ROOT && | 1766 location != SHORTCUT_LOCATION_START_MENU_ROOT && |
| 1742 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1767 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && |
| 1743 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { | 1768 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { |
| 1744 NOTREACHED(); | 1769 NOTREACHED(); |
| 1745 return false; | 1770 return false; |
| 1746 } | 1771 } |
| 1747 | 1772 |
| 1748 DCHECK(dist); | 1773 DCHECK(dist); |
| 1749 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1774 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
| 1750 DCHECK(!properties.pin_to_taskbar || | 1775 DCHECK(!properties.pin_to_taskbar || |
| 1751 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1776 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
| 1752 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1777 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 const base::FilePath& chrome_exe) { | 1866 const base::FilePath& chrome_exe) { |
| 1842 return L"\"" + chrome_exe.value() + L"\" -- %*"; | 1867 return L"\"" + chrome_exe.value() + L"\" -- %*"; |
| 1843 } | 1868 } |
| 1844 | 1869 |
| 1845 void ShellUtil::GetRegisteredBrowsers( | 1870 void ShellUtil::GetRegisteredBrowsers( |
| 1846 BrowserDistribution* dist, | 1871 BrowserDistribution* dist, |
| 1847 std::map<base::string16, base::string16>* browsers) { | 1872 std::map<base::string16, base::string16>* browsers) { |
| 1848 DCHECK(dist); | 1873 DCHECK(dist); |
| 1849 DCHECK(browsers); | 1874 DCHECK(browsers); |
| 1850 | 1875 |
| 1851 const base::string16 base_key(ShellUtil::kRegStartMenuInternet); | 1876 const base::string16 base_key(kRegStartMenuInternet); |
| 1852 base::string16 client_path; | 1877 base::string16 client_path; |
| 1853 RegKey key; | 1878 RegKey key; |
| 1854 base::string16 name; | 1879 base::string16 name; |
| 1855 base::string16 command; | 1880 base::string16 command; |
| 1856 | 1881 |
| 1857 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ. | 1882 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ. |
| 1858 // Look in HKCU second to override any identical values found in HKLM. | 1883 // Look in HKCU second to override any identical values found in HKLM. |
| 1859 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | 1884 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; |
| 1860 for (int i = 0; i < arraysize(roots); ++i) { | 1885 for (int i = 0; i < arraysize(roots); ++i) { |
| 1861 const HKEY root = roots[i]; | 1886 const HKEY root = roots[i]; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 // No spaces are allowed in the AppUserModelId according to MSDN. | 2006 // No spaces are allowed in the AppUserModelId according to MSDN. |
| 1982 base::ReplaceChars(app_id, base::ASCIIToUTF16(" "), base::ASCIIToUTF16("_"), | 2007 base::ReplaceChars(app_id, base::ASCIIToUTF16(" "), base::ASCIIToUTF16("_"), |
| 1983 &app_id); | 2008 &app_id); |
| 1984 return app_id; | 2009 return app_id; |
| 1985 } | 2010 } |
| 1986 | 2011 |
| 1987 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() { | 2012 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() { |
| 1988 base::FilePath app_path; | 2013 base::FilePath app_path; |
| 1989 if (!PathService::Get(base::FILE_EXE, &app_path)) { | 2014 if (!PathService::Get(base::FILE_EXE, &app_path)) { |
| 1990 NOTREACHED(); | 2015 NOTREACHED(); |
| 1991 return ShellUtil::UNKNOWN_DEFAULT; | 2016 return UNKNOWN_DEFAULT; |
| 1992 } | 2017 } |
| 1993 | 2018 |
| 1994 return GetChromeDefaultStateFromPath(app_path); | 2019 return GetChromeDefaultStateFromPath(app_path); |
| 1995 } | 2020 } |
| 1996 | 2021 |
| 1997 ShellUtil::DefaultState ShellUtil::GetChromeDefaultStateFromPath( | 2022 ShellUtil::DefaultState ShellUtil::GetChromeDefaultStateFromPath( |
| 1998 const base::FilePath& chrome_exe) { | 2023 const base::FilePath& chrome_exe) { |
| 1999 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 2024 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 2000 if (distribution->GetDefaultBrowserControlPolicy() == | 2025 if (distribution->GetDefaultBrowserControlPolicy() == |
| 2001 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 2026 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2024 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 2049 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| 2025 return NOT_DEFAULT; | 2050 return NOT_DEFAULT; |
| 2026 } | 2051 } |
| 2027 | 2052 |
| 2028 if (protocol.empty()) | 2053 if (protocol.empty()) |
| 2029 return UNKNOWN_DEFAULT; | 2054 return UNKNOWN_DEFAULT; |
| 2030 | 2055 |
| 2031 base::FilePath chrome_exe; | 2056 base::FilePath chrome_exe; |
| 2032 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 2057 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 2033 NOTREACHED(); | 2058 NOTREACHED(); |
| 2034 return ShellUtil::UNKNOWN_DEFAULT; | 2059 return UNKNOWN_DEFAULT; |
| 2035 } | 2060 } |
| 2036 | 2061 |
| 2037 const wchar_t* const protocols[] = { protocol.c_str() }; | 2062 const wchar_t* const protocols[] = { protocol.c_str() }; |
| 2038 return ProbeProtocolHandlers(chrome_exe, | 2063 return ProbeProtocolHandlers(chrome_exe, |
| 2039 protocols, | 2064 protocols, |
| 2040 arraysize(protocols)); | 2065 arraysize(protocols)); |
| 2041 } | 2066 } |
| 2042 | 2067 |
| 2043 // static | 2068 // static |
| 2044 bool ShellUtil::CanMakeChromeDefaultUnattended() { | 2069 bool ShellUtil::CanMakeChromeDefaultUnattended() { |
| 2045 return base::win::GetVersion() < base::win::VERSION_WIN8; | 2070 return base::win::GetVersion() < base::win::VERSION_WIN8; |
| 2046 } | 2071 } |
| 2047 | 2072 |
| 2048 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 2073 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
| 2049 int shell_change, | 2074 int shell_change, |
| 2050 const base::FilePath& chrome_exe, | 2075 const base::FilePath& chrome_exe, |
| 2051 bool elevate_if_not_admin) { | 2076 bool elevate_if_not_admin) { |
| 2052 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); | 2077 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin()); |
| 2053 | 2078 |
| 2054 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 2079 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 2055 if (distribution->GetDefaultBrowserControlPolicy() != | 2080 if (distribution->GetDefaultBrowserControlPolicy() != |
| 2056 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { | 2081 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { |
| 2057 return false; | 2082 return false; |
| 2058 } | 2083 } |
| 2059 | 2084 |
| 2060 // Windows 8 does not permit making a browser default just like that. | 2085 // Windows 8 does not permit making a browser default just like that. |
| 2061 // This process needs to be routed through the system's UI. Use | 2086 // This process needs to be routed through the system's UI. Use |
| 2062 // ShowMakeChromeDefaultSystemUI instead (below). | 2087 // ShowMakeChromeDefaultSystemUI instead (below). |
| 2063 if (!CanMakeChromeDefaultUnattended()) { | 2088 if (!CanMakeChromeDefaultUnattended()) { |
| 2064 return false; | 2089 return false; |
| 2065 } | 2090 } |
| 2066 | 2091 |
| 2067 if (!ShellUtil::RegisterChromeBrowser( | 2092 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), |
| 2068 dist, chrome_exe, base::string16(), elevate_if_not_admin)) { | 2093 elevate_if_not_admin)) { |
| 2069 return false; | 2094 return false; |
| 2070 } | 2095 } |
| 2071 | 2096 |
| 2072 bool ret = true; | 2097 bool ret = true; |
| 2073 // First use the new "recommended" way on Vista to make Chrome default | 2098 // First use the new "recommended" way on Vista to make Chrome default |
| 2074 // browser. | 2099 // browser. |
| 2075 base::string16 app_name = GetApplicationName(dist, chrome_exe); | 2100 base::string16 app_name = GetApplicationName(dist, chrome_exe); |
| 2076 | 2101 |
| 2077 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 2102 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 2078 // On Windows Vista and Win7 we still can set ourselves via the | 2103 // On Windows Vista and Win7 we still can set ourselves via the |
| 2079 // the IApplicationAssociationRegistration interface. | 2104 // the IApplicationAssociationRegistration interface. |
| 2080 VLOG(1) << "Registering Chrome as default browser on Vista."; | 2105 VLOG(1) << "Registering Chrome as default browser on Vista."; |
| 2081 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 2106 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 2082 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 2107 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 2083 NULL, CLSCTX_INPROC); | 2108 NULL, CLSCTX_INPROC); |
| 2084 if (SUCCEEDED(hr)) { | 2109 if (SUCCEEDED(hr)) { |
| 2085 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 2110 for (int i = 0; kBrowserProtocolAssociations[i] != NULL; i++) { |
| 2086 hr = pAAR->SetAppAsDefault(app_name.c_str(), | 2111 hr = pAAR->SetAppAsDefault( |
| 2087 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); | 2112 app_name.c_str(), kBrowserProtocolAssociations[i], AT_URLPROTOCOL); |
| 2088 if (!SUCCEEDED(hr)) { | 2113 if (!SUCCEEDED(hr)) { |
| 2089 ret = false; | 2114 ret = false; |
| 2090 LOG(ERROR) << "Failed to register as default for protocol " | 2115 LOG(ERROR) << "Failed to register as default for protocol " |
| 2091 << ShellUtil::kBrowserProtocolAssociations[i] | 2116 << kBrowserProtocolAssociations[i] << " (" << hr << ")"; |
| 2092 << " (" << hr << ")"; | |
| 2093 } | 2117 } |
| 2094 } | 2118 } |
| 2095 | 2119 |
| 2096 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { | 2120 for (int i = 0; kDefaultFileAssociations[i] != NULL; i++) { |
| 2097 hr = pAAR->SetAppAsDefault(app_name.c_str(), | 2121 hr = pAAR->SetAppAsDefault( |
| 2098 ShellUtil::kDefaultFileAssociations[i], AT_FILEEXTENSION); | 2122 app_name.c_str(), kDefaultFileAssociations[i], AT_FILEEXTENSION); |
| 2099 if (!SUCCEEDED(hr)) { | 2123 if (!SUCCEEDED(hr)) { |
| 2100 ret = false; | 2124 ret = false; |
| 2101 LOG(ERROR) << "Failed to register as default for file extension " | 2125 LOG(ERROR) << "Failed to register as default for file extension " |
| 2102 << ShellUtil::kDefaultFileAssociations[i] | 2126 << kDefaultFileAssociations[i] << " (" << hr << ")"; |
| 2103 << " (" << hr << ")"; | |
| 2104 } | 2127 } |
| 2105 } | 2128 } |
| 2106 } | 2129 } |
| 2107 } | 2130 } |
| 2108 | 2131 |
| 2109 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe)) | 2132 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe)) |
| 2110 ret = false; | 2133 ret = false; |
| 2111 | 2134 |
| 2112 // Send Windows notification event so that it can update icons for | 2135 // Send Windows notification event so that it can update icons for |
| 2113 // file associations. | 2136 // file associations. |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2375 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 2398 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 2376 // Elevate to do the whole job | 2399 // Elevate to do the whole job |
| 2377 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 2400 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
| 2378 } else { | 2401 } else { |
| 2379 // Admin rights are required to register capabilities before Windows 8. | 2402 // Admin rights are required to register capabilities before Windows 8. |
| 2380 return false; | 2403 return false; |
| 2381 } | 2404 } |
| 2382 } | 2405 } |
| 2383 | 2406 |
| 2384 // static | 2407 // static |
| 2385 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, | 2408 bool ShellUtil::RemoveShortcuts(ShortcutLocation location, |
| 2386 BrowserDistribution* dist, | 2409 BrowserDistribution* dist, |
| 2387 ShellChange level, | 2410 ShellChange level, |
| 2388 const base::FilePath& target_exe) { | 2411 const base::FilePath& target_exe) { |
| 2389 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2412 if (!ShortcutLocationIsSupported(location)) |
| 2390 return true; // Vacuous success. | 2413 return true; // Vacuous success. |
| 2391 | 2414 |
| 2392 FilterTargetEq shortcut_filter(target_exe, false); | 2415 FilterTargetEq shortcut_filter(target_exe, false); |
| 2393 // Main operation to apply to each shortcut in the directory specified. | 2416 // Main operation to apply to each shortcut in the directory specified. |
| 2394 ShortcutOperationCallback shortcut_operation( | 2417 ShortcutOperationCallback shortcut_operation( |
| 2395 location == SHORTCUT_LOCATION_TASKBAR_PINS | 2418 location == SHORTCUT_LOCATION_TASKBAR_PINS |
| 2396 ? base::Bind(&ShortcutOpUnpinFromTaskbar) | 2419 ? base::Bind(&ShortcutOpUnpinFromTaskbar) |
| 2397 : base::Bind(&ShortcutOpDelete)); | 2420 : base::Bind(&ShortcutOpDelete)); |
| 2398 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2421 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2399 shortcut_operation, location, dist, level, | 2422 shortcut_operation, location, dist, level, |
| 2400 NULL); | 2423 NULL); |
| 2401 // Remove chrome-specific shortcut folders if they are now empty. | 2424 // Remove chrome-specific shortcut folders if they are now empty. |
| 2402 if (success && | 2425 if (success && |
| 2403 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || | 2426 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || |
| 2404 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || | 2427 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || |
| 2405 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { | 2428 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { |
| 2406 success = RemoveShortcutFolderIfEmpty(location, dist, level); | 2429 success = RemoveShortcutFolderIfEmpty(location, dist, level); |
| 2407 } | 2430 } |
| 2408 return success; | 2431 return success; |
| 2409 } | 2432 } |
| 2410 | 2433 |
| 2411 // static | 2434 // static |
| 2412 bool ShellUtil::RetargetShortcutsWithArgs( | 2435 bool ShellUtil::RetargetShortcutsWithArgs( |
| 2413 ShellUtil::ShortcutLocation location, | 2436 ShortcutLocation location, |
| 2414 BrowserDistribution* dist, | 2437 BrowserDistribution* dist, |
| 2415 ShellChange level, | 2438 ShellChange level, |
| 2416 const base::FilePath& old_target_exe, | 2439 const base::FilePath& old_target_exe, |
| 2417 const base::FilePath& new_target_exe) { | 2440 const base::FilePath& new_target_exe) { |
| 2418 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2441 if (!ShortcutLocationIsSupported(location)) |
| 2419 return true; // Vacuous success. | 2442 return true; // Vacuous success. |
| 2420 | 2443 |
| 2421 FilterTargetEq shortcut_filter(old_target_exe, true); | 2444 FilterTargetEq shortcut_filter(old_target_exe, true); |
| 2422 ShortcutOperationCallback shortcut_operation( | 2445 ShortcutOperationCallback shortcut_operation( |
| 2423 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); | 2446 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); |
| 2424 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2447 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2425 shortcut_operation, location, dist, level, NULL); | 2448 shortcut_operation, location, dist, level, NULL); |
| 2426 } | 2449 } |
| 2427 | 2450 |
| 2428 // static | 2451 // static |
| 2429 bool ShellUtil::ShortcutListMaybeRemoveUnknownArgs( | 2452 bool ShellUtil::ShortcutListMaybeRemoveUnknownArgs( |
| 2430 ShellUtil::ShortcutLocation location, | 2453 ShortcutLocation location, |
| 2431 BrowserDistribution* dist, | 2454 BrowserDistribution* dist, |
| 2432 ShellChange level, | 2455 ShellChange level, |
| 2433 const base::FilePath& chrome_exe, | 2456 const base::FilePath& chrome_exe, |
| 2434 bool do_removal, | 2457 bool do_removal, |
| 2435 const scoped_refptr<SharedCancellationFlag>& cancel, | 2458 const scoped_refptr<SharedCancellationFlag>& cancel, |
| 2436 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts) { | 2459 std::vector<std::pair<base::FilePath, base::string16>>* shortcuts) { |
| 2437 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2460 if (!ShortcutLocationIsSupported(location)) |
| 2438 return false; | 2461 return false; |
| 2439 DCHECK(dist); | 2462 DCHECK(dist); |
| 2440 FilterTargetEq shortcut_filter(chrome_exe, true); | 2463 FilterTargetEq shortcut_filter(chrome_exe, true); |
| 2441 ShortcutOperationCallback shortcut_operation( | 2464 ShortcutOperationCallback shortcut_operation( |
| 2442 base::Bind(&ShortcutOpListOrRemoveUnknownArgs, do_removal, shortcuts)); | 2465 base::Bind(&ShortcutOpListOrRemoveUnknownArgs, do_removal, shortcuts)); |
| 2443 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2466 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2444 shortcut_operation, location, dist, level, cancel); | 2467 shortcut_operation, location, dist, level, cancel); |
| 2445 } | 2468 } |
| 2446 | 2469 |
| 2447 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { | 2470 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2549 RegistryEntry::GetAppDefaultRegistrationEntries( | 2572 RegistryEntry::GetAppDefaultRegistrationEntries( |
| 2550 prog_id, ext, false, &entries); | 2573 prog_id, ext, false, &entries); |
| 2551 } | 2574 } |
| 2552 | 2575 |
| 2553 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 2576 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 2554 } | 2577 } |
| 2555 | 2578 |
| 2556 // static | 2579 // static |
| 2557 bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) { | 2580 bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) { |
| 2558 // Delete the key HKEY_CURRENT_USER\Software\Classes\PROGID. | 2581 // Delete the key HKEY_CURRENT_USER\Software\Classes\PROGID. |
| 2559 base::string16 key_path(ShellUtil::kRegClasses); | 2582 base::string16 key_path(kRegClasses); |
| 2560 key_path.push_back(base::FilePath::kSeparators[0]); | 2583 key_path.push_back(base::FilePath::kSeparators[0]); |
| 2561 key_path.append(prog_id); | 2584 key_path.append(prog_id); |
| 2562 return InstallUtil::DeleteRegistryKey( | 2585 return InstallUtil::DeleteRegistryKey( |
| 2563 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); | 2586 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); |
| 2564 | 2587 |
| 2565 // TODO(mgiuca): Remove the extension association entries. This requires that | 2588 // TODO(mgiuca): Remove the extension association entries. This requires that |
| 2566 // the extensions associated with a particular prog_id are stored in that | 2589 // the extensions associated with a particular prog_id are stored in that |
| 2567 // prog_id's key. | 2590 // prog_id's key. |
| 2568 } | 2591 } |
| OLD | NEW |