[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 5 | #include "chrome/browser/shell_integration_win.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 6 | |
| 7 | #include <windows.h> |
robliao | a872e99 | 2017-05-18 06:36:19 | [diff] [blame] | 8 | #include <objbase.h> |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 9 | #include <shobjidl.h> |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 10 | #include <propkey.h> // Needs to come after shobjidl.h. |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
Robert Liao | b2bc703d | 2017-10-17 20:52:35 | [diff] [blame] | 13 | #include <wrl/client.h> |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 14 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 15 | #include <memory> |
| 16 | #include <utility> |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 19 | #include "base/bind.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 20 | #include "base/callback.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 21 | #include "base/command_line.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 22 | #include "base/files/file_enumerator.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 23 | #include "base/files/file_util.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 25 | #include "base/metrics/histogram_macros.h" |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 26 | #include "base/metrics/user_metrics.h" |
| 27 | #include "base/metrics/user_metrics_action.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 28 | #include "base/path_service.h" |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 29 | #include "base/stl_util.h" |
[email protected] | 24a555b6 | 2013-06-10 22:01:17 | [diff] [blame] | 30 | #include "base/strings/string_util.h" |
| 31 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 32 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 33 | #include "base/task/post_task.h" |
Etienne Pierre-doray | 6fa6aa5 | 2018-09-27 16:38:12 | [diff] [blame] | 34 | #include "base/threading/scoped_blocking_call.h" |
Etienne Bergeron | 147591d | 2019-06-19 16:40:12 | [diff] [blame] | 35 | #include "base/threading/scoped_thread_priority.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 36 | #include "base/time/time.h" |
| 37 | #include "base/timer/timer.h" |
[email protected] | 2d650398 | 2010-10-17 04:41:54 | [diff] [blame] | 38 | #include "base/win/registry.h" |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 39 | #include "base/win/scoped_propvariant.h" |
Danil Chapovalov | 3518f36 | 2018-08-11 16:13:43 | [diff] [blame] | 40 | #include "base/win/shlwapi.h" |
[email protected] | f1024e2 | 2012-09-12 07:14:55 | [diff] [blame] | 41 | #include "base/win/shortcut.h" |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 42 | #include "base/win/windows_version.h" |
[email protected] | 89d4383 | 2013-06-29 20:25:20 | [diff] [blame] | 43 | #include "chrome/browser/policy/policy_path_parser.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 44 | #include "chrome/browser/shell_integration.h" |
Alexey Baskakov | 2f8bf816 | 2018-07-17 01:06:11 | [diff] [blame] | 45 | #include "chrome/browser/web_applications/components/web_app_helpers.h" |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 46 | #include "chrome/browser/web_applications/components/web_app_shortcut_win.h" |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 47 | #include "chrome/browser/win/settings_app_monitor.h" |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 48 | #include "chrome/browser/win/util_win_service.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 49 | #include "chrome/common/chrome_constants.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 50 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 51 | #include "chrome/common/chrome_switches.h" |
grt | c9880346 | 2017-03-08 10:05:08 | [diff] [blame] | 52 | #include "chrome/install_static/install_util.h" |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 53 | #include "chrome/installer/util/install_util.h" |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 54 | #include "chrome/installer/util/scoped_user_protocol_entry.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 55 | #include "chrome/installer/util/shell_util.h" |
Patrick Monette | afe350c | 2019-01-21 17:59:35 | [diff] [blame] | 56 | #include "chrome/services/util_win/public/mojom/util_win.mojom.h" |
pmonette | 2b1dbee | 2016-01-08 20:18:58 | [diff] [blame] | 57 | #include "components/variations/variations_associated_data.h" |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 58 | #include "mojo/public/cpp/bindings/remote.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 59 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 60 | namespace shell_integration { |
| 61 | |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 62 | namespace { |
| 63 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 64 | // Helper function for GetAppId to generates profile id |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 65 | // from profile path. "profile_id" is composed of sanitized basenames of |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 66 | // user data dir and profile dir joined by a ".". |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 67 | base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 68 | // Return empty string if profile_path is empty |
| 69 | if (profile_path.empty()) |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 70 | return base::string16(); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 71 | |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 72 | // Get joined basenames of user data dir and profile. |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 73 | base::string16 basenames = profile_path.DirName().BaseName().value() + |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 74 | L"." + profile_path.BaseName().value(); |
| 75 | |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 76 | base::string16 profile_id; |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 77 | profile_id.reserve(basenames.size()); |
| 78 | |
| 79 | // Generate profile_id from sanitized basenames. |
| 80 | for (size_t i = 0; i < basenames.length(); ++i) { |
brettw | b341306 | 2015-06-24 00:39:02 | [diff] [blame] | 81 | if (base::IsAsciiAlpha(basenames[i]) || |
| 82 | base::IsAsciiDigit(basenames[i]) || |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 83 | basenames[i] == L'.') |
| 84 | profile_id += basenames[i]; |
| 85 | } |
| 86 | |
| 87 | return profile_id; |
| 88 | } |
| 89 | |
tapted | c2c690ab | 2016-05-25 02:49:03 | [diff] [blame] | 90 | base::string16 GetAppListAppName() { |
| 91 | static const base::char16 kAppListAppNameSuffix[] = L"AppList"; |
grt | c9880346 | 2017-03-08 10:05:08 | [diff] [blame] | 92 | base::string16 app_name(install_static::GetBaseAppId()); |
tapted | c2c690ab | 2016-05-25 02:49:03 | [diff] [blame] | 93 | app_name.append(kAppListAppNameSuffix); |
| 94 | return app_name; |
| 95 | } |
| 96 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 97 | // Gets expected app id for given Chrome (based on |command_line| and |
| 98 | // |is_per_user_install|). |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 99 | base::string16 GetExpectedAppId(const base::CommandLine& command_line, |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 100 | bool is_per_user_install) { |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 101 | base::FilePath user_data_dir; |
| 102 | if (command_line.HasSwitch(switches::kUserDataDir)) |
| 103 | user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir); |
| 104 | else |
| 105 | chrome::GetDefaultUserDataDirectory(&user_data_dir); |
[email protected] | 89d4383 | 2013-06-29 20:25:20 | [diff] [blame] | 106 | // Adjust with any policy that overrides any other way to set the path. |
| 107 | policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 108 | DCHECK(!user_data_dir.empty()); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 109 | |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 110 | base::FilePath profile_subdir; |
| 111 | if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 112 | profile_subdir = |
| 113 | command_line.GetSwitchValuePath(switches::kProfileDirectory); |
| 114 | } else { |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 115 | profile_subdir = |
| 116 | base::FilePath(base::ASCIIToUTF16(chrome::kInitialProfile)); |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 117 | } |
| 118 | DCHECK(!profile_subdir.empty()); |
| 119 | |
| 120 | base::FilePath profile_path = user_data_dir.Append(profile_subdir); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 121 | base::string16 app_name; |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 122 | if (command_line.HasSwitch(switches::kApp)) { |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 123 | app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 124 | GURL(command_line.GetSwitchValueASCII(switches::kApp)))); |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 125 | } else if (command_line.HasSwitch(switches::kAppId)) { |
Alexey Baskakov | 2ce2ffc84 | 2018-08-06 02:57:15 | [diff] [blame] | 126 | app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromAppId( |
| 127 | command_line.GetSwitchValueASCII(switches::kAppId))); |
tapted | c2c690ab | 2016-05-25 02:49:03 | [diff] [blame] | 128 | } else if (command_line.HasSwitch(switches::kShowAppList)) { |
| 129 | app_name = GetAppListAppName(); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 130 | } else { |
grt | c9880346 | 2017-03-08 10:05:08 | [diff] [blame] | 131 | app_name = ShellUtil::GetBrowserModelId(is_per_user_install); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 132 | } |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 133 | DCHECK(!app_name.empty()); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 134 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 135 | return win::GetAppModelIdForProfile(app_name, profile_path); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 136 | } |
| 137 | |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 138 | // Windows treats a given scheme as an Internet scheme only if its registry |
| 139 | // entry has a "URL Protocol" key. Check this, otherwise we allow ProgIDs to be |
| 140 | // used as custom protocols which leads to security bugs. |
| 141 | bool IsValidCustomProtocol(const base::string16& scheme) { |
| 142 | if (scheme.empty()) |
| 143 | return false; |
| 144 | base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, scheme.c_str(), KEY_QUERY_VALUE); |
| 145 | return cmd_key.Valid() && cmd_key.HasValue(L"URL Protocol"); |
| 146 | } |
| 147 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 148 | // Windows 8 introduced a new protocol->executable binding system which cannot |
| 149 | // be retrieved in the HKCR registry subkey method implemented below. We call |
| 150 | // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead. |
| 151 | base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) { |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 152 | const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); |
| 153 | if (!IsValidCustomProtocol(url_scheme)) |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 154 | return base::string16(); |
| 155 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 156 | // Query AssocQueryString for a human-readable description of the program |
| 157 | // that will be invoked given the provided URL spec. This is used only to |
| 158 | // populate the external protocol dialog box the user sees when invoking |
| 159 | // an unknown external protocol. |
| 160 | wchar_t out_buffer[1024]; |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 161 | DWORD buffer_size = base::size(out_buffer); |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 162 | HRESULT hr = |
| 163 | AssocQueryString(ASSOCF_IS_PROTOCOL, ASSOCSTR_FRIENDLYAPPNAME, |
| 164 | url_scheme.c_str(), NULL, out_buffer, &buffer_size); |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 165 | if (FAILED(hr)) { |
| 166 | DLOG(WARNING) << "AssocQueryString failed!"; |
| 167 | return base::string16(); |
| 168 | } |
| 169 | return base::string16(out_buffer); |
| 170 | } |
| 171 | |
| 172 | base::string16 GetAppForProtocolUsingRegistry(const GURL& url) { |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 173 | const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); |
| 174 | if (!IsValidCustomProtocol(url_scheme)) |
| 175 | return base::string16(); |
dominickn | 0c9a506 | 2016-10-06 20:49:00 | [diff] [blame] | 176 | |
| 177 | // First, try and extract the application's display name. |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 178 | base::string16 command_to_launch; |
| 179 | base::win::RegKey cmd_key_name(HKEY_CLASSES_ROOT, url_scheme.c_str(), |
dominickn | 0c9a506 | 2016-10-06 20:49:00 | [diff] [blame] | 180 | KEY_READ); |
| 181 | if (cmd_key_name.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS && |
| 182 | !command_to_launch.empty()) { |
| 183 | return command_to_launch; |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 184 | } |
dominickn | 0c9a506 | 2016-10-06 20:49:00 | [diff] [blame] | 185 | |
| 186 | // Otherwise, parse the command line in the registry, and return the basename |
| 187 | // of the program path if it exists. |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 188 | const base::string16 cmd_key_path = url_scheme + L"\\shell\\open\\command"; |
dominickn | 0c9a506 | 2016-10-06 20:49:00 | [diff] [blame] | 189 | base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), |
| 190 | KEY_READ); |
| 191 | if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) { |
| 192 | base::CommandLine command_line( |
| 193 | base::CommandLine::FromString(command_to_launch)); |
| 194 | return command_line.GetProgram().BaseName().value(); |
| 195 | } |
| 196 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 197 | return base::string16(); |
| 198 | } |
| 199 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 200 | DefaultWebClientState GetDefaultWebClientStateFromShellUtilDefaultState( |
| 201 | ShellUtil::DefaultState default_state) { |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 202 | switch (default_state) { |
Greg Thompson | 75b1c8e | 2017-08-16 13:36:28 | [diff] [blame] | 203 | case ShellUtil::UNKNOWN_DEFAULT: |
| 204 | return DefaultWebClientState::UNKNOWN_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 205 | case ShellUtil::NOT_DEFAULT: |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 206 | return DefaultWebClientState::NOT_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 207 | case ShellUtil::IS_DEFAULT: |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 208 | return DefaultWebClientState::IS_DEFAULT; |
Greg Thompson | 75b1c8e | 2017-08-16 13:36:28 | [diff] [blame] | 209 | case ShellUtil::OTHER_MODE_IS_DEFAULT: |
| 210 | return DefaultWebClientState::OTHER_MODE_IS_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 211 | } |
Greg Thompson | 75b1c8e | 2017-08-16 13:36:28 | [diff] [blame] | 212 | NOTREACHED(); |
| 213 | return DefaultWebClientState::UNKNOWN_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 214 | } |
| 215 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 216 | // A recorder of user actions in the Windows Settings app. |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 217 | class DefaultBrowserActionRecorder : public SettingsAppMonitor::Delegate { |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 218 | public: |
| 219 | // Creates the recorder and the monitor that drives it. |continuation| will be |
| 220 | // run once the monitor's initialization completes (regardless of success or |
| 221 | // failure). |
| 222 | explicit DefaultBrowserActionRecorder(base::Closure continuation) |
| 223 | : continuation_(std::move(continuation)), settings_app_monitor_(this) {} |
| 224 | |
| 225 | private: |
| 226 | // win::SettingsAppMonitor::Delegate: |
| 227 | void OnInitialized(HRESULT result) override { |
Greg Thompson | ea27a2c | 2019-06-25 19:22:22 | [diff] [blame] | 228 | // UMA indicates that this succeeds > 99.98% of the time. |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 229 | if (SUCCEEDED(result)) { |
| 230 | base::RecordAction( |
| 231 | base::UserMetricsAction("SettingsAppMonitor.Initialized")); |
| 232 | } |
| 233 | continuation_.Run(); |
| 234 | continuation_ = base::Closure(); |
| 235 | } |
| 236 | |
| 237 | void OnAppFocused() override { |
| 238 | base::RecordAction( |
| 239 | base::UserMetricsAction("SettingsAppMonitor.AppFocused")); |
| 240 | } |
| 241 | |
| 242 | void OnChooserInvoked() override { |
| 243 | base::RecordAction( |
| 244 | base::UserMetricsAction("SettingsAppMonitor.ChooserInvoked")); |
| 245 | } |
| 246 | |
| 247 | void OnBrowserChosen(const base::string16& browser_name) override { |
Greg Thompson | 005a710c | 2018-09-06 06:54:38 | [diff] [blame] | 248 | if (browser_name == InstallUtil::GetDisplayName()) { |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 249 | base::RecordAction( |
| 250 | base::UserMetricsAction("SettingsAppMonitor.ChromeBrowserChosen")); |
| 251 | } else { |
| 252 | base::RecordAction( |
| 253 | base::UserMetricsAction("SettingsAppMonitor.OtherBrowserChosen")); |
| 254 | } |
| 255 | } |
| 256 | |
pmonette | b66514b4 | 2016-12-07 20:28:39 | [diff] [blame] | 257 | void OnPromoFocused() override { |
| 258 | base::RecordAction( |
| 259 | base::UserMetricsAction("SettingsAppMonitor.PromoFocused")); |
| 260 | } |
| 261 | |
| 262 | void OnPromoChoiceMade(bool accept_promo) override { |
| 263 | if (accept_promo) { |
| 264 | base::RecordAction( |
| 265 | base::UserMetricsAction("SettingsAppMonitor.CheckItOut")); |
| 266 | } else { |
| 267 | base::RecordAction( |
| 268 | base::UserMetricsAction("SettingsAppMonitor.SwitchAnyway")); |
| 269 | } |
| 270 | } |
| 271 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 272 | // A closure to be run once initialization completes. |
| 273 | base::Closure continuation_; |
| 274 | |
| 275 | // Monitors user interaction with the Windows Settings app for the sake of |
| 276 | // reporting user actions. |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 277 | SettingsAppMonitor settings_app_monitor_; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 278 | |
| 279 | DISALLOW_COPY_AND_ASSIGN(DefaultBrowserActionRecorder); |
| 280 | }; |
| 281 | |
| 282 | // A function bound up in a callback with a DefaultBrowserActionRecorder and |
| 283 | // a closure to keep the former alive until the time comes to run the latter. |
| 284 | void OnSettingsAppFinished( |
| 285 | std::unique_ptr<DefaultBrowserActionRecorder> recorder, |
| 286 | const base::Closure& on_finished_callback) { |
| 287 | recorder.reset(); |
| 288 | on_finished_callback.Run(); |
| 289 | } |
| 290 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 291 | // There is no way to make sure the user is done with the system settings, but a |
| 292 | // signal that the interaction is finished is needed for UMA. A timer of 2 |
| 293 | // minutes is used as a substitute. The registry keys for the protocol |
| 294 | // association with an app are also monitored to signal the end of the |
| 295 | // interaction early when it is clear that the user made a choice (e.g. http |
| 296 | // and https for default browser). |
| 297 | // |
| 298 | // This helper class manages both the timer and the registry watchers and makes |
| 299 | // sure the callback for the end of the settings interaction is only run once. |
| 300 | // This class also manages its own lifetime. |
| 301 | class OpenSystemSettingsHelper { |
| 302 | public: |
| 303 | // Begin the monitoring and will call |on_finished_callback| when done. |
| 304 | // Takes in a null-terminated array of |protocols| whose registry keys must be |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 305 | // watched. The array must contain at least one element. |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 306 | static void Begin(const wchar_t* const protocols[], |
| 307 | const base::Closure& on_finished_callback) { |
pmonette | c541d94 | 2016-06-15 22:08:32 | [diff] [blame] | 308 | delete instance_; |
| 309 | instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback); |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | private: |
| 313 | // The reason the settings interaction concluded. Do not modify the ordering |
| 314 | // because it is used for UMA. |
| 315 | enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; |
| 316 | |
| 317 | OpenSystemSettingsHelper(const wchar_t* const protocols[], |
| 318 | const base::Closure& on_finished_callback) |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 319 | : scoped_user_protocol_entry_(protocols[0]), |
| 320 | on_finished_callback_(on_finished_callback), |
| 321 | weak_ptr_factory_(this) { |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 322 | static const wchar_t kUrlAssociationFormat[] = |
| 323 | L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\" |
| 324 | L"%ls\\UserChoice"; |
| 325 | |
| 326 | // Remember the start time. |
| 327 | start_time_ = base::TimeTicks::Now(); |
| 328 | |
| 329 | for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) { |
| 330 | AddRegistryKeyWatcher( |
| 331 | base::StringPrintf(kUrlAssociationFormat, *scan).c_str()); |
| 332 | } |
| 333 | // Only the watchers that were succesfully initialized are counted. |
| 334 | registry_watcher_count_ = registry_key_watchers_.size(); |
| 335 | |
| 336 | timer_.Start( |
| 337 | FROM_HERE, base::TimeDelta::FromMinutes(2), |
| 338 | base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction, |
| 339 | weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT)); |
| 340 | } |
| 341 | |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 342 | ~OpenSystemSettingsHelper() { |
| 343 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 344 | } |
| 345 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 346 | // Called when a change is detected on one of the registry keys being watched. |
| 347 | // Note: All types of modification to the registry key will trigger this |
| 348 | // function even if the value change is the only one that matters. This |
| 349 | // is good enough for now. |
| 350 | void OnRegistryKeyChanged() { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 351 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 352 | // Make sure all the registry watchers have fired. |
| 353 | if (--registry_watcher_count_ == 0) { |
| 354 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 355 | "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration", |
| 356 | base::TimeTicks::Now() - start_time_); |
| 357 | |
| 358 | ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // Ends the monitoring with the system settings. Will call |
| 363 | // |on_finished_callback_| and then dispose of this class instance to make |
| 364 | // sure the callback won't get called subsequently. |
| 365 | void ConcludeInteraction(ConcludeReason conclude_reason) { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 366 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 367 | |
| 368 | UMA_HISTOGRAM_ENUMERATION( |
| 369 | "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason, |
| 370 | NUM_CONCLUDE_REASON_TYPES); |
| 371 | on_finished_callback_.Run(); |
pmonette | c541d94 | 2016-06-15 22:08:32 | [diff] [blame] | 372 | delete instance_; |
| 373 | instance_ = nullptr; |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // Helper function to create a registry watcher for a given |key_path|. Do |
| 377 | // nothing on initialization failure. |
| 378 | void AddRegistryKeyWatcher(const wchar_t* key_path) { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 379 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 380 | |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 381 | auto reg_key = std::make_unique<base::win::RegKey>(HKEY_CURRENT_USER, |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 382 | key_path, KEY_NOTIFY); |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 383 | |
| 384 | if (reg_key->Valid() && |
| 385 | reg_key->StartWatching( |
| 386 | base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, |
| 387 | weak_ptr_factory_.GetWeakPtr()))) { |
| 388 | registry_key_watchers_.push_back(std::move(reg_key)); |
| 389 | } |
| 390 | } |
| 391 | |
pmonette | c541d94 | 2016-06-15 22:08:32 | [diff] [blame] | 392 | // Used to make sure only one instance is alive at the same time. |
| 393 | static OpenSystemSettingsHelper* instance_; |
| 394 | |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 395 | // This is needed to make sure that Windows displays an entry for the protocol |
| 396 | // inside the "Choose default apps by protocol" settings page. |
| 397 | ScopedUserProtocolEntry scoped_user_protocol_entry_; |
| 398 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 399 | // The function to call when the interaction with the system settings is |
| 400 | // finished. |
| 401 | base::Closure on_finished_callback_; |
| 402 | |
| 403 | // The number of time the registry key watchers must fire. |
| 404 | int registry_watcher_count_ = 0; |
| 405 | |
| 406 | // There can be multiple registry key watchers as some settings modify |
| 407 | // multiple protocol associations. e.g. Changing the default browser modifies |
| 408 | // the http and https associations. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 409 | std::vector<std::unique_ptr<base::win::RegKey>> registry_key_watchers_; |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 410 | |
| 411 | base::OneShotTimer timer_; |
| 412 | |
| 413 | // Records the time it takes for the final registry watcher to get signaled. |
| 414 | base::TimeTicks start_time_; |
| 415 | |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 416 | SEQUENCE_CHECKER(sequence_checker_); |
| 417 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 418 | // Weak ptrs are used to bind this class to the callbacks of the timer and the |
| 419 | // registry watcher. This makes it possible to self-delete after one of the |
| 420 | // callbacks is executed to cancel the remaining ones. |
| 421 | base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_; |
| 422 | |
| 423 | DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper); |
| 424 | }; |
| 425 | |
pmonette | c541d94 | 2016-06-15 22:08:32 | [diff] [blame] | 426 | OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr; |
| 427 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 428 | // Helper class to determine if Chrome is pinned to the taskbar. Hides the |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 429 | // complexity of managing the lifetime of the connection to the ChromeWinUtil |
| 430 | // service. |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 431 | class IsPinnedToTaskbarHelper { |
| 432 | public: |
| 433 | using ResultCallback = win::IsPinnedToTaskbarCallback; |
| 434 | using ErrorCallback = win::ConnectionErrorCallback; |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 435 | static void GetState(const ErrorCallback& error_callback, |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 436 | const ResultCallback& result_callback); |
| 437 | |
| 438 | private: |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 439 | IsPinnedToTaskbarHelper(const ErrorCallback& error_callback, |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 440 | const ResultCallback& result_callback); |
| 441 | |
| 442 | void OnConnectionError(); |
| 443 | void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar); |
| 444 | |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 445 | mojo::Remote<chrome::mojom::UtilWin> remote_util_win_; |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 446 | |
| 447 | ErrorCallback error_callback_; |
| 448 | ResultCallback result_callback_; |
| 449 | |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 450 | SEQUENCE_CHECKER(sequence_checker_); |
| 451 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 452 | DISALLOW_COPY_AND_ASSIGN(IsPinnedToTaskbarHelper); |
| 453 | }; |
| 454 | |
| 455 | // static |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 456 | void IsPinnedToTaskbarHelper::GetState( |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 457 | const ErrorCallback& error_callback, |
| 458 | const ResultCallback& result_callback) { |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 459 | // Self-deleting when the ShellHandler completes. |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 460 | new IsPinnedToTaskbarHelper(error_callback, result_callback); |
pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 461 | } |
| 462 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 463 | IsPinnedToTaskbarHelper::IsPinnedToTaskbarHelper( |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 464 | const ErrorCallback& error_callback, |
| 465 | const ResultCallback& result_callback) |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 466 | : remote_util_win_(LaunchUtilWinServiceInstance()), |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 467 | error_callback_(error_callback), |
| 468 | result_callback_(result_callback) { |
pmonette | 83edc1e | 2016-12-15 17:36:44 | [diff] [blame] | 469 | DCHECK(error_callback_); |
| 470 | DCHECK(result_callback_); |
| 471 | |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 472 | // |remote_util_win_| owns the callbacks and is guaranteed to be destroyed |
| 473 | // before |this|, therefore making base::Unretained() safe to use. |
| 474 | remote_util_win_.set_disconnect_handler(base::BindOnce( |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 475 | &IsPinnedToTaskbarHelper::OnConnectionError, base::Unretained(this))); |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 476 | remote_util_win_->IsPinnedToTaskbar( |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 477 | base::Bind(&IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult, |
| 478 | base::Unretained(this))); |
| 479 | } |
| 480 | |
| 481 | void IsPinnedToTaskbarHelper::OnConnectionError() { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 482 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 483 | error_callback_.Run(); |
| 484 | delete this; |
| 485 | } |
| 486 | |
| 487 | void IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult( |
pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 488 | bool succeeded, |
| 489 | bool is_pinned_to_taskbar) { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 490 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 491 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 492 | result_callback_.Run(succeeded, is_pinned_to_taskbar); |
| 493 | delete this; |
pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 494 | } |
| 495 | |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 496 | void MigrateChromeAndChromeProxyShortcuts( |
| 497 | const base::FilePath& chrome_exe, |
| 498 | const base::FilePath& chrome_proxy_path, |
| 499 | const base::FilePath& shortcut_path) { |
| 500 | win::MigrateShortcutsInPathInternal(chrome_exe, shortcut_path); |
| 501 | |
| 502 | // Migrate any pinned PWA shortcuts in taskbar directory. |
| 503 | win::MigrateShortcutsInPathInternal(chrome_proxy_path, shortcut_path); |
| 504 | } |
| 505 | |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 506 | } // namespace |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 507 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 508 | bool SetAsDefaultBrowser() { |
Etienne Bergeron | 436d4221 | 2019-02-26 17:15:12 | [diff] [blame] | 509 | base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, |
| 510 | base::BlockingType::MAY_BLOCK); |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 511 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 512 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 513 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 514 | LOG(ERROR) << "Error getting app exe path"; |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | // From UI currently we only allow setting default browser for current user. |
Greg Thompson | 8fc94ef | 2018-09-10 16:53:12 | [diff] [blame] | 519 | if (!ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, chrome_exe, |
grt | e76ca285 | 2014-12-05 16:42:10 | [diff] [blame] | 520 | true /* elevate_if_not_admin */)) { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 521 | LOG(ERROR) << "Chrome could not be set as default browser."; |
| 522 | return false; |
| 523 | } |
| 524 | |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 525 | VLOG(1) << "Chrome registered as default browser."; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 526 | return true; |
| 527 | } |
| 528 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 529 | bool SetAsDefaultProtocolClient(const std::string& protocol) { |
Etienne Bergeron | 436d4221 | 2019-02-26 17:15:12 | [diff] [blame] | 530 | base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, |
| 531 | base::BlockingType::MAY_BLOCK); |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 532 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 533 | if (protocol.empty()) |
| 534 | return false; |
| 535 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 536 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 537 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 538 | LOG(ERROR) << "Error getting app exe path"; |
| 539 | return false; |
| 540 | } |
| 541 | |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 542 | base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
Greg Thompson | 8fc94ef | 2018-09-10 16:53:12 | [diff] [blame] | 543 | if (!ShellUtil::MakeChromeDefaultProtocolClient(chrome_exe, wprotocol)) { |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 544 | LOG(ERROR) << "Chrome could not be set as default handler for " |
| 545 | << protocol << "."; |
| 546 | return false; |
| 547 | } |
| 548 | |
| 549 | VLOG(1) << "Chrome registered as default handler for " << protocol << "."; |
| 550 | return true; |
| 551 | } |
| 552 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 553 | DefaultWebClientSetPermission GetDefaultWebClientSetPermission() { |
grt | 509bc94 | 2017-03-25 08:43:21 | [diff] [blame] | 554 | if (!install_static::SupportsSetAsDefaultBrowser()) |
pmonette | 034a03d9 | 2015-10-02 21:04:27 | [diff] [blame] | 555 | return SET_DEFAULT_NOT_ALLOWED; |
pmonette | 034a03d9 | 2015-10-02 21:04:27 | [diff] [blame] | 556 | if (ShellUtil::CanMakeChromeDefaultUnattended()) |
| 557 | return SET_DEFAULT_UNATTENDED; |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 558 | // Windows 8 and 10 both introduced a new way to set the default web client |
| 559 | // which require user interaction. |
pmonette | f89ac7c7 | 2015-10-06 03:22:01 | [diff] [blame] | 560 | return SET_DEFAULT_INTERACTIVE; |
pmonette | 034a03d9 | 2015-10-02 21:04:27 | [diff] [blame] | 561 | } |
| 562 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 563 | bool IsElevationNeededForSettingDefaultProtocolClient() { |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 564 | return base::win::GetVersion() < base::win::Version::WIN8; |
pmonette | 868ca64 | 2015-09-02 14:34:02 | [diff] [blame] | 565 | } |
| 566 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 567 | base::string16 GetApplicationNameForProtocol(const GURL& url) { |
benwells | d0c67aa | 2016-07-28 02:57:20 | [diff] [blame] | 568 | // Windows 8 or above has a new protocol association query. |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 569 | if (base::win::GetVersion() >= base::win::Version::WIN8) { |
Mustafa Emre Acer | d19a75fc | 2018-10-08 18:15:14 | [diff] [blame] | 570 | base::string16 application_name = GetAppForProtocolUsingAssocQuery(url); |
benwells | d0c67aa | 2016-07-28 02:57:20 | [diff] [blame] | 571 | if (!application_name.empty()) |
| 572 | return application_name; |
| 573 | } |
| 574 | |
| 575 | return GetAppForProtocolUsingRegistry(url); |
[email protected] | 42dc940 | 2013-01-30 07:54:20 | [diff] [blame] | 576 | } |
| 577 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 578 | DefaultWebClientState GetDefaultBrowser() { |
pmonette | 034a03d9 | 2015-10-02 21:04:27 | [diff] [blame] | 579 | return GetDefaultWebClientStateFromShellUtilDefaultState( |
| 580 | ShellUtil::GetChromeDefaultState()); |
| 581 | } |
| 582 | |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 583 | // There is no reliable way to say which browser is default on a machine (each |
| 584 | // browser can have some of the protocols/shortcuts). So we look for only HTTP |
| 585 | // protocol handler. Even this handler is located at different places in |
| 586 | // registry on XP and Vista: |
| 587 | // - HKCR\http\shell\open\command (XP) |
| 588 | // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ |
| 589 | // http\UserChoice (Vista) |
thakis | e4a02ff3 | 2016-09-20 17:00:42 | [diff] [blame] | 590 | // This method checks if Firefox is default browser by checking these |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 591 | // locations and returns true if Firefox traces are found there. In case of |
| 592 | // error (or if Firefox is not found)it returns the default value which |
| 593 | // is false. |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 594 | bool IsFirefoxDefaultBrowser() { |
Patrick Monette | ab240ec | 2017-07-13 22:49:14 | [diff] [blame] | 595 | base::string16 app_cmd; |
| 596 | base::win::RegKey key(HKEY_CURRENT_USER, ShellUtil::kRegVistaUrlPrefs, |
| 597 | KEY_READ); |
| 598 | return key.Valid() && key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS && |
| 599 | app_cmd == L"FirefoxURL"; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 600 | } |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 601 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 602 | DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) { |
pmonette | 034a03d9 | 2015-10-02 21:04:27 | [diff] [blame] | 603 | return GetDefaultWebClientStateFromShellUtilDefaultState( |
| 604 | ShellUtil::GetChromeDefaultProtocolClientState( |
| 605 | base::UTF8ToUTF16(protocol))); |
| 606 | } |
| 607 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 608 | namespace win { |
| 609 | |
| 610 | bool SetAsDefaultBrowserUsingIntentPicker() { |
Etienne Bergeron | 436d4221 | 2019-02-26 17:15:12 | [diff] [blame] | 611 | base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, |
| 612 | base::BlockingType::MAY_BLOCK); |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 613 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 614 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 615 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 616 | NOTREACHED() << "Error getting app exe path"; |
| 617 | return false; |
| 618 | } |
| 619 | |
Greg Thompson | 8fc94ef | 2018-09-10 16:53:12 | [diff] [blame] | 620 | if (!ShellUtil::ShowMakeChromeDefaultSystemUI(chrome_exe)) { |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 621 | LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | VLOG(1) << "Set-default-browser Windows UI completed."; |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | void SetAsDefaultBrowserUsingSystemSettings( |
| 630 | const base::Closure& on_finished_callback) { |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 631 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 632 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 633 | NOTREACHED() << "Error getting app exe path"; |
| 634 | on_finished_callback.Run(); |
| 635 | return; |
| 636 | } |
| 637 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 638 | // Create an action recorder that will open the settings app once it has |
| 639 | // initialized. |
| 640 | std::unique_ptr<DefaultBrowserActionRecorder> recorder( |
| 641 | new DefaultBrowserActionRecorder(base::Bind( |
| 642 | base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI), |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 643 | chrome_exe))); |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 644 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 645 | // The helper manages its own lifetime. Bind the action recorder |
| 646 | // into the finished callback to keep it alive throughout the |
| 647 | // interaction. |
| 648 | static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr}; |
| 649 | OpenSystemSettingsHelper::Begin( |
| 650 | kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder), |
| 651 | on_finished_callback)); |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) { |
Etienne Bergeron | 436d4221 | 2019-02-26 17:15:12 | [diff] [blame] | 655 | base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, |
| 656 | base::BlockingType::MAY_BLOCK); |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 657 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 658 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 659 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 660 | NOTREACHED() << "Error getting app exe path"; |
| 661 | return false; |
| 662 | } |
| 663 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 664 | base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
Greg Thompson | 8fc94ef | 2018-09-10 16:53:12 | [diff] [blame] | 665 | if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(chrome_exe, |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 666 | wprotocol)) { |
| 667 | LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | VLOG(1) << "Set-default-client Windows UI completed."; |
| 672 | return true; |
| 673 | } |
| 674 | |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 675 | void SetAsDefaultProtocolClientUsingSystemSettings( |
| 676 | const std::string& protocol, |
| 677 | const base::Closure& on_finished_callback) { |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 678 | base::FilePath chrome_exe; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 679 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) { |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 680 | NOTREACHED() << "Error getting app exe path"; |
| 681 | on_finished_callback.Run(); |
| 682 | return; |
| 683 | } |
| 684 | |
| 685 | // The helper manages its own lifetime. |
| 686 | base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| 687 | const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr}; |
| 688 | OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback); |
| 689 | |
Greg Thompson | 8fc94ef | 2018-09-10 16:53:12 | [diff] [blame] | 690 | ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(chrome_exe, wprotocol); |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 691 | } |
| 692 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 693 | base::string16 GetAppModelIdForProfile(const base::string16& app_name, |
| 694 | const base::FilePath& profile_path) { |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 695 | std::vector<base::string16> components; |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 696 | components.push_back(app_name); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 697 | const base::string16 profile_id(GetProfileIdFromPath(profile_path)); |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 698 | if (!profile_id.empty()) |
| 699 | components.push_back(profile_id); |
| 700 | return ShellUtil::BuildAppModelId(components); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 701 | } |
| 702 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 703 | base::string16 GetChromiumModelIdForProfile( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 704 | const base::FilePath& profile_path) { |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 705 | return GetAppModelIdForProfile( |
grt | c9880346 | 2017-03-08 10:05:08 | [diff] [blame] | 706 | ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()), |
[email protected] | 78679969 | 2012-09-26 14:16:48 | [diff] [blame] | 707 | profile_path); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 708 | } |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 709 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 710 | void MigrateTaskbarPins() { |
pmonette | b18379f | 2017-06-01 01:18:44 | [diff] [blame] | 711 | // This needs to happen (e.g. so that the appid is fixed and the |
| 712 | // run-time Chrome icon is merged with the taskbar shortcut), but it is not an |
| 713 | // urgent task. |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 714 | base::FilePath taskbar_path; |
| 715 | if (!base::PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_path)) { |
| 716 | NOTREACHED(); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | // Migrate any pinned shortcuts in ImplicitApps sub-directories. |
| 721 | base::FilePath implicit_apps_path; |
| 722 | if (!base::PathService::Get(base::DIR_IMPLICIT_APP_SHORTCUTS, |
| 723 | &implicit_apps_path)) { |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 724 | NOTREACHED(); |
| 725 | return; |
| 726 | } |
| 727 | |
Sami Kyostila | 9525040 | 2019-08-07 18:58:56 | [diff] [blame^] | 728 | base::CreateCOMSTATaskRunner( |
| 729 | {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT}) |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 730 | ->PostTask(FROM_HERE, base::BindOnce(&MigrateTaskbarPinsCallback, |
| 731 | taskbar_path, implicit_apps_path)); |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 732 | } |
| 733 | |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 734 | void MigrateTaskbarPinsCallback(const base::FilePath& taskbar_path, |
| 735 | const base::FilePath& implicit_apps_path) { |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 736 | // Get full path of chrome. |
| 737 | base::FilePath chrome_exe; |
| 738 | if (!base::PathService::Get(base::FILE_EXE, &chrome_exe)) |
| 739 | return; |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 740 | base::FilePath chrome_proxy_path(web_app::GetChromeProxyPath()); |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 741 | |
David Bienvenu | 4105186 | 2019-07-25 22:17:38 | [diff] [blame] | 742 | MigrateChromeAndChromeProxyShortcuts(chrome_exe, chrome_proxy_path, |
| 743 | taskbar_path); |
| 744 | base::FileEnumerator directory_enum(implicit_apps_path, /*recursive=*/false, |
| 745 | base::FileEnumerator::DIRECTORIES); |
| 746 | for (base::FilePath implicit_app_sub_directory = directory_enum.Next(); |
| 747 | !implicit_app_sub_directory.empty(); |
| 748 | implicit_app_sub_directory = directory_enum.Next()) { |
| 749 | MigrateChromeAndChromeProxyShortcuts(chrome_exe, chrome_proxy_path, |
| 750 | implicit_app_sub_directory); |
| 751 | } |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 752 | } |
[email protected] | 43903b8 | 2012-06-01 05:26:23 | [diff] [blame] | 753 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 754 | void GetIsPinnedToTaskbarState( |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 755 | const ConnectionErrorCallback& on_error_callback, |
| 756 | const IsPinnedToTaskbarCallback& result_callback) { |
Ken Rockot | 95fe3f6 | 2019-07-25 20:29:51 | [diff] [blame] | 757 | IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback); |
pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 758 | } |
| 759 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 760 | int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
| 761 | const base::FilePath& path) { |
Etienne Bergeron | 147591d | 2019-06-19 16:40:12 | [diff] [blame] | 762 | // Mitigate the issues caused by loading DLLs on a background thread |
| 763 | // (http://crbug/973868). |
| 764 | base::ScopedThreadMayLoadLibraryOnBackgroundThread priority_boost(FROM_HERE); |
| 765 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 766 | // Enumerate all pinned shortcuts in the given path directly. |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 767 | base::FileEnumerator shortcuts_enum( |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 768 | path, false, // not recursive |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 769 | base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 770 | |
grt | 973412f | 2017-02-25 08:04:21 | [diff] [blame] | 771 | bool is_per_user_install = InstallUtil::IsPerUserInstall(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 772 | |
| 773 | int shortcuts_migrated = 0; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 774 | base::FilePath target_path; |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 775 | base::string16 arguments; |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 776 | base::win::ScopedPropVariant propvariant; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 777 | for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 778 | shortcut = shortcuts_enum.Next()) { |
| 779 | // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once |
| 780 | // it is fixed to work with FilePaths with spaces. |
| 781 | if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || |
| 782 | chrome_exe != target_path) { |
| 783 | continue; |
| 784 | } |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 785 | base::CommandLine command_line( |
| 786 | base::CommandLine::FromString(base::StringPrintf( |
| 787 | L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 788 | |
| 789 | // Get the expected AppId for this Chrome shortcut. |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 790 | base::string16 expected_app_id( |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 791 | GetExpectedAppId(command_line, is_per_user_install)); |
| 792 | if (expected_app_id.empty()) |
| 793 | continue; |
| 794 | |
| 795 | // Load the shortcut. |
Robert Liao | b2bc703d | 2017-10-17 20:52:35 | [diff] [blame] | 796 | Microsoft::WRL::ComPtr<IShellLink> shell_link; |
| 797 | Microsoft::WRL::ComPtr<IPersistFile> persist_file; |
robliao | a872e99 | 2017-05-18 06:36:19 | [diff] [blame] | 798 | if (FAILED(::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, |
| 799 | IID_PPV_ARGS(&shell_link))) || |
robliao | a7956aa | 2017-05-17 19:10:54 | [diff] [blame] | 800 | FAILED(shell_link.CopyTo(persist_file.GetAddressOf())) || |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 801 | FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) { |
| 802 | DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value(); |
| 803 | continue; |
| 804 | } |
| 805 | |
| 806 | // Any properties that need to be updated on the shortcut will be stored in |
| 807 | // |updated_properties|. |
| 808 | base::win::ShortcutProperties updated_properties; |
| 809 | |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 810 | base::string16 current_app_id; |
| 811 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 812 | // Validate the existing app id for the shortcut. |
Robert Liao | b2bc703d | 2017-10-17 20:52:35 | [diff] [blame] | 813 | Microsoft::WRL::ComPtr<IPropertyStore> property_store; |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 814 | propvariant.Reset(); |
robliao | a7956aa | 2017-05-17 19:10:54 | [diff] [blame] | 815 | if (FAILED(shell_link.CopyTo(property_store.GetAddressOf())) || |
dcheng | 81762e0 | 2014-11-21 21:22:28 | [diff] [blame] | 816 | property_store->GetValue(PKEY_AppUserModel_ID, propvariant.Receive()) != |
| 817 | S_OK) { |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 818 | // When in doubt, prefer not updating the shortcut. |
| 819 | NOTREACHED(); |
| 820 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 821 | } else { |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 822 | switch (propvariant.get().vt) { |
| 823 | case VT_EMPTY: |
| 824 | // If there is no app_id set, set our app_id if one is expected. |
| 825 | if (!expected_app_id.empty()) |
| 826 | updated_properties.set_app_id(expected_app_id); |
| 827 | break; |
| 828 | case VT_LPWSTR: |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 829 | current_app_id = base::string16(propvariant.get().pwszVal); |
| 830 | if (expected_app_id != current_app_id) |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 831 | updated_properties.set_app_id(expected_app_id); |
| 832 | break; |
| 833 | default: |
| 834 | NOTREACHED(); |
| 835 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
gab | 88257b6 | 2016-01-15 03:19:19 | [diff] [blame] | 839 | // Clear dual_mode property from any shortcuts that previously had it (it |
| 840 | // was only ever installed on shortcuts with the |
| 841 | // |default_chromium_model_id|). |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 842 | base::string16 default_chromium_model_id( |
grt | c9880346 | 2017-03-08 10:05:08 | [diff] [blame] | 843 | ShellUtil::GetBrowserModelId(is_per_user_install)); |
David Bienvenu | 7f9c2bf | 2019-07-15 13:37:34 | [diff] [blame] | 844 | if (current_app_id == default_chromium_model_id) { |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 845 | propvariant.Reset(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 846 | if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 847 | propvariant.Receive()) != S_OK) { |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 848 | // When in doubt, prefer to not update the shortcut. |
| 849 | NOTREACHED(); |
| 850 | continue; |
gab | 38d242d4d | 2016-01-14 20:38:12 | [diff] [blame] | 851 | } |
| 852 | if (propvariant.get().vt == VT_BOOL && |
| 853 | !!propvariant.get().boolVal) { |
| 854 | updated_properties.set_dual_mode(false); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
robliao | 9212cb4 | 2017-04-06 17:43:39 | [diff] [blame] | 858 | persist_file.Reset(); |
| 859 | shell_link.Reset(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 860 | |
| 861 | // Update the shortcut if some of its properties need to be updated. |
| 862 | if (updated_properties.options && |
| 863 | base::win::CreateOrUpdateShortcutLink( |
| 864 | shortcut, updated_properties, |
| 865 | base::win::SHORTCUT_UPDATE_EXISTING)) { |
| 866 | ++shortcuts_migrated; |
| 867 | } |
| 868 | } |
| 869 | return shortcuts_migrated; |
| 870 | } |
| 871 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 872 | } // namespace win |
| 873 | |
pmonette | 9fa59e88 | 2016-02-10 00:12:19 | [diff] [blame] | 874 | } // namespace shell_integration |