Chromium Code Reviews| 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 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 // Chrome as default browser at system level. | 904 // Chrome as default browser at system level. |
| 905 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | 905 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && |
| 906 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | 906 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { |
| 907 ret = false; | 907 ret = false; |
| 908 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | 908 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; |
| 909 } | 909 } |
| 910 | 910 |
| 911 return ret; | 911 return ret; |
| 912 } | 912 } |
| 913 | 913 |
| 914 // Associates Chrome with |protocol| in the registry. This should not be | |
| 915 // required on Vista+ but since some applications still read these registry | |
| 916 // keys directly, we have to do this on Vista+ as well. | |
| 917 // See http://msdn.microsoft.com/library/aa767914.aspx for more details. | |
| 918 bool RegisterChromeAsDefaultProtocolClientForXP(BrowserDistribution* dist, | |
| 919 const string16& chrome_exe, | |
| 920 const string16& protocol) { | |
| 921 ScopedVector<RegistryEntry> entries; | |
| 922 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | |
| 923 const string16 chrome_icon(ShellUtil::GetChromeIcon(dist, chrome_exe)); | |
| 924 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | |
| 925 &entries); | |
| 926 // Change the default protocol handler for current user. | |
| 927 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | |
| 928 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | |
| 929 return false; | |
| 930 } | |
| 931 | |
| 932 return true; | |
| 933 } | |
| 934 | |
| 914 } // namespace | 935 } // namespace |
| 915 | 936 |
| 916 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 937 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
| 917 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 938 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
| 918 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 939 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
| 919 const wchar_t* ShellUtil::kRegStartMenuInternet = | 940 const wchar_t* ShellUtil::kRegStartMenuInternet = |
| 920 L"Software\\Clients\\StartMenuInternet"; | 941 L"Software\\Clients\\StartMenuInternet"; |
| 921 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 942 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
| 922 const wchar_t* ShellUtil::kRegRegisteredApplications = | 943 const wchar_t* ShellUtil::kRegRegisteredApplications = |
| 923 L"Software\\RegisteredApplications"; | 944 L"Software\\RegisteredApplications"; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1368 | 1389 |
| 1369 return ret; | 1390 return ret; |
| 1370 } | 1391 } |
| 1371 | 1392 |
| 1372 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1393 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, |
| 1373 const string16& chrome_exe, | 1394 const string16& chrome_exe, |
| 1374 const string16& protocol) { | 1395 const string16& protocol) { |
| 1375 if (!dist->CanSetAsDefault()) | 1396 if (!dist->CanSetAsDefault()) |
| 1376 return false; | 1397 return false; |
| 1377 | 1398 |
| 1378 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); | 1399 if (!RegisterChromeForProtocol(dist, chrome_exe, string16(), protocol, true)) |
| 1400 return false; | |
| 1401 | |
| 1402 // Windows 8 does not permit making a browser default just like that. | |
| 1403 // This process needs to be routed through the system's UI. Use | |
| 1404 // ShowMakeChromeDefaultProocolClientSystemUI instead (below). | |
| 1405 if (!CanMakeChromeDefaultUnattended()) | |
| 1406 return false; | |
| 1379 | 1407 |
| 1380 bool ret = true; | 1408 bool ret = true; |
| 1381 // First use the new "recommended" way on Vista to make Chrome default | 1409 // First use the new "recommended" way on Vista to make Chrome default |
| 1382 // protocol handler. | 1410 // protocol handler. |
| 1383 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1411 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1384 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1412 VLOG(1) << "Registering Chrome as default handler for " << protocol |
| 1385 << " on Vista."; | 1413 << " on Vista."; |
| 1386 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1414 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1387 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1415 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1388 NULL, CLSCTX_INPROC); | 1416 NULL, CLSCTX_INPROC); |
| 1389 if (SUCCEEDED(hr)) { | 1417 if (SUCCEEDED(hr)) { |
| 1390 string16 app_name = GetApplicationName(dist, chrome_exe); | 1418 string16 app_name = GetApplicationName(dist, chrome_exe); |
| 1391 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1419 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
| 1392 AT_URLPROTOCOL); | 1420 AT_URLPROTOCOL); |
| 1393 } | 1421 } |
| 1394 if (!SUCCEEDED(hr)) { | 1422 if (!SUCCEEDED(hr)) { |
| 1395 ret = false; | 1423 ret = false; |
| 1396 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1424 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
| 1397 << " HRESULT=" << hr << "."; | 1425 << " HRESULT=" << hr << "."; |
| 1398 } | 1426 } |
| 1399 } | 1427 } |
| 1400 | 1428 |
| 1401 // Now use the old way to associate Chrome with the desired protocol. This | 1429 // Now use the old way to associate Chrome with the desired protocol. This |
| 1402 // should not be required on Vista but since some applications still read | 1430 // should not be required on Vista but since some applications still read |
| 1403 // Software\Classes\http key directly, we have to do this on Vista also. | 1431 // Software\Classes\http key directly, we have to do this on Vista also. |
| 1404 | 1432 if (!RegisterChromeAsDefaultProtocolClientForXP(dist, chrome_exe, protocol)) |
| 1405 ScopedVector<RegistryEntry> entries; | 1433 ret = false; |
| 1406 const string16 suffix(GetCurrentInstallationSuffix(dist, chrome_exe)); | |
| 1407 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | |
| 1408 const string16 chrome_icon(ShellUtil::GetChromeIcon(dist, chrome_exe)); | |
| 1409 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | |
| 1410 &entries); | |
| 1411 // Change the default protocol handler for current user. | |
| 1412 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | |
| 1413 ret = false; | |
| 1414 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | |
| 1415 } | |
| 1416 | 1434 |
| 1417 return ret; | 1435 return ret; |
| 1418 } | 1436 } |
| 1437 | |
| 1438 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( | |
|
gab
2012/10/03 19:32:42
I just saw this in the code, does this work from C
| |
| 1439 BrowserDistribution* dist, | |
| 1440 const string16& chrome_exe, | |
| 1441 const string16& protocol) { | |
| 1442 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); | |
| 1443 if (!dist->CanSetAsDefault()) | |
| 1444 return false; | |
| 1445 | |
| 1446 if (!RegisterChromeForProtocol(dist, chrome_exe, string16(), protocol, true)) | |
| 1447 return false; | |
| 1448 | |
| 1449 // On Windows 8, you can't set yourself as the default handler | |
| 1450 // programatically. In other words IApplicationAssociationRegistration | |
| 1451 // has been rendered useless. What you can do is to launch | |
| 1452 // "Set Program Associations" section of the "Default Programs" | |
| 1453 // control panel, which is a mess, or pop the concise "How you want to open | |
| 1454 // links of this type (protocol)?" dialog. We choose the latter. | |
| 1455 // Return true only when the user took an action and there was no error. | |
| 1456 const bool ret = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); | |
| 1457 | |
| 1458 if (ret) | |
| 1459 RegisterChromeAsDefaultProtocolClientForXP(dist, chrome_exe, protocol); | |
| 1460 | |
| 1461 return ret; | |
| 1462 } | |
| 1419 | 1463 |
| 1420 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, | 1464 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, |
| 1421 const string16& chrome_exe, | 1465 const string16& chrome_exe, |
| 1422 const string16& unique_suffix, | 1466 const string16& unique_suffix, |
| 1423 bool elevate_if_not_admin) { | 1467 bool elevate_if_not_admin) { |
| 1424 if (!dist->CanSetAsDefault()) | 1468 if (!dist->CanSetAsDefault()) |
| 1425 return false; | 1469 return false; |
| 1426 | 1470 |
| 1427 string16 suffix; | 1471 string16 suffix; |
| 1428 if (!unique_suffix.empty()) { | 1472 if (!unique_suffix.empty()) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1744 // are any left...). | 1788 // are any left...). |
| 1745 if (free_bits >= 8 && next_byte_index < size) { | 1789 if (free_bits >= 8 && next_byte_index < size) { |
| 1746 free_bits -= 8; | 1790 free_bits -= 8; |
| 1747 bit_stream += bytes[next_byte_index++] << free_bits; | 1791 bit_stream += bytes[next_byte_index++] << free_bits; |
| 1748 } | 1792 } |
| 1749 } | 1793 } |
| 1750 | 1794 |
| 1751 DCHECK_EQ(ret.length(), encoded_length); | 1795 DCHECK_EQ(ret.length(), encoded_length); |
| 1752 return ret; | 1796 return ret; |
| 1753 } | 1797 } |
| OLD | NEW |