Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 10617002: Use a better registration suffix that will always be unique while respecting the MSDN rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address gregs initial comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 PLOG(DFATAL) << "GetUserName failed";
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 PLOG(DFATAL) << "GetUserName failed";
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
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
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
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
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
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
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 if (!GetOldUserSpecificRegistrySuffix(&old_suffix)) {
robertshield 2012/06/22 19:20:22 add a comment saying that this gets what the old s
gab 2012/06/22 20:32:12 Done.
844 return false;
robertshield 2012/06/22 19:20:22 Add a NOTREACHED() right before this.
gab 2012/06/22 20:32:12 Done.
845 } else if (QuickIsChromeRegistered(dist, chrome_exe, old_suffix,
robertshield 2012/06/22 19:20:22 don't make this an else, make it a separate if sta
gab 2012/06/22 20:32:12 Done.
846 CONFIRM_SHELL_REGISTRATION)) {
847 // Username suffix for installs that are suffixed as per the old-style.
848 suffix->assign(old_suffix);
849 return true;
850 }
851
852 return GetNewUserSpecificRegistrySuffix(suffix);
788 } 853 }
789 854
790 // Returns the root registry key (HKLM or HKCU) into which shell integration 855 // 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 856 // registration for default protocols must be placed. As of Windows 8 everything
792 // can go in HKCU for per-user installs. 857 // can go in HKCU for per-user installs.
793 HKEY DetermineShellIntegrationRoot(bool is_per_user) { 858 HKEY DetermineShellIntegrationRoot(bool is_per_user) {
794 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? 859 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ?
795 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 860 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
796 } 861 }
797 862
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS && 1118 key.ReadValue(kReinstallCommand, &command) == ERROR_SUCCESS &&
1054 !command.empty()) { 1119 !command.empty()) {
1055 (*browsers)[name] = command; 1120 (*browsers)[name] = command;
1056 } 1121 }
1057 } 1122 }
1058 } 1123 }
1059 } 1124 }
1060 1125
1061 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, 1126 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist,
1062 const string16& chrome_exe) { 1127 const string16& chrome_exe) {
1128 // This method is somewhat the opposite of GetInstallationSpecificSuffix().
1129 // In this case we are not trying to determine the current suffix for the
1130 // upcoming installation (i.e. not trying to stick to a currently bad
1131 // registration style if one is present).
1132 // Here we want to determine which suffix we should use at run-time.
1133 // In order of preference, we prefer (for user-level installs):
1134 // 1) Base 32 encoding of the md5 hash of the username (new-style).
1135 // 2) Username (old-style).
1136 // 3) Unsuffixed (even worst).
robertshield 2012/06/22 19:20:22 worst -> worse
gab 2012/06/22 20:32:12 Done.
1063 string16 tested_suffix; 1137 string16 tested_suffix;
1064 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || 1138 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ||
1065 !GetUserSpecificRegistrySuffix(&tested_suffix) || 1139 ((!GetNewUserSpecificRegistrySuffix(&tested_suffix) ||
1066 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, 1140 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix,
1067 CONFIRM_PROGID_REGISTRATION)) { 1141 CONFIRM_PROGID_REGISTRATION)) &&
1142 (!GetOldUserSpecificRegistrySuffix(&tested_suffix) ||
1143 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix,
1144 CONFIRM_PROGID_REGISTRATION)))) {
1145 // The current installation's suffix should only be empty on system-level
1146 // installs and unsuffixed (old-style) user-level installs.
1147 DCHECK(!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ||
1148 QuickIsChromeRegistered(dist, chrome_exe, string16(),
1149 CONFIRM_PROGID_REGISTRATION));
1068 return string16(); 1150 return string16();
1069 } 1151 }
1070 return tested_suffix; 1152 return tested_suffix;
1071 } 1153 }
1072 1154
1073 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, 1155 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist,
1074 const string16& chrome_exe) { 1156 const string16& chrome_exe) {
1075 string16 app_name = dist->GetBaseAppName(); 1157 string16 app_name = dist->GetBaseAppName();
1076 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); 1158 app_name += GetCurrentInstallationSuffix(dist, chrome_exe);
1077 return app_name; 1159 return app_name;
1078 } 1160 }
1079 1161
1080 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist, 1162 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist,
1081 const string16& chrome_exe) { 1163 const string16& chrome_exe) {
1082 string16 app_id(dist->GetBaseAppId()); 1164 string16 app_id(dist->GetBaseAppId());
1083 string16 suffix; 1165 string16 suffix;
1084 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && 1166 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) &&
1085 !GetUserSpecificRegistrySuffix(&suffix)) { 1167 !GetNewUserSpecificRegistrySuffix(&suffix)) {
1086 NOTREACHED(); 1168 NOTREACHED();
1087 } 1169 }
1088 // There is only one component (i.e. the suffixed appid) in this case, but it 1170 // 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 1171 // is still necessary to go through the appid constructor to make sure the
1090 // returned appid is truncated if necessary. 1172 // returned appid is truncated if necessary.
1091 std::vector<string16> components(1, app_id.append(suffix)); 1173 std::vector<string16> components(1, app_id.append(suffix));
1092 return BuildAppModelId(components); 1174 return BuildAppModelId(components);
1093 } 1175 }
1094 1176
1095 string16 ShellUtil::BuildAppModelId( 1177 string16 ShellUtil::BuildAppModelId(
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 chrome_exe.c_str(), 1595 chrome_exe.c_str(),
1514 shortcut.c_str(), 1596 shortcut.c_str(),
1515 chrome_path.value().c_str(), 1597 chrome_path.value().c_str(),
1516 arguments.c_str(), 1598 arguments.c_str(),
1517 description.c_str(), 1599 description.c_str(),
1518 icon_path.c_str(), 1600 icon_path.c_str(),
1519 icon_index, 1601 icon_index,
1520 app_id.c_str(), 1602 app_id.c_str(),
1521 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1603 ConvertShellUtilShortcutOptionsToFileUtil(options));
1522 } 1604 }
1605
1606 string16 ShellUtil::MD5DigestToBase32(const base::MD5Digest& digest) {
1607 static char const kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
1608 // An MD5 digest is 16 bytes, the base32 encoding should thus always be 26
1609 // characters.
1610 const int kEncodedLength = 26;
1611
1612 string16 ret;
1613 ret.reserve(kEncodedLength);
1614
1615 // A bit stream which will be read from the left and appended to from the
1616 // right as it's emptied.
1617 uint16 bit_stream = (digest.a[0] << 8) + digest.a[1];
1618 int next_byte_index = 2;
1619 int free_bits = 0;
1620 while (free_bits < 16) {
1621 // Extract the 5 leftmost bits in the stream
1622 ret.push_back(kEncoding[(bit_stream & 0xf800) >> 11]);
1623 bit_stream <<= 5;
1624 free_bits += 5;
1625
1626 // If there is enough room in the bit stream, inject another byte (if there
1627 // are any left...).
1628 if (free_bits >= 8 && next_byte_index < sizeof(base::MD5Digest)) {
1629 free_bits -= 8;
1630 bit_stream += digest.a[next_byte_index++] << free_bits;
1631 }
1632 }
1633
1634 DCHECK_EQ(ret.length(), static_cast<size_t>(kEncodedLength));
1635 return ret;
1636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698