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

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

Issue 10542031: Suffix Chrome's appid on user-level installs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to r142814 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
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // HKLM for system-level installs. 129 // HKLM for system-level installs.
130 static bool GetProgIdEntries(BrowserDistribution* dist, 130 static bool GetProgIdEntries(BrowserDistribution* dist,
131 const string16& chrome_exe, 131 const string16& chrome_exe,
132 const string16& suffix, 132 const string16& suffix,
133 std::list<RegistryEntry*>* entries) { 133 std::list<RegistryEntry*>* entries) {
134 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); 134 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe));
135 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); 135 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe));
136 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); 136 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe));
137 // For user-level installs: entries for the app id and DelegateExecute verb 137 // For user-level installs: entries for the app id and DelegateExecute verb
138 // handler will be in HKCU; thus we do not need a suffix on those entries. 138 // handler will be in HKCU; thus we do not need a suffix on those entries.
139 string16 app_id(dist->GetBrowserAppId()); 139 string16 app_id(ShellUtil::GetBrowserModelId(dist, chrome_exe));
140 string16 delegate_guid; 140 string16 delegate_guid;
141 // TODO(grt): remove HasDelegateExecuteHandler when the exe is ever-present; 141 // TODO(grt): remove HasDelegateExecuteHandler when the exe is ever-present;
142 // see also install_worker.cc's AddDelegateExecuteWorkItems. 142 // see also install_worker.cc's AddDelegateExecuteWorkItems.
143 bool set_delegate_execute = 143 bool set_delegate_execute =
144 IsChromeMetroSupported() && 144 IsChromeMetroSupported() &&
145 dist->GetDelegateExecuteHandlerData(&delegate_guid, NULL, NULL, NULL) && 145 dist->GetDelegateExecuteHandlerData(&delegate_guid, NULL, NULL, NULL) &&
146 InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe); 146 InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe);
147 147
148 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8. 148 // DelegateExecute ProgId. Needed for Chrome Metro in Windows 8.
149 if (set_delegate_execute) { 149 if (set_delegate_execute) {
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) || 656 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) ||
657 !IsChromeMetroSupported())) { 657 !IsChromeMetroSupported())) {
658 // There's no need to rollback, so forgo the usual work item lists and just 658 // There's no need to rollback, so forgo the usual work item lists and just
659 // remove the values from the registry. 659 // remove the values from the registry.
660 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? 660 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ?
661 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 661 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
662 // Use the current installation's suffix, not the about-to-be-installed 662 // Use the current installation's suffix, not the about-to-be-installed
663 // suffix. 663 // suffix.
664 const string16 installation_suffix( 664 const string16 installation_suffix(
665 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe)); 665 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe));
666 const string16 app_id(dist->GetBrowserAppId()); 666 const string16 app_id(ShellUtil::GetBrowserModelId(dist, chrome_exe));
667 667
668 // <root hkey>\Software\Classes\<app_id> 668 // <root hkey>\Software\Classes\<app_id>
669 string16 key(ShellUtil::kRegClasses); 669 string16 key(ShellUtil::kRegClasses);
670 key.push_back(FilePath::kSeparators[0]); 670 key.push_back(FilePath::kSeparators[0]);
671 key.append(app_id); 671 key.append(app_id);
672 InstallUtil::DeleteRegistryKey(root_key, key); 672 InstallUtil::DeleteRegistryKey(root_key, key);
673 673
674 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command 674 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command
675 key = ShellUtil::kRegClasses; 675 key = ShellUtil::kRegClasses;
676 key.push_back(FilePath::kSeparators[0]); 676 key.push_back(FilePath::kSeparators[0]);
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 return tested_suffix; 1067 return tested_suffix;
1068 } 1068 }
1069 1069
1070 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist, 1070 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist,
1071 const string16& chrome_exe) { 1071 const string16& chrome_exe) {
1072 string16 app_name = dist->GetBaseAppName(); 1072 string16 app_name = dist->GetBaseAppName();
1073 app_name += GetCurrentInstallationSuffix(dist, chrome_exe); 1073 app_name += GetCurrentInstallationSuffix(dist, chrome_exe);
1074 return app_name; 1074 return app_name;
1075 } 1075 }
1076 1076
1077 string16 ShellUtil::GetBrowserModelId(BrowserDistribution* dist,
1078 const string16& chrome_exe) {
1079 string16 app_id(dist->GetBaseAppId());
1080 string16 suffix;
1081 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) &&
1082 !GetUserSpecificRegistrySuffix(&suffix)) {
1083 NOTREACHED();
1084 }
1085 // There is only one component (i.e. the suffixed appid) in this case, but it
1086 // is still necessary to go through the appid constructor to make sure the
1087 // returned appid is truncated if necessary.
1088 std::vector<string16> components(1, app_id.append(suffix));
1089 return BuildAppModelId(components);
1090 }
1091
1092 string16 ShellUtil::BuildAppModelId(
1093 const std::vector<string16>& components) {
1094 DCHECK_GT(components.size(), 0U);
1095
1096 // Find the maximum numbers of characters allowed in each component
1097 // (accounting for the dots added between each component).
1098 const size_t available_chars =
1099 installer::kMaxAppModelIdLength - (components.size() - 1);
1100 const size_t max_component_length = available_chars / components.size();
1101
1102 // |max_component_length| should be at least 2; otherwise the truncation logic
1103 // below breaks.
1104 if (max_component_length < 2U) {
1105 NOTREACHED();
1106 return (*components.begin()).substr(0, installer::kMaxAppModelIdLength);
1107 }
1108
1109 string16 app_id;
1110 app_id.reserve(installer::kMaxAppModelIdLength);
1111 for (std::vector<string16>::const_iterator it = components.begin();
1112 it != components.end(); ++it) {
1113 if (it != components.begin())
1114 app_id.push_back(L'.');
1115
1116 const string16& component = *it;
1117 DCHECK(!component.empty());
1118 if (component.length() > max_component_length) {
1119 // Append a shortened version of this component. Cut in the middle to try
1120 // to avoid losing the unique parts of this component (which are usually
1121 // at the beginning or end for things like usernames and paths).
1122 app_id.append(component.c_str(), 0, max_component_length / 2);
1123 app_id.append(component.c_str(),
1124 component.length() - ((max_component_length + 1) / 2),
1125 string16::npos);
1126 } else {
1127 app_id.append(component);
1128 }
1129 }
1130 return app_id;
1131 }
1132
1077 // static 1133 // static
1078 bool ShellUtil::CanMakeChromeDefaultUnattended() { 1134 bool ShellUtil::CanMakeChromeDefaultUnattended() {
1079 return base::win::GetVersion() < base::win::VERSION_WIN8; 1135 return base::win::GetVersion() < base::win::VERSION_WIN8;
1080 } 1136 }
1081 1137
1082 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 1138 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
1083 int shell_change, 1139 int shell_change,
1084 const string16& chrome_exe, 1140 const string16& chrome_exe,
1085 bool elevate_if_not_admin) { 1141 bool elevate_if_not_admin) {
1086 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); 1142 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin());
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 } 1486 }
1431 1487
1432 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, 1488 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist,
1433 const string16& chrome_exe, 1489 const string16& chrome_exe,
1434 const string16& shortcut, 1490 const string16& shortcut,
1435 const string16& arguments, 1491 const string16& arguments,
1436 const string16& description, 1492 const string16& description,
1437 const string16& icon_path, 1493 const string16& icon_path,
1438 int icon_index, 1494 int icon_index,
1439 uint32 options) { 1495 uint32 options) {
1440 string16 chrome_path = FilePath(chrome_exe).DirName().value(); 1496 const FilePath chrome_path(FilePath(chrome_exe).DirName());
1441 1497
1442 FilePath prefs_path(chrome_path); 1498 installer::MasterPreferences prefs(
1443 prefs_path = prefs_path.AppendASCII(installer::kDefaultMasterPrefs); 1499 chrome_path.AppendASCII(installer::kDefaultMasterPrefs));
1444 installer::MasterPreferences prefs(prefs_path);
1445 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { 1500 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) {
1446 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, 1501 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex,
1447 &icon_index); 1502 &icon_index);
1448 } 1503 }
1449 1504
1505 const string16 app_id(GetBrowserModelId(dist, chrome_exe));
1506
1450 return file_util::CreateOrUpdateShortcutLink( 1507 return file_util::CreateOrUpdateShortcutLink(
1451 chrome_exe.c_str(), 1508 chrome_exe.c_str(),
1452 shortcut.c_str(), 1509 shortcut.c_str(),
1453 chrome_path.c_str(), 1510 chrome_path.value().c_str(),
1454 arguments.c_str(), 1511 arguments.c_str(),
1455 description.c_str(), 1512 description.c_str(),
1456 icon_path.c_str(), 1513 icon_path.c_str(),
1457 icon_index, 1514 icon_index,
1458 dist->GetBrowserAppId().c_str(), 1515 app_id.c_str(),
1459 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1516 ConvertShellUtilShortcutOptionsToFileUtil(options));
1460 } 1517 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698