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, |
367 dist->GetDisplayName())); | |
363 // Register the "open" verb for launching Chrome via the "Internet" link. | 368 // Register the "open" verb for launching Chrome via the "Internet" link. |
364 entries->push_back(new RegistryEntry( | 369 entries->push_back(new RegistryEntry( |
365 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); | 370 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); |
366 // Register Chrome's icon for the Start Menu "Internet" link. | 371 // Register Chrome's icon for the Start Menu "Internet" link. |
367 entries->push_back(new RegistryEntry( | 372 entries->push_back(new RegistryEntry( |
368 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); | 373 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); |
369 | 374 |
370 // Register installation information. | 375 // Register installation information. |
371 string16 install_info(start_menu_entry + L"\\InstallInfo"); | 376 string16 install_info(start_menu_entry + L"\\InstallInfo"); |
372 // Note: not using CommandLine since it has ambiguous rules for quoting | 377 // 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. | 393 // Write out Chrome's Default Programs info. |
389 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 394 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
390 // resource rather than this. | 395 // resource rather than this. |
391 entries->push_back(new RegistryEntry( | 396 entries->push_back(new RegistryEntry( |
392 capabilities, ShellUtil::kRegApplicationDescription, | 397 capabilities, ShellUtil::kRegApplicationDescription, |
393 dist->GetLongAppDescription())); | 398 dist->GetLongAppDescription())); |
394 entries->push_back(new RegistryEntry( | 399 entries->push_back(new RegistryEntry( |
395 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 400 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
396 entries->push_back(new RegistryEntry( | 401 entries->push_back(new RegistryEntry( |
397 capabilities, ShellUtil::kRegApplicationName, | 402 capabilities, ShellUtil::kRegApplicationName, |
398 dist->GetAppShortCutName())); | 403 dist->GetDisplayName())); |
399 | 404 |
400 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", | 405 entries->push_back(new RegistryEntry(capabilities + L"\\Startmenu", |
401 L"StartMenuInternet", reg_app_name)); | 406 L"StartMenuInternet", reg_app_name)); |
402 | 407 |
403 const string16 html_prog_id(GetBrowserProgId(suffix)); | 408 const string16 html_prog_id(GetBrowserProgId(suffix)); |
404 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { | 409 for (int i = 0; ShellUtil::kPotentialFileAssociations[i] != NULL; i++) { |
405 entries->push_back(new RegistryEntry( | 410 entries->push_back(new RegistryEntry( |
406 capabilities + L"\\FileAssociations", | 411 capabilities + L"\\FileAssociations", |
407 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); | 412 ShellUtil::kPotentialFileAssociations[i], html_prog_id)); |
408 } | 413 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { | 499 for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) { |
495 string16 ext_key(ShellUtil::kRegClasses); | 500 string16 ext_key(ShellUtil::kRegClasses); |
496 ext_key.push_back(base::FilePath::kSeparators[0]); | 501 ext_key.push_back(base::FilePath::kSeparators[0]); |
497 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); | 502 ext_key.append(ShellUtil::kDefaultFileAssociations[i]); |
498 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); | 503 entries->push_back(new RegistryEntry(ext_key, html_prog_id)); |
499 } | 504 } |
500 | 505 |
501 // Protocols associations. | 506 // Protocols associations. |
502 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 507 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
503 string16 chrome_icon = | 508 string16 chrome_icon = |
504 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex()); | 509 ShellUtil::FormatIconLocation( |
510 chrome_exe, | |
511 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME)); | |
505 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 512 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
506 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 513 GetXPStyleUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
507 chrome_icon, chrome_open, entries); | 514 chrome_icon, chrome_open, entries); |
508 } | 515 } |
509 | 516 |
510 // start->Internet shortcut. | 517 // start->Internet shortcut. |
511 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 518 string16 start_menu(ShellUtil::kRegStartMenuInternet); |
512 string16 app_name = dist->GetBaseAppName() + suffix; | 519 string16 app_name = dist->GetBaseAppName() + suffix; |
513 entries->push_back(new RegistryEntry(start_menu, app_name)); | 520 entries->push_back(new RegistryEntry(start_menu, app_name)); |
514 } | 521 } |
(...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 | 906 // Associates Chrome with |protocol| in the registry. This should not be |
900 // required on Vista+ but since some applications still read these registry | 907 // required on Vista+ but since some applications still read these registry |
901 // keys directly, we have to do this on Vista+ as well. | 908 // keys directly, we have to do this on Vista+ as well. |
902 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. | 909 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. |
903 bool RegisterChromeAsDefaultProtocolClientXPStyle(BrowserDistribution* dist, | 910 bool RegisterChromeAsDefaultProtocolClientXPStyle(BrowserDistribution* dist, |
904 const string16& chrome_exe, | 911 const string16& chrome_exe, |
905 const string16& protocol) { | 912 const string16& protocol) { |
906 ScopedVector<RegistryEntry> entries; | 913 ScopedVector<RegistryEntry> entries; |
907 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 914 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
908 const string16 chrome_icon( | 915 const string16 chrome_icon( |
909 ShellUtil::FormatIconLocation(chrome_exe, dist->GetIconIndex())); | 916 ShellUtil::FormatIconLocation( |
917 chrome_exe, | |
918 dist->GetIconIndex(BrowserDistribution::SHORTCUT_CHROME))); | |
910 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, | 919 RegistryEntry::GetXPStyleUserProtocolEntries(protocol, chrome_icon, |
911 chrome_open, &entries); | 920 chrome_open, &entries); |
912 // Change the default protocol handler for current user. | 921 // Change the default protocol handler for current user. |
913 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 922 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
914 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 923 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
915 return false; | 924 return false; |
916 } | 925 } |
917 | 926 |
918 return true; | 927 return true; |
919 } | 928 } |
920 | 929 |
921 // Returns |properties.shortcut_name| if the property is set, otherwise it | 930 // Returns |properties.shortcut_name| if the property is set, otherwise it |
922 // returns dist->GetAppShortcutName(). In any case, it makes sure the | 931 // returns dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME). In any |
923 // return value is suffixed with ".lnk". | 932 // case, it makes sure the return value is suffixed with ".lnk". |
924 string16 ExtractShortcutNameFromProperties( | 933 string16 ExtractShortcutNameFromProperties( |
925 BrowserDistribution* dist, | 934 BrowserDistribution* dist, |
926 const ShellUtil::ShortcutProperties& properties) { | 935 const ShellUtil::ShortcutProperties& properties) { |
927 DCHECK(dist); | 936 DCHECK(dist); |
928 string16 shortcut_name; | 937 string16 shortcut_name; |
929 if (properties.has_shortcut_name()) | 938 if (properties.has_shortcut_name()) { |
930 shortcut_name = properties.shortcut_name; | 939 shortcut_name = properties.shortcut_name; |
931 else | 940 } else { |
932 shortcut_name = dist->GetAppShortCutName(); | 941 shortcut_name = |
942 dist->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME); | |
943 } | |
933 | 944 |
934 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) | 945 if (!EndsWith(shortcut_name, installer::kLnkExt, false)) |
935 shortcut_name.append(installer::kLnkExt); | 946 shortcut_name.append(installer::kLnkExt); |
936 | 947 |
937 return shortcut_name; | 948 return shortcut_name; |
938 } | 949 } |
939 | 950 |
940 // Converts ShellUtil::ShortcutOperation to the best-matching value in | 951 // Converts ShellUtil::ShortcutOperation to the best-matching value in |
941 // base::win::ShortcutOperation. | 952 // base::win::ShortcutOperation. |
942 base::win::ShortcutOperation TranslateShortcutOperation( | 953 base::win::ShortcutOperation TranslateShortcutOperation( |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1390 default: | 1401 default: |
1391 NOTREACHED(); | 1402 NOTREACHED(); |
1392 return false; | 1403 return false; |
1393 } | 1404 } |
1394 | 1405 |
1395 if (!PathService::Get(dir_key, path) || path->empty()) { | 1406 if (!PathService::Get(dir_key, path) || path->empty()) { |
1396 NOTREACHED() << dir_key; | 1407 NOTREACHED() << dir_key; |
1397 return false; | 1408 return false; |
1398 } | 1409 } |
1399 | 1410 |
1400 if (add_folder_for_dist) | 1411 if (add_folder_for_dist) { |
1401 *path = path->Append(dist->GetAppShortCutName()); | 1412 *path = path->Append( |
1413 dist->GetStartMenuShortcutSubfolder( | |
gab
2013/06/27 11:49:43
nit: This likely fits on the previous line now.
calamity
2013/07/05 09:00:29
Done.
| |
1414 BrowserDistribution::SUBFOLDER_CHROME)); | |
gab
2013/06/27 11:49:43
nit: Indent 2 more spaces.
(or 2 less if comment
calamity
2013/07/05 09:00:29
Done.
| |
1415 } | |
1402 | 1416 |
1403 return true; | 1417 return true; |
1404 } | 1418 } |
1405 | 1419 |
1406 bool ShellUtil::CreateOrUpdateShortcut( | 1420 bool ShellUtil::CreateOrUpdateShortcut( |
1407 ShellUtil::ShortcutLocation location, | 1421 ShellUtil::ShortcutLocation location, |
1408 BrowserDistribution* dist, | 1422 BrowserDistribution* dist, |
1409 const ShellUtil::ShortcutProperties& properties, | 1423 const ShellUtil::ShortcutProperties& properties, |
1410 ShellUtil::ShortcutOperation operation) { | 1424 ShellUtil::ShortcutOperation operation) { |
1411 // Explicitly whitelist locations to which this is applicable. | 1425 // Explicitly whitelist locations to which this is applicable. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1486 if (!ret) { | 1500 if (!ret) { |
1487 LOG(ERROR) << "Failed to pin " << chosen_path->value(); | 1501 LOG(ERROR) << "Failed to pin " << chosen_path->value(); |
1488 } | 1502 } |
1489 } | 1503 } |
1490 | 1504 |
1491 return ret; | 1505 return ret; |
1492 } | 1506 } |
1493 | 1507 |
1494 string16 ShellUtil::FormatIconLocation(const string16& icon_path, | 1508 string16 ShellUtil::FormatIconLocation(const string16& icon_path, |
1495 int icon_index) { | 1509 int icon_index) { |
1510 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
gab
2013/06/27 11:49:43
Remove this line.
calamity
2013/07/05 09:00:29
Done.
| |
1496 string16 icon_string(icon_path); | 1511 string16 icon_string(icon_path); |
1497 icon_string.append(L","); | 1512 icon_string.append(L","); |
1498 icon_string.append(base::IntToString16(icon_index)); | 1513 icon_string.append(base::IntToString16(icon_index)); |
1499 return icon_string; | 1514 return icon_string; |
1500 } | 1515 } |
1501 | 1516 |
1502 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { | 1517 string16 ShellUtil::GetChromeShellOpenCmd(const string16& chrome_exe) { |
1503 return L"\"" + chrome_exe + L"\" -- \"%1\""; | 1518 return L"\"" + chrome_exe + L"\" -- \"%1\""; |
1504 } | 1519 } |
1505 | 1520 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2081 // are any left...). | 2096 // are any left...). |
2082 if (free_bits >= 8 && next_byte_index < size) { | 2097 if (free_bits >= 8 && next_byte_index < size) { |
2083 free_bits -= 8; | 2098 free_bits -= 8; |
2084 bit_stream += bytes[next_byte_index++] << free_bits; | 2099 bit_stream += bytes[next_byte_index++] << free_bits; |
2085 } | 2100 } |
2086 } | 2101 } |
2087 | 2102 |
2088 DCHECK_EQ(ret.length(), encoded_length); | 2103 DCHECK_EQ(ret.length(), encoded_length); |
2089 return ret; | 2104 return ret; |
2090 } | 2105 } |
OLD | NEW |