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

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

Issue 1140293002: Improve the default browser settings dialog for Win10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 5 years, 7 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"
11 11
12 #include <windows.h> 12 #include <windows.h>
13 #include <shlobj.h> 13 #include <shlobj.h>
14 #include <shobjidl.h>
14 15
15 #include <limits> 16 #include <limits>
16 #include <string> 17 #include <string>
17 18
18 #include "base/bind.h" 19 #include "base/bind.h"
19 #include "base/command_line.h" 20 #include "base/command_line.h"
20 #include "base/files/file_enumerator.h" 21 #include "base/files/file_enumerator.h"
21 #include "base/files/file_path.h" 22 #include "base/files/file_path.h"
22 #include "base/files/file_util.h" 23 #include "base/files/file_util.h"
23 #include "base/lazy_instance.h" 24 #include "base/lazy_instance.h"
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 } 870 }
870 871
871 DWORD ret_val = 0; 872 DWORD ret_val = 0;
872 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val); 873 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val);
873 if (ret_val == 0) 874 if (ret_val == 0)
874 return true; 875 return true;
875 } 876 }
876 return false; 877 return false;
877 } 878 }
878 879
880 // Launches the Windows 'settings' modern app with the 'default apps' view
881 // focused. This only works for Windows 8 and Windows 10. The appModelId
882 // looks arbitrary but it is the same in Win8 and Win10 previews. There
883 // is no easy way to retrieve the appModelId from the registry.
884 bool LaunchDefaultAppsSettingsModernDialog() {
885 base::win::ScopedComPtr<IApplicationActivationManager> activator;
886 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager);
887 if (SUCCEEDED(hr)) {
888 DWORD pid = 0;
889 CoAllowSetForegroundWindow(activator.get(), nullptr);
890 hr = activator->ActivateApplication(
891 L"windows.immersivecontrolpanel_cw5n1h2txyewy"
892 L"!microsoft.windows.immersivecontrolpanel",
893 L"page=SettingsPageAppsDefaults", AO_NONE, &pid);
894 return SUCCEEDED(hr);
895 }
896 return false;
897 }
898
879 // Launches the Windows 7 and Windows 8 dialog for picking the application to 899 // Launches the Windows 7 and Windows 8 dialog for picking the application to
880 // handle the given protocol. Most importantly, this is used to set the default 900 // handle the given protocol. Most importantly, this is used to set the default
881 // handler for http (and, implicitly with it, https). In that case it is also 901 // handler for http (and, implicitly with it, https). In that case it is also
882 // known as the 'how do you want to open webpages' dialog. 902 // known as the 'how do you want to open webpages' dialog.
883 // It is required that Chrome be already *registered* for the given protocol. 903 // It is required that Chrome be already *registered* for the given protocol.
884 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) { 904 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) {
885 DCHECK(protocol); 905 DCHECK(protocol);
886 OPENASINFO open_as_info = {}; 906 OPENASINFO open_as_info = {};
887 open_as_info.pcszFile = protocol; 907 open_as_info.pcszFile = protocol;
888 open_as_info.oaifInFlags = 908 open_as_info.oaifInFlags =
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { 2074 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) {
2055 return false; 2075 return false;
2056 } 2076 }
2057 2077
2058 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true)) 2078 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true))
2059 return false; 2079 return false;
2060 2080
2061 bool succeeded = true; 2081 bool succeeded = true;
2062 bool is_default = (GetChromeDefaultState() == IS_DEFAULT); 2082 bool is_default = (GetChromeDefaultState() == IS_DEFAULT);
2063 if (!is_default) { 2083 if (!is_default) {
2064 // On Windows 8, you can't set yourself as the default handler 2084 if (base::win::GetVersion() < base::win::VERSION_WIN10) {
2065 // programatically. In other words IApplicationAssociationRegistration 2085 // On Windows 8, you can't set yourself as the default handler
2066 // has been rendered useless. What you can do is to launch 2086 // programatically. In other words IApplicationAssociationRegistration
2067 // "Set Program Associations" section of the "Default Programs" 2087 // has been rendered useless. What you can do is to launch
2068 // control panel, which is a mess, or pop the concise "How you want to open 2088 // "Set Program Associations" section of the "Default Programs"
2069 // webpages?" dialog. We choose the latter. 2089 // control panel, which is a mess, or pop the concise "How you want to
2070 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); 2090 // open webpages?" dialog. We choose the latter.
2091 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http");
2092 } else {
2093 // On Windows 10, you can't even launch the associations dialog.
2094 // So we launch the settings dialog. Quoting from MSDN: "The Open With
2095 // dialog box can no longer be used to change the default program used to
2096 // open a file extension. You can only use SHOpenWithDialog to open
2097 // a single file."
2098 succeeded = LaunchDefaultAppsSettingsModernDialog();
2099 }
2071 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); 2100 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT);
2072 } 2101 }
2073 if (succeeded && is_default) 2102 if (succeeded && is_default)
2074 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe); 2103 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe);
2075 return succeeded; 2104 return succeeded;
2076 } 2105 }
2077 2106
2078 bool ShellUtil::MakeChromeDefaultProtocolClient( 2107 bool ShellUtil::MakeChromeDefaultProtocolClient(
2079 BrowserDistribution* dist, 2108 BrowserDistribution* dist,
2080 const base::FilePath& chrome_exe, 2109 const base::FilePath& chrome_exe,
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 base::string16 key_path(ShellUtil::kRegClasses); 2509 base::string16 key_path(ShellUtil::kRegClasses);
2481 key_path.push_back(base::FilePath::kSeparators[0]); 2510 key_path.push_back(base::FilePath::kSeparators[0]);
2482 key_path.append(prog_id); 2511 key_path.append(prog_id);
2483 return InstallUtil::DeleteRegistryKey( 2512 return InstallUtil::DeleteRegistryKey(
2484 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); 2513 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default);
2485 2514
2486 // TODO(mgiuca): Remove the extension association entries. This requires that 2515 // TODO(mgiuca): Remove the extension association entries. This requires that
2487 // the extensions associated with a particular prog_id are stored in that 2516 // the extensions associated with a particular prog_id are stored in that
2488 // prog_id's key. 2517 // prog_id's key.
2489 } 2518 }
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