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 bool RegisterChromeAsDefaultProtocolClientForXP(BrowserDistribution* dist, | |
|
grt (UTC plus 2)
2012/09/20 13:10:13
please add a comment for the function directing th
benwells
2012/09/21 01:15:20
Done.
| |
| 915 const string16& chrome_exe, | |
| 916 const string16& protocol) { | |
| 917 ScopedVector<RegistryEntry> entries; | |
| 918 const string16 suffix(ShellUtil::GetCurrentInstallationSuffix(dist, | |
|
grt (UTC plus 2)
2012/09/20 13:10:13
suffix is never used, please remove.
benwells
2012/09/21 01:15:20
Done.
| |
| 919 chrome_exe)); | |
| 920 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | |
| 921 const string16 chrome_icon(ShellUtil::GetChromeIcon(dist, chrome_exe)); | |
| 922 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | |
| 923 &entries); | |
| 924 // Change the default protocol handler for current user. | |
| 925 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | |
| 926 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | |
|
grt (UTC plus 2)
2012/09/20 13:10:13
nit: de-indent two spaces
benwells
2012/09/21 01:15:20
Done.
| |
| 927 return false; | |
| 928 } | |
| 929 | |
| 930 return true; | |
| 931 } | |
| 932 | |
| 914 } // namespace | 933 } // namespace |
| 915 | 934 |
| 916 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 935 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
| 917 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 936 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
| 918 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 937 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
| 919 const wchar_t* ShellUtil::kRegStartMenuInternet = | 938 const wchar_t* ShellUtil::kRegStartMenuInternet = |
| 920 L"Software\\Clients\\StartMenuInternet"; | 939 L"Software\\Clients\\StartMenuInternet"; |
| 921 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 940 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
| 922 const wchar_t* ShellUtil::kRegRegisteredApplications = | 941 const wchar_t* ShellUtil::kRegRegisteredApplications = |
| 923 L"Software\\RegisteredApplications"; | 942 L"Software\\RegisteredApplications"; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1348 return false; | 1367 return false; |
| 1349 | 1368 |
| 1350 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true)) | 1369 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true)) |
| 1351 return false; | 1370 return false; |
| 1352 | 1371 |
| 1353 // On Windows 8, you can't set yourself as the default handler | 1372 // On Windows 8, you can't set yourself as the default handler |
| 1354 // programatically. In other words IApplicationAssociationRegistration | 1373 // programatically. In other words IApplicationAssociationRegistration |
| 1355 // has been rendered useless. What you can do is to launch | 1374 // has been rendered useless. What you can do is to launch |
| 1356 // "Set Program Associations" section of the "Default Programs" | 1375 // "Set Program Associations" section of the "Default Programs" |
| 1357 // control panel, which is a mess, or pop the concise "How you want to open | 1376 // control panel, which is a mess, or pop the concise "How you want to open |
| 1358 // webpages?" dialog. We choose the latter. | 1377 // links of this type (protocol)?" dialog. We choose the latter. |
|
grt (UTC plus 2)
2012/09/20 13:10:13
Looks like this is the text for line 1452 (and vic
benwells
2012/09/21 01:15:20
Done.
| |
| 1359 // Return true only when the user took an action and there was no error. | 1378 // Return true only when the user took an action and there was no error. |
| 1360 const bool ret = LaunchSelectDefaultProtocolHandlerDialog(L"http"); | 1379 const bool ret = LaunchSelectDefaultProtocolHandlerDialog(L"http"); |
| 1361 | 1380 |
| 1362 if (ret) { | 1381 if (ret) { |
| 1363 const int shell_change = | 1382 const int shell_change = |
| 1364 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? CURRENT_USER : | 1383 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? CURRENT_USER : |
| 1365 SYSTEM_LEVEL; | 1384 SYSTEM_LEVEL; |
| 1366 RegisterChromeAsDefaultForXP(dist, shell_change, chrome_exe); | 1385 RegisterChromeAsDefaultForXP(dist, shell_change, chrome_exe); |
| 1367 } | 1386 } |
| 1368 | 1387 |
| 1369 return ret; | 1388 return ret; |
| 1370 } | 1389 } |
| 1371 | 1390 |
| 1372 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1391 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, |
| 1373 const string16& chrome_exe, | 1392 const string16& chrome_exe, |
| 1374 const string16& protocol) { | 1393 const string16& protocol) { |
| 1375 if (!dist->CanSetAsDefault()) | 1394 if (!dist->CanSetAsDefault()) |
| 1376 return false; | 1395 return false; |
| 1377 | 1396 |
| 1378 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); | 1397 if (!RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true)) |
|
grt (UTC plus 2)
2012/09/20 13:10:13
L"" -> string16()
benwells
2012/09/21 01:15:20
Done.
| |
| 1398 return false; | |
| 1399 | |
| 1400 // Windows 8 does not permit making a browser default just like that. | |
| 1401 // This process needs to be routed through the system's UI. Use | |
| 1402 // ShowMakeChromeDefaultProocolClientSystemUI instead (below). | |
| 1403 if (!CanMakeChromeDefaultUnattended()) | |
| 1404 return false; | |
| 1379 | 1405 |
| 1380 bool ret = true; | 1406 bool ret = true; |
| 1381 // First use the new "recommended" way on Vista to make Chrome default | 1407 // First use the new "recommended" way on Vista to make Chrome default |
| 1382 // protocol handler. | 1408 // protocol handler. |
| 1383 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1409 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1384 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1410 VLOG(1) << "Registering Chrome as default handler for " << protocol |
| 1385 << " on Vista."; | 1411 << " on Vista."; |
| 1386 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1412 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1387 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1413 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1388 NULL, CLSCTX_INPROC); | 1414 NULL, CLSCTX_INPROC); |
| 1389 if (SUCCEEDED(hr)) { | 1415 if (SUCCEEDED(hr)) { |
| 1390 string16 app_name = GetApplicationName(dist, chrome_exe); | 1416 string16 app_name = GetApplicationName(dist, chrome_exe); |
| 1391 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1417 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
| 1392 AT_URLPROTOCOL); | 1418 AT_URLPROTOCOL); |
| 1393 } | 1419 } |
| 1394 if (!SUCCEEDED(hr)) { | 1420 if (!SUCCEEDED(hr)) { |
| 1395 ret = false; | 1421 ret = false; |
| 1396 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1422 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
| 1397 << " HRESULT=" << hr << "."; | 1423 << " HRESULT=" << hr << "."; |
| 1398 } | 1424 } |
| 1399 } | 1425 } |
| 1400 | 1426 |
| 1401 // Now use the old way to associate Chrome with the desired protocol. This | 1427 // 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 | 1428 // 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. | 1429 // Software\Classes\http key directly, we have to do this on Vista also. |
| 1404 | 1430 if (!RegisterChromeAsDefaultProtocolClientForXP(dist, chrome_exe, protocol)) |
| 1405 ScopedVector<RegistryEntry> entries; | 1431 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 | 1432 |
| 1417 return ret; | 1433 return ret; |
| 1418 } | 1434 } |
| 1435 | |
| 1436 bool ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI( | |
| 1437 BrowserDistribution* dist, | |
| 1438 const string16& chrome_exe, | |
| 1439 const string16& protocol) { | |
| 1440 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); | |
| 1441 if (!dist->CanSetAsDefault()) | |
| 1442 return false; | |
| 1443 | |
| 1444 if (!RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true)) | |
|
grt (UTC plus 2)
2012/09/20 13:10:13
L"" -> string16()
benwells
2012/09/21 01:15:20
Done.
| |
| 1445 return false; | |
|
grt (UTC plus 2)
2012/09/20 13:10:13
de-indent two spaces
benwells
2012/09/21 01:15:20
Done.
| |
| 1446 | |
| 1447 // On Windows 8, you can't set yourself as the default handler | |
| 1448 // programatically. In other words IApplicationAssociationRegistration | |
| 1449 // has been rendered useless. What you can do is to launch | |
| 1450 // "Set Program Associations" section of the "Default Programs" | |
| 1451 // control panel, which is a mess, or pop the concise "How you want to open | |
| 1452 // webpages?" dialog. We choose the latter. | |
| 1453 // Return true only when the user took an action and there was no error. | |
| 1454 const bool ret = LaunchSelectDefaultProtocolHandlerDialog(protocol.c_str()); | |
| 1455 | |
| 1456 if (ret) | |
| 1457 RegisterChromeAsDefaultProtocolClientForXP(dist, chrome_exe, protocol); | |
| 1458 | |
| 1459 return ret; | |
| 1460 } | |
| 1419 | 1461 |
| 1420 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, | 1462 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, |
| 1421 const string16& chrome_exe, | 1463 const string16& chrome_exe, |
| 1422 const string16& unique_suffix, | 1464 const string16& unique_suffix, |
| 1423 bool elevate_if_not_admin) { | 1465 bool elevate_if_not_admin) { |
| 1424 if (!dist->CanSetAsDefault()) | 1466 if (!dist->CanSetAsDefault()) |
| 1425 return false; | 1467 return false; |
| 1426 | 1468 |
| 1427 string16 suffix; | 1469 string16 suffix; |
| 1428 if (!unique_suffix.empty()) { | 1470 if (!unique_suffix.empty()) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1744 // are any left...). | 1786 // are any left...). |
| 1745 if (free_bits >= 8 && next_byte_index < size) { | 1787 if (free_bits >= 8 && next_byte_index < size) { |
| 1746 free_bits -= 8; | 1788 free_bits -= 8; |
| 1747 bit_stream += bytes[next_byte_index++] << free_bits; | 1789 bit_stream += bytes[next_byte_index++] << free_bits; |
| 1748 } | 1790 } |
| 1749 } | 1791 } |
| 1750 | 1792 |
| 1751 DCHECK_EQ(ret.length(), encoded_length); | 1793 DCHECK_EQ(ret.length(), encoded_length); |
| 1752 return ret; | 1794 return ret; |
| 1753 } | 1795 } |
| OLD | NEW |