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

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 the reviewer's remark. 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 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 // It is required that Chrome be already *registered* for the given protocol.
619 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) {
620 DCHECK(protocol);
621 OPENASINFO open_as_info = {};
622 open_as_info.pcszFile = protocol;
623 open_as_info.oaifInFlags =
624 OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | OAIF_REGISTER_EXT;
625 HRESULT hr = SHOpenWithDialog(NULL, &open_as_info);
626 DLOG_IF(WARNING, FAILED(hr)) << "Failed to set as default " << protocol
627 << " handler; hr=0x" << std::hex << hr;
628 return SUCCEEDED(hr);
629 }
630
614 // Launches the Windows 7 and Windows 8 application association dialog, which 631 // 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 632 // is the only documented way to make a browser the default browser on
616 // Windows 8. 633 // Windows 8.
617 bool LaunchApplicationAssociationDialog(const string16& app_id) { 634 bool LaunchApplicationAssociationDialog(const string16& app_id) {
618 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; 635 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui;
619 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); 636 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI);
620 if (FAILED(hr)) 637 if (FAILED(hr))
621 return false; 638 return false;
622 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); 639 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str());
623 return SUCCEEDED(hr); 640 return SUCCEEDED(hr);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 KEY_READ).Valid(); 955 KEY_READ).Valid();
939 } 956 }
940 957
941 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, 958 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
942 int shell_change, 959 int shell_change,
943 const string16& chrome_exe, 960 const string16& chrome_exe,
944 bool elevate_if_not_admin) { 961 bool elevate_if_not_admin) {
945 if (!dist->CanSetAsDefault()) 962 if (!dist->CanSetAsDefault())
946 return false; 963 return false;
947 964
965 // Windows 8 does not permit making a browser default just like that.
966 // This process needs to be routed through the system's UI. Use
967 // ShowMakeChromeDefaultSystemUI instead (below).
968 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
969 NOTREACHED();
970 return false;
971 }
972
948 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); 973 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin);
949 974
950 bool ret = true; 975 bool ret = true;
951 // First use the new "recommended" way on Vista to make Chrome default 976 // First use the new "recommended" way on Vista to make Chrome default
952 // browser. 977 // browser.
953 string16 app_name = dist->GetApplicationName(); 978 string16 app_name = dist->GetApplicationName();
954 string16 app_suffix; 979 string16 app_suffix;
955 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) 980 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix))
956 app_name += app_suffix; 981 app_name += app_suffix;
957 982
958 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 983 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 984 // On Windows Vista and Win7 we still can set ourselves via the
970 // the IApplicationAssociationRegistration interface. 985 // the IApplicationAssociationRegistration interface.
971 VLOG(1) << "Registering Chrome as default browser on Vista."; 986 VLOG(1) << "Registering Chrome as default browser on Vista.";
972 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 987 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
973 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 988 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
974 NULL, CLSCTX_INPROC); 989 NULL, CLSCTX_INPROC);
975 if (SUCCEEDED(hr)) { 990 if (SUCCEEDED(hr)) {
976 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { 991 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
977 hr = pAAR->SetAppAsDefault(app_name.c_str(), 992 hr = pAAR->SetAppAsDefault(app_name.c_str(),
978 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL); 993 ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 ret = false; 1035 ret = false;
1021 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; 1036 LOG(ERROR) << "Could not make Chrome default browser (XP/system level).";
1022 } 1037 }
1023 1038
1024 // Send Windows notification event so that it can update icons for 1039 // Send Windows notification event so that it can update icons for
1025 // file associations. 1040 // file associations.
1026 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1041 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1027 return ret; 1042 return ret;
1028 } 1043 }
1029 1044
1045 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist,
1046 const string16& chrome_exe) {
1047 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8);
1048 if (!dist->CanSetAsDefault())
1049 return false;
1050
1051 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true))
1052 return false;
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 LaunchSelectDefaultProtocolHandlerDialog(L"http");
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