Commit 8707fef0 authored by cpu's avatar cpu Committed by Commit bot

Improve the default browser settings dialog for Win10

On Win10 the current approach of SHOpenWithDialog is suboptimal. See
the bug for more details.

BUG=488774,489803

Review URL: https://codereview.chromium.org/1140293002

Cr-Commit-Position: refs/heads/master@{#330596}
parent e860606d
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <windows.h> #include <windows.h>
#include <shlobj.h> #include <shlobj.h>
#include <shobjidl.h>
#include <limits> #include <limits>
#include <string> #include <string>
...@@ -876,6 +877,25 @@ bool ElevateAndRegisterChrome(BrowserDistribution* dist, ...@@ -876,6 +877,25 @@ bool ElevateAndRegisterChrome(BrowserDistribution* dist,
return false; return false;
} }
// Launches the Windows 'settings' modern app with the 'default apps' view
// focused. This only works for Windows 8 and Windows 10. 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;
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 // 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 // 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 // handler for http (and, implicitly with it, https). In that case it is also
...@@ -2061,13 +2081,22 @@ bool ShellUtil::ShowMakeChromeDefaultSystemUI( ...@@ -2061,13 +2081,22 @@ bool ShellUtil::ShowMakeChromeDefaultSystemUI(
bool succeeded = true; bool succeeded = true;
bool is_default = (GetChromeDefaultState() == IS_DEFAULT); bool is_default = (GetChromeDefaultState() == IS_DEFAULT);
if (!is_default) { if (!is_default) {
// On Windows 8, you can't set yourself as the default handler if (base::win::GetVersion() < base::win::VERSION_WIN10) {
// programatically. In other words IApplicationAssociationRegistration // On Windows 8, you can't set yourself as the default handler
// has been rendered useless. What you can do is to launch // programatically. In other words IApplicationAssociationRegistration
// "Set Program Associations" section of the "Default Programs" // has been rendered useless. What you can do is to launch
// control panel, which is a mess, or pop the concise "How you want to open // "Set Program Associations" section of the "Default Programs"
// webpages?" dialog. We choose the latter. // control panel, which is a mess, or pop the concise "How you want to
succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); // 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); is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT);
} }
if (succeeded && is_default) if (succeeded && is_default)
......
...@@ -445,11 +445,15 @@ class ShellUtil { ...@@ -445,11 +445,15 @@ class ShellUtil {
const base::FilePath& chrome_exe, const base::FilePath& chrome_exe,
bool elevate_if_not_admin); bool elevate_if_not_admin);
// Shows and waits for the Windows 8 "How do you want to open webpages?" // Windows 8: Shows and waits for the "How do you want to open webpages?"
// dialog if Chrome is not already the default HTTP/HTTPS handler. Also does // dialog if Chrome is not already the default HTTP/HTTPS handler. Also does
// XP-era registrations if Chrome is chosen or was already the default. Do // XP-era registrations if Chrome is chosen or was already the default. Do
// not use on pre-Win8 OSes. // not use on pre-Win8 OSes.
// //
// Windows 10: The associations dialog cannot be launched so the settings
// dialog focused on default apps is launched. The function does not wait
// in this case.
//
// |dist| gives the type of browser distribution currently in use. // |dist| gives the type of browser distribution currently in use.
// |chrome_exe| The chrome.exe path to register as default browser. // |chrome_exe| The chrome.exe path to register as default browser.
static bool ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist, static bool ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment