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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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::GetChromiumModelId(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 Loading... | |
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::GetChromiumModelId(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 Loading... | |
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::GetChromiumModelId(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; | |
grt (UTC plus 2)
2012/06/18 19:45:08
you can construct and populate the vector in one f
gab
2012/06/18 21:52:43
Nice! I'd looked for (and obviously didn't find) a
| |
1089 components.push_back(app_id.append(suffix)); | |
1090 return ConstructAppModelId(components); | |
1091 } | |
1092 | |
1093 string16 ShellUtil::ConstructAppModelId( | |
1094 const std::vector<string16>& components) { | |
1095 // Find the maximum numbers of characters allowed in each component | |
1096 // (accounting for the dots added between each component). | |
1097 const size_t available_chars = | |
1098 chrome::kMaxAppModelIdLength - (components.size() - 1); | |
1099 const size_t max_component_length = available_chars / components.size(); | |
1100 | |
1101 // |max_component_length| should be at least 2; otherwise the truncation logic | |
1102 // below breaks. | |
grt (UTC plus 2)
2012/06/18 19:45:08
can you add something to the non-debug case to not
gab
2012/06/18 21:52:43
Done.
| |
1103 DCHECK_GE(max_component_length, 2U); | |
1104 | |
1105 string16 app_id; | |
grt (UTC plus 2)
2012/06/18 19:45:08
just after this line, add:
app_id.reserve(chrome::
gab
2012/06/18 21:52:43
Done.
| |
1106 for (std::vector<string16>::const_iterator it = components.begin(); | |
1107 it != components.end(); ++it) { | |
1108 if (it != components.begin()) | |
1109 app_id.push_back(L'.'); | |
1110 | |
1111 const string16& component = *it; | |
1112 if (component.length() > max_component_length) { | |
1113 // Append a truncated version of this component. Truncate in the middle | |
grt (UTC plus 2)
2012/06/18 19:45:08
"to truncate" means to chop off the end. i think
gab
2012/06/18 21:52:43
http://www.thefreedictionary.com/truncate says "sh
| |
1114 // to try to avoid losing the unique parts of this component (which are | |
1115 // usually at the beginning or end for things like usernames and paths). | |
1116 app_id.append(component.substr(0, max_component_length / 2)); | |
grt (UTC plus 2)
2012/06/18 19:45:08
app_id.append(component, 0, max_component_length /
gab
2012/06/18 21:52:43
Done.
| |
1117 app_id.append( | |
grt (UTC plus 2)
2012/06/18 19:45:08
app_id.append(component, component.length() - ((ma
gab
2012/06/18 21:52:43
Done.
| |
1118 component.substr(component.length() - (max_component_length / 2))); | |
1119 } else { | |
1120 app_id.append(component); | |
1121 } | |
1122 } | |
1123 return app_id; | |
1124 } | |
1125 | |
1077 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 1126 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
1078 int shell_change, | 1127 int shell_change, |
1079 const string16& chrome_exe, | 1128 const string16& chrome_exe, |
1080 bool elevate_if_not_admin) { | 1129 bool elevate_if_not_admin) { |
1081 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); | 1130 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); |
1082 | 1131 |
1083 if (!dist->CanSetAsDefault()) | 1132 if (!dist->CanSetAsDefault()) |
1084 return false; | 1133 return false; |
1085 | 1134 |
1086 // Windows 8 does not permit making a browser default just like that. | 1135 // Windows 8 does not permit making a browser default just like that. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1425 } | 1474 } |
1426 | 1475 |
1427 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, | 1476 bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, |
1428 const string16& chrome_exe, | 1477 const string16& chrome_exe, |
1429 const string16& shortcut, | 1478 const string16& shortcut, |
1430 const string16& arguments, | 1479 const string16& arguments, |
1431 const string16& description, | 1480 const string16& description, |
1432 const string16& icon_path, | 1481 const string16& icon_path, |
1433 int icon_index, | 1482 int icon_index, |
1434 uint32 options) { | 1483 uint32 options) { |
1435 string16 chrome_path = FilePath(chrome_exe).DirName().value(); | 1484 const FilePath chrome_path(FilePath(chrome_exe).DirName()); |
1436 | 1485 |
1437 FilePath prefs_path(chrome_path); | 1486 installer::MasterPreferences prefs( |
1438 prefs_path = prefs_path.AppendASCII(installer::kDefaultMasterPrefs); | 1487 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); |
1439 installer::MasterPreferences prefs(prefs_path); | |
1440 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { | 1488 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { |
1441 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | 1489 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, |
1442 &icon_index); | 1490 &icon_index); |
1443 } | 1491 } |
1444 | 1492 |
1493 const string16 app_id(GetChromiumModelId(dist, chrome_exe)); | |
1494 | |
1445 return file_util::CreateOrUpdateShortcutLink( | 1495 return file_util::CreateOrUpdateShortcutLink( |
1446 chrome_exe.c_str(), | 1496 chrome_exe.c_str(), |
1447 shortcut.c_str(), | 1497 shortcut.c_str(), |
1448 chrome_path.c_str(), | 1498 chrome_path.value().c_str(), |
1449 arguments.c_str(), | 1499 arguments.c_str(), |
1450 description.c_str(), | 1500 description.c_str(), |
1451 icon_path.c_str(), | 1501 icon_path.c_str(), |
1452 icon_index, | 1502 icon_index, |
1453 dist->GetBrowserAppId().c_str(), | 1503 app_id.c_str(), |
1454 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1504 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
1455 } | 1505 } |
OLD | NEW |