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