OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 351 } |
352 | 352 |
353 // This method checks if Chrome is already registered on the local machine. | 353 // This method checks if Chrome is already registered on the local machine. |
354 // It gets all the required registry entries for Chrome and then checks if | 354 // It gets all the required registry entries for Chrome and then checks if |
355 // they exist in HKLM. Returns true if all the entries exist, otherwise false. | 355 // they exist in HKLM. Returns true if all the entries exist, otherwise false. |
356 bool IsChromeRegistered(BrowserDistribution* dist, | 356 bool IsChromeRegistered(BrowserDistribution* dist, |
357 const std::wstring& chrome_exe, | 357 const std::wstring& chrome_exe, |
358 const std::wstring& suffix) { | 358 const std::wstring& suffix) { |
359 bool registered = true; | 359 bool registered = true; |
360 std::list<RegistryEntry*> entries; | 360 std::list<RegistryEntry*> entries; |
361 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 361 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
362 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 362 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
363 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); | 363 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); |
364 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); | 364 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); |
365 itr != entries.end() && registered; ++itr) { | 365 itr != entries.end() && registered; ++itr) { |
366 // We do not need registered = registered && ... since the loop condition | 366 // We do not need registered = registered && ... since the loop condition |
367 // is set to exit early. | 367 // is set to exit early. |
368 registered = (*itr)->ExistsInHKLM(); | 368 registered = (*itr)->ExistsInHKLM(); |
369 } | 369 } |
370 return registered; | 370 return registered; |
371 } | 371 } |
372 | 372 |
373 // This method checks if Chrome is already registered on the local machine | 373 // This method checks if Chrome is already registered on the local machine |
374 // for the requested protocol. It just checks the one value required for this. | 374 // for the requested protocol. It just checks the one value required for this. |
375 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, | 375 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, |
376 const std::wstring& suffix, | 376 const std::wstring& suffix, |
377 const std::wstring& protocol) { | 377 const std::wstring& protocol) { |
378 bool registered = true; | 378 bool registered = true; |
379 std::list<RegistryEntry*> entries; | 379 std::list<RegistryEntry*> entries; |
380 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 380 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
381 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); | 381 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); |
382 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); | 382 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); |
383 itr != entries.end() && registered; ++itr) { | 383 itr != entries.end() && registered; ++itr) { |
384 // We do not need registered = registered && ... since the loop condition | 384 // We do not need registered = registered && ... since the loop condition |
385 // is set to exit early. | 385 // is set to exit early. |
386 registered = (*itr)->ExistsInHKLM(); | 386 registered = (*itr)->ExistsInHKLM(); |
387 } | 387 } |
388 return registered; | 388 return registered; |
389 } | 389 } |
390 | 390 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 L"https", NULL}; | 525 L"https", NULL}; |
526 const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = {L"ftp", L"http", | 526 const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = {L"ftp", L"http", |
527 L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", L"sms", L"smsto", | 527 L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", L"sms", L"smsto", |
528 L"tel", L"urn", L"webcal", NULL}; | 528 L"tel", L"urn", L"webcal", NULL}; |
529 const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; | 529 const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; |
530 | 530 |
531 bool ShellUtil::AdminNeededForRegistryCleanup(BrowserDistribution* dist, | 531 bool ShellUtil::AdminNeededForRegistryCleanup(BrowserDistribution* dist, |
532 const std::wstring& suffix) { | 532 const std::wstring& suffix) { |
533 bool cleanup_needed = false; | 533 bool cleanup_needed = false; |
534 std::list<RegistryEntry*> entries; | 534 std::list<RegistryEntry*> entries; |
535 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 535 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
536 RegistryEntry::GetProgIdEntries(dist, L"chrome.exe", suffix, &entries); | 536 RegistryEntry::GetProgIdEntries(dist, L"chrome.exe", suffix, &entries); |
537 RegistryEntry::GetSystemEntries(dist, L"chrome.exe", suffix, &entries); | 537 RegistryEntry::GetSystemEntries(dist, L"chrome.exe", suffix, &entries); |
538 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); | 538 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); |
539 itr != entries.end() && !cleanup_needed; ++itr) { | 539 itr != entries.end() && !cleanup_needed; ++itr) { |
540 cleanup_needed = (*itr)->NameExistsInHKLM(); | 540 cleanup_needed = (*itr)->NameExistsInHKLM(); |
541 } | 541 } |
542 return cleanup_needed; | 542 return cleanup_needed; |
543 } | 543 } |
544 | 544 |
545 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 545 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 } | 796 } |
797 } | 797 } |
798 } | 798 } |
799 | 799 |
800 // Now use the old way to associate Chrome with supported protocols and file | 800 // Now use the old way to associate Chrome with supported protocols and file |
801 // associations. This should not be required on Vista but since some | 801 // associations. This should not be required on Vista but since some |
802 // applications still read Software\Classes\http key directly, we have to do | 802 // applications still read Software\Classes\http key directly, we have to do |
803 // this on Vista also. | 803 // this on Vista also. |
804 | 804 |
805 std::list<RegistryEntry*> entries; | 805 std::list<RegistryEntry*> entries; |
806 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 806 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
807 std::wstring suffix; | 807 std::wstring suffix; |
808 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | 808 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) |
809 suffix = L""; | 809 suffix = L""; |
810 RegistryEntry::GetUserEntries(dist, chrome_exe, suffix, &entries); | 810 RegistryEntry::GetUserEntries(dist, chrome_exe, suffix, &entries); |
811 // Change the default browser for current user. | 811 // Change the default browser for current user. |
812 if ((shell_change & ShellUtil::CURRENT_USER) && | 812 if ((shell_change & ShellUtil::CURRENT_USER) && |
813 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 813 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
814 ret = false; | 814 ret = false; |
815 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | 815 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; |
816 } | 816 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 859 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
860 << " HRESULT=" << hr << "."; | 860 << " HRESULT=" << hr << "."; |
861 } | 861 } |
862 } | 862 } |
863 | 863 |
864 // Now use the old way to associate Chrome with the desired protocol. This | 864 // Now use the old way to associate Chrome with the desired protocol. This |
865 // should not be required on Vista but since some applications still read | 865 // should not be required on Vista but since some applications still read |
866 // Software\Classes\http key directly, we have to do this on Vista also. | 866 // Software\Classes\http key directly, we have to do this on Vista also. |
867 | 867 |
868 std::list<RegistryEntry*> entries; | 868 std::list<RegistryEntry*> entries; |
869 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 869 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
870 std::wstring suffix; | 870 std::wstring suffix; |
871 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | 871 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) |
872 suffix = L""; | 872 suffix = L""; |
873 std::wstring chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 873 std::wstring chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
874 std::wstring chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | 874 std::wstring chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); |
875 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | 875 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, |
876 &entries); | 876 &entries); |
877 // Change the default protocol handler for current user. | 877 // Change the default protocol handler for current user. |
878 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 878 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
879 ret = false; | 879 ret = false; |
(...skipping 21 matching lines...) Expand all Loading... |
901 suffix = L""; | 901 suffix = L""; |
902 } | 902 } |
903 | 903 |
904 // Check if Chromium is already registered with this suffix. | 904 // Check if Chromium is already registered with this suffix. |
905 if (IsChromeRegistered(dist, chrome_exe, suffix)) | 905 if (IsChromeRegistered(dist, chrome_exe, suffix)) |
906 return true; | 906 return true; |
907 | 907 |
908 // If user is an admin try to register and return the status. | 908 // If user is an admin try to register and return the status. |
909 if (IsUserAnAdmin()) { | 909 if (IsUserAnAdmin()) { |
910 std::list<RegistryEntry*> entries; | 910 std::list<RegistryEntry*> entries; |
911 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 911 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
912 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 912 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
913 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); | 913 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); |
914 return AddRegistryEntries(HKEY_LOCAL_MACHINE, entries); | 914 return AddRegistryEntries(HKEY_LOCAL_MACHINE, entries); |
915 } | 915 } |
916 | 916 |
917 // If user is not an admin and OS is Vista, try to elevate and register. | 917 // If user is not an admin and OS is Vista, try to elevate and register. |
918 if (elevate_if_not_admin && | 918 if (elevate_if_not_admin && |
919 base::win::GetVersion() >= base::win::VERSION_VISTA && | 919 base::win::GetVersion() >= base::win::VERSION_VISTA && |
920 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) | 920 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) |
921 return true; | 921 return true; |
922 | 922 |
923 // If we got to this point then all we can do is create ProgIds under HKCU | 923 // If we got to this point then all we can do is create ProgIds under HKCU |
924 // on XP as well as Vista. | 924 // on XP as well as Vista. |
925 std::list<RegistryEntry*> entries; | 925 std::list<RegistryEntry*> entries; |
926 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 926 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
927 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); | 927 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); |
928 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 928 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
929 } | 929 } |
930 | 930 |
931 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 931 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
932 const std::wstring& chrome_exe, | 932 const std::wstring& chrome_exe, |
933 const std::wstring& unique_suffix, | 933 const std::wstring& unique_suffix, |
934 const std::wstring& protocol, | 934 const std::wstring& protocol, |
935 bool elevate_if_not_admin) { | 935 bool elevate_if_not_admin) { |
936 if (!dist->CanSetAsDefault()) | 936 if (!dist->CanSetAsDefault()) |
(...skipping 18 matching lines...) Expand all Loading... |
955 // We can do this operation directly. | 955 // We can do this operation directly. |
956 // If we're not registered at all, try to register. If that fails | 956 // If we're not registered at all, try to register. If that fails |
957 // we should give up. | 957 // we should give up. |
958 if (!IsChromeRegistered(dist, chrome_exe, suffix) && | 958 if (!IsChromeRegistered(dist, chrome_exe, suffix) && |
959 !RegisterChromeBrowser(dist, chrome_exe, suffix, false)) { | 959 !RegisterChromeBrowser(dist, chrome_exe, suffix, false)) { |
960 return false; | 960 return false; |
961 } | 961 } |
962 | 962 |
963 // Write in the capabillity for the protocol. | 963 // Write in the capabillity for the protocol. |
964 std::list<RegistryEntry*> entries; | 964 std::list<RegistryEntry*> entries; |
965 STLElementDeleter<std::list<RegistryEntry*>> entries_deleter(&entries); | 965 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
966 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, | 966 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, |
967 &entries); | 967 &entries); |
968 return AddRegistryEntries(HKEY_LOCAL_MACHINE, entries); | 968 return AddRegistryEntries(HKEY_LOCAL_MACHINE, entries); |
969 } else if (elevate_if_not_admin && | 969 } else if (elevate_if_not_admin && |
970 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 970 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
971 // Elevate to do the whole job | 971 // Elevate to do the whole job |
972 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 972 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
973 } else { | 973 } else { |
974 // we need admin rights to register our capability. If we don't | 974 // we need admin rights to register our capability. If we don't |
975 // have them and can't elevate, give up. | 975 // have them and can't elevate, give up. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 chrome_exe.c_str(), // target | 1089 chrome_exe.c_str(), // target |
1090 shortcut.c_str(), // shortcut | 1090 shortcut.c_str(), // shortcut |
1091 chrome_path.c_str(), // working dir | 1091 chrome_path.c_str(), // working dir |
1092 arguments.c_str(), // arguments | 1092 arguments.c_str(), // arguments |
1093 description.c_str(), // description | 1093 description.c_str(), // description |
1094 icon_path.c_str(), // icon file | 1094 icon_path.c_str(), // icon file |
1095 icon_index, // icon index | 1095 icon_index, // icon index |
1096 dist->GetBrowserAppId().c_str()); // app id | 1096 dist->GetBrowserAppId().c_str()); // app id |
1097 } | 1097 } |
1098 } | 1098 } |
OLD | NEW |