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 3 // found in the LICENSE file. 4 // 5 // This file declares methods that are useful for integrating Chrome in 6 // Windows shell. These methods are all static and currently part of 7 // ShellUtil class. 8 9 #ifndef CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ 10 #define CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ 11 12 #include <windows.h> 13 14 #include <map> 15 #include <utility> 16 #include <vector> 17 18 #include "base/basictypes.h" 19 #include "base/files/file_path.h" 20 #include "base/logging.h" 21 #include "base/memory/ref_counted.h" 22 #include "base/strings/string16.h" 23 #include "chrome/installer/util/work_item_list.h" 24 25 class BrowserDistribution; 26 27 namespace base { 28 class CancellationFlag; 29 } 30 31 // This is a utility class that provides common shell integration methods 32 // that can be used by installer as well as Chrome. 33 class ShellUtil { 34 public: 35 // Input to any methods that make changes to OS shell. 36 enum ShellChange { 37 CURRENT_USER = 0x1, // Make any shell changes only at the user level 38 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level 39 }; 40 41 // Chrome's default handler state for a given protocol. 42 enum DefaultState { 43 UNKNOWN_DEFAULT, 44 NOT_DEFAULT, 45 IS_DEFAULT, 46 }; 47 48 // Typical shortcut directories. Resolved in GetShortcutPath(). 49 // Also used in ShortcutLocationIsSupported(). 50 enum ShortcutLocation { 51 SHORTCUT_LOCATION_FIRST = 0, 52 SHORTCUT_LOCATION_DESKTOP = SHORTCUT_LOCATION_FIRST, 53 SHORTCUT_LOCATION_QUICK_LAUNCH, 54 SHORTCUT_LOCATION_START_MENU_ROOT, 55 SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 56 SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 57 SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 + 58 SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 + 59 NUM_SHORTCUT_LOCATIONS 60 }; 61 62 enum ShortcutOperation { 63 // Create a new shortcut (overwriting if necessary). 64 SHELL_SHORTCUT_CREATE_ALWAYS, 65 // Create the per-user shortcut only if its system-level equivalent (with 66 // the same name) is not present. 67 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, 68 // Overwrite an existing shortcut (fail if the shortcut doesn't exist). 69 // If the arguments are not specified on the new shortcut, keep the old 70 // shortcut's arguments. 71 SHELL_SHORTCUT_REPLACE_EXISTING, 72 // Update specified properties only on an existing shortcut. 73 SHELL_SHORTCUT_UPDATE_EXISTING, 74 }; 75 76 // Properties for shortcuts. Properties set will be applied to 77 // the shortcut on creation/update. On update, unset properties are ignored; 78 // on create (and replaced) unset properties might have a default value (see 79 // individual property setters below for details). 80 // Callers are encouraged to use the setters provided which take care of 81 // setting |options| as desired. 82 struct ShortcutProperties { 83 enum IndividualProperties { 84 PROPERTIES_TARGET = 1 << 0, 85 PROPERTIES_ARGUMENTS = 1 << 1, 86 PROPERTIES_DESCRIPTION = 1 << 2, 87 PROPERTIES_ICON = 1 << 3, 88 PROPERTIES_APP_ID = 1 << 4, 89 PROPERTIES_SHORTCUT_NAME = 1 << 5, 90 PROPERTIES_DUAL_MODE = 1 << 6, 91 }; 92 93 explicit ShortcutProperties(ShellChange level_in) 94 : level(level_in), icon_index(0), dual_mode(false), 95 pin_to_taskbar(false), options(0U) {} 96 97 // Sets the target executable to launch from this shortcut. 98 // This is mandatory when creating a shortcut. 99 void set_target(const base::FilePath& target_in) { 100 target = target_in; 101 options |= PROPERTIES_TARGET; 102 } 103 104 // Sets the arguments to be passed to |target| when launching from this 105 // shortcut. 106 // The length of this string must be less than MAX_PATH. 107 void set_arguments(const base::string16& arguments_in) { 108 // Size restriction as per MSDN at 109 // http://msdn.microsoft.com/library/windows/desktop/bb774954.aspx. 110 DCHECK(arguments_in.length() < MAX_PATH); 111 arguments = arguments_in; 112 options |= PROPERTIES_ARGUMENTS; 113 } 114 115 // Sets the localized description of the shortcut. 116 // The length of this string must be less than MAX_PATH. 117 void set_description(const base::string16& description_in) { 118 // Size restriction as per MSDN at 119 // http://msdn.microsoft.com/library/windows/desktop/bb774955.aspx. 120 DCHECK(description_in.length() < MAX_PATH); 121 description = description_in; 122 options |= PROPERTIES_DESCRIPTION; 123 } 124 125 // Sets the path to the icon (icon_index set to 0). 126 // icon index unless otherwise specified in master_preferences). 127 void set_icon(const base::FilePath& icon_in, int icon_index_in) { 128 icon = icon_in; 129 icon_index = icon_index_in; 130 options |= PROPERTIES_ICON; 131 } 132 133 // Sets the app model id for the shortcut (Win7+). 134 void set_app_id(const base::string16& app_id_in) { 135 app_id = app_id_in; 136 options |= PROPERTIES_APP_ID; 137 } 138 139 // Forces the shortcut's name to |shortcut_name_in|. 140 // Default: the current distribution's GetShortcutName(SHORTCUT_CHROME). 141 // The ".lnk" extension will automatically be added to this name. 142 void set_shortcut_name(const base::string16& shortcut_name_in) { 143 shortcut_name = shortcut_name_in; 144 options |= PROPERTIES_SHORTCUT_NAME; 145 } 146 147 // Sets whether this is a dual mode shortcut (Win8+). 148 // NOTE: Only the default (no arguments and default browser appid) browser 149 // shortcut in the Start menu (Start screen on Win8+) should be made dual 150 // mode. 151 void set_dual_mode(bool dual_mode_in) { 152 dual_mode = dual_mode_in; 153 options |= PROPERTIES_DUAL_MODE; 154 } 155 156 // Sets whether to pin this shortcut to the taskbar after creating it 157 // (ignored if the shortcut is only being updated). 158 // Note: This property doesn't have a mask in |options|. 159 void set_pin_to_taskbar(bool pin_to_taskbar_in) { 160 pin_to_taskbar = pin_to_taskbar_in; 161 } 162 163 bool has_target() const { 164 return (options & PROPERTIES_TARGET) != 0; 165 } 166 167 bool has_arguments() const { 168 return (options & PROPERTIES_ARGUMENTS) != 0; 169 } 170 171 bool has_description() const { 172 return (options & PROPERTIES_DESCRIPTION) != 0; 173 } 174 175 bool has_icon() const { 176 return (options & PROPERTIES_ICON) != 0; 177 } 178 179 bool has_app_id() const { 180 return (options & PROPERTIES_APP_ID) != 0; 181 } 182 183 bool has_shortcut_name() const { 184 return (options & PROPERTIES_SHORTCUT_NAME) != 0; 185 } 186 187 bool has_dual_mode() const { 188 return (options & PROPERTIES_DUAL_MODE) != 0; 189 } 190 191 // The level to install this shortcut at (CURRENT_USER for a per-user 192 // shortcut and SYSTEM_LEVEL for an all-users shortcut). 193 ShellChange level; 194 195 base::FilePath target; 196 base::string16 arguments; 197 base::string16 description; 198 base::FilePath icon; 199 int icon_index; 200 base::string16 app_id; 201 base::string16 shortcut_name; 202 bool dual_mode; 203 bool pin_to_taskbar; 204 // Bitfield made of IndividualProperties. Properties set in |options| will 205 // be used to create/update the shortcut, others will be ignored on update 206 // and possibly replaced by default values on create (see individual 207 // property setters above for details on default values). 208 uint32 options; 209 }; 210 211 // Relative path of the URL Protocol registry entry (prefixed with '\'). 212 static const wchar_t* kRegURLProtocol; 213 214 // Relative path of DefaultIcon registry entry (prefixed with '\'). 215 static const wchar_t* kRegDefaultIcon; 216 217 // Relative path of "shell" registry key. 218 static const wchar_t* kRegShellPath; 219 220 // Relative path of shell open command in Windows registry 221 // (i.e. \\shell\\open\\command). 222 static const wchar_t* kRegShellOpen; 223 224 // Relative path of registry key under which applications need to register 225 // to control Windows Start menu links. 226 static const wchar_t* kRegStartMenuInternet; 227 228 // Relative path of Classes registry entry under which file associations 229 // are added on Windows. 230 static const wchar_t* kRegClasses; 231 232 // Relative path of RegisteredApplications registry entry under which 233 // we add Chrome as a Windows application 234 static const wchar_t* kRegRegisteredApplications; 235 236 // The key path and key name required to register Chrome on Windows such 237 // that it can be launched from Start->Run just by name (chrome.exe). 238 static const wchar_t* kAppPathsRegistryKey; 239 static const wchar_t* kAppPathsRegistryPathName; 240 241 // Registry path that stores url associations on Vista. 242 static const wchar_t* kRegVistaUrlPrefs; 243 244 // File extensions that Chrome registers itself as the default handler 245 // for when the user makes Chrome the default browser. 246 static const wchar_t* kDefaultFileAssociations[]; 247 248 // File extensions that Chrome registers itself as being capable of 249 // handling. 250 static const wchar_t* kPotentialFileAssociations[]; 251 252 // Protocols that Chrome registers itself as the default handler for 253 // when the user makes Chrome the default browser. 254 static const wchar_t* kBrowserProtocolAssociations[]; 255 256 // Protocols that Chrome registers itself as being capable of handling. 257 static const wchar_t* kPotentialProtocolAssociations[]; 258 259 // Registry value name that is needed for ChromeHTML ProgId 260 static const wchar_t* kRegUrlProtocol; 261 262 // Relative registry path from \Software\Classes\ChromeHTML to the ProgId 263 // Application definitions. 264 static const wchar_t* kRegApplication; 265 266 // Registry value name for the AppUserModelId of an application. 267 static const wchar_t* kRegAppUserModelId; 268 269 // Registry value name for the description of an application. 270 static const wchar_t* kRegApplicationDescription; 271 272 // Registry value name for an application's name. 273 static const wchar_t* kRegApplicationName; 274 275 // Registry value name for the path to an application's icon. 276 static const wchar_t* kRegApplicationIcon; 277 278 // Registry value name for an application's company. 279 static const wchar_t* kRegApplicationCompany; 280 281 // Relative path of ".exe" registry key. 282 static const wchar_t* kRegExePath; 283 284 // Registry value name of the open verb. 285 static const wchar_t* kRegVerbOpen; 286 287 // Registry value name of the opennewwindow verb. 288 static const wchar_t* kRegVerbOpenNewWindow; 289 290 // Registry value name of the run verb. 291 static const wchar_t* kRegVerbRun; 292 293 // Registry value name for command entries. 294 static const wchar_t* kRegCommand; 295 296 // Registry value name for the DelegateExecute verb handler. 297 static const wchar_t* kRegDelegateExecute; 298 299 // Registry value name for the OpenWithProgids entry for file associations. 300 static const wchar_t* kRegOpenWithProgids; 301 302 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. 303 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and 304 // doesn't otherwise validate a full Chrome install in HKLM. 305 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, 306 const base::string16& chrome_exe, 307 const base::string16& suffix); 308 309 // Returns true if the current Windows version supports the presence of 310 // shortcuts at |location|. 311 static bool ShortcutLocationIsSupported(ShellUtil::ShortcutLocation location); 312 313 // Sets |path| to the path for a shortcut at the |location| desired for the 314 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for 315 // all-users path). 316 // Returns false on failure. 317 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, 318 BrowserDistribution* dist, 319 ShellChange level, 320 base::FilePath* path); 321 322 // Updates shortcut in |location| (or creates it if |options| specify 323 // SHELL_SHORTCUT_CREATE_ALWAYS). 324 // |dist| gives the type of browser distribution currently in use. 325 // |properties| and |operation| affect this method as described on their 326 // invidividual definitions above. 327 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, 328 // SHORTCUT_LOCATION_QUICK_LAUNCH, SHORTCUT_LOCATION_START_MENU_ROOT, 329 // SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or 330 // SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR. 331 static bool CreateOrUpdateShortcut( 332 ShellUtil::ShortcutLocation location, 333 BrowserDistribution* dist, 334 const ShellUtil::ShortcutProperties& properties, 335 ShellUtil::ShortcutOperation operation); 336 337 // Returns the string "|icon_path|,|icon_index|" (see, for example, 338 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). 339 static base::string16 FormatIconLocation(const base::string16& icon_path, 340 int icon_index); 341 342 // This method returns the command to open URLs/files using chrome. Typically 343 // this command is written to the registry under shell\open\command key. 344 // |chrome_exe|: the full path to chrome.exe 345 static base::string16 GetChromeShellOpenCmd(const base::string16& chrome_exe); 346 347 // This method returns the command to be called by the DelegateExecute verb 348 // handler to launch chrome on Windows 8. Typically this command is written to 349 // the registry under the HKCR\Chrome\.exe\shell\(open|run)\command key. 350 // |chrome_exe|: the full path to chrome.exe 351 static base::string16 GetChromeDelegateCommand( 352 const base::string16& chrome_exe); 353 354 // Gets a mapping of all registered browser names (excluding browsers in the 355 // |dist| distribution) and their reinstall command (which usually sets 356 // browser as default). 357 // Given browsers can be registered in HKCU (as of Win7) and/or in HKLM, this 358 // method looks in both and gives precedence to values in HKCU as per the msdn 359 // standard: http://goo.gl/xjczJ. 360 static void GetRegisteredBrowsers( 361 BrowserDistribution* dist, 362 std::map<base::string16, base::string16>* browsers); 363 364 // Returns the suffix this user's Chrome install is registered with. 365 // Always returns the empty string on system-level installs. 366 // 367 // This method is meant for external methods which need to know the suffix of 368 // the current install at run-time, not for install-time decisions. 369 // There are no guarantees that this suffix will not change later: 370 // (e.g. if two user-level installs were previously installed in parallel on 371 // the same machine, both without admin rights and with no user-level install 372 // having claimed the non-suffixed HKLM registrations, they both have no 373 // suffix in their progId entries (as per the old suffix rules). If they were 374 // to both fully register (i.e. click "Make Chrome Default" and go through 375 // UAC; or upgrade to Win8 and get the automatic no UAC full registration) 376 // they would then both get a suffixed registration as per the new suffix 377 // rules). 378 // 379 // |chrome_exe| The path to the currently installed (or running) chrome.exe. 380 static base::string16 GetCurrentInstallationSuffix( 381 BrowserDistribution* dist, 382 const base::string16& chrome_exe); 383 384 // Returns the application name of the program under |dist|. 385 // This application name will be suffixed as is appropriate for the current 386 // install. 387 // This is the name that is registered with Default Programs on Windows and 388 // that should thus be used to "make chrome default" and such. 389 static base::string16 GetApplicationName(BrowserDistribution* dist, 390 const base::string16& chrome_exe); 391 392 // Returns the AppUserModelId for |dist|. This identifier is unconditionally 393 // suffixed with a unique id for this user on user-level installs (in contrast 394 // to other registration entries which are suffixed as described in 395 // GetCurrentInstallationSuffix() above). 396 static base::string16 GetBrowserModelId(BrowserDistribution* dist, 397 bool is_per_user_install); 398 399 // Returns an AppUserModelId composed of each member of |components| separated 400 // by dots. 401 // The returned appid is guaranteed to be no longer than 402 // chrome::kMaxAppModelIdLength (some of the components might have been 403 // shortened to enforce this). 404 static base::string16 BuildAppModelId( 405 const std::vector<base::string16>& components); 406 407 // Returns true if Chrome can make itself the default browser without relying 408 // on the Windows shell to prompt the user. This is the case for versions of 409 // Windows prior to Windows 8. 410 static bool CanMakeChromeDefaultUnattended(); 411 412 // Returns the DefaultState of Chrome for HTTP and HTTPS. 413 static DefaultState GetChromeDefaultState(); 414 415 // Returns the DefaultState of the Chrome instance with the specified path 416 // for HTTP and HTTPs. 417 static DefaultState GetChromeDefaultStateFromPath( 418 const base::FilePath& chrome_exe); 419 420 // Returns the DefaultState of Chrome for |protocol|. 421 static DefaultState GetChromeDefaultProtocolClientState( 422 const base::string16& protocol); 423 424 // Make Chrome the default browser. This function works by going through 425 // the url protocols and file associations that are related to general 426 // browsing, e.g. http, https, .html etc., and requesting to become the 427 // default handler for each. If any of these fails the operation will return 428 // false to indicate failure, which is consistent with the return value of 429 // ShellIntegration::GetDefaultBrowser. 430 // 431 // In the case of failure any successful changes will be left, however no 432 // more changes will be attempted. 433 // TODO(benwells): Attempt to undo any changes that were successfully made. 434 // http://crbug.com/83970 435 // 436 // shell_change: Defined whether to register as default browser at system 437 // level or user level. If value has ShellChange::SYSTEM_LEVEL 438 // we should be running as admin user. 439 // chrome_exe: The chrome.exe path to register as default browser. 440 // elevate_if_not_admin: On Vista if user is not admin, try to elevate for 441 // Chrome registration. 442 static bool MakeChromeDefault(BrowserDistribution* dist, 443 int shell_change, 444 const base::string16& chrome_exe, 445 bool elevate_if_not_admin); 446 447 // Shows and waits for the Windows 8 "How do you want to open webpages?" 448 // dialog if Chrome is not already the default HTTP/HTTPS handler. Also does 449 // XP-era registrations if Chrome is chosen or was already the default. Do 450 // not use on pre-Win8 OSes. 451 // 452 // |dist| gives the type of browser distribution currently in use. 453 // |chrome_exe| The chrome.exe path to register as default browser. 454 static bool ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist, 455 const base::string16& chrome_exe); 456 457 // Make Chrome the default application for a protocol. 458 // chrome_exe: The chrome.exe path to register as default browser. 459 // protocol: The protocol to register as the default handler for. 460 static bool MakeChromeDefaultProtocolClient(BrowserDistribution* dist, 461 const base::string16& chrome_exe, 462 const base::string16& protocol); 463 464 // Shows and waits for the Windows 8 "How do you want to open links of this 465 // type?" dialog if Chrome is not already the default |protocol| 466 // handler. Also does XP-era registrations if Chrome is chosen or was already 467 // the default for |protocol|. Do not use on pre-Win8 OSes. 468 // 469 // |dist| gives the type of browser distribution currently in use. 470 // |chrome_exe| The chrome.exe path to register as default browser. 471 // |protocol| is the protocol being registered. 472 static bool ShowMakeChromeDefaultProtocolClientSystemUI( 473 BrowserDistribution* dist, 474 const base::string16& chrome_exe, 475 const base::string16& protocol); 476 477 // Registers Chrome as a potential default browser and handler for filetypes 478 // and protocols. 479 // If Chrome is already registered, this method is a no-op. 480 // This method requires write access to HKLM (prior to Win8) so is just a 481 // best effort deal. 482 // If write to HKLM is required, but fails, and: 483 // - |elevate_if_not_admin| is true (and OS is Vista or above): 484 // tries to launch setup.exe with admin priviledges (by prompting the user 485 // with a UAC) to do these tasks. 486 // - |elevate_if_not_admin| is false (or OS is XP): 487 // adds the ProgId entries to HKCU. These entries will not make Chrome show 488 // in Default Programs but they are still useful because Chrome can be 489 // registered to run when the user clicks on an http link or an html file. 490 // 491 // |chrome_exe| full path to chrome.exe. 492 // |unique_suffix| Optional input. If given, this function appends the value 493 // to default browser entries names that it creates in the registry. 494 // Currently, this is only used to continue an install with the same suffix 495 // when elevating and calling setup.exe with admin privileges as described 496 // above. 497 // |elevate_if_not_admin| if true will make this method try alternate methods 498 // as described above. This should only be true when following a user action 499 // (e.g. "Make Chrome Default") as it allows this method to UAC. 500 // 501 // Returns true if Chrome is successfully registered (or already registered). 502 static bool RegisterChromeBrowser(BrowserDistribution* dist, 503 const base::string16& chrome_exe, 504 const base::string16& unique_suffix, 505 bool elevate_if_not_admin); 506 507 // This method declares to Windows that Chrome is capable of handling the 508 // given protocol. This function will call the RegisterChromeBrowser function 509 // to register with Windows as capable of handling the protocol, if it isn't 510 // currently registered as capable. 511 // Declaring the capability of handling a protocol is necessary to register 512 // as the default handler for the protocol in Vista and later versions of 513 // Windows. 514 // 515 // If called by the browser and elevation is required, it will elevate by 516 // calling setup.exe which will again call this function with elevate false. 517 // 518 // |chrome_exe| full path to chrome.exe. 519 // |unique_suffix| Optional input. If given, this function appends the value 520 // to default browser entries names that it creates in the registry. 521 // |protocol| The protocol to register as being capable of handling.s 522 // |elevate_if_not_admin| if true will make this method try alternate methods 523 // as described above. 524 static bool RegisterChromeForProtocol(BrowserDistribution* dist, 525 const base::string16& chrome_exe, 526 const base::string16& unique_suffix, 527 const base::string16& protocol, 528 bool elevate_if_not_admin); 529 530 // Removes installed shortcut(s) at |location|. 531 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to 532 // remove all-users shortcuts. 533 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when 534 // their target is |target_exe|. 535 // If |location| is a Chrome-specific folder, it will be deleted as well. 536 // Returns true if all shortcuts pointing to |target_exe| are successfully 537 // deleted, including the case where no such shortcuts are found. 538 static bool RemoveShortcuts(ShellUtil::ShortcutLocation location, 539 BrowserDistribution* dist, 540 ShellChange level, 541 const base::FilePath& target_exe); 542 543 // Updates the target of all shortcuts in |location| that satisfy the 544 // following: 545 // - the shortcut's original target is |old_target_exe|, 546 // - the original arguments are non-empty. 547 // If the shortcut's icon points to |old_target_exe|, then it also gets 548 // redirected to |new_target_exe|. 549 // Returns true if all updates to matching shortcuts are successful, including 550 // the vacuous case where no matching shortcuts are found. 551 static bool RetargetShortcutsWithArgs( 552 ShellUtil::ShortcutLocation location, 553 BrowserDistribution* dist, 554 ShellChange level, 555 const base::FilePath& old_target_exe, 556 const base::FilePath& new_target_exe); 557 558 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag; 559 560 // Appends Chrome shortcuts with non-whitelisted arguments to |shortcuts| if 561 // not NULL. If |do_removal|, also removes non-whitelisted arguments from 562 // those shortcuts. This method will abort and return false if |cancel| is 563 // non-NULL and gets set at any point during this call. 564 static bool ShortcutListMaybeRemoveUnknownArgs( 565 ShellUtil::ShortcutLocation location, 566 BrowserDistribution* dist, 567 ShellChange level, 568 const base::FilePath& chrome_exe, 569 bool do_removal, 570 const scoped_refptr<SharedCancellationFlag>& cancel, 571 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts); 572 573 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid 574 // preceded by a dot. 575 // This is guaranteed to be unique on the machine and 27 characters long 576 // (including the '.'). 577 // This suffix is then meant to be added to all registration that may conflict 578 // with another user-level Chrome install. 579 // Note that prior to Chrome 21, the suffix registered used to be the user's 580 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old 581 // installs registered that way, but it was wrong because some of the 582 // characters allowed in a username are not allowed in a ProgId. 583 // Returns true unless the OS call to retrieve the username fails. 584 // NOTE: Only the installer should use this suffix directly. Other callers 585 // should call GetCurrentInstallationSuffix(). 586 static bool GetUserSpecificRegistrySuffix(base::string16* suffix); 587 588 // Sets |suffix| to this user's username preceded by a dot. This suffix should 589 // only be used to support legacy installs that used this suffixing 590 // style. 591 // Returns true unless the OS call to retrieve the username fails. 592 // NOTE: Only the installer should use this suffix directly. Other callers 593 // should call GetCurrentInstallationSuffix(). 594 static bool GetOldUserSpecificRegistrySuffix(base::string16* suffix); 595 596 // Returns the base32 encoding (using the [A-Z2-7] alphabet) of |bytes|. 597 // |size| is the length of |bytes|. 598 // Note: This method does not suffix the output with '=' signs as technically 599 // required by the base32 standard for inputs that aren't a multiple of 5 600 // bytes. 601 static base::string16 ByteArrayToBase32(const uint8* bytes, size_t size); 602 603 private: 604 DISALLOW_COPY_AND_ASSIGN(ShellUtil); 605 }; 606 607 608 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ 609