1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/containers/span.h"
#include "base/containers/to_vector.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/types/optional_util.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/affiliations/affiliation_service_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/device_reauth/chrome_device_authenticator_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/password_manager/account_password_store_factory.h"
#include "chrome/browser/password_manager/android/first_cct_page_load_marker.h"
#include "chrome/browser/password_manager/chrome_password_change_service.h"
#include "chrome/browser/password_manager/chrome_webauthn_credentials_delegate.h"
#include "chrome/browser/password_manager/chrome_webauthn_credentials_delegate_factory.h"
#include "chrome/browser/password_manager/field_info_manager_factory.h"
#include "chrome/browser/password_manager/password_change_service_factory.h"
#include "chrome/browser/password_manager/password_manager_settings_service_factory.h"
#include "chrome/browser/password_manager/password_reuse_manager_factory.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/passwords/password_cross_domain_confirmation_popup_controller_impl.h"
#include "chrome/browser/ui/passwords/password_generation_popup_controller_impl.h"
#include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/browser/ui/passwords/ui_utils.h"
#include "chrome/browser/ui/user_education/browser_user_education_interface.h"
#include "chrome/browser/ui/webauthn/authenticator_request_window.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/content/browser/content_autofill_client.h"
#include "components/autofill/content/browser/renderer_forms_from_browser_form.h"
#include "components/autofill/content/browser/scoped_autofill_managers_observation.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/logging/log_router.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/password_generation_util.h"
#include "components/browsing_data/content/browsing_data_helper.h"
#include "components/device_reauth/device_authenticator.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_contents.h"
#include "components/password_manager/content/browser/bad_message.h"
#include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
#include "components/password_manager/content/browser/form_meta_data.h"
#include "components/password_manager/content/browser/password_manager_log_router_factory.h"
#include "components/password_manager/content/browser/password_requirements_service_factory.h"
#include "components/password_manager/core/browser/browser_save_password_progress_logger.h"
#include "components/password_manager/core/browser/credential_manager_impl.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/hsts_query.h"
#include "components/password_manager/core/browser/http_auth_manager.h"
#include "components/password_manager/core/browser/http_auth_manager_impl.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#include "components/password_manager/core/browser/one_time_passwords/otp_manager.h"
#include "components/password_manager/core/browser/passkey_credential.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_manager_setting.h"
#include "components/password_manager/core/browser/password_manager_settings_service.h"
#include "components/password_manager/core/browser/password_requirements_service.h"
#include "components/password_manager/core/browser/password_store/password_store_backend_error.h"
#include "components/password_manager/core/browser/password_store/password_store_interface.h"
#include "components/password_manager/core/browser/password_sync_util.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/policy/content/password_manager_blocklist_policy.h"
#include "components/policy/core/browser/url_blocklist_manager.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/safe_browsing/buildflags.h"
#include "components/sessions/content/content_record_password_state.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/site_isolation/site_isolation_policy.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/translate/core/browser/translate_manager.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/page.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "extensions/buildflags/buildflags.h"
#include "net/base/url_util.h"
#include "net/cert/cert_status_flags.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
#include "chrome/browser/safe_browsing/user_interaction_observer.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/android/tab_web_contents_delegate_android.h"
#include "chrome/browser/keyboard_accessory/android/manual_filling_controller.h"
#include "chrome/browser/keyboard_accessory/android/password_accessory_controller.h"
#include "chrome/browser/keyboard_accessory/android/password_accessory_controller_impl.h"
#include "chrome/browser/password_manager/android/access_loss/password_access_loss_warning_bridge_impl.h"
#include "chrome/browser/password_manager/android/account_chooser_dialog_android.h"
#include "chrome/browser/password_manager/android/auto_signin_first_run_dialog_android.h"
#include "chrome/browser/password_manager/android/auto_signin_prompt_controller.h"
#include "chrome/browser/password_manager/android/cred_man_controller.h"
#include "chrome/browser/password_manager/android/credential_leak_controller_android.h"
#include "chrome/browser/password_manager/android/grouped_affiliations/acknowledge_grouped_credential_sheet_bridge.h"
#include "chrome/browser/password_manager/android/grouped_affiliations/acknowledge_grouped_credential_sheet_controller.h"
#include "chrome/browser/password_manager/android/local_passwords_migration_warning_util.h"
#include "chrome/browser/password_manager/android/one_time_passwords/android_sms_otp_backend_factory.h"
#include "chrome/browser/password_manager/android/password_checkup_launcher_helper_impl.h"
#include "chrome/browser/password_manager/android/password_generation_controller.h"
#include "chrome/browser/password_manager/android/password_manager_android_util.h"
#include "chrome/browser/password_manager/android/password_manager_error_message_helper_bridge_impl.h"
#include "chrome/browser/password_manager/android/password_manager_launcher_android.h"
#include "chrome/browser/password_manager/android/password_manager_ui_util_android.h"
#include "chrome/browser/password_manager/android/password_manager_util_bridge.h"
#include "chrome/browser/touch_to_fill/password_manager/password_generation/android/touch_to_fill_password_generation_controller.h"
#include "chrome/browser/touch_to_fill/password_manager/touch_to_fill_controller_autofill_delegate.h"
#include "components/password_manager/content/browser/keyboard_replacing_surface_visibility_controller_impl.h"
#include "components/password_manager/core/browser/credential_cache.h"
#include "components/password_manager/core/browser/one_time_passwords/sms_otp_backend.h"
#include "components/password_manager/core/browser/password_credential_filler_impl.h"
#include "components/webauthn/android/webauthn_cred_man_delegate.h"
#include "components/webauthn/android/webauthn_cred_man_delegate_factory.h"
#else
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/hats/hats_service.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/hats/survey_config.h"
#include "components/policy/core/common/features.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS) || BUILDFLAG(IS_ANDROID)
#include "chrome/browser/enterprise/connectors/reporting/reporting_event_router_factory.h"
#include "components/enterprise/connectors/core/reporting_event_router.h"
#endif // BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS) || BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
#include "chrome/browser/signin/dice_web_signin_interceptor_factory.h"
#include "chrome/browser/ui/browser.h"
#endif
#if BUILDFLAG(IS_ANDROID)
using base::android::BuildInfo;
using password_manager::CredentialCache;
using password_manager_android_util::GmsVersionCohort;
#endif
using autofill::mojom::FocusedFieldType;
using autofill::password_generation::PasswordGenerationType;
using password_manager::BadMessageReason;
using password_manager::ContentPasswordManagerDriverFactory;
using password_manager::FieldInfoManager;
using password_manager::PasswordCredentialFillerImpl;
using password_manager::PasswordForm;
using password_manager::PasswordManagerClientHelper;
using password_manager::PasswordManagerDriver;
using password_manager::PasswordManagerMetricsRecorder;
using password_manager::PasswordManagerSetting;
using password_manager::PasswordManagerSettingsService;
using password_manager::PasswordStoreBackendError;
using password_manager::metrics_util::PasswordType;
using sessions::SerializedNavigationEntry;
// Shorten the name to spare line breaks. The code provides enough context
// already.
using Logger = autofill::SavePasswordProgressLogger;
namespace {
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS) || BUILDFLAG(IS_ANDROID)
constexpr char kPasswordBreachEntryTrigger[] = "PASSWORD_ENTRY";
#endif
#if BUILDFLAG(IS_ANDROID)
// TODO(crbug.com/41485955): Get rid of DeprecatedGetOriginAsURL().
url::Origin URLToOrigin(GURL url) {
return url::Origin::Create(url.DeprecatedGetOriginAsURL());
}
void ShowAccessLossWarning(PrefService* prefs,
base::WeakPtr<content::WebContents> web_contents,
Profile* profile) {
if (!web_contents) {
return;
}
PasswordAccessLossWarningBridgeImpl bridge;
bridge.MaybeShowAccessLossNoticeSheet(
prefs, web_contents->GetTopLevelNativeWindow(), profile,
/*called_at_startup=*/true,
password_manager_android_util::PasswordAccessLossWarningTriggers::
kChromeStartup);
}
void MaybeShowPostMigrationSheetWrapper(
base::WeakPtr<content::WebContents> web_contents,
Profile* profile) {
if (!web_contents) {
return;
}
local_password_migration::MaybeShowPostMigrationSheet(
web_contents->GetTopLevelNativeWindow(), profile);
}
#endif
bool PredictionsContainOtpFields(
const base::flat_map<autofill::FieldGlobalId, autofill::FieldType>&
predictions) {
return std::any_of(predictions.begin(), predictions.end(),
[](const auto& field) {
return field.second == autofill::ONE_TIME_CODE;
});
}
} // namespace
// static
void ChromePasswordManagerClient::CreateForWebContents(
content::WebContents* contents) {
if (FromWebContents(contents)) {
return;
}
contents->SetUserData(
UserDataKey(),
base::WrapUnique(new ChromePasswordManagerClient(contents)));
}
// static
void ChromePasswordManagerClient::BindPasswordGenerationDriver(
mojo::PendingAssociatedReceiver<autofill::mojom::PasswordGenerationDriver>
receiver,
content::RenderFrameHost* rfh) {
// [spec] https://wicg.github.io/anonymous-iframe/#spec-autofill
if (rfh->IsCredentialless()) {
return;
}
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
if (!web_contents) {
return;
}
auto* tab_helper = ChromePasswordManagerClient::FromWebContents(web_contents);
if (!tab_helper) {
return;
}
tab_helper->password_generation_driver_receivers_.Bind(rfh,
std::move(receiver));
}
ChromePasswordManagerClient::~ChromePasswordManagerClient() = default;
bool ChromePasswordManagerClient::IsSavingAndFillingEnabled(
const GURL& url) const {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableAutomation)) {
// Disable the password saving UI for automated tests. It obscures the
// page, and there is no API to access (or dismiss) UI bubbles/infobars.
return false;
}
password_manager::PasswordManagerSettingsService* settings_service =
PasswordManagerSettingsServiceFactory::GetForProfile(profile_);
return settings_service &&
settings_service->IsSettingEnabled(
PasswordManagerSetting::kOfferToSavePasswords) &&
!IsOffTheRecord() && IsFillingEnabled(url);
}
bool ChromePasswordManagerClient::IsFillingEnabled(const GURL& url) const {
const Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
// Guest profiles don't have PasswordStore at all, so filling should be
// disabled for them.
if (!profile || profile->IsGuestSession()) {
return false;
}
// Filling is impossible if password store in unavailable.
if (!GetProfilePasswordStore()) {
return false;
}
const bool ssl_errors = net::IsCertStatusError(GetMainFrameCertStatus());
autofill::LogManager* log_manager = GetOrCreateLogManager();
if (log_manager && log_manager->IsLoggingActive()) {
password_manager::BrowserSavePasswordProgressLogger logger(log_manager);
logger.LogBoolean(Logger::STRING_SSL_ERRORS_PRESENT, ssl_errors);
}
return !ssl_errors && IsPasswordManagementEnabledForCurrentPage(url);
}
bool ChromePasswordManagerClient::IsAutoSignInEnabled() const {
#if BUILDFLAG(IS_ANDROID)
if (BuildInfo::GetInstance()->is_automotive()) {
return false;
}
#endif
password_manager::PasswordManagerSettingsService* settings_service =
PasswordManagerSettingsServiceFactory::GetForProfile(profile_);
return settings_service && settings_service->IsSettingEnabled(
PasswordManagerSetting::kAutoSignIn);
}
void ChromePasswordManagerClient::TriggerUserPerceptionOfPasswordManagerSurvey(
const std::string& filling_assistance) {
#if !BUILDFLAG(IS_ANDROID)
if (filling_assistance.empty()) {
return;
}
HatsService* hats_service =
HatsServiceFactory::GetForProfile(profile_, /*create_if_necessary=*/true);
if (!hats_service) {
return;
}
hats_service->LaunchDelayedSurveyForWebContents(
kHatsSurveyTriggerAutofillPasswordUserPerception, web_contents(),
/*timeout_ms=*/5000, /*product_specific_bits_data=*/
{}, {{"Filling assistance", filling_assistance}});
#endif
}
bool ChromePasswordManagerClient::PromptUserToSaveOrUpdatePassword(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
bool update_password) {
#if BUILDFLAG(IS_ANDROID)
// The metrics are only relevant for cases in which the CCT doesn't have time
// to show a prompt.
cct_saving_metrics_recorder_bridge_.reset();
#endif
// The save password infobar and the password bubble prompt in case of
// "webby" URLs and do not prompt in case of "non-webby" URLS (e.g. file://).
if (!CanShowBubbleOnURL(web_contents()->GetLastCommittedURL())) {
return false;
}
#if BUILDFLAG(IS_ANDROID)
if (form_to_save->IsBlocklisted()) {
autofill::LogManager* log_manager = GetCurrentLogManager();
if (log_manager && log_manager->IsLoggingActive()) {
password_manager::BrowserSavePasswordProgressLogger logger(log_manager);
logger.LogMessage(Logger::STRING_SAVING_BLOCKLISTED_EXPLICITLY);
}
return false;
}
// base::Unretained() is safe: If the callback is called, AccountStorageNotice
// is alive, then so are its parent ChromePasswordManagerClient, its sibling
// SaveUpdatePasswordMessageDelegate and web_contents() (the client is per
// web_contents()).
MaybeShowAccountStorageNotice(base::BindOnce(
&SaveUpdatePasswordMessageDelegate::DisplaySaveUpdatePasswordPrompt,
base::Unretained(&save_update_password_message_delegate_),
base::Unretained(web_contents()), std::move(form_to_save),
update_password, base::Unretained(this)));
#else
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
// TODO(crbug.com/372873259): This suddenly started being called/being null,
// in the Chrome sign-in flow in M129. Find out why.
if (!manage_passwords_ui_controller) {
return false;
}
if (update_password) {
manage_passwords_ui_controller->OnUpdatePasswordSubmitted(
std::move(form_to_save));
} else {
manage_passwords_ui_controller->OnPasswordSubmitted(
std::move(form_to_save));
}
#endif
return true;
}
void ChromePasswordManagerClient::PromptUserToMovePasswordToAccount(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_move) {
#if !BUILDFLAG(IS_ANDROID)
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnShowMoveToAccountBubble(
std::move(form_to_move));
}
#endif // !BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::ShowManualFallbackForSaving(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
bool has_generated_password,
bool is_update) {
#if !BUILDFLAG(IS_ANDROID)
if (!CanShowBubbleOnURL(web_contents()->GetLastCommittedURL())) {
return;
}
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
// There may be no UI controller for ChromeOS login page
// (see crbug.com/774676).
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnShowManualFallbackForSaving(
std::move(form_to_save), has_generated_password, is_update);
}
#endif // !BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::HideManualFallbackForSaving() {
#if !BUILDFLAG(IS_ANDROID)
if (!CanShowBubbleOnURL(web_contents()->GetLastCommittedURL())) {
return;
}
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
// There may be no UI controller for ChromeOS login page
// (see crbug.com/774676).
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnHideManualFallbackForSaving();
}
#endif // !BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::FocusedInputChanged(
PasswordManagerDriver* driver,
autofill::FieldRendererId focused_field_id,
autofill::mojom::FocusedFieldType focused_field_type) {
#if BUILDFLAG(IS_ANDROID)
// If there was a timer waiting for passkeys before showing a bottom sheet,
// cancel it because the original element is no longer focused.
wait_for_passkeys_timer_.Stop();
// Suppress keyboard accessory if password store is not available.
if (GetProfilePasswordStore() == nullptr) {
return;
}
ManualFillingController::GetOrCreate(web_contents())
->NotifyFocusedInputChanged(focused_field_id, focused_field_type);
GetOrCreatePasswordAccessory()->UpdateCredManReentryUi(focused_field_type);
password_manager::ContentPasswordManagerDriver* content_driver =
static_cast<password_manager::ContentPasswordManagerDriver*>(driver);
if (!ShouldAcceptFocusEvent(web_contents(), content_driver,
focused_field_type)) {
return;
}
if (!content_driver->CanShowAutofillUi()) {
return;
}
// Allow to manually generate password if the field parser suggests the field
// is a password field.
bool manual_generation_enabled_on_field =
(focused_field_type ==
autofill::mojom::FocusedFieldType::kFillablePasswordField ||
(autofill::IsFillable(focused_field_type) &&
content_driver->IsPasswordFieldForPasswordManager(focused_field_id,
std::nullopt)));
if (web_contents()->GetFocusedFrame()) {
GetOrCreatePasswordAccessory()->RefreshSuggestionsForField(
focused_field_type, manual_generation_enabled_on_field);
}
PasswordGenerationController::GetOrCreate(web_contents())
->FocusedInputChanged(/*is_field_eligible_for_generation=*/
manual_generation_enabled_on_field,
content_driver->AsWeakPtrImpl());
#endif // BUILDFLAG(IS_ANDROID)
}
bool ChromePasswordManagerClient::PromptUserToChooseCredentials(
std::vector<std::unique_ptr<PasswordForm>> local_forms,
const url::Origin& origin,
CredentialsCallback callback) {
// Set up an intercept callback if the prompt is zero-clickable (e.g. just one
// form provided).
CredentialsCallback intercept = base::BindOnce(
&PasswordManagerClientHelper::OnCredentialsChosen,
base::Unretained(&helper_), std::move(callback), local_forms.size() == 1);
#if BUILDFLAG(IS_ANDROID)
// Deletes itself on the event from Java counterpart, when user interacts with
// dialog.
AccountChooserDialogAndroid* acccount_chooser_dialog =
new AccountChooserDialogAndroid(web_contents(), /*client=*/this,
std::move(local_forms), origin,
std::move(intercept));
return acccount_chooser_dialog->ShowDialog();
#else
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (!manage_passwords_ui_controller) {
return false;
}
return manage_passwords_ui_controller->OnChooseCredentials(
std::move(local_forms), origin, std::move(intercept));
#endif
}
#if BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::ShowPasswordManagerErrorMessage(
password_manager::ErrorMessageFlowType flow_type,
password_manager::PasswordStoreBackendErrorType error_type) {
bool oldGMSSavingDisabled = error_type ==
password_manager::PasswordStoreBackendErrorType::
kGMSCoreOutdatedSavingDisabled;
bool oldGMSSavingPossible = error_type ==
password_manager::PasswordStoreBackendErrorType::
kGMSCoreOutdatedSavingPossible;
password_manager_android_util::PasswordManagerUtilBridge util_bridge;
bool noPlayStore = !util_bridge.IsPlayStoreAppPresent();
bool login_db_deprecation_enabled = base::FeatureList::IsEnabled(
password_manager::features::kLoginDbDeprecationAndroid);
if ((oldGMSSavingDisabled || oldGMSSavingPossible) &&
(noPlayStore || login_db_deprecation_enabled)) {
// Warning messages about old GMS Core versions should not be shown if there
// is no store or if the login DB deprecation has begun.
return;
}
if (!password_manager_error_message_delegate_) {
password_manager_error_message_delegate_ =
std::make_unique<PasswordManagerErrorMessageDelegate>(
std::make_unique<PasswordManagerErrorMessageHelperBridgeImpl>());
password_manager_error_message_delegate_->MaybeDisplayErrorMessage(
web_contents(), GetPrefs(), flow_type, error_type,
base::BindOnce(&ChromePasswordManagerClient::ResetErrorMessageDelegate,
base::Unretained(this)));
}
}
password_manager::CredManController::PasskeyDelayCallback
ChromePasswordManagerClient::GetPasskeyDelayCallback(
base::OnceClosure continue_closure) {
return base::BindOnce(
[](base::WeakPtr<ChromePasswordManagerClient> client,
base::OnceClosure continue_closure,
base::OnceCallback<void(base::OnceClosure)>
request_notification_callback) {
if (client && !client->wait_for_passkeys_timer_.IsRunning()) {
// The callback has to be split because there are two ways for this
// to resolve:
// 1. It times out, in which case the closure passed to the
// `timer_` fires, resuming the attempt to show the sheet.
// 2. Passkeys become available before the timer expires.
// In this case the second callback gets invoked, and cancels
// the timer.
auto split_closures =
base::SplitOnceCallback(std::move(continue_closure));
client->wait_for_passkeys_timer_.Start(
FROM_HERE,
base::Milliseconds(password_manager::features::
kDelaySuggestionsOnAutofocusTimeout.Get()),
std::move(split_closures.first));
// If passkeys become available before the timer expires, this
// closure checks if the timer is still running. If so, it triggers
// the bottom sheet to show, and cancels the timer so there won't
// be a second attempt to show it.
base::OnceClosure passkeys_available_callback = base::BindOnce(
[](base::WeakPtr<ChromePasswordManagerClient> client,
base::OnceClosure continue_closure) {
if (!client) {
return;
}
if (client->wait_for_passkeys_timer_.IsRunning()) {
client->wait_for_passkeys_timer_.Stop();
std::move(continue_closure).Run();
}
},
client, std::move(split_closures.second));
std::move(request_notification_callback)
.Run(std::move(passkeys_available_callback));
}
},
weak_ptr_factory_.GetWeakPtr(), std::move(continue_closure));
}
void ChromePasswordManagerClient::ShowKeyboardReplacingSurface(
password_manager::PasswordManagerDriver* driver,
const autofill::PasswordSuggestionRequest& request) {
password_manager::ContentPasswordManagerDriver* content_driver =
static_cast<password_manager::ContentPasswordManagerDriver*>(driver);
if (keyboard_replacing_surface_visibility_controller_ &&
!keyboard_replacing_surface_visibility_controller_->CanBeShown()) {
if (!keyboard_replacing_surface_visibility_controller_->IsVisible()) {
content_driver->GetPasswordAutofillManager()->ShowSuggestions(
request.field);
}
return;
}
password_manager::CredManController::PasskeyDelayCallback delay_callback;
if (base::FeatureList::IsEnabled(
password_manager::features::
kDelaySuggestionsOnAutofocusWaitingForPasskeys) &&
request.field.trigger_source ==
autofill::AutofillSuggestionTriggerSource::
kPasswordManagerProcessedFocusedField) {
// A null PasskeyDelayCallback is bound to `continue_closure` to prevent
// it from delaying again, even if the passkey list has not yet arrived.
auto continue_closure = base::BindOnce(
&ChromePasswordManagerClient::ContinueShowKeyboardReplacingSurface,
weak_ptr_factory_.GetWeakPtr(), driver->AsWeakPtr(), request,
password_manager::CredManController::PasskeyDelayCallback());
delay_callback = GetPasskeyDelayCallback(std::move(continue_closure));
} else if (wait_for_passkeys_timer_.IsRunning()) {
// If there was an attempt to show the new surface with a different trigger
// source while waiting for passkey enumeration, stop the timer and
// proceed without waiting.
wait_for_passkeys_timer_.Stop();
}
ContinueShowKeyboardReplacingSurface(driver->AsWeakPtr(), request,
std::move(delay_callback));
}
void ChromePasswordManagerClient::ContinueShowKeyboardReplacingSurface(
base::WeakPtr<password_manager::PasswordManagerDriver> weak_driver,
const autofill::PasswordSuggestionRequest& request,
password_manager::CredManController::PasskeyDelayCallback delay_callback) {
// The delay callback gets split because one instance has to be passed to the
// CredMan controller. If CredMan will not be used, that instance is destroyed
// without being called.
auto split_delay_callback =
base::SplitOnceCallback(std::move(delay_callback));
password_manager::ContentPasswordManagerDriver* content_driver =
static_cast<password_manager::ContentPasswordManagerDriver*>(
weak_driver.get());
if (GetOrCreateCredManController()->Show(
GetWebAuthnCredManDelegateForDriver(weak_driver.get()),
std::make_unique<PasswordCredentialFillerImpl>(weak_driver, request),
content_driver->AsWeakPtrImpl(),
request.field.show_webauthn_credentials,
std::move(split_delay_callback.first))) {
return;
}
// base::Unretained() is safe: if the callback is called, AccountStorageNotice
// is alive, then so is its parent ChromePasswordManagerClient.
MaybeShowAccountStorageNotice(base::BindOnce(
&ChromePasswordManagerClient::
ShowKeyboardReplacingSurfaceOnAccountStorageNoticeDone,
base::Unretained(this), content_driver->AsWeakPtrImpl(),
request.field, // Intentional & cheap copy.
std::make_unique<PasswordCredentialFillerImpl>(weak_driver, request),
std::move(split_delay_callback.second)));
}
void ChromePasswordManagerClient::
ShowKeyboardReplacingSurfaceOnAccountStorageNoticeDone(
base::WeakPtr<password_manager::ContentPasswordManagerDriver>
weak_driver,
autofill::TriggeringField triggering_field,
std::unique_ptr<PasswordCredentialFillerImpl> filler,
password_manager::CredManController::PasskeyDelayCallback
delay_callback) {
// TODO(crbug.com/346748438): Maybe don't show TTF if there was a navigation.
if (!weak_driver) {
// No further suggestions are possible: without the driver, there is no
// PasswordAutofillManager anymore.
return;
}
password_manager::ContentPasswordManagerDriver* driver = weak_driver.get();
auto* webauthn_delegate = GetWebAuthnCredentialsDelegateForDriver(driver);
std::vector<password_manager::PasskeyCredential> passkeys;
bool should_show_hybrid_option = false;
if (webauthn_delegate) {
webauthn_delegate->NotifyForPasskeysDisplay();
auto maybe_passkeys = webauthn_delegate->GetPasskeys();
if (maybe_passkeys.has_value()) {
passkeys = *maybe_passkeys.value();
should_show_hybrid_option =
webauthn_delegate->IsSecurityKeyOrHybridFlowAvailable();
} else if (!delay_callback.is_null() &&
maybe_passkeys.error() ==
password_manager::WebAuthnCredentialsDelegate::
PasskeysUnavailableReason::kNotReceived) {
base::OnceCallback<void(base::OnceClosure)> notification_callback =
base::BindOnce(&password_manager::WebAuthnCredentialsDelegate::
RequestNotificationWhenPasskeysReady,
webauthn_delegate->AsWeakPtr());
std::move(delay_callback).Run(std::move(notification_callback));
return;
}
}
const PasswordForm* form_to_fill = password_manager_.GetParsedObservedForm(
driver, triggering_field.element_id);
auto ttf_controller_autofill_delegate =
std::make_unique<TouchToFillControllerAutofillDelegate>(
this, GetDeviceAuthenticator(), webauthn_delegate->AsWeakPtr(),
std::move(filler), form_to_fill, triggering_field.element_id,
TouchToFillControllerAutofillDelegate::ShowHybridOption(
should_show_hybrid_option));
TouchToFillController* ttf_controller = GetOrCreateTouchToFillController();
ttf_controller->InitData(
credential_cache_
.GetCredentialStore(URLToOrigin(driver->GetLastCommittedURL()))
.GetCredentials(),
std::move(passkeys), driver->AsWeakPtrImpl());
if (!ttf_controller->Show(std::move(ttf_controller_autofill_delegate),
GetWebAuthnCredManDelegateForDriver(driver))) {
driver->GetPasswordAutofillManager()->ShowSuggestions(triggering_field);
}
}
#endif
bool ChromePasswordManagerClient::IsReauthBeforeFillingRequired(
device_reauth::DeviceAuthenticator* authenticator) {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
if (!GetLocalStatePrefs() || !GetPrefs() || !authenticator) {
return false;
}
return GetPasswordFeatureManager()
->IsBiometricAuthenticationBeforeFillingEnabled();
#elif BUILDFLAG(IS_ANDROID)
if (base::android::BuildInfo::GetInstance()->is_automotive()) {
CHECK(authenticator);
return true;
}
if (!authenticator || !GetPrefs()) {
return false;
}
device_reauth::BiometricStatus biometric_status =
authenticator->GetBiometricAvailabilityStatus();
base::UmaHistogramBoolean(
"PasswordManager.BiometricAuthPwdFillAndroid."
"CanAuthenticateWithBiometricOrScreenLock",
biometric_status != device_reauth::BiometricStatus::kUnavailable);
switch (biometric_status) {
case device_reauth::BiometricStatus::kRequired:
return true;
case device_reauth::BiometricStatus::kBiometricsAvailable:
case device_reauth::BiometricStatus::kOnlyLskfAvailable:
return base::FeatureList::IsEnabled(
password_manager::features::kBiometricTouchToFill) &&
GetPrefs()->GetBoolean(password_manager::prefs::
kBiometricAuthenticationBeforeFilling);
case device_reauth::BiometricStatus::kUnavailable:
return false;
}
#else
return false;
#endif
}
std::unique_ptr<device_reauth::DeviceAuthenticator>
ChromePasswordManagerClient::GetDeviceAuthenticator() {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || \
BUILDFLAG(IS_CHROMEOS)
device_reauth::DeviceAuthParams params(
base::Seconds(60), device_reauth::DeviceAuthSource::kPasswordManager);
return ChromeDeviceAuthenticatorFactory::GetForProfile(
profile_, web_contents()->GetTopLevelNativeWindow(), params);
#else
return nullptr;
#endif
}
void ChromePasswordManagerClient::GeneratePassword(
PasswordGenerationType type) {
#if BUILDFLAG(IS_ANDROID)
PasswordGenerationController* generation_controller =
PasswordGenerationController::GetIfExisting(web_contents());
base::WeakPtr<PasswordManagerDriver> driver =
generation_controller->GetActiveFrameDriver();
if (!driver) {
return;
}
password_manager::ContentPasswordManagerDriver* content_driver =
static_cast<password_manager::ContentPasswordManagerDriver*>(
driver.get());
#else
password_manager::ContentPasswordManagerDriver* content_driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
web_contents()->GetFocusedFrame());
if (!content_driver) {
return;
}
#endif
// Using unretained pointer is safe because |this| outlives
// ContentPasswordManagerDriver that holds the connection.
content_driver->GeneratePassword(base::BindOnce(
&ChromePasswordManagerClient::GenerationResultAvailable,
base::Unretained(this), type, content_driver->AsWeakPtrImpl()));
}
void ChromePasswordManagerClient::NotifyUserAutoSignin(
std::vector<std::unique_ptr<PasswordForm>> local_forms,
const url::Origin& origin) {
DCHECK(!local_forms.empty());
helper_.NotifyUserAutoSignin();
#if BUILDFLAG(IS_ANDROID)
ShowAutoSigninPrompt(web_contents(), local_forms[0]->username_value);
#else
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnAutoSignin(std::move(local_forms),
origin);
}
#endif
}
void ChromePasswordManagerClient::NotifyUserCouldBeAutoSignedIn(
std::unique_ptr<PasswordForm> form) {
helper_.NotifyUserCouldBeAutoSignedIn(std::move(form));
}
void ChromePasswordManagerClient::NotifySuccessfulLoginWithExistingPassword(
std::unique_ptr<password_manager::PasswordFormManagerForUI>
submitted_manager) {
helper_.NotifySuccessfulLoginWithExistingPassword(
std::move(submitted_manager));
}
void ChromePasswordManagerClient::NotifyStorePasswordCalled() {
helper_.NotifyStorePasswordCalled();
was_store_ever_called_ = true;
}
bool ChromePasswordManagerClient::IsPasswordChangeOngoing() {
ChromePasswordChangeService* password_change_service =
PasswordChangeServiceFactory::GetForProfile(profile_);
if (password_change_service) {
auto* delegate =
password_change_service->GetPasswordChangeDelegate(web_contents());
if (delegate) {
return delegate->GetCurrentState() ==
PasswordChangeDelegate::State::kChangingPassword;
}
}
return false;
}
void ChromePasswordManagerClient::NotifyOnSuccessfulLogin(
const std::u16string& submitted_username) {
#if BUILDFLAG(IS_ANDROID)
if (!username_filled_by_touch_to_fill_) {
return;
}
base::TimeDelta delta =
base::Time::Now() - username_filled_by_touch_to_fill_->second;
// Filter out unrelated logins.
if (delta < base::Minutes(1) &&
username_filled_by_touch_to_fill_->first == submitted_username) {
UmaHistogramMediumTimes("PasswordManager.TouchToFill.TimeToSuccessfulLogin",
delta);
ukm::builders::TouchToFill_TimeToSuccessfulLogin(GetUkmSourceId())
.SetTimeToSuccessfulLogin(
ukm::GetExponentialBucketMinForUserTiming(delta.InMilliseconds()))
.Record(ukm::UkmRecorder::Get());
base::UmaHistogramBoolean(
"PasswordManager.TouchToFill.SuccessfulSubmissionWasObserved", true);
username_filled_by_touch_to_fill_.reset();
} else {
ResetSubmissionTrackingAfterTouchToFill();
}
#else
ChromePasswordChangeService* password_change_service =
PasswordChangeServiceFactory::GetForProfile(profile_);
if (password_change_service &&
password_change_service->GetPasswordChangeDelegate(web_contents())) {
password_change_service->GetPasswordChangeDelegate(web_contents())
->OnPasswordFormSubmission(web_contents());
}
#endif // BUILDFLAG(IS_ANDROID)
}
#if BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::StartSubmissionTrackingAfterTouchToFill(
const std::u16string& filled_username) {
username_filled_by_touch_to_fill_ =
std::make_pair(filled_username, base::Time::Now());
}
void ChromePasswordManagerClient::ResetSubmissionTrackingAfterTouchToFill() {
if (username_filled_by_touch_to_fill_.has_value()) {
base::UmaHistogramBoolean(
"PasswordManager.TouchToFill.SuccessfulSubmissionWasObserved", false);
username_filled_by_touch_to_fill_.reset();
}
}
#endif // BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::UpdateCredentialCache(
const url::Origin& origin,
base::span<const PasswordForm> best_matches,
bool is_blocklisted,
std::optional<PasswordStoreBackendError> backend_error) {
#if BUILDFLAG(IS_ANDROID)
credential_cache_.SaveCredentialsAndBlocklistedForOrigin(
best_matches, CredentialCache::IsOriginBlocklisted(is_blocklisted),
backend_error, origin);
#endif
}
void ChromePasswordManagerClient::AutomaticPasswordSave(
std::unique_ptr<password_manager::PasswordFormManagerForUI> saved_form,
bool is_update_confirmation) {
#if BUILDFLAG(IS_ANDROID)
generated_password_saved_message_delegate_.ShowPrompt(web_contents(),
std::move(saved_form));
#else
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnAutomaticPasswordSave(
std::move(saved_form), is_update_confirmation);
}
#endif
}
void ChromePasswordManagerClient::PasswordWasAutofilled(
base::span<const PasswordForm> best_matches,
const url::Origin& origin,
base::span<const PasswordForm> federated_matches,
bool was_autofilled_on_pageload) {
#if !BUILDFLAG(IS_ANDROID)
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (!manage_passwords_ui_controller) {
return;
}
manage_passwords_ui_controller->OnPasswordAutofilled(best_matches, origin,
federated_matches);
#endif
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
if (was_autofilled_on_pageload &&
!IsAuthenticatorRequestWindowUrl(GetLastCommittedURL()) &&
password_manager_util::
ShouldShowBiometricAuthenticationBeforeFillingPromo(this)) {
manage_passwords_ui_controller->OnBiometricAuthenticationForFilling(
GetPrefs());
}
#endif
}
void ChromePasswordManagerClient::AutofillHttpAuth(
const PasswordForm& preferred_match,
const password_manager::PasswordFormManagerForUI* form_manager) {
httpauth_manager_.Autofill(preferred_match, form_manager);
DCHECK(!form_manager->GetBestMatches().empty());
PasswordWasAutofilled(form_manager->GetBestMatches(),
url::Origin::Create(form_manager->GetURL()), {},
/*was_autofilled_on_pageload=*/false);
}
void ChromePasswordManagerClient::NotifyUserCredentialsWereLeaked(
password_manager::LeakedPasswordDetails details) {
#if BUILDFLAG(IS_ANDROID)
auto metrics_recorder = std::make_unique<
password_manager::metrics_util::LeakDialogMetricsRecorder>(
web_contents()->GetPrimaryMainFrame()->GetPageUkmSourceId(),
password_manager::GetLeakDialogType(details.leak_type));
const syncer::SyncService* sync_service =
SyncServiceFactory::GetForProfile(profile_);
// If the leaked credential is stored in the account store, the user should be
// able to access password check for the account from the leak detection
// dialog that is about to be shown. If the leaked credential is stored only
// in the local store, password check for local should be accessible from the
// dialog.
std::string account =
details.in_account_store &&
password_manager::sync_util::HasChosenToSyncPasswords(
sync_service)
? sync_service->GetAccountInfo().email
: "";
(new CredentialLeakControllerAndroid(
details.leak_type, details.origin, details.username, profile_,
web_contents()->GetTopLevelNativeWindow(),
std::make_unique<PasswordCheckupLauncherHelperImpl>(),
std::move(metrics_recorder), account))
->ShowDialog();
#else // !BUILDFLAG(IS_ANDROID)
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnCredentialLeak(std::move(details));
}
#endif // BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::NotifyKeychainError() {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnKeychainError();
}
#endif
}
PrefService* ChromePasswordManagerClient::GetPrefs() const {
return profile_->GetPrefs();
}
PrefService* ChromePasswordManagerClient::GetLocalStatePrefs() const {
return g_browser_process->local_state();
}
const syncer::SyncService* ChromePasswordManagerClient::GetSyncService() const {
if (SyncServiceFactory::HasSyncService(profile_)) {
return SyncServiceFactory::GetForProfile(profile_);
}
return nullptr;
}
affiliations::AffiliationService*
ChromePasswordManagerClient::GetAffiliationService() {
return AffiliationServiceFactory::GetForProfile(profile_);
}
password_manager::PasswordStoreInterface*
ChromePasswordManagerClient::GetProfilePasswordStore() const {
// Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord
// itself when it shouldn't access the PasswordStore.
return ProfilePasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS)
.get();
}
password_manager::PasswordStoreInterface*
ChromePasswordManagerClient::GetAccountPasswordStore() const {
// Always use EXPLICIT_ACCESS as the password manager checks IsOffTheRecord
// itself when it shouldn't access the PasswordStore.
return AccountPasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS)
.get();
}
password_manager::PasswordReuseManager*
ChromePasswordManagerClient::GetPasswordReuseManager() const {
return PasswordReuseManagerFactory::GetForProfile(profile_);
}
password_manager::PasswordChangeServiceInterface*
ChromePasswordManagerClient::GetPasswordChangeService() const {
return PasswordChangeServiceFactory::GetForProfile(profile_);
}
bool ChromePasswordManagerClient::WasLastNavigationHTTPError() const {
DCHECK(web_contents());
std::unique_ptr<password_manager::BrowserSavePasswordProgressLogger> logger;
autofill::LogManager* log_manager = GetOrCreateLogManager();
if (log_manager && log_manager->IsLoggingActive()) {
logger =
std::make_unique<password_manager::BrowserSavePasswordProgressLogger>(
log_manager);
logger->LogMessage(Logger::STRING_WAS_LAST_NAVIGATION_HTTP_ERROR_METHOD);
}
content::NavigationEntry* entry =
web_contents()->GetController().GetVisibleEntry();
if (!entry) {
return false;
}
int http_status_code = entry->GetHttpStatusCode();
if (logger) {
logger->LogNumber(Logger::STRING_HTTP_STATUS_CODE, http_status_code);
}
if (http_status_code >= 400 && http_status_code < 600) {
return true;
}
return false;
}
net::CertStatus ChromePasswordManagerClient::GetMainFrameCertStatus() const {
content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
if (!entry) {
return 0;
}
return entry->GetSSL().cert_status;
}
void ChromePasswordManagerClient::PromptUserToEnableAutosignin() {
#if BUILDFLAG(IS_ANDROID)
// Dialog is deleted by the Java counterpart after user interacts with it.
AutoSigninFirstRunDialogAndroid* auto_signin_first_run_dialog =
new AutoSigninFirstRunDialogAndroid(web_contents());
auto_signin_first_run_dialog->ShowDialog();
#else
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnPromptEnableAutoSignin();
}
#endif
}
bool ChromePasswordManagerClient::IsOffTheRecord() const {
return web_contents()->GetBrowserContext()->IsOffTheRecord();
}
profile_metrics::BrowserProfileType
ChromePasswordManagerClient::GetProfileType() const {
content::BrowserContext* browser_context =
web_contents()->GetBrowserContext();
return profile_metrics::GetBrowserProfileType(browser_context);
}
const password_manager::PasswordManagerInterface*
ChromePasswordManagerClient::GetPasswordManager() const {
return &password_manager_;
}
const password_manager::PasswordFeatureManager*
ChromePasswordManagerClient::GetPasswordFeatureManager() const {
return &password_feature_manager_;
}
password_manager::HttpAuthManager*
ChromePasswordManagerClient::GetHttpAuthManager() {
return &httpauth_manager_;
}
autofill::AutofillCrowdsourcingManager*
ChromePasswordManagerClient::GetAutofillCrowdsourcingManager() {
if (auto* client =
autofill::ContentAutofillClient::FromWebContents(web_contents())) {
return &client->GetCrowdsourcingManager();
}
return nullptr;
}
bool ChromePasswordManagerClient::IsCommittedMainFrameSecure() const {
return network::IsOriginPotentiallyTrustworthy(
web_contents()->GetPrimaryMainFrame()->GetLastCommittedOrigin());
}
const GURL& ChromePasswordManagerClient::GetLastCommittedURL() const {
return web_contents()->GetLastCommittedURL();
}
url::Origin ChromePasswordManagerClient::GetLastCommittedOrigin() const {
DCHECK(web_contents());
return web_contents()->GetPrimaryMainFrame()->GetLastCommittedOrigin();
}
const password_manager::CredentialsFilter*
ChromePasswordManagerClient::GetStoreResultFilter() const {
return &credentials_filter_;
}
autofill::LogManager* ChromePasswordManagerClient::GetCurrentLogManager() {
return GetOrCreateLogManager();
}
autofill::LogManager* ChromePasswordManagerClient::GetOrCreateLogManager()
const {
if (!log_manager_ && log_router_ && log_router_->HasReceivers()) {
ContentPasswordManagerDriverFactory* driver_factory = GetDriverFactory();
log_manager_ = autofill::LogManager::Create(
log_router_, base::BindRepeating(&ContentPasswordManagerDriverFactory::
RequestSendLoggingAvailability,
base::Unretained(driver_factory)));
driver_factory->RequestSendLoggingAvailability();
}
return log_manager_.get();
}
void ChromePasswordManagerClient::AnnotateNavigationEntry(
bool has_password_field) {
content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
if (!entry) {
return;
}
SerializedNavigationEntry::PasswordState old_state =
sessions::GetPasswordStateFromNavigation(entry);
SerializedNavigationEntry::PasswordState new_state =
(has_password_field ? SerializedNavigationEntry::HAS_PASSWORD_FIELD
: SerializedNavigationEntry::NO_PASSWORD_FIELD);
if (new_state > old_state) {
SetPasswordStateInNavigation(new_state, entry);
if (HistoryTabHelper* history_tab_helper =
HistoryTabHelper::FromWebContents(web_contents())) {
history_tab_helper->OnPasswordStateUpdated(new_state);
}
}
}
autofill::LanguageCode ChromePasswordManagerClient::GetPageLanguage() const {
// TODO(crbug.com/41430413): iOS vs other platforms extracts language from
// the top level frame vs whatever frame directly holds the form.
auto* translate_manager =
ChromeTranslateClient::GetManagerFromWebContents(web_contents());
if (translate_manager) {
return autofill::LanguageCode(
translate_manager->GetLanguageState()->source_language());
}
return autofill::LanguageCode();
}
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
safe_browsing::PasswordProtectionService*
ChromePasswordManagerClient::GetPasswordProtectionService() const {
return safe_browsing::ChromePasswordProtectionService::
GetPasswordProtectionService(profile_);
}
#endif
#if defined(ON_FOCUS_PING_ENABLED) && BUILDFLAG(SAFE_BROWSING_AVAILABLE)
void ChromePasswordManagerClient::CheckSafeBrowsingReputation(
const GURL& form_action,
const GURL& frame_url) {
safe_browsing::PasswordProtectionService* pps =
GetPasswordProtectionService();
if (pps) {
pps->MaybeStartPasswordFieldOnFocusRequest(
web_contents(), web_contents()->GetLastCommittedURL(), form_action,
frame_url, pps->GetAccountInfo().hosted_domain);
}
}
#endif // defined(ON_FOCUS_PING_ENABLED) && BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS) || BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::MaybeReportEnterpriseLoginEvent(
const GURL& url,
bool is_federated,
const url::SchemeHostPort& federated_origin,
const std::u16string& login_user_name) const {
#if BUILDFLAG(IS_ANDROID)
if (!base::FeatureList::IsEnabled(
enterprise_connectors::kEnterpriseSecurityEventReportingOnAndroid)) {
return;
}
#endif // BUILDFLAG(IS_ANDROID)
enterprise_connectors::ReportingEventRouter* router =
enterprise_connectors::ReportingEventRouterFactory::GetForBrowserContext(
profile_);
if (!router) {
return;
}
// The router is responsible for checking if the reporting of this event type
// is enabled by the admin.
router->OnLoginEvent(url, is_federated, federated_origin, login_user_name);
}
void ChromePasswordManagerClient::MaybeReportEnterprisePasswordBreachEvent(
const std::vector<std::pair<GURL, std::u16string>>& identities) const {
#if BUILDFLAG(IS_ANDROID)
if (!base::FeatureList::IsEnabled(
enterprise_connectors::kEnterpriseSecurityEventReportingOnAndroid)) {
return;
}
#endif // BUILDFLAG(IS_ANDROID)
enterprise_connectors::ReportingEventRouter* router =
enterprise_connectors::ReportingEventRouterFactory::GetForBrowserContext(
profile_);
if (!router) {
return;
}
// The router is responsible for checking if the reporting of this event type
// is enabled by the admin.
router->OnPasswordBreach(kPasswordBreachEntryTrigger, identities);
}
#endif // BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS) || BUILDFLAG(IS_ANDROID)
ukm::SourceId ChromePasswordManagerClient::GetUkmSourceId() {
return web_contents()->GetPrimaryMainFrame()->GetPageUkmSourceId();
}
PasswordManagerMetricsRecorder*
ChromePasswordManagerClient::GetMetricsRecorder() {
if (!metrics_recorder_) {
metrics_recorder_.emplace(GetUkmSourceId());
}
return base::OptionalToPtr(metrics_recorder_);
}
#if BUILDFLAG(IS_ANDROID)
password_manager::FirstCctPageLoadPasswordsUkmRecorder*
ChromePasswordManagerClient::GetFirstCctPageLoadUkmRecorder() {
if (first_cct_page_load_metrics_recorder_) {
return first_cct_page_load_metrics_recorder_.get();
}
return nullptr;
}
void ChromePasswordManagerClient::PotentialSaveFormSubmitted() {
TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents());
if (!tab_android || !tab_android->IsCustomTab()) {
return;
}
// If the recorder existed already, it means that the session it was
// recording was not the latest form submission in the tab so it wouldn't
// have been recording metrics anyway.Its intended that we destroy and
// recreate a new recorder here.
cct_saving_metrics_recorder_bridge_ =
CctPasswordSavingMetricsRecorderBridge::MaybeCreate(web_contents());
if (cct_saving_metrics_recorder_bridge_) {
cct_saving_metrics_recorder_bridge_->OnPotentialSaveFormSubmitted();
}
}
#endif
password_manager::PasswordRequirementsService*
ChromePasswordManagerClient::GetPasswordRequirementsService() {
return password_manager::PasswordRequirementsServiceFactory::
GetForBrowserContext(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
}
favicon::FaviconService* ChromePasswordManagerClient::GetFaviconService() {
return FaviconServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
}
signin::IdentityManager* ChromePasswordManagerClient::GetIdentityManager() {
return IdentityManagerFactory::GetForProfile(profile_->GetOriginalProfile());
}
const signin::IdentityManager* ChromePasswordManagerClient::GetIdentityManager()
const {
return IdentityManagerFactory::GetForProfile(profile_->GetOriginalProfile());
}
FieldInfoManager* ChromePasswordManagerClient::GetFieldInfoManager() const {
return FieldInfoManagerFactory::GetForProfile(profile_);
}
scoped_refptr<network::SharedURLLoaderFactory>
ChromePasswordManagerClient::GetURLLoaderFactory() {
return profile_->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess();
}
network::mojom::NetworkContext* ChromePasswordManagerClient::GetNetworkContext()
const {
return profile_->GetDefaultStoragePartition()->GetNetworkContext();
}
void ChromePasswordManagerClient::UpdateFormManagers() {
password_manager_.UpdateFormManagers();
}
void ChromePasswordManagerClient::NavigateToManagePasswordsPage(
password_manager::ManagePasswordsReferrer referrer) {
#if BUILDFLAG(IS_ANDROID)
password_manager_launcher::ShowPasswordSettings(web_contents(), referrer,
/*manage_passkeys=*/false);
#else
Browser* browser = chrome::FindBrowserWithTab(web_contents());
if (!browser) {
browser = chrome::FindLastActive();
}
::NavigateToManagePasswordsPage(browser, referrer);
#endif
}
void ChromePasswordManagerClient::InformPasswordChangeServiceOfOtpPresent() {
ChromePasswordChangeService* password_change_service =
PasswordChangeServiceFactory::GetForProfile(profile_);
if (password_change_service &&
password_change_service->GetPasswordChangeDelegate(web_contents())) {
password_change_service->GetPasswordChangeDelegate(web_contents())
->OnOtpFieldDetected(web_contents());
}
}
#if BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::NavigateToManagePasskeysPage(
password_manager::ManagePasswordsReferrer referrer) {
password_manager_launcher::ShowPasswordSettings(web_contents(), referrer,
/*manage_passkeys=*/true);
}
#endif
bool ChromePasswordManagerClient::IsIsolationForPasswordSitesEnabled() const {
// TODO(crbug.com/41401202): Move the following function (and the feature) to
// the password component. Then remove IsIsolationForPasswordsSitesEnabled()
// from the PasswordManagerClient interface.
return site_isolation::SiteIsolationPolicy::
IsIsolationForPasswordSitesEnabled();
}
bool ChromePasswordManagerClient::IsNewTabPage() const {
auto origin = GetLastCommittedURL().DeprecatedGetOriginAsURL();
return origin ==
GURL(chrome::kChromeUINewTabPageURL).DeprecatedGetOriginAsURL() ||
origin == GURL(chrome::kChromeUINewTabURL).DeprecatedGetOriginAsURL();
}
password_manager::WebAuthnCredentialsDelegate*
ChromePasswordManagerClient::GetWebAuthnCredentialsDelegateForDriver(
PasswordManagerDriver* driver) {
auto* frame_host =
static_cast<password_manager::ContentPasswordManagerDriver*>(driver)
->render_frame_host();
return ChromeWebAuthnCredentialsDelegateFactory::GetFactory(web_contents())
->GetDelegateForFrame(frame_host);
}
#if BUILDFLAG(IS_ANDROID)
webauthn::WebAuthnCredManDelegate*
ChromePasswordManagerClient::GetWebAuthnCredManDelegateForDriver(
PasswordManagerDriver* driver) {
auto* frame_host =
static_cast<password_manager::ContentPasswordManagerDriver*>(driver)
->render_frame_host();
return webauthn::WebAuthnCredManDelegateFactory::GetFactory(web_contents())
->GetRequestDelegate(frame_host);
}
void ChromePasswordManagerClient::MarkSharedCredentialsAsNotified(
const GURL& url) {
for (const PasswordForm& form :
credential_cache_.GetCredentialStore(URLToOrigin(url))
.GetUnnotifiedSharedCredentials()) {
// Make a non-const copy so we can modify it.
password_manager::PasswordForm updatedForm = form;
updatedForm.sharing_notification_displayed = true;
if (updatedForm.IsUsingAccountStore()) {
GetAccountPasswordStore()->UpdateLogin(std::move(updatedForm));
} else {
GetProfilePasswordStore()->UpdateLogin(std::move(updatedForm));
}
}
}
password_manager::SmsOtpBackend* ChromePasswordManagerClient::GetSmsOtpBackend()
const {
return AndroidSmsOtpBackendFactory::GetForProfile(profile_);
}
#endif // BUILDFLAG(IS_ANDROID)
version_info::Channel ChromePasswordManagerClient::GetChannel() const {
return chrome::GetChannel();
}
void ChromePasswordManagerClient::RefreshPasswordManagerSettingsIfNeeded()
const {
#if BUILDFLAG(IS_ANDROID)
if (PasswordManagerSettingsService* settings_service =
PasswordManagerSettingsServiceFactory::GetForProfile(profile_)) {
settings_service->RequestSettingsFromBackend();
}
#endif
}
#if !BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::OpenPasswordDetailsBubble(
const PasswordForm& form) {
PasswordsClientUIDelegate* manage_passwords_ui_controller =
PasswordsClientUIDelegateFromWebContents(web_contents());
if (manage_passwords_ui_controller) {
manage_passwords_ui_controller->OnOpenPasswordDetailsBubble(form);
}
}
#endif // !BUILDFLAG(IS_ANDROID)
std::unique_ptr<
password_manager::PasswordCrossDomainConfirmationPopupController>
ChromePasswordManagerClient::ShowCrossDomainConfirmationPopup(
const gfx::RectF& element_bounds,
base::i18n::TextDirection text_direction,
const GURL& domain,
const std::u16string& password_hostname,
bool show_warning_text,
base::OnceClosure confirmation_callback) {
#if BUILDFLAG(IS_ANDROID)
auto controller =
cross_domain_confirmation_popup_factory_for_testing_
? cross_domain_confirmation_popup_factory_for_testing_.Run()
: std::make_unique<AcknowledgeGroupedCredentialSheetController>();
controller->ShowAcknowledgeSheet(
GetDisplayOrigin(url::Origin::Create(domain)),
base::UTF16ToUTF8(password_hostname),
web_contents()->GetTopLevelNativeWindow(),
base::BindOnce(
[](base::OnceClosure confirmation_callback,
AcknowledgeGroupedCredentialSheetBridge::DismissReason
dismiss_reason) {
if (dismiss_reason != AcknowledgeGroupedCredentialSheetBridge::
DismissReason::kAccept) {
return;
}
std::move(confirmation_callback).Run();
},
std::move(confirmation_callback)));
return controller;
#else
gfx::Rect client_area = web_contents()->GetContainerBounds();
gfx::RectF element_bounds_in_screen_space =
element_bounds + client_area.OffsetFromOrigin();
auto controller =
cross_domain_confirmation_popup_factory_for_testing_
? cross_domain_confirmation_popup_factory_for_testing_.Run()
: std::make_unique<
PasswordCrossDomainConfirmationPopupControllerImpl>(
web_contents());
controller->Show(element_bounds_in_screen_space, text_direction, domain,
password_hostname, std::move(confirmation_callback),
show_warning_text);
return controller;
#endif // BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::TriggerSignIn(
signin_metrics::AccessPoint access_point) const {
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
signin_ui_util::ShowReauthForPrimaryAccountWithAuthError(profile_,
access_point);
#endif
}
void ChromePasswordManagerClient::AutomaticGenerationAvailable(
const autofill::password_generation::PasswordGenerationUIData& ui_data) {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckChildProcessSecurityPolicyForURL(
rfh, ui_data.form_data.url(),
BadMessageReason::
CPMD_BAD_ORIGIN_AUTOMATIC_GENERATION_STATUS_CHANGED)) {
return;
}
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
password_manager::ContentPasswordManagerDriver* driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
rfh);
// This method is called over Mojo via a RenderFrameHostReceiverSet; the
// current target frame must be live.
CHECK(driver);
// This guards against possibility that generation was available on page load
// but later became unavailable due to inability to save passwords.
if (!driver->GetPasswordGenerationHelper() ||
!driver->GetPasswordGenerationHelper()->IsGenerationEnabled(
/*log_debug_data*/ false)) {
return;
}
#if BUILDFLAG(IS_ANDROID)
if (!ShouldAcceptFocusEvent(web_contents(), driver,
FocusedFieldType::kFillablePasswordField)) {
return;
}
PasswordGenerationController* generation_controller =
PasswordGenerationController::GetOrCreate(web_contents());
gfx::RectF element_bounds_in_screen_space = TransformToRootCoordinates(
password_generation_driver_receivers_.GetCurrentTargetFrame(),
ui_data.bounds);
auto has_saved_credentials =
!credential_cache_.GetCredentialStore(rfh->GetLastCommittedOrigin())
.GetCredentials()
.empty();
generation_controller->OnAutomaticGenerationAvailable(
driver->AsWeakPtrImpl(), ui_data, has_saved_credentials,
element_bounds_in_screen_space);
// Trigger password suggestions. This is a fallback case if the field was
// wrongly classified as new password field.
driver->GetPasswordAutofillManager()->MaybeShowPasswordSuggestions(
element_bounds_in_screen_space, ui_data.text_direction);
#else
// Attempt to show the autofill dropdown UI first.
gfx::RectF element_bounds_in_top_frame_space =
TransformToRootCoordinates(driver->render_frame_host(), ui_data.bounds);
if (driver->GetPasswordAutofillManager()
->MaybeShowPasswordSuggestionsWithGeneration(
element_bounds_in_top_frame_space, ui_data.text_direction,
/*show_password_suggestions=*/
ui_data.is_generation_element_password_type)) {
// (see crbug.com/1338105)
if (popup_controller_) {
popup_controller_->GeneratedPasswordRejected();
}
driver->SetSuggestionAvailability(
ui_data.generation_element_id,
autofill::mojom::AutofillSuggestionAvailability::kAutofillAvailable);
return;
}
if (!ui_data.generation_rejected) {
ShowPasswordGenerationPopup(PasswordGenerationType::kAutomatic, driver,
ui_data);
}
#endif // BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::PresaveGeneratedPassword(
const autofill::FormData& form_data,
const std::u16string& password_value) {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
#if !BUILDFLAG(IS_ANDROID)
if (popup_controller_) {
popup_controller_->UpdateGeneratedPassword(password_value);
}
#endif // !BUILDFLAG(IS_ANDROID)
PasswordManagerDriver* driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
rfh);
// This method is called over Mojo via a RenderFrameHostReceiverSet; the
// current target frame must be live.
CHECK(driver);
password_manager_.OnPresaveGeneratedPassword(
driver,
password_manager::GetFormWithFrameAndFormMetaData(
password_generation_driver_receivers_.GetCurrentTargetFrame(),
form_data),
password_value);
}
void ChromePasswordManagerClient::PasswordNoLongerGenerated(
const autofill::FormData& form_data) {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
PasswordManagerDriver* driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
rfh);
// This method is called over Mojo via a RenderFrameHostReceiverSet; the
// current target frame must be live.
CHECK(driver);
password_manager_.OnPasswordNoLongerGenerated(
driver, password_manager::GetFormWithFrameAndFormMetaData(
password_generation_driver_receivers_.GetCurrentTargetFrame(),
form_data));
#if !BUILDFLAG(IS_ANDROID)
PasswordGenerationPopupController* controller = popup_controller_.get();
if (controller &&
controller->state() ==
PasswordGenerationPopupController::kEditGeneratedPassword) {
popup_controller_->GeneratedPasswordRejected();
}
#endif // !BUILDFLAG(IS_ANDROID)
}
#if !BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::ShowPasswordEditingPopup(
const gfx::RectF& bounds,
const autofill::FormData& form_data,
autofill::FieldRendererId field_renderer_id,
const std::u16string& password_value) {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
if (!password_manager::bad_message::CheckGeneratedPassword(rfh,
password_value)) {
return;
}
auto* driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
rfh);
// This method is called over Mojo via a RenderFrameHostReceiverSet; the
// current target frame must be live.
CHECK(driver);
gfx::RectF element_bounds_in_screen_space =
GetBoundsInScreenSpace(TransformToRootCoordinates(
password_generation_driver_receivers_.GetCurrentTargetFrame(),
bounds));
autofill::password_generation::PasswordGenerationUIData ui_data(
bounds, /*max_length=*/0, /*generation_element=*/std::u16string(),
field_renderer_id,
/*is_generation_element_password_type=*/true, base::i18n::TextDirection(),
password_manager::GetFormWithFrameAndFormMetaData(
password_generation_driver_receivers_.GetCurrentTargetFrame(),
form_data),
/*input_field_empty=*/false);
popup_controller_ = PasswordGenerationPopupControllerImpl::GetOrCreate(
popup_controller_, element_bounds_in_screen_space, ui_data,
driver->AsWeakPtr(), observer_, web_contents(),
password_generation_driver_receivers_.GetCurrentTargetFrame());
CHECK(!password_value.empty());
popup_controller_->UpdateGeneratedPassword(password_value);
popup_controller_->Show(
PasswordGenerationPopupController::kEditGeneratedPassword);
}
void ChromePasswordManagerClient::PasswordGenerationRejectedByTyping() {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
if (popup_controller_) {
popup_controller_->GeneratedPasswordRejected();
}
}
void ChromePasswordManagerClient::FrameWasScrolled() {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
if (popup_controller_) {
popup_controller_->FrameWasScrolled();
}
}
void ChromePasswordManagerClient::GenerationElementLostFocus() {
content::RenderFrameHost* rfh =
password_generation_driver_receivers_.GetCurrentTargetFrame();
if (!password_manager::bad_message::CheckFrameNotPrerendering(rfh)) {
return;
}
// TODO(crbug.com/40629608): Look into removing this since FocusedInputChanged
// seems to be a good replacement.
if (popup_controller_) {
popup_controller_->GenerationElementLostFocus();
}
}
#endif // !BUILDFLAG(IS_ANDROID)
autofill::PasswordManagerDelegate*
ChromePasswordManagerClient::GetAutofillDelegate(
const autofill::FieldGlobalId& field_id) {
if (content::RenderFrameHost* rfh = autofill::FindRenderFrameHostByToken(
*web_contents(), field_id.frame_token)) {
if (password_manager::ContentPasswordManagerDriver* driver =
password_manager::ContentPasswordManagerDriver::
GetForRenderFrameHost(rfh)) {
return driver->GetPasswordAutofillManager();
}
}
return nullptr;
}
void ChromePasswordManagerClient::SetTestObserver(
PasswordGenerationPopupObserver* observer) {
observer_ = observer;
}
// static
bool ChromePasswordManagerClient::CanShowBubbleOnURL(const GURL& url) {
std::string scheme = url.scheme();
return (content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
scheme) &&
#if BUILDFLAG(ENABLE_EXTENSIONS)
scheme != extensions::kExtensionScheme &&
#endif
scheme != content::kChromeDevToolsScheme);
}
#if BUILDFLAG(IS_ANDROID)
PasswordAccessoryController*
ChromePasswordManagerClient::GetOrCreatePasswordAccessory() {
return PasswordAccessoryController::GetOrCreate(web_contents(),
&credential_cache_);
}
TouchToFillController*
ChromePasswordManagerClient::GetOrCreateTouchToFillController() {
if (!touch_to_fill_controller_) {
touch_to_fill_controller_ = std::make_unique<TouchToFillController>(
profile_, GetOrCreateKeyboardReplacingSurfaceVisibilityController(),
std::make_unique<AcknowledgeGroupedCredentialSheetController>());
}
return touch_to_fill_controller_.get();
}
void ChromePasswordManagerClient::MaybeShowAccountStorageNotice(
base::OnceClosure callback) {
// Unretained() is safe because `this` outlives `account_storage_notice_`.
auto destroy_notice_cb = base::BindOnce(
[](ChromePasswordManagerClient* client) {
client->account_storage_notice_.reset();
},
base::Unretained(this));
const bool had_notice = account_storage_notice_.get();
account_storage_notice_ = AccountStorageNotice::MaybeShow(
SyncServiceFactory::GetForProfile(profile_), profile_->GetPrefs(),
web_contents()->GetNativeView()->GetWindowAndroid(),
std::move(destroy_notice_cb).Then(std::move(callback)));
// MaybeShow() will return non-null at most once, since this is a one-off
// notice. So the possible cases are:
// - `account_storage_notice_` was null and stayed so: No notice shown, just
// invokes `callback`.
// - `account_storage_notice_` was null and became non-null: Shows the notice.
// - (Speculative) `account_storage_notice_` was non-null and became null:
// Hides the notice and executes `callback`. The alternative would be to
// ignore `callback` and wait for `account_storage_notice_` to go away, but
// that's dangerous (if there's a bug and `account_storage_notice_` is never
// reset, the method would always no-op, breaking the saving/filling
// callers).
CHECK(!had_notice || !account_storage_notice_);
}
password_manager::CredManController*
ChromePasswordManagerClient::GetOrCreateCredManController() {
if (!cred_man_controller_) {
cred_man_controller_ =
std::make_unique<password_manager::CredManController>(
GetOrCreateKeyboardReplacingSurfaceVisibilityController(), this);
}
return cred_man_controller_.get();
}
base::WeakPtr<password_manager::KeyboardReplacingSurfaceVisibilityController>
ChromePasswordManagerClient::
GetOrCreateKeyboardReplacingSurfaceVisibilityController() {
if (!keyboard_replacing_surface_visibility_controller_) {
keyboard_replacing_surface_visibility_controller_ = std::make_unique<
password_manager::KeyboardReplacingSurfaceVisibilityControllerImpl>();
}
return keyboard_replacing_surface_visibility_controller_->AsWeakPtr();
}
#endif // BUILDFLAG(IS_ANDROID)
credential_management::ContentCredentialManager*
ChromePasswordManagerClient::GetContentCredentialManager() {
return &content_credential_manager_;
}
ChromePasswordManagerClient::ChromePasswordManagerClient(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
content::WebContentsUserData<ChromePasswordManagerClient>(*web_contents),
profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
password_manager_(this),
password_feature_manager_(profile_->GetPrefs(),
g_browser_process->local_state(),
SyncServiceFactory::GetForProfile(profile_)),
httpauth_manager_(this),
otp_manager_(this),
content_credential_manager_(
std::make_unique<password_manager::CredentialManagerImpl>(this)),
password_generation_driver_receivers_(web_contents, this),
observer_(nullptr),
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
credentials_filter_(
this,
DiceWebSigninInterceptorFactory::GetForProfile(profile_)),
#else
credentials_filter_(this),
#endif // BUILDFLAG(ENABLE_DICE_SUPPORT)
log_router_(password_manager::PasswordManagerLogRouterFactory::
GetForBrowserContext(profile_)),
helper_(this) {
ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this);
autofill_managers_observation_.Observe(
web_contents, autofill::ScopedAutofillManagersObservation::
InitializationPolicy::kObservePreexistingManagers);
#if BUILDFLAG(IS_ANDROID)
// This prevents the access loss warning from trying to show on opening new
// tabs after the initial attempt to show the sheet on startup.
static bool tried_launching_access_loss_warning_on_startup = false;
if (!tried_launching_access_loss_warning_on_startup) {
tried_launching_access_loss_warning_on_startup = true;
TryToShowAccessLossWarningSheet();
}
#endif // BUILDFLAG(IS_ANDROID)
}
void ChromePasswordManagerClient::PrimaryPageChanged(content::Page& page) {
#if BUILDFLAG(IS_ANDROID)
if (first_cct_page_load_metrics_recorder_) {
first_cct_page_load_metrics_recorder_.reset();
} else {
bool first_cct_page_load =
FirstCctPageLoadMarker::ConsumeMarker(web_contents());
TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents());
if (tab_android && tab_android->IsCustomTab() && first_cct_page_load) {
first_cct_page_load_metrics_recorder_ = std::make_unique<
password_manager::FirstCctPageLoadPasswordsUkmRecorder>(
web_contents()->GetPrimaryMainFrame()->GetPageUkmSourceId());
}
}
#endif // BUILDFLAG(IS_ANDROID)
// Logging has no sense on WebUI sites.
if (GetCurrentLogManager()) {
log_manager_->SetSuspended(web_contents()->GetWebUI() != nullptr);
}
// Send any collected metrics by destroying the metrics recorder.
metrics_recorder_.reset();
httpauth_manager_.OnDidFinishMainFrameNavigation();
// From this point on, the ContentCredentialManager will service API calls
// in the context of the new WebContents::GetLastCommittedURL, which may
// very well be cross-origin. Disconnect existing client, and drop pending
// requests.
content_credential_manager_.DisconnectBinding();
#if BUILDFLAG(IS_ANDROID)
credential_cache_.ClearCredentials();
#endif // BUILDFLAG(IS_ANDROID)
// Hide form filling UI on navigating away.
HideFillingUI();
}
void ChromePasswordManagerClient::WebContentsDestroyed() {
// crbug/1090011
// Drop the connection before the WebContentsObserver destructors are invoked.
// Other classes may contain callbacks to the Mojo methods. Those callbacks
// don't like to be destroyed earlier than the pipe itself.
content_credential_manager_.DisconnectBinding();
#if BUILDFLAG(IS_ANDROID)
save_update_password_message_delegate_.DismissSaveUpdatePasswordPrompt();
if (password_manager_error_message_delegate_) {
password_manager_error_message_delegate_
->DismissPasswordManagerErrorMessage(
messages::DismissReason::TAB_DESTROYED);
}
#endif
}
void ChromePasswordManagerClient::ResourceLoadComplete(
content::RenderFrameHost* render_frame_host,
const content::GlobalRequestID& request_id,
const blink::mojom::ResourceLoadInfo& resource_load_info) {
if (resource_load_info.method == "POST" &&
resource_load_info.http_status_code >= 400 &&
resource_load_info.http_status_code <= 403) {
password_manager_.OnResourceLoadingFailed(
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
render_frame_host),
resource_load_info.original_url);
}
}
void ChromePasswordManagerClient::OnFieldTypesDetermined(
autofill::AutofillManager& manager,
autofill::FormGlobalId form_id,
FieldTypeSource source) {
if (source != FieldTypeSource::kAutofillServer &&
!base::FeatureList::IsEnabled(
password_manager::features::kPasswordFormClientsideClassifier)) {
return;
}
std::optional<autofill::RendererForms> renderer_forms =
autofill::RendererFormsFromBrowserForm(manager, form_id);
if (!renderer_forms.has_value()) {
return;
}
for (const auto& [form, rfh_id] : renderer_forms.value()) {
auto* rfh = content::RenderFrameHost::FromID(rfh_id);
if (!rfh) {
continue;
}
auto* driver =
password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
rfh);
if (!driver) {
continue;
}
std::vector<autofill::FieldGlobalId> field_ids =
base::ToVector(form.fields(), &autofill::FormFieldData::global_id);
switch (source) {
case FieldTypeSource::kAutofillServer:
case FieldTypeSource::kAutofillAiModel:
password_manager_.ProcessAutofillPredictions(
driver, form,
manager.GetServerPredictionsForForm(form_id, field_ids));
break;
case FieldTypeSource::kHeuristicsOrAutocomplete: {
auto predictions = manager.GetHeursticPredictionForForm(
autofill::HeuristicSource::kPasswordManagerMachineLearning, form_id,
field_ids);
password_manager_.ProcessClassificationModelPredictions(driver, form,
predictions);
if (PredictionsContainOtpFields(predictions)) {
otp_manager_.ProcessClassificationModelPredictions(form, predictions);
}
break;
}
}
}
}
password_manager::ContentPasswordManagerDriverFactory*
ChromePasswordManagerClient::GetDriverFactory() const {
return password_manager::ContentPasswordManagerDriverFactory::FromWebContents(
web_contents());
}
gfx::RectF ChromePasswordManagerClient::GetBoundsInScreenSpace(
const gfx::RectF& bounds) {
gfx::Rect client_area = web_contents()->GetContainerBounds();
return bounds + client_area.OffsetFromOrigin();
}
void ChromePasswordManagerClient::HideFillingUI() {
#if BUILDFLAG(IS_ANDROID)
base::WeakPtr<ManualFillingController> mf_controller =
ManualFillingController::Get(web_contents());
// Hides all the manual filling UI if the controller already exists.
if (mf_controller) {
mf_controller->Hide();
}
PasswordGenerationController* generation_controller =
PasswordGenerationController::GetIfExisting(web_contents());
if (generation_controller) {
generation_controller->HideBottomSheetIfNeeded();
}
if (touch_to_fill_controller_) {
touch_to_fill_controller_->Reset();
}
if (cred_man_controller_) {
cred_man_controller_.reset();
}
if (keyboard_replacing_surface_visibility_controller_) {
keyboard_replacing_surface_visibility_controller_->Reset();
}
#endif // BUILDFLAG(IS_ANDROID)
}
bool ChromePasswordManagerClient::IsPasswordManagementEnabledForCurrentPage(
const GURL& url) const {
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
if (IsPasswordManagerForUrlDisallowedByPolicy(url)) {
return false;
}
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
bool is_enabled = CanShowBubbleOnURL(url);
// The password manager is disabled on Google Password Manager page.
if (url.DeprecatedGetOriginAsURL() ==
GURL(password_manager::kPasswordManagerAccountDashboardURL)) {
is_enabled = false;
}
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
// SafeBrowsing Delayed Warnings experiment can delay some SafeBrowsing
// warnings until user interaction. If the current page has a delayed warning,
// it'll have a user interaction observer attached. Disable password
// management in that case.
if (auto* observer =
safe_browsing::SafeBrowsingUserInteractionObserver::FromWebContents(
web_contents())) {
observer->OnPasswordSaveOrAutofillDenied();
is_enabled = false;
}
#endif
autofill::LogManager* log_manager = GetOrCreateLogManager();
if (log_manager && log_manager->IsLoggingActive()) {
password_manager::BrowserSavePasswordProgressLogger logger(log_manager);
logger.LogURL(Logger::STRING_SECURITY_ORIGIN, url);
logger.LogBoolean(
Logger::STRING_PASSWORD_MANAGEMENT_ENABLED_FOR_CURRENT_PAGE,
is_enabled);
}
return is_enabled;
}
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
bool ChromePasswordManagerClient::IsPasswordManagerForUrlDisallowedByPolicy(
const GURL& url) const {
if (!GetPrefs() || !GetPrefs()->HasPrefPath(
policy::policy_prefs::kPasswordManagerBlocklist)) {
return false;
}
PasswordManagerBlocklistPolicy* blocklist_policy =
PasswordManagerBlocklistPolicyFactory::GetForBrowserContext(
web_contents()->GetBrowserContext());
if (blocklist_policy &&
blocklist_policy->GetURLBlocklistState(url) ==
policy::URLBlocklist::URLBlocklistState::URL_IN_BLOCKLIST) {
return true;
}
return false;
}
#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) ||
// BUILDFLAG(IS_CHROMEOS)
void ChromePasswordManagerClient::GenerationResultAvailable(
PasswordGenerationType type,
base::WeakPtr<password_manager::ContentPasswordManagerDriver> driver,
const std::optional<
autofill::password_generation::PasswordGenerationUIData>& ui_data) {
if (!ui_data || !driver) {
return;
}
// Check the data because it's a Mojo callback and the input isn't trusted.
if (!password_manager::bad_message::CheckChildProcessSecurityPolicyForURL(
driver->render_frame_host(), ui_data->form_data.url(),
BadMessageReason::
CPMD_BAD_ORIGIN_SHOW_MANUAL_PASSWORD_GENERATION_POPUP)) {
return;
}
#if BUILDFLAG(IS_ANDROID)
PasswordGenerationController* password_generation_controller =
PasswordGenerationController::GetIfExisting(web_contents());
DCHECK(password_generation_controller);
password_generation_controller->ShowManualGenerationDialog(driver.get(),
ui_data.value());
#else
ShowPasswordGenerationPopup(type, driver.get(), *ui_data);
#endif
}
#if !BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::ShowPasswordGenerationPopup(
PasswordGenerationType type,
password_manager::ContentPasswordManagerDriver* driver,
const autofill::password_generation::PasswordGenerationUIData& ui_data) {
gfx::RectF element_bounds_in_top_frame_space =
TransformToRootCoordinates(driver->render_frame_host(), ui_data.bounds);
gfx::RectF element_bounds_in_screen_space =
GetBoundsInScreenSpace(element_bounds_in_top_frame_space);
password_manager_.SetGenerationElementAndTypeForForm(
driver, ui_data.form_data.renderer_id(), ui_data.generation_element_id,
type);
popup_controller_ = PasswordGenerationPopupControllerImpl::GetOrCreate(
popup_controller_, element_bounds_in_screen_space, ui_data,
driver->AsWeakPtr(), observer_, web_contents(),
driver->render_frame_host());
popup_controller_->GeneratePasswordValue(type);
popup_controller_->Show(PasswordGenerationPopupController::kOfferGeneration);
driver->SetSuggestionAvailability(
ui_data.generation_element_id,
popup_controller_ && popup_controller_->IsVisible()
? autofill::mojom::AutofillSuggestionAvailability::kAutofillAvailable
: autofill::mojom::AutofillSuggestionAvailability::kNoSuggestions);
}
void ChromePasswordManagerClient::MaybeShowSavePasswordPrimingPromo(
const GURL& current_url) {
// If the user has any stored passwords do not show the promo.
auto* const prefs = GetPrefs();
if (prefs->GetBoolean(
password_manager::prefs::
kAutofillableCredentialsProfileStoreLoginDatabase) ||
prefs->GetBoolean(
password_manager::prefs::
kAutofillableCredentialsAccountStoreLoginDatabase)) {
return;
}
// If the current page is not eligible for password saving, do not show the
// promo.
if (!IsSavingAndFillingEnabled(current_url)) {
return;
}
if (auto* const user_ed =
BrowserUserEducationInterface::MaybeGetForWebContentsInTab(
web_contents())) {
if (signin::IdentityManager* const identity_manager =
IdentityManagerFactory::GetForProfile(profile_)) {
const bool signed_in =
identity_manager->HasPrimaryAccount(signin::ConsentLevel::kSignin);
user_education::FeaturePromoParams params(
feature_engagement::kIPHPasswordsSavePrimingPromoFeature);
params.body_params = l10n_util::GetStringUTF16(
signed_in ? IDS_PASSWORDS_SAVE_PRIMING_PROMO_BODY_SIGNED_IN
: IDS_PASSWORDS_SAVE_PRIMING_PROMO_BODY_NOT_SIGNED_IN);
user_ed->MaybeShowFeaturePromo(std::move(params));
}
}
}
#endif // !BUILDFLAG(IS_ANDROID)
gfx::RectF ChromePasswordManagerClient::TransformToRootCoordinates(
content::RenderFrameHost* frame_host,
const gfx::RectF& bounds_in_frame_coordinates) {
content::RenderWidgetHostView* rwhv = frame_host->GetView();
if (!rwhv) {
return bounds_in_frame_coordinates;
}
return gfx::RectF(rwhv->TransformPointToRootCoordSpaceF(
bounds_in_frame_coordinates.origin()),
bounds_in_frame_coordinates.size());
}
#if BUILDFLAG(IS_ANDROID)
void ChromePasswordManagerClient::ResetErrorMessageDelegate() {
password_manager_error_message_delegate_.reset();
}
void ChromePasswordManagerClient::TryToShowPostPasswordMigrationSheet() {
// This is to run the function after all the initialization tasks have been
// completed.
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MaybeShowPostMigrationSheetWrapper,
web_contents()->GetWeakPtr(), profile_));
}
void ChromePasswordManagerClient::TryToShowAccessLossWarningSheet() {
PasswordAccessLossWarningBridgeImpl bridge;
// If the feature is not enabled or it's too early to show the startup warning
// sheet, the method ends.
if (!bridge.ShouldShowAccessLossNoticeSheet(GetPrefs(),
/*called_at_startup=*/true)) {
return;
}
GmsVersionCohort gms_version_cohort =
password_manager_android_util::GetGmsVersionCohort();
if (gms_version_cohort == GmsVersionCohort::kFullUpmSupport &&
!password_manager_android_util::LastMigrationAttemptToUpmLocalFailed()) {
// There is already full UPM support. No need to show any warning.
return;
}
if (GetPrefs()
->FindPreference(
password_manager::prefs::kEmptyProfileStoreLoginDatabase)
->IsDefaultValue()) {
// The state of the login db is unknown. This pref is initialized on
// startup, so it should be available in the next session at the latest.
return;
}
if (!GetPrefs()->GetBoolean(
password_manager::prefs::kEmptyProfileStoreLoginDatabase)) {
// This is to run the function after all the initialization tasks have been
// completed.
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&ShowAccessLossWarning, GetPrefs(),
web_contents()->GetWeakPtr(), profile_));
return;
}
// Unless a user has account UPM support, no passwords in the login DB means
// they're not a password manager user, so they shouldn't see the warning.
if (gms_version_cohort != GmsVersionCohort::kOnlyAccountUpmSupport) {
return;
}
// If the user has only account UPM support, they might still have passwords
// in GMS core. The support for this state will be removed in the future, so
// they also need to see the warning.
const syncer::SyncService* sync_service =
SyncServiceFactory::GetForProfile(profile_);
// If the user hasn't chosen to sync passwords, they don't store passwords in
// this version of GMS Core.
if (!sync_service ||
!password_manager::sync_util::HasChosenToSyncPasswords(sync_service)) {
return;
}
// The user is syncing, the login DB is empty and the GMS Core version only
// supports account passwords. An empty login DB combined with the other two
// conditions implies that the user has access to the GMS core storage,
// because either all their passwords were migrated and then removed or they
// never had any passwords in the first place, so they never needed migration.
password_manager::PasswordStoreInterface* profile_password_store =
GetProfilePasswordStore();
password_access_loss_warning_startup_launcher_ =
std::make_unique<PasswordAccessLossWarningStartupLauncher>(
base::BindOnce(&ShowAccessLossWarning, GetPrefs(),
web_contents()->GetWeakPtr(), profile_));
password_access_loss_warning_startup_launcher_->FetchPasswordsAndShowWarning(
profile_password_store);
}
#endif
WEB_CONTENTS_USER_DATA_KEY_IMPL(ChromePasswordManagerClient);
|