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

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

Issue 10446111: Abstract suffixing logic away from GetApplicationName (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2012 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // speaking, we should use the name of the executable (e.g., "chrome.exe"), 86 // speaking, we should use the name of the executable (e.g., "chrome.exe"),
87 // but that ship has sailed. The cost of switching now is re-prompting users 87 // but that ship has sailed. The cost of switching now is re-prompting users
88 // to make Chrome their default browser, which isn't polite. |suffix| is the 88 // to make Chrome their default browser, which isn't polite. |suffix| is the
89 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix 89 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix
90 // in shell_util.h for details. 90 // in shell_util.h for details.
91 static string16 GetBrowserClientKey(BrowserDistribution* dist, 91 static string16 GetBrowserClientKey(BrowserDistribution* dist,
92 const string16& suffix) { 92 const string16& suffix) {
93 DCHECK(suffix.empty() || suffix[0] == L'.'); 93 DCHECK(suffix.empty() || suffix[0] == L'.');
94 return string16(ShellUtil::kRegStartMenuInternet) 94 return string16(ShellUtil::kRegStartMenuInternet)
95 .append(1, L'\\') 95 .append(1, L'\\')
96 .append(dist->GetApplicationName()) 96 .append(dist->GetBaseAppName())
97 .append(suffix); 97 .append(suffix);
98 } 98 }
99 99
100 // Returns the Windows Default Programs capabilities key for Chrome. For 100 // Returns the Windows Default Programs capabilities key for Chrome. For
101 // example: 101 // example:
102 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". 102 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities".
103 static string16 GetCapabilitiesKey(BrowserDistribution* dist, 103 static string16 GetCapabilitiesKey(BrowserDistribution* dist,
104 const string16& suffix) { 104 const string16& suffix) {
105 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); 105 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities");
106 } 106 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 string16 chrome_application(chrome_html_prog_id + 190 string16 chrome_application(chrome_html_prog_id +
191 ShellUtil::kRegApplication); 191 ShellUtil::kRegApplication);
192 entries->push_front(new RegistryEntry( 192 entries->push_front(new RegistryEntry(
193 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); 193 chrome_application, ShellUtil::kRegAppUserModelId, app_id));
194 entries->push_front(new RegistryEntry( 194 entries->push_front(new RegistryEntry(
195 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); 195 chrome_application, ShellUtil::kRegApplicationIcon, icon_path));
196 // TODO(grt): http://crbug.com/75152 Write a reference to a localized 196 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
197 // resource for name, description, and company. 197 // resource for name, description, and company.
198 entries->push_front(new RegistryEntry( 198 entries->push_front(new RegistryEntry(
199 chrome_application, ShellUtil::kRegApplicationName, 199 chrome_application, ShellUtil::kRegApplicationName,
200 dist->GetApplicationName().append(suffix))); 200 dist->GetAppShortCutName().append(suffix)));
201 entries->push_front(new RegistryEntry( 201 entries->push_front(new RegistryEntry(
202 chrome_application, ShellUtil::kRegApplicationDescription, 202 chrome_application, ShellUtil::kRegApplicationDescription,
203 dist->GetAppDescription())); 203 dist->GetAppDescription()));
204 entries->push_front(new RegistryEntry( 204 entries->push_front(new RegistryEntry(
205 chrome_application, ShellUtil::kRegApplicationCompany, 205 chrome_application, ShellUtil::kRegApplicationCompany,
206 dist->GetPublisherName())); 206 dist->GetPublisherName()));
207 } 207 }
208 208
209 return true; 209 return true;
210 } 210 }
(...skipping 18 matching lines...) Expand all
229 std::list<RegistryEntry*>* entries) { 229 std::list<RegistryEntry*>* entries) {
230 string16 icon_path = ShellUtil::GetChromeIcon(dist, chrome_exe); 230 string16 icon_path = ShellUtil::GetChromeIcon(dist, chrome_exe);
231 string16 quoted_exe_path = L"\"" + chrome_exe + L"\""; 231 string16 quoted_exe_path = L"\"" + chrome_exe + L"\"";
232 232
233 // Register for the Start Menu "Internet" link (pre-Win7). 233 // Register for the Start Menu "Internet" link (pre-Win7).
234 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); 234 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix));
235 // Register Chrome's display name. 235 // Register Chrome's display name.
236 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see 236 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see
237 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85) .aspx#registering_the_display_name 237 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85) .aspx#registering_the_display_name
238 entries->push_front(new RegistryEntry( 238 entries->push_front(new RegistryEntry(
239 start_menu_entry, dist->GetApplicationName())); 239 start_menu_entry, dist->GetAppShortCutName()));
240 // Register the "open" verb for launching Chrome via the "Internet" link. 240 // Register the "open" verb for launching Chrome via the "Internet" link.
241 entries->push_front(new RegistryEntry( 241 entries->push_front(new RegistryEntry(
242 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); 242 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path));
243 // Register Chrome's icon for the Start Menu "Internet" link. 243 // Register Chrome's icon for the Start Menu "Internet" link.
244 entries->push_front(new RegistryEntry( 244 entries->push_front(new RegistryEntry(
245 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); 245 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path));
246 246
247 // Register installation information. 247 // Register installation information.
248 string16 install_info(start_menu_entry + L"\\InstallInfo"); 248 string16 install_info(start_menu_entry + L"\\InstallInfo");
249 // Note: not using CommandLine since it has ambiguous rules for quoting 249 // Note: not using CommandLine since it has ambiguous rules for quoting
250 // strings. 250 // strings.
251 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, 251 entries->push_front(new RegistryEntry(install_info, kReinstallCommand,
252 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); 252 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser)));
253 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", 253 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand",
254 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); 254 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons)));
255 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", 255 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand",
256 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); 256 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons)));
257 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); 257 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1));
258 258
259 // Register with Default Programs. 259 // Register with Default Programs.
260 string16 reg_app_name(dist->GetApplicationName().append(suffix)); 260 string16 reg_app_name(dist->GetBaseAppName().append(suffix));
261 // Tell Windows where to find Chrome's Default Programs info. 261 // Tell Windows where to find Chrome's Default Programs info.
262 string16 capabilities(GetCapabilitiesKey(dist, suffix)); 262 string16 capabilities(GetCapabilitiesKey(dist, suffix));
263 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, 263 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications,
264 reg_app_name, capabilities)); 264 reg_app_name, capabilities));
265 // Write out Chrome's Default Programs info. 265 // Write out Chrome's Default Programs info.
266 // TODO(grt): http://crbug.com/75152 Write a reference to a localized 266 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
267 // resource rather than this. 267 // resource rather than this.
268 entries->push_front(new RegistryEntry( 268 entries->push_front(new RegistryEntry(
269 capabilities, ShellUtil::kRegApplicationDescription, 269 capabilities, ShellUtil::kRegApplicationDescription,
270 dist->GetLongAppDescription())); 270 dist->GetLongAppDescription()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // Protocols associations. 359 // Protocols associations.
360 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); 360 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe);
361 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); 361 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe);
362 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 362 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
363 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], 363 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i],
364 chrome_icon, chrome_open, entries); 364 chrome_icon, chrome_open, entries);
365 } 365 }
366 366
367 // start->Internet shortcut. 367 // start->Internet shortcut.
368 string16 start_menu(ShellUtil::kRegStartMenuInternet); 368 string16 start_menu(ShellUtil::kRegStartMenuInternet);
369 string16 app_name = dist->GetApplicationName() + suffix; 369 string16 app_name = dist->GetBaseAppName() + suffix;
370 entries->push_front(new RegistryEntry(start_menu, app_name)); 370 entries->push_front(new RegistryEntry(start_menu, app_name));
371 return true; 371 return true;
372 } 372 }
373 373
374 // Generate work_item tasks required to create current registry entry and 374 // Generate work_item tasks required to create current registry entry and
375 // add them to the given work item list. 375 // add them to the given work item list.
376 void AddToWorkItemList(HKEY root, WorkItemList *items) const { 376 void AddToWorkItemList(HKEY root, WorkItemList *items) const {
377 items->AddCreateRegKeyWorkItem(root, _key_path); 377 items->AddCreateRegKeyWorkItem(root, _key_path);
378 if (_is_string) { 378 if (_is_string) {
379 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); 379 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true);
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 key.ReadValue(NULL, &name) != ERROR_SUCCESS) { 923 key.ReadValue(NULL, &name) != ERROR_SUCCESS) {
924 continue; 924 continue;
925 } 925 }
926 // Read the browser's reinstall command. 926 // Read the browser's reinstall command.
927 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(), 927 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(),
928 KEY_QUERY_VALUE) != ERROR_SUCCESS || 928 KEY_QUERY_VALUE) != ERROR_SUCCESS ||
929 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { 929 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) {
930 continue; 930 continue;
931 } 931 }
932 if (!name.empty() && !command.empty() && 932 if (!name.empty() && !command.empty() &&
933 name.find(dist->GetApplicationName()) == string16::npos) 933 name.find(dist->GetBaseAppName()) == string16::npos)
934 (*browsers)[name] = command; 934 (*browsers)[name] = command;
935 } 935 }
936 } 936 }
937 937
938 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, 938 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist,
939 const string16& chrome_exe) { 939 const string16& chrome_exe) {
940 string16 tested_suffix; 940 string16 tested_suffix;
941 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || 941 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ||
942 !GetUserSpecificRegistrySuffix(&tested_suffix) || 942 !GetUserSpecificRegistrySuffix(&tested_suffix) ||
943 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, 943 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 // Assert that |reg_key| points to |chrome_exe| in HKLM. 990 // Assert that |reg_key| points to |chrome_exe| in HKLM.
991 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); 991 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE);
992 string16 hklm_value; 992 string16 hklm_value;
993 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { 993 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) {
994 return InstallUtil::ProgramCompare( 994 return InstallUtil::ProgramCompare(
995 FilePath(chrome_exe)).Evaluate(hklm_value); 995 FilePath(chrome_exe)).Evaluate(hklm_value);
996 } 996 }
997 return false; 997 return false;
998 } 998 }
999 999
1000 string16 ShellUtil::GetApplicationName(BrowserDistribution* dist,
1001 const string16& chrome_exe) {
1002 string16 app_name = dist->GetBaseAppName();
1003 app_name += GetCurrentInstallationSuffix(dist, chrome_exe);
1004 return app_name;
1005 }
1006
1000 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 1007 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
1001 int shell_change, 1008 int shell_change,
1002 const string16& chrome_exe, 1009 const string16& chrome_exe,
1003 bool elevate_if_not_admin) { 1010 bool elevate_if_not_admin) {
1004 if (!dist->CanSetAsDefault()) 1011 if (!dist->CanSetAsDefault())
1005 return false; 1012 return false;
1006 1013
1007 if (!ShellUtil::RegisterChromeBrowser( 1014 if (!ShellUtil::RegisterChromeBrowser(
1008 dist, chrome_exe, string16(), elevate_if_not_admin)) { 1015 dist, chrome_exe, string16(), elevate_if_not_admin)) {
1009 return false; 1016 return false;
1010 } 1017 }
1011 1018
1012 bool ret = true; 1019 bool ret = true;
1013 // First use the new "recommended" way on Vista to make Chrome default 1020 // First use the new "recommended" way on Vista to make Chrome default
1014 // browser. 1021 // browser.
1015 string16 app_name = dist->GetApplicationName(); 1022 string16 app_name = GetApplicationName(dist, chrome_exe);
1016 const string16 app_suffix(
1017 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe));
1018 app_name += app_suffix;
1019 1023
1020 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 1024 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
1021 // On Windows 8, you can't set yourself as the default handler 1025 // On Windows 8, you can't set yourself as the default handler
1022 // programatically. In other words IApplicationAssociationRegistration 1026 // programatically. In other words IApplicationAssociationRegistration
1023 // has been rendered useless. What you can do is to launch 1027 // has been rendered useless. What you can do is to launch
1024 // "Set Program Associations" section of the "Default Programs" 1028 // "Set Program Associations" section of the "Default Programs"
1025 // control panel. This action does not require elevation and we 1029 // control panel. This action does not require elevation and we
1026 // don't get to control window activation. More info at: 1030 // don't get to control window activation. More info at:
1027 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx 1031 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx
1028 return LaunchApplicationAssociationDialog(app_name.c_str()); 1032 return LaunchApplicationAssociationDialog(app_name.c_str());
(...skipping 29 matching lines...) Expand all
1058 } 1062 }
1059 } 1063 }
1060 1064
1061 // Now use the old way to associate Chrome with supported protocols and file 1065 // Now use the old way to associate Chrome with supported protocols and file
1062 // associations. This should not be required on Vista but since some 1066 // associations. This should not be required on Vista but since some
1063 // applications still read Software\Classes\http key directly, we have to do 1067 // applications still read Software\Classes\http key directly, we have to do
1064 // this on Vista also. 1068 // this on Vista also.
1065 1069
1066 std::list<RegistryEntry*> entries; 1070 std::list<RegistryEntry*> entries;
1067 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); 1071 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries);
1068 RegistryEntry::GetUserEntries(dist, chrome_exe, app_suffix, &entries); 1072 RegistryEntry::GetUserEntries(dist,
1073 chrome_exe,
1074 GetCurrentInstallationSuffix(dist, chrome_exe),
1075 &entries);
1069 // Change the default browser for current user. 1076 // Change the default browser for current user.
1070 if ((shell_change & ShellUtil::CURRENT_USER) && 1077 if ((shell_change & ShellUtil::CURRENT_USER) &&
1071 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { 1078 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) {
1072 ret = false; 1079 ret = false;
1073 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; 1080 LOG(ERROR) << "Could not make Chrome default browser (XP/current user).";
1074 } 1081 }
1075 1082
1076 // Chrome as default browser at system level. 1083 // Chrome as default browser at system level.
1077 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && 1084 if ((shell_change & ShellUtil::SYSTEM_LEVEL) &&
1078 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { 1085 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) {
(...skipping 18 matching lines...) Expand all
1097 bool ret = true; 1104 bool ret = true;
1098 // First use the new "recommended" way on Vista to make Chrome default 1105 // First use the new "recommended" way on Vista to make Chrome default
1099 // protocol handler. 1106 // protocol handler.
1100 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 1107 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
1101 VLOG(1) << "Registering Chrome as default handler for " << protocol 1108 VLOG(1) << "Registering Chrome as default handler for " << protocol
1102 << " on Vista."; 1109 << " on Vista.";
1103 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 1110 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
1104 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 1111 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
1105 NULL, CLSCTX_INPROC); 1112 NULL, CLSCTX_INPROC);
1106 if (SUCCEEDED(hr)) { 1113 if (SUCCEEDED(hr)) {
1107 string16 app_name = dist->GetApplicationName(); 1114 string16 app_name = GetApplicationName(dist, chrome_exe);
1108 app_name += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe);
1109
1110 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), 1115 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(),
1111 AT_URLPROTOCOL); 1116 AT_URLPROTOCOL);
1112 } 1117 }
1113 if (!SUCCEEDED(hr)) { 1118 if (!SUCCEEDED(hr)) {
1114 ret = false; 1119 ret = false;
1115 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" 1120 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):"
1116 << " HRESULT=" << hr << "."; 1121 << " HRESULT=" << hr << ".";
1117 } 1122 }
1118 } 1123 }
1119 1124
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 chrome_exe.c_str(), 1353 chrome_exe.c_str(),
1349 shortcut.c_str(), 1354 shortcut.c_str(),
1350 chrome_path.c_str(), 1355 chrome_path.c_str(),
1351 arguments.c_str(), 1356 arguments.c_str(),
1352 description.c_str(), 1357 description.c_str(),
1353 icon_path.c_str(), 1358 icon_path.c_str(),
1354 icon_index, 1359 icon_index,
1355 dist->GetBrowserAppId().c_str(), 1360 dist->GetBrowserAppId().c_str(),
1356 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1361 ConvertShellUtilShortcutOptionsToFileUtil(options));
1357 } 1362 }
OLDNEW
« chrome/installer/util/browser_distribution.h ('K') | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698