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

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

Issue 1896513002: Fix registerProtocolHandler implementation on Windows 8 and 10. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clang compilation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | no next file » | 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 13 matching lines...) Expand all
24 #include "base/files/file_util.h" 24 #include "base/files/file_util.h"
25 #include "base/lazy_instance.h" 25 #include "base/lazy_instance.h"
26 #include "base/logging.h" 26 #include "base/logging.h"
27 #include "base/macros.h" 27 #include "base/macros.h"
28 #include "base/md5.h" 28 #include "base/md5.h"
29 #include "base/memory/scoped_vector.h" 29 #include "base/memory/scoped_vector.h"
30 #include "base/metrics/sparse_histogram.h" 30 #include "base/metrics/sparse_histogram.h"
31 #include "base/path_service.h" 31 #include "base/path_service.h"
32 #include "base/strings/string16.h" 32 #include "base/strings/string16.h"
33 #include "base/strings/string_number_conversions.h" 33 #include "base/strings/string_number_conversions.h"
34 #include "base/strings/string_piece.h"
34 #include "base/strings/string_split.h" 35 #include "base/strings/string_split.h"
35 #include "base/strings/string_util.h" 36 #include "base/strings/string_util.h"
36 #include "base/strings/stringprintf.h" 37 #include "base/strings/stringprintf.h"
37 #include "base/strings/utf_string_conversions.h" 38 #include "base/strings/utf_string_conversions.h"
38 #include "base/synchronization/cancellation_flag.h" 39 #include "base/synchronization/cancellation_flag.h"
39 #include "base/values.h" 40 #include "base/values.h"
40 #include "base/win/registry.h" 41 #include "base/win/registry.h"
41 #include "base/win/scoped_co_mem.h" 42 #include "base/win/scoped_co_mem.h"
42 #include "base/win/scoped_comptr.h" 43 #include "base/win/scoped_comptr.h"
43 #include "base/win/shortcut.h" 44 #include "base/win/shortcut.h"
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 701 }
701 702
702 DWORD ret_val = 0; 703 DWORD ret_val = 0;
703 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val); 704 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val);
704 if (ret_val == 0) 705 if (ret_val == 0)
705 return true; 706 return true;
706 } 707 }
707 return false; 708 return false;
708 } 709 }
709 710
711 // Returns the target used as a activate parameter when opening the settings
712 // pointing to the page that is the most relevant to a user trying to change the
713 // default handler for |protocol|.
714 base::string16 GetTargetForDefaultAppsSettings(const wchar_t* protocol) {
715 static const wchar_t kSystemSettingsDefaultAppsFormat[] =
716 L"SystemSettings_DefaultApps_%ls";
717
718 if (base::EqualsCaseInsensitiveASCII(protocol, L"http"))
719 return base::StringPrintf(kSystemSettingsDefaultAppsFormat, L"Browser");
720 if (base::EqualsCaseInsensitiveASCII(protocol, L"mailto"))
721 return base::StringPrintf(kSystemSettingsDefaultAppsFormat, L"Email");
722 return L"SettingsPageAppsDefaultsProtocolView";
723 }
724
710 // Launches the Windows 'settings' modern app with the 'default apps' view 725 // Launches the Windows 'settings' modern app with the 'default apps' view
711 // focused. This only works for Windows 8 and Windows 10. The appModelId 726 // focused. This only works for Windows 8 and Windows 10. The appModelId
712 // looks arbitrary but it is the same in Win8 and Win10 previews. There 727 // looks arbitrary but it is the same in Win8 and Win10. There is no easy way to
713 // is no easy way to retrieve the appModelId from the registry. 728 // retrieve the appModelId from the registry.
714 bool LaunchDefaultAppsSettingsModernDialog() { 729 bool LaunchDefaultAppsSettingsModernDialog(const wchar_t* protocol) {
730 DCHECK(protocol);
731 static const wchar_t kControlPanelAppModelId[] =
732 L"windows.immersivecontrolpanel_cw5n1h2txyewy"
733 L"!microsoft.windows.immersivecontrolpanel";
734
715 base::win::ScopedComPtr<IApplicationActivationManager> activator; 735 base::win::ScopedComPtr<IApplicationActivationManager> activator;
716 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); 736 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager);
717 if (SUCCEEDED(hr)) { 737 if (SUCCEEDED(hr)) {
718 DWORD pid = 0; 738 DWORD pid = 0;
719 CoAllowSetForegroundWindow(activator.get(), nullptr); 739 CoAllowSetForegroundWindow(activator.get(), nullptr);
720 hr = activator->ActivateApplication( 740 hr = activator->ActivateApplication(kControlPanelAppModelId,
721 L"windows.immersivecontrolpanel_cw5n1h2txyewy" 741 L"page=SettingsPageAppsDefaults",
722 L"!microsoft.windows.immersivecontrolpanel", 742 AO_NONE, &pid);
723 L"page=SettingsPageAppsDefaults", AO_NONE, &pid);
724 if (SUCCEEDED(hr)) { 743 if (SUCCEEDED(hr)) {
725 hr = activator->ActivateApplication( 744 hr = activator->ActivateApplication(
726 L"windows.immersivecontrolpanel_cw5n1h2txyewy" 745 kControlPanelAppModelId,
727 L"!microsoft.windows.immersivecontrolpanel", 746 base::StringPrintf(L"page=SettingsPageAppsDefaults&target=%ls",
728 L"page=SettingsPageAppsDefaults" 747 GetTargetForDefaultAppsSettings(protocol).c_str())
729 L"&target=SystemSettings_DefaultApps_Browser", AO_NONE, &pid); 748 .c_str(),
749 AO_NONE, &pid);
730 } 750 }
731 if (SUCCEEDED(hr)) 751 if (SUCCEEDED(hr))
732 return true; 752 return true;
733 UMA_HISTOGRAM_SPARSE_SLOWLY("DefaultBrowser.ActivateSettings.ErrorHresult", 753 UMA_HISTOGRAM_SPARSE_SLOWLY("DefaultBrowser.ActivateSettings.ErrorHresult",
734 hr); 754 hr);
735 } 755 }
736 return false; 756 return false;
737 } 757 }
738 758
739 // Launches the Windows 7 and Windows 8 dialog for picking the application to 759 // Launches the Windows 7 and Windows 8 dialog for picking the application to
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 return ProbeProtocolHandlers(chrome_exe, 1831 return ProbeProtocolHandlers(chrome_exe,
1812 protocols, 1832 protocols,
1813 arraysize(protocols)); 1833 arraysize(protocols));
1814 } 1834 }
1815 1835
1816 // static 1836 // static
1817 bool ShellUtil::CanMakeChromeDefaultUnattended() { 1837 bool ShellUtil::CanMakeChromeDefaultUnattended() {
1818 return base::win::GetVersion() < base::win::VERSION_WIN8; 1838 return base::win::GetVersion() < base::win::VERSION_WIN8;
1819 } 1839 }
1820 1840
1841 // static
1842 ShellUtil::InteractiveSetDefaultMode ShellUtil::GetInteractiveSetDefaultMode() {
1843 DCHECK(!CanMakeChromeDefaultUnattended());
1844
1845 if (base::win::GetVersion() == base::win::VERSION_WIN8)
1846 return InteractiveSetDefaultMode::INTENT_PICKER;
1847
1848 return InteractiveSetDefaultMode::SYSTEM_SETTINGS;
1849 }
1850
1821 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 1851 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
1822 int shell_change, 1852 int shell_change,
1823 const base::FilePath& chrome_exe, 1853 const base::FilePath& chrome_exe,
1824 bool elevate_if_not_admin) { 1854 bool elevate_if_not_admin) {
1825 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin()); 1855 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin());
1826 1856
1827 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 1857 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
1828 if (distribution->GetDefaultBrowserControlPolicy() != 1858 if (distribution->GetDefaultBrowserControlPolicy() !=
1829 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 1859 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1830 return false; 1860 return false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 1914
1885 // Send Windows notification event so that it can update icons for 1915 // Send Windows notification event so that it can update icons for
1886 // file associations. 1916 // file associations.
1887 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1917 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1888 return ret; 1918 return ret;
1889 } 1919 }
1890 1920
1891 bool ShellUtil::ShowMakeChromeDefaultSystemUI( 1921 bool ShellUtil::ShowMakeChromeDefaultSystemUI(
1892 BrowserDistribution* dist, 1922 BrowserDistribution* dist,
1893 const base::FilePath& chrome_exe) { 1923 const base::FilePath& chrome_exe) {
1894 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); 1924 DCHECK(!CanMakeChromeDefaultUnattended());
1895 if (dist->GetDefaultBrowserControlPolicy() != 1925 if (dist->GetDefaultBrowserControlPolicy() !=
1896 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 1926 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1897 return false; 1927 return false;
1898 } 1928 }
1899 1929
1900 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true)) 1930 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true))
1901 return false; 1931 return false;
1902 1932
1903 bool succeeded = true; 1933 bool succeeded = true;
1904 bool is_default = (GetChromeDefaultState() == IS_DEFAULT); 1934 bool is_default = (GetChromeDefaultState() == IS_DEFAULT);
1905 if (!is_default) { 1935 if (!is_default) {
1906 if (base::win::GetVersion() < base::win::VERSION_WIN10) { 1936 switch (GetInteractiveSetDefaultMode()) {
1907 // On Windows 8, you can't set yourself as the default handler 1937 case INTENT_PICKER: {
1908 // programatically. In other words IApplicationAssociationRegistration 1938 // On Windows 8, you can't set yourself as the default handler
1909 // has been rendered useless. What you can do is to launch 1939 // programatically. In other words IApplicationAssociationRegistration
1910 // "Set Program Associations" section of the "Default Programs" 1940 // has been rendered useless. What you can do is to launch
1911 // control panel, which is a mess, or pop the concise "How you want to 1941 // "Set Program Associations" section of the "Default Programs"
1912 // open webpages?" dialog. We choose the latter. 1942 // control panel, which is a mess, or pop the concise "How you want to
1913 ScopedUserProtocolEntry user_protocol_entry; 1943 // open webpages?" dialog. We choose the latter.
1914 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); 1944 ScopedUserProtocolEntry user_protocol_entry(L"http");
1915 } else { 1945 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http");
1916 // On Windows 10, you can't even launch the associations dialog. 1946 } break;
1917 // So we launch the settings dialog. Quoting from MSDN: "The Open With 1947 case SYSTEM_SETTINGS:
1918 // dialog box can no longer be used to change the default program used to 1948 // On Windows 10, you can't even launch the associations dialog.
1919 // open a file extension. You can only use SHOpenWithDialog to open 1949 // So we launch the settings dialog. Quoting from MSDN: "The Open With
1920 // a single file." 1950 // dialog box can no longer be used to change the default program used
1921 succeeded = LaunchDefaultAppsSettingsModernDialog(); 1951 // to open a file extension. You can only use SHOpenWithDialog to open
1952 // a single file."
1953 succeeded = LaunchDefaultAppsSettingsModernDialog(L"http");
1954 break;
1922 } 1955 }
1923 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); 1956 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT);
1924 } 1957 }
1925 if (succeeded && is_default) 1958 if (succeeded && is_default)
1926 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe); 1959 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe);
1927 return succeeded; 1960 return succeeded;
1928 } 1961 }
1929 1962
1930 bool ShellUtil::MakeChromeDefaultProtocolClient( 1963 bool ShellUtil::MakeChromeDefaultProtocolClient(
1931 BrowserDistribution* dist, 1964 BrowserDistribution* dist,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol)) 2006 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol))
1974 ret = false; 2007 ret = false;
1975 2008
1976 return ret; 2009 return ret;
1977 } 2010 }
1978 2011
1979 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( 2012 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(
1980 BrowserDistribution* dist, 2013 BrowserDistribution* dist,
1981 const base::FilePath& chrome_exe, 2014 const base::FilePath& chrome_exe,
1982 const base::string16& protocol) { 2015 const base::string16& protocol) {
1983 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); 2016 DCHECK(!CanMakeChromeDefaultUnattended());
1984 if (dist->GetDefaultBrowserControlPolicy() != 2017 if (dist->GetDefaultBrowserControlPolicy() !=
1985 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 2018 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1986 return false; 2019 return false;
1987 } 2020 }
1988 2021
1989 if (!RegisterChromeForProtocol( 2022 if (!RegisterChromeForProtocol(
1990 dist, chrome_exe, base::string16(), protocol, true)) 2023 dist, chrome_exe, base::string16(), protocol, true))
1991 return false; 2024 return false;
1992 2025
1993 bool succeeded = true; 2026 bool succeeded = true;
1994 bool is_default = ( 2027 bool is_default = (
1995 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); 2028 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT);
1996 if (!is_default) { 2029 if (!is_default) {
1997 // On Windows 8, you can't set yourself as the default handler 2030 switch (GetInteractiveSetDefaultMode()) {
1998 // programatically. In other words IApplicationAssociationRegistration 2031 case INTENT_PICKER: {
1999 // has been rendered useless. What you can do is to launch 2032 // On Windows 8, you can't set yourself as the default handler
2000 // "Set Program Associations" section of the "Default Programs" 2033 // programatically. In other words IApplicationAssociationRegistration
2001 // control panel, which is a mess, or pop the concise "How you want to open 2034 // has been rendered useless. What you can do is to launch
2002 // links of this type (protocol)?" dialog. We choose the latter. 2035 // "Set Program Associations" section of the "Default Programs"
2003 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); 2036 // control panel, which is a mess, or pop the concise "How you want to
2037 // open
2038 // links of this type (protocol)?" dialog. We choose the latter.
2039 ScopedUserProtocolEntry user_protocol_entry(protocol.c_str());
2040 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str());
2041 } break;
2042 case SYSTEM_SETTINGS:
2043 // On Windows 10, you can't even launch the associations dialog.
2044 // So we launch the settings dialog.
2045 succeeded = LaunchDefaultAppsSettingsModernDialog(protocol.c_str());
2046 break;
2047 }
2004 is_default = (succeeded && 2048 is_default = (succeeded &&
2005 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); 2049 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT);
2006 } 2050 }
2007 if (succeeded && is_default) 2051 if (succeeded && is_default)
2008 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol); 2052 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol);
2009 return succeeded; 2053 return succeeded;
2010 } 2054 }
2011 2055
2012 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, 2056 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist,
2013 const base::FilePath& chrome_exe, 2057 const base::FilePath& chrome_exe,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 itr != entries.end(); ++itr) 2387 itr != entries.end(); ++itr)
2344 (*itr)->AddToWorkItemList(root, items.get()); 2388 (*itr)->AddToWorkItemList(root, items.get());
2345 2389
2346 // Apply all the registry changes and if there is a problem, rollback 2390 // Apply all the registry changes and if there is a problem, rollback
2347 if (!items->Do()) { 2391 if (!items->Do()) {
2348 items->Rollback(); 2392 items->Rollback();
2349 return false; 2393 return false;
2350 } 2394 }
2351 return true; 2395 return true;
2352 } 2396 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698