[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 | |
| 5 | #include "chrome/browser/shell_integration.h" |
| 6 | |
| 7 | #include <windows.h> |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 8 | #include <shlwapi.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. |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 11 | |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 14 | #include "base/files/file_enumerator.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | fa1e0e1 | 2013-07-18 00:10:14 | [diff] [blame] | 16 | #include "base/message_loop/message_loop.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 17 | #include "base/path_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 18 | #include "base/strings/string_number_conversions.h" |
[email protected] | 24a555b6 | 2013-06-10 22:01:17 | [diff] [blame] | 19 | #include "base/strings/string_util.h" |
| 20 | #include "base/strings/stringprintf.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 21 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 2d650398 | 2010-10-17 04:41:54 | [diff] [blame] | 22 | #include "base/win/registry.h" |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 23 | #include "base/win/scoped_comptr.h" |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 24 | #include "base/win/scoped_propvariant.h" |
[email protected] | f1024e2 | 2012-09-12 07:14:55 | [diff] [blame] | 25 | #include "base/win/shortcut.h" |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 26 | #include "base/win/windows_version.h" |
[email protected] | 89d4383 | 2013-06-29 20:25:20 | [diff] [blame] | 27 | #include "chrome/browser/policy/policy_path_parser.h" |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 28 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 29 | #include "chrome/common/chrome_constants.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 30 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 31 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 32 | #include "chrome/installer/setup/setup_util.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 33 | #include "chrome/installer/util/browser_distribution.h" |
| 34 | #include "chrome/installer/util/create_reg_key_work_item.h" |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 35 | #include "chrome/installer/util/install_util.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 36 | #include "chrome/installer/util/set_reg_value_work_item.h" |
| 37 | #include "chrome/installer/util/shell_util.h" |
| 38 | #include "chrome/installer/util/util_constants.h" |
| 39 | #include "chrome/installer/util/work_item.h" |
| 40 | #include "chrome/installer/util/work_item_list.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 41 | #include "content/public/browser/browser_thread.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 42 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 43 | using content::BrowserThread; |
| 44 | |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 45 | namespace { |
| 46 | |
[email protected] | da1ffc3 | 2013-02-15 21:22:56 | [diff] [blame] | 47 | const wchar_t kAppListAppNameSuffix[] = L"AppList"; |
[email protected] | 99002fd | 2012-11-06 04:35:52 | [diff] [blame] | 48 | |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 49 | // Helper function for ShellIntegration::GetAppId to generates profile id |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 50 | // from profile path. "profile_id" is composed of sanitized basenames of |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 51 | // user data dir and profile dir joined by a ".". |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 52 | base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 53 | // Return empty string if profile_path is empty |
| 54 | if (profile_path.empty()) |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 55 | return base::string16(); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 56 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 57 | base::FilePath default_user_data_dir; |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 58 | // Return empty string if profile_path is in default user data |
| 59 | // dir and is the default profile. |
| 60 | if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) && |
| 61 | profile_path.DirName() == default_user_data_dir && |
[email protected] | 162b599 | 2011-03-15 19:40:48 | [diff] [blame] | 62 | profile_path.BaseName().value() == |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 63 | base::ASCIIToUTF16(chrome::kInitialProfile)) { |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 64 | return base::string16(); |
[email protected] | 162b599 | 2011-03-15 19:40:48 | [diff] [blame] | 65 | } |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 66 | |
| 67 | // Get joined basenames of user data dir and profile. |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 68 | base::string16 basenames = profile_path.DirName().BaseName().value() + |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 69 | L"." + profile_path.BaseName().value(); |
| 70 | |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 71 | base::string16 profile_id; |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 72 | profile_id.reserve(basenames.size()); |
| 73 | |
| 74 | // Generate profile_id from sanitized basenames. |
| 75 | for (size_t i = 0; i < basenames.length(); ++i) { |
| 76 | if (IsAsciiAlpha(basenames[i]) || |
| 77 | IsAsciiDigit(basenames[i]) || |
| 78 | basenames[i] == L'.') |
| 79 | profile_id += basenames[i]; |
| 80 | } |
| 81 | |
| 82 | return profile_id; |
| 83 | } |
| 84 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 85 | base::string16 GetAppListAppName() { |
[email protected] | da1ffc3 | 2013-02-15 21:22:56 | [diff] [blame] | 86 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 87 | base::string16 app_name(dist->GetBaseAppId()); |
[email protected] | da1ffc3 | 2013-02-15 21:22:56 | [diff] [blame] | 88 | app_name.append(kAppListAppNameSuffix); |
| 89 | return app_name; |
| 90 | } |
| 91 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 92 | // Gets expected app id for given Chrome (based on |command_line| and |
| 93 | // |is_per_user_install|). |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 94 | base::string16 GetExpectedAppId(const CommandLine& command_line, |
| 95 | bool is_per_user_install) { |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 96 | base::FilePath user_data_dir; |
| 97 | if (command_line.HasSwitch(switches::kUserDataDir)) |
| 98 | user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir); |
| 99 | else |
| 100 | chrome::GetDefaultUserDataDirectory(&user_data_dir); |
[email protected] | 89d4383 | 2013-06-29 20:25:20 | [diff] [blame] | 101 | // Adjust with any policy that overrides any other way to set the path. |
| 102 | policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 103 | DCHECK(!user_data_dir.empty()); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 104 | |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 105 | base::FilePath profile_subdir; |
| 106 | if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 107 | profile_subdir = |
| 108 | command_line.GetSwitchValuePath(switches::kProfileDirectory); |
| 109 | } else { |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 110 | profile_subdir = |
| 111 | base::FilePath(base::ASCIIToUTF16(chrome::kInitialProfile)); |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 112 | } |
| 113 | DCHECK(!profile_subdir.empty()); |
| 114 | |
| 115 | base::FilePath profile_path = user_data_dir.Append(profile_subdir); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 116 | base::string16 app_name; |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 117 | if (command_line.HasSwitch(switches::kApp)) { |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 118 | app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 119 | GURL(command_line.GetSwitchValueASCII(switches::kApp)))); |
[email protected] | 2f1c09d | 2011-01-14 14:58:14 | [diff] [blame] | 120 | } else if (command_line.HasSwitch(switches::kAppId)) { |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 121 | app_name = base::UTF8ToUTF16( |
| 122 | web_app::GenerateApplicationNameFromExtensionId( |
| 123 | command_line.GetSwitchValueASCII(switches::kAppId))); |
[email protected] | 99002fd | 2012-11-06 04:35:52 | [diff] [blame] | 124 | } else if (command_line.HasSwitch(switches::kShowAppList)) { |
[email protected] | da1ffc3 | 2013-02-15 21:22:56 | [diff] [blame] | 125 | app_name = GetAppListAppName(); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 126 | } else { |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 127 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 128 | app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 129 | } |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 130 | DCHECK(!app_name.empty()); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 131 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 132 | return ShellIntegration::GetAppModelIdForProfile(app_name, profile_path); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 135 | void MigrateChromiumShortcutsCallback() { |
| 136 | // This should run on the file thread. |
| 137 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 138 | |
| 139 | // Get full path of chrome. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 140 | base::FilePath chrome_exe; |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 141 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
| 142 | return; |
| 143 | |
| 144 | // Locations to check for shortcuts migration. |
| 145 | static const struct { |
| 146 | int location_id; |
| 147 | const wchar_t* sub_dir; |
| 148 | } kLocations[] = { |
| 149 | { |
[email protected] | e5f9d82 | 2012-11-06 22:27:01 | [diff] [blame] | 150 | base::DIR_TASKBAR_PINS, |
| 151 | NULL |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 152 | }, { |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 153 | base::DIR_USER_DESKTOP, |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 154 | NULL |
| 155 | }, { |
| 156 | base::DIR_START_MENU, |
| 157 | NULL |
| 158 | }, { |
| 159 | base::DIR_APP_DATA, |
| 160 | L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\StartMenu" |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | for (int i = 0; i < arraysize(kLocations); ++i) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 165 | base::FilePath path; |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 166 | if (!PathService::Get(kLocations[i].location_id, &path)) { |
| 167 | NOTREACHED(); |
| 168 | continue; |
| 169 | } |
| 170 | |
| 171 | if (kLocations[i].sub_dir) |
| 172 | path = path.Append(kLocations[i].sub_dir); |
| 173 | |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 174 | bool check_dual_mode = (kLocations[i].location_id == base::DIR_START_MENU); |
| 175 | ShellIntegration::MigrateShortcutsInPathInternal(chrome_exe, path, |
| 176 | check_dual_mode); |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 180 | // Windows 8 introduced a new protocol->executable binding system which cannot |
| 181 | // be retrieved in the HKCR registry subkey method implemented below. We call |
| 182 | // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead. |
| 183 | base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) { |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame^] | 184 | base::string16 url_scheme = base::ASCIIToUTF16(url.scheme()); |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 185 | // Don't attempt to query protocol association on an empty string. |
[email protected] | 6e84d37 | 2014-05-29 23:36:39 | [diff] [blame] | 186 | if (url_scheme.empty()) |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 187 | return base::string16(); |
| 188 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 189 | // Query AssocQueryString for a human-readable description of the program |
| 190 | // that will be invoked given the provided URL spec. This is used only to |
| 191 | // populate the external protocol dialog box the user sees when invoking |
| 192 | // an unknown external protocol. |
| 193 | wchar_t out_buffer[1024]; |
| 194 | DWORD buffer_size = arraysize(out_buffer); |
| 195 | HRESULT hr = AssocQueryString(ASSOCF_IS_PROTOCOL, |
| 196 | ASSOCSTR_FRIENDLYAPPNAME, |
[email protected] | 6e84d37 | 2014-05-29 23:36:39 | [diff] [blame] | 197 | url_scheme.c_str(), |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 198 | NULL, |
| 199 | out_buffer, |
| 200 | &buffer_size); |
| 201 | if (FAILED(hr)) { |
| 202 | DLOG(WARNING) << "AssocQueryString failed!"; |
| 203 | return base::string16(); |
| 204 | } |
| 205 | return base::string16(out_buffer); |
| 206 | } |
| 207 | |
| 208 | base::string16 GetAppForProtocolUsingRegistry(const GURL& url) { |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame^] | 209 | base::string16 url_spec = base::ASCIIToUTF16(url.possibly_invalid_spec()); |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 210 | const base::string16 cmd_key_path = |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame^] | 211 | base::ASCIIToUTF16(url.scheme() + "\\shell\\open\\command"); |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 212 | base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, |
| 213 | cmd_key_path.c_str(), |
| 214 | KEY_READ); |
| 215 | size_t split_offset = url_spec.find(L':'); |
| 216 | if (split_offset == base::string16::npos) |
| 217 | return base::string16(); |
| 218 | const base::string16 parameters = url_spec.substr(split_offset + 1, |
| 219 | url_spec.length() - 1); |
| 220 | base::string16 application_to_launch; |
| 221 | if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { |
| 222 | ReplaceSubstringsAfterOffset(&application_to_launch, |
| 223 | 0, |
| 224 | L"%1", |
| 225 | parameters); |
| 226 | return application_to_launch; |
| 227 | } |
| 228 | return base::string16(); |
| 229 | } |
| 230 | |
| 231 | |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 232 | ShellIntegration::DefaultWebClientState |
| 233 | GetDefaultWebClientStateFromShellUtilDefaultState( |
| 234 | ShellUtil::DefaultState default_state) { |
| 235 | switch (default_state) { |
| 236 | case ShellUtil::NOT_DEFAULT: |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 237 | return ShellIntegration::NOT_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 238 | case ShellUtil::IS_DEFAULT: |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 239 | return ShellIntegration::IS_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 240 | default: |
| 241 | DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state); |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 242 | return ShellIntegration::UNKNOWN_DEFAULT; |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 246 | } // namespace |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 247 | |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 248 | ShellIntegration::DefaultWebClientSetPermission |
| 249 | ShellIntegration::CanSetAsDefaultBrowser() { |
[email protected] | ee5396f60 | 2013-10-23 18:52:54 | [diff] [blame] | 250 | BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 251 | if (distribution->GetDefaultBrowserControlPolicy() != |
| 252 | BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 253 | return SET_DEFAULT_NOT_ALLOWED; |
| 254 | |
[email protected] | 9fcf07f | 2012-06-18 16:13:51 | [diff] [blame] | 255 | if (ShellUtil::CanMakeChromeDefaultUnattended()) |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 256 | return SET_DEFAULT_UNATTENDED; |
[email protected] | 9fcf07f | 2012-06-18 16:13:51 | [diff] [blame] | 257 | else |
| 258 | return SET_DEFAULT_INTERACTIVE; |
[email protected] | a01481b | 2011-07-15 04:30:02 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 261 | bool ShellIntegration::SetAsDefaultBrowser() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 262 | base::FilePath chrome_exe; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 263 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 264 | LOG(ERROR) << "Error getting app exe path"; |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | // From UI currently we only allow setting default browser for current user. |
[email protected] | bf6117c7e | 2010-12-01 06:00:25 | [diff] [blame] | 269 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 270 | if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, |
[email protected] | b969648 | 2010-11-30 23:56:18 | [diff] [blame] | 271 | chrome_exe.value(), true)) { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 272 | LOG(ERROR) << "Chrome could not be set as default browser."; |
| 273 | return false; |
| 274 | } |
| 275 | |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 276 | VLOG(1) << "Chrome registered as default browser."; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 277 | return true; |
| 278 | } |
| 279 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 280 | bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
| 281 | if (protocol.empty()) |
| 282 | return false; |
| 283 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 284 | base::FilePath chrome_exe; |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 285 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 286 | LOG(ERROR) << "Error getting app exe path"; |
| 287 | return false; |
| 288 | } |
| 289 | |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 290 | base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 291 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 292 | if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(), |
| 293 | wprotocol)) { |
| 294 | LOG(ERROR) << "Chrome could not be set as default handler for " |
| 295 | << protocol << "."; |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | VLOG(1) << "Chrome registered as default handler for " << protocol << "."; |
| 300 | return true; |
| 301 | } |
| 302 | |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 303 | bool ShellIntegration::SetAsDefaultBrowserInteractive() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 304 | base::FilePath chrome_exe; |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 305 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 306 | NOTREACHED() << "Error getting app exe path"; |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 311 | if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe.value())) { |
| 312 | LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; |
| 313 | return false; |
| 314 | } |
| 315 | |
[email protected] | ee9d89d | 2012-09-25 18:21:03 | [diff] [blame] | 316 | VLOG(1) << "Set-default-browser Windows UI completed."; |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | bool ShellIntegration::SetAsDefaultProtocolClientInteractive( |
| 321 | const std::string& protocol) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 322 | base::FilePath chrome_exe; |
[email protected] | ee9d89d | 2012-09-25 18:21:03 | [diff] [blame] | 323 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 324 | NOTREACHED() << "Error getting app exe path"; |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 329 | base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
[email protected] | ee9d89d | 2012-09-25 18:21:03 | [diff] [blame] | 330 | if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( |
| 331 | dist, chrome_exe.value(), wprotocol)) { |
| 332 | LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | VLOG(1) << "Set-default-client Windows UI completed."; |
[email protected] | bd046bd4 | 2012-06-08 05:07:32 | [diff] [blame] | 337 | return true; |
| 338 | } |
| 339 | |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 340 | ShellIntegration::DefaultWebClientState ShellIntegration::GetDefaultBrowser() { |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 341 | return GetDefaultWebClientStateFromShellUtilDefaultState( |
[email protected] | 8ad11c55 | 2012-10-16 17:40:52 | [diff] [blame] | 342 | ShellUtil::GetChromeDefaultState()); |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | ShellIntegration::DefaultWebClientState |
| 346 | ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
[email protected] | eb63da7 | 2012-10-15 20:39:48 | [diff] [blame] | 347 | return GetDefaultWebClientStateFromShellUtilDefaultState( |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 348 | ShellUtil::GetChromeDefaultProtocolClientState( |
| 349 | base::UTF8ToUTF16(protocol))); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | caa0535 | 2014-03-01 00:43:05 | [diff] [blame] | 352 | base::string16 ShellIntegration::GetApplicationNameForProtocol( |
| 353 | const GURL& url) { |
| 354 | // Windows 8 or above requires a new protocol association query. |
| 355 | if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| 356 | return GetAppForProtocolUsingAssocQuery(url); |
| 357 | else |
| 358 | return GetAppForProtocolUsingRegistry(url); |
[email protected] | 42dc940 | 2013-01-30 07:54:20 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 361 | // There is no reliable way to say which browser is default on a machine (each |
| 362 | // browser can have some of the protocols/shortcuts). So we look for only HTTP |
| 363 | // protocol handler. Even this handler is located at different places in |
| 364 | // registry on XP and Vista: |
| 365 | // - HKCR\http\shell\open\command (XP) |
| 366 | // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ |
| 367 | // http\UserChoice (Vista) |
| 368 | // This method checks if Firefox is defualt browser by checking these |
| 369 | // locations and returns true if Firefox traces are found there. In case of |
| 370 | // error (or if Firefox is not found)it returns the default value which |
| 371 | // is false. |
| 372 | bool ShellIntegration::IsFirefoxDefaultBrowser() { |
| 373 | bool ff_default = false; |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 374 | if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 375 | base::string16 app_cmd; |
[email protected] | 2d650398 | 2010-10-17 04:41:54 | [diff] [blame] | 376 | base::win::RegKey key(HKEY_CURRENT_USER, |
| 377 | ShellUtil::kRegVistaUrlPrefs, KEY_READ); |
[email protected] | e06f4d5 | 2011-01-19 07:28:46 | [diff] [blame] | 378 | if (key.Valid() && (key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS) && |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 379 | app_cmd == L"FirefoxURL") |
| 380 | ff_default = true; |
| 381 | } else { |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 382 | base::string16 key_path(L"http"); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 383 | key_path.append(ShellUtil::kRegShellOpen); |
[email protected] | 2d650398 | 2010-10-17 04:41:54 | [diff] [blame] | 384 | base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 385 | base::string16 app_cmd; |
[email protected] | e06f4d5 | 2011-01-19 07:28:46 | [diff] [blame] | 386 | if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) && |
[email protected] | cb1f4ac | 2014-08-07 16:55:42 | [diff] [blame] | 387 | base::string16::npos != |
| 388 | base::StringToLowerASCII(app_cmd).find(L"firefox")) |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 389 | ff_default = true; |
| 390 | } |
| 391 | return ff_default; |
| 392 | } |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 393 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 394 | base::string16 ShellIntegration::GetAppModelIdForProfile( |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 395 | const base::string16& app_name, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 396 | const base::FilePath& profile_path) { |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 397 | std::vector<base::string16> components; |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 398 | components.push_back(app_name); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 399 | const base::string16 profile_id(GetProfileIdFromPath(profile_path)); |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 400 | if (!profile_id.empty()) |
| 401 | components.push_back(profile_id); |
| 402 | return ShellUtil::BuildAppModelId(components); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 403 | } |
| 404 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 405 | base::string16 ShellIntegration::GetChromiumModelIdForProfile( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 406 | const base::FilePath& profile_path) { |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 407 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 408 | base::FilePath chrome_exe; |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 409 | if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 410 | NOTREACHED(); |
| 411 | return dist->GetBaseAppId(); |
| 412 | } |
| 413 | return GetAppModelIdForProfile( |
[email protected] | 78679969 | 2012-09-26 14:16:48 | [diff] [blame] | 414 | ShellUtil::GetBrowserModelId( |
| 415 | dist, InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())), |
| 416 | profile_path); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 417 | } |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 418 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 419 | base::string16 ShellIntegration::GetAppListAppModelIdForProfile( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 420 | const base::FilePath& profile_path) { |
[email protected] | da1ffc3 | 2013-02-15 21:22:56 | [diff] [blame] | 421 | return ShellIntegration::GetAppModelIdForProfile( |
| 422 | GetAppListAppName(), profile_path); |
[email protected] | 99002fd | 2012-11-06 04:35:52 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 425 | void ShellIntegration::MigrateChromiumShortcuts() { |
[email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 426 | if (base::win::GetVersion() < base::win::VERSION_WIN7) |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 427 | return; |
| 428 | |
[email protected] | 81fcf95 | 2012-11-26 22:25:14 | [diff] [blame] | 429 | // This needs to happen eventually (e.g. so that the appid is fixed and the |
| 430 | // run-time Chrome icon is merged with the taskbar shortcut), but this is not |
| 431 | // urgent and shouldn't delay Chrome startup. |
| 432 | static const int64 kMigrateChromiumShortcutsDelaySeconds = 15; |
| 433 | BrowserThread::PostDelayedTask( |
[email protected] | 3a3e72c | 2011-11-29 02:59:38 | [diff] [blame] | 434 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 81fcf95 | 2012-11-26 22:25:14 | [diff] [blame] | 435 | base::Bind(&MigrateChromiumShortcutsCallback), |
| 436 | base::TimeDelta::FromSeconds(kMigrateChromiumShortcutsDelaySeconds)); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 437 | } |
[email protected] | 43903b8 | 2012-06-01 05:26:23 | [diff] [blame] | 438 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 439 | int ShellIntegration::MigrateShortcutsInPathInternal( |
| 440 | const base::FilePath& chrome_exe, |
| 441 | const base::FilePath& path, |
| 442 | bool check_dual_mode) { |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 443 | DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); |
| 444 | |
| 445 | // Enumerate all pinned shortcuts in the given path directly. |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 446 | base::FileEnumerator shortcuts_enum( |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 447 | path, false, // not recursive |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 448 | base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 449 | |
| 450 | bool is_per_user_install = |
| 451 | InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()); |
| 452 | |
| 453 | int shortcuts_migrated = 0; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 454 | base::FilePath target_path; |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 455 | base::string16 arguments; |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 456 | base::win::ScopedPropVariant propvariant; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 457 | for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 458 | shortcut = shortcuts_enum.Next()) { |
| 459 | // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once |
| 460 | // it is fixed to work with FilePaths with spaces. |
| 461 | if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) || |
| 462 | chrome_exe != target_path) { |
| 463 | continue; |
| 464 | } |
| 465 | CommandLine command_line(CommandLine::FromString(base::StringPrintf( |
| 466 | L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str()))); |
| 467 | |
| 468 | // Get the expected AppId for this Chrome shortcut. |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 469 | base::string16 expected_app_id( |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 470 | GetExpectedAppId(command_line, is_per_user_install)); |
| 471 | if (expected_app_id.empty()) |
| 472 | continue; |
| 473 | |
| 474 | // Load the shortcut. |
| 475 | base::win::ScopedComPtr<IShellLink> shell_link; |
| 476 | base::win::ScopedComPtr<IPersistFile> persist_file; |
| 477 | if (FAILED(shell_link.CreateInstance(CLSID_ShellLink, NULL, |
| 478 | CLSCTX_INPROC_SERVER)) || |
dcheng | 81762e0 | 2014-11-21 21:22:28 | [diff] [blame] | 479 | FAILED(persist_file.QueryFrom(shell_link.get())) || |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 480 | FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) { |
| 481 | DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value(); |
| 482 | continue; |
| 483 | } |
| 484 | |
| 485 | // Any properties that need to be updated on the shortcut will be stored in |
| 486 | // |updated_properties|. |
| 487 | base::win::ShortcutProperties updated_properties; |
| 488 | |
| 489 | // Validate the existing app id for the shortcut. |
| 490 | base::win::ScopedComPtr<IPropertyStore> property_store; |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 491 | propvariant.Reset(); |
dcheng | 81762e0 | 2014-11-21 21:22:28 | [diff] [blame] | 492 | if (FAILED(property_store.QueryFrom(shell_link.get())) || |
| 493 | property_store->GetValue(PKEY_AppUserModel_ID, propvariant.Receive()) != |
| 494 | S_OK) { |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 495 | // When in doubt, prefer not updating the shortcut. |
| 496 | NOTREACHED(); |
| 497 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 498 | } else { |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 499 | switch (propvariant.get().vt) { |
| 500 | case VT_EMPTY: |
| 501 | // If there is no app_id set, set our app_id if one is expected. |
| 502 | if (!expected_app_id.empty()) |
| 503 | updated_properties.set_app_id(expected_app_id); |
| 504 | break; |
| 505 | case VT_LPWSTR: |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 506 | if (expected_app_id != base::string16(propvariant.get().pwszVal)) |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 507 | updated_properties.set_app_id(expected_app_id); |
| 508 | break; |
| 509 | default: |
| 510 | NOTREACHED(); |
| 511 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 515 | // Only set dual mode if the expected app id is the default app id. |
| 516 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 517 | base::string16 default_chromium_model_id( |
[email protected] | b39e32e | 2013-04-24 08:55:54 | [diff] [blame] | 518 | ShellUtil::GetBrowserModelId(dist, is_per_user_install)); |
| 519 | if (check_dual_mode && expected_app_id == default_chromium_model_id) { |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 520 | propvariant.Reset(); |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 521 | if (property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 522 | propvariant.Receive()) != S_OK) { |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 523 | // When in doubt, prefer to not update the shortcut. |
| 524 | NOTREACHED(); |
| 525 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 526 | } else { |
[email protected] | 0798330 | 2013-01-21 19:41:44 | [diff] [blame] | 527 | switch (propvariant.get().vt) { |
| 528 | case VT_EMPTY: |
| 529 | // If dual_mode is not set at all, make sure it gets set to true. |
| 530 | updated_properties.set_dual_mode(true); |
| 531 | break; |
| 532 | case VT_BOOL: |
| 533 | // If it is set to false, make sure it gets set to true as well. |
| 534 | if (!propvariant.get().boolVal) |
| 535 | updated_properties.set_dual_mode(true); |
| 536 | break; |
| 537 | default: |
| 538 | NOTREACHED(); |
| 539 | continue; |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 540 | } |
[email protected] | 8ea8f1ef | 2013-01-06 18:39:03 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | persist_file.Release(); |
| 545 | shell_link.Release(); |
| 546 | |
| 547 | // Update the shortcut if some of its properties need to be updated. |
| 548 | if (updated_properties.options && |
| 549 | base::win::CreateOrUpdateShortcutLink( |
| 550 | shortcut, updated_properties, |
| 551 | base::win::SHORTCUT_UPDATE_EXISTING)) { |
| 552 | ++shortcuts_migrated; |
| 553 | } |
| 554 | } |
| 555 | return shortcuts_migrated; |
| 556 | } |
| 557 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 558 | base::FilePath ShellIntegration::GetStartMenuShortcut( |
| 559 | const base::FilePath& chrome_exe) { |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 560 | static const int kFolderIds[] = { |
| 561 | base::DIR_COMMON_START_MENU, |
| 562 | base::DIR_START_MENU, |
| 563 | }; |
| 564 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 565 | base::string16 shortcut_name( |
[email protected] | 16fcc0d | 2013-08-14 04:22:13 | [diff] [blame] | 566 | dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME)); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 567 | base::FilePath shortcut; |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 568 | |
| 569 | // Check both the common and the per-user Start Menu folders for system-level |
| 570 | // installs. |
| 571 | size_t folder = |
| 572 | InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()) ? 1 : 0; |
| 573 | for (; folder < arraysize(kFolderIds); ++folder) { |
| 574 | if (!PathService::Get(kFolderIds[folder], &shortcut)) { |
| 575 | NOTREACHED(); |
| 576 | continue; |
| 577 | } |
| 578 | |
[email protected] | 126f462 | 2012-10-05 01:34:05 | [diff] [blame] | 579 | shortcut = shortcut.Append(shortcut_name).Append(shortcut_name + |
| 580 | installer::kLnkExt); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 581 | if (base::PathExists(shortcut)) |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 582 | return shortcut; |
| 583 | } |
| 584 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 585 | return base::FilePath(); |
[email protected] | 3f69d6e61 | 2012-08-03 18:52:27 | [diff] [blame] | 586 | } |