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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". | 70 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". |
71 static string16 GetCapabilitiesKey(BrowserDistribution* dist, | 71 static string16 GetCapabilitiesKey(BrowserDistribution* dist, |
72 const string16& suffix) { | 72 const string16& suffix) { |
73 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); | 73 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); |
74 } | 74 } |
75 | 75 |
76 // This method returns a list of all the registry entries that | 76 // This method returns a list of all the registry entries that |
77 // are needed to register Chromium ProgIds. | 77 // are needed to register Chromium ProgIds. |
78 // These entries should be registered in HKCU for user-level installs and in | 78 // These entries should be registered in HKCU for user-level installs and in |
79 // HKLM for system-level installs. | 79 // HKLM for system-level installs. |
80 // TODO (gab): Extract the Windows 8 only registrations out of this function. | |
81 static bool GetProgIdEntries(BrowserDistribution* dist, | 80 static bool GetProgIdEntries(BrowserDistribution* dist, |
82 const string16& chrome_exe, | 81 const string16& chrome_exe, |
83 const string16& suffix, | 82 const string16& suffix, |
84 std::list<RegistryEntry*>* entries) { | 83 std::list<RegistryEntry*>* entries) { |
85 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); | 84 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); |
86 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 85 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
87 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); | 86 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); |
88 // For user-level installs: entries for the app id and DelegateExecute verb | 87 // For user-level installs: entries for the app id and DelegateExecute verb |
89 // handler will be in HKCU; thus we do not need a suffix on those entries. | 88 // handler will be in HKCU; thus we do not need a suffix on those entries. |
90 string16 app_id(dist->GetBrowserAppId()); | 89 string16 app_id(dist->GetBrowserAppId()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); | 141 chrome_html_prog_id + ShellUtil::kRegDefaultIcon, icon_path)); |
143 entries->push_front(new RegistryEntry( | 142 entries->push_front(new RegistryEntry( |
144 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); | 143 chrome_html_prog_id + ShellUtil::kRegShellOpen, open_cmd)); |
145 if (set_delegate_execute) { | 144 if (set_delegate_execute) { |
146 entries->push_front(new RegistryEntry( | 145 entries->push_front(new RegistryEntry( |
147 chrome_html_prog_id + ShellUtil::kRegShellOpen, | 146 chrome_html_prog_id + ShellUtil::kRegShellOpen, |
148 ShellUtil::kRegDelegateExecute, delegate_guid)); | 147 ShellUtil::kRegDelegateExecute, delegate_guid)); |
149 } | 148 } |
150 | 149 |
151 // The following entries are required as of Windows 8, but do not | 150 // The following entries are required as of Windows 8, but do not |
152 // depend on the DelegateExecute. | 151 // depend on the DelegateExecute verb handler being set. |
153 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 152 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
154 entries->push_front(new RegistryEntry( | 153 entries->push_front(new RegistryEntry( |
155 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); | 154 chrome_html_prog_id, ShellUtil::kRegAppUserModelId, app_id)); |
156 | 155 |
157 // Add \Software\Classes\ChromeHTML\Application entries | 156 // Add \Software\Classes\ChromeHTML\Application entries |
158 string16 chrome_application(chrome_html_prog_id + | 157 string16 chrome_application(chrome_html_prog_id + |
159 ShellUtil::kRegApplication); | 158 ShellUtil::kRegApplication); |
160 entries->push_front(new RegistryEntry( | 159 entries->push_front(new RegistryEntry( |
161 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); | 160 chrome_application, ShellUtil::kRegAppUserModelId, app_id)); |
162 entries->push_front(new RegistryEntry( | 161 entries->push_front(new RegistryEntry( |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // This method registers Chrome on Vista by launching an elevated setup.exe. | 482 // This method registers Chrome on Vista by launching an elevated setup.exe. |
484 // That will show the user the standard Vista elevation prompt. If the user | 483 // That will show the user the standard Vista elevation prompt. If the user |
485 // accepts it the new process will make the necessary changes and return SUCCESS | 484 // accepts it the new process will make the necessary changes and return SUCCESS |
486 // that we capture and return. | 485 // that we capture and return. |
487 // If protocol is non-empty we will also register Chrome as being capable of | 486 // If protocol is non-empty we will also register Chrome as being capable of |
488 // handling the protocol. | 487 // handling the protocol. |
489 bool ElevateAndRegisterChrome(BrowserDistribution* dist, | 488 bool ElevateAndRegisterChrome(BrowserDistribution* dist, |
490 const string16& chrome_exe, | 489 const string16& chrome_exe, |
491 const string16& suffix, | 490 const string16& suffix, |
492 const string16& protocol) { | 491 const string16& protocol) { |
| 492 // Only user-level installs prior to Windows 8 should need to elevate to |
| 493 // register. |
| 494 DCHECK(InstallUtil::IsPerUserInstall(chrome_exe.c_str())); |
| 495 DCHECK_LT(base::win::GetVersion(), base::win::VERSION_WIN8); |
493 FilePath exe_path = | 496 FilePath exe_path = |
494 FilePath::FromWStringHack(chrome_exe).DirName() | 497 FilePath::FromWStringHack(chrome_exe).DirName() |
495 .Append(installer::kSetupExe); | 498 .Append(installer::kSetupExe); |
496 if (!file_util::PathExists(exe_path)) { | 499 if (!file_util::PathExists(exe_path)) { |
497 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 500 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
498 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 501 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
499 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); | 502 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); |
500 string16 uninstall_string; | 503 string16 uninstall_string; |
501 key.ReadValue(installer::kUninstallStringField, &uninstall_string); | 504 key.ReadValue(installer::kUninstallStringField, &uninstall_string); |
502 CommandLine command_line = CommandLine::FromString(uninstall_string); | 505 CommandLine command_line = CommandLine::FromString(uninstall_string); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 else | 585 else |
583 one_mismatch = true; | 586 one_mismatch = true; |
584 } | 587 } |
585 } | 588 } |
586 return true; | 589 return true; |
587 } | 590 } |
588 | 591 |
589 // Launches the Windows 7 and Windows 8 application association dialog, which | 592 // Launches the Windows 7 and Windows 8 application association dialog, which |
590 // is the only documented way to make a browser the default browser on | 593 // is the only documented way to make a browser the default browser on |
591 // Windows 8. | 594 // Windows 8. |
592 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 595 bool LaunchApplicationAssociationDialog() { |
593 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 596 const wchar_t* protocol = L"http"; |
594 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 597 OPENASINFO open_as_info = {}; |
595 if (FAILED(hr)) | 598 open_as_info.pcszFile = protocol; |
596 return false; | 599 open_as_info.oaifInFlags = |
597 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 600 OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | OAIF_REGISTER_EXT; |
| 601 HRESULT hr = SHOpenWithDialog(NULL, &open_as_info); |
598 return SUCCEEDED(hr); | 602 return SUCCEEDED(hr); |
599 } | 603 } |
600 | 604 |
601 uint32 ConvertShellUtilShortcutOptionsToFileUtil(uint32 options) { | 605 uint32 ConvertShellUtilShortcutOptionsToFileUtil(uint32 options) { |
602 uint32 converted_options = 0; | 606 uint32 converted_options = 0; |
603 if (options & ShellUtil::SHORTCUT_DUAL_MODE) | 607 if (options & ShellUtil::SHORTCUT_DUAL_MODE) |
604 converted_options |= file_util::SHORTCUT_DUAL_MODE; | 608 converted_options |= file_util::SHORTCUT_DUAL_MODE; |
605 if (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) | 609 if (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) |
606 converted_options |= file_util::SHORTCUT_CREATE_ALWAYS; | 610 converted_options |= file_util::SHORTCUT_CREATE_ALWAYS; |
607 return converted_options; | 611 return converted_options; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 key = ShellUtil::kRegClasses; | 644 key = ShellUtil::kRegClasses; |
641 key.push_back(FilePath::kSeparators[0]); | 645 key.push_back(FilePath::kSeparators[0]); |
642 key.append(ShellUtil::kChromeHTMLProgId); | 646 key.append(ShellUtil::kChromeHTMLProgId); |
643 key.append(suffix); | 647 key.append(suffix); |
644 key.append(ShellUtil::kRegShellOpen); | 648 key.append(ShellUtil::kRegShellOpen); |
645 InstallUtil::DeleteRegistryValue(root_key, key, | 649 InstallUtil::DeleteRegistryValue(root_key, key, |
646 ShellUtil::kRegDelegateExecute); | 650 ShellUtil::kRegDelegateExecute); |
647 } | 651 } |
648 } | 652 } |
649 | 653 |
| 654 // Returns the root registry key (HKLM or HKCU) into which system registration |
| 655 // for default protocols must be placed. As of Windows 8 everything can go in |
| 656 // HKCU for per-user installs. |
| 657 HKEY DetermineRegistrationRoot(bool is_per_user) { |
| 658 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? |
| 659 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 660 } |
| 661 |
650 } // namespace | 662 } // namespace |
651 | 663 |
652 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 664 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
653 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 665 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
654 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 666 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
655 const wchar_t* ShellUtil::kRegStartMenuInternet = | 667 const wchar_t* ShellUtil::kRegStartMenuInternet = |
656 L"Software\\Clients\\StartMenuInternet"; | 668 L"Software\\Clients\\StartMenuInternet"; |
657 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 669 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
658 const wchar_t* ShellUtil::kRegRegisteredApplications = | 670 const wchar_t* ShellUtil::kRegRegisteredApplications = |
659 L"Software\\RegisteredApplications"; | 671 L"Software\\RegisteredApplications"; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 | 917 |
906 return RegKey(HKEY_LOCAL_MACHINE, | 918 return RegKey(HKEY_LOCAL_MACHINE, |
907 RegistryEntry::GetBrowserClientKey(dist, *entry).c_str(), | 919 RegistryEntry::GetBrowserClientKey(dist, *entry).c_str(), |
908 KEY_READ).Valid(); | 920 KEY_READ).Valid(); |
909 } | 921 } |
910 | 922 |
911 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 923 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
912 int shell_change, | 924 int shell_change, |
913 const string16& chrome_exe, | 925 const string16& chrome_exe, |
914 bool elevate_if_not_admin) { | 926 bool elevate_if_not_admin) { |
| 927 DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin()); |
| 928 |
915 if (!dist->CanSetAsDefault()) | 929 if (!dist->CanSetAsDefault()) |
916 return false; | 930 return false; |
917 | 931 |
| 932 // Windows 8 does not permit making a browser default just like that. |
| 933 // This process needs to be routed through the system's UI. Use |
| 934 // ShowMakeChromeDefaultSystemUI instead (below). |
| 935 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| 936 return false; |
| 937 |
918 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); | 938 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); |
919 | 939 |
920 bool ret = true; | 940 bool ret = true; |
921 // First use the new "recommended" way on Vista to make Chrome default | 941 // First use the new "recommended" way on Vista to make Chrome default |
922 // browser. | 942 // browser. |
923 string16 app_name = dist->GetApplicationName(); | 943 string16 app_name = dist->GetApplicationName(); |
924 string16 app_suffix; | 944 string16 app_suffix; |
925 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) | 945 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) |
926 app_name += app_suffix; | 946 app_name += app_suffix; |
927 | 947 |
928 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 948 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
929 // On Windows 8, you can't set yourself as the default handler | 949 // On Windows 8, you can't set yourself as the default handler |
930 // programatically. In other words IApplicationAssociationRegistration | 950 // programatically. In other words IApplicationAssociationRegistration |
931 // has been rendered useless. What you can do is to launch | 951 // has been rendered useless. What you can do is to launch |
932 // "Set Program Associations" section of the "Default Programs" | 952 // "Set Program Associations" section of the "Default Programs" |
933 // control panel. This action does not require elevation and we | 953 // control panel. This action does not require elevation and we |
934 // don't get to control window activation. More info at: | 954 // don't get to control window activation. More info at: |
935 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx | 955 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx |
936 return LaunchApplicationAssociationDialog(app_name.c_str()); | 956 // Since this will show a modal UI elementm this has been split into |
| 957 // a separate flow (see ShowMakeChromeDefaultSystemUI). |
| 958 return false; |
| 959 } |
937 | 960 |
938 } else if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 961 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
939 // On Windows Vista and Win7 we still can set ourselves via the | 962 // On Windows Vista and Win7 we still can set ourselves via the |
940 // the IApplicationAssociationRegistration interface. | 963 // the IApplicationAssociationRegistration interface. |
941 VLOG(1) << "Registering Chrome as default browser on Vista."; | 964 VLOG(1) << "Registering Chrome as default browser on Vista."; |
942 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 965 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
943 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 966 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
944 NULL, CLSCTX_INPROC); | 967 NULL, CLSCTX_INPROC); |
945 if (SUCCEEDED(hr)) { | 968 if (SUCCEEDED(hr)) { |
946 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 969 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
947 hr = pAAR->SetAppAsDefault(app_name.c_str(), | 970 hr = pAAR->SetAppAsDefault(app_name.c_str(), |
948 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); | 971 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 ret = false; | 1013 ret = false; |
991 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | 1014 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; |
992 } | 1015 } |
993 | 1016 |
994 // Send Windows notification event so that it can update icons for | 1017 // Send Windows notification event so that it can update icons for |
995 // file associations. | 1018 // file associations. |
996 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 1019 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
997 return ret; | 1020 return ret; |
998 } | 1021 } |
999 | 1022 |
| 1023 bool ShellUtil::ShowMakeChromeDefaultSystemUI( |
| 1024 BrowserDistribution* dist, int shell_change, const string16& chrome_exe, |
| 1025 bool elevate_if_not_admin) { |
| 1026 if (!dist->CanSetAsDefault()) |
| 1027 return false; |
| 1028 |
| 1029 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); |
| 1030 |
| 1031 // On Windows 8, you can't set yourself as the default handler |
| 1032 // programatically. In other words IApplicationAssociationRegistration |
| 1033 // has been rendered useless. What you can do is to launch |
| 1034 // "Set Program Associations" section of the "Default Programs" |
| 1035 // control panel. This action does not require elevation and we |
| 1036 // don't get to control window activation. More info at: |
| 1037 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx |
| 1038 return LaunchApplicationAssociationDialog(); |
| 1039 } |
| 1040 |
1000 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1041 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, |
1001 const string16& chrome_exe, | 1042 const string16& chrome_exe, |
1002 const string16& protocol) { | 1043 const string16& protocol) { |
1003 if (!dist->CanSetAsDefault()) | 1044 if (!dist->CanSetAsDefault()) |
1004 return false; | 1045 return false; |
1005 | 1046 |
1006 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); | 1047 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); |
1007 | 1048 |
1008 bool ret = true; | 1049 bool ret = true; |
1009 // First use the new "recommended" way on Vista to make Chrome default | 1050 // First use the new "recommended" way on Vista to make Chrome default |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 suffix = L""; | 1111 suffix = L""; |
1071 } | 1112 } |
1072 | 1113 |
1073 // TODO(grt): remove this on or after 2012-08-01; see impl for details. | 1114 // TODO(grt): remove this on or after 2012-08-01; see impl for details. |
1074 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe, suffix); | 1115 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe, suffix); |
1075 | 1116 |
1076 // Check if Chromium is already registered with this suffix. | 1117 // Check if Chromium is already registered with this suffix. |
1077 if (IsChromeRegistered(dist, chrome_exe, suffix)) | 1118 if (IsChromeRegistered(dist, chrome_exe, suffix)) |
1078 return true; | 1119 return true; |
1079 | 1120 |
1080 // If user is an admin try to register and return the status. | 1121 bool user_level = InstallUtil::IsPerUserInstall(chrome_exe.c_str()); |
1081 if (IsUserAnAdmin()) { | 1122 HKEY root = DetermineRegistrationRoot(user_level); |
| 1123 |
| 1124 // Do the full registration if we can do it at user-level or if the user is an |
| 1125 // admin. |
| 1126 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { |
1082 std::list<RegistryEntry*> progids; | 1127 std::list<RegistryEntry*> progids; |
1083 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); | 1128 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); |
1084 std::list<RegistryEntry*> sys_entries; | 1129 std::list<RegistryEntry*> sys_entries; |
1085 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); | 1130 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); |
1086 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); | 1131 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); |
1087 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); | 1132 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); |
1088 return AddRegistryEntries( | 1133 return AddRegistryEntries(user_level ? HKEY_CURRENT_USER : |
1089 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 1134 HKEY_LOCAL_MACHINE, |
1090 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, | 1135 progids) && |
1091 progids) && | 1136 AddRegistryEntries(root, sys_entries); |
1092 AddRegistryEntries(HKEY_LOCAL_MACHINE, sys_entries); | |
1093 } | 1137 } |
1094 | 1138 |
1095 // If user is not an admin and OS is Vista, try to elevate and register. | 1139 // If the user is not an admin and OS is between Vista and Windows 7 |
| 1140 // inclusively, try to elevate and register. This is only intended for |
| 1141 // user-level installs as system-level installs should always be run with |
| 1142 // admin rights. |
1096 if (elevate_if_not_admin && | 1143 if (elevate_if_not_admin && |
1097 base::win::GetVersion() >= base::win::VERSION_VISTA && | 1144 base::win::GetVersion() >= base::win::VERSION_VISTA && |
1098 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) | 1145 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) |
1099 return true; | 1146 return true; |
1100 | 1147 |
1101 // If we got to this point then all we can do is create ProgIds under HKCU | 1148 // If we got to this point then all we can do is create ProgIds under HKCU. |
1102 // on XP as well as Vista. | |
1103 std::list<RegistryEntry*> entries; | 1149 std::list<RegistryEntry*> entries; |
1104 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1150 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
1105 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); | 1151 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); |
1106 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 1152 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
1107 } | 1153 } |
1108 | 1154 |
1109 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 1155 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
1110 const string16& chrome_exe, | 1156 const string16& chrome_exe, |
1111 const string16& unique_suffix, | 1157 const string16& unique_suffix, |
1112 const string16& protocol, | 1158 const string16& protocol, |
1113 bool elevate_if_not_admin) { | 1159 bool elevate_if_not_admin) { |
1114 if (!dist->CanSetAsDefault()) | 1160 if (!dist->CanSetAsDefault()) |
1115 return false; | 1161 return false; |
1116 | 1162 |
1117 // Figure out we need to append a suffix to the registry entries to | 1163 // Figure out we need to append a suffix to the registry entries to |
1118 // make them unique. | 1164 // make them unique. |
1119 string16 suffix; | 1165 string16 suffix; |
1120 if (!unique_suffix.empty()) { | 1166 if (!unique_suffix.empty()) { |
1121 suffix = unique_suffix; | 1167 suffix = unique_suffix; |
1122 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1168 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && |
1123 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && | 1169 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && |
1124 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { | 1170 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { |
1125 suffix = L""; | 1171 suffix = L""; |
1126 } | 1172 } |
1127 | 1173 |
1128 // Check if Chromium is already registered with this suffix. | 1174 // Check if Chromium is already registered with this suffix. |
1129 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) | 1175 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) |
1130 return true; | 1176 return true; |
1131 | 1177 |
1132 if (IsUserAnAdmin()) { | 1178 HKEY root = DetermineRegistrationRoot( |
| 1179 InstallUtil::IsPerUserInstall(chrome_exe.c_str())); |
| 1180 |
| 1181 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { |
1133 // We can do this operation directly. | 1182 // We can do this operation directly. |
1134 // If we're not registered at all, try to register. If that fails | 1183 // If we're not registered at all, try to register. If that fails |
1135 // we should give up. | 1184 // we should give up. |
1136 if (!IsChromeRegistered(dist, chrome_exe, suffix) && | 1185 if (!IsChromeRegistered(dist, chrome_exe, suffix) && |
1137 !RegisterChromeBrowser(dist, chrome_exe, suffix, false)) { | 1186 !RegisterChromeBrowser(dist, chrome_exe, suffix, false)) { |
1138 return false; | 1187 return false; |
1139 } | 1188 } |
1140 | 1189 |
1141 // Write in the capabillity for the protocol. | 1190 // Write in the capabillity for the protocol. |
1142 std::list<RegistryEntry*> entries; | 1191 std::list<RegistryEntry*> entries; |
1143 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1192 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
1144 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, | 1193 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, |
1145 &entries); | 1194 &entries); |
1146 return AddRegistryEntries(HKEY_LOCAL_MACHINE, entries); | 1195 return AddRegistryEntries(root, entries); |
1147 } else if (elevate_if_not_admin && | 1196 } else if (elevate_if_not_admin && |
1148 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1197 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1149 // Elevate to do the whole job | 1198 // Elevate to do the whole job |
1150 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 1199 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
1151 } else { | 1200 } else { |
1152 // we need admin rights to register our capability. If we don't | 1201 // Admin rights are required to register capabilities before Windows 8. |
1153 // have them and can't elevate, give up. | |
1154 return false; | 1202 return false; |
1155 } | 1203 } |
1156 } | 1204 } |
1157 | 1205 |
1158 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, | 1206 bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, |
1159 int shell_change, uint32 options) { | 1207 int shell_change, uint32 options) { |
1160 // Only SHORTCUT_ALTERNATE is a valid option for this function. | 1208 // Only SHORTCUT_ALTERNATE is a valid option for this function. |
1161 DCHECK(!options || options == ShellUtil::SHORTCUT_ALTERNATE); | 1209 DCHECK(!options || options == ShellUtil::SHORTCUT_ALTERNATE); |
1162 | 1210 |
1163 string16 shortcut_name; | 1211 string16 shortcut_name; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 chrome_exe.c_str(), | 1309 chrome_exe.c_str(), |
1262 shortcut.c_str(), | 1310 shortcut.c_str(), |
1263 chrome_path.c_str(), | 1311 chrome_path.c_str(), |
1264 arguments.c_str(), | 1312 arguments.c_str(), |
1265 description.c_str(), | 1313 description.c_str(), |
1266 icon_path.c_str(), | 1314 icon_path.c_str(), |
1267 icon_index, | 1315 icon_index, |
1268 dist->GetBrowserAppId().c_str(), | 1316 dist->GetBrowserAppId().c_str(), |
1269 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1317 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
1270 } | 1318 } |
OLD | NEW |