Chromium Code Reviews| Index: chrome/installer/util/shell_util.cc |
| diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc |
| index acff489d78441011d3fe5ea115e82576981d484c..5ba4aabe16892e80a49ccf2716b9d49bfe24e8bf 100644 |
| --- a/chrome/installer/util/shell_util.cc |
| +++ b/chrome/installer/util/shell_util.cc |
| @@ -876,6 +876,25 @@ bool ElevateAndRegisterChrome(BrowserDistribution* dist, |
| return false; |
| } |
| +// Launches the Windows 'settings' modern app with the 'default apps' view |
| +// focused. This only works for Windows 8 and and. The appModelId |
| +// looks arbitrary but it is the same in Win8 and Win10 previews. There |
| +// is no easy way to retrieve the appModelId from the registry. |
| +bool LaunchDefaultAppsSettingsModernDialog() { |
| + base::win::ScopedComPtr<IApplicationActivationManager> activator; |
|
Will Harris
2015/05/16 05:04:02
msdn says this needs shobjidl.h included
|
| + HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); |
| + if (SUCCEEDED(hr)) { |
| + DWORD pid = 0; |
| + CoAllowSetForegroundWindow(activator.get(), nullptr); |
| + hr = activator->ActivateApplication( |
| + L"windows.immersivecontrolpanel_cw5n1h2txyewy" |
| + L"!microsoft.windows.immersivecontrolpanel", |
| + L"page=SettingsPageAppsDefaults", AO_NONE, &pid); |
| + return SUCCEEDED(hr); |
| + } |
| + return false; |
| +} |
| + |
| // Launches the Windows 7 and Windows 8 dialog for picking the application to |
| // handle the given protocol. Most importantly, this is used to set the default |
| // handler for http (and, implicitly with it, https). In that case it is also |
| @@ -2061,13 +2080,22 @@ bool ShellUtil::ShowMakeChromeDefaultSystemUI( |
| bool succeeded = true; |
| bool is_default = (GetChromeDefaultState() == IS_DEFAULT); |
| if (!is_default) { |
| - // On Windows 8, you can't set yourself as the default handler |
| - // programatically. In other words IApplicationAssociationRegistration |
| - // has been rendered useless. What you can do is to launch |
| - // "Set Program Associations" section of the "Default Programs" |
| - // control panel, which is a mess, or pop the concise "How you want to open |
| - // webpages?" dialog. We choose the latter. |
| - succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); |
| + if (base::win::GetVersion() < base::win::VERSION_WIN10) { |
| + // On Windows 8, you can't set yourself as the default handler |
| + // programatically. In other words IApplicationAssociationRegistration |
| + // has been rendered useless. What you can do is to launch |
| + // "Set Program Associations" section of the "Default Programs" |
| + // control panel, which is a mess, or pop the concise "How you want to |
| + // open webpages?" dialog. We choose the latter. |
| + succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); |
| + } else { |
| + // On Windows 10, you can't even launch the associations dialog. |
| + // So we launch the settings dialog. Quoting from MSDN: "The Open With |
| + // dialog box can no longer be used to change the default program used to |
| + // open a file extension. You can only use SHOpenWithDialog to open |
| + // a single file." |
| + succeeded = LaunchDefaultAppsSettingsModernDialog(); |
| + } |
| is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); |
| } |
| if (succeeded && is_default) |