| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
| 6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
| 7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
| 8 // this class. | 8 // this class. |
| 9 | 9 |
| 10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 DWORD type_mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | | 95 DWORD type_mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | |
| 96 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR; | 96 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR; |
| 97 | 97 |
| 98 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; | 98 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Returns the current (or installed) browser's ProgId (e.g. | 101 // Returns the current (or installed) browser's ProgId (e.g. |
| 102 // "ChromeHTML|suffix|"). | 102 // "ChromeHTML|suffix|"). |
| 103 // |suffix| can be the empty string. | 103 // |suffix| can be the empty string. |
| 104 string16 GetBrowserProgId(const string16& suffix) { | 104 base::string16 GetBrowserProgId(const base::string16& suffix) { |
| 105 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 105 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 106 string16 chrome_html(dist->GetBrowserProgIdPrefix()); | 106 base::string16 chrome_html(dist->GetBrowserProgIdPrefix()); |
| 107 chrome_html.append(suffix); | 107 chrome_html.append(suffix); |
| 108 | 108 |
| 109 // ProgIds cannot be longer than 39 characters. | 109 // ProgIds cannot be longer than 39 characters. |
| 110 // Ref: http://msdn.microsoft.com/en-us/library/aa911706.aspx. | 110 // Ref: http://msdn.microsoft.com/en-us/library/aa911706.aspx. |
| 111 // Make all new registrations comply with this requirement (existing | 111 // Make all new registrations comply with this requirement (existing |
| 112 // registrations must be preserved). | 112 // registrations must be preserved). |
| 113 string16 new_style_suffix; | 113 base::string16 new_style_suffix; |
| 114 if (ShellUtil::GetUserSpecificRegistrySuffix(&new_style_suffix) && | 114 if (ShellUtil::GetUserSpecificRegistrySuffix(&new_style_suffix) && |
| 115 suffix == new_style_suffix && chrome_html.length() > 39) { | 115 suffix == new_style_suffix && chrome_html.length() > 39) { |
| 116 NOTREACHED(); | 116 NOTREACHED(); |
| 117 chrome_html.erase(39); | 117 chrome_html.erase(39); |
| 118 } | 118 } |
| 119 return chrome_html; | 119 return chrome_html; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // This class is used to initialize and cache a base 32 encoding of the md5 hash | 122 // This class is used to initialize and cache a base 32 encoding of the md5 hash |
| 123 // of this user's sid preceded by a dot. | 123 // of this user's sid preceded by a dot. |
| 124 // This is guaranteed to be unique on the machine and 27 characters long | 124 // This is guaranteed to be unique on the machine and 27 characters long |
| 125 // (including the '.'). | 125 // (including the '.'). |
| 126 // This is then meant to be used as a suffix on all registrations that may | 126 // This is then meant to be used as a suffix on all registrations that may |
| 127 // conflict with another user-level Chrome install. | 127 // conflict with another user-level Chrome install. |
| 128 class UserSpecificRegistrySuffix { | 128 class UserSpecificRegistrySuffix { |
| 129 public: | 129 public: |
| 130 // All the initialization is done in the constructor to be able to build the | 130 // All the initialization is done in the constructor to be able to build the |
| 131 // suffix in a thread-safe manner when used in conjunction with a | 131 // suffix in a thread-safe manner when used in conjunction with a |
| 132 // LazyInstance. | 132 // LazyInstance. |
| 133 UserSpecificRegistrySuffix(); | 133 UserSpecificRegistrySuffix(); |
| 134 | 134 |
| 135 // Sets |suffix| to the pre-computed suffix cached in this object. | 135 // Sets |suffix| to the pre-computed suffix cached in this object. |
| 136 // Returns true unless the initialization originally failed. | 136 // Returns true unless the initialization originally failed. |
| 137 bool GetSuffix(string16* suffix); | 137 bool GetSuffix(base::string16* suffix); |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 string16 suffix_; | 140 base::string16 suffix_; |
| 141 | 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(UserSpecificRegistrySuffix); | 142 DISALLOW_COPY_AND_ASSIGN(UserSpecificRegistrySuffix); |
| 143 }; // class UserSpecificRegistrySuffix | 143 }; // class UserSpecificRegistrySuffix |
| 144 | 144 |
| 145 UserSpecificRegistrySuffix::UserSpecificRegistrySuffix() { | 145 UserSpecificRegistrySuffix::UserSpecificRegistrySuffix() { |
| 146 string16 user_sid; | 146 base::string16 user_sid; |
| 147 if (!base::win::GetUserSidString(&user_sid)) { | 147 if (!base::win::GetUserSidString(&user_sid)) { |
| 148 NOTREACHED(); | 148 NOTREACHED(); |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 COMPILE_ASSERT(sizeof(base::MD5Digest) == 16, size_of_MD5_not_as_expected_); | 151 COMPILE_ASSERT(sizeof(base::MD5Digest) == 16, size_of_MD5_not_as_expected_); |
| 152 base::MD5Digest md5_digest; | 152 base::MD5Digest md5_digest; |
| 153 std::string user_sid_ascii(UTF16ToASCII(user_sid)); | 153 std::string user_sid_ascii(UTF16ToASCII(user_sid)); |
| 154 base::MD5Sum(user_sid_ascii.c_str(), user_sid_ascii.length(), &md5_digest); | 154 base::MD5Sum(user_sid_ascii.c_str(), user_sid_ascii.length(), &md5_digest); |
| 155 const string16 base32_md5( | 155 const base::string16 base32_md5( |
| 156 ShellUtil::ByteArrayToBase32(md5_digest.a, arraysize(md5_digest.a))); | 156 ShellUtil::ByteArrayToBase32(md5_digest.a, arraysize(md5_digest.a))); |
| 157 // The value returned by the base32 algorithm above must never change and | 157 // The value returned by the base32 algorithm above must never change and |
| 158 // must always be 26 characters long (i.e. if someone ever moves this to | 158 // must always be 26 characters long (i.e. if someone ever moves this to |
| 159 // base and implements the full base32 algorithm (i.e. with appended '=' | 159 // base and implements the full base32 algorithm (i.e. with appended '=' |
| 160 // signs in the output), they must provide a flag to allow this method to | 160 // signs in the output), they must provide a flag to allow this method to |
| 161 // still request the output with no appended '=' signs). | 161 // still request the output with no appended '=' signs). |
| 162 DCHECK_EQ(base32_md5.length(), 26U); | 162 DCHECK_EQ(base32_md5.length(), 26U); |
| 163 suffix_.reserve(base32_md5.length() + 1); | 163 suffix_.reserve(base32_md5.length() + 1); |
| 164 suffix_.assign(1, L'.'); | 164 suffix_.assign(1, L'.'); |
| 165 suffix_.append(base32_md5); | 165 suffix_.append(base32_md5); |
| 166 } | 166 } |
| 167 | 167 |
| 168 bool UserSpecificRegistrySuffix::GetSuffix(string16* suffix) { | 168 bool UserSpecificRegistrySuffix::GetSuffix(base::string16* suffix) { |
| 169 if (suffix_.empty()) { | 169 if (suffix_.empty()) { |
| 170 NOTREACHED(); | 170 NOTREACHED(); |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 suffix->assign(suffix_); | 173 suffix->assign(suffix_); |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // This class represents a single registry entry. The objective is to | 177 // This class represents a single registry entry. The objective is to |
| 178 // encapsulate all the registry entries required for registering Chrome at one | 178 // encapsulate all the registry entries required for registering Chrome at one |
| 179 // place. This class can not be instantiated outside the class and the objects | 179 // place. This class can not be instantiated outside the class and the objects |
| 180 // of this class type can be obtained only by calling a static method of this | 180 // of this class type can be obtained only by calling a static method of this |
| 181 // class. | 181 // class. |
| 182 class RegistryEntry { | 182 class RegistryEntry { |
| 183 public: | 183 public: |
| 184 // A bit-field enum of places to look for this key in the Windows registry. | 184 // A bit-field enum of places to look for this key in the Windows registry. |
| 185 enum LookForIn { | 185 enum LookForIn { |
| 186 LOOK_IN_HKCU = 1 << 0, | 186 LOOK_IN_HKCU = 1 << 0, |
| 187 LOOK_IN_HKLM = 1 << 1, | 187 LOOK_IN_HKLM = 1 << 1, |
| 188 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, | 188 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 // Returns the Windows browser client registration key for Chrome. For | 191 // Returns the Windows browser client registration key for Chrome. For |
| 192 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly | 192 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly |
| 193 // speaking, we should use the name of the executable (e.g., "chrome.exe"), | 193 // speaking, we should use the name of the executable (e.g., "chrome.exe"), |
| 194 // but that ship has sailed. The cost of switching now is re-prompting users | 194 // but that ship has sailed. The cost of switching now is re-prompting users |
| 195 // to make Chrome their default browser, which isn't polite. |suffix| is the | 195 // to make Chrome their default browser, which isn't polite. |suffix| is the |
| 196 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix | 196 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix |
| 197 // in shell_util.h for details. | 197 // in shell_util.h for details. |
| 198 static string16 GetBrowserClientKey(BrowserDistribution* dist, | 198 static base::string16 GetBrowserClientKey(BrowserDistribution* dist, |
| 199 const string16& suffix) { | 199 const base::string16& suffix) { |
| 200 DCHECK(suffix.empty() || suffix[0] == L'.'); | 200 DCHECK(suffix.empty() || suffix[0] == L'.'); |
| 201 return string16(ShellUtil::kRegStartMenuInternet) | 201 return base::string16(ShellUtil::kRegStartMenuInternet) |
| 202 .append(1, L'\\') | 202 .append(1, L'\\') |
| 203 .append(dist->GetBaseAppName()) | 203 .append(dist->GetBaseAppName()) |
| 204 .append(suffix); | 204 .append(suffix); |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Returns the Windows Default Programs capabilities key for Chrome. For | 207 // Returns the Windows Default Programs capabilities key for Chrome. For |
| 208 // example: | 208 // example: |
| 209 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". | 209 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". |
| 210 static string16 GetCapabilitiesKey(BrowserDistribution* dist, | 210 static base::string16 GetCapabilitiesKey(BrowserDistribution* dist, |
| 211 const string16& suffix) { | 211 const base::string16& suffix) { |
| 212 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); | 212 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // This method returns a list of all the registry entries that | 215 // This method returns a list of all the registry entries that |
| 216 // are needed to register this installation's ProgId and AppId. | 216 // are needed to register this installation's ProgId and AppId. |
| 217 // These entries need to be registered in HKLM prior to Win8. | 217 // These entries need to be registered in HKLM prior to Win8. |
| 218 static void GetProgIdEntries(BrowserDistribution* dist, | 218 static void GetProgIdEntries(BrowserDistribution* dist, |
| 219 const string16& chrome_exe, | 219 const base::string16& chrome_exe, |
| 220 const string16& suffix, | 220 const base::string16& suffix, |
| 221 ScopedVector<RegistryEntry>* entries) { | 221 ScopedVector<RegistryEntry>* entries) { |
| 222 string16 icon_path( | 222 base::string16 icon_path( |
| 223 ShellUtil::FormatIconLocation( | 223 ShellUtil::FormatIconLocation( |
| 224 chrome_exe, | 224 chrome_exe, |
| 225 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); | 225 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
| 226 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 226 base::string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
| 227 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); | 227 base::string16 delegate_command( |
| 228 ShellUtil::GetChromeDelegateCommand(chrome_exe)); |
| 228 // For user-level installs: entries for the app id and DelegateExecute verb | 229 // For user-level installs: entries for the app id and DelegateExecute verb |
| 229 // handler will be in HKCU; thus we do not need a suffix on those entries. | 230 // handler will be in HKCU; thus we do not need a suffix on those entries. |
| 230 string16 app_id( | 231 base::string16 app_id( |
| 231 ShellUtil::GetBrowserModelId( | 232 ShellUtil::GetBrowserModelId( |
| 232 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); | 233 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); |
| 233 string16 delegate_guid; | 234 base::string16 delegate_guid; |
| 234 bool set_delegate_execute = | 235 bool set_delegate_execute = |
| 235 IsChromeMetroSupported() && | 236 IsChromeMetroSupported() && |
| 236 dist->GetCommandExecuteImplClsid(&delegate_guid); | 237 dist->GetCommandExecuteImplClsid(&delegate_guid); |
| 237 | 238 |
| 238 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. | 239 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. |
| 239 if (set_delegate_execute) { | 240 if (set_delegate_execute) { |
| 240 string16 model_id_shell(ShellUtil::kRegClasses); | 241 base::string16 model_id_shell(ShellUtil::kRegClasses); |
| 241 model_id_shell.push_back(base::FilePath::kSeparators[0]); | 242 model_id_shell.push_back(base::FilePath::kSeparators[0]); |
| 242 model_id_shell.append(app_id); | 243 model_id_shell.append(app_id); |
| 243 model_id_shell.append(ShellUtil::kRegExePath); | 244 model_id_shell.append(ShellUtil::kRegExePath); |
| 244 model_id_shell.append(ShellUtil::kRegShellPath); | 245 model_id_shell.append(ShellUtil::kRegShellPath); |
| 245 | 246 |
| 246 // <root hkey>\Software\Classes\<app_id>\.exe\shell @=open | 247 // <root hkey>\Software\Classes\<app_id>\.exe\shell @=open |
| 247 entries->push_back(new RegistryEntry(model_id_shell, | 248 entries->push_back(new RegistryEntry(model_id_shell, |
| 248 ShellUtil::kRegVerbOpen)); | 249 ShellUtil::kRegVerbOpen)); |
| 249 | 250 |
| 250 // Each of Chrome's shortcuts has an appid; which, as of Windows 8, is | 251 // Each of Chrome's shortcuts has an appid; which, as of Windows 8, is |
| 251 // registered to handle some verbs. This registration has the side-effect | 252 // registered to handle some verbs. This registration has the side-effect |
| 252 // that these verbs now show up in the shortcut's context menu. We | 253 // that these verbs now show up in the shortcut's context menu. We |
| 253 // mitigate this side-effect by making the context menu entries | 254 // mitigate this side-effect by making the context menu entries |
| 254 // user readable/localized strings. See relevant MSDN article: | 255 // user readable/localized strings. See relevant MSDN article: |
| 255 // http://msdn.microsoft.com/en-US/library/windows/desktop/cc144171.aspx | 256 // http://msdn.microsoft.com/en-US/library/windows/desktop/cc144171.aspx |
| 256 const struct { | 257 const struct { |
| 257 const wchar_t* verb; | 258 const wchar_t* verb; |
| 258 int name_id; | 259 int name_id; |
| 259 } verbs[] = { | 260 } verbs[] = { |
| 260 { ShellUtil::kRegVerbOpen, -1 }, | 261 { ShellUtil::kRegVerbOpen, -1 }, |
| 261 { ShellUtil::kRegVerbOpenNewWindow, IDS_SHORTCUT_NEW_WINDOW_BASE }, | 262 { ShellUtil::kRegVerbOpenNewWindow, IDS_SHORTCUT_NEW_WINDOW_BASE }, |
| 262 }; | 263 }; |
| 263 for (size_t i = 0; i < arraysize(verbs); ++i) { | 264 for (size_t i = 0; i < arraysize(verbs); ++i) { |
| 264 string16 sub_path(model_id_shell); | 265 base::string16 sub_path(model_id_shell); |
| 265 sub_path.push_back(base::FilePath::kSeparators[0]); | 266 sub_path.push_back(base::FilePath::kSeparators[0]); |
| 266 sub_path.append(verbs[i].verb); | 267 sub_path.append(verbs[i].verb); |
| 267 | 268 |
| 268 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb> | 269 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb> |
| 269 if (verbs[i].name_id != -1) { | 270 if (verbs[i].name_id != -1) { |
| 270 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 271 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 271 // resource. | 272 // resource. |
| 272 string16 verb_name(installer::GetLocalizedString(verbs[i].name_id)); | 273 base::string16 verb_name( |
| 274 installer::GetLocalizedString(verbs[i].name_id)); |
| 273 entries->push_back(new RegistryEntry(sub_path, verb_name.c_str())); | 275 entries->push_back(new RegistryEntry(sub_path, verb_name.c_str())); |
| 274 } | 276 } |
| 275 entries->push_back(new RegistryEntry( | 277 entries->push_back(new RegistryEntry( |
| 276 sub_path, L"CommandId", L"Browser.Launch")); | 278 sub_path, L"CommandId", L"Browser.Launch")); |
| 277 | 279 |
| 278 sub_path.push_back(base::FilePath::kSeparators[0]); | 280 sub_path.push_back(base::FilePath::kSeparators[0]); |
| 279 sub_path.append(ShellUtil::kRegCommand); | 281 sub_path.append(ShellUtil::kRegCommand); |
| 280 | 282 |
| 281 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command | 283 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command |
| 282 entries->push_back(new RegistryEntry(sub_path, delegate_command)); | 284 entries->push_back(new RegistryEntry(sub_path, delegate_command)); |
| 283 entries->push_back(new RegistryEntry( | 285 entries->push_back(new RegistryEntry( |
| 284 sub_path, ShellUtil::kRegDelegateExecute, delegate_guid)); | 286 sub_path, ShellUtil::kRegDelegateExecute, delegate_guid)); |
| 285 } | 287 } |
| 286 } | 288 } |
| 287 | 289 |
| 288 // File association ProgId | 290 // File association ProgId |
| 289 string16 chrome_html_prog_id(ShellUtil::kRegClasses); | 291 base::string16 chrome_html_prog_id(ShellUtil::kRegClasses); |
| 290 chrome_html_prog_id.push_back(base::FilePath::kSeparators[0]); | 292 chrome_html_prog_id.push_back(base::FilePath::kSeparators[0]); |
| 291 chrome_html_prog_id.append(GetBrowserProgId(suffix)); | 293 chrome_html_prog_id.append(GetBrowserProgId(suffix)); |
| 292 entries->push_back(new RegistryEntry( | 294 entries->push_back(new RegistryEntry( |
| 293 chrome_html_prog_id, dist->GetBrowserProgIdDesc())); | 295 chrome_html_prog_id, dist->GetBrowserProgIdDesc())); |
| 294 entries->push_back(new RegistryEntry( | 296 entries->push_back(new RegistryEntry( |
| 295 chrome_html_prog_id, ShellUtil::kRegUrlProtocol, L"")); | 297 chrome_html_prog_id, ShellUtil::kRegUrlProtocol, L"")); |
| 296 entries->push_back(new RegistryEntry( | 298 entries->push_back(new RegistryEntry( |
| 297 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); | 299 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); |
| 298 entries->push_back(new RegistryEntry( | 300 entries->push_back(new RegistryEntry( |
| 299 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); | 301 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); |
| 300 if (set_delegate_execute) { | 302 if (set_delegate_execute) { |
| 301 entries->push_back(new RegistryEntry( | 303 entries->push_back(new RegistryEntry( |
| 302 chrome_html_prog_id + ShellUtil::kRegShellOpen, | 304 chrome_html_prog_id + ShellUtil::kRegShellOpen, |
| 303 ShellUtil::kRegDelegateExecute, delegate_guid)); | 305 ShellUtil::kRegDelegateExecute, delegate_guid)); |
| 304 } | 306 } |
| 305 | 307 |
| 306 // The following entries are required as of Windows 8, but do not | 308 // The following entries are required as of Windows 8, but do not |
| 307 // depend on the DelegateExecute verb handler being set. | 309 // depend on the DelegateExecute verb handler being set. |
| 308 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 310 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 309 entries->push_back(new RegistryEntry( | 311 entries->push_back(new RegistryEntry( |
| 310 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); | 312 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); |
| 311 | 313 |
| 312 // Add \Software\Classes\ChromeHTML\Application entries | 314 // Add \Software\Classes\ChromeHTML\Application entries |
| 313 string16 chrome_application(chrome_html_prog_id + | 315 base::string16 chrome_application(chrome_html_prog_id + |
| 314 ShellUtil::kRegApplication); | 316 ShellUtil::kRegApplication); |
| 315 entries->push_back(new RegistryEntry( | 317 entries->push_back(new RegistryEntry( |
| 316 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); | 318 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); |
| 317 entries->push_back(new RegistryEntry( | 319 entries->push_back(new RegistryEntry( |
| 318 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); | 320 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); |
| 319 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 321 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 320 // resource for name, description, and company. | 322 // resource for name, description, and company. |
| 321 entries->push_back(new RegistryEntry( | 323 entries->push_back(new RegistryEntry( |
| 322 chrome_application, ShellUtil::kRegApplicationName, | 324 chrome_application, ShellUtil::kRegApplicationName, |
| 323 dist->GetDisplayName())); | 325 dist->GetDisplayName())); |
| 324 entries->push_back(new RegistryEntry( | 326 entries->push_back(new RegistryEntry( |
| 325 chrome_application, ShellUtil::kRegApplicationDescription, | 327 chrome_application, ShellUtil::kRegApplicationDescription, |
| 326 dist->GetAppDescription())); | 328 dist->GetAppDescription())); |
| 327 entries->push_back(new RegistryEntry( | 329 entries->push_back(new RegistryEntry( |
| 328 chrome_application, ShellUtil::kRegApplicationCompany, | 330 chrome_application, ShellUtil::kRegApplicationCompany, |
| 329 dist->GetPublisherName())); | 331 dist->GetPublisherName())); |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 // This method returns a list of the registry entries needed to declare a | 335 // This method returns a list of the registry entries needed to declare a |
| 334 // capability of handling a protocol on Windows. | 336 // capability of handling a protocol on Windows. |
| 335 static void GetProtocolCapabilityEntries( | 337 static void GetProtocolCapabilityEntries( |
| 336 BrowserDistribution* dist, | 338 BrowserDistribution* dist, |
| 337 const string16& suffix, | 339 const base::string16& suffix, |
| 338 const string16& protocol, | 340 const base::string16& protocol, |
| 339 ScopedVector<RegistryEntry>* entries) { | 341 ScopedVector<RegistryEntry>* entries) { |
| 340 entries->push_back(new RegistryEntry( | 342 entries->push_back(new RegistryEntry( |
| 341 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), | 343 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), |
| 342 protocol, GetBrowserProgId(suffix))); | 344 protocol, GetBrowserProgId(suffix))); |
| 343 } | 345 } |
| 344 | 346 |
| 345 // This method returns a list of the registry entries required to register | 347 // This method returns a list of the registry entries required to register |
| 346 // this installation in "RegisteredApplications" on Windows (to appear in | 348 // this installation in "RegisteredApplications" on Windows (to appear in |
| 347 // Default Programs, StartMenuInternet, etc.). | 349 // Default Programs, StartMenuInternet, etc.). |
| 348 // These entries need to be registered in HKLM prior to Win8. | 350 // These entries need to be registered in HKLM prior to Win8. |
| 349 // If |suffix| is not empty, these entries are guaranteed to be unique on this | 351 // If |suffix| is not empty, these entries are guaranteed to be unique on this |
| 350 // machine. | 352 // machine. |
| 351 static void GetShellIntegrationEntries(BrowserDistribution* dist, | 353 static void GetShellIntegrationEntries(BrowserDistribution* dist, |
| 352 const string16& chrome_exe, | 354 const base::string16& chrome_exe, |
| 353 const string16& suffix, | 355 const base::string16& suffix, |
| 354 ScopedVector<RegistryEntry>* entries) { | 356 ScopedVector<RegistryEntry>* entries) { |
| 355 const string16 icon_path( | 357 const base::string16 icon_path( |
| 356 ShellUtil::FormatIconLocation( | 358 ShellUtil::FormatIconLocation( |
| 357 chrome_exe, | 359 chrome_exe, |
| 358 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); | 360 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
| 359 const string16 quoted_exe_path(L"\"" + chrome_exe + L"\""); | 361 const base::string16 quoted_exe_path(L"\"" + chrome_exe + L"\""); |
| 360 | 362 |
| 361 // Register for the Start Menu "Internet" link (pre-Win7). | 363 // Register for the Start Menu "Internet" link (pre-Win7). |
| 362 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); | 364 const base::string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); |
| 363 // Register Chrome's display name. | 365 // Register Chrome's display name. |
| 364 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see | 366 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see |
| 365 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name | 367 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name |
| 366 entries->push_back(new RegistryEntry( | 368 entries->push_back(new RegistryEntry( |
| 367 start_menu_entry, dist->GetDisplayName())); | 369 start_menu_entry, dist->GetDisplayName())); |
| 368 // Register the "open" verb for launching Chrome via the "Internet" link. | 370 // Register the "open" verb for launching Chrome via the "Internet" link. |
| 369 entries->push_back(new RegistryEntry( | 371 entries->push_back(new RegistryEntry( |
| 370 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); | 372 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); |
| 371 // Register Chrome's icon for the Start Menu "Internet" link. | 373 // Register Chrome's icon for the Start Menu "Internet" link. |
| 372 entries->push_back(new RegistryEntry( | 374 entries->push_back(new RegistryEntry( |
| 373 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); | 375 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); |
| 374 | 376 |
| 375 // Register installation information. | 377 // Register installation information. |
| 376 string16 install_info(start_menu_entry + L"\\InstallInfo"); | 378 base::string16 install_info(start_menu_entry + L"\\InstallInfo"); |
| 377 // Note: not using CommandLine since it has ambiguous rules for quoting | 379 // Note: not using CommandLine since it has ambiguous rules for quoting |
| 378 // strings. | 380 // strings. |
| 379 entries->push_back(new RegistryEntry(install_info, kReinstallCommand, | 381 entries->push_back(new RegistryEntry(install_info, kReinstallCommand, |
| 380 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); | 382 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); |
| 381 entries->push_back(new RegistryEntry(install_info, L"HideIconsCommand", | 383 entries->push_back(new RegistryEntry(install_info, L"HideIconsCommand", |
| 382 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); | 384 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); |
| 383 entries->push_back(new RegistryEntry(install_info, L"ShowIconsCommand", | 385 entries->push_back(new RegistryEntry(install_info, L"ShowIconsCommand", |
| 384 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); | 386 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); |
| 385 entries->push_back(new RegistryEntry(install_info, L"IconsVisible", 1)); | 387 entries->push_back(new RegistryEntry(install_info, L"IconsVisible", 1)); |
| 386 | 388 |
| 387 // Register with Default Programs. | 389 // Register with Default Programs. |
| 388 const string16 reg_app_name(dist->GetBaseAppName().append(suffix)); | 390 const base::string16 reg_app_name(dist->GetBaseAppName().append(suffix)); |
| 389 // Tell Windows where to find Chrome's Default Programs info. | 391 // Tell Windows where to find Chrome's Default Programs info. |
| 390 const string16 capabilities(GetCapabilitiesKey(dist, suffix)); | 392 const base::string16 capabilities(GetCapabilitiesKey(dist, suffix)); |
| 391 entries->push_back(new RegistryEntry(ShellUtil::kRegRegisteredApplications, | 393 entries->push_back(new RegistryEntry(ShellUtil::kRegRegisteredApplications, |
| 392 reg_app_name, capabilities)); | 394 reg_app_name, capabilities)); |
| 393 // Write out Chrome's Default Programs info. | 395 // Write out Chrome's Default Programs info. |
| 394 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 396 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 395 // resource rather than this. | 397 // resource rather than this. |
| 396 entries->push_back(new RegistryEntry( | 398 entries->push_back(new RegistryEntry( |
| 397 capabilities, ShellUtil::kRegApplicationDescription, | 399 capabilities, ShellUtil::kRegApplicationDescription, |
| 398 dist->GetLongAppDescription())); | 400 dist->GetLongAppDescription())); |
| 399 entries->push_back(new RegistryEntry( | 401 entries->push_back(new RegistryEntry( |
| 400 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 402 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
| 401 entries->push_back(new RegistryEntry( | 403 entries->push_back(new RegistryEntry( |
| 402 capabilities, ShellUtil::kRegApplicationName, | 404 capabilities, ShellUtil::kRegApplicationName, |
| 403 dist->GetDisplayName())); | 405 dist->GetDisplayName())); |
| 404 | 406 |
| 405 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", | 407 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", |
| 406 L"StartMenuInternet", reg_app_name)); | 408 L"StartMenuInternet", reg_app_name)); |
| 407 | 409 |
| 408 const string16 html_prog_id(GetBrowserProgId(suffix)); | 410 const base::string16 html_prog_id(GetBrowserProgId(suffix)); |
| 409 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { | 411 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { |
| 410 entries->push_back(new RegistryEntry( | 412 entries->push_back(new RegistryEntry( |
| 411 capabilities + L"\\FileAssociations", | 413 capabilities + L"\\FileAssociations", |
| 412 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); | 414 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); |
| 413 } | 415 } |
| 414 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; | 416 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; |
| 415 i++) { | 417 i++) { |
| 416 entries->push_back(new RegistryEntry( | 418 entries->push_back(new RegistryEntry( |
| 417 capabilities + L"\\URLAssociations", | 419 capabilities + L"\\URLAssociations", |
| 418 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); | 420 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); |
| 419 } | 421 } |
| 420 } | 422 } |
| 421 | 423 |
| 422 // This method returns a list of the registry entries required for this | 424 // This method returns a list of the registry entries required for this |
| 423 // installation to be registered in the Windows shell. | 425 // installation to be registered in the Windows shell. |
| 424 // In particular: | 426 // In particular: |
| 425 // - App Paths | 427 // - App Paths |
| 426 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 | 428 // http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 |
| 427 // - File Associations | 429 // - File Associations |
| 428 // http://msdn.microsoft.com/en-us/library/bb166549 | 430 // http://msdn.microsoft.com/en-us/library/bb166549 |
| 429 // These entries need to be registered in HKLM prior to Win8. | 431 // These entries need to be registered in HKLM prior to Win8. |
| 430 static void GetAppRegistrationEntries(const string16& chrome_exe, | 432 static void GetAppRegistrationEntries(const base::string16& chrome_exe, |
| 431 const string16& suffix, | 433 const base::string16& suffix, |
| 432 ScopedVector<RegistryEntry>* entries) { | 434 ScopedVector<RegistryEntry>* entries) { |
| 433 const base::FilePath chrome_path(chrome_exe); | 435 const base::FilePath chrome_path(chrome_exe); |
| 434 string16 app_path_key(ShellUtil::kAppPathsRegistryKey); | 436 base::string16 app_path_key(ShellUtil::kAppPathsRegistryKey); |
| 435 app_path_key.push_back(base::FilePath::kSeparators[0]); | 437 app_path_key.push_back(base::FilePath::kSeparators[0]); |
| 436 app_path_key.append(chrome_path.BaseName().value()); | 438 app_path_key.append(chrome_path.BaseName().value()); |
| 437 entries->push_back(new RegistryEntry(app_path_key, chrome_exe)); | 439 entries->push_back(new RegistryEntry(app_path_key, chrome_exe)); |
| 438 entries->push_back(new RegistryEntry(app_path_key, | 440 entries->push_back(new RegistryEntry(app_path_key, |
| 439 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); | 441 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); |
| 440 | 442 |
| 441 const string16 html_prog_id(GetBrowserProgId(suffix)); | 443 const base::string16 html_prog_id(GetBrowserProgId(suffix)); |
| 442 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { | 444 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { |
| 443 string16 key(ShellUtil::kRegClasses); | 445 base::string16 key(ShellUtil::kRegClasses); |
| 444 key.push_back(base::FilePath::kSeparators[0]); | 446 key.push_back(base::FilePath::kSeparators[0]); |
| 445 key.append(ShellUtil::kPotentialFileAssociations[i]); | 447 key.append(ShellUtil::kPotentialFileAssociations[i]); |
| 446 key.push_back(base::FilePath::kSeparators[0]); | 448 key.push_back(base::FilePath::kSeparators[0]); |
| 447 key.append(ShellUtil::kRegOpenWithProgids); | 449 key.append(ShellUtil::kRegOpenWithProgids); |
| 448 entries->push_back(new RegistryEntry(key, html_prog_id, string16())); | 450 entries->push_back( |
| 451 new RegistryEntry(key, html_prog_id, base::string16())); |
| 449 } | 452 } |
| 450 } | 453 } |
| 451 | 454 |
| 452 // This method returns a list of all the user level registry entries that | 455 // This method returns a list of all the user level registry entries that |
| 453 // are needed to make Chromium the default handler for a protocol on XP. | 456 // are needed to make Chromium the default handler for a protocol on XP. |
| 454 static void GetXPStyleUserProtocolEntries( | 457 static void GetXPStyleUserProtocolEntries( |
| 455 const string16& protocol, | 458 const base::string16& protocol, |
| 456 const string16& chrome_icon, | 459 const base::string16& chrome_icon, |
| 457 const string16& chrome_open, | 460 const base::string16& chrome_open, |
| 458 ScopedVector<RegistryEntry>* entries) { | 461 ScopedVector<RegistryEntry>* entries) { |
| 459 // Protocols associations. | 462 // Protocols associations. |
| 460 string16 url_key(ShellUtil::kRegClasses); | 463 base::string16 url_key(ShellUtil::kRegClasses); |
| 461 url_key.push_back(base::FilePath::kSeparators[0]); | 464 url_key.push_back(base::FilePath::kSeparators[0]); |
| 462 url_key.append(protocol); | 465 url_key.append(protocol); |
| 463 | 466 |
| 464 // This registry value tells Windows that this 'class' is a URL scheme | 467 // This registry value tells Windows that this 'class' is a URL scheme |
| 465 // so IE, explorer and other apps will route it to our handler. | 468 // so IE, explorer and other apps will route it to our handler. |
| 466 // <root hkey>\Software\Classes\<protocol>\URL Protocol | 469 // <root hkey>\Software\Classes\<protocol>\URL Protocol |
| 467 entries->push_back(new RegistryEntry(url_key, | 470 entries->push_back(new RegistryEntry(url_key, |
| 468 ShellUtil::kRegUrlProtocol, L"")); | 471 ShellUtil::kRegUrlProtocol, L"")); |
| 469 | 472 |
| 470 // <root hkey>\Software\Classes\<protocol>\DefaultIcon | 473 // <root hkey>\Software\Classes\<protocol>\DefaultIcon |
| 471 string16 icon_key = url_key + ShellUtil::kRegDefaultIcon; | 474 base::string16 icon_key = url_key + ShellUtil::kRegDefaultIcon; |
| 472 entries->push_back(new RegistryEntry(icon_key, chrome_icon)); | 475 entries->push_back(new RegistryEntry(icon_key, chrome_icon)); |
| 473 | 476 |
| 474 // <root hkey>\Software\Classes\<protocol>\shell\open\command | 477 // <root hkey>\Software\Classes\<protocol>\shell\open\command |
| 475 string16 shell_key = url_key + ShellUtil::kRegShellOpen; | 478 base::string16 shell_key = url_key + ShellUtil::kRegShellOpen; |
| 476 entries->push_back(new RegistryEntry(shell_key, chrome_open)); | 479 entries->push_back(new RegistryEntry(shell_key, chrome_open)); |
| 477 | 480 |
| 478 // <root hkey>\Software\Classes\<protocol>\shell\open\ddeexec | 481 // <root hkey>\Software\Classes\<protocol>\shell\open\ddeexec |
| 479 string16 dde_key = url_key + L"\\shell\\open\\ddeexec"; | 482 base::string16 dde_key = url_key + L"\\shell\\open\\ddeexec"; |
| 480 entries->push_back(new RegistryEntry(dde_key, L"")); | 483 entries->push_back(new RegistryEntry(dde_key, L"")); |
| 481 | 484 |
| 482 // <root hkey>\Software\Classes\<protocol>\shell\@ | 485 // <root hkey>\Software\Classes\<protocol>\shell\@ |
| 483 string16 protocol_shell_key = url_key + ShellUtil::kRegShellPath; | 486 base::string16 protocol_shell_key = url_key + ShellUtil::kRegShellPath; |
| 484 entries->push_back(new RegistryEntry(protocol_shell_key, L"open")); | 487 entries->push_back(new RegistryEntry(protocol_shell_key, L"open")); |
| 485 } | 488 } |
| 486 | 489 |
| 487 // This method returns a list of all the user level registry entries that | 490 // This method returns a list of all the user level registry entries that |
| 488 // are needed to make Chromium default browser on XP. | 491 // are needed to make Chromium default browser on XP. |
| 489 // Some of these entries are irrelevant in recent versions of Windows, but | 492 // Some of these entries are irrelevant in recent versions of Windows, but |
| 490 // we register them anyways as some legacy apps are hardcoded to lookup those | 493 // we register them anyways as some legacy apps are hardcoded to lookup those |
| 491 // values. | 494 // values. |
| 492 static void GetXPStyleDefaultBrowserUserEntries( | 495 static void GetXPStyleDefaultBrowserUserEntries( |
| 493 BrowserDistribution* dist, | 496 BrowserDistribution* dist, |
| 494 const string16& chrome_exe, | 497 const base::string16& chrome_exe, |
| 495 const string16& suffix, | 498 const base::string16& suffix, |
| 496 ScopedVector<RegistryEntry>* entries) { | 499 ScopedVector<RegistryEntry>* entries) { |
| 497 // File extension associations. | 500 // File extension associations. |
| 498 string16 html_prog_id(GetBrowserProgId(suffix)); | 501 base::string16 html_prog_id(GetBrowserProgId(suffix)); |
| 499 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { | 502 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { |
| 500 string16 ext_key(ShellUtil::kRegClasses); | 503 base::string16 ext_key(ShellUtil::kRegClasses); |
| 501 ext_key.push_back(base::FilePath::kSeparators[0]); | 504 ext_key.push_back(base::FilePath::kSeparators[0]); |
| 502 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); | 505 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); |
| 503 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); | 506 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); |
| 504 } | 507 } |
| 505 | 508 |
| 506 // Protocols associations. | 509 // Protocols associations. |
| 507 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 510 base::string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
| 508 string16 chrome_icon = | 511 base::string16 chrome_icon = |
| 509 ShellUtil::FormatIconLocation( | 512 ShellUtil::FormatIconLocation( |
| 510 chrome_exe, | 513 chrome_exe, |
| 511 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); | 514 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); |
| 512 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 515 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
| 513 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 516 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
| 514 chrome_icon, chrome_open, entries); | 517 chrome_icon, chrome_open, entries); |
| 515 } | 518 } |
| 516 | 519 |
| 517 // start->Internet shortcut. | 520 // start->Internet shortcut. |
| 518 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 521 base::string16 start_menu(ShellUtil::kRegStartMenuInternet); |
| 519 string16 app_name = dist->GetBaseAppName() + suffix; | 522 base::string16 app_name = dist->GetBaseAppName() + suffix; |
| 520 entries->push_back(new RegistryEntry(start_menu, app_name)); | 523 entries->push_back(new RegistryEntry(start_menu, app_name)); |
| 521 } | 524 } |
| 522 | 525 |
| 523 // Generate work_item tasks required to create current registry entry and | 526 // Generate work_item tasks required to create current registry entry and |
| 524 // add them to the given work item list. | 527 // add them to the given work item list. |
| 525 void AddToWorkItemList(HKEY root, WorkItemList *items) const { | 528 void AddToWorkItemList(HKEY root, WorkItemList *items) const { |
| 526 items->AddCreateRegKeyWorkItem(root, key_path_); | 529 items->AddCreateRegKeyWorkItem(root, key_path_); |
| 527 if (is_string_) { | 530 if (is_string_) { |
| 528 items->AddSetRegValueWorkItem(root, key_path_, name_, value_, true); | 531 items->AddSetRegValueWorkItem(root, key_path_, name_, value_, true); |
| 529 } else { | 532 } else { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 559 enum RegistryStatus { | 562 enum RegistryStatus { |
| 560 // |name_| does not exist in the registry | 563 // |name_| does not exist in the registry |
| 561 DOES_NOT_EXIST, | 564 DOES_NOT_EXIST, |
| 562 // |name_| exists, but its value != |value_| | 565 // |name_| exists, but its value != |value_| |
| 563 DIFFERENT_VALUE, | 566 DIFFERENT_VALUE, |
| 564 // |name_| exists and its value is |value_| | 567 // |name_| exists and its value is |value_| |
| 565 SAME_VALUE, | 568 SAME_VALUE, |
| 566 }; | 569 }; |
| 567 | 570 |
| 568 // Create a object that represent default value of a key | 571 // Create a object that represent default value of a key |
| 569 RegistryEntry(const string16& key_path, const string16& value) | 572 RegistryEntry(const base::string16& key_path, const base::string16& value) |
| 570 : key_path_(key_path), name_(), | 573 : key_path_(key_path), name_(), |
| 571 is_string_(true), value_(value), int_value_(0) { | 574 is_string_(true), value_(value), int_value_(0) { |
| 572 } | 575 } |
| 573 | 576 |
| 574 // Create a object that represent a key of type REG_SZ | 577 // Create a object that represent a key of type REG_SZ |
| 575 RegistryEntry(const string16& key_path, const string16& name, | 578 RegistryEntry(const base::string16& key_path, const base::string16& name, |
| 576 const string16& value) | 579 const base::string16& value) |
| 577 : key_path_(key_path), name_(name), | 580 : key_path_(key_path), name_(name), |
| 578 is_string_(true), value_(value), int_value_(0) { | 581 is_string_(true), value_(value), int_value_(0) { |
| 579 } | 582 } |
| 580 | 583 |
| 581 // Create a object that represent a key of integer type | 584 // Create a object that represent a key of integer type |
| 582 RegistryEntry(const string16& key_path, const string16& name, | 585 RegistryEntry(const base::string16& key_path, const base::string16& name, |
| 583 DWORD value) | 586 DWORD value) |
| 584 : key_path_(key_path), name_(name), | 587 : key_path_(key_path), name_(name), |
| 585 is_string_(false), value_(), int_value_(value) { | 588 is_string_(false), value_(), int_value_(value) { |
| 586 } | 589 } |
| 587 | 590 |
| 588 string16 key_path_; // key path for the registry entry | 591 base::string16 key_path_; // key path for the registry entry |
| 589 string16 name_; // name of the registry entry | 592 base::string16 name_; // name of the registry entry |
| 590 bool is_string_; // true if current registry entry is of type REG_SZ | 593 bool is_string_; // true if current registry entry is of type REG_SZ |
| 591 string16 value_; // string value (useful if is_string_ = true) | 594 base::string16 value_; // string value (useful if is_string_ = true) |
| 592 DWORD int_value_; // integer value (useful if is_string_ = false) | 595 DWORD int_value_; // integer value (useful if is_string_ = false) |
| 593 | 596 |
| 594 // Helper function for ExistsInRegistry(). | 597 // Helper function for ExistsInRegistry(). |
| 595 // Returns the RegistryStatus of the current registry entry in | 598 // Returns the RegistryStatus of the current registry entry in |
| 596 // |root|\|key_path_|\|name_|. | 599 // |root|\|key_path_|\|name_|. |
| 597 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const { | 600 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const { |
| 598 RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); | 601 RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); |
| 599 bool found = false; | 602 bool found = false; |
| 600 bool correct_value = false; | 603 bool correct_value = false; |
| 601 if (is_string_) { | 604 if (is_string_) { |
| 602 string16 read_value; | 605 base::string16 read_value; |
| 603 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; | 606 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; |
| 604 correct_value = read_value.size() == value_.size() && | 607 correct_value = read_value.size() == value_.size() && |
| 605 std::equal(value_.begin(), value_.end(), read_value.begin(), | 608 std::equal(value_.begin(), value_.end(), read_value.begin(), |
| 606 base::CaseInsensitiveCompare<wchar_t>()); | 609 base::CaseInsensitiveCompare<wchar_t>()); |
| 607 } else { | 610 } else { |
| 608 DWORD read_value; | 611 DWORD read_value; |
| 609 found = key.ReadValueDW(name_.c_str(), &read_value) == ERROR_SUCCESS; | 612 found = key.ReadValueDW(name_.c_str(), &read_value) == ERROR_SUCCESS; |
| 610 correct_value = read_value == int_value_; | 613 correct_value = read_value == int_value_; |
| 611 } | 614 } |
| 612 return found ? | 615 return found ? |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // on this computer. See RegistryEntry::ExistsInRegistry for the behavior of | 656 // on this computer. See RegistryEntry::ExistsInRegistry for the behavior of |
| 654 // |look_for_in|. | 657 // |look_for_in|. |
| 655 // Note: between r133333 and r154145 we were registering parts of Chrome in HKCU | 658 // Note: between r133333 and r154145 we were registering parts of Chrome in HKCU |
| 656 // and parts in HKLM for user-level installs; we now always register everything | 659 // and parts in HKLM for user-level installs; we now always register everything |
| 657 // under a single registry root. Not doing so caused http://crbug.com/144910 for | 660 // under a single registry root. Not doing so caused http://crbug.com/144910 for |
| 658 // users who first-installed Chrome in that revision range (those users are | 661 // users who first-installed Chrome in that revision range (those users are |
| 659 // still impacted by http://crbug.com/144910). This method will keep returning | 662 // still impacted by http://crbug.com/144910). This method will keep returning |
| 660 // true for affected users (i.e. who have all the registrations, but over both | 663 // true for affected users (i.e. who have all the registrations, but over both |
| 661 // registry roots). | 664 // registry roots). |
| 662 bool IsChromeRegistered(BrowserDistribution* dist, | 665 bool IsChromeRegistered(BrowserDistribution* dist, |
| 663 const string16& chrome_exe, | 666 const base::string16& chrome_exe, |
| 664 const string16& suffix, | 667 const base::string16& suffix, |
| 665 uint32 look_for_in) { | 668 uint32 look_for_in) { |
| 666 ScopedVector<RegistryEntry> entries; | 669 ScopedVector<RegistryEntry> entries; |
| 667 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 670 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 668 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); | 671 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); |
| 669 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); | 672 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); |
| 670 return AreEntriesRegistered(entries, look_for_in); | 673 return AreEntriesRegistered(entries, look_for_in); |
| 671 } | 674 } |
| 672 | 675 |
| 673 // This method checks if Chrome is already registered on the local machine | 676 // This method checks if Chrome is already registered on the local machine |
| 674 // for the requested protocol. It just checks the one value required for this. | 677 // for the requested protocol. It just checks the one value required for this. |
| 675 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|. | 678 // See RegistryEntry::ExistsInRegistry for the behavior of |look_for_in|. |
| 676 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, | 679 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, |
| 677 const string16& suffix, | 680 const base::string16& suffix, |
| 678 const string16& protocol, | 681 const base::string16& protocol, |
| 679 uint32 look_for_in) { | 682 uint32 look_for_in) { |
| 680 ScopedVector<RegistryEntry> entries; | 683 ScopedVector<RegistryEntry> entries; |
| 681 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); | 684 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); |
| 682 return AreEntriesRegistered(entries, look_for_in); | 685 return AreEntriesRegistered(entries, look_for_in); |
| 683 } | 686 } |
| 684 | 687 |
| 685 // This method registers Chrome on Vista by launching an elevated setup.exe. | 688 // This method registers Chrome on Vista by launching an elevated setup.exe. |
| 686 // That will show the user the standard Vista elevation prompt. If the user | 689 // That will show the user the standard Vista elevation prompt. If the user |
| 687 // accepts it the new process will make the necessary changes and return SUCCESS | 690 // accepts it the new process will make the necessary changes and return SUCCESS |
| 688 // that we capture and return. | 691 // that we capture and return. |
| 689 // If protocol is non-empty we will also register Chrome as being capable of | 692 // If protocol is non-empty we will also register Chrome as being capable of |
| 690 // handling the protocol. | 693 // handling the protocol. |
| 691 bool ElevateAndRegisterChrome(BrowserDistribution* dist, | 694 bool ElevateAndRegisterChrome(BrowserDistribution* dist, |
| 692 const string16& chrome_exe, | 695 const base::string16& chrome_exe, |
| 693 const string16& suffix, | 696 const base::string16& suffix, |
| 694 const string16& protocol) { | 697 const base::string16& protocol) { |
| 695 // Only user-level installs prior to Windows 8 should need to elevate to | 698 // Only user-level installs prior to Windows 8 should need to elevate to |
| 696 // register. | 699 // register. |
| 697 DCHECK(InstallUtil::IsPerUserInstall(chrome_exe.c_str())); | 700 DCHECK(InstallUtil::IsPerUserInstall(chrome_exe.c_str())); |
| 698 DCHECK_LT(base::win::GetVersion(), base::win::VERSION_WIN8); | 701 DCHECK_LT(base::win::GetVersion(), base::win::VERSION_WIN8); |
| 699 base::FilePath exe_path = | 702 base::FilePath exe_path = |
| 700 base::FilePath(chrome_exe).DirName().Append(installer::kSetupExe); | 703 base::FilePath(chrome_exe).DirName().Append(installer::kSetupExe); |
| 701 if (!base::PathExists(exe_path)) { | 704 if (!base::PathExists(exe_path)) { |
| 702 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 705 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
| 703 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 706 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 704 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); | 707 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); |
| 705 string16 uninstall_string; | 708 base::string16 uninstall_string; |
| 706 key.ReadValue(installer::kUninstallStringField, &uninstall_string); | 709 key.ReadValue(installer::kUninstallStringField, &uninstall_string); |
| 707 CommandLine command_line = CommandLine::FromString(uninstall_string); | 710 CommandLine command_line = CommandLine::FromString(uninstall_string); |
| 708 exe_path = command_line.GetProgram(); | 711 exe_path = command_line.GetProgram(); |
| 709 } | 712 } |
| 710 | 713 |
| 711 if (base::PathExists(exe_path)) { | 714 if (base::PathExists(exe_path)) { |
| 712 CommandLine cmd(exe_path); | 715 CommandLine cmd(exe_path); |
| 713 cmd.AppendSwitchNative(installer::switches::kRegisterChromeBrowser, | 716 cmd.AppendSwitchNative(installer::switches::kRegisterChromeBrowser, |
| 714 chrome_exe); | 717 chrome_exe); |
| 715 if (!suffix.empty()) { | 718 if (!suffix.empty()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 << " handler; hr=0x" << std::hex << hr; | 754 << " handler; hr=0x" << std::hex << hr; |
| 752 if (FAILED(hr)) | 755 if (FAILED(hr)) |
| 753 return false; | 756 return false; |
| 754 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 757 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
| 755 return true; | 758 return true; |
| 756 } | 759 } |
| 757 | 760 |
| 758 // Launches the Windows 7 and Windows 8 application association dialog, which | 761 // Launches the Windows 7 and Windows 8 application association dialog, which |
| 759 // is the only documented way to make a browser the default browser on | 762 // is the only documented way to make a browser the default browser on |
| 760 // Windows 8. | 763 // Windows 8. |
| 761 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 764 bool LaunchApplicationAssociationDialog(const base::string16& app_id) { |
| 762 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 765 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; |
| 763 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 766 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); |
| 764 if (FAILED(hr)) | 767 if (FAILED(hr)) |
| 765 return false; | 768 return false; |
| 766 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 769 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); |
| 767 return SUCCEEDED(hr); | 770 return SUCCEEDED(hr); |
| 768 } | 771 } |
| 769 | 772 |
| 770 // Returns true if the current install's |chrome_exe| has been registered with | 773 // Returns true if the current install's |chrome_exe| has been registered with |
| 771 // |suffix|. | 774 // |suffix|. |
| 772 // |confirmation_level| is the level of verification desired as described in | 775 // |confirmation_level| is the level of verification desired as described in |
| 773 // the RegistrationConfirmationLevel enum above. | 776 // the RegistrationConfirmationLevel enum above. |
| 774 // |suffix| can be the empty string (this is used to support old installs | 777 // |suffix| can be the empty string (this is used to support old installs |
| 775 // where we used to not suffix user-level installs if they were the first to | 778 // where we used to not suffix user-level installs if they were the first to |
| 776 // request the non-suffixed registry entries on the machine). | 779 // request the non-suffixed registry entries on the machine). |
| 777 // NOTE: This a quick check that only validates that a single registry entry | 780 // NOTE: This a quick check that only validates that a single registry entry |
| 778 // points to |chrome_exe|. This should only be used at run-time to determine | 781 // points to |chrome_exe|. This should only be used at run-time to determine |
| 779 // how Chrome is registered, not to know whether the registration is complete | 782 // how Chrome is registered, not to know whether the registration is complete |
| 780 // at install-time (IsChromeRegistered() can be used for that). | 783 // at install-time (IsChromeRegistered() can be used for that). |
| 781 bool QuickIsChromeRegistered(BrowserDistribution* dist, | 784 bool QuickIsChromeRegistered(BrowserDistribution* dist, |
| 782 const string16& chrome_exe, | 785 const base::string16& chrome_exe, |
| 783 const string16& suffix, | 786 const base::string16& suffix, |
| 784 RegistrationConfirmationLevel confirmation_level) { | 787 RegistrationConfirmationLevel confirmation_level) { |
| 785 // Get the appropriate key to look for based on the level desired. | 788 // Get the appropriate key to look for based on the level desired. |
| 786 string16 reg_key; | 789 base::string16 reg_key; |
| 787 switch (confirmation_level) { | 790 switch (confirmation_level) { |
| 788 case CONFIRM_PROGID_REGISTRATION: | 791 case CONFIRM_PROGID_REGISTRATION: |
| 789 // Software\Classes\ChromeHTML|suffix| | 792 // Software\Classes\ChromeHTML|suffix| |
| 790 reg_key = ShellUtil::kRegClasses; | 793 reg_key = ShellUtil::kRegClasses; |
| 791 reg_key.push_back(base::FilePath::kSeparators[0]); | 794 reg_key.push_back(base::FilePath::kSeparators[0]); |
| 792 reg_key.append(dist->GetBrowserProgIdPrefix()); | 795 reg_key.append(dist->GetBrowserProgIdPrefix()); |
| 793 reg_key.append(suffix); | 796 reg_key.append(suffix); |
| 794 break; | 797 break; |
| 795 case CONFIRM_SHELL_REGISTRATION: | 798 case CONFIRM_SHELL_REGISTRATION: |
| 796 case CONFIRM_SHELL_REGISTRATION_IN_HKLM: | 799 case CONFIRM_SHELL_REGISTRATION_IN_HKLM: |
| 797 // Software\Clients\StartMenuInternet\Google Chrome|suffix| | 800 // Software\Clients\StartMenuInternet\Google Chrome|suffix| |
| 798 reg_key = RegistryEntry::GetBrowserClientKey(dist, suffix); | 801 reg_key = RegistryEntry::GetBrowserClientKey(dist, suffix); |
| 799 break; | 802 break; |
| 800 default: | 803 default: |
| 801 NOTREACHED(); | 804 NOTREACHED(); |
| 802 break; | 805 break; |
| 803 } | 806 } |
| 804 reg_key.append(ShellUtil::kRegShellOpen); | 807 reg_key.append(ShellUtil::kRegShellOpen); |
| 805 | 808 |
| 806 // ProgId registrations are allowed to reside in HKCU for user-level installs | 809 // ProgId registrations are allowed to reside in HKCU for user-level installs |
| 807 // (and values there have priority over values in HKLM). The same is true for | 810 // (and values there have priority over values in HKLM). The same is true for |
| 808 // shell integration entries as of Windows 8. | 811 // shell integration entries as of Windows 8. |
| 809 if (confirmation_level == CONFIRM_PROGID_REGISTRATION || | 812 if (confirmation_level == CONFIRM_PROGID_REGISTRATION || |
| 810 (confirmation_level == CONFIRM_SHELL_REGISTRATION && | 813 (confirmation_level == CONFIRM_SHELL_REGISTRATION && |
| 811 base::win::GetVersion() >= base::win::VERSION_WIN8)) { | 814 base::win::GetVersion() >= base::win::VERSION_WIN8)) { |
| 812 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE); | 815 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE); |
| 813 string16 hkcu_value; | 816 base::string16 hkcu_value; |
| 814 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|. | 817 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|. |
| 815 // Otherwise, fall back on an HKLM lookup below. | 818 // Otherwise, fall back on an HKLM lookup below. |
| 816 if (key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS) { | 819 if (key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS) { |
| 817 return InstallUtil::ProgramCompare( | 820 return InstallUtil::ProgramCompare( |
| 818 base::FilePath(chrome_exe)).Evaluate(hkcu_value); | 821 base::FilePath(chrome_exe)).Evaluate(hkcu_value); |
| 819 } | 822 } |
| 820 } | 823 } |
| 821 | 824 |
| 822 // Assert that |reg_key| points to |chrome_exe| in HKLM. | 825 // Assert that |reg_key| points to |chrome_exe| in HKLM. |
| 823 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); | 826 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); |
| 824 string16 hklm_value; | 827 base::string16 hklm_value; |
| 825 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { | 828 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { |
| 826 return InstallUtil::ProgramCompare( | 829 return InstallUtil::ProgramCompare( |
| 827 base::FilePath(chrome_exe)).Evaluate(hklm_value); | 830 base::FilePath(chrome_exe)).Evaluate(hklm_value); |
| 828 } | 831 } |
| 829 return false; | 832 return false; |
| 830 } | 833 } |
| 831 | 834 |
| 832 // Sets |suffix| to a 27 character string that is specific to this user on this | 835 // Sets |suffix| to a 27 character string that is specific to this user on this |
| 833 // machine (on user-level installs only). | 836 // machine (on user-level installs only). |
| 834 // To support old-style user-level installs however, |suffix| is cleared if the | 837 // To support old-style user-level installs however, |suffix| is cleared if the |
| 835 // user currently owns the non-suffixed HKLM registrations. | 838 // user currently owns the non-suffixed HKLM registrations. |
| 836 // |suffix| can also be set to the user's username if the current install is | 839 // |suffix| can also be set to the user's username if the current install is |
| 837 // suffixed as per the old-style registrations. | 840 // suffixed as per the old-style registrations. |
| 838 // |suffix| is cleared on system-level installs. | 841 // |suffix| is cleared on system-level installs. |
| 839 // |suffix| should then be appended to all Chrome properties that may conflict | 842 // |suffix| should then be appended to all Chrome properties that may conflict |
| 840 // with other Chrome user-level installs. | 843 // with other Chrome user-level installs. |
| 841 // Returns true unless one of the underlying calls fails. | 844 // Returns true unless one of the underlying calls fails. |
| 842 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, | 845 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, |
| 843 const string16& chrome_exe, | 846 const base::string16& chrome_exe, |
| 844 string16* suffix) { | 847 base::string16* suffix) { |
| 845 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || | 848 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 846 QuickIsChromeRegistered(dist, chrome_exe, string16(), | 849 QuickIsChromeRegistered(dist, chrome_exe, base::string16(), |
| 847 CONFIRM_SHELL_REGISTRATION)) { | 850 CONFIRM_SHELL_REGISTRATION)) { |
| 848 // No suffix on system-level installs and user-level installs already | 851 // No suffix on system-level installs and user-level installs already |
| 849 // registered with no suffix. | 852 // registered with no suffix. |
| 850 suffix->clear(); | 853 suffix->clear(); |
| 851 return true; | 854 return true; |
| 852 } | 855 } |
| 853 | 856 |
| 854 // Get the old suffix for the check below. | 857 // Get the old suffix for the check below. |
| 855 if (!ShellUtil::GetOldUserSpecificRegistrySuffix(suffix)) { | 858 if (!ShellUtil::GetOldUserSpecificRegistrySuffix(suffix)) { |
| 856 NOTREACHED(); | 859 NOTREACHED(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 871 HKEY DetermineRegistrationRoot(bool is_per_user) { | 874 HKEY DetermineRegistrationRoot(bool is_per_user) { |
| 872 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? | 875 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? |
| 873 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 876 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 874 } | 877 } |
| 875 | 878 |
| 876 // Associates Chrome with supported protocols and file associations. This should | 879 // Associates Chrome with supported protocols and file associations. This should |
| 877 // not be required on Vista+ but since some applications still read | 880 // not be required on Vista+ but since some applications still read |
| 878 // Software\Classes\http key directly, we have to do this on Vista+ as well. | 881 // Software\Classes\http key directly, we have to do this on Vista+ as well. |
| 879 bool RegisterChromeAsDefaultXPStyle(BrowserDistribution* dist, | 882 bool RegisterChromeAsDefaultXPStyle(BrowserDistribution* dist, |
| 880 int shell_change, | 883 int shell_change, |
| 881 const string16& chrome_exe) { | 884 const base::string16& chrome_exe) { |
| 882 bool ret = true; | 885 bool ret = true; |
| 883 ScopedVector<RegistryEntry> entries; | 886 ScopedVector<RegistryEntry> entries; |
| 884 RegistryEntry::GetXPStyleDefaultBrowserUserEntries( | 887 RegistryEntry::GetXPStyleDefaultBrowserUserEntries( |
| 885 dist, chrome_exe, | 888 dist, chrome_exe, |
| 886 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe), &entries); | 889 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe), &entries); |
| 887 | 890 |
| 888 // Change the default browser for current user. | 891 // Change the default browser for current user. |
| 889 if ((shell_change & ShellUtil::CURRENT_USER) && | 892 if ((shell_change & ShellUtil::CURRENT_USER) && |
| 890 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 893 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 891 ret = false; | 894 ret = false; |
| 892 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | 895 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; |
| 893 } | 896 } |
| 894 | 897 |
| 895 // Chrome as default browser at system level. | 898 // Chrome as default browser at system level. |
| 896 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | 899 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && |
| 897 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | 900 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { |
| 898 ret = false; | 901 ret = false; |
| 899 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | 902 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; |
| 900 } | 903 } |
| 901 | 904 |
| 902 return ret; | 905 return ret; |
| 903 } | 906 } |
| 904 | 907 |
| 905 // Associates Chrome with |protocol| in the registry. This should not be | 908 // Associates Chrome with |protocol| in the registry. This should not be |
| 906 // required on Vista+ but since some applications still read these registry | 909 // required on Vista+ but since some applications still read these registry |
| 907 // keys directly, we have to do this on Vista+ as well. | 910 // keys directly, we have to do this on Vista+ as well. |
| 908 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. | 911 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. |
| 909 bool RegisterChromeAsDefaultProtocolClientXPStyle(BrowserDistribution* dist, | 912 bool RegisterChromeAsDefaultProtocolClientXPStyle( |
| 910 const string16& chrome_exe, | 913 BrowserDistribution* dist, |
| 911 const string16& protocol) { | 914 const base::string16& chrome_exe, |
| 915 const base::string16& protocol) { |
| 912 ScopedVector<RegistryEntry> entries; | 916 ScopedVector<RegistryEntry> entries; |
| 913 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 917 const base::string16 chrome_open( |
| 914 const string16 chrome_icon( | 918 ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
| 919 const base::string16 chrome_icon( |
| 915 ShellUtil::FormatIconLocation( | 920 ShellUtil::FormatIconLocation( |
| 916 chrome_exe, | 921 chrome_exe, |
| 917 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); | 922 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
| 918 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, | 923 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, |
| 919 chrome_open, &entries); | 924 chrome_open, &entries); |
| 920 // Change the default protocol handler for current user. | 925 // Change the default protocol handler for current user. |
| 921 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 926 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 922 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 927 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
| 923 return false; | 928 return false; |
| 924 } | 929 } |
| 925 | 930 |
| 926 return true; | 931 return true; |
| 927 } | 932 } |
| 928 | 933 |
| 929 // Returns |properties.shortcut_name| if the property is set, otherwise it | 934 // Returns |properties.shortcut_name| if the property is set, otherwise it |
| 930 // returns dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME). In any | 935 // returns dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME). In any |
| 931 // case, it makes sure the return value is suffixed with ".lnk". | 936 // case, it makes sure the return value is suffixed with ".lnk". |
| 932 string16 ExtractShortcutNameFromProperties( | 937 base::string16 ExtractShortcutNameFromProperties( |
| 933 BrowserDistribution* dist, | 938 BrowserDistribution* dist, |
| 934 const ShellUtil::ShortcutProperties& properties) { | 939 const ShellUtil::ShortcutProperties& properties) { |
| 935 DCHECK(dist); | 940 DCHECK(dist); |
| 936 string16 shortcut_name; | 941 base::string16 shortcut_name; |
| 937 if (properties.has_shortcut_name()) { | 942 if (properties.has_shortcut_name()) { |
| 938 shortcut_name = properties.shortcut_name; | 943 shortcut_name = properties.shortcut_name; |
| 939 } else { | 944 } else { |
| 940 shortcut_name = | 945 shortcut_name = |
| 941 dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); | 946 dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); |
| 942 } | 947 } |
| 943 | 948 |
| 944 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) | 949 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) |
| 945 shortcut_name.append(installer::kLnkExt); | 950 shortcut_name.append(installer::kLnkExt); |
| 946 | 951 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 shortcut_properties.set_app_id(properties.app_id); | 998 shortcut_properties.set_app_id(properties.app_id); |
| 994 | 999 |
| 995 if (properties.has_dual_mode()) | 1000 if (properties.has_dual_mode()) |
| 996 shortcut_properties.set_dual_mode(properties.dual_mode); | 1001 shortcut_properties.set_dual_mode(properties.dual_mode); |
| 997 | 1002 |
| 998 return shortcut_properties; | 1003 return shortcut_properties; |
| 999 } | 1004 } |
| 1000 | 1005 |
| 1001 // Cleans up an old verb (run) we used to register in | 1006 // Cleans up an old verb (run) we used to register in |
| 1002 // <root>\Software\Classes\Chrome<.suffix>\.exe\shell\run on Windows 8. | 1007 // <root>\Software\Classes\Chrome<.suffix>\.exe\shell\run on Windows 8. |
| 1003 void RemoveRunVerbOnWindows8( | 1008 void RemoveRunVerbOnWindows8(BrowserDistribution* dist, |
| 1004 BrowserDistribution* dist, | 1009 const base::string16& chrome_exe) { |
| 1005 const string16& chrome_exe) { | |
| 1006 if (IsChromeMetroSupported()) { | 1010 if (IsChromeMetroSupported()) { |
| 1007 bool is_per_user_install =InstallUtil::IsPerUserInstall(chrome_exe.c_str()); | 1011 bool is_per_user_install =InstallUtil::IsPerUserInstall(chrome_exe.c_str()); |
| 1008 HKEY root_key = DetermineRegistrationRoot(is_per_user_install); | 1012 HKEY root_key = DetermineRegistrationRoot(is_per_user_install); |
| 1009 // There's no need to rollback, so forgo the usual work item lists and just | 1013 // There's no need to rollback, so forgo the usual work item lists and just |
| 1010 // remove the key from the registry. | 1014 // remove the key from the registry. |
| 1011 string16 run_verb_key(ShellUtil::kRegClasses); | 1015 base::string16 run_verb_key(ShellUtil::kRegClasses); |
| 1012 run_verb_key.push_back(base::FilePath::kSeparators[0]); | 1016 run_verb_key.push_back(base::FilePath::kSeparators[0]); |
| 1013 run_verb_key.append(ShellUtil::GetBrowserModelId( | 1017 run_verb_key.append(ShellUtil::GetBrowserModelId( |
| 1014 dist, is_per_user_install)); | 1018 dist, is_per_user_install)); |
| 1015 run_verb_key.append(ShellUtil::kRegExePath); | 1019 run_verb_key.append(ShellUtil::kRegExePath); |
| 1016 run_verb_key.append(ShellUtil::kRegShellPath); | 1020 run_verb_key.append(ShellUtil::kRegShellPath); |
| 1017 run_verb_key.push_back(base::FilePath::kSeparators[0]); | 1021 run_verb_key.push_back(base::FilePath::kSeparators[0]); |
| 1018 run_verb_key.append(ShellUtil::kRegVerbRun); | 1022 run_verb_key.append(ShellUtil::kRegVerbRun); |
| 1019 InstallUtil::DeleteRegistryKey(root_key, run_verb_key); | 1023 InstallUtil::DeleteRegistryKey(root_key, run_verb_key); |
| 1020 } | 1024 } |
| 1021 } | 1025 } |
| 1022 | 1026 |
| 1023 // Gets the short (8.3) form of |path|, putting the result in |short_path| and | 1027 // Gets the short (8.3) form of |path|, putting the result in |short_path| and |
| 1024 // returning true on success. |short_path| is not modified on failure. | 1028 // returning true on success. |short_path| is not modified on failure. |
| 1025 bool ShortNameFromPath(const base::FilePath& path, string16* short_path) { | 1029 bool ShortNameFromPath(const base::FilePath& path, base::string16* short_path) { |
| 1026 DCHECK(short_path); | 1030 DCHECK(short_path); |
| 1027 string16 result(MAX_PATH, L'\0'); | 1031 base::string16 result(MAX_PATH, L'\0'); |
| 1028 DWORD short_length = GetShortPathName(path.value().c_str(), &result[0], | 1032 DWORD short_length = GetShortPathName(path.value().c_str(), &result[0], |
| 1029 result.size()); | 1033 result.size()); |
| 1030 if (short_length == 0 || short_length > result.size()) { | 1034 if (short_length == 0 || short_length > result.size()) { |
| 1031 PLOG(ERROR) << "Error getting short (8.3) path"; | 1035 PLOG(ERROR) << "Error getting short (8.3) path"; |
| 1032 return false; | 1036 return false; |
| 1033 } | 1037 } |
| 1034 | 1038 |
| 1035 result.resize(short_length); | 1039 result.resize(short_length); |
| 1036 short_path->swap(result); | 1040 short_path->swap(result); |
| 1037 return true; | 1041 return true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1051 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); | 1055 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); |
| 1052 if (FAILED(hr)) | 1056 if (FAILED(hr)) |
| 1053 return ShellUtil::UNKNOWN_DEFAULT; | 1057 return ShellUtil::UNKNOWN_DEFAULT; |
| 1054 | 1058 |
| 1055 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 1059 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 1056 base::FilePath chrome_exe; | 1060 base::FilePath chrome_exe; |
| 1057 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 1061 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 1058 NOTREACHED(); | 1062 NOTREACHED(); |
| 1059 return ShellUtil::UNKNOWN_DEFAULT; | 1063 return ShellUtil::UNKNOWN_DEFAULT; |
| 1060 } | 1064 } |
| 1061 string16 prog_id(dist->GetBrowserProgIdPrefix()); | 1065 base::string16 prog_id(dist->GetBrowserProgIdPrefix()); |
| 1062 prog_id += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe.value()); | 1066 prog_id += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe.value()); |
| 1063 | 1067 |
| 1064 for (size_t i = 0; i < num_protocols; ++i) { | 1068 for (size_t i = 0; i < num_protocols; ++i) { |
| 1065 base::win::ScopedCoMem<wchar_t> current_app; | 1069 base::win::ScopedCoMem<wchar_t> current_app; |
| 1066 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, | 1070 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, |
| 1067 AL_EFFECTIVE, ¤t_app); | 1071 AL_EFFECTIVE, ¤t_app); |
| 1068 if (FAILED(hr) || prog_id.compare(current_app) != 0) | 1072 if (FAILED(hr) || prog_id.compare(current_app) != 0) |
| 1069 return ShellUtil::NOT_DEFAULT; | 1073 return ShellUtil::NOT_DEFAULT; |
| 1070 } | 1074 } |
| 1071 | 1075 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1082 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); | 1086 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); |
| 1083 if (FAILED(hr)) | 1087 if (FAILED(hr)) |
| 1084 return ShellUtil::UNKNOWN_DEFAULT; | 1088 return ShellUtil::UNKNOWN_DEFAULT; |
| 1085 | 1089 |
| 1086 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 1090 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 1087 base::FilePath chrome_exe; | 1091 base::FilePath chrome_exe; |
| 1088 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 1092 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 1089 NOTREACHED(); | 1093 NOTREACHED(); |
| 1090 return ShellUtil::UNKNOWN_DEFAULT; | 1094 return ShellUtil::UNKNOWN_DEFAULT; |
| 1091 } | 1095 } |
| 1092 string16 app_name(ShellUtil::GetApplicationName(dist, chrome_exe.value())); | 1096 base::string16 app_name( |
| 1097 ShellUtil::GetApplicationName(dist, chrome_exe.value())); |
| 1093 | 1098 |
| 1094 BOOL result; | 1099 BOOL result; |
| 1095 for (size_t i = 0; i < num_protocols; ++i) { | 1100 for (size_t i = 0; i < num_protocols; ++i) { |
| 1096 result = TRUE; | 1101 result = TRUE; |
| 1097 hr = registration->QueryAppIsDefault(protocols[i], AT_URLPROTOCOL, | 1102 hr = registration->QueryAppIsDefault(protocols[i], AT_URLPROTOCOL, |
| 1098 AL_EFFECTIVE, app_name.c_str(), &result); | 1103 AL_EFFECTIVE, app_name.c_str(), &result); |
| 1099 if (FAILED(hr) || result == FALSE) | 1104 if (FAILED(hr) || result == FALSE) |
| 1100 return ShellUtil::NOT_DEFAULT; | 1105 return ShellUtil::NOT_DEFAULT; |
| 1101 } | 1106 } |
| 1102 | 1107 |
| 1103 return ShellUtil::IS_DEFAULT; | 1108 return ShellUtil::IS_DEFAULT; |
| 1104 } | 1109 } |
| 1105 | 1110 |
| 1106 // Probe the current commands registered to handle the shell "open" verb for | 1111 // Probe the current commands registered to handle the shell "open" verb for |
| 1107 // |protocols| (Windows XP); see ProbeProtocolHandlers. | 1112 // |protocols| (Windows XP); see ProbeProtocolHandlers. |
| 1108 ShellUtil::DefaultState ProbeOpenCommandHandlers( | 1113 ShellUtil::DefaultState ProbeOpenCommandHandlers( |
| 1109 const wchar_t* const* protocols, | 1114 const wchar_t* const* protocols, |
| 1110 size_t num_protocols) { | 1115 size_t num_protocols) { |
| 1111 // Get the path to the current exe (Chrome). | 1116 // Get the path to the current exe (Chrome). |
| 1112 base::FilePath app_path; | 1117 base::FilePath app_path; |
| 1113 if (!PathService::Get(base::FILE_EXE, &app_path)) { | 1118 if (!PathService::Get(base::FILE_EXE, &app_path)) { |
| 1114 LOG(ERROR) << "Error getting app exe path"; | 1119 LOG(ERROR) << "Error getting app exe path"; |
| 1115 return ShellUtil::UNKNOWN_DEFAULT; | 1120 return ShellUtil::UNKNOWN_DEFAULT; |
| 1116 } | 1121 } |
| 1117 | 1122 |
| 1118 // Get its short (8.3) form. | 1123 // Get its short (8.3) form. |
| 1119 string16 short_app_path; | 1124 base::string16 short_app_path; |
| 1120 if (!ShortNameFromPath(app_path, &short_app_path)) | 1125 if (!ShortNameFromPath(app_path, &short_app_path)) |
| 1121 return ShellUtil::UNKNOWN_DEFAULT; | 1126 return ShellUtil::UNKNOWN_DEFAULT; |
| 1122 | 1127 |
| 1123 const HKEY root_key = HKEY_CLASSES_ROOT; | 1128 const HKEY root_key = HKEY_CLASSES_ROOT; |
| 1124 string16 key_path; | 1129 base::string16 key_path; |
| 1125 base::win::RegKey key; | 1130 base::win::RegKey key; |
| 1126 string16 value; | 1131 base::string16 value; |
| 1127 CommandLine command_line(CommandLine::NO_PROGRAM); | 1132 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 1128 string16 short_path; | 1133 base::string16 short_path; |
| 1129 | 1134 |
| 1130 for (size_t i = 0; i < num_protocols; ++i) { | 1135 for (size_t i = 0; i < num_protocols; ++i) { |
| 1131 // Get the command line from HKCU\<protocol>\shell\open\command. | 1136 // Get the command line from HKCU\<protocol>\shell\open\command. |
| 1132 key_path.assign(protocols[i]).append(ShellUtil::kRegShellOpen); | 1137 key_path.assign(protocols[i]).append(ShellUtil::kRegShellOpen); |
| 1133 if ((key.Open(root_key, key_path.c_str(), | 1138 if ((key.Open(root_key, key_path.c_str(), |
| 1134 KEY_QUERY_VALUE) != ERROR_SUCCESS) || | 1139 KEY_QUERY_VALUE) != ERROR_SUCCESS) || |
| 1135 (key.ReadValue(L"", &value) != ERROR_SUCCESS)) { | 1140 (key.ReadValue(L"", &value) != ERROR_SUCCESS)) { |
| 1136 return ShellUtil::NOT_DEFAULT; | 1141 return ShellUtil::NOT_DEFAULT; |
| 1137 } | 1142 } |
| 1138 | 1143 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 return false; | 1197 return false; |
| 1193 } | 1198 } |
| 1194 | 1199 |
| 1195 *path = folder; | 1200 *path = folder; |
| 1196 return true; | 1201 return true; |
| 1197 } | 1202 } |
| 1198 | 1203 |
| 1199 // Shortcut filters for BatchShortcutAction(). | 1204 // Shortcut filters for BatchShortcutAction(). |
| 1200 | 1205 |
| 1201 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/, | 1206 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/, |
| 1202 const string16& /*args*/)> | 1207 const base::string16& /*args*/)> |
| 1203 ShortcutFilterCallback; | 1208 ShortcutFilterCallback; |
| 1204 | 1209 |
| 1205 // FilterTargetEq is a shortcut filter that matches only shortcuts that have a | 1210 // FilterTargetEq is a shortcut filter that matches only shortcuts that have a |
| 1206 // specific target, and optionally matches shortcuts that have non-empty | 1211 // specific target, and optionally matches shortcuts that have non-empty |
| 1207 // arguments. | 1212 // arguments. |
| 1208 class FilterTargetEq { | 1213 class FilterTargetEq { |
| 1209 public: | 1214 public: |
| 1210 FilterTargetEq(const base::FilePath& desired_target_exe, bool require_args); | 1215 FilterTargetEq(const base::FilePath& desired_target_exe, bool require_args); |
| 1211 | 1216 |
| 1212 // Returns true if filter rules are satisfied, i.e.: | 1217 // Returns true if filter rules are satisfied, i.e.: |
| 1213 // - |target_path|'s target == |desired_target_compare_|, and | 1218 // - |target_path|'s target == |desired_target_compare_|, and |
| 1214 // - |args| is non-empty (if |require_args_| == true). | 1219 // - |args| is non-empty (if |require_args_| == true). |
| 1215 bool Match(const base::FilePath& target_path, const string16& args) const; | 1220 bool Match(const base::FilePath& target_path, |
| 1221 const base::string16& args) const; |
| 1216 | 1222 |
| 1217 // A convenience routine to create a callback to call Match(). | 1223 // A convenience routine to create a callback to call Match(). |
| 1218 // The callback is only valid during the lifetime of the FilterTargetEq | 1224 // The callback is only valid during the lifetime of the FilterTargetEq |
| 1219 // instance. | 1225 // instance. |
| 1220 ShortcutFilterCallback AsShortcutFilterCallback(); | 1226 ShortcutFilterCallback AsShortcutFilterCallback(); |
| 1221 | 1227 |
| 1222 private: | 1228 private: |
| 1223 InstallUtil::ProgramCompare desired_target_compare_; | 1229 InstallUtil::ProgramCompare desired_target_compare_; |
| 1224 | 1230 |
| 1225 bool require_args_; | 1231 bool require_args_; |
| 1226 }; | 1232 }; |
| 1227 | 1233 |
| 1228 FilterTargetEq::FilterTargetEq(const base::FilePath& desired_target_exe, | 1234 FilterTargetEq::FilterTargetEq(const base::FilePath& desired_target_exe, |
| 1229 bool require_args) | 1235 bool require_args) |
| 1230 : desired_target_compare_(desired_target_exe), | 1236 : desired_target_compare_(desired_target_exe), |
| 1231 require_args_(require_args) {} | 1237 require_args_(require_args) {} |
| 1232 | 1238 |
| 1233 bool FilterTargetEq::Match(const base::FilePath& target_path, | 1239 bool FilterTargetEq::Match(const base::FilePath& target_path, |
| 1234 const string16& args) const { | 1240 const base::string16& args) const { |
| 1235 if (!desired_target_compare_.EvaluatePath(target_path)) | 1241 if (!desired_target_compare_.EvaluatePath(target_path)) |
| 1236 return false; | 1242 return false; |
| 1237 if (require_args_ && args.empty()) | 1243 if (require_args_ && args.empty()) |
| 1238 return false; | 1244 return false; |
| 1239 return true; | 1245 return true; |
| 1240 } | 1246 } |
| 1241 | 1247 |
| 1242 ShortcutFilterCallback FilterTargetEq::AsShortcutFilterCallback() { | 1248 ShortcutFilterCallback FilterTargetEq::AsShortcutFilterCallback() { |
| 1243 return base::Bind(&FilterTargetEq::Match, base::Unretained(this)); | 1249 return base::Bind(&FilterTargetEq::Match, base::Unretained(this)); |
| 1244 } | 1250 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 DCHECK(!shortcut_operation.is_null()); | 1289 DCHECK(!shortcut_operation.is_null()); |
| 1284 base::FilePath shortcut_folder; | 1290 base::FilePath shortcut_folder; |
| 1285 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1291 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
| 1286 LOG(WARNING) << "Cannot find path at location " << location; | 1292 LOG(WARNING) << "Cannot find path at location " << location; |
| 1287 return false; | 1293 return false; |
| 1288 } | 1294 } |
| 1289 | 1295 |
| 1290 bool success = true; | 1296 bool success = true; |
| 1291 base::FileEnumerator enumerator( | 1297 base::FileEnumerator enumerator( |
| 1292 shortcut_folder, false, base::FileEnumerator::FILES, | 1298 shortcut_folder, false, base::FileEnumerator::FILES, |
| 1293 string16(L"*") + installer::kLnkExt); | 1299 base::string16(L"*") + installer::kLnkExt); |
| 1294 base::FilePath target_path; | 1300 base::FilePath target_path; |
| 1295 string16 args; | 1301 base::string16 args; |
| 1296 for (base::FilePath shortcut_path = enumerator.Next(); | 1302 for (base::FilePath shortcut_path = enumerator.Next(); |
| 1297 !shortcut_path.empty(); | 1303 !shortcut_path.empty(); |
| 1298 shortcut_path = enumerator.Next()) { | 1304 shortcut_path = enumerator.Next()) { |
| 1299 if (base::win::ResolveShortcut(shortcut_path, &target_path, &args)) { | 1305 if (base::win::ResolveShortcut(shortcut_path, &target_path, &args)) { |
| 1300 if (shortcut_filter.Run(target_path, args) && | 1306 if (shortcut_filter.Run(target_path, args) && |
| 1301 !shortcut_operation.Run(shortcut_path)) { | 1307 !shortcut_operation.Run(shortcut_path)) { |
| 1302 success = false; | 1308 success = false; |
| 1303 } | 1309 } |
| 1304 } else { | 1310 } else { |
| 1305 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); | 1311 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; | 1379 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; |
| 1374 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; | 1380 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; |
| 1375 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; | 1381 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; |
| 1376 const wchar_t* ShellUtil::kRegVerbOpenNewWindow = L"opennewwindow"; | 1382 const wchar_t* ShellUtil::kRegVerbOpenNewWindow = L"opennewwindow"; |
| 1377 const wchar_t* ShellUtil::kRegVerbRun = L"run"; | 1383 const wchar_t* ShellUtil::kRegVerbRun = L"run"; |
| 1378 const wchar_t* ShellUtil::kRegCommand = L"command"; | 1384 const wchar_t* ShellUtil::kRegCommand = L"command"; |
| 1379 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 1385 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
| 1380 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; | 1386 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; |
| 1381 | 1387 |
| 1382 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 1388 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
| 1383 const string16& chrome_exe, | 1389 const base::string16& chrome_exe, |
| 1384 const string16& suffix) { | 1390 const base::string16& suffix) { |
| 1385 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1391 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 1386 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1392 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
| 1387 } | 1393 } |
| 1388 | 1394 |
| 1389 bool ShellUtil::ShortcutLocationIsSupported( | 1395 bool ShellUtil::ShortcutLocationIsSupported( |
| 1390 ShellUtil::ShortcutLocation location) { | 1396 ShellUtil::ShortcutLocation location) { |
| 1391 switch (location) { | 1397 switch (location) { |
| 1392 case SHORTCUT_LOCATION_DESKTOP: // Falls through. | 1398 case SHORTCUT_LOCATION_DESKTOP: // Falls through. |
| 1393 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. | 1399 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. |
| 1394 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. | 1400 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1487 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
| 1482 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1488 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
| 1483 | 1489 |
| 1484 base::FilePath user_shortcut_path; | 1490 base::FilePath user_shortcut_path; |
| 1485 base::FilePath system_shortcut_path; | 1491 base::FilePath system_shortcut_path; |
| 1486 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path)) { | 1492 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path)) { |
| 1487 NOTREACHED(); | 1493 NOTREACHED(); |
| 1488 return false; | 1494 return false; |
| 1489 } | 1495 } |
| 1490 | 1496 |
| 1491 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); | 1497 base::string16 shortcut_name( |
| 1498 ExtractShortcutNameFromProperties(dist, properties)); |
| 1492 system_shortcut_path = system_shortcut_path.Append(shortcut_name); | 1499 system_shortcut_path = system_shortcut_path.Append(shortcut_name); |
| 1493 | 1500 |
| 1494 base::FilePath* chosen_path; | 1501 base::FilePath* chosen_path; |
| 1495 bool should_install_shortcut = true; | 1502 bool should_install_shortcut = true; |
| 1496 if (properties.level == SYSTEM_LEVEL) { | 1503 if (properties.level == SYSTEM_LEVEL) { |
| 1497 // Install the system-level shortcut if requested. | 1504 // Install the system-level shortcut if requested. |
| 1498 chosen_path = &system_shortcut_path; | 1505 chosen_path = &system_shortcut_path; |
| 1499 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || | 1506 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || |
| 1500 !base::PathExists(system_shortcut_path)) { | 1507 !base::PathExists(system_shortcut_path)) { |
| 1501 // Otherwise install the user-level shortcut, unless the system-level | 1508 // Otherwise install the user-level shortcut, unless the system-level |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 base::win::GetVersion() >= base::win::VERSION_WIN7) { | 1550 base::win::GetVersion() >= base::win::VERSION_WIN7) { |
| 1544 ret = base::win::TaskbarPinShortcutLink(chosen_path->value().c_str()); | 1551 ret = base::win::TaskbarPinShortcutLink(chosen_path->value().c_str()); |
| 1545 if (!ret) { | 1552 if (!ret) { |
| 1546 LOG(ERROR) << "Failed to pin " << chosen_path->value(); | 1553 LOG(ERROR) << "Failed to pin " << chosen_path->value(); |
| 1547 } | 1554 } |
| 1548 } | 1555 } |
| 1549 | 1556 |
| 1550 return ret; | 1557 return ret; |
| 1551 } | 1558 } |
| 1552 | 1559 |
| 1553 string16 ShellUtil::FormatIconLocation(const string16& icon_path, | 1560 base::string16 ShellUtil::FormatIconLocation(const base::string16& icon_path, |
| 1554 int icon_index) { | 1561 int icon_index) { |
| 1555 string16 icon_string(icon_path); | 1562 base::string16 icon_string(icon_path); |
| 1556 icon_string.append(L","); | 1563 icon_string.append(L","); |
| 1557 icon_string.append(base::IntToString16(icon_index)); | 1564 icon_string.append(base::IntToString16(icon_index)); |
| 1558 return icon_string; | 1565 return icon_string; |
| 1559 } | 1566 } |
| 1560 | 1567 |
| 1561 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { | 1568 base::string16 ShellUtil::GetChromeShellOpenCmd( |
| 1569 const base::string16& chrome_exe) { |
| 1562 return L"\"" + chrome_exe + L"\" -- \"%1\""; | 1570 return L"\"" + chrome_exe + L"\" -- \"%1\""; |
| 1563 } | 1571 } |
| 1564 | 1572 |
| 1565 string16 ShellUtil::GetChromeDelegateCommand(const string16& chrome_exe) { | 1573 base::string16 ShellUtil::GetChromeDelegateCommand( |
| 1574 const base::string16& chrome_exe) { |
| 1566 return L"\"" + chrome_exe + L"\" -- %*"; | 1575 return L"\"" + chrome_exe + L"\" -- %*"; |
| 1567 } | 1576 } |
| 1568 | 1577 |
| 1569 void ShellUtil::GetRegisteredBrowsers( | 1578 void ShellUtil::GetRegisteredBrowsers( |
| 1570 BrowserDistribution* dist, | 1579 BrowserDistribution* dist, |
| 1571 std::map<string16, string16>* browsers) { | 1580 std::map<base::string16, base::string16>* browsers) { |
| 1572 DCHECK(dist); | 1581 DCHECK(dist); |
| 1573 DCHECK(browsers); | 1582 DCHECK(browsers); |
| 1574 | 1583 |
| 1575 const string16 base_key(ShellUtil::kRegStartMenuInternet); | 1584 const base::string16 base_key(ShellUtil::kRegStartMenuInternet); |
| 1576 string16 client_path; | 1585 base::string16 client_path; |
| 1577 RegKey key; | 1586 RegKey key; |
| 1578 string16 name; | 1587 base::string16 name; |
| 1579 string16 command; | 1588 base::string16 command; |
| 1580 | 1589 |
| 1581 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ. | 1590 // HKCU has precedence over HKLM for these registrations: http://goo.gl/xjczJ. |
| 1582 // Look in HKCU second to override any identical values found in HKLM. | 1591 // Look in HKCU second to override any identical values found in HKLM. |
| 1583 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; | 1592 const HKEY roots[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; |
| 1584 for (int i = 0; i < arraysize(roots); ++i) { | 1593 for (int i = 0; i < arraysize(roots); ++i) { |
| 1585 const HKEY root = roots[i]; | 1594 const HKEY root = roots[i]; |
| 1586 for (base::win::RegistryKeyIterator iter(root, base_key.c_str()); | 1595 for (base::win::RegistryKeyIterator iter(root, base_key.c_str()); |
| 1587 iter.Valid(); ++iter) { | 1596 iter.Valid(); ++iter) { |
| 1588 client_path.assign(base_key).append(1, L'\\').append(iter.Name()); | 1597 client_path.assign(base_key).append(1, L'\\').append(iter.Name()); |
| 1589 // Read the browser's name (localized according to install language). | 1598 // Read the browser's name (localized according to install language). |
| 1590 if (key.Open(root, client_path.c_str(), | 1599 if (key.Open(root, client_path.c_str(), |
| 1591 KEY_QUERY_VALUE) != ERROR_SUCCESS || | 1600 KEY_QUERY_VALUE) != ERROR_SUCCESS || |
| 1592 key.ReadValue(NULL, &name) != ERROR_SUCCESS || | 1601 key.ReadValue(NULL, &name) != ERROR_SUCCESS || |
| 1593 name.empty() || | 1602 name.empty() || |
| 1594 name.find(dist->GetBaseAppName()) != string16::npos) { | 1603 name.find(dist->GetBaseAppName()) != base::string16::npos) { |
| 1595 continue; | 1604 continue; |
| 1596 } | 1605 } |
| 1597 // Read the browser's reinstall command. | 1606 // Read the browser's reinstall command. |
| 1598 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(), | 1607 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(), |
| 1599 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 1608 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 1600 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS && | 1609 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS && |
| 1601 !command.empty()) { | 1610 !command.empty()) { |
| 1602 (*browsers)[name] = command; | 1611 (*browsers)[name] = command; |
| 1603 } | 1612 } |
| 1604 } | 1613 } |
| 1605 } | 1614 } |
| 1606 } | 1615 } |
| 1607 | 1616 |
| 1608 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, | 1617 base::string16 ShellUtil::GetCurrentInstallationSuffix( |
| 1609 const string16& chrome_exe) { | 1618 BrowserDistribution* dist, |
| 1619 const base::string16& chrome_exe) { |
| 1610 // This method is somewhat the opposite of GetInstallationSpecificSuffix(). | 1620 // This method is somewhat the opposite of GetInstallationSpecificSuffix(). |
| 1611 // In this case we are not trying to determine the current suffix for the | 1621 // In this case we are not trying to determine the current suffix for the |
| 1612 // upcoming installation (i.e. not trying to stick to a currently bad | 1622 // upcoming installation (i.e. not trying to stick to a currently bad |
| 1613 // registration style if one is present). | 1623 // registration style if one is present). |
| 1614 // Here we want to determine which suffix we should use at run-time. | 1624 // Here we want to determine which suffix we should use at run-time. |
| 1615 // In order of preference, we prefer (for user-level installs): | 1625 // In order of preference, we prefer (for user-level installs): |
| 1616 // 1) Base 32 encoding of the md5 hash of the user's sid (new-style). | 1626 // 1) Base 32 encoding of the md5 hash of the user's sid (new-style). |
| 1617 // 2) Username (old-style). | 1627 // 2) Username (old-style). |
| 1618 // 3) Unsuffixed (even worse). | 1628 // 3) Unsuffixed (even worse). |
| 1619 string16 tested_suffix; | 1629 base::string16 tested_suffix; |
| 1620 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1630 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && |
| 1621 (!GetUserSpecificRegistrySuffix(&tested_suffix) || | 1631 (!GetUserSpecificRegistrySuffix(&tested_suffix) || |
| 1622 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, | 1632 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 1623 CONFIRM_PROGID_REGISTRATION)) && | 1633 CONFIRM_PROGID_REGISTRATION)) && |
| 1624 (!GetOldUserSpecificRegistrySuffix(&tested_suffix) || | 1634 (!GetOldUserSpecificRegistrySuffix(&tested_suffix) || |
| 1625 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, | 1635 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 1626 CONFIRM_PROGID_REGISTRATION)) && | 1636 CONFIRM_PROGID_REGISTRATION)) && |
| 1627 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix.erase(), | 1637 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix.erase(), |
| 1628 CONFIRM_PROGID_REGISTRATION)) { | 1638 CONFIRM_PROGID_REGISTRATION)) { |
| 1629 // If Chrome is not registered under any of the possible suffixes (e.g. | 1639 // If Chrome is not registered under any of the possible suffixes (e.g. |
| 1630 // tests, Canary, etc.): use the new-style suffix at run-time. | 1640 // tests, Canary, etc.): use the new-style suffix at run-time. |
| 1631 if (!GetUserSpecificRegistrySuffix(&tested_suffix)) | 1641 if (!GetUserSpecificRegistrySuffix(&tested_suffix)) |
| 1632 NOTREACHED(); | 1642 NOTREACHED(); |
| 1633 } | 1643 } |
| 1634 return tested_suffix; | 1644 return tested_suffix; |
| 1635 } | 1645 } |
| 1636 | 1646 |
| 1637 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, | 1647 base::string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, |
| 1638 const string16& chrome_exe) { | 1648 const base::string16& chrome_exe) { |
| 1639 string16 app_name = dist->GetBaseAppName(); | 1649 base::string16 app_name = dist->GetBaseAppName(); |
| 1640 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); | 1650 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); |
| 1641 return app_name; | 1651 return app_name; |
| 1642 } | 1652 } |
| 1643 | 1653 |
| 1644 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist, | 1654 base::string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist, |
| 1645 bool is_per_user_install) { | 1655 bool is_per_user_install) { |
| 1646 string16 app_id(dist->GetBaseAppId()); | 1656 base::string16 app_id(dist->GetBaseAppId()); |
| 1647 string16 suffix; | 1657 base::string16 suffix; |
| 1648 | 1658 |
| 1649 // TODO(robertshield): Temporary hack to make the kRegisterChromeBrowserSuffix | 1659 // TODO(robertshield): Temporary hack to make the kRegisterChromeBrowserSuffix |
| 1650 // apply to all registry values computed down in these murky depths. | 1660 // apply to all registry values computed down in these murky depths. |
| 1651 CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1661 CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1652 if (command_line.HasSwitch( | 1662 if (command_line.HasSwitch( |
| 1653 installer::switches::kRegisterChromeBrowserSuffix)) { | 1663 installer::switches::kRegisterChromeBrowserSuffix)) { |
| 1654 suffix = command_line.GetSwitchValueNative( | 1664 suffix = command_line.GetSwitchValueNative( |
| 1655 installer::switches::kRegisterChromeBrowserSuffix); | 1665 installer::switches::kRegisterChromeBrowserSuffix); |
| 1656 } else if (is_per_user_install && !GetUserSpecificRegistrySuffix(&suffix)) { | 1666 } else if (is_per_user_install && !GetUserSpecificRegistrySuffix(&suffix)) { |
| 1657 NOTREACHED(); | 1667 NOTREACHED(); |
| 1658 } | 1668 } |
| 1659 // There is only one component (i.e. the suffixed appid) in this case, but it | 1669 // There is only one component (i.e. the suffixed appid) in this case, but it |
| 1660 // is still necessary to go through the appid constructor to make sure the | 1670 // is still necessary to go through the appid constructor to make sure the |
| 1661 // returned appid is truncated if necessary. | 1671 // returned appid is truncated if necessary. |
| 1662 std::vector<string16> components(1, app_id.append(suffix)); | 1672 std::vector<base::string16> components(1, app_id.append(suffix)); |
| 1663 return BuildAppModelId(components); | 1673 return BuildAppModelId(components); |
| 1664 } | 1674 } |
| 1665 | 1675 |
| 1666 string16 ShellUtil::BuildAppModelId( | 1676 base::string16 ShellUtil::BuildAppModelId( |
| 1667 const std::vector<string16>& components) { | 1677 const std::vector<base::string16>& components) { |
| 1668 DCHECK_GT(components.size(), 0U); | 1678 DCHECK_GT(components.size(), 0U); |
| 1669 | 1679 |
| 1670 // Find the maximum numbers of characters allowed in each component | 1680 // Find the maximum numbers of characters allowed in each component |
| 1671 // (accounting for the dots added between each component). | 1681 // (accounting for the dots added between each component). |
| 1672 const size_t available_chars = | 1682 const size_t available_chars = |
| 1673 installer::kMaxAppModelIdLength - (components.size() - 1); | 1683 installer::kMaxAppModelIdLength - (components.size() - 1); |
| 1674 const size_t max_component_length = available_chars / components.size(); | 1684 const size_t max_component_length = available_chars / components.size(); |
| 1675 | 1685 |
| 1676 // |max_component_length| should be at least 2; otherwise the truncation logic | 1686 // |max_component_length| should be at least 2; otherwise the truncation logic |
| 1677 // below breaks. | 1687 // below breaks. |
| 1678 if (max_component_length < 2U) { | 1688 if (max_component_length < 2U) { |
| 1679 NOTREACHED(); | 1689 NOTREACHED(); |
| 1680 return (*components.begin()).substr(0, installer::kMaxAppModelIdLength); | 1690 return (*components.begin()).substr(0, installer::kMaxAppModelIdLength); |
| 1681 } | 1691 } |
| 1682 | 1692 |
| 1683 string16 app_id; | 1693 base::string16 app_id; |
| 1684 app_id.reserve(installer::kMaxAppModelIdLength); | 1694 app_id.reserve(installer::kMaxAppModelIdLength); |
| 1685 for (std::vector<string16>::const_iterator it = components.begin(); | 1695 for (std::vector<base::string16>::const_iterator it = components.begin(); |
| 1686 it != components.end(); ++it) { | 1696 it != components.end(); ++it) { |
| 1687 if (it != components.begin()) | 1697 if (it != components.begin()) |
| 1688 app_id.push_back(L'.'); | 1698 app_id.push_back(L'.'); |
| 1689 | 1699 |
| 1690 const string16& component = *it; | 1700 const base::string16& component = *it; |
| 1691 DCHECK(!component.empty()); | 1701 DCHECK(!component.empty()); |
| 1692 if (component.length() > max_component_length) { | 1702 if (component.length() > max_component_length) { |
| 1693 // Append a shortened version of this component. Cut in the middle to try | 1703 // Append a shortened version of this component. Cut in the middle to try |
| 1694 // to avoid losing the unique parts of this component (which are usually | 1704 // to avoid losing the unique parts of this component (which are usually |
| 1695 // at the beginning or end for things like usernames and paths). | 1705 // at the beginning or end for things like usernames and paths). |
| 1696 app_id.append(component.c_str(), 0, max_component_length / 2); | 1706 app_id.append(component.c_str(), 0, max_component_length / 2); |
| 1697 app_id.append(component.c_str(), | 1707 app_id.append(component.c_str(), |
| 1698 component.length() - ((max_component_length + 1) / 2), | 1708 component.length() - ((max_component_length + 1) / 2), |
| 1699 string16::npos); | 1709 base::string16::npos); |
| 1700 } else { | 1710 } else { |
| 1701 app_id.append(component); | 1711 app_id.append(component); |
| 1702 } | 1712 } |
| 1703 } | 1713 } |
| 1704 // No spaces are allowed in the AppUserModelId according to MSDN. | 1714 // No spaces are allowed in the AppUserModelId according to MSDN. |
| 1705 base::ReplaceChars(app_id, L" ", L"_", &app_id); | 1715 base::ReplaceChars(app_id, L" ", L"_", &app_id); |
| 1706 return app_id; | 1716 return app_id; |
| 1707 } | 1717 } |
| 1708 | 1718 |
| 1709 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() { | 1719 ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() { |
| 1710 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 1720 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 1711 if (distribution->GetDefaultBrowserControlPolicy() == | 1721 if (distribution->GetDefaultBrowserControlPolicy() == |
| 1712 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 1722 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| 1713 return NOT_DEFAULT; | 1723 return NOT_DEFAULT; |
| 1714 } | 1724 } |
| 1715 // When we check for default browser we don't necessarily want to count file | 1725 // When we check for default browser we don't necessarily want to count file |
| 1716 // type handlers and icons as having changed the default browser status, | 1726 // type handlers and icons as having changed the default browser status, |
| 1717 // since the user may have changed their shell settings to cause HTML files | 1727 // since the user may have changed their shell settings to cause HTML files |
| 1718 // to open with a text editor for example. We also don't want to aggressively | 1728 // to open with a text editor for example. We also don't want to aggressively |
| 1719 // claim FTP, since the user may have a separate FTP client. It is an open | 1729 // claim FTP, since the user may have a separate FTP client. It is an open |
| 1720 // question as to how to "heal" these settings. Perhaps the user should just | 1730 // question as to how to "heal" these settings. Perhaps the user should just |
| 1721 // re-run the installer or run with the --set-default-browser command line | 1731 // re-run the installer or run with the --set-default-browser command line |
| 1722 // flag. There is doubtless some other key we can hook into to cause "Repair" | 1732 // flag. There is doubtless some other key we can hook into to cause "Repair" |
| 1723 // to show up in Add/Remove programs for us. | 1733 // to show up in Add/Remove programs for us. |
| 1724 static const wchar_t* const kChromeProtocols[] = { L"http", L"https" }; | 1734 static const wchar_t* const kChromeProtocols[] = { L"http", L"https" }; |
| 1725 return ProbeProtocolHandlers(kChromeProtocols, arraysize(kChromeProtocols)); | 1735 return ProbeProtocolHandlers(kChromeProtocols, arraysize(kChromeProtocols)); |
| 1726 } | 1736 } |
| 1727 | 1737 |
| 1728 ShellUtil::DefaultState ShellUtil::GetChromeDefaultProtocolClientState( | 1738 ShellUtil::DefaultState ShellUtil::GetChromeDefaultProtocolClientState( |
| 1729 const string16& protocol) { | 1739 const base::string16& protocol) { |
| 1730 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 1740 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 1731 if (distribution->GetDefaultBrowserControlPolicy() == | 1741 if (distribution->GetDefaultBrowserControlPolicy() == |
| 1732 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 1742 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| 1733 return NOT_DEFAULT; | 1743 return NOT_DEFAULT; |
| 1734 } | 1744 } |
| 1735 | 1745 |
| 1736 if (protocol.empty()) | 1746 if (protocol.empty()) |
| 1737 return UNKNOWN_DEFAULT; | 1747 return UNKNOWN_DEFAULT; |
| 1738 | 1748 |
| 1739 const wchar_t* const protocols[] = { protocol.c_str() }; | 1749 const wchar_t* const protocols[] = { protocol.c_str() }; |
| 1740 return ProbeProtocolHandlers(protocols, arraysize(protocols)); | 1750 return ProbeProtocolHandlers(protocols, arraysize(protocols)); |
| 1741 } | 1751 } |
| 1742 | 1752 |
| 1743 // static | 1753 // static |
| 1744 bool ShellUtil::CanMakeChromeDefaultUnattended() { | 1754 bool ShellUtil::CanMakeChromeDefaultUnattended() { |
| 1745 return base::win::GetVersion() < base::win::VERSION_WIN8; | 1755 return base::win::GetVersion() < base::win::VERSION_WIN8; |
| 1746 } | 1756 } |
| 1747 | 1757 |
| 1748 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 1758 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
| 1749 int shell_change, | 1759 int shell_change, |
| 1750 const string16& chrome_exe, | 1760 const base::string16& chrome_exe, |
| 1751 bool elevate_if_not_admin) { | 1761 bool elevate_if_not_admin) { |
| 1752 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); | 1762 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); |
| 1753 | 1763 |
| 1754 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); | 1764 BrowserDistribution* distribution = BrowserDistribution::GetDistribution(); |
| 1755 if (distribution->GetDefaultBrowserControlPolicy() != | 1765 if (distribution->GetDefaultBrowserControlPolicy() != |
| 1756 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { | 1766 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { |
| 1757 return false; | 1767 return false; |
| 1758 } | 1768 } |
| 1759 | 1769 |
| 1760 // Windows 8 does not permit making a browser default just like that. | 1770 // Windows 8 does not permit making a browser default just like that. |
| 1761 // This process needs to be routed through the system's UI. Use | 1771 // This process needs to be routed through the system's UI. Use |
| 1762 // ShowMakeChromeDefaultSystemUI instead (below). | 1772 // ShowMakeChromeDefaultSystemUI instead (below). |
| 1763 if (!CanMakeChromeDefaultUnattended()) { | 1773 if (!CanMakeChromeDefaultUnattended()) { |
| 1764 return false; | 1774 return false; |
| 1765 } | 1775 } |
| 1766 | 1776 |
| 1767 if (!ShellUtil::RegisterChromeBrowser( | 1777 if (!ShellUtil::RegisterChromeBrowser( |
| 1768 dist, chrome_exe, string16(), elevate_if_not_admin)) { | 1778 dist, chrome_exe, base::string16(), elevate_if_not_admin)) { |
| 1769 return false; | 1779 return false; |
| 1770 } | 1780 } |
| 1771 | 1781 |
| 1772 bool ret = true; | 1782 bool ret = true; |
| 1773 // First use the new "recommended" way on Vista to make Chrome default | 1783 // First use the new "recommended" way on Vista to make Chrome default |
| 1774 // browser. | 1784 // browser. |
| 1775 string16 app_name = GetApplicationName(dist, chrome_exe); | 1785 base::string16 app_name = GetApplicationName(dist, chrome_exe); |
| 1776 | 1786 |
| 1777 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1787 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1778 // On Windows Vista and Win7 we still can set ourselves via the | 1788 // On Windows Vista and Win7 we still can set ourselves via the |
| 1779 // the IApplicationAssociationRegistration interface. | 1789 // the IApplicationAssociationRegistration interface. |
| 1780 VLOG(1) << "Registering Chrome as default browser on Vista."; | 1790 VLOG(1) << "Registering Chrome as default browser on Vista."; |
| 1781 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1791 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1782 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1792 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1783 NULL, CLSCTX_INPROC); | 1793 NULL, CLSCTX_INPROC); |
| 1784 if (SUCCEEDED(hr)) { | 1794 if (SUCCEEDED(hr)) { |
| 1785 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 1795 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1808 | 1818 |
| 1809 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe)) | 1819 if (!RegisterChromeAsDefaultXPStyle(dist, shell_change, chrome_exe)) |
| 1810 ret = false; | 1820 ret = false; |
| 1811 | 1821 |
| 1812 // Send Windows notification event so that it can update icons for | 1822 // Send Windows notification event so that it can update icons for |
| 1813 // file associations. | 1823 // file associations. |
| 1814 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 1824 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
| 1815 return ret; | 1825 return ret; |
| 1816 } | 1826 } |
| 1817 | 1827 |
| 1818 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist, | 1828 bool ShellUtil::ShowMakeChromeDefaultSystemUI( |
| 1819 const string16& chrome_exe) { | 1829 BrowserDistribution* dist, |
| 1830 const base::string16& chrome_exe) { |
| 1820 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); | 1831 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); |
| 1821 if (dist->GetDefaultBrowserControlPolicy() != | 1832 if (dist->GetDefaultBrowserControlPolicy() != |
| 1822 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { | 1833 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { |
| 1823 return false; | 1834 return false; |
| 1824 } | 1835 } |
| 1825 | 1836 |
| 1826 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true)) | 1837 if (!RegisterChromeBrowser(dist, chrome_exe, base::string16(), true)) |
| 1827 return false; | 1838 return false; |
| 1828 | 1839 |
| 1829 bool succeeded = true; | 1840 bool succeeded = true; |
| 1830 bool is_default = (GetChromeDefaultState() == IS_DEFAULT); | 1841 bool is_default = (GetChromeDefaultState() == IS_DEFAULT); |
| 1831 if (!is_default) { | 1842 if (!is_default) { |
| 1832 // On Windows 8, you can't set yourself as the default handler | 1843 // On Windows 8, you can't set yourself as the default handler |
| 1833 // programatically. In other words IApplicationAssociationRegistration | 1844 // programatically. In other words IApplicationAssociationRegistration |
| 1834 // has been rendered useless. What you can do is to launch | 1845 // has been rendered useless. What you can do is to launch |
| 1835 // "Set Program Associations" section of the "Default Programs" | 1846 // "Set Program Associations" section of the "Default Programs" |
| 1836 // control panel, which is a mess, or pop the concise "How you want to open | 1847 // control panel, which is a mess, or pop the concise "How you want to open |
| 1837 // webpages?" dialog. We choose the latter. | 1848 // webpages?" dialog. We choose the latter. |
| 1838 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); | 1849 succeeded = LaunchSelectDefaultProtocolHandlerDialog(L"http"); |
| 1839 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); | 1850 is_default = (succeeded && GetChromeDefaultState() == IS_DEFAULT); |
| 1840 } | 1851 } |
| 1841 if (succeeded && is_default) | 1852 if (succeeded && is_default) |
| 1842 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe); | 1853 RegisterChromeAsDefaultXPStyle(dist, CURRENT_USER, chrome_exe); |
| 1843 return succeeded; | 1854 return succeeded; |
| 1844 } | 1855 } |
| 1845 | 1856 |
| 1846 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1857 bool ShellUtil::MakeChromeDefaultProtocolClient( |
| 1847 const string16& chrome_exe, | 1858 BrowserDistribution* dist, |
| 1848 const string16& protocol) { | 1859 const base::string16& chrome_exe, |
| 1860 const base::string16& protocol) { |
| 1849 if (dist->GetDefaultBrowserControlPolicy() != | 1861 if (dist->GetDefaultBrowserControlPolicy() != |
| 1850 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { | 1862 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { |
| 1851 return false; | 1863 return false; |
| 1852 } | 1864 } |
| 1853 | 1865 |
| 1854 if (!RegisterChromeForProtocol(dist, chrome_exe, string16(), protocol, true)) | 1866 if (!RegisterChromeForProtocol( |
| 1867 dist, chrome_exe, base::string16(), protocol, true)) |
| 1855 return false; | 1868 return false; |
| 1856 | 1869 |
| 1857 // Windows 8 does not permit making a browser default just like that. | 1870 // Windows 8 does not permit making a browser default just like that. |
| 1858 // This process needs to be routed through the system's UI. Use | 1871 // This process needs to be routed through the system's UI. Use |
| 1859 // ShowMakeChromeDefaultProocolClientSystemUI instead (below). | 1872 // ShowMakeChromeDefaultProocolClientSystemUI instead (below). |
| 1860 if (!CanMakeChromeDefaultUnattended()) | 1873 if (!CanMakeChromeDefaultUnattended()) |
| 1861 return false; | 1874 return false; |
| 1862 | 1875 |
| 1863 bool ret = true; | 1876 bool ret = true; |
| 1864 // First use the new "recommended" way on Vista to make Chrome default | 1877 // First use the new "recommended" way on Vista to make Chrome default |
| 1865 // protocol handler. | 1878 // protocol handler. |
| 1866 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1879 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1867 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1880 VLOG(1) << "Registering Chrome as default handler for " << protocol |
| 1868 << " on Vista."; | 1881 << " on Vista."; |
| 1869 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1882 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1870 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1883 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1871 NULL, CLSCTX_INPROC); | 1884 NULL, CLSCTX_INPROC); |
| 1872 if (SUCCEEDED(hr)) { | 1885 if (SUCCEEDED(hr)) { |
| 1873 string16 app_name = GetApplicationName(dist, chrome_exe); | 1886 base::string16 app_name = GetApplicationName(dist, chrome_exe); |
| 1874 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1887 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
| 1875 AT_URLPROTOCOL); | 1888 AT_URLPROTOCOL); |
| 1876 } | 1889 } |
| 1877 if (!SUCCEEDED(hr)) { | 1890 if (!SUCCEEDED(hr)) { |
| 1878 ret = false; | 1891 ret = false; |
| 1879 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1892 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
| 1880 << " HRESULT=" << hr << "."; | 1893 << " HRESULT=" << hr << "."; |
| 1881 } | 1894 } |
| 1882 } | 1895 } |
| 1883 | 1896 |
| 1884 // Now use the old way to associate Chrome with the desired protocol. This | 1897 // Now use the old way to associate Chrome with the desired protocol. This |
| 1885 // should not be required on Vista+, but since some applications still read | 1898 // should not be required on Vista+, but since some applications still read |
| 1886 // Software\Classes\<protocol> key directly, do this on Vista+ also. | 1899 // Software\Classes\<protocol> key directly, do this on Vista+ also. |
| 1887 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol)) | 1900 if (!RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol)) |
| 1888 ret = false; | 1901 ret = false; |
| 1889 | 1902 |
| 1890 return ret; | 1903 return ret; |
| 1891 } | 1904 } |
| 1892 | 1905 |
| 1893 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( | 1906 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( |
| 1894 BrowserDistribution* dist, | 1907 BrowserDistribution* dist, |
| 1895 const string16& chrome_exe, | 1908 const base::string16& chrome_exe, |
| 1896 const string16& protocol) { | 1909 const base::string16& protocol) { |
| 1897 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); | 1910 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); |
| 1898 if (dist->GetDefaultBrowserControlPolicy() != | 1911 if (dist->GetDefaultBrowserControlPolicy() != |
| 1899 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { | 1912 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL) { |
| 1900 return false; | 1913 return false; |
| 1901 } | 1914 } |
| 1902 | 1915 |
| 1903 if (!RegisterChromeForProtocol(dist, chrome_exe, string16(), protocol, true)) | 1916 if (!RegisterChromeForProtocol( |
| 1917 dist, chrome_exe, base::string16(), protocol, true)) |
| 1904 return false; | 1918 return false; |
| 1905 | 1919 |
| 1906 bool succeeded = true; | 1920 bool succeeded = true; |
| 1907 bool is_default = ( | 1921 bool is_default = ( |
| 1908 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); | 1922 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); |
| 1909 if (!is_default) { | 1923 if (!is_default) { |
| 1910 // On Windows 8, you can't set yourself as the default handler | 1924 // On Windows 8, you can't set yourself as the default handler |
| 1911 // programatically. In other words IApplicationAssociationRegistration | 1925 // programatically. In other words IApplicationAssociationRegistration |
| 1912 // has been rendered useless. What you can do is to launch | 1926 // has been rendered useless. What you can do is to launch |
| 1913 // "Set Program Associations" section of the "Default Programs" | 1927 // "Set Program Associations" section of the "Default Programs" |
| 1914 // control panel, which is a mess, or pop the concise "How you want to open | 1928 // control panel, which is a mess, or pop the concise "How you want to open |
| 1915 // links of this type (protocol)?" dialog. We choose the latter. | 1929 // links of this type (protocol)?" dialog. We choose the latter. |
| 1916 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); | 1930 succeeded = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); |
| 1917 is_default = (succeeded && | 1931 is_default = (succeeded && |
| 1918 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); | 1932 GetChromeDefaultProtocolClientState(protocol) == IS_DEFAULT); |
| 1919 } | 1933 } |
| 1920 if (succeeded && is_default) | 1934 if (succeeded && is_default) |
| 1921 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol); | 1935 RegisterChromeAsDefaultProtocolClientXPStyle(dist, chrome_exe, protocol); |
| 1922 return succeeded; | 1936 return succeeded; |
| 1923 } | 1937 } |
| 1924 | 1938 |
| 1925 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, | 1939 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, |
| 1926 const string16& chrome_exe, | 1940 const base::string16& chrome_exe, |
| 1927 const string16& unique_suffix, | 1941 const base::string16& unique_suffix, |
| 1928 bool elevate_if_not_admin) { | 1942 bool elevate_if_not_admin) { |
| 1929 if (dist->GetDefaultBrowserControlPolicy() == | 1943 if (dist->GetDefaultBrowserControlPolicy() == |
| 1930 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 1944 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| 1931 return false; | 1945 return false; |
| 1932 } | 1946 } |
| 1933 | 1947 |
| 1934 CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1948 CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1935 | 1949 |
| 1936 string16 suffix; | 1950 base::string16 suffix; |
| 1937 if (!unique_suffix.empty()) { | 1951 if (!unique_suffix.empty()) { |
| 1938 suffix = unique_suffix; | 1952 suffix = unique_suffix; |
| 1939 } else if (command_line.HasSwitch( | 1953 } else if (command_line.HasSwitch( |
| 1940 installer::switches::kRegisterChromeBrowserSuffix)) { | 1954 installer::switches::kRegisterChromeBrowserSuffix)) { |
| 1941 suffix = command_line.GetSwitchValueNative( | 1955 suffix = command_line.GetSwitchValueNative( |
| 1942 installer::switches::kRegisterChromeBrowserSuffix); | 1956 installer::switches::kRegisterChromeBrowserSuffix); |
| 1943 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { | 1957 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 1944 return false; | 1958 return false; |
| 1945 } | 1959 } |
| 1946 | 1960 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) { | 1993 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) { |
| 1980 // If the user is not an admin and OS is between Vista and Windows 7 | 1994 // If the user is not an admin and OS is between Vista and Windows 7 |
| 1981 // inclusively, try to elevate and register. This is only intended for | 1995 // inclusively, try to elevate and register. This is only intended for |
| 1982 // user-level installs as system-level installs should always be run with | 1996 // user-level installs as system-level installs should always be run with |
| 1983 // admin rights. | 1997 // admin rights. |
| 1984 result = true; | 1998 result = true; |
| 1985 } else { | 1999 } else { |
| 1986 // If we got to this point then all we can do is create ProgId and basic app | 2000 // If we got to this point then all we can do is create ProgId and basic app |
| 1987 // registrations under HKCU. | 2001 // registrations under HKCU. |
| 1988 ScopedVector<RegistryEntry> entries; | 2002 ScopedVector<RegistryEntry> entries; |
| 1989 RegistryEntry::GetProgIdEntries(dist, chrome_exe, string16(), &entries); | 2003 RegistryEntry::GetProgIdEntries( |
| 2004 dist, chrome_exe, base::string16(), &entries); |
| 1990 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered | 2005 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered |
| 1991 // with no suffix (as per the old registration style): in which case some | 2006 // with no suffix (as per the old registration style): in which case some |
| 1992 // other registry entries could refer to them and since we were not able to | 2007 // other registry entries could refer to them and since we were not able to |
| 1993 // set our HKLM entries above, we are better off not altering these here. | 2008 // set our HKLM entries above, we are better off not altering these here. |
| 1994 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { | 2009 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { |
| 1995 if (!suffix.empty()) { | 2010 if (!suffix.empty()) { |
| 1996 entries.clear(); | 2011 entries.clear(); |
| 1997 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 2012 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 1998 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); | 2013 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); |
| 1999 } | 2014 } |
| 2000 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); | 2015 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 2001 } else { | 2016 } else { |
| 2002 // The ProgId is registered unsuffixed in HKCU, also register the app with | 2017 // The ProgId is registered unsuffixed in HKCU, also register the app with |
| 2003 // Windows in HKCU (this was not done in the old registration style and | 2018 // Windows in HKCU (this was not done in the old registration style and |
| 2004 // thus needs to be done after the above check for the unsuffixed | 2019 // thus needs to be done after the above check for the unsuffixed |
| 2005 // registration). | 2020 // registration). |
| 2006 entries.clear(); | 2021 entries.clear(); |
| 2007 RegistryEntry::GetAppRegistrationEntries(chrome_exe, string16(), | 2022 RegistryEntry::GetAppRegistrationEntries(chrome_exe, base::string16(), |
| 2008 &entries); | 2023 &entries); |
| 2009 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); | 2024 result = AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 2010 } | 2025 } |
| 2011 } | 2026 } |
| 2012 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 2027 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
| 2013 return result; | 2028 return result; |
| 2014 } | 2029 } |
| 2015 | 2030 |
| 2016 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 2031 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
| 2017 const string16& chrome_exe, | 2032 const base::string16& chrome_exe, |
| 2018 const string16& unique_suffix, | 2033 const base::string16& unique_suffix, |
| 2019 const string16& protocol, | 2034 const base::string16& protocol, |
| 2020 bool elevate_if_not_admin) { | 2035 bool elevate_if_not_admin) { |
| 2021 if (dist->GetDefaultBrowserControlPolicy() == | 2036 if (dist->GetDefaultBrowserControlPolicy() == |
| 2022 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { | 2037 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED) { |
| 2023 return false; | 2038 return false; |
| 2024 } | 2039 } |
| 2025 | 2040 |
| 2026 string16 suffix; | 2041 base::string16 suffix; |
| 2027 if (!unique_suffix.empty()) { | 2042 if (!unique_suffix.empty()) { |
| 2028 suffix = unique_suffix; | 2043 suffix = unique_suffix; |
| 2029 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { | 2044 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 2030 return false; | 2045 return false; |
| 2031 } | 2046 } |
| 2032 | 2047 |
| 2033 bool user_level = InstallUtil::IsPerUserInstall(chrome_exe.c_str()); | 2048 bool user_level = InstallUtil::IsPerUserInstall(chrome_exe.c_str()); |
| 2034 HKEY root = DetermineRegistrationRoot(user_level); | 2049 HKEY root = DetermineRegistrationRoot(user_level); |
| 2035 | 2050 |
| 2036 // Look only in HKLM for system-level installs (otherwise, if a user-level | 2051 // Look only in HKLM for system-level installs (otherwise, if a user-level |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2115 if (!ShellUtil::ShortcutLocationIsSupported(location)) |
| 2101 return true; // Vacuous success. | 2116 return true; // Vacuous success. |
| 2102 | 2117 |
| 2103 FilterTargetEq shortcut_filter(target_exe, true); | 2118 FilterTargetEq shortcut_filter(target_exe, true); |
| 2104 ShortcutOperationCallback shortcut_operation( | 2119 ShortcutOperationCallback shortcut_operation( |
| 2105 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); | 2120 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); |
| 2106 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2121 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2107 shortcut_operation, location, dist, level); | 2122 shortcut_operation, location, dist, level); |
| 2108 } | 2123 } |
| 2109 | 2124 |
| 2110 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 2125 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { |
| 2111 // Use a thread-safe cache for the user's suffix. | 2126 // Use a thread-safe cache for the user's suffix. |
| 2112 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 2127 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
| 2113 LAZY_INSTANCE_INITIALIZER; | 2128 LAZY_INSTANCE_INITIALIZER; |
| 2114 return suffix_instance.Get().GetSuffix(suffix); | 2129 return suffix_instance.Get().GetSuffix(suffix); |
| 2115 } | 2130 } |
| 2116 | 2131 |
| 2117 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 2132 bool ShellUtil::GetOldUserSpecificRegistrySuffix(base::string16* suffix) { |
| 2118 wchar_t user_name[256]; | 2133 wchar_t user_name[256]; |
| 2119 DWORD size = arraysize(user_name); | 2134 DWORD size = arraysize(user_name); |
| 2120 if (::GetUserName(user_name, &size) == 0 || size < 1) { | 2135 if (::GetUserName(user_name, &size) == 0 || size < 1) { |
| 2121 NOTREACHED(); | 2136 NOTREACHED(); |
| 2122 return false; | 2137 return false; |
| 2123 } | 2138 } |
| 2124 suffix->reserve(size); | 2139 suffix->reserve(size); |
| 2125 suffix->assign(1, L'.'); | 2140 suffix->assign(1, L'.'); |
| 2126 suffix->append(user_name, size - 1); | 2141 suffix->append(user_name, size - 1); |
| 2127 return true; | 2142 return true; |
| 2128 } | 2143 } |
| 2129 | 2144 |
| 2130 string16 ShellUtil::ByteArrayToBase32(const uint8* bytes, size_t size) { | 2145 base::string16 ShellUtil::ByteArrayToBase32(const uint8* bytes, size_t size) { |
| 2131 static const char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | 2146 static const char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; |
| 2132 | 2147 |
| 2133 // Eliminate special cases first. | 2148 // Eliminate special cases first. |
| 2134 if (size == 0) { | 2149 if (size == 0) { |
| 2135 return string16(); | 2150 return base::string16(); |
| 2136 } else if (size == 1) { | 2151 } else if (size == 1) { |
| 2137 string16 ret; | 2152 base::string16 ret; |
| 2138 ret.push_back(kEncoding[(bytes[0] & 0xf8) >> 3]); | 2153 ret.push_back(kEncoding[(bytes[0] & 0xf8) >> 3]); |
| 2139 ret.push_back(kEncoding[(bytes[0] & 0x07) << 2]); | 2154 ret.push_back(kEncoding[(bytes[0] & 0x07) << 2]); |
| 2140 return ret; | 2155 return ret; |
| 2141 } else if (size >= std::numeric_limits<size_t>::max() / 8) { | 2156 } else if (size >= std::numeric_limits<size_t>::max() / 8) { |
| 2142 // If |size| is too big, the calculation of |encoded_length| below will | 2157 // If |size| is too big, the calculation of |encoded_length| below will |
| 2143 // overflow. | 2158 // overflow. |
| 2144 NOTREACHED(); | 2159 NOTREACHED(); |
| 2145 return string16(); | 2160 return base::string16(); |
| 2146 } | 2161 } |
| 2147 | 2162 |
| 2148 // Overestimate the number of bits in the string by 4 so that dividing by 5 | 2163 // Overestimate the number of bits in the string by 4 so that dividing by 5 |
| 2149 // is the equivalent of rounding up the actual number of bits divided by 5. | 2164 // is the equivalent of rounding up the actual number of bits divided by 5. |
| 2150 const size_t encoded_length = (size * 8 + 4) / 5; | 2165 const size_t encoded_length = (size * 8 + 4) / 5; |
| 2151 | 2166 |
| 2152 string16 ret; | 2167 base::string16 ret; |
| 2153 ret.reserve(encoded_length); | 2168 ret.reserve(encoded_length); |
| 2154 | 2169 |
| 2155 // A bit stream which will be read from the left and appended to from the | 2170 // A bit stream which will be read from the left and appended to from the |
| 2156 // right as it's emptied. | 2171 // right as it's emptied. |
| 2157 uint16 bit_stream = (bytes[0] << 8) + bytes[1]; | 2172 uint16 bit_stream = (bytes[0] << 8) + bytes[1]; |
| 2158 size_t next_byte_index = 2; | 2173 size_t next_byte_index = 2; |
| 2159 int free_bits = 0; | 2174 int free_bits = 0; |
| 2160 while (free_bits < 16) { | 2175 while (free_bits < 16) { |
| 2161 // Extract the 5 leftmost bits in the stream | 2176 // Extract the 5 leftmost bits in the stream |
| 2162 ret.push_back(kEncoding[(bit_stream & 0xf800) >> 11]); | 2177 ret.push_back(kEncoding[(bit_stream & 0xf800) >> 11]); |
| 2163 bit_stream <<= 5; | 2178 bit_stream <<= 5; |
| 2164 free_bits += 5; | 2179 free_bits += 5; |
| 2165 | 2180 |
| 2166 // If there is enough room in the bit stream, inject another byte (if there | 2181 // If there is enough room in the bit stream, inject another byte (if there |
| 2167 // are any left...). | 2182 // are any left...). |
| 2168 if (free_bits >= 8 && next_byte_index < size) { | 2183 if (free_bits >= 8 && next_byte_index < size) { |
| 2169 free_bits -= 8; | 2184 free_bits -= 8; |
| 2170 bit_stream += bytes[next_byte_index++] << free_bits; | 2185 bit_stream += bytes[next_byte_index++] << free_bits; |
| 2171 } | 2186 } |
| 2172 } | 2187 } |
| 2173 | 2188 |
| 2174 DCHECK_EQ(ret.length(), encoded_length); | 2189 DCHECK_EQ(ret.length(), encoded_length); |
| 2175 return ret; | 2190 return ret; |
| 2176 } | 2191 } |
| OLD | NEW |