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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 212 } |
213 | 213 |
214 // This method returns a list of all the registry entries that | 214 // This method returns a list of all the registry entries that |
215 // are needed to register this installation's ProgId and AppId. | 215 // are needed to register this installation's ProgId and AppId. |
216 // These entries need to be registered in HKLM prior to Win8. | 216 // These entries need to be registered in HKLM prior to Win8. |
217 static void GetProgIdEntries(BrowserDistribution* dist, | 217 static void GetProgIdEntries(BrowserDistribution* dist, |
218 const string16& chrome_exe, | 218 const string16& chrome_exe, |
219 const string16& suffix, | 219 const string16& suffix, |
220 ScopedVector<RegistryEntry>* entries) { | 220 ScopedVector<RegistryEntry>* entries) { |
221 string16 icon_path( | 221 string16 icon_path( |
222 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex())); | 222 ShellUtil::FormatIconLocation( |
| 223 chrome_exe, |
| 224 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
223 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 225 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
224 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); | 226 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); |
225 // For user-level installs: entries for the app id and DelegateExecute verb | 227 // For user-level installs: entries for the app id and DelegateExecute verb |
226 // handler will be in HKCU; thus we do not need a suffix on those entries. | 228 // handler will be in HKCU; thus we do not need a suffix on those entries. |
227 string16 app_id( | 229 string16 app_id( |
228 ShellUtil::GetBrowserModelId( | 230 ShellUtil::GetBrowserModelId( |
229 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); | 231 dist, InstallUtil::IsPerUserInstall(chrome_exe.c_str()))); |
230 string16 delegate_guid; | 232 string16 delegate_guid; |
231 bool set_delegate_execute = | 233 bool set_delegate_execute = |
232 IsChromeMetroSupported() && | 234 IsChromeMetroSupported() && |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 string16 chrome_application(chrome_html_prog_id + | 312 string16 chrome_application(chrome_html_prog_id + |
311 ShellUtil::kRegApplication); | 313 ShellUtil::kRegApplication); |
312 entries->push_back(new RegistryEntry( | 314 entries->push_back(new RegistryEntry( |
313 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); | 315 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); |
314 entries->push_back(new RegistryEntry( | 316 entries->push_back(new RegistryEntry( |
315 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); | 317 chrome_application, ShellUtil::kRegApplicationIcon, icon_path)); |
316 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 318 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
317 // resource for name, description, and company. | 319 // resource for name, description, and company. |
318 entries->push_back(new RegistryEntry( | 320 entries->push_back(new RegistryEntry( |
319 chrome_application, ShellUtil::kRegApplicationName, | 321 chrome_application, ShellUtil::kRegApplicationName, |
320 dist->GetAppShortCutName())); | 322 dist->GetDisplayName())); |
321 entries->push_back(new RegistryEntry( | 323 entries->push_back(new RegistryEntry( |
322 chrome_application, ShellUtil::kRegApplicationDescription, | 324 chrome_application, ShellUtil::kRegApplicationDescription, |
323 dist->GetAppDescription())); | 325 dist->GetAppDescription())); |
324 entries->push_back(new RegistryEntry( | 326 entries->push_back(new RegistryEntry( |
325 chrome_application, ShellUtil::kRegApplicationCompany, | 327 chrome_application, ShellUtil::kRegApplicationCompany, |
326 dist->GetPublisherName())); | 328 dist->GetPublisherName())); |
327 } | 329 } |
328 } | 330 } |
329 | 331 |
330 // This method returns a list of the registry entries needed to declare a | 332 // This method returns a list of the registry entries needed to declare a |
(...skipping 12 matching lines...) Expand all Loading... |
343 // this installation in "RegisteredApplications" on Windows (to appear in | 345 // this installation in "RegisteredApplications" on Windows (to appear in |
344 // Default Programs, StartMenuInternet, etc.). | 346 // Default Programs, StartMenuInternet, etc.). |
345 // These entries need to be registered in HKLM prior to Win8. | 347 // These entries need to be registered in HKLM prior to Win8. |
346 // If |suffix| is not empty, these entries are guaranteed to be unique on this | 348 // If |suffix| is not empty, these entries are guaranteed to be unique on this |
347 // machine. | 349 // machine. |
348 static void GetShellIntegrationEntries(BrowserDistribution* dist, | 350 static void GetShellIntegrationEntries(BrowserDistribution* dist, |
349 const string16& chrome_exe, | 351 const string16& chrome_exe, |
350 const string16& suffix, | 352 const string16& suffix, |
351 ScopedVector<RegistryEntry>* entries) { | 353 ScopedVector<RegistryEntry>* entries) { |
352 const string16 icon_path( | 354 const string16 icon_path( |
353 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex())); | 355 ShellUtil::FormatIconLocation( |
| 356 chrome_exe, |
| 357 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
354 const string16 quoted_exe_path(L"\"" + chrome_exe + L"\""); | 358 const string16 quoted_exe_path(L"\"" + chrome_exe + L"\""); |
355 | 359 |
356 // Register for the Start Menu "Internet" link (pre-Win7). | 360 // Register for the Start Menu "Internet" link (pre-Win7). |
357 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); | 361 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); |
358 // Register Chrome's display name. | 362 // Register Chrome's display name. |
359 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see | 363 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see |
360 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name | 364 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85)
.aspx#registering_the_display_name |
361 entries->push_back(new RegistryEntry( | 365 entries->push_back(new RegistryEntry( |
362 start_menu_entry, dist->GetAppShortCutName())); | 366 start_menu_entry, dist->GetDisplayName())); |
363 // Register the "open" verb for launching Chrome via the "Internet" link. | 367 // Register the "open" verb for launching Chrome via the "Internet" link. |
364 entries->push_back(new RegistryEntry( | 368 entries->push_back(new RegistryEntry( |
365 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); | 369 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); |
366 // Register Chrome's icon for the Start Menu "Internet" link. | 370 // Register Chrome's icon for the Start Menu "Internet" link. |
367 entries->push_back(new RegistryEntry( | 371 entries->push_back(new RegistryEntry( |
368 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); | 372 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); |
369 | 373 |
370 // Register installation information. | 374 // Register installation information. |
371 string16 install_info(start_menu_entry + L"\\InstallInfo"); | 375 string16 install_info(start_menu_entry + L"\\InstallInfo"); |
372 // Note: not using CommandLine since it has ambiguous rules for quoting | 376 // Note: not using CommandLine since it has ambiguous rules for quoting |
(...skipping 15 matching lines...) Expand all Loading... |
388 // Write out Chrome's Default Programs info. | 392 // Write out Chrome's Default Programs info. |
389 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 393 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
390 // resource rather than this. | 394 // resource rather than this. |
391 entries->push_back(new RegistryEntry( | 395 entries->push_back(new RegistryEntry( |
392 capabilities, ShellUtil::kRegApplicationDescription, | 396 capabilities, ShellUtil::kRegApplicationDescription, |
393 dist->GetLongAppDescription())); | 397 dist->GetLongAppDescription())); |
394 entries->push_back(new RegistryEntry( | 398 entries->push_back(new RegistryEntry( |
395 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 399 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
396 entries->push_back(new RegistryEntry( | 400 entries->push_back(new RegistryEntry( |
397 capabilities, ShellUtil::kRegApplicationName, | 401 capabilities, ShellUtil::kRegApplicationName, |
398 dist->GetAppShortCutName())); | 402 dist->GetDisplayName())); |
399 | 403 |
400 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", | 404 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", |
401 L"StartMenuInternet", reg_app_name)); | 405 L"StartMenuInternet", reg_app_name)); |
402 | 406 |
403 const string16 html_prog_id(GetBrowserProgId(suffix)); | 407 const string16 html_prog_id(GetBrowserProgId(suffix)); |
404 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { | 408 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { |
405 entries->push_back(new RegistryEntry( | 409 entries->push_back(new RegistryEntry( |
406 capabilities + L"\\FileAssociations", | 410 capabilities + L"\\FileAssociations", |
407 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); | 411 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); |
408 } | 412 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { | 498 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { |
495 string16 ext_key(ShellUtil::kRegClasses); | 499 string16 ext_key(ShellUtil::kRegClasses); |
496 ext_key.push_back(base::FilePath::kSeparators[0]); | 500 ext_key.push_back(base::FilePath::kSeparators[0]); |
497 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); | 501 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); |
498 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); | 502 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); |
499 } | 503 } |
500 | 504 |
501 // Protocols associations. | 505 // Protocols associations. |
502 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 506 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
503 string16 chrome_icon = | 507 string16 chrome_icon = |
504 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex()); | 508 ShellUtil::FormatIconLocation( |
| 509 chrome_exe, |
| 510 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); |
505 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 511 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
506 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 512 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
507 chrome_icon, chrome_open, entries); | 513 chrome_icon, chrome_open, entries); |
508 } | 514 } |
509 | 515 |
510 // start->Internet shortcut. | 516 // start->Internet shortcut. |
511 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 517 string16 start_menu(ShellUtil::kRegStartMenuInternet); |
512 string16 app_name = dist->GetBaseAppName() + suffix; | 518 string16 app_name = dist->GetBaseAppName() + suffix; |
513 entries->push_back(new RegistryEntry(start_menu, app_name)); | 519 entries->push_back(new RegistryEntry(start_menu, app_name)); |
514 } | 520 } |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 // Associates Chrome with |protocol| in the registry. This should not be | 905 // Associates Chrome with |protocol| in the registry. This should not be |
900 // required on Vista+ but since some applications still read these registry | 906 // required on Vista+ but since some applications still read these registry |
901 // keys directly, we have to do this on Vista+ as well. | 907 // keys directly, we have to do this on Vista+ as well. |
902 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. | 908 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. |
903 bool RegisterChromeAsDefaultProtocolClientXPStyle(BrowserDistribution* dist, | 909 bool RegisterChromeAsDefaultProtocolClientXPStyle(BrowserDistribution* dist, |
904 const string16& chrome_exe, | 910 const string16& chrome_exe, |
905 const string16& protocol) { | 911 const string16& protocol) { |
906 ScopedVector<RegistryEntry> entries; | 912 ScopedVector<RegistryEntry> entries; |
907 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 913 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
908 const string16 chrome_icon( | 914 const string16 chrome_icon( |
909 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex())); | 915 ShellUtil::FormatIconLocation( |
| 916 chrome_exe, |
| 917 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); |
910 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, | 918 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, |
911 chrome_open, &entries); | 919 chrome_open, &entries); |
912 // Change the default protocol handler for current user. | 920 // Change the default protocol handler for current user. |
913 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 921 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
914 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 922 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
915 return false; | 923 return false; |
916 } | 924 } |
917 | 925 |
918 return true; | 926 return true; |
919 } | 927 } |
920 | 928 |
921 // Returns |properties.shortcut_name| if the property is set, otherwise it | 929 // Returns |properties.shortcut_name| if the property is set, otherwise it |
922 // returns dist->GetAppShortcutName(). In any case, it makes sure the | 930 // returns dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME). In any |
923 // return value is suffixed with ".lnk". | 931 // case, it makes sure the return value is suffixed with ".lnk". |
924 string16 ExtractShortcutNameFromProperties( | 932 string16 ExtractShortcutNameFromProperties( |
925 BrowserDistribution* dist, | 933 BrowserDistribution* dist, |
926 const ShellUtil::ShortcutProperties& properties) { | 934 const ShellUtil::ShortcutProperties& properties) { |
927 DCHECK(dist); | 935 DCHECK(dist); |
928 string16 shortcut_name; | 936 string16 shortcut_name; |
929 if (properties.has_shortcut_name()) | 937 if (properties.has_shortcut_name()) { |
930 shortcut_name = properties.shortcut_name; | 938 shortcut_name = properties.shortcut_name; |
931 else | 939 } else { |
932 shortcut_name = dist->GetAppShortCutName(); | 940 shortcut_name = |
| 941 dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); |
| 942 } |
933 | 943 |
934 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) | 944 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) |
935 shortcut_name.append(installer::kLnkExt); | 945 shortcut_name.append(installer::kLnkExt); |
936 | 946 |
937 return shortcut_name; | 947 return shortcut_name; |
938 } | 948 } |
939 | 949 |
940 // Converts ShellUtil::ShortcutOperation to the best-matching value in | 950 // Converts ShellUtil::ShortcutOperation to the best-matching value in |
941 // base::win::ShortcutOperation. | 951 // base::win::ShortcutOperation. |
942 base::win::ShortcutOperation TranslateShortcutOperation( | 952 base::win::ShortcutOperation TranslateShortcutOperation( |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 default: | 1437 default: |
1428 NOTREACHED(); | 1438 NOTREACHED(); |
1429 return false; | 1439 return false; |
1430 } | 1440 } |
1431 | 1441 |
1432 if (!PathService::Get(dir_key, path) || path->empty()) { | 1442 if (!PathService::Get(dir_key, path) || path->empty()) { |
1433 NOTREACHED() << dir_key; | 1443 NOTREACHED() << dir_key; |
1434 return false; | 1444 return false; |
1435 } | 1445 } |
1436 | 1446 |
1437 if (add_folder_for_dist) | 1447 if (add_folder_for_dist) { |
1438 *path = path->Append(dist->GetAppShortCutName()); | 1448 *path = path->Append(dist->GetStartMenuShortcutSubfolder( |
| 1449 BrowserDistribution::SUBFOLDER_CHROME)); |
| 1450 } |
1439 | 1451 |
1440 return true; | 1452 return true; |
1441 } | 1453 } |
1442 | 1454 |
1443 bool ShellUtil::CreateOrUpdateShortcut( | 1455 bool ShellUtil::CreateOrUpdateShortcut( |
1444 ShellUtil::ShortcutLocation location, | 1456 ShellUtil::ShortcutLocation location, |
1445 BrowserDistribution* dist, | 1457 BrowserDistribution* dist, |
1446 const ShellUtil::ShortcutProperties& properties, | 1458 const ShellUtil::ShortcutProperties& properties, |
1447 ShellUtil::ShortcutOperation operation) { | 1459 ShellUtil::ShortcutOperation operation) { |
1448 // Explicitly whitelist locations to which this is applicable. | 1460 // Explicitly whitelist locations to which this is applicable. |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 // are any left...). | 2142 // are any left...). |
2131 if (free_bits >= 8 && next_byte_index < size) { | 2143 if (free_bits >= 8 && next_byte_index < size) { |
2132 free_bits -= 8; | 2144 free_bits -= 8; |
2133 bit_stream += bytes[next_byte_index++] << free_bits; | 2145 bit_stream += bytes[next_byte_index++] << free_bits; |
2134 } | 2146 } |
2135 } | 2147 } |
2136 | 2148 |
2137 DCHECK_EQ(ret.length(), encoded_length); | 2149 DCHECK_EQ(ret.length(), encoded_length); |
2138 return ret; | 2150 return ret; |
2139 } | 2151 } |
OLD | NEW |