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

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: addressed gregs 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 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 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 1133 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
1078 int shell_change, 1134 int shell_change,
1079 const string16& chrome_exe, 1135 const string16& chrome_exe,
1080 bool elevate_if_not_admin) { 1136 bool elevate_if_not_admin) {
1081 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); 1137 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin());
1082 1138
1083 if (!dist->CanSetAsDefault()) 1139 if (!dist->CanSetAsDefault())
1084 return false; 1140 return false;
1085 1141
1086 // Windows 8 does not permit making a browser default just like that. 1142 // Windows 8 does not permit making a browser default just like that.
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 } 1481 }
1426 1482
1427 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, 1483 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist,
1428 const string16& chrome_exe, 1484 const string16& chrome_exe,
1429 const string16& shortcut, 1485 const string16& shortcut,
1430 const string16& arguments, 1486 const string16& arguments,
1431 const string16& description, 1487 const string16& description,
1432 const string16& icon_path, 1488 const string16& icon_path,
1433 int icon_index, 1489 int icon_index,
1434 uint32 options) { 1490 uint32 options) {
1435 string16 chrome_path = FilePath(chrome_exe).DirName().value(); 1491 const FilePath chrome_path(FilePath(chrome_exe).DirName());
1436 1492
1437 FilePath prefs_path(chrome_path); 1493 installer::MasterPreferences prefs(
1438 prefs_path = prefs_path.AppendASCII(installer::kDefaultMasterPrefs); 1494 chrome_path.AppendASCII(installer::kDefaultMasterPrefs));
1439 installer::MasterPreferences prefs(prefs_path);
1440 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { 1495 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) {
1441 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, 1496 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex,
1442 &icon_index); 1497 &icon_index);
1443 } 1498 }
1444 1499
1500 const string16 app_id(GetBrowserModelId(dist, chrome_exe));
1501
1445 return file_util::CreateOrUpdateShortcutLink( 1502 return file_util::CreateOrUpdateShortcutLink(
1446 chrome_exe.c_str(), 1503 chrome_exe.c_str(),
1447 shortcut.c_str(), 1504 shortcut.c_str(),
1448 chrome_path.c_str(), 1505 chrome_path.value().c_str(),
1449 arguments.c_str(), 1506 arguments.c_str(),
1450 description.c_str(), 1507 description.c_str(),
1451 icon_path.c_str(), 1508 icon_path.c_str(),
1452 icon_index, 1509 icon_index,
1453 dist->GetBrowserAppId().c_str(), 1510 app_id.c_str(),
1454 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1511 ConvertShellUtilShortcutOptionsToFileUtil(options));
1455 } 1512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698