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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 else | 607 else |
608 one_mismatch = true; | 608 one_mismatch = true; |
609 } | 609 } |
610 } | 610 } |
611 return true; | 611 return true; |
612 } | 612 } |
613 | 613 |
614 // Launches the Windows 7 and Windows 8 application association dialog, which | 614 // Launches the Windows 7 and Windows 8 application association dialog, which |
615 // is the only documented way to make a browser the default browser on | 615 // is the only documented way to make a browser the default browser on |
616 // Windows 8. | 616 // Windows 8. |
617 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 617 bool LaunchApplicationAssociationDialog() { |
grt (UTC plus 2)
2012/05/28 20:47:02
please update the comment and function name since
gab
2012/05/29 16:05:19
Also, can you leave the old call around? It will n
motek.
2012/05/31 21:59:04
Done.
motek.
2012/05/31 21:59:04
Done.
| |
618 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 618 const wchar_t* protocol = L"http"; |
grt (UTC plus 2)
2012/05/28 20:47:02
static const wchar_t protocol[] = L"http";
to be s
motek.
2012/05/31 21:59:04
Done.
| |
619 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 619 OPENASINFO open_as_info = {}; |
620 if (FAILED(hr)) | 620 open_as_info.pcszFile = protocol; |
621 return false; | 621 open_as_info.oaifInFlags = |
622 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 622 OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | OAIF_REGISTER_EXT; |
623 HRESULT hr = SHOpenWithDialog(NULL, &open_as_info); | |
623 return SUCCEEDED(hr); | 624 return SUCCEEDED(hr); |
grt (UTC plus 2)
2012/05/28 20:47:02
how about adding this just before the return:
DLOG
motek.
2012/05/31 21:59:04
Done.
| |
624 } | 625 } |
625 | 626 |
626 uint32 ConvertShellUtilShortcutOptionsToFileUtil(uint32 options) { | 627 uint32 ConvertShellUtilShortcutOptionsToFileUtil(uint32 options) { |
627 uint32 converted_options = 0; | 628 uint32 converted_options = 0; |
628 if (options & ShellUtil::SHORTCUT_DUAL_MODE) | 629 if (options & ShellUtil::SHORTCUT_DUAL_MODE) |
629 converted_options |= file_util::SHORTCUT_DUAL_MODE; | 630 converted_options |= file_util::SHORTCUT_DUAL_MODE; |
630 if (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) | 631 if (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) |
631 converted_options |= file_util::SHORTCUT_CREATE_ALWAYS; | 632 converted_options |= file_util::SHORTCUT_CREATE_ALWAYS; |
632 return converted_options; | 633 return converted_options; |
633 } | 634 } |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 KEY_READ).Valid(); | 939 KEY_READ).Valid(); |
939 } | 940 } |
940 | 941 |
941 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 942 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
942 int shell_change, | 943 int shell_change, |
943 const string16& chrome_exe, | 944 const string16& chrome_exe, |
944 bool elevate_if_not_admin) { | 945 bool elevate_if_not_admin) { |
945 if (!dist->CanSetAsDefault()) | 946 if (!dist->CanSetAsDefault()) |
946 return false; | 947 return false; |
947 | 948 |
949 // Windows 8 does not permit making a browser default just like that. | |
950 // This process needs to be routed through the system's UI. Use | |
951 // ShowMakeChromeDefaultSystemUI instead (below). | |
952 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | |
953 return false; | |
grt (UTC plus 2)
2012/05/28 20:47:02
should there be a NOTREACHED() here?
motek.
2012/05/31 21:59:04
Done.
| |
954 | |
948 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); | 955 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); |
949 | 956 |
950 bool ret = true; | 957 bool ret = true; |
951 // First use the new "recommended" way on Vista to make Chrome default | 958 // First use the new "recommended" way on Vista to make Chrome default |
952 // browser. | 959 // browser. |
953 string16 app_name = dist->GetApplicationName(); | 960 string16 app_name = dist->GetApplicationName(); |
954 string16 app_suffix; | 961 string16 app_suffix; |
955 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) | 962 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) |
956 app_name += app_suffix; | 963 app_name += app_suffix; |
957 | 964 |
958 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 965 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
959 // On Windows 8, you can't set yourself as the default handler | |
960 // programatically. In other words IApplicationAssociationRegistration | |
961 // has been rendered useless. What you can do is to launch | |
962 // "Set Program Associations" section of the "Default Programs" | |
963 // control panel. This action does not require elevation and we | |
964 // don't get to control window activation. More info at: | |
965 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx | |
966 return LaunchApplicationAssociationDialog(app_name.c_str()); | |
967 | |
968 } else if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
969 // On Windows Vista and Win7 we still can set ourselves via the | 966 // On Windows Vista and Win7 we still can set ourselves via the |
970 // the IApplicationAssociationRegistration interface. | 967 // the IApplicationAssociationRegistration interface. |
971 VLOG(1) << "Registering Chrome as default browser on Vista."; | 968 VLOG(1) << "Registering Chrome as default browser on Vista."; |
972 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 969 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
973 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 970 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
974 NULL, CLSCTX_INPROC); | 971 NULL, CLSCTX_INPROC); |
975 if (SUCCEEDED(hr)) { | 972 if (SUCCEEDED(hr)) { |
976 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 973 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
977 hr = pAAR->SetAppAsDefault(app_name.c_str(), | 974 hr = pAAR->SetAppAsDefault(app_name.c_str(), |
978 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); | 975 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1020 ret = false; | 1017 ret = false; |
1021 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | 1018 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; |
1022 } | 1019 } |
1023 | 1020 |
1024 // Send Windows notification event so that it can update icons for | 1021 // Send Windows notification event so that it can update icons for |
1025 // file associations. | 1022 // file associations. |
1026 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 1023 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
1027 return ret; | 1024 return ret; |
1028 } | 1025 } |
1029 | 1026 |
1027 bool ShellUtil::ShowMakeChromeDefaultSystemUI( | |
1028 BrowserDistribution* dist, int shell_change, const string16& chrome_exe, | |
grt (UTC plus 2)
2012/05/28 20:47:02
put each parameters on its own line, indented four
motek.
2012/05/31 21:59:04
Done.
| |
1029 bool elevate_if_not_admin) { | |
1030 if (!dist->CanSetAsDefault()) | |
1031 return false; | |
1032 | |
gab
2012/05/29 16:05:19
This is only for Win8+ right? If so, can you add a
motek.
2012/05/31 21:59:04
I don't know. It is not only Windows 8. This dialo
gab
2012/05/31 22:17:20
Thanks, my point is that it will never be used on
| |
1033 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); | |
gab
2012/05/29 16:05:19
Note to self (and reminder to my future reviewers!
motek.
2012/05/31 21:59:04
Well, OK.
| |
1034 | |
1035 // On Windows 8, you can't set yourself as the default handler | |
1036 // programatically. In other words IApplicationAssociationRegistration | |
1037 // has been rendered useless. What you can do is to launch | |
1038 // "Set Program Associations" section of the "Default Programs" | |
1039 // control panel. This action does not require elevation and we | |
grt (UTC plus 2)
2012/05/28 20:47:02
i suggest replacing the last few lines of this com
motek.
2012/05/31 21:59:04
Done.
| |
1040 // don't get to control window activation. More info at: | |
1041 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx | |
1042 return LaunchApplicationAssociationDialog(); | |
1043 } | |
1044 | |
1030 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1045 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, |
1031 const string16& chrome_exe, | 1046 const string16& chrome_exe, |
1032 const string16& protocol) { | 1047 const string16& protocol) { |
1033 if (!dist->CanSetAsDefault()) | 1048 if (!dist->CanSetAsDefault()) |
1034 return false; | 1049 return false; |
1035 | 1050 |
1036 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); | 1051 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); |
1037 | 1052 |
1038 bool ret = true; | 1053 bool ret = true; |
1039 // First use the new "recommended" way on Vista to make Chrome default | 1054 // First use the new "recommended" way on Vista to make Chrome default |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 chrome_exe.c_str(), | 1306 chrome_exe.c_str(), |
1292 shortcut.c_str(), | 1307 shortcut.c_str(), |
1293 chrome_path.c_str(), | 1308 chrome_path.c_str(), |
1294 arguments.c_str(), | 1309 arguments.c_str(), |
1295 description.c_str(), | 1310 description.c_str(), |
1296 icon_path.c_str(), | 1311 icon_path.c_str(), |
1297 icon_index, | 1312 icon_index, |
1298 dist->GetBrowserAppId().c_str(), | 1313 dist->GetBrowserAppId().c_str(), |
1299 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1314 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
1300 } | 1315 } |
OLD | NEW |