Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 10453041: Support for interactive set-chrome-as-default in Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: A minor style-oops. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 s2.begin(), base::CaseInsensitiveCompare<wchar_t>()))) { 604 s2.begin(), base::CaseInsensitiveCompare<wchar_t>()))) {
605 if (one_mismatch) 605 if (one_mismatch)
606 return false; 606 return false;
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 dialog for picking the application to
615 // handle the given protocol. Most importantly, this is used to set the default
616 // handler for http (and, implicitly with it, https). In that case it is also
617 // known as the 'how do you want to open webpages' dialog.
618 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) {
gab 2012/06/06 22:47:21 This method should either: - RegisterChromeForProt
grt (UTC plus 2) 2012/06/07 02:50:36 Don't do this. This is a small, private, easy to
gab 2012/06/07 14:01:51 Ok, but do add it to the contract then, right?
motek. 2012/06/07 14:58:50 Ack.
motek. 2012/06/07 14:58:50 Ack. But see below.
motek. 2012/06/07 14:58:50 Well, perhaps to comments. Enforcement through DCH
gab 2012/06/07 15:18:54 Arg, indeed, for now, because you need to know the
619 DCHECK(protocol);
620 OPENASINFO open_as_info = {};
621 open_as_info.pcszFile = protocol;
622 open_as_info.oaifInFlags =
623 OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | OAIF_REGISTER_EXT;
624 HRESULT hr = SHOpenWithDialog(NULL, &open_as_info);
625 DLOG_IF(WARNING, FAILED(hr)) << "Failed to set as default http handler; hr=0x"
gab 2012/06/06 22:47:21 "http" --> << protocol <<
motek. 2012/06/07 14:58:50 Done.
626 << std::hex << hr;
gab 2012/06/06 22:47:21 I'm not exactly sure which osstream is used for DL
grt (UTC plus 2) 2012/06/07 02:50:36 The stream's lifetime is bound to the log message
gab 2012/06/07 15:18:54 Awesome, good to know :).
627 return SUCCEEDED(hr);
628 }
629
614 // Launches the Windows 7 and Windows 8 application association dialog, which 630 // 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 631 // is the only documented way to make a browser the default browser on
616 // Windows 8. 632 // Windows 8.
617 bool LaunchApplicationAssociationDialog(const string16& app_id) { 633 bool LaunchApplicationAssociationDialog(const string16& app_id) {
618 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; 634 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui;
619 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); 635 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI);
620 if (FAILED(hr)) 636 if (FAILED(hr))
621 return false; 637 return false;
622 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); 638 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str());
623 return SUCCEEDED(hr); 639 return SUCCEEDED(hr);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 KEY_READ).Valid(); 954 KEY_READ).Valid();
939 } 955 }
940 956
941 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 957 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
942 int shell_change, 958 int shell_change,
943 const string16& chrome_exe, 959 const string16& chrome_exe,
944 bool elevate_if_not_admin) { 960 bool elevate_if_not_admin) {
945 if (!dist->CanSetAsDefault()) 961 if (!dist->CanSetAsDefault())
946 return false; 962 return false;
947 963
964 // Windows 8 does not permit making a browser default just like that.
965 // This process needs to be routed through the system's UI. Use
966 // ShowMakeChromeDefaultSystemUI instead (below).
967 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
968 NOTREACHED();
969 return false;
970 }
971
948 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); 972 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin);
949 973
950 bool ret = true; 974 bool ret = true;
951 // First use the new "recommended" way on Vista to make Chrome default 975 // First use the new "recommended" way on Vista to make Chrome default
952 // browser. 976 // browser.
953 string16 app_name = dist->GetApplicationName(); 977 string16 app_name = dist->GetApplicationName();
954 string16 app_suffix; 978 string16 app_suffix;
955 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) 979 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix))
956 app_name += app_suffix; 980 app_name += app_suffix;
957 981
958 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 982 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 983 // On Windows Vista and Win7 we still can set ourselves via the
970 // the IApplicationAssociationRegistration interface. 984 // the IApplicationAssociationRegistration interface.
971 VLOG(1) << "Registering Chrome as default browser on Vista."; 985 VLOG(1) << "Registering Chrome as default browser on Vista.";
972 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 986 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
973 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 987 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
974 NULL, CLSCTX_INPROC); 988 NULL, CLSCTX_INPROC);
975 if (SUCCEEDED(hr)) { 989 if (SUCCEEDED(hr)) {
976 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 990 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
977 hr = pAAR->SetAppAsDefault(app_name.c_str(), 991 hr = pAAR->SetAppAsDefault(app_name.c_str(),
978 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); 992 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 ret = false; 1034 ret = false;
1021 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; 1035 LOG(ERROR) << "Could not make Chrome default browser (XP/system level).";
1022 } 1036 }
1023 1037
1024 // Send Windows notification event so that it can update icons for 1038 // Send Windows notification event so that it can update icons for
1025 // file associations. 1039 // file associations.
1026 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1040 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1027 return ret; 1041 return ret;
1028 } 1042 }
1029 1043
1044 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist,
1045 const string16& chrome_exe) {
1046 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8);
1047 if (!dist->CanSetAsDefault())
1048 return false;
1049
1050 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true))
1051 return false;
1052
1053 // On Windows 8, you can't set yourself as the default handler
1054 // programatically. In other words IApplicationAssociationRegistration
1055 // has been rendered useless. What you can do is to launch
1056 // "Set Program Associations" section of the "Default Programs"
1057 // control panel, which is a mess, or pop the concise "How you want to open
1058 // webpages"? dialog. We choose the latter.
gab 2012/06/06 22:47:21 The '?' goes inside the quotes right?
gab 2012/06/06 22:47:21 choose --> chose (i.e. chose is the past tense of
grt (UTC plus 2) 2012/06/07 02:50:36 Dunno. It sounds fine to me as-is.
motek. 2012/06/07 14:58:50 Done.
motek. 2012/06/07 14:58:50 This is as intended. I find the present tense to b
motek. 2012/06/07 14:58:50 Ack.
1059 return LaunchSelectDefaultProtocolHandlerDialog(L"http");
1060 }
1061
1030 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, 1062 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist,
1031 const string16& chrome_exe, 1063 const string16& chrome_exe,
1032 const string16& protocol) { 1064 const string16& protocol) {
1033 if (!dist->CanSetAsDefault()) 1065 if (!dist->CanSetAsDefault())
1034 return false; 1066 return false;
1035 1067
1036 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); 1068 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true);
1037 1069
1038 bool ret = true; 1070 bool ret = true;
1039 // First use the new "recommended" way on Vista to make Chrome default 1071 // First use the new "recommended" way on Vista to make Chrome default
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 chrome_exe.c_str(), 1323 chrome_exe.c_str(),
1292 shortcut.c_str(), 1324 shortcut.c_str(),
1293 chrome_path.c_str(), 1325 chrome_path.c_str(),
1294 arguments.c_str(), 1326 arguments.c_str(),
1295 description.c_str(), 1327 description.c_str(),
1296 icon_path.c_str(), 1328 icon_path.c_str(),
1297 icon_index, 1329 icon_index,
1298 dist->GetBrowserAppId().c_str(), 1330 dist->GetBrowserAppId().c_str(),
1299 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1331 ConvertShellUtilShortcutOptionsToFileUtil(options));
1300 } 1332 }
OLDNEW
« chrome/installer/util/shell_util.h ('K') | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698