| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 24 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
| 25 #include "base/string_split.h" | 25 #include "base/string_split.h" |
| 26 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "base/win/registry.h" | 29 #include "base/win/registry.h" |
| 30 #include "base/win/scoped_comptr.h" | 30 #include "base/win/scoped_comptr.h" |
| 31 #include "base/win/win_util.h" |
| 31 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 32 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| 33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/installer/util/browser_distribution.h" | 35 #include "chrome/installer/util/browser_distribution.h" |
| 35 #include "chrome/installer/util/install_util.h" | 36 #include "chrome/installer/util/install_util.h" |
| 36 #include "chrome/installer/util/master_preferences.h" | 37 #include "chrome/installer/util/master_preferences.h" |
| 37 #include "chrome/installer/util/master_preferences_constants.h" | 38 #include "chrome/installer/util/master_preferences_constants.h" |
| 38 | 39 |
| 39 using base::win::RegKey; | 40 using base::win::RegKey; |
| 40 | 41 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 VER_SET_CONDITION(condition_mask, VER_BUILDNUMBER, VER_GREATER_EQUAL); | 79 VER_SET_CONDITION(condition_mask, VER_BUILDNUMBER, VER_GREATER_EQUAL); |
| 79 VER_SET_CONDITION(condition_mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); | 80 VER_SET_CONDITION(condition_mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); |
| 80 VER_SET_CONDITION(condition_mask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); | 81 VER_SET_CONDITION(condition_mask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); |
| 81 | 82 |
| 82 DWORD type_mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | | 83 DWORD type_mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | |
| 83 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR; | 84 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR; |
| 84 | 85 |
| 85 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; | 86 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; |
| 86 } | 87 } |
| 87 | 88 |
| 89 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's username |
| 90 // preceded by a dot. |
| 91 // This is guaranteed to be unique on the machine and 27 characters long |
| 92 // (including the '.'). |
| 93 // This suffix is then meant to be added to all registration that may conflict |
| 94 // with another user-level Chrome install. |
| 95 // Note that prior to Chrome 21, the suffix registered used to be the user's |
| 96 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old |
| 97 // installs registered that way, but it was wrong because some of the characters |
| 98 // allowed in a username are not allowed in a ProgId. |
| 99 // Returns true unless the OS call to retrieve the username fails. |
| 100 bool GetNewUserSpecificRegistrySuffix(string16* suffix) { |
| 101 wchar_t user_name[256]; |
| 102 DWORD size = arraysize(user_name); |
| 103 if (::GetUserName(user_name, &size) == 0 || size < 1) { |
| 104 NOTREACHED(); |
| 105 return false; |
| 106 } |
| 107 base::MD5Digest md5_digest; |
| 108 base::MD5Sum(user_name, size, &md5_digest); |
| 109 const string16 base32_md5(ShellUtil::MD5DigestToBase32(md5_digest)); |
| 110 // The value returned by the base32 algorithm above must never change and must |
| 111 // always be 26 characters long (i.e. if someone ever moves this to base and |
| 112 // implements the full base32 algorithm (i.e. with appended '=' signs in the |
| 113 // output), they must provide a flag to allow this method to still request |
| 114 // the output with no appended '=' signs). |
| 115 DCHECK_EQ(base32_md5.length(), 26U); |
| 116 suffix->reserve(27); |
| 117 suffix->assign(1, L'.'); |
| 118 suffix->append(base32_md5); |
| 119 return true; |
| 120 } |
| 121 |
| 122 // Sets |suffix| to this user's username preceded by a dot. This suffix is then |
| 123 // meant to be added to all registration that may conflict with another |
| 124 // user-level Chrome install. |
| 125 // Returns true unless the OS call to retrieve the username fails. |
| 126 bool GetOldUserSpecificRegistrySuffix(string16* suffix) { |
| 127 wchar_t user_name[256]; |
| 128 DWORD size = arraysize(user_name); |
| 129 if (::GetUserName(user_name, &size) == 0 || size < 1) { |
| 130 NOTREACHED(); |
| 131 return false; |
| 132 } |
| 133 suffix->reserve(size); |
| 134 suffix->assign(1, L'.'); |
| 135 suffix->append(user_name, size - 1); |
| 136 return true; |
| 137 } |
| 138 |
| 139 // Returns the current (or installed) browser's ProgId (e.g. |
| 140 // "ChromeHTML|suffix|"). |
| 141 // |suffix| can be the empty string. |
| 142 string16 GetBrowserProgId(const string16& suffix) { |
| 143 string16 chrome_html(ShellUtil::kChromeHTMLProgId); |
| 144 chrome_html.append(suffix); |
| 145 |
| 146 // ProgIds cannot be longer than 39 characters. |
| 147 // Ref: http://msdn.microsoft.com/en-us/library/aa911706.aspx. |
| 148 // Make all new registrations comply with this requirement (existing |
| 149 // registrations must be preserved). |
| 150 // Note: since |new_style_suffix| will always be the same for this user, only |
| 151 // initialize it once, re-use the derived value in subsequent calls. |
| 152 static string16 new_style_suffix; |
| 153 if ((!new_style_suffix.empty() || |
| 154 GetNewUserSpecificRegistrySuffix(&new_style_suffix)) && |
| 155 suffix.compare(new_style_suffix) == 0 && chrome_html.length() > 39) { |
| 156 NOTREACHED(); |
| 157 chrome_html.erase(39); |
| 158 } |
| 159 return chrome_html; |
| 160 } |
| 161 |
| 88 // This class represents a single registry entry. The objective is to | 162 // This class represents a single registry entry. The objective is to |
| 89 // encapsulate all the registry entries required for registering Chrome at one | 163 // encapsulate all the registry entries required for registering Chrome at one |
| 90 // place. This class can not be instantiated outside the class and the objects | 164 // place. This class can not be instantiated outside the class and the objects |
| 91 // of this class type can be obtained only by calling a static method of this | 165 // of this class type can be obtained only by calling a static method of this |
| 92 // class. | 166 // class. |
| 93 class RegistryEntry { | 167 class RegistryEntry { |
| 94 public: | 168 public: |
| 95 // A bit-field enum of places to look for this key in the Windows registry. | 169 // A bit-field enum of places to look for this key in the Windows registry. |
| 96 enum LookForIn { | 170 enum LookForIn { |
| 97 LOOK_IN_HKCU = 1 << 0, | 171 LOOK_IN_HKCU = 1 << 0, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command | 248 // <root hkey>\Software\Classes\<app_id>\.exe\shell\<verb>\command |
| 175 entries->push_front(new RegistryEntry(sub_path, delegate_command)); | 249 entries->push_front(new RegistryEntry(sub_path, delegate_command)); |
| 176 entries->push_front(new RegistryEntry( | 250 entries->push_front(new RegistryEntry( |
| 177 sub_path, ShellUtil::kRegDelegateExecute, delegate_guid)); | 251 sub_path, ShellUtil::kRegDelegateExecute, delegate_guid)); |
| 178 } | 252 } |
| 179 } | 253 } |
| 180 | 254 |
| 181 // File association ProgId | 255 // File association ProgId |
| 182 string16 chrome_html_prog_id(ShellUtil::kRegClasses); | 256 string16 chrome_html_prog_id(ShellUtil::kRegClasses); |
| 183 chrome_html_prog_id.push_back(FilePath::kSeparators[0]); | 257 chrome_html_prog_id.push_back(FilePath::kSeparators[0]); |
| 184 chrome_html_prog_id.append(ShellUtil::kChromeHTMLProgId); | 258 chrome_html_prog_id.append(GetBrowserProgId(suffix)); |
| 185 chrome_html_prog_id.append(suffix); | |
| 186 entries->push_front(new RegistryEntry( | 259 entries->push_front(new RegistryEntry( |
| 187 chrome_html_prog_id, ShellUtil::kChromeHTMLProgIdDesc)); | 260 chrome_html_prog_id, ShellUtil::kChromeHTMLProgIdDesc)); |
| 188 entries->push_front(new RegistryEntry( | 261 entries->push_front(new RegistryEntry( |
| 189 chrome_html_prog_id, ShellUtil::kRegUrlProtocol, L"")); | 262 chrome_html_prog_id, ShellUtil::kRegUrlProtocol, L"")); |
| 190 entries->push_front(new RegistryEntry( | 263 entries->push_front(new RegistryEntry( |
| 191 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); | 264 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); |
| 192 entries->push_front(new RegistryEntry( | 265 entries->push_front(new RegistryEntry( |
| 193 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); | 266 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); |
| 194 if (set_delegate_execute) { | 267 if (set_delegate_execute) { |
| 195 entries->push_front(new RegistryEntry( | 268 entries->push_front(new RegistryEntry( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 300 } |
| 228 | 301 |
| 229 // This method returns a list of the registry entries needed to declare a | 302 // This method returns a list of the registry entries needed to declare a |
| 230 // capability of handling a protocol on Windows. | 303 // capability of handling a protocol on Windows. |
| 231 static bool GetProtocolCapabilityEntries(BrowserDistribution* dist, | 304 static bool GetProtocolCapabilityEntries(BrowserDistribution* dist, |
| 232 const string16& suffix, | 305 const string16& suffix, |
| 233 const string16& protocol, | 306 const string16& protocol, |
| 234 std::list<RegistryEntry*>* entries) { | 307 std::list<RegistryEntry*>* entries) { |
| 235 entries->push_front(new RegistryEntry( | 308 entries->push_front(new RegistryEntry( |
| 236 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), | 309 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), |
| 237 protocol, string16(ShellUtil::kChromeHTMLProgId).append(suffix))); | 310 protocol, GetBrowserProgId(suffix))); |
| 238 return true; | 311 return true; |
| 239 } | 312 } |
| 240 | 313 |
| 241 // This method returns a list of all the registry entries required to fully | 314 // This method returns a list of all the registry entries required to fully |
| 242 // integrate Chrome with Windows (i.e. StartMenuInternet, Default Programs, | 315 // integrate Chrome with Windows (i.e. StartMenuInternet, Default Programs, |
| 243 // AppPaths, etc.). This entries need to be registered in HKLM prior to Win8. | 316 // AppPaths, etc.). This entries need to be registered in HKLM prior to Win8. |
| 244 static bool GetShellIntegrationEntries(BrowserDistribution* dist, | 317 static bool GetShellIntegrationEntries(BrowserDistribution* dist, |
| 245 const string16& chrome_exe, | 318 const string16& chrome_exe, |
| 246 const string16& suffix, | 319 const string16& suffix, |
| 247 std::list<RegistryEntry*>* entries) { | 320 std::list<RegistryEntry*>* entries) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 dist->GetLongAppDescription())); | 361 dist->GetLongAppDescription())); |
| 289 entries->push_front(new RegistryEntry( | 362 entries->push_front(new RegistryEntry( |
| 290 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 363 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
| 291 entries->push_front(new RegistryEntry( | 364 entries->push_front(new RegistryEntry( |
| 292 capabilities, ShellUtil::kRegApplicationName, | 365 capabilities, ShellUtil::kRegApplicationName, |
| 293 dist->GetAppShortCutName())); | 366 dist->GetAppShortCutName())); |
| 294 | 367 |
| 295 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", | 368 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", |
| 296 L"StartMenuInternet", reg_app_name)); | 369 L"StartMenuInternet", reg_app_name)); |
| 297 | 370 |
| 298 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); | 371 string16 html_prog_id(GetBrowserProgId(suffix)); |
| 299 html_prog_id.append(suffix); | |
| 300 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 372 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
| 301 entries->push_front(new RegistryEntry( | 373 entries->push_front(new RegistryEntry( |
| 302 capabilities + L"\\FileAssociations", | 374 capabilities + L"\\FileAssociations", |
| 303 ShellUtil::kFileAssociations[i], html_prog_id)); | 375 ShellUtil::kFileAssociations[i], html_prog_id)); |
| 304 } | 376 } |
| 305 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; | 377 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; |
| 306 i++) { | 378 i++) { |
| 307 entries->push_front(new RegistryEntry( | 379 entries->push_front(new RegistryEntry( |
| 308 capabilities + L"\\URLAssociations", | 380 capabilities + L"\\URLAssociations", |
| 309 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); | 381 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 return true; | 430 return true; |
| 359 } | 431 } |
| 360 | 432 |
| 361 // This method returns a list of all the user level registry entries that | 433 // This method returns a list of all the user level registry entries that |
| 362 // are needed to make Chromium default browser. | 434 // are needed to make Chromium default browser. |
| 363 static bool GetUserEntries(BrowserDistribution* dist, | 435 static bool GetUserEntries(BrowserDistribution* dist, |
| 364 const string16& chrome_exe, | 436 const string16& chrome_exe, |
| 365 const string16& suffix, | 437 const string16& suffix, |
| 366 std::list<RegistryEntry*>* entries) { | 438 std::list<RegistryEntry*>* entries) { |
| 367 // File extension associations. | 439 // File extension associations. |
| 368 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); | 440 string16 html_prog_id(GetBrowserProgId(suffix)); |
| 369 html_prog_id.append(suffix); | |
| 370 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 441 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
| 371 string16 ext_key(ShellUtil::kRegClasses); | 442 string16 ext_key(ShellUtil::kRegClasses); |
| 372 ext_key.push_back(FilePath::kSeparators[0]); | 443 ext_key.push_back(FilePath::kSeparators[0]); |
| 373 ext_key.append(ShellUtil::kFileAssociations[i]); | 444 ext_key.append(ShellUtil::kFileAssociations[i]); |
| 374 entries->push_front(new RegistryEntry(ext_key, html_prog_id)); | 445 entries->push_front(new RegistryEntry(ext_key, html_prog_id)); |
| 375 } | 446 } |
| 376 | 447 |
| 377 // Protocols associations. | 448 // Protocols associations. |
| 378 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 449 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
| 379 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | 450 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 741 |
| 671 // <root hkey>\Software\Classes\<app_id> | 742 // <root hkey>\Software\Classes\<app_id> |
| 672 string16 key(ShellUtil::kRegClasses); | 743 string16 key(ShellUtil::kRegClasses); |
| 673 key.push_back(FilePath::kSeparators[0]); | 744 key.push_back(FilePath::kSeparators[0]); |
| 674 key.append(app_id); | 745 key.append(app_id); |
| 675 InstallUtil::DeleteRegistryKey(root_key, key); | 746 InstallUtil::DeleteRegistryKey(root_key, key); |
| 676 | 747 |
| 677 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command | 748 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command |
| 678 key = ShellUtil::kRegClasses; | 749 key = ShellUtil::kRegClasses; |
| 679 key.push_back(FilePath::kSeparators[0]); | 750 key.push_back(FilePath::kSeparators[0]); |
| 680 key.append(ShellUtil::kChromeHTMLProgId); | 751 key.append(GetBrowserProgId(installation_suffix)); |
| 681 key.append(installation_suffix); | |
| 682 key.append(ShellUtil::kRegShellOpen); | 752 key.append(ShellUtil::kRegShellOpen); |
| 683 InstallUtil::DeleteRegistryValue(root_key, key, | 753 InstallUtil::DeleteRegistryValue(root_key, key, |
| 684 ShellUtil::kRegDelegateExecute); | 754 ShellUtil::kRegDelegateExecute); |
| 685 } | 755 } |
| 686 } | 756 } |
| 687 | 757 |
| 688 // Returns true if the current install's |chrome_exe| has been registered with | 758 // Returns true if the current install's |chrome_exe| has been registered with |
| 689 // |suffix|. | 759 // |suffix|. |
| 690 // |confirmation_level| is the level of verification desired as described in | 760 // |confirmation_level| is the level of verification desired as described in |
| 691 // the RegistrationConfirmationLevel enum above. | 761 // the RegistrationConfirmationLevel enum above. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 // Assert that |reg_key| points to |chrome_exe| in HKLM. | 810 // Assert that |reg_key| points to |chrome_exe| in HKLM. |
| 741 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); | 811 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); |
| 742 string16 hklm_value; | 812 string16 hklm_value; |
| 743 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { | 813 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { |
| 744 return InstallUtil::ProgramCompare( | 814 return InstallUtil::ProgramCompare( |
| 745 FilePath(chrome_exe)).Evaluate(hklm_value); | 815 FilePath(chrome_exe)).Evaluate(hklm_value); |
| 746 } | 816 } |
| 747 return false; | 817 return false; |
| 748 } | 818 } |
| 749 | 819 |
| 750 // Sets |suffix| to this user's username preceded by a dot. This suffix is then | 820 // Sets |suffix| to a 27 characters string that is specific to this user on |
| 751 // meant to be added to all registration that may conflict with another | 821 // this machine, on user-level installs, preferably. |
| 752 // user-level Chrome install. | |
| 753 // Returns true unless the OS call to retrieve the username fails. | |
| 754 bool GetUserSpecificRegistrySuffix(string16* suffix) { | |
| 755 wchar_t user_name[256]; | |
| 756 DWORD size = arraysize(user_name); | |
| 757 if (::GetUserName(user_name, &size) == 0 || size < 1) { | |
| 758 PLOG(DFATAL) << "GetUserName failed"; | |
| 759 return false; | |
| 760 } | |
| 761 suffix->reserve(size); | |
| 762 suffix->assign(1, L'.'); | |
| 763 suffix->append(user_name, size - 1); | |
| 764 return true; | |
| 765 } | |
| 766 | |
| 767 // Sets |suffix| to the current user's username, preceded by a dot, on | |
| 768 // user-level installs. | |
| 769 // To support old-style user-level installs however, |suffix| is cleared if | 822 // To support old-style user-level installs however, |suffix| is cleared if |
| 770 // the user currently owns the non-suffixed HKLM registrations. | 823 // the user currently owns the non-suffixed HKLM registrations. |
| 771 // |suffix| is also cleared on system-level installs. | 824 // |suffix| can also be set to the user's username if the current install |
| 825 // is suffixed as per the old-style registrations. |
| 826 // |suffix| is cleared on system-level installs. |
| 772 // |suffix| should then be appended to all Chrome properties that may conflict | 827 // |suffix| should then be appended to all Chrome properties that may conflict |
| 773 // with other Chrome user-level installs. | 828 // with other Chrome user-level installs. |
| 774 // Returns true unless one of the underlying calls fails. | 829 // Returns true unless one of the underlying calls fails. |
| 775 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, | 830 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, |
| 776 const string16& chrome_exe, | 831 const string16& chrome_exe, |
| 777 string16* suffix) { | 832 string16* suffix) { |
| 778 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || | 833 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 779 QuickIsChromeRegistered(dist, chrome_exe, string16(), | 834 QuickIsChromeRegistered(dist, chrome_exe, string16(), |
| 780 CONFIRM_SHELL_REGISTRATION)) { | 835 CONFIRM_SHELL_REGISTRATION)) { |
| 781 // No suffix on system-level installs and user-level installs already | 836 // No suffix on system-level installs and user-level installs already |
| 782 // registered with no suffix. | 837 // registered with no suffix. |
| 783 suffix->clear(); | 838 suffix->clear(); |
| 784 return true; | 839 return true; |
| 785 } else { | |
| 786 return GetUserSpecificRegistrySuffix(suffix); | |
| 787 } | 840 } |
| 841 |
| 842 string16 old_suffix; |
| 843 // Get the |old_suffix| for the check below. |
| 844 if (!GetOldUserSpecificRegistrySuffix(&old_suffix)) { |
| 845 NOTREACHED(); |
| 846 return false; |
| 847 } |
| 848 if (QuickIsChromeRegistered(dist, chrome_exe, old_suffix, |
| 849 CONFIRM_SHELL_REGISTRATION)) { |
| 850 // Username suffix for installs that are suffixed as per the old-style. |
| 851 suffix->assign(old_suffix); |
| 852 return true; |
| 853 } |
| 854 |
| 855 return GetNewUserSpecificRegistrySuffix(suffix); |
| 788 } | 856 } |
| 789 | 857 |
| 790 // Returns the root registry key (HKLM or HKCU) into which shell integration | 858 // Returns the root registry key (HKLM or HKCU) into which shell integration |
| 791 // registration for default protocols must be placed. As of Windows 8 everything | 859 // registration for default protocols must be placed. As of Windows 8 everything |
| 792 // can go in HKCU for per-user installs. | 860 // can go in HKCU for per-user installs. |
| 793 HKEY DetermineShellIntegrationRoot(bool is_per_user) { | 861 HKEY DetermineShellIntegrationRoot(bool is_per_user) { |
| 794 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? | 862 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? |
| 795 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 863 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 796 } | 864 } |
| 797 | 865 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS && | 1121 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS && |
| 1054 !command.empty()) { | 1122 !command.empty()) { |
| 1055 (*browsers)[name] = command; | 1123 (*browsers)[name] = command; |
| 1056 } | 1124 } |
| 1057 } | 1125 } |
| 1058 } | 1126 } |
| 1059 } | 1127 } |
| 1060 | 1128 |
| 1061 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, | 1129 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, |
| 1062 const string16& chrome_exe) { | 1130 const string16& chrome_exe) { |
| 1131 // This method is somewhat the opposite of GetInstallationSpecificSuffix(). |
| 1132 // In this case we are not trying to determine the current suffix for the |
| 1133 // upcoming installation (i.e. not trying to stick to a currently bad |
| 1134 // registration style if one is present). |
| 1135 // Here we want to determine which suffix we should use at run-time. |
| 1136 // In order of preference, we prefer (for user-level installs): |
| 1137 // 1) Base 32 encoding of the md5 hash of the username (new-style). |
| 1138 // 2) Username (old-style). |
| 1139 // 3) Unsuffixed (even worse). |
| 1063 string16 tested_suffix; | 1140 string16 tested_suffix; |
| 1064 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || | 1141 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 1065 !GetUserSpecificRegistrySuffix(&tested_suffix) || | 1142 ((!GetNewUserSpecificRegistrySuffix(&tested_suffix) || |
| 1066 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, | 1143 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 1067 CONFIRM_PROGID_REGISTRATION)) { | 1144 CONFIRM_PROGID_REGISTRATION)) && |
| 1145 (!GetOldUserSpecificRegistrySuffix(&tested_suffix) || |
| 1146 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 1147 CONFIRM_PROGID_REGISTRATION)))) { |
| 1148 // The current installation's suffix should only be empty on system-level |
| 1149 // installs and unsuffixed (old-style) user-level installs. |
| 1150 DCHECK(!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 1151 QuickIsChromeRegistered(dist, chrome_exe, string16(), |
| 1152 CONFIRM_PROGID_REGISTRATION)); |
| 1068 return string16(); | 1153 return string16(); |
| 1069 } | 1154 } |
| 1070 return tested_suffix; | 1155 return tested_suffix; |
| 1071 } | 1156 } |
| 1072 | 1157 |
| 1073 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, | 1158 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, |
| 1074 const string16& chrome_exe) { | 1159 const string16& chrome_exe) { |
| 1075 string16 app_name = dist->GetBaseAppName(); | 1160 string16 app_name = dist->GetBaseAppName(); |
| 1076 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); | 1161 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); |
| 1077 return app_name; | 1162 return app_name; |
| 1078 } | 1163 } |
| 1079 | 1164 |
| 1080 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist, | 1165 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist, |
| 1081 const string16& chrome_exe) { | 1166 const string16& chrome_exe) { |
| 1082 string16 app_id(dist->GetBaseAppId()); | 1167 string16 app_id(dist->GetBaseAppId()); |
| 1083 string16 suffix; | 1168 string16 suffix; |
| 1084 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1169 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && |
| 1085 !GetUserSpecificRegistrySuffix(&suffix)) { | 1170 !GetNewUserSpecificRegistrySuffix(&suffix)) { |
| 1086 NOTREACHED(); | 1171 NOTREACHED(); |
| 1087 } | 1172 } |
| 1088 // There is only one component (i.e. the suffixed appid) in this case, but it | 1173 // There is only one component (i.e. the suffixed appid) in this case, but it |
| 1089 // is still necessary to go through the appid constructor to make sure the | 1174 // is still necessary to go through the appid constructor to make sure the |
| 1090 // returned appid is truncated if necessary. | 1175 // returned appid is truncated if necessary. |
| 1091 std::vector<string16> components(1, app_id.append(suffix)); | 1176 std::vector<string16> components(1, app_id.append(suffix)); |
| 1092 return BuildAppModelId(components); | 1177 return BuildAppModelId(components); |
| 1093 } | 1178 } |
| 1094 | 1179 |
| 1095 string16 ShellUtil::BuildAppModelId( | 1180 string16 ShellUtil::BuildAppModelId( |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 chrome_exe.c_str(), | 1598 chrome_exe.c_str(), |
| 1514 shortcut.c_str(), | 1599 shortcut.c_str(), |
| 1515 chrome_path.value().c_str(), | 1600 chrome_path.value().c_str(), |
| 1516 arguments.c_str(), | 1601 arguments.c_str(), |
| 1517 description.c_str(), | 1602 description.c_str(), |
| 1518 icon_path.c_str(), | 1603 icon_path.c_str(), |
| 1519 icon_index, | 1604 icon_index, |
| 1520 app_id.c_str(), | 1605 app_id.c_str(), |
| 1521 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1606 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
| 1522 } | 1607 } |
| 1608 |
| 1609 string16 ShellUtil::MD5DigestToBase32(const base::MD5Digest& digest) { |
| 1610 COMPILE_ASSERT(sizeof(base::MD5Digest) == 16, size_of_MD5_not_as_expected_); |
| 1611 string16 encoding(ByteArrayToBase32(digest.a, 16)); |
| 1612 // This must always remain 26 characters as callers which write to solid |
| 1613 // state depend on this. |
| 1614 DCHECK_EQ(encoding.length(), 26U); |
| 1615 return encoding; |
| 1616 } |
| 1617 |
| 1618 string16 ShellUtil::ByteArrayToBase32(const unsigned char bytes[], int size) { |
| 1619 static char const kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; |
| 1620 |
| 1621 // Eliminate special cases first. |
| 1622 if (size == 0) { |
| 1623 return string16(); |
| 1624 } else if (size == 1) { |
| 1625 string16 ret; |
| 1626 ret.push_back(kEncoding[(bytes[0] & 0xf8) >> 3]); |
| 1627 ret.push_back(kEncoding[(bytes[0] & 0x07) << 2]); |
| 1628 return ret; |
| 1629 } |
| 1630 |
| 1631 // Overestimate the number of bits in the string by 4 so that dividing by 5 |
| 1632 // is the equivalent of rounding up the actual number of bits divided by 5. |
| 1633 const int kEncodedLength = (size * 8 + 4) / 5; |
| 1634 |
| 1635 string16 ret; |
| 1636 ret.reserve(kEncodedLength); |
| 1637 |
| 1638 // A bit stream which will be read from the left and appended to from the |
| 1639 // right as it's emptied. |
| 1640 uint16 bit_stream = (bytes[0] << 8) + bytes[1]; |
| 1641 int next_byte_index = 2; |
| 1642 int free_bits = 0; |
| 1643 while (free_bits < 16) { |
| 1644 // Extract the 5 leftmost bits in the stream |
| 1645 ret.push_back(kEncoding[(bit_stream & 0xf800) >> 11]); |
| 1646 bit_stream <<= 5; |
| 1647 free_bits += 5; |
| 1648 |
| 1649 // If there is enough room in the bit stream, inject another byte (if there |
| 1650 // are any left...). |
| 1651 if (free_bits >= 8 && next_byte_index < size) { |
| 1652 free_bits -= 8; |
| 1653 bit_stream += bytes[next_byte_index++] << free_bits; |
| 1654 } |
| 1655 } |
| 1656 |
| 1657 DCHECK_EQ(ret.length(), static_cast<size_t>(kEncodedLength)); |
| 1658 return ret; |
| 1659 } |
| OLD | NEW |