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" |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
| 13 #include <objbase.h> |
13 #include <shlobj.h> | 14 #include <shlobj.h> |
14 #include <shobjidl.h> | 15 #include <shobjidl.h> |
15 | 16 |
16 #include <algorithm> | 17 #include <algorithm> |
17 #include <iterator> | 18 #include <iterator> |
18 #include <limits> | 19 #include <limits> |
19 #include <memory> | 20 #include <memory> |
20 #include <string> | 21 #include <string> |
21 #include <utility> | 22 #include <utility> |
22 | 23 |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 // focused. This only works for Windows 8 and Windows 10. The appModelId | 752 // focused. This only works for Windows 8 and Windows 10. The appModelId |
752 // looks arbitrary but it is the same in Win8 and Win10. There is no easy way to | 753 // looks arbitrary but it is the same in Win8 and Win10. There is no easy way to |
753 // retrieve the appModelId from the registry. | 754 // retrieve the appModelId from the registry. |
754 bool LaunchDefaultAppsSettingsModernDialog(const wchar_t* protocol) { | 755 bool LaunchDefaultAppsSettingsModernDialog(const wchar_t* protocol) { |
755 DCHECK(protocol); | 756 DCHECK(protocol); |
756 static const wchar_t kControlPanelAppModelId[] = | 757 static const wchar_t kControlPanelAppModelId[] = |
757 L"windows.immersivecontrolpanel_cw5n1h2txyewy" | 758 L"windows.immersivecontrolpanel_cw5n1h2txyewy" |
758 L"!microsoft.windows.immersivecontrolpanel"; | 759 L"!microsoft.windows.immersivecontrolpanel"; |
759 | 760 |
760 base::win::ScopedComPtr<IApplicationActivationManager> activator; | 761 base::win::ScopedComPtr<IApplicationActivationManager> activator; |
761 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | 762 HRESULT hr = ::CoCreateInstance(CLSID_ApplicationActivationManager, nullptr, |
| 763 CLSCTX_ALL, IID_PPV_ARGS(&activator)); |
762 if (SUCCEEDED(hr)) { | 764 if (SUCCEEDED(hr)) { |
763 DWORD pid = 0; | 765 DWORD pid = 0; |
764 CoAllowSetForegroundWindow(activator.Get(), nullptr); | 766 CoAllowSetForegroundWindow(activator.Get(), nullptr); |
765 hr = activator->ActivateApplication(kControlPanelAppModelId, | 767 hr = activator->ActivateApplication(kControlPanelAppModelId, |
766 L"page=SettingsPageAppsDefaults", | 768 L"page=SettingsPageAppsDefaults", |
767 AO_NONE, &pid); | 769 AO_NONE, &pid); |
768 if (SUCCEEDED(hr)) { | 770 if (SUCCEEDED(hr)) { |
769 hr = activator->ActivateApplication( | 771 hr = activator->ActivateApplication( |
770 kControlPanelAppModelId, | 772 kControlPanelAppModelId, |
771 base::StringPrintf(L"page=SettingsPageAppsDefaults&target=%ls", | 773 base::StringPrintf(L"page=SettingsPageAppsDefaults&target=%ls", |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 // (Windows 8); see ProbeProtocolHandlers. This mechanism is not suitable for | 1043 // (Windows 8); see ProbeProtocolHandlers. This mechanism is not suitable for |
1042 // use on previous versions of Windows despite the presence of | 1044 // use on previous versions of Windows despite the presence of |
1043 // QueryCurrentDefault on them since versions of Windows prior to Windows 8 | 1045 // QueryCurrentDefault on them since versions of Windows prior to Windows 8 |
1044 // did not perform validation on the ProgID registered as the current default. | 1046 // did not perform validation on the ProgID registered as the current default. |
1045 // As a result, stale ProgIDs could be returned, leading to false positives. | 1047 // As a result, stale ProgIDs could be returned, leading to false positives. |
1046 ShellUtil::DefaultState ProbeCurrentDefaultHandlers( | 1048 ShellUtil::DefaultState ProbeCurrentDefaultHandlers( |
1047 const base::FilePath& chrome_exe, | 1049 const base::FilePath& chrome_exe, |
1048 const wchar_t* const* protocols, | 1050 const wchar_t* const* protocols, |
1049 size_t num_protocols) { | 1051 size_t num_protocols) { |
1050 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; | 1052 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; |
1051 HRESULT hr = registration.CreateInstance( | 1053 HRESULT hr = |
1052 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); | 1054 ::CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, |
| 1055 CLSCTX_INPROC, IID_PPV_ARGS(®istration)); |
1053 if (FAILED(hr)) | 1056 if (FAILED(hr)) |
1054 return ShellUtil::UNKNOWN_DEFAULT; | 1057 return ShellUtil::UNKNOWN_DEFAULT; |
1055 | 1058 |
1056 base::string16 prog_id(install_static::GetProgIdPrefix()); | 1059 base::string16 prog_id(install_static::GetProgIdPrefix()); |
1057 prog_id += ShellUtil::GetCurrentInstallationSuffix(chrome_exe); | 1060 prog_id += ShellUtil::GetCurrentInstallationSuffix(chrome_exe); |
1058 | 1061 |
1059 for (size_t i = 0; i < num_protocols; ++i) { | 1062 for (size_t i = 0; i < num_protocols; ++i) { |
1060 base::win::ScopedCoMem<wchar_t> current_app; | 1063 base::win::ScopedCoMem<wchar_t> current_app; |
1061 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, | 1064 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, |
1062 AL_EFFECTIVE, ¤t_app); | 1065 AL_EFFECTIVE, ¤t_app); |
1063 if (FAILED(hr) || prog_id.compare(current_app) != 0) | 1066 if (FAILED(hr) || prog_id.compare(current_app) != 0) |
1064 return ShellUtil::NOT_DEFAULT; | 1067 return ShellUtil::NOT_DEFAULT; |
1065 } | 1068 } |
1066 | 1069 |
1067 return ShellUtil::IS_DEFAULT; | 1070 return ShellUtil::IS_DEFAULT; |
1068 } | 1071 } |
1069 | 1072 |
1070 // Probe using IApplicationAssociationRegistration::QueryAppIsDefault (Vista and | 1073 // Probe using IApplicationAssociationRegistration::QueryAppIsDefault (Vista and |
1071 // Windows 7); see ProbeProtocolHandlers. | 1074 // Windows 7); see ProbeProtocolHandlers. |
1072 ShellUtil::DefaultState ProbeAppIsDefaultHandlers( | 1075 ShellUtil::DefaultState ProbeAppIsDefaultHandlers( |
1073 const base::FilePath& chrome_exe, | 1076 const base::FilePath& chrome_exe, |
1074 const wchar_t* const* protocols, | 1077 const wchar_t* const* protocols, |
1075 size_t num_protocols) { | 1078 size_t num_protocols) { |
1076 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; | 1079 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; |
1077 HRESULT hr = registration.CreateInstance( | 1080 HRESULT hr = |
1078 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); | 1081 ::CoCreateInstance(CLSID_ApplicationAssociationRegistration, NULL, |
| 1082 CLSCTX_INPROC, IID_PPV_ARGS(®istration)); |
1079 if (FAILED(hr)) | 1083 if (FAILED(hr)) |
1080 return ShellUtil::UNKNOWN_DEFAULT; | 1084 return ShellUtil::UNKNOWN_DEFAULT; |
1081 | 1085 |
1082 base::string16 app_name(GetApplicationName(chrome_exe)); | 1086 base::string16 app_name(GetApplicationName(chrome_exe)); |
1083 | 1087 |
1084 BOOL result; | 1088 BOOL result; |
1085 for (size_t i = 0; i < num_protocols; ++i) { | 1089 for (size_t i = 0; i < num_protocols; ++i) { |
1086 result = TRUE; | 1090 result = TRUE; |
1087 hr = registration->QueryAppIsDefault(protocols[i], AT_URLPROTOCOL, | 1091 hr = registration->QueryAppIsDefault(protocols[i], AT_URLPROTOCOL, |
1088 AL_EFFECTIVE, app_name.c_str(), &result); | 1092 AL_EFFECTIVE, app_name.c_str(), &result); |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 bool ret = true; | 1874 bool ret = true; |
1871 // First use the new "recommended" way on Vista to make Chrome default | 1875 // First use the new "recommended" way on Vista to make Chrome default |
1872 // browser. | 1876 // browser. |
1873 base::string16 app_name = GetApplicationName(chrome_exe); | 1877 base::string16 app_name = GetApplicationName(chrome_exe); |
1874 | 1878 |
1875 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1879 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1876 // On Windows Vista and Win7 we still can set ourselves via the | 1880 // On Windows Vista and Win7 we still can set ourselves via the |
1877 // the IApplicationAssociationRegistration interface. | 1881 // the IApplicationAssociationRegistration interface. |
1878 VLOG(1) << "Registering Chrome as default browser on Vista."; | 1882 VLOG(1) << "Registering Chrome as default browser on Vista."; |
1879 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1883 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
1880 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1884 HRESULT hr = ::CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
1881 NULL, CLSCTX_INPROC); | 1885 NULL, CLSCTX_INPROC, IID_PPV_ARGS(&pAAR)); |
1882 if (SUCCEEDED(hr)) { | 1886 if (SUCCEEDED(hr)) { |
1883 for (int i = 0; kBrowserProtocolAssociations[i] != NULL; i++) { | 1887 for (int i = 0; kBrowserProtocolAssociations[i] != NULL; i++) { |
1884 hr = pAAR->SetAppAsDefault(app_name.c_str(), | 1888 hr = pAAR->SetAppAsDefault(app_name.c_str(), |
1885 kBrowserProtocolAssociations[i], AT_URLPROTOCOL); | 1889 kBrowserProtocolAssociations[i], AT_URLPROTOCOL); |
1886 if (!SUCCEEDED(hr)) { | 1890 if (!SUCCEEDED(hr)) { |
1887 ret = false; | 1891 ret = false; |
1888 LOG(ERROR) << "Failed to register as default for protocol " | 1892 LOG(ERROR) << "Failed to register as default for protocol " |
1889 << kBrowserProtocolAssociations[i] | 1893 << kBrowserProtocolAssociations[i] |
1890 << " (" << hr << ")"; | 1894 << " (" << hr << ")"; |
1891 } | 1895 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 if (!CanMakeChromeDefaultUnattended()) | 1981 if (!CanMakeChromeDefaultUnattended()) |
1978 return false; | 1982 return false; |
1979 | 1983 |
1980 bool ret = true; | 1984 bool ret = true; |
1981 // First use the new "recommended" way on Vista to make Chrome default | 1985 // First use the new "recommended" way on Vista to make Chrome default |
1982 // protocol handler. | 1986 // protocol handler. |
1983 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1987 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1984 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1988 VLOG(1) << "Registering Chrome as default handler for " << protocol |
1985 << " on Vista."; | 1989 << " on Vista."; |
1986 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1990 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
1987 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1991 HRESULT hr = ::CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
1988 NULL, CLSCTX_INPROC); | 1992 NULL, CLSCTX_INPROC, IID_PPV_ARGS(&pAAR)); |
1989 if (SUCCEEDED(hr)) { | 1993 if (SUCCEEDED(hr)) { |
1990 base::string16 app_name = GetApplicationName(chrome_exe); | 1994 base::string16 app_name = GetApplicationName(chrome_exe); |
1991 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1995 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
1992 AT_URLPROTOCOL); | 1996 AT_URLPROTOCOL); |
1993 } | 1997 } |
1994 if (!SUCCEEDED(hr)) { | 1998 if (!SUCCEEDED(hr)) { |
1995 ret = false; | 1999 ret = false; |
1996 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 2000 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
1997 << " HRESULT=" << hr << "."; | 2001 << " HRESULT=" << hr << "."; |
1998 } | 2002 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 for (const auto& entry : entries) | 2348 for (const auto& entry : entries) |
2345 entry->AddToWorkItemList(root, items.get()); | 2349 entry->AddToWorkItemList(root, items.get()); |
2346 | 2350 |
2347 // Apply all the registry changes and if there is a problem, rollback | 2351 // Apply all the registry changes and if there is a problem, rollback |
2348 if (!items->Do()) { | 2352 if (!items->Do()) { |
2349 items->Rollback(); | 2353 items->Rollback(); |
2350 return false; | 2354 return false; |
2351 } | 2355 } |
2352 return true; | 2356 return true; |
2353 } | 2357 } |
OLD | NEW |