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

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: grt comments 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
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))
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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 return ProbeProtocolHandlers(chrome_exe, 1828 return ProbeProtocolHandlers(chrome_exe,
1809 protocols, 1829 protocols,
1810 arraysize(protocols)); 1830 arraysize(protocols));
1811 } 1831 }
1812 1832
1813 // static 1833 // static
1814 bool ShellUtil::CanMakeChromeDefaultUnattended() { 1834 bool ShellUtil::CanMakeChromeDefaultUnattended() {
1815 return base::win::GetVersion() < base::win::VERSION_WIN8; 1835 return base::win::GetVersion() < base::win::VERSION_WIN8;
1816 } 1836 }
1817 1837
1838 // static
1839 ShellUtil::InteractiveSetDefaultMode ShellUtil::GetInteractiveSetDefaultMode() {
1840 DCHECK(!CanMakeChromeDefaultUnattended());
1841
1842 if (base::win::GetVersion() == base::win::VERSION_WIN8)
1843 return InteractiveSetDefaultMode::INTENT_PICKER;
1844
1845 return InteractiveSetDefaultMode::SYSTEM_SETTINGS;
1846 }
1847
1818 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 1848 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
1819 int shell_change, 1849 int shell_change,
1820 const base::FilePath& chrome_exe, 1850 const base::FilePath& chrome_exe,
1821 bool elevate_if_not_admin) { 1851 bool elevate_if_not_admin) {
1822 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin()); 1852 DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin());
1823 1853
1824 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); 1854 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
1825 if (distribution->GetDefaultBrowserControlPolicy() != 1855 if (distribution->GetDefaultBrowserControlPolicy() !=
1826 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 1856 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1827 return false; 1857 return false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 1911
1882 // Send Windows notification event so that it can update icons for 1912 // Send Windows notification event so that it can update icons for
1883 // file associations. 1913 // file associations.
1884 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1914 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1885 return ret; 1915 return ret;
1886 } 1916 }
1887 1917
1888 bool ShellUtil::ShowMakeChromeDefaultSystemUI( 1918 bool ShellUtil::ShowMakeChromeDefaultSystemUI(
1889 BrowserDistribution* dist, 1919 BrowserDistribution* dist,
1890 const base::FilePath& chrome_exe) { 1920 const base::FilePath& chrome_exe) {
1891 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); 1921 DCHECK(!CanMakeChromeDefaultUnattended());
1892 if (dist->GetDefaultBrowserControlPolicy() != 1922 if (dist->GetDefaultBrowserControlPolicy() !=
1893 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 1923 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1894 return false; 1924 return false;
1895 } 1925 }
1896 1926
1897 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true)) 1927 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true))
1898 return false; 1928 return false;
1899 1929
1900 bool succeeded = true; 1930 bool succeeded = true;
1901 bool is_default = (GetChromeDefaultState() == IS_DEFAULT); 1931 bool is_default = (GetChromeDefaultState() == IS_DEFAULT);
1902 if (!is_default) { 1932 if (!is_default) {
1903 if (base::win::GetVersion() < base::win::VERSION_WIN10) { 1933 switch (GetInteractiveSetDefaultMode()) {
1904 // On Windows 8, you can't set yourself as the default handler 1934 case INTENT_PICKER: {
1905 // programatically. In other words IApplicationAssociationRegistration 1935 // On Windows 8, you can't set yourself as the default handler
1906 // has been rendered useless. What you can do is to launch 1936 // programatically. In other words IApplicationAssociationRegistration
1907 // "Set Program Associations" section of the "Default Programs" 1937 // has been rendered useless. What you can do is to launch
1908 // control panel, which is a mess, or pop the concise "How you want to 1938 // "Set Program Associations" section of the "Default Programs"
1909 // open webpages?" dialog. We choose the latter. 1939 // control panel, which is a mess, or pop the concise "How you want to
1910 ScopedUserProtocolEntry user_protocol_entry; 1940 // open webpages?" dialog. We choose the latter.
1911 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); 1941 ScopedUserProtocolEntry user_protocol_entry(L"http");
1912 } else { 1942 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http");
1913 // On Windows 10, you can't even launch the associations dialog. 1943 } break;
1914 // So we launch the settings dialog. Quoting from MSDN: "The Open With 1944 case SYSTEM_SETTINGS:
1915 // dialog box can no longer be used to change the default program used to 1945 // On Windows 10, you can't even launch the associations dialog.
1916 // open a file extension. You can only use SHOpenWithDialog to open 1946 // So we launch the settings dialog. Quoting from MSDN: "The Open With
1917 // a single file." 1947 // dialog box can no longer be used to change the default program used
1918 succeeded = LaunchDefaultAppsSettingsModernDialog(); 1948 // to open a file extension. You can only use SHOpenWithDialog to open
1949 // a single file."
1950 succeeded = LaunchDefaultAppsSettingsModernDialog(L"http");
1951 break;
1919 } 1952 }
1920 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); 1953 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT);
1921 } 1954 }
1922 if (succeeded && is_default) 1955 if (succeeded && is_default)
1923 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe); 1956 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe);
1924 return succeeded; 1957 return succeeded;
1925 } 1958 }
1926 1959
1927 bool ShellUtil::MakeChromeDefaultProtocolClient( 1960 bool ShellUtil::MakeChromeDefaultProtocolClient(
1928 BrowserDistribution* dist, 1961 BrowserDistribution* dist,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol)) 2003 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol))
1971 ret = false; 2004 ret = false;
1972 2005
1973 return ret; 2006 return ret;
1974 } 2007 }
1975 2008
1976 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( 2009 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(
1977 BrowserDistribution* dist, 2010 BrowserDistribution* dist,
1978 const base::FilePath& chrome_exe, 2011 const base::FilePath& chrome_exe,
1979 const base::string16& protocol) { 2012 const base::string16& protocol) {
1980 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); 2013 DCHECK(!CanMakeChromeDefaultUnattended());
1981 if (dist->GetDefaultBrowserControlPolicy() != 2014 if (dist->GetDefaultBrowserControlPolicy() !=
1982 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 2015 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
1983 return false; 2016 return false;
1984 } 2017 }
1985 2018
1986 if (!RegisterChromeForProtocol( 2019 if (!RegisterChromeForProtocol(
1987 dist, chrome_exe, base::string16(), protocol, true)) 2020 dist, chrome_exe, base::string16(), protocol, true))
1988 return false; 2021 return false;
1989 2022
1990 bool succeeded = true; 2023 bool succeeded = true;
1991 bool is_default = ( 2024 bool is_default = (
1992 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); 2025 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT);
1993 if (!is_default) { 2026 if (!is_default) {
1994 // On Windows 8, you can't set yourself as the default handler 2027 switch (GetInteractiveSetDefaultMode()) {
1995 // programatically. In other words IApplicationAssociationRegistration 2028 case INTENT_PICKER: {
1996 // has been rendered useless. What you can do is to launch 2029 // On Windows 8, you can't set yourself as the default handler
1997 // "Set Program Associations" section of the "Default Programs" 2030 // programatically. In other words IApplicationAssociationRegistration
1998 // control panel, which is a mess, or pop the concise "How you want to open 2031 // has been rendered useless. What you can do is to launch
1999 // links of this type (protocol)?" dialog. We choose the latter. 2032 // "Set Program Associations" section of the "Default Programs"
2000 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); 2033 // control panel, which is a mess, or pop the concise "How you want to
2034 // open
2035 // links of this type (protocol)?" dialog. We choose the latter.
2036 ScopedUserProtocolEntry user_protocol_entry(protocol.c_str());
2037 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str());
2038 } break;
2039 case SYSTEM_SETTINGS:
2040 // On Windows 10, you can't even launch the associations dialog.
2041 // So we launch the settings dialog.
2042 succeeded = LaunchDefaultAppsSettingsModernDialog(protocol.c_str());
2043 break;
2044 }
2001 is_default = (succeeded && 2045 is_default = (succeeded &&
2002 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); 2046 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT);
2003 } 2047 }
2004 if (succeeded && is_default) 2048 if (succeeded && is_default)
2005 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol); 2049 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol);
2006 return succeeded; 2050 return succeeded;
2007 } 2051 }
2008 2052
2009 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, 2053 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist,
2010 const base::FilePath& chrome_exe, 2054 const base::FilePath& chrome_exe,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 itr != entries.end(); ++itr) 2384 itr != entries.end(); ++itr)
2341 (*itr)->AddToWorkItemList(root, items.get()); 2385 (*itr)->AddToWorkItemList(root, items.get());
2342 2386
2343 // Apply all the registry changes and if there is a problem, rollback 2387 // Apply all the registry changes and if there is a problem, rollback
2344 if (!items->Do()) { 2388 if (!items->Do()) {
2345 items->Rollback(); 2389 items->Rollback();
2346 return false; 2390 return false;
2347 } 2391 }
2348 return true; 2392 return true;
2349 } 2393 }
OLDNEW
« chrome/browser/shell_integration_win.cc ('K') | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698