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

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: Addressed reviewers' remarks. 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
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 http (and https) protocol. Also known as 'how do you want to open
616 // webpages' dialog.
617 bool LaunchSelectDefaultHttpHandlerDialog(const wchar_t* protocol) {
grt (UTC plus 2) 2012/06/04 02:41:14 Replace "Http" with "Protocol" in the function nam
motek. 2012/06/06 18:30:41 Done.
618 OPENASINFO open_as_info = {};
grt (UTC plus 2) 2012/06/04 02:41:14 DCHECK(protocol); just before this
motek. 2012/06/06 18:30:41 Done.
619 open_as_info.pcszFile = protocol;
620 open_as_info.oaifInFlags =
621 OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | OAIF_REGISTER_EXT;
622 HRESULT hr = SHOpenWithDialog(NULL, &open_as_info);
623 DLOG_IF(WARNING, FAILED(hr)) << "Failed to set as default http handler; hr=0x"
624 << std::hex << hr;
625 return SUCCEEDED(hr);
626 }
627
614 // Launches the Windows 7 and Windows 8 application association dialog, which 628 // 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 629 // is the only documented way to make a browser the default browser on
616 // Windows 8. 630 // Windows 8.
617 bool LaunchApplicationAssociationDialog(const string16& app_id) { 631 bool LaunchApplicationAssociationDialog(const string16& app_id) {
618 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; 632 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui;
619 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); 633 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI);
620 if (FAILED(hr)) 634 if (FAILED(hr))
621 return false; 635 return false;
622 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); 636 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str());
623 return SUCCEEDED(hr); 637 return SUCCEEDED(hr);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 KEY_READ).Valid(); 952 KEY_READ).Valid();
939 } 953 }
940 954
941 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 955 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
942 int shell_change, 956 int shell_change,
943 const string16& chrome_exe, 957 const string16& chrome_exe,
944 bool elevate_if_not_admin) { 958 bool elevate_if_not_admin) {
945 if (!dist->CanSetAsDefault()) 959 if (!dist->CanSetAsDefault())
946 return false; 960 return false;
947 961
962 // Windows 8 does not permit making a browser default just like that.
963 // This process needs to be routed through the system's UI. Use
964 // ShowMakeChromeDefaultSystemUI instead (below).
965 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
966 NOTREACHED();
967 return false;
968 }
969
948 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); 970 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin);
949 971
950 bool ret = true; 972 bool ret = true;
951 // First use the new "recommended" way on Vista to make Chrome default 973 // First use the new "recommended" way on Vista to make Chrome default
952 // browser. 974 // browser.
953 string16 app_name = dist->GetApplicationName(); 975 string16 app_name = dist->GetApplicationName();
954 string16 app_suffix; 976 string16 app_suffix;
955 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) 977 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix))
956 app_name += app_suffix; 978 app_name += app_suffix;
957 979
958 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 980 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 981 // On Windows Vista and Win7 we still can set ourselves via the
970 // the IApplicationAssociationRegistration interface. 982 // the IApplicationAssociationRegistration interface.
971 VLOG(1) << "Registering Chrome as default browser on Vista."; 983 VLOG(1) << "Registering Chrome as default browser on Vista.";
972 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 984 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
973 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 985 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
974 NULL, CLSCTX_INPROC); 986 NULL, CLSCTX_INPROC);
975 if (SUCCEEDED(hr)) { 987 if (SUCCEEDED(hr)) {
976 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 988 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
977 hr = pAAR->SetAppAsDefault(app_name.c_str(), 989 hr = pAAR->SetAppAsDefault(app_name.c_str(),
978 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); 990 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 ret = false; 1032 ret = false;
1021 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; 1033 LOG(ERROR) << "Could not make Chrome default browser (XP/system level).";
1022 } 1034 }
1023 1035
1024 // Send Windows notification event so that it can update icons for 1036 // Send Windows notification event so that it can update icons for
1025 // file associations. 1037 // file associations.
1026 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1038 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1027 return ret; 1039 return ret;
1028 } 1040 }
1029 1041
1042 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist,
1043 const string16& chrome_exe) {
1044 static const wchar_t* protocol = L"http";
gab 2012/06/05 01:48:48 nit: static strings in the Chrome codebase should
gab 2012/06/05 01:48:48 nit: How about "protocol" -->"http_protocol" or ha
motek. 2012/06/06 18:30:41 In-lined as discussed.
motek. 2012/06/06 18:30:41 Ack.
1045 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN8);
grt (UTC plus 2) 2012/06/04 02:41:14 nit: DCHECK_GE(base::win::GetVersion(), base::win:
motek. 2012/06/06 18:30:41 Done.
1046 if (!dist->CanSetAsDefault())
1047 return false;
1048
1049 if (!IsChromeRegistered(dist, chrome_exe, L"") &&
1050 !RegisterChromeBrowser(dist, chrome_exe, L"", true)) {
grt (UTC plus 2) 2012/06/04 02:41:14 ubernit: L"" -> string()
motek. 2012/06/06 18:30:41 string16() ;-)? Done.
1051 return false;
1052 }
1053
1054 // On Windows 8, you can't set yourself as the default handler
1055 // programatically. In other words IApplicationAssociationRegistration
1056 // has been rendered useless. What you can do is to launch
1057 // "Set Program Associations" section of the "Default Programs"
1058 // control panel, which is a mess, or pop the concise "How you want to open
1059 // webpages"? dialog. We choose the latter.
1060 return LaunchSelectDefaultHttpHandlerDialog(protocol);
1061 }
1062
1030 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, 1063 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist,
1031 const string16& chrome_exe, 1064 const string16& chrome_exe,
1032 const string16& protocol) { 1065 const string16& protocol) {
1033 if (!dist->CanSetAsDefault()) 1066 if (!dist->CanSetAsDefault())
1034 return false; 1067 return false;
1035 1068
1036 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); 1069 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true);
1037 1070
1038 bool ret = true; 1071 bool ret = true;
1039 // First use the new "recommended" way on Vista to make Chrome default 1072 // 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(), 1324 chrome_exe.c_str(),
1292 shortcut.c_str(), 1325 shortcut.c_str(),
1293 chrome_path.c_str(), 1326 chrome_path.c_str(),
1294 arguments.c_str(), 1327 arguments.c_str(),
1295 description.c_str(), 1328 description.c_str(),
1296 icon_path.c_str(), 1329 icon_path.c_str(),
1297 icon_index, 1330 icon_index,
1298 dist->GetBrowserAppId().c_str(), 1331 dist->GetBrowserAppId().c_str(),
1299 ConvertShellUtilShortcutOptionsToFileUtil(options)); 1332 ConvertShellUtilShortcutOptionsToFileUtil(options));
1300 } 1333 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698