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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // speaking, we should use the name of the executable (e.g., "chrome.exe"), | 85 // speaking, we should use the name of the executable (e.g., "chrome.exe"), |
86 // but that ship has sailed. The cost of switching now is re-prompting users | 86 // but that ship has sailed. The cost of switching now is re-prompting users |
87 // to make Chrome their default browser, which isn't polite. |suffix| is the | 87 // to make Chrome their default browser, which isn't polite. |suffix| is the |
88 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix | 88 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix |
89 // in shell_util.h for details. | 89 // in shell_util.h for details. |
90 static string16 GetBrowserClientKey(BrowserDistribution* dist, | 90 static string16 GetBrowserClientKey(BrowserDistribution* dist, |
91 const string16& suffix) { | 91 const string16& suffix) { |
92 DCHECK(suffix.empty() || suffix[0] == L'.'); | 92 DCHECK(suffix.empty() || suffix[0] == L'.'); |
93 return string16(ShellUtil::kRegStartMenuInternet) | 93 return string16(ShellUtil::kRegStartMenuInternet) |
94 .append(1, L'\\') | 94 .append(1, L'\\') |
95 .append(dist->GetApplicationName()) | 95 .append(dist->GetUnsuffixedAppName()) |
96 .append(suffix); | 96 .append(suffix); |
97 } | 97 } |
98 | 98 |
99 // Returns the Windows Default Programs capabilities key for Chrome. For | 99 // Returns the Windows Default Programs capabilities key for Chrome. For |
100 // example: | 100 // example: |
101 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". | 101 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". |
102 static string16 GetCapabilitiesKey(BrowserDistribution* dist, | 102 static string16 GetCapabilitiesKey(BrowserDistribution* dist, |
103 const string16& suffix) { | 103 const string16& suffix) { |
104 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); | 104 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); |
105 } | 105 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 string16 chrome_application(chrome_html_prog_id + | 205 string16 chrome_application(chrome_html_prog_id + |
206 ShellUtil::kRegApplication); | 206 ShellUtil::kRegApplication); |
207 entries->push_front(new RegistryEntry( | 207 entries->push_front(new RegistryEntry( |
208 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); | 208 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); |
209 entries->push_front(new RegistryEntry( | 209 entries->push_front(new RegistryEntry( |
210 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); | 210 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); |
211 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 211 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
212 // resource for name, description, and company. | 212 // resource for name, description, and company. |
213 entries->push_front(new RegistryEntry( | 213 entries->push_front(new RegistryEntry( |
214 chrome_application, ShellUtil::kRegApplicationName, | 214 chrome_application, ShellUtil::kRegApplicationName, |
215 dist->GetApplicationName().append(suffix))); | 215 dist->GetAppShortCutName().append(suffix))); |
216 entries->push_front(new RegistryEntry( | 216 entries->push_front(new RegistryEntry( |
217 chrome_application, ShellUtil::kRegApplicationDescription, | 217 chrome_application, ShellUtil::kRegApplicationDescription, |
218 dist->GetAppDescription())); | 218 dist->GetAppDescription())); |
219 entries->push_front(new RegistryEntry( | 219 entries->push_front(new RegistryEntry( |
220 chrome_application, ShellUtil::kRegApplicationCompany, | 220 chrome_application, ShellUtil::kRegApplicationCompany, |
221 dist->GetPublisherName())); | 221 dist->GetPublisherName())); |
222 } | 222 } |
223 | 223 |
224 return true; | 224 return true; |
225 } | 225 } |
(...skipping 18 matching lines...) Expand all Loading... |
244 std::list<RegistryEntry*>* entries) { | 244 std::list<RegistryEntry*>* entries) { |
245 string16 icon_path = ShellUtil::GetChromeIcon(dist, chrome_exe); | 245 string16 icon_path = ShellUtil::GetChromeIcon(dist, chrome_exe); |
246 string16 quoted_exe_path = L"\"" + chrome_exe + L"\""; | 246 string16 quoted_exe_path = L"\"" + chrome_exe + L"\""; |
247 | 247 |
248 // Register for the Start Menu "Internet" link (pre-Win7). | 248 // Register for the Start Menu "Internet" link (pre-Win7). |
249 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); | 249 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); |
250 // Register Chrome's display name. | 250 // Register Chrome's display name. |
251 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see | 251 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see |
252 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name | 252 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name |
253 entries->push_front(new RegistryEntry( | 253 entries->push_front(new RegistryEntry( |
254 start_menu_entry, dist->GetApplicationName())); | 254 start_menu_entry, dist->GetAppShortCutName())); |
255 // Register the "open" verb for launching Chrome via the "Internet" link. | 255 // Register the "open" verb for launching Chrome via the "Internet" link. |
256 entries->push_front(new RegistryEntry( | 256 entries->push_front(new RegistryEntry( |
257 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); | 257 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); |
258 // Register Chrome's icon for the Start Menu "Internet" link. | 258 // Register Chrome's icon for the Start Menu "Internet" link. |
259 entries->push_front(new RegistryEntry( | 259 entries->push_front(new RegistryEntry( |
260 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); | 260 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); |
261 | 261 |
262 // Register installation information. | 262 // Register installation information. |
263 string16 install_info(start_menu_entry + L"\\InstallInfo"); | 263 string16 install_info(start_menu_entry + L"\\InstallInfo"); |
264 // Note: not using CommandLine since it has ambiguous rules for quoting | 264 // Note: not using CommandLine since it has ambiguous rules for quoting |
265 // strings. | 265 // strings. |
266 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, | 266 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, |
267 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); | 267 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); |
268 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", | 268 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", |
269 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); | 269 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); |
270 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", | 270 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", |
271 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); | 271 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); |
272 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); | 272 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); |
273 | 273 |
274 // Register with Default Programs. | 274 // Register with Default Programs. |
275 string16 reg_app_name(dist->GetApplicationName().append(suffix)); | 275 string16 reg_app_name(dist->GetUnsuffixedAppName().append(suffix)); |
276 // Tell Windows where to find Chrome's Default Programs info. | 276 // Tell Windows where to find Chrome's Default Programs info. |
277 string16 capabilities(GetCapabilitiesKey(dist, suffix)); | 277 string16 capabilities(GetCapabilitiesKey(dist, suffix)); |
278 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, | 278 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, |
279 reg_app_name, capabilities)); | 279 reg_app_name, capabilities)); |
280 // Write out Chrome's Default Programs info. | 280 // Write out Chrome's Default Programs info. |
281 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 281 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
282 // resource rather than this. | 282 // resource rather than this. |
283 entries->push_front(new RegistryEntry( | 283 entries->push_front(new RegistryEntry( |
284 capabilities, ShellUtil::kRegApplicationDescription, | 284 capabilities, ShellUtil::kRegApplicationDescription, |
285 dist->GetLongAppDescription())); | 285 dist->GetLongAppDescription())); |
286 entries->push_front(new RegistryEntry( | 286 entries->push_front(new RegistryEntry( |
287 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 287 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
288 entries->push_front(new RegistryEntry( | 288 entries->push_front(new RegistryEntry( |
289 capabilities, ShellUtil::kRegApplicationName, | 289 capabilities, ShellUtil::kRegApplicationName, |
290 dist->GetApplicationName())); | 290 dist->GetAppShortCutName())); |
291 | 291 |
292 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", | 292 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", |
293 L"StartMenuInternet", reg_app_name)); | 293 L"StartMenuInternet", reg_app_name)); |
294 | 294 |
295 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); | 295 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); |
296 html_prog_id.append(suffix); | 296 html_prog_id.append(suffix); |
297 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 297 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
298 entries->push_front(new RegistryEntry( | 298 entries->push_front(new RegistryEntry( |
299 capabilities + L"\\FileAssociations", | 299 capabilities + L"\\FileAssociations", |
300 ShellUtil::kFileAssociations[i], html_prog_id)); | 300 ShellUtil::kFileAssociations[i], html_prog_id)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // Protocols associations. | 374 // Protocols associations. |
375 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 375 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
376 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | 376 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); |
377 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 377 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
378 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 378 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
379 chrome_icon, chrome_open, entries); | 379 chrome_icon, chrome_open, entries); |
380 } | 380 } |
381 | 381 |
382 // start->Internet shortcut. | 382 // start->Internet shortcut. |
383 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 383 string16 start_menu(ShellUtil::kRegStartMenuInternet); |
384 string16 app_name = dist->GetApplicationName() + suffix; | 384 string16 app_name = dist->GetUnsuffixedAppName() + suffix; |
385 entries->push_front(new RegistryEntry(start_menu, app_name)); | 385 entries->push_front(new RegistryEntry(start_menu, app_name)); |
386 return true; | 386 return true; |
387 } | 387 } |
388 | 388 |
389 // Generate work_item tasks required to create current registry entry and | 389 // Generate work_item tasks required to create current registry entry and |
390 // add them to the given work item list. | 390 // add them to the given work item list. |
391 void AddToWorkItemList(HKEY root, WorkItemList *items) const { | 391 void AddToWorkItemList(HKEY root, WorkItemList *items) const { |
392 items->AddCreateRegKeyWorkItem(root, _key_path); | 392 items->AddCreateRegKeyWorkItem(root, _key_path); |
393 if (_is_string) { | 393 if (_is_string) { |
394 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); | 394 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 key.ReadValue(NULL, &name) != ERROR_SUCCESS) { | 951 key.ReadValue(NULL, &name) != ERROR_SUCCESS) { |
952 continue; | 952 continue; |
953 } | 953 } |
954 // Read the browser's reinstall command. | 954 // Read the browser's reinstall command. |
955 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(), | 955 if (key.Open(root, (client_path + L"\\InstallInfo").c_str(), |
956 KEY_QUERY_VALUE) != ERROR_SUCCESS || | 956 KEY_QUERY_VALUE) != ERROR_SUCCESS || |
957 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { | 957 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { |
958 continue; | 958 continue; |
959 } | 959 } |
960 if (!name.empty() && !command.empty() && | 960 if (!name.empty() && !command.empty() && |
961 name.find(dist->GetApplicationName()) == string16::npos) | 961 name.find(dist->GetUnsuffixedAppName()) == string16::npos) |
962 (*browsers)[name] = command; | 962 (*browsers)[name] = command; |
963 } | 963 } |
964 } | 964 } |
965 | 965 |
966 string16 ShellUtil::GetCurrentInstallationSuffix() { | 966 string16 ShellUtil::GetCurrentInstallationSuffix() { |
967 // Make sure we return an empty suffix if this is a system-level install. | 967 // Make sure we return an empty suffix if this is a system-level install. |
968 // This check is needed because it is technically possible for a system-level | 968 // This check is needed because it is technically possible for a system-level |
969 // install to run when a suffixed user-level is present (if the user never | 969 // install to run when a suffixed user-level is present (if the user never |
970 // runs his user-level install after a system-level Chrome is installed and | 970 // runs his user-level install after a system-level Chrome is installed and |
971 // instead runs the system-level chrome himself from Program Files...). In the | 971 // instead runs the system-level chrome himself from Program Files...). In the |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 return false; | 1026 return false; |
1027 | 1027 |
1028 if (!ShellUtil::RegisterChromeBrowser( | 1028 if (!ShellUtil::RegisterChromeBrowser( |
1029 dist, chrome_exe, L"", elevate_if_not_admin)) { | 1029 dist, chrome_exe, L"", elevate_if_not_admin)) { |
1030 return false; | 1030 return false; |
1031 } | 1031 } |
1032 | 1032 |
1033 bool ret = true; | 1033 bool ret = true; |
1034 // First use the new "recommended" way on Vista to make Chrome default | 1034 // First use the new "recommended" way on Vista to make Chrome default |
1035 // browser. | 1035 // browser. |
1036 string16 app_name = dist->GetApplicationName(); | 1036 string16 app_name = dist->GetAppName(); |
1037 const string16 app_suffix(ShellUtil::GetCurrentInstallationSuffix()); | |
1038 app_name += app_suffix; | |
1039 | 1037 |
1040 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 1038 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
1041 // On Windows 8, you can't set yourself as the default handler | 1039 // On Windows 8, you can't set yourself as the default handler |
1042 // programatically. In other words IApplicationAssociationRegistration | 1040 // programatically. In other words IApplicationAssociationRegistration |
1043 // has been rendered useless. What you can do is to launch | 1041 // has been rendered useless. What you can do is to launch |
1044 // "Set Program Associations" section of the "Default Programs" | 1042 // "Set Program Associations" section of the "Default Programs" |
1045 // control panel. This action does not require elevation and we | 1043 // control panel. This action does not require elevation and we |
1046 // don't get to control window activation. More info at: | 1044 // don't get to control window activation. More info at: |
1047 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx | 1045 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx |
1048 return LaunchApplicationAssociationDialog(app_name.c_str()); | 1046 return LaunchApplicationAssociationDialog(app_name.c_str()); |
(...skipping 29 matching lines...) Expand all Loading... |
1078 } | 1076 } |
1079 } | 1077 } |
1080 | 1078 |
1081 // Now use the old way to associate Chrome with supported protocols and file | 1079 // Now use the old way to associate Chrome with supported protocols and file |
1082 // associations. This should not be required on Vista but since some | 1080 // associations. This should not be required on Vista but since some |
1083 // applications still read Software\Classes\http key directly, we have to do | 1081 // applications still read Software\Classes\http key directly, we have to do |
1084 // this on Vista also. | 1082 // this on Vista also. |
1085 | 1083 |
1086 std::list<RegistryEntry*> entries; | 1084 std::list<RegistryEntry*> entries; |
1087 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1085 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
1088 RegistryEntry::GetUserEntries(dist, chrome_exe, app_suffix, &entries); | 1086 RegistryEntry::GetUserEntries( |
| 1087 dist, chrome_exe, ShellUtil::GetCurrentInstallationSuffix(), &entries); |
1089 // Change the default browser for current user. | 1088 // Change the default browser for current user. |
1090 if ((shell_change & ShellUtil::CURRENT_USER) && | 1089 if ((shell_change & ShellUtil::CURRENT_USER) && |
1091 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 1090 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
1092 ret = false; | 1091 ret = false; |
1093 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | 1092 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; |
1094 } | 1093 } |
1095 | 1094 |
1096 // Chrome as default browser at system level. | 1095 // Chrome as default browser at system level. |
1097 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | 1096 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && |
1098 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | 1097 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { |
(...skipping 18 matching lines...) Expand all Loading... |
1117 bool ret = true; | 1116 bool ret = true; |
1118 // First use the new "recommended" way on Vista to make Chrome default | 1117 // First use the new "recommended" way on Vista to make Chrome default |
1119 // protocol handler. | 1118 // protocol handler. |
1120 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1119 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1121 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1120 VLOG(1) << "Registering Chrome as default handler for " << protocol |
1122 << " on Vista."; | 1121 << " on Vista."; |
1123 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1122 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
1124 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1123 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
1125 NULL, CLSCTX_INPROC); | 1124 NULL, CLSCTX_INPROC); |
1126 if (SUCCEEDED(hr)) { | 1125 if (SUCCEEDED(hr)) { |
1127 string16 app_name = dist->GetApplicationName(); | 1126 string16 app_name = dist->GetAppName(); |
1128 app_name += ShellUtil::GetCurrentInstallationSuffix(); | |
1129 | |
1130 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1127 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
1131 AT_URLPROTOCOL); | 1128 AT_URLPROTOCOL); |
1132 } | 1129 } |
1133 if (!SUCCEEDED(hr)) { | 1130 if (!SUCCEEDED(hr)) { |
1134 ret = false; | 1131 ret = false; |
1135 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1132 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
1136 << " HRESULT=" << hr << "."; | 1133 << " HRESULT=" << hr << "."; |
1137 } | 1134 } |
1138 } | 1135 } |
1139 | 1136 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 chrome_exe.c_str(), | 1363 chrome_exe.c_str(), |
1367 shortcut.c_str(), | 1364 shortcut.c_str(), |
1368 chrome_path.c_str(), | 1365 chrome_path.c_str(), |
1369 arguments.c_str(), | 1366 arguments.c_str(), |
1370 description.c_str(), | 1367 description.c_str(), |
1371 icon_path.c_str(), | 1368 icon_path.c_str(), |
1372 icon_index, | 1369 icon_index, |
1373 dist->GetBrowserAppId().c_str(), | 1370 dist->GetBrowserAppId().c_str(), |
1374 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1371 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
1375 } | 1372 } |
OLD | NEW |