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
|
// Copyright 2012 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/ui/toolbar/app_menu_model.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <optional>
#include "base/command_line.h"
#include "base/debug/debugging_buildflags.h"
#include "base/debug/profiler.h"
#include "base/functional/bind.h"
#include "base/i18n/number_formatting.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/sharing_hub/sharing_hub_features.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/hats/trust_safety_sentiment_service_factory.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/lens/lens_overlay_controller.h"
#include "chrome/browser/ui/lens/lens_overlay_entry_point_controller.h"
#include "chrome/browser/ui/managed_ui.h"
#include "chrome/browser/ui/profiles/profile_colors_util.h"
#include "chrome/browser/ui/profiles/profile_view_utils.h"
#include "chrome/browser/ui/safety_hub/menu_notification_service_factory.h"
#include "chrome/browser/ui/safety_hub/safety_hub_constants.h"
#include "chrome/browser/ui/safety_hub/safety_hub_hats_service.h"
#include "chrome/browser/ui/safety_hub/safety_hub_hats_service_factory.h"
#include "chrome/browser/ui/startup/default_browser_prompt/default_browser_prompt_manager.h"
#include "chrome/browser/ui/tabs/organization/tab_declutter_controller.h"
#include "chrome/browser/ui/tabs/organization/tab_organization_service_factory.h"
#include "chrome/browser/ui/tabs/organization/tab_organization_utils.h"
#include "chrome/browser/ui/tabs/recent_tabs_sub_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/app_menu_icon_controller.h"
#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_model.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_prefs.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/customize_chrome_page_handler.h"
#include "chrome/browser/ui/webui/whats_new/whats_new_util.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_tab_helper.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/dom_distiller/content/browser/distillable_page_utils.h"
#include "components/dom_distiller/content/browser/uma_helper.h"
#include "components/dom_distiller/core/dom_distiller_features.h"
#include "components/dom_distiller/core/url_utils.h"
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/lens/lens_features.h"
#include "components/omnibox/browser/vector_icons.h"
#include "components/password_manager/content/common/web_ui_constants.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/saved_tab_groups/public/features.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_strings.h"
#include "components/user_education/common/feature_promo/feature_promo_controller.h"
#include "components/vector_icons/vector_icons.h"
#include "components/webapps/browser/banners/app_banner_manager.h"
#include "components/webapps/browser/banners/install_banner_config.h"
#include "components/webapps/browser/banners/installable_web_app_check_result.h"
#include "components/webapps/browser/banners/web_app_banner_data.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/profiling.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/extension_features.h"
#include "media/base/media_switches.h"
#include "ui/base/accelerators/menu_label_accelerator_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/button_menu_item_model.h"
#include "ui/base/models/image_model.h"
#include "ui/base/models/menu_separator_types.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/text_elider.h"
#include "ui/menus/simple_menu_model.h"
#if BUILDFLAG(ENABLE_GLIC)
#include "chrome/browser/glic/browser_ui/glic_vector_icon_manager.h"
#include "chrome/browser/glic/glic_enabling.h"
#include "chrome/browser/glic/resources/grit/glic_browser_resources.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) || BUILDFLAG(IS_CHROMEOS)
#include "base/feature_list.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "ui/display/screen.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/shortcut.h"
#include "base/win/windows_version.h"
#include "content/public/browser/gpu_data_manager.h"
#endif
using base::UserMetricsAction;
using content::WebContents;
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kProfileMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kProfileOpenGuestItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kBookmarksMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kTabGroupsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kDownloadsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kHistoryMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kExtensionsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kMoreToolsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kIncognitoMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel,
kPasswordAndAutofillMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kPasswordManagerMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kShowLensOverlay);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kSaveAndShareMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kCastTitleItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kInstallAppItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel, kCreateShortcutItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(AppMenuModel,
kSetBrowserAsDefaultMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(ToolsMenuModel, kPerformanceMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(ToolsMenuModel, kChromeLabsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(ToolsMenuModel, kReadingModeMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(ExtensionsMenuModel,
kManageExtensionsMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(ExtensionsMenuModel,
kVisitChromeWebStoreMenuItem);
namespace {
////////////////////////////////////////////////////////////////////////////////
// AddItemWithStringIdAndVectorIcon
void AddItemWithStringIdAndVectorIcon(ui::SimpleMenuModel* model,
int command_id,
int string_id,
const gfx::VectorIcon& vector_icon) {
return model->AddItemWithStringIdAndIcon(
command_id, string_id,
ui::ImageModel::FromVectorIcon(vector_icon, ui::kColorMenuIcon,
ui::SimpleMenuModel::kDefaultIconSize));
}
////////////////////////////////////////////////////////////////////////////////
// AddSubMenuWithStringIdAndVectorIcon
void AddSubMenuWithStringIdAndVectorIcon(ui::SimpleMenuModel* model,
int command_id,
int string_id,
ui::MenuModel* sub_menu,
const gfx::VectorIcon& vector_icon) {
return model->AddSubMenuWithStringIdAndIcon(
command_id, string_id, sub_menu,
ui::ImageModel::FromVectorIcon(vector_icon, ui::kColorMenuIcon,
ui::SimpleMenuModel::kDefaultIconSize));
}
// Conditionally return the update app menu item title based on upgrade detector
// state.
std::u16string GetUpgradeDialogTitleText() {
if (UpgradeDetector::GetInstance()->is_outdated_install() ||
UpgradeDetector::GetInstance()->is_outdated_install_no_au()) {
return l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_MENU_ITEM);
}
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && \
(BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX))
return l10n_util::GetStringUTF16(IDS_RELAUNCH_TO_UPDATE_ALT);
#else
return l10n_util::GetStringUTF16(IDS_RELAUNCH_TO_UPDATE);
#endif
}
// Returns the appropriate menu label for the IDC_INSTALL_PWA command if
// available.
std::u16string GetInstallPWALabel(const Browser* browser) {
// There may be no active web contents in tests.
auto* const web_contents = browser->tab_strip_model()->GetActiveWebContents();
if (!web_contents) {
return std::u16string();
}
if (!web_app::CanCreateWebApp(browser)) {
return std::u16string();
}
// Don't allow apps created from chrome-extension urls.
if (web_contents->GetLastCommittedURL().SchemeIs("chrome-extension")) {
return std::u16string();
}
// TODO(b/328077967): Support async nature of AppBannerManager pipeline runs
// with the menu model instead of needing this workaround to verify if an
// non-installable site is installed.
const webapps::AppId* app_id =
web_app::WebAppTabHelper::GetAppId(web_contents);
web_app::WebAppProvider* const provider =
web_app::WebAppProvider::GetForLocalAppsUnchecked(browser->profile());
if (app_id &&
provider->registrar_unsafe().GetInstallState(*app_id) ==
web_app::proto::INSTALLED_WITH_OS_INTEGRATION &&
provider->registrar_unsafe().GetAppUserDisplayMode(*app_id) !=
web_app::mojom::UserDisplayMode::kBrowser) {
return std::u16string();
}
std::u16string install_page_as_app_label =
l10n_util::GetStringUTF16(IDS_INSTALL_DIY_TO_OS_LAUNCH_SURFACE);
webapps::AppBannerManager* banner =
webapps::AppBannerManager::FromWebContents(web_contents);
if (!banner) {
// Showing `Install Page as App` allows the user to refetch the manifest and
// go through the install flow without relying on the AppBannerManager to
// finish working.
return install_page_as_app_label;
}
std::optional<webapps::InstallBannerConfig> install_config =
banner->GetCurrentBannerConfig();
if (!install_config) {
// In some edge cases where the `AppBannerManager` pipeline hasn't run yet,
// the information populated to be used for determining installability and
// other parameters is not available. In this case, allow users to try
// installability by refetching the manifest.
return install_page_as_app_label;
}
CHECK_EQ(install_config->mode, webapps::AppBannerMode::kWebApp);
webapps::InstallableWebAppCheckResult installable =
banner->GetInstallableWebAppCheckResult();
switch (installable) {
case webapps::InstallableWebAppCheckResult::kUnknown:
// Loading of the menu model is synchronous, so there could be a condition
// where the `AppBannerManager` has not yet finished the pipeline while
// the menu item has been triggered. In such a case,
// `banner->GetInstallableWebAppCheckResult()` returns the default value
// of `kUnknown`.
// Show `Install Page as App` for that use-case, since that allows the
// user to trigger the install flow to verify all the data required for
// installability. The correct dialog will be shown to the user depending
// on whether the app turns out to be installable or not.
return install_page_as_app_label;
case webapps::InstallableWebAppCheckResult::kNo_AlreadyInstalled:
// Returning an empty string here allows the `launch page as app` field to
// get populated in place of the `install` strings.
return std::u16string();
case webapps::InstallableWebAppCheckResult::kNo:
return install_page_as_app_label;
case webapps::InstallableWebAppCheckResult::kYes_ByUserRequest:
case webapps::InstallableWebAppCheckResult::kYes_Promotable:
std::u16string app_name = install_config->GetWebOrNativeAppName();
if (app_name.empty()) {
// Prefer showing `Install Page as App` here, as users can set the name
// of the installed app on the DIY app dialog anyway.
return install_page_as_app_label;
}
return l10n_util::GetStringFUTF16(
IDS_INSTALL_TO_OS_LAUNCH_SURFACE,
ui::EscapeMenuLabelAmpersands(app_name));
}
}
// TODO(b/328077967): Implement async updates of menu for app icon.
ui::ImageModel GetInstallPWAIcon(Browser* browser) {
ui::ImageModel app_icon_to_use = ui::ImageModel::FromVectorIcon(
kInstallDesktopChromeRefreshIcon, ui::kColorMenuIcon,
ui::SimpleMenuModel::kDefaultIconSize);
content::WebContents* const web_contents =
browser->tab_strip_model()->GetActiveWebContents();
if (!web_contents) {
return app_icon_to_use;
}
webapps::AppBannerManager* const banner =
webapps::AppBannerManager::FromWebContents(web_contents);
if (!banner) {
return app_icon_to_use;
}
// For sites that are not installable (DIY apps), do not return any icons,
// instead use the default chrome refresh icon for installing.
auto installable_check_result = banner->GetInstallableWebAppCheckResult();
if (installable_check_result == webapps::InstallableWebAppCheckResult::kNo ||
installable_check_result ==
webapps::InstallableWebAppCheckResult::kUnknown) {
return app_icon_to_use;
}
std::optional<webapps::WebAppBannerData> install_config =
banner->GetCurrentWebAppBannerData();
// If no data or no icons have been obtained by the AppBannerManager, return
// the default icon.
if (!install_config || install_config->primary_icon.empty()) {
return app_icon_to_use;
}
gfx::ImageSkia primary_icon =
gfx::ImageSkia::CreateFrom1xBitmap(install_config->primary_icon);
gfx::ImageSkia resized_app_icon =
gfx::ImageSkiaOperations::CreateResizedImage(
primary_icon, skia::ImageOperations::RESIZE_BEST,
gfx::Size(ui::SimpleMenuModel::kDefaultIconSize,
ui::SimpleMenuModel::kDefaultIconSize));
app_icon_to_use = ui::ImageModel::FromImageSkia(resized_app_icon);
return app_icon_to_use;
}
// Returns the appropriate menu label for the IDC_OPEN_IN_PWA_WINDOW command if
// available.
std::u16string GetOpenPWALabel(const Browser* browser) {
std::optional<webapps::AppId> app_id =
web_app::GetWebAppForActiveTab(browser);
if (!app_id.has_value()) {
return std::u16string();
}
// Only show this menu item for apps that open in an app window.
const auto* const provider =
web_app::WebAppProvider::GetForLocalAppsUnchecked(browser->profile());
if (provider->registrar_unsafe().GetAppUserDisplayMode(*app_id) ==
web_app::mojom::UserDisplayMode::kBrowser) {
return std::u16string();
}
const std::u16string short_name =
base::UTF8ToUTF16(provider->registrar_unsafe().GetAppShortName(*app_id));
return l10n_util::GetStringFUTF16(
IDS_OPEN_IN_APP_WINDOW,
ui::EscapeMenuLabelAmpersands(gfx::TruncateString(
short_name, GetLayoutConstant(APP_MENU_MAXIMUM_CHARACTER_LENGTH),
gfx::CHARACTER_BREAK)));
}
std::u16string GetSyncSectionTitle(Profile* profile,
signin::IdentityManager* identity_manager) {
const AccountInfo account = GetAccountInfoFromProfile(profile);
if (IsSyncPaused(profile) || account.IsEmpty()) {
return l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE);
}
if (signin_util::IsSigninPending(identity_manager)) {
return base::UTF8ToUTF16(account.email);
}
return l10n_util::GetStringFUTF16(
IDS_PROFILE_ROW_SIGNED_IN_MESSAGE_WITH_EMAIL,
{base::UTF8ToUTF16(account.email)});
}
class ProfileSubMenuModel : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
ProfileSubMenuModel(ui::SimpleMenuModel::Delegate* delegate,
Profile* profile,
const ui::ColorProvider* color_provider);
ProfileSubMenuModel(const ProfileSubMenuModel&) = delete;
ProfileSubMenuModel& operator=(const ProfileSubMenuModel&) = delete;
~ProfileSubMenuModel() override = default;
const ui::ImageModel& avatar_image_model() const {
return avatar_image_model_;
}
const std::u16string& profile_name() const { return profile_name_; }
// Returns |next_menu_id_| and increments it by n. This allows for 'sharing'
// command ids with the other variable sized menu, which also uses every other
// int as an id.
int GetAndIncrementNextMenuID();
// Overridden from ui::SimpleMenuModel::Delegate:
bool IsCommandIdChecked(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override;
bool GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) const override;
void ExecuteCommand(int command_id, int event_flags) override;
private:
bool BuildSyncSection();
void BuildGuestProfileRow(Profile* profile);
void BuildCustomizeProfileRow(Profile* profile);
void BuildCloseProfileRow(Profile* profile);
void BuildManageGoogleAccountRow(Profile* profile);
ui::ImageModel avatar_image_model_;
std::u16string profile_name_;
raw_ptr<Profile> profile_;
raw_ptr<ui::SimpleMenuModel::Delegate> app_menu_model_delegate_;
// ID of the next menu item.
int next_other_profile_menu_id_;
base::flat_map<int, base::FilePath> other_profiles_;
};
ProfileSubMenuModel::ProfileSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
Profile* profile,
const ui::ColorProvider* color_provider)
: SimpleMenuModel(this),
profile_(profile),
app_menu_model_delegate_(delegate),
next_other_profile_menu_id_(AppMenuModel::kMinOtherProfileCommandId) {
const int avatar_icon_size =
GetLayoutConstant(APP_MENU_PROFILE_ROW_AVATAR_ICON_SIZE);
avatar_image_model_ = ui::ImageModel::FromVectorIcon(
kAccountCircleChromeRefreshIcon, ui::kColorMenuIcon, avatar_icon_size);
if (profile->IsIncognitoProfile()) {
avatar_image_model_ = ui::ImageModel::FromVectorIcon(
kIncognitoIcon, ui::kColorAvatarIconIncognito, avatar_icon_size);
profile_name_ = l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE);
} else if (profile->IsGuestSession()) {
profile_name_ = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
} else {
if (BuildSyncSection()) {
AddSeparator(ui::NORMAL_SEPARATOR);
}
ProfileAttributesEntry* profile_attributes =
GetProfileAttributesFromProfile(profile);
// If the profile is being deleted, profile_attributes may be null.
if (profile_attributes) {
AccountInfo account_info = GetAccountInfoFromProfile(profile);
gfx::Image avatar_image =
account_info.IsEmpty()
? profile_attributes->GetAvatarIcon(
avatar_icon_size, /*use_high_res_file=*/true,
GetPlaceholderAvatarIconParamsDependingOnTheme(
ThemeServiceFactory::GetForProfile(profile),
/*background_color_id=*/ui::kColorMenuBackground,
*color_provider))
: account_info.account_image;
// The avatar image can be empty if the account image hasn't been
// fetched yet, if there is no image, or in tests.
if (!avatar_image.IsEmpty()) {
avatar_image_model_ =
ui::ImageModel::FromImage(profiles::GetSizedAvatarIcon(
avatar_image, avatar_icon_size, avatar_icon_size,
profiles::SHAPE_CIRCLE));
}
profile_name_ = GetProfileMenuDisplayName(profile_attributes);
}
}
BuildManageGoogleAccountRow(profile);
BuildCustomizeProfileRow(profile);
BuildCloseProfileRow(profile);
bool needs_separator = false;
const bool is_guest_mode_enabled = profiles::IsGuestModeEnabled(*profile);
if (!profile->IsIncognitoProfile() && !profile->IsGuestSession()) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddTitle(l10n_util::GetStringUTF16(IDS_OTHER_CHROME_PROFILES_TITLE));
auto profile_entries = GetAllOtherProfileEntriesForProfileSubMenu(profile);
needs_separator = !profile_entries.empty();
profiles::PlaceholderAvatarIconParams icon_params =
GetPlaceholderAvatarIconParamsVisibleAgainstColor(
color_provider->GetColor(ui::kColorMenuBackground));
for (ProfileAttributesEntry* profile_entry : profile_entries) {
std::u16string display_name = GetProfileMenuDisplayName(profile_entry);
int menu_id = GetAndIncrementNextMenuID();
AddItemWithIcon(
menu_id,
ui::EscapeMenuLabelAmpersands(gfx::TruncateString(
display_name,
GetLayoutConstant(APP_MENU_MAXIMUM_CHARACTER_LENGTH),
gfx::CHARACTER_BREAK)),
ui::ImageModel::FromImage(profiles::GetSizedAvatarIcon(
profile_entry->GetAvatarIcon(
avatar_icon_size, /*use_high_res_file=*/true, icon_params),
avatar_icon_size, avatar_icon_size, profiles::SHAPE_CIRCLE)));
other_profiles_.insert({menu_id, profile_entry->GetPath()});
}
if (needs_separator) {
AddSeparator(ui::NORMAL_SEPARATOR);
}
if (profiles::IsProfileCreationAllowed()) {
AddItemWithStringIdAndVectorIcon(this, IDC_ADD_NEW_PROFILE,
IDS_ADD_NEW_PROFILE,
kAccountAddChromeRefreshIcon);
}
if (is_guest_mode_enabled) {
BuildGuestProfileRow(profile);
}
AddItemWithStringIdAndVectorIcon(this, IDC_MANAGE_CHROME_PROFILES,
IDS_MANAGE_CHROME_PROFILES,
kAccountManageChromeRefreshIcon);
}
}
bool ProfileSubMenuModel::IsCommandIdChecked(int command_id) const {
return false;
}
bool ProfileSubMenuModel::IsCommandIdEnabled(int command_id) const {
if (command_id >= AppMenuModel::kMinOtherProfileCommandId) {
return true;
}
return app_menu_model_delegate_ &&
app_menu_model_delegate_->IsCommandIdEnabled(command_id);
}
bool ProfileSubMenuModel::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const {
return app_menu_model_delegate_ &&
app_menu_model_delegate_->GetAcceleratorForCommandId(command_id,
accelerator);
}
void ProfileSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
if (other_profiles_.find(command_id) != other_profiles_.end()) {
return profiles::SwitchToProfile(other_profiles_[command_id],
/*always_create=*/false);
}
if (app_menu_model_delegate_) {
app_menu_model_delegate_->ExecuteCommand(command_id, event_flags);
}
return;
}
int ProfileSubMenuModel::GetAndIncrementNextMenuID() {
const int current_id = next_other_profile_menu_id_;
next_other_profile_menu_id_ += AppMenuModel::kNumUnboundedMenuTypes;
return current_id;
}
bool ProfileSubMenuModel::BuildSyncSection() {
if (!profile_->GetPrefs()->GetBoolean(prefs::kSigninAllowed)) {
return false;
}
if (!SyncServiceFactory::IsSyncAllowed(profile_)) {
return false;
}
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_);
AddTitle(GetSyncSectionTitle(profile_, identity_manager));
// First, check for sync errors. They may exist even if sync-the-feature is
// disabled and only sync-the-transport is running.
const std::optional<AvatarSyncErrorType> error =
GetAvatarSyncErrorType(profile_);
if (error.has_value()) {
if (error == AvatarSyncErrorType::kSyncPaused) {
// If sync is paused the menu item will be specific to the paused error.
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_SIGNIN_WHEN_PAUSED,
IDS_PROFILE_ROW_SIGN_IN_AGAIN,
vector_icons::kSyncOffChromeRefreshIcon);
} else {
// All remaining errors will have the same menu item.
AddItemWithStringIdAndVectorIcon(
this, IDC_SHOW_SYNC_SETTINGS, IDS_PROFILE_ROW_SYNC_ERROR_MESSAGE,
vector_icons::kSyncProblemChromeRefreshIcon);
}
return true;
}
if (signin_util::IsSigninPending(identity_manager)) {
AddItemWithStringIdAndVectorIcon(
this, IDC_SHOW_SIGNIN_WHEN_PAUSED, IDS_PROFILES_VERIFY_ACCOUNT_BUTTON,
vector_icons::kAccountCircleOffChromeRefreshIcon);
} else if (identity_manager->HasPrimaryAccount(signin::ConsentLevel::kSync)) {
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_SYNC_SETTINGS,
IDS_PROFILE_ROW_SYNC_IS_ON,
vector_icons::kSyncChromeRefreshIcon);
} else {
AddItemWithStringIdAndVectorIcon(this, IDC_TURN_ON_SYNC,
IDS_PROFILE_ROW_TURN_ON_SYNC,
vector_icons::kSyncOffChromeRefreshIcon);
}
return true;
}
void ProfileSubMenuModel::BuildGuestProfileRow(Profile* profile) {
AddItemWithStringIdAndVectorIcon(this, IDC_OPEN_GUEST_PROFILE,
IDS_OPEN_GUEST_PROFILE, kAccountBoxIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_OPEN_GUEST_PROFILE).value(),
AppMenuModel::kProfileOpenGuestItem);
}
void ProfileSubMenuModel::BuildCustomizeProfileRow(Profile* profile) {
if (!profile->IsIncognitoProfile() && !profile->IsGuestSession()) {
AddItemWithStringIdAndVectorIcon(this, IDC_CUSTOMIZE_CHROME,
IDS_CUSTOMIZE_CHROME,
vector_icons::kEditChromeRefreshIcon);
}
}
void ProfileSubMenuModel::BuildCloseProfileRow(Profile* profile) {
AddItemWithIcon(
IDC_CLOSE_PROFILE,
l10n_util::GetPluralStringFUTF16(IDS_CLOSE_PROFILE,
CountBrowsersFor(profile)),
ui::ImageModel::FromVectorIcon(vector_icons::kCloseChromeRefreshIcon,
ui::kColorMenuIcon, kDefaultIconSize));
}
void ProfileSubMenuModel::BuildManageGoogleAccountRow(Profile* profile) {
if (HasUnconstentedProfile(profile) && !IsSyncPaused(profile) &&
!profile->IsIncognitoProfile()) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const gfx::VectorIcon& manage_account_icon =
vector_icons::kGoogleGLogoMonochromeIcon;
#else
const gfx::VectorIcon& manage_account_icon =
kAccountManageChromeRefreshIcon;
#endif
AddItemWithStringIdAndVectorIcon(this, IDC_MANAGE_GOOGLE_ACCOUNT,
IDS_MANAGE_GOOGLE_ACCOUNT,
manage_account_icon);
}
}
class PasswordsAndAutofillSubMenuModel : public ui::SimpleMenuModel {
public:
explicit PasswordsAndAutofillSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate);
PasswordsAndAutofillSubMenuModel(const PasswordsAndAutofillSubMenuModel&) =
delete;
PasswordsAndAutofillSubMenuModel& operator=(
const PasswordsAndAutofillSubMenuModel&) = delete;
~PasswordsAndAutofillSubMenuModel() override = default;
};
PasswordsAndAutofillSubMenuModel::PasswordsAndAutofillSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate)
: SimpleMenuModel(delegate) {
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_PASSWORD_MANAGER,
IDS_VIEW_PASSWORDS,
vector_icons::kPasswordManagerIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_SHOW_PASSWORD_MANAGER).value(),
AppMenuModel::kPasswordManagerMenuItem);
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_PAYMENT_METHODS,
IDS_PAYMENT_METHOD_SUBMENU_OPTION,
kCreditCardChromeRefreshIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_ADDRESSES,
IDS_ADDRESSES_AND_MORE_SUBMENU_OPTION,
vector_icons::kLocationOnChromeRefreshIcon);
}
class FindAndEditSubMenuModel : public ui::SimpleMenuModel {
public:
explicit FindAndEditSubMenuModel(ui::SimpleMenuModel::Delegate* delegate);
FindAndEditSubMenuModel(const FindAndEditSubMenuModel&) = delete;
FindAndEditSubMenuModel& operator=(const FindAndEditSubMenuModel&) = delete;
~FindAndEditSubMenuModel() override = default;
};
FindAndEditSubMenuModel::FindAndEditSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate)
: SimpleMenuModel(delegate) {
AddItemWithStringIdAndVectorIcon(this, IDC_FIND, IDS_FIND, kSearchMenuIcon);
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_CUT, IDS_CUT, kCutMenuIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_COPY, IDS_COPY, kCopyMenuIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_PASTE, IDS_PASTE, kPasteMenuIcon);
}
class SaveAndShareSubMenuModel : public ui::SimpleMenuModel {
public:
SaveAndShareSubMenuModel(ui::SimpleMenuModel::Delegate* delegate,
Browser* browser);
SaveAndShareSubMenuModel(const SaveAndShareSubMenuModel&) = delete;
SaveAndShareSubMenuModel& operator=(const SaveAndShareSubMenuModel&) = delete;
~SaveAndShareSubMenuModel() override = default;
};
SaveAndShareSubMenuModel::SaveAndShareSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
Browser* browser)
: SimpleMenuModel(delegate) {
if (media_router::MediaRouterEnabled(browser->profile())) {
AddTitle(l10n_util::GetStringUTF16(IDS_SAVE_AND_SHARE_MENU_CAST));
SetElementIdentifierAt(GetItemCount() - 1, AppMenuModel::kCastTitleItem);
AddItemWithStringIdAndVectorIcon(this, IDC_ROUTE_MEDIA,
IDS_MEDIA_ROUTER_MENU_ITEM_TITLE,
kCastChromeRefreshIcon);
AddSeparator(ui::NORMAL_SEPARATOR);
}
AddTitle(l10n_util::GetStringUTF16(IDS_SAVE_AND_SHARE_MENU_SAVE));
AddItemWithStringIdAndVectorIcon(this, IDC_SAVE_PAGE, IDS_SAVE_PAGE,
kFileSaveChromeRefreshIcon);
AddSeparator(ui::NORMAL_SEPARATOR);
if (std::u16string install_item = GetInstallPWALabel(browser);
!install_item.empty()) {
AddItemWithIcon(IDC_INSTALL_PWA, install_item, GetInstallPWAIcon(browser));
SetElementIdentifierAt(GetItemCount() - 1, AppMenuModel::kInstallAppItem);
} else if (std::u16string open_item = GetOpenPWALabel(browser);
!open_item.empty()) {
AddItemWithIcon(
IDC_OPEN_IN_PWA_WINDOW, open_item,
ui::ImageModel::FromVectorIcon(kDesktopWindowsChromeRefreshIcon,
ui::kColorMenuIcon, kDefaultIconSize));
}
AddItemWithStringIdAndVectorIcon(this, IDC_CREATE_SHORTCUT,
IDS_ADD_TO_OS_LAUNCH_SURFACE,
kDriveShortcutChromeRefreshIcon);
SetElementIdentifierAt(GetItemCount() - 1, AppMenuModel::kCreateShortcutItem);
if (!sharing_hub::SharingIsDisabledByPolicy(browser->profile()) ||
media_router::MediaRouterEnabled(browser->profile())) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddTitle(l10n_util::GetStringUTF16(IDS_SAVE_AND_SHARE_MENU_SHARE));
if (!sharing_hub::SharingIsDisabledByPolicy(browser->profile())) {
AddItemWithStringIdAndVectorIcon(
this, IDC_COPY_URL, IDS_APP_MENU_COPY_LINK, kLinkChromeRefreshIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_SEND_TAB_TO_SELF,
IDS_MENU_SEND_TAB_TO_SELF,
kDevicesChromeRefreshIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_QRCODE_GENERATOR,
IDS_APP_MENU_CREATE_QR_CODE,
kQrCodeChromeRefreshIcon);
}
}
if (sharing_hub::DesktopScreenshotsFeatureEnabled(browser->profile())) {
AddItemWithStringIdAndVectorIcon(this, IDC_SHARING_HUB_SCREENSHOT,
IDS_SHARING_HUB_SCREENSHOT_LABEL,
kSharingHubScreenshotIcon);
}
}
bool ArePromotionsEnabled() {
PrefService* local_state = g_browser_process->local_state();
return local_state && local_state->GetBoolean(prefs::kPromotionsEnabled);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// SetCommandIcon
void SetCommandIcon(ui::SimpleMenuModel* model,
int command_id,
const gfx::VectorIcon& vector_icon) {
auto index = model->GetIndexOfCommandId(command_id);
if (index) {
model->SetIcon(index.value(), ui::ImageModel::FromVectorIcon(
vector_icon, ui::kColorMenuIcon,
ui::SimpleMenuModel::kDefaultIconSize));
}
}
////////////////////////////////////////////////////////////////////////////////
// LogWrenchMenuAction
void LogWrenchMenuAction(AppMenuAction action_id) {
base::UmaHistogramEnumeration("WrenchMenu.MenuAction", action_id,
LIMIT_MENU_ACTION);
}
////////////////////////////////////////////////////////////////////////////////
// HelpMenuModel
// Only used in branded builds.
class HelpMenuModel : public ui::SimpleMenuModel {
public:
HelpMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser)
: SimpleMenuModel(delegate) {
Build(browser);
}
HelpMenuModel(const HelpMenuModel&) = delete;
HelpMenuModel& operator=(const HelpMenuModel&) = delete;
private:
void Build(Browser* browser) {
#if BUILDFLAG(IS_CHROMEOS) && defined(OFFICIAL_BUILD)
int help_string_id = IDS_GET_HELP;
#else
int help_string_id = IDS_HELP_PAGE;
#endif
AddItemWithStringIdAndVectorIcon(this, IDC_ABOUT, IDS_ABOUT,
vector_icons::kInfoRefreshIcon);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (whats_new::IsEnabled()) {
AddItemWithStringIdAndVectorIcon(this, IDC_CHROME_WHATS_NEW,
IDS_CHROME_WHATS_NEW, kReleaseAlertIcon);
}
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
AddItemWithStringId(IDC_HELP_PAGE_VIA_MENU, help_string_id);
if (browser_defaults::kShowHelpMenuItemIcon) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SetIcon(GetIndexOfCommandId(IDC_HELP_PAGE_VIA_MENU).value(),
ui::ImageModel::FromImage(rb.GetNativeImageNamed(IDR_HELP_MENU)));
} else {
SetCommandIcon(this, IDC_HELP_PAGE_VIA_MENU, kHelpMenuIcon);
}
if (browser->profile()->GetPrefs()->GetBoolean(
prefs::kUserFeedbackAllowed)) {
AddItemWithStringIdAndVectorIcon(this, IDC_FEEDBACK, IDS_FEEDBACK,
kReportIcon);
}
}
};
////////////////////////////////////////////////////////////////////////////////
// ToolsMenuModel
ToolsMenuModel::ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate,
Browser* browser)
: SimpleMenuModel(delegate) {
Build(browser);
}
ToolsMenuModel::~ToolsMenuModel() = default;
// More tools submenu is constructed as follows:
// - Page specific actions overflow (save page, adding to desktop).
// - Browser / OS level tools (extensions, task manager).
// - Reading mode.
// - Developer tools.
// - Option to enable profiling.
void ToolsMenuModel::Build(Browser* browser) {
// Tablet mode does not have a Tab Search button, so tab organization and
// declutter are unavailable. We should not show tablet mode users these menu
// items.
bool is_tablet_mode = false;
#if BUILDFLAG(IS_CHROMEOS)
is_tablet_mode = display::Screen::GetScreen()->InTabletMode();
#endif // BUILDFLAG(IS_CHROMEOS)
if (!is_tablet_mode) {
if (features::HasTabSearchToolbarButton()) {
AddItemWithStringIdAndVectorIcon(this, IDC_TAB_SEARCH,
IDS_TAB_SEARCH_MENU,
vector_icons::kTabSearchIcon);
}
if (base::FeatureList::IsEnabled(features::kTabOrganizationAppMenuItem) &&
TabOrganizationUtils::GetInstance()->IsEnabled(browser->profile())) {
auto* const tab_organization_service =
TabOrganizationServiceFactory::GetForProfile(browser->profile());
if (tab_organization_service) {
AddItemWithStringIdAndVectorIcon(
this, IDC_ORGANIZE_TABS, IDS_TAB_ORGANIZE_MENU, kAutoTabGroupsIcon);
}
}
if (base::FeatureList::IsEnabled(features::kTabstripDeclutter) &&
!browser->profile()->IsIncognitoProfile()) {
AddItemWithStringIdAndVectorIcon(this, IDC_DECLUTTER_TABS,
features::IsTabstripDedupeEnabled()
? IDS_DECLUTTER_MENU
: IDS_DECLUTTER_MENU_NO_DEDUPE,
kTabCloseInactiveIcon);
SetIsNewFeatureAt(GetIndexOfCommandId(IDC_DECLUTTER_TABS).value(),
browser->window()->MaybeShowNewBadgeFor(
features::kTabstripDeclutter));
}
}
AddItemWithStringIdAndVectorIcon(this, IDC_NAME_WINDOW, IDS_NAME_WINDOW,
kNameWindowIcon);
if (CustomizeChromePageHandler::IsSupported(
NtpCustomBackgroundServiceFactory::GetForProfile(browser->profile()),
browser->profile())) {
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_CUSTOMIZE_CHROME_SIDE_PANEL,
IDS_SHOW_CUSTOMIZE_CHROME_SIDE_PANEL,
kEditChromeRefreshIcon);
}
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_READING_MODE_SIDE_PANEL,
IDS_SHOW_READING_MODE_SIDE_PANEL,
kMenuBookChromeRefreshIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_SHOW_READING_MODE_SIDE_PANEL).value(),
kReadingModeMenuItem);
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_PERFORMANCE, IDS_SHOW_PERFORMANCE,
kPerformanceIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_PERFORMANCE).value(),
kPerformanceMenuItem);
if (chrome::CanOpenTaskManager()) {
AddItemWithStringIdAndVectorIcon(this, IDC_TASK_MANAGER_APP_MENU,
IDS_TASK_MANAGER, kTaskManagerIcon);
}
#if BUILDFLAG(IS_CHROMEOS)
AddItemWithStringId(IDC_TAKE_SCREENSHOT, IDS_TAKE_SCREENSHOT);
#endif
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_DEV_TOOLS, IDS_DEV_TOOLS,
kDeveloperToolsIcon);
if (base::debug::IsProfilingSupported()) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED);
}
if (IsChromeLabsEnabled()) {
auto* profile = browser->profile();
chrome_labs_model_ = std::make_unique<ChromeLabsModel>();
UpdateChromeLabsNewBadgePrefs(profile, chrome_labs_model_.get());
if (ShouldShowChromeLabsUI(chrome_labs_model_.get(), profile)) {
BooleanPrefMember show_chrome_labs_item;
show_chrome_labs_item.Init(
chrome_labs_prefs::kBrowserLabsEnabledEnterprisePolicy,
profile->GetPrefs());
if (show_chrome_labs_item.GetValue()) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_CHROME_LABS,
IDS_CHROMELABS, kScienceIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_SHOW_CHROME_LABS).value(),
kChromeLabsMenuItem);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// ExtensionsMenuModel
ExtensionsMenuModel::ExtensionsMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
Browser* browser)
: SimpleMenuModel(delegate) {
Build(browser);
}
ExtensionsMenuModel::~ExtensionsMenuModel() = default;
// Extensions (sub)menu is constructed as follows:
// - An overflow with two items:
// - An item to manage extensions at chrome://extensions
// - An item to visit the Chrome Web Store
void ExtensionsMenuModel::Build(Browser* browser) {
AddItemWithStringIdAndVectorIcon(
this, IDC_EXTENSIONS_SUBMENU_MANAGE_EXTENSIONS,
IDS_EXTENSIONS_SUBMENU_MANAGE_EXTENSIONS_ITEM,
vector_icons::kExtensionChromeRefreshIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_EXTENSIONS_SUBMENU_MANAGE_EXTENSIONS).value(),
kManageExtensionsMenuItem);
AddItemWithStringId(IDC_EXTENSIONS_SUBMENU_VISIT_CHROME_WEB_STORE,
IDS_EXTENSIONS_SUBMENU_CHROME_WEBSTORE_ITEM);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_EXTENSIONS_SUBMENU_VISIT_CHROME_WEB_STORE)
.value(),
kVisitChromeWebStoreMenuItem);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
SetCommandIcon(this, IDC_EXTENSIONS_SUBMENU_VISIT_CHROME_WEB_STORE,
vector_icons::kGoogleChromeWebstoreIcon);
#endif
}
////////////////////////////////////////////////////////////////////////////////
// AppMenuModel
AppMenuModel::AppMenuModel(ui::AcceleratorProvider* provider,
Browser* browser,
AppMenuIconController* app_menu_icon_controller,
AlertMenuItem alert_item)
: ui::SimpleMenuModel(this),
uma_action_recorded_(false),
provider_(provider),
browser_(browser),
app_menu_icon_controller_(app_menu_icon_controller),
alert_item_(alert_item) {
DCHECK(browser_);
}
AppMenuModel::~AppMenuModel() = default;
void AppMenuModel::SetHighlightedIdentifier(
ui::ElementIdentifier highlighted_menu_identifier) {
highlighted_menu_identifier_ = highlighted_menu_identifier;
}
void AppMenuModel::Init() {
Build();
#if BUILDFLAG(IS_CHROMEOS)
PrefService* const local_state = g_browser_process->local_state();
if (local_state) {
local_state_pref_change_registrar_.Init(local_state);
local_state_pref_change_registrar_.Add(
policy::policy_prefs::kSystemFeaturesDisableList,
base::BindRepeating(&AppMenuModel::UpdateSettingsItemState,
base::Unretained(this)));
UpdateSettingsItemState();
}
#endif // BUILDFLAG(IS_CHROMEOS)
}
bool AppMenuModel::DoesCommandIdDismissMenu(int command_id) const {
return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS;
}
void AppMenuModel::ExecuteCommand(int command_id, int event_flags) {
GlobalError* error =
GlobalErrorServiceFactory::GetForProfile(browser_->profile())
->GetGlobalErrorByMenuItemCommandID(command_id);
if (error) {
error->ExecuteMenuItem(browser_);
return;
}
if (command_id == IDC_VIEW_PASSWORDS) {
browser()->profile()->GetPrefs()->SetBoolean(
password_manager::prefs::kPasswordsPrefWithNewLabelUsed, true);
}
LogMenuMetrics(command_id);
chrome::ExecuteCommand(browser_, command_id);
}
void AppMenuModel::LogSafetyHubInteractionMetrics(
safety_hub::SafetyHubModuleType sh_module,
int event_flags) {
base::UmaHistogramEnumeration("Settings.SafetyHub.Interaction",
safety_hub::SafetyHubSurfaces::kThreeDotMenu);
base::UmaHistogramEnumeration(
"Settings.SafetyHub.EntryPointInteraction",
safety_hub::SafetyHubEntryPoint::kMenuNotifications);
base::UmaHistogramEnumeration("Settings.SafetyHub.MenuNotificationClicked",
sh_module);
if (SafetyHubHatsService* hats_service =
SafetyHubHatsServiceFactory::GetForProfile(browser_->profile())) {
hats_service->SafetyHubNotificationClicked(sh_module);
}
}
void AppMenuModel::LogMenuMetrics(int command_id) {
base::TimeDelta delta = timer_.Elapsed();
switch (command_id) {
case IDC_UPGRADE_DIALOG:
LogMenuAction(MENU_ACTION_UPGRADE_DIALOG);
break;
case IDC_NEW_TAB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.NewTab", delta);
}
LogMenuAction(MENU_ACTION_NEW_TAB);
break;
case IDC_NEW_WINDOW:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.NewWindow",
delta);
}
LogMenuAction(MENU_ACTION_NEW_WINDOW);
break;
case IDC_NEW_INCOGNITO_WINDOW:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.NewIncognitoWindow", delta);
}
LogMenuAction(MENU_ACTION_NEW_INCOGNITO_WINDOW);
break;
// Bookmarks sub menu.
case IDC_SHOW_BOOKMARK_BAR:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowBookmarkBar",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_BOOKMARK_BAR);
break;
case IDC_SHOW_BOOKMARK_SIDE_PANEL:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowBookmarkSidePanel", delta);
}
LogMenuAction(MENU_ACTION_SHOW_BOOKMARK_SIDE_PANEL);
// Close IPH for side panel menu, if shown.
browser()->window()->NotifyFeaturePromoFeatureUsed(
feature_engagement::kIPHPowerBookmarksSidePanelFeature,
FeaturePromoFeatureUsedAction::kIgnorePromoIfPresent);
break;
case IDC_SHOW_BOOKMARK_MANAGER:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowBookmarkMgr",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_BOOKMARK_MANAGER);
break;
case IDC_IMPORT_SETTINGS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ImportSettings",
delta);
}
LogMenuAction(MENU_ACTION_IMPORT_SETTINGS);
break;
case IDC_BOOKMARK_THIS_TAB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.BookmarkPage",
delta);
}
LogMenuAction(MENU_ACTION_BOOKMARK_THIS_TAB);
break;
case IDC_BOOKMARK_ALL_TABS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.BookmarkAllTabs",
delta);
}
LogMenuAction(MENU_ACTION_BOOKMARK_ALL_TABS);
break;
// Lens overlay.
case IDC_CONTENT_CONTEXT_LENS_OVERLAY:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowLensOverlay",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_LENS_OVERLAY);
break;
// Extensions menu.
case IDC_EXTENSIONS_SUBMENU_MANAGE_EXTENSIONS:
// Logging the original histograms for experiment comparison purposes.
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ManageExtensions", delta);
}
LogMenuAction(MENU_ACTION_MANAGE_EXTENSIONS);
break;
case IDC_EXTENSIONS_SUBMENU_VISIT_CHROME_WEB_STORE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.VisitChromeWebStore", delta);
}
LogMenuAction(MENU_ACTION_VISIT_CHROME_WEB_STORE);
break;
case IDC_FIND_EXTENSIONS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.FindExtensions",
delta);
}
LogMenuAction(MENU_ACTION_FIND_EXTENSIONS);
break;
// Recent tabs menu.
case IDC_RESTORE_TAB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.RestoreTab",
delta);
}
LogMenuAction(MENU_ACTION_RESTORE_TAB);
break;
case IDC_OPEN_RECENT_TAB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.OpenRecentTab",
delta);
}
LogMenuAction(MENU_ACTION_RECENT_TAB);
break;
case IDC_RECENT_TABS_LOGIN_FOR_DEVICE_TABS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.LoginForDeviceTabs", delta);
}
LogMenuAction(MENU_ACTION_RECENT_TABS_LOGIN_FOR_DEVICE_TABS);
break;
case IDC_FIND:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Find", delta);
}
LogMenuAction(MENU_ACTION_FIND);
break;
case IDC_PRINT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Print", delta);
}
LogMenuAction(MENU_ACTION_PRINT);
break;
#if BUILDFLAG(ENABLE_GLIC)
case IDC_OPEN_GLIC:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.OpenGlic",
delta);
}
LogMenuAction(MENU_ACTION_OPEN_GLIC);
break;
#endif
case IDC_SHOW_TRANSLATE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowTranslate",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_TRANSLATE);
break;
// Edit menu.
case IDC_CUT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Cut", delta);
}
LogMenuAction(MENU_ACTION_CUT);
break;
case IDC_COPY:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Copy", delta);
}
LogMenuAction(MENU_ACTION_COPY);
break;
case IDC_PASTE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Paste", delta);
}
LogMenuAction(MENU_ACTION_PASTE);
break;
// Save and share menu.
case IDC_SAVE_PAGE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.SavePage",
delta);
}
LogMenuAction(MENU_ACTION_SAVE_PAGE);
break;
case IDC_INSTALL_PWA:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.InstallPwa",
delta);
}
LogMenuAction(MENU_ACTION_INSTALL_PWA);
break;
case IDC_OPEN_IN_PWA_WINDOW:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.OpenInPwaWindow",
delta);
}
LogMenuAction(MENU_ACTION_OPEN_IN_PWA_WINDOW);
break;
case IDC_CREATE_SHORTCUT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.CreateHostedApp",
delta);
}
LogMenuAction(MENU_ACTION_CREATE_HOSTED_APP);
break;
case IDC_COPY_URL:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.CopyUrl", delta);
}
LogMenuAction(MENU_ACTION_COPY_URL);
break;
case IDC_SEND_TAB_TO_SELF:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.SendToDevices",
delta);
}
LogMenuAction(MENU_ACTION_SEND_TO_DEVICES);
break;
case IDC_QRCODE_GENERATOR:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.CreateQrCode",
delta);
}
LogMenuAction(MENU_ACTION_CREATE_QR_CODE);
break;
case IDC_ROUTE_MEDIA:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Cast", delta);
}
LogMenuAction(MENU_ACTION_CAST);
break;
// Tools menu.
case IDC_MANAGE_EXTENSIONS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ManageExtensions", delta);
}
LogMenuAction(MENU_ACTION_MANAGE_EXTENSIONS);
break;
case IDC_TASK_MANAGER:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.TaskManager",
delta);
}
LogMenuAction(MENU_ACTION_TASK_MANAGER);
break;
case IDC_CLEAR_BROWSING_DATA:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ClearBrowsingData", delta);
}
LogMenuAction(MENU_ACTION_CLEAR_BROWSING_DATA);
break;
case IDC_VIEW_SOURCE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ViewSource",
delta);
}
LogMenuAction(MENU_ACTION_VIEW_SOURCE);
break;
case IDC_DEV_TOOLS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.DevTools",
delta);
}
LogMenuAction(MENU_ACTION_DEV_TOOLS);
break;
case IDC_DEV_TOOLS_CONSOLE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.DevToolsConsole",
delta);
}
LogMenuAction(MENU_ACTION_DEV_TOOLS_CONSOLE);
break;
case IDC_DEV_TOOLS_DEVICES:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.DevToolsDevices",
delta);
}
LogMenuAction(MENU_ACTION_DEV_TOOLS_DEVICES);
break;
case IDC_PROFILING_ENABLED:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ProfilingEnabled", delta);
}
LogMenuAction(MENU_ACTION_PROFILING_ENABLED);
break;
case IDC_SHOW_CHROME_LABS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowChromeLabs",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_CHROME_LABS);
break;
case IDC_SHOW_HISTORY_CLUSTERS_SIDE_PANEL:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowHistoryClustersSidePanel", delta);
}
LogMenuAction(MENU_ACTION_SHOW_HISTORY_CLUSTER_SIDE_PANEL);
break;
case IDC_SHOW_READING_MODE_SIDE_PANEL:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowReadingModeSidePanel", delta);
}
LogMenuAction(MENU_ACTION_SHOW_READING_MODE_SIDE_PANEL);
// Close IPH for side panel menu, if shown.
browser()->window()->NotifyFeaturePromoFeatureUsed(
feature_engagement::kIPHReadingModeSidePanelFeature,
FeaturePromoFeatureUsedAction::kIgnorePromoIfPresent);
break;
case IDC_SHOW_CUSTOMIZE_CHROME_SIDE_PANEL:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowCustomizeChromeSidePanel", delta);
}
LogMenuAction(MENU_ACTION_SHOW_CUSTOMIZE_CHROME_SIDE_PANEL);
// Close IPH for side panel menu, if shown.
browser()->window()->NotifyFeaturePromoFeatureUsed(
feature_engagement::kIPHDesktopCustomizeChromeRefreshFeature,
FeaturePromoFeatureUsedAction::kIgnorePromoIfPresent);
break;
// Zoom menu
case IDC_ZOOM_MINUS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ZoomMinus",
delta);
LogMenuAction(MENU_ACTION_ZOOM_MINUS);
}
break;
case IDC_ZOOM_PLUS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ZoomPlus",
delta);
LogMenuAction(MENU_ACTION_ZOOM_PLUS);
}
break;
case IDC_FULLSCREEN:
base::RecordAction(UserMetricsAction("EnterFullScreenWithWrenchMenu"));
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.EnterFullScreen",
delta);
}
LogMenuAction(MENU_ACTION_FULLSCREEN);
break;
case IDC_SHOW_HISTORY:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowHistory",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_HISTORY);
break;
case IDC_SHOW_DOWNLOADS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowDownloads",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_DOWNLOADS);
base::UmaHistogramEnumeration(
"Download.OpenDownloadsFromMenu.PerProfileType",
profile_metrics::GetBrowserProfileType(browser_->profile()));
break;
case IDC_OPTIONS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Settings",
delta);
}
LogMenuAction(MENU_ACTION_OPTIONS);
base::UmaHistogramEnumeration(
"Settings.OpenSettingsFromMenu.PerProfileType",
profile_metrics::GetBrowserProfileType(browser_->profile()));
break;
case IDC_ABOUT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.About", delta);
}
LogMenuAction(MENU_ACTION_ABOUT);
break;
// Help menu.
case IDC_HELP_PAGE_VIA_MENU:
base::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu"));
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.HelpPage",
delta);
}
LogMenuAction(MENU_ACTION_HELP_PAGE_VIA_MENU);
break;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
case IDC_SHOW_BETA_FORUM:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.BetaForum",
delta);
}
LogMenuAction(MENU_ACTION_BETA_FORUM);
break;
case IDC_FEEDBACK:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Feedback",
delta);
}
LogMenuAction(MENU_ACTION_FEEDBACK);
break;
case IDC_CHROME_TIPS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ChromeTips",
delta);
}
LogMenuAction(MENU_ACTION_CHROME_TIPS);
break;
case IDC_CHROME_WHATS_NEW:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ChromeWhatsNew",
delta);
}
LogMenuAction(MENU_ACTION_CHROME_WHATS_NEW);
break;
#endif
case IDC_TOGGLE_REQUEST_TABLET_SITE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.RequestTabletSite", delta);
}
LogMenuAction(MENU_ACTION_TOGGLE_REQUEST_TABLET_SITE);
break;
case IDC_EXIT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.Exit", delta);
}
LogMenuAction(MENU_ACTION_EXIT);
break;
// Hosted App menu.
case IDC_OPEN_IN_CHROME:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.OpenInChrome",
delta);
}
LogMenuAction(MENU_ACTION_OPEN_IN_CHROME);
break;
case IDC_WEB_APP_MENU_APP_INFO:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.AppInfo", delta);
}
LogMenuAction(MENU_ACTION_APP_INFO);
break;
case IDC_VIEW_PASSWORDS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.PasswordManager",
delta);
}
LogMenuAction(MENU_ACTION_PASSWORD_MANAGER);
break;
// Profile submenu.
#if !BUILDFLAG(IS_CHROMEOS)
case IDC_CUSTOMIZE_CHROME:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.CustomizeChrome",
delta);
}
LogMenuAction(MENU_ACTION_CUSTOMIZE_CHROME);
break;
case IDC_CLOSE_PROFILE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.CloseProfile",
delta);
}
LogMenuAction(MENU_ACTION_CLOSE_PROFILE);
break;
case IDC_MANAGE_GOOGLE_ACCOUNT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ManageGoogleAccount", delta);
}
LogMenuAction(MENU_ACTION_MANAGE_GOOGLE_ACCOUNT);
break;
case IDC_SHOW_SYNC_SETTINGS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowSyncSettings", delta);
}
LogMenuAction(MENU_SHOW_SYNC_SETTINGS);
break;
case IDC_TURN_ON_SYNC:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowTurnOnSync",
delta);
}
LogMenuAction(MENU_TURN_ON_SYNC);
break;
case IDC_SHOW_SIGNIN_WHEN_PAUSED:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowSigninWhenPaused", delta);
}
LogMenuAction(MENU_SHOW_SIGNIN_WHEN_PAUSED);
break;
case IDC_OPEN_GUEST_PROFILE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.OpenGuestProfile", delta);
}
LogMenuAction(MENU_ACTION_OPEN_GUEST_PROFILE);
break;
case IDC_ADD_NEW_PROFILE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.AddNewProfile",
delta);
}
LogMenuAction(MENU_ACTION_ADD_NEW_PROFILE);
break;
case IDC_MANAGE_CHROME_PROFILES:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ManageChromeProfiles", delta);
}
LogMenuAction(MENU_ACTION_MANAGE_CHROME_PROFILES);
break;
#endif
// Reading list submenu.
case IDC_READING_LIST_MENU_ADD_TAB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ReadingListAddTab", delta);
}
LogMenuAction(MENU_ACTION_READING_LIST_ADD_TAB);
break;
case IDC_READING_LIST_MENU_SHOW_UI:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ReadingListShowUi", delta);
}
LogMenuAction(MENU_ACTION_READING_LIST_SHOW_UI);
break;
// Password autofill submenu.
case IDC_SHOW_PASSWORD_MANAGER:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowPasswordManager", delta);
}
LogMenuAction(MENU_ACTION_SHOW_PASSWORD_MANAGER);
break;
case IDC_SHOW_PAYMENT_METHODS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowPaymentMethods", delta);
}
LogMenuAction(MENU_ACTION_SHOW_PAYMENT_METHODS);
break;
case IDC_SHOW_ADDRESSES:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.ShowAddresses",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_ADDRESSES);
break;
case IDC_PERFORMANCE:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.ShowPerformanceSettings", delta);
}
LogMenuAction(MENU_ACTION_SHOW_PERFORMANCE_SETTINGS);
break;
case IDC_SET_BROWSER_AS_DEFAULT:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.SetBrowserAsDefault", delta);
}
LogMenuAction(MENU_ACTION_SET_BROWSER_AS_DEFAULT);
break;
case IDC_SAFETY_HUB_SHOW_PASSWORD_CHECKUP:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.SafetyHubNotificationPasswordCheck",
delta);
}
LogMenuAction(MENU_ACTION_SAFETY_HUB_SHOW_PASSWORD_CHECKUP);
break;
case IDC_OPEN_SAFETY_HUB:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.SafetyHubNotificationOpenSafetyHub",
delta);
}
LogMenuAction(MENU_ACTION_SHOW_SAFETY_HUB);
break;
case IDC_DECLUTTER_TABS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction.DeclutterTabs",
delta);
}
tabs::TabDeclutterController::EmitEntryPointHistogram(
tab_search::mojom::TabDeclutterEntryPoint::kAppMenu);
LogMenuAction(MENU_ACTION_DECLUTTER_TABS);
break;
case IDC_SAFETY_HUB_MANAGE_EXTENSIONS:
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.SafetyHubNotificationManageExtensions",
delta);
}
LogMenuAction(MENU_ACTION_SAFETY_HUB_MANAGE_EXTENSIONS);
break;
default: {
if (IsOtherProfileCommand(command_id)) {
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes(
"WrenchMenu.TimeToAction.SwitchToAnotherProfile", delta);
}
LogMenuAction(MENU_ACTION_SWITCH_TO_ANOTHER_PROFILE);
}
break;
}
}
if (!uma_action_recorded_) {
base::UmaHistogramMediumTimes("WrenchMenu.TimeToAction", delta);
uma_action_recorded_ = true;
}
}
bool AppMenuModel::IsCommandIdChecked(int command_id) const {
if (command_id == IDC_SHOW_BOOKMARK_BAR) {
return browser_->profile()->GetPrefs()->GetBoolean(
bookmarks::prefs::kShowBookmarkBar);
}
if (command_id == IDC_PROFILING_ENABLED) {
return content::Profiling::BeingProfiled();
}
if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) {
return chrome::IsRequestingTabletSite(browser_);
}
return false;
}
bool AppMenuModel::IsCommandIdEnabled(int command_id) const {
GlobalError* error =
GlobalErrorServiceFactory::GetForProfile(browser_->profile())
->GetGlobalErrorByMenuItemCommandID(command_id);
if (error) {
return true;
}
switch (command_id) {
case IDC_NEW_INCOGNITO_WINDOW:
return IncognitoModePrefs::IsIncognitoAllowed(browser_->profile());
default:
return chrome::IsCommandEnabled(browser_, command_id);
}
}
bool AppMenuModel::IsCommandIdAlerted(int command_id) const {
if (command_id == IDC_VIEW_PASSWORDS ||
command_id == IDC_SHOW_PASSWORD_MANAGER) {
return alert_item_ == AlertMenuItem::kPasswordManager;
}
return false;
}
bool AppMenuModel::IsElementIdAlerted(ui::ElementIdentifier element_id) const {
return highlighted_menu_identifier_ == element_id;
}
bool AppMenuModel::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const {
return provider_->GetAcceleratorForCommandId(command_id, accelerator);
}
void AppMenuModel::LogMenuAction(AppMenuAction action_id) {
LogWrenchMenuAction(action_id);
}
// Note: When adding new menu items please place under an appropriate section.
// Menu is organised as follows:
// - Extension toolbar overflow.
// - Global browser errors and warnings.
// - Tabs and windows.
// - Places previously been e.g. History, bookmarks, recent tabs.
// - Page actions e.g. zoom, edit, find, print.
// - Learn about the browser and global customisation e.g. settings, help.
// - Browser relaunch, quit.
void AppMenuModel::Build() {
// Build (and, by extension, Init) should only be called once.
DCHECK_EQ(0u, GetItemCount());
if (app_menu_icon_controller_ &&
app_menu_icon_controller_->GetTypeAndSeverity().type ==
AppMenuIconController::IconType::UPGRADE_NOTIFICATION) {
AddSeparator(ui::SPACING_SEPARATOR);
const auto update_icon = ui::ImageModel::FromVectorIcon(
kBrowserToolsUpdateChromeRefreshIcon,
ui::kColorMenuIconOnEmphasizedBackground, kDefaultIconSize);
if (browser_defaults::kShowUpgradeMenuItem) {
AddItemWithIcon(IDC_UPGRADE_DIALOG, GetUpgradeDialogTitleText(),
update_icon);
AddSeparator(ui::SPACING_SEPARATOR);
}
}
if (AddSafetyHubMenuItem() || AddGlobalErrorMenuItems() ||
AddDefaultBrowserMenuItems()) {
AddSeparator(ui::NORMAL_SEPARATOR);
}
AddItemWithStringIdAndVectorIcon(
this, IDC_NEW_TAB,
browser_->profile()->IsIncognitoProfile() &&
!browser_->profile()->IsGuestSession()
? IDS_NEW_INCOGNITO_TAB
: IDS_NEW_TAB,
kNewTabRefreshIcon);
AddItemWithStringIdAndVectorIcon(this, IDC_NEW_WINDOW, IDS_NEW_WINDOW,
kNewWindowIcon);
// This menu item is not visible in Guest Mode. If incognito mode is not
// available, it will be shown in disabled state. (crbug.com/1100791)
if (!browser_->profile()->IsGuestSession()) {
AddItemWithStringIdAndVectorIcon(this, IDC_NEW_INCOGNITO_WINDOW,
IDS_NEW_INCOGNITO_WINDOW,
kIncognitoRefreshMenuIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_NEW_INCOGNITO_WINDOW).value(),
kIncognitoMenuItem);
}
AddSeparator(ui::NORMAL_SEPARATOR);
#if !BUILDFLAG(IS_CHROMEOS)
sub_menus_.push_back(std::make_unique<ProfileSubMenuModel>(
this, browser()->profile(), browser()->window()->GetColorProvider()));
auto* const profile_submenu_model =
static_cast<ProfileSubMenuModel*>(sub_menus_.back().get());
AddSubMenu(IDC_PROFILE_MENU_IN_APP_MENU,
profile_submenu_model->profile_name(), profile_submenu_model);
SetIcon(GetIndexOfCommandId(IDC_PROFILE_MENU_IN_APP_MENU).value(),
profile_submenu_model->avatar_image_model());
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_PROFILE_MENU_IN_APP_MENU).value(),
kProfileMenuItem);
AddSeparator(ui::SPACING_SEPARATOR);
#endif
if (!browser_->profile()->IsGuestSession()) {
sub_menus_.push_back(
std::make_unique<PasswordsAndAutofillSubMenuModel>(this));
AddSubMenuWithStringIdAndVectorIcon(
this, IDC_PASSWORDS_AND_AUTOFILL_MENU, IDS_PASSWORDS_AND_AUTOFILL_MENU,
sub_menus_.back().get(), vector_icons::kPasswordManagerIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_PASSWORDS_AND_AUTOFILL_MENU).value(),
kPasswordAndAutofillMenuItem);
}
if (!browser_->profile()->IsOffTheRecord()) {
auto recent_tabs_sub_menu =
std::make_unique<RecentTabsSubMenuModel>(provider_, browser_);
recent_tabs_sub_menu->RegisterLogMenuMetricsCallback(base::BindRepeating(
&AppMenuModel::LogMenuMetrics, base::Unretained(this)));
sub_menus_.push_back(std::move(recent_tabs_sub_menu));
AddSubMenuWithStringIdAndVectorIcon(this, IDC_RECENT_TABS_MENU,
IDS_HISTORY_MENU,
sub_menus_.back().get(), kHistoryIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_RECENT_TABS_MENU).value(),
kHistoryMenuItem);
}
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS,
kDownloadMenuIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_SHOW_DOWNLOADS).value(),
kDownloadsMenuItem);
if (!browser_->profile()->IsGuestSession()) {
bookmark_sub_menu_model_ =
std::make_unique<BookmarkSubMenuModel>(this, browser_);
AddSubMenuWithStringIdAndVectorIcon(
this, IDC_BOOKMARKS_MENU, IDS_BOOKMARKS_AND_LISTS_MENU,
bookmark_sub_menu_model_.get(), kBookmarksListsMenuIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_BOOKMARKS_MENU).value(),
kBookmarksMenuItem);
}
if (browser_->profile()->IsRegularProfile()) {
auto saved_tab_groups_model = std::make_unique<ui::SimpleMenuModel>(this);
sub_menus_.push_back(std::move(saved_tab_groups_model));
AddSubMenuWithStringIdAndVectorIcon(
this, IDC_SAVED_TAB_GROUPS_MENU, IDS_SAVED_TAB_GROUPS_MENU,
sub_menus_.back().get(), kSavedTabGroupBarEverythingIcon);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_SAVED_TAB_GROUPS_MENU).value(),
kTabGroupsMenuItem);
}
// Extensions sub menu.
if (ArePromotionsEnabled() &&
base::FeatureList::IsEnabled(features::kExtensionsCollapseMainMenu) &&
!extensions::ui_util::HasManageableExtensions(browser_->profile())) {
AddItemWithStringIdAndVectorIcon(this, IDC_FIND_EXTENSIONS,
IDS_FIND_EXTENSIONS,
vector_icons::kExtensionChromeRefreshIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_FIND_EXTENSIONS).value(),
ExtensionsMenuModel::kVisitChromeWebStoreMenuItem);
} else {
sub_menus_.push_back(std::make_unique<ExtensionsMenuModel>(this, browser_));
AddSubMenuWithStringIdAndVectorIcon(
this, IDC_EXTENSIONS_SUBMENU, IDS_EXTENSIONS_SUBMENU,
sub_menus_.back().get(), vector_icons::kExtensionChromeRefreshIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_EXTENSIONS_SUBMENU).value(),
kExtensionsMenuItem);
}
AddItemWithStringIdAndVectorIcon(this, IDC_CLEAR_BROWSING_DATA,
IDS_CLEAR_BROWSING_DATA,
kTrashCanRefreshIcon);
AddSeparator(ui::NORMAL_SEPARATOR);
CreateZoomMenu();
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringIdAndVectorIcon(this, IDC_PRINT, IDS_PRINT, kPrintMenuIcon);
#if BUILDFLAG(ENABLE_GLIC)
if (glic::GlicEnabling::IsEnabledForProfile(browser_->profile())) {
AddItemWithStringIdAndVectorIcon(this, IDC_OPEN_GLIC,
IDS_GLIC_THREE_DOT_MENU_ITEM,
glic::GlicVectorIconManager::GetVectorIcon(
IDR_GLIC_BUTTON_VECTOR_ICON));
SetIsNewFeatureAt(GetIndexOfCommandId(IDC_OPEN_GLIC).value(),
browser()->window()->MaybeShowNewBadgeFor(
features::kGlicAppMenuNewBadge));
}
#endif
if (browser()
->GetFeatures()
.lens_overlay_entry_point_controller()
->IsEnabled()) {
const gfx::VectorIcon& icon =
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
vector_icons::kGoogleLensMonochromeLogoIcon;
#else
vector_icons::kSearchChromeRefreshIcon;
#endif
AddItemWithStringIdAndVectorIcon(this, IDC_CONTENT_CONTEXT_LENS_OVERLAY,
IDS_SHOW_LENS_OVERLAY, icon);
const int lens_command_index =
GetIndexOfCommandId(IDC_CONTENT_CONTEXT_LENS_OVERLAY).value();
SetElementIdentifierAt(lens_command_index, kShowLensOverlay);
SetIsNewFeatureAt(lens_command_index,
browser()->window()->MaybeShowNewBadgeFor(
lens::features::kLensOverlay));
}
AddItemWithStringIdAndVectorIcon(this, IDC_SHOW_TRANSLATE, IDS_SHOW_TRANSLATE,
kTranslateIcon);
CreateFindAndEditSubMenu();
sub_menus_.push_back(
std::make_unique<SaveAndShareSubMenuModel>(this, browser_));
int string_id = media_router::MediaRouterEnabled(browser()->profile())
? IDS_CAST_SAVE_AND_SHARE_MENU
: IDS_SAVE_AND_SHARE_MENU;
AddSubMenuWithStringIdAndVectorIcon(this, IDC_SAVE_AND_SHARE_MENU, string_id,
sub_menus_.back().get(),
kFileSaveChromeRefreshIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_SAVE_AND_SHARE_MENU).value(),
kSaveAndShareMenuItem);
#if BUILDFLAG(IS_CHROMEOS)
// Always show this option if we're in tablet mode on Chrome OS.
if (display::Screen::GetScreen()->InTabletMode()) {
AddItemWithStringIdAndVectorIcon(this, IDC_TOGGLE_REQUEST_TABLET_SITE,
IDS_TOGGLE_REQUEST_TABLET_SITE,
chrome::IsRequestingTabletSite(browser_)
? kRequestMobileSiteCheckedIcon
: kRequestMobileSiteUncheckedIcon);
}
#endif
sub_menus_.push_back(std::make_unique<ToolsMenuModel>(this, browser_));
AddSubMenuWithStringIdAndVectorIcon(
this, IDC_MORE_TOOLS_MENU, IDS_MORE_TOOLS_MENU, sub_menus_.back().get(),
kMoreToolsMenuIcon);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_MORE_TOOLS_MENU).value(),
kMoreToolsMenuItem);
AddSeparator(ui::NORMAL_SEPARATOR);
// The help submenu is only displayed on official Chrome builds. As the
// 'About' item has been moved to this submenu, it's reinstated here for
// Chromium builds.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
sub_menus_.push_back(std::make_unique<HelpMenuModel>(this, browser_));
AddSubMenuWithStringIdAndVectorIcon(this, IDC_HELP_MENU, IDS_HELP_MENU,
sub_menus_.back().get(), kHelpMenuIcon);
#else
#if BUILDFLAG(IS_CHROMEOS)
AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT));
#else
AddItemWithStringIdAndVectorIcon(this, IDC_ABOUT, IDS_ABOUT,
vector_icons::kInfoRefreshIcon);
#endif
#endif
AddItemWithStringIdAndVectorIcon(this, IDC_OPTIONS, IDS_SETTINGS,
kSettingsMenuIcon);
if (browser_defaults::kShowExitMenuItem) {
AddItemWithStringIdAndVectorIcon(this, IDC_EXIT, IDS_EXIT, kExitMenuIcon);
}
// On Chrome OS, similar UI is displayed in the system tray menu, instead of
// this menu.
#if !BUILDFLAG(IS_CHROMEOS)
if (ShouldDisplayManagedUi(browser_->profile())) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithIcon(
IDC_SHOW_MANAGEMENT_PAGE,
GetManagedUiMenuItemLabel(browser_->profile()),
ui::ImageModel::FromVectorIcon(GetManagedUiIcon(browser_->profile()),
ui::kColorMenuIcon, kDefaultIconSize));
SetAccessibleNameAt(GetIndexOfCommandId(IDC_SHOW_MANAGEMENT_PAGE).value(),
GetManagedUiMenuItemTooltip(browser_->profile()));
}
#endif // !BUILDFLAG(IS_CHROMEOS)
uma_action_recorded_ = false;
}
void AppMenuModel::CreateCutCopyPasteMenu() {
edit_menu_item_model_ =
std::make_unique<ui::ButtonMenuItemModel>(IDS_EDIT, this);
edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT);
edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY);
edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE);
AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get());
}
void AppMenuModel::CreateFindAndEditSubMenu() {
sub_menus_.push_back(std::make_unique<FindAndEditSubMenuModel>(this));
AddSubMenuWithStringIdAndVectorIcon(this, IDC_FIND_AND_EDIT_MENU,
IDS_FIND_AND_EDIT_MENU,
sub_menus_.back().get(), kSearchMenuIcon);
}
void AppMenuModel::CreateZoomMenu() {
zoom_menu_item_model_ =
std::make_unique<ui::ButtonMenuItemModel>(IDS_ZOOM_MENU, this);
zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_MINUS,
IDS_ZOOM_MINUS2);
zoom_menu_item_model_->AddGroupItemWithStringId(IDC_ZOOM_PLUS,
IDS_ZOOM_PLUS2);
zoom_menu_item_model_->AddImageItem(IDC_FULLSCREEN);
AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get());
SetCommandIcon(this, IDC_ZOOM_MENU, kZoomInIcon);
}
bool AppMenuModel::AddGlobalErrorMenuItems() {
// TODO(sail): Currently we only build the app menu once per browser
// window. This means that if a new error is added after the menu is built
// it won't show in the existing app menu. To fix this we need to some
// how update the menu if new errors are added.
const GlobalErrorService::GlobalErrorList& errors =
GlobalErrorServiceFactory::GetForProfile(browser_->profile())->errors();
bool menu_items_added = false;
for (GlobalError* error : errors) {
DCHECK(error);
if (error->HasMenuItem()) {
AddItem(error->MenuItemCommandID(), error->MenuItemLabel());
SetIcon(GetIndexOfCommandId(error->MenuItemCommandID()).value(),
error->MenuItemIcon());
menu_items_added = true;
}
}
return menu_items_added;
}
bool AppMenuModel::AddDefaultBrowserMenuItems() {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS)
if (browser_->profile()->IsIncognitoProfile() ||
browser_->profile()->IsGuestSession()) {
return false;
}
if ((app_menu_icon_controller_ &&
app_menu_icon_controller_->GetTypeAndSeverity().type ==
AppMenuIconController::IconType::DEFAULT_BROWSER_PROMPT) ||
(DefaultBrowserPromptManager::GetInstance()->show_app_menu_item())) {
AddItemWithIcon(
IDC_SET_BROWSER_AS_DEFAULT,
l10n_util::GetStringUTF16(IDS_SET_BROWSER_AS_DEFAULT_MENU_ITEM),
ui::ImageModel::FromVectorIcon(omnibox::kProductChromeRefreshIcon,
ui::kColorMenuIcon, kDefaultIconSize));
SetElementIdentifierAt(GetItemCount() - 1,
AppMenuModel::kSetBrowserAsDefaultMenuItem);
return true;
}
#endif
return false;
}
bool AppMenuModel::AddSafetyHubMenuItem() {
auto* safety_hub_menu_notification_service =
SafetyHubMenuNotificationServiceFactory::GetForProfile(
browser_->profile());
if (!safety_hub_menu_notification_service) {
return false;
}
safety_hub_menu_notification_service->MaybeTriggerControlSurvey();
std::optional<MenuNotificationEntry> notification =
safety_hub_menu_notification_service->GetNotificationToShow();
if (!notification.has_value()) {
return false;
}
base::UmaHistogramEnumeration("Settings.SafetyHub.Impression",
safety_hub::SafetyHubSurfaces::kThreeDotMenu);
base::UmaHistogramEnumeration(
"Settings.SafetyHub.EntryPointImpression",
safety_hub::SafetyHubEntryPoint::kMenuNotifications);
base::UmaHistogramEnumeration("Settings.SafetyHub.MenuNotificationImpression",
notification->module);
const auto safety_hub_icon = ui::ImageModel::FromVectorIcon(
kSecurityIcon, ui::kColorMenuIcon, kDefaultIconSize);
AddItemWithIcon(notification->command, notification->label, safety_hub_icon);
SetExecuteCallbackAt(
GetIndexOfCommandId(notification->command).value(),
base::BindRepeating(&AppMenuModel::LogSafetyHubInteractionMetrics,
base::Unretained(this), notification->module));
return true;
}
#if BUILDFLAG(IS_CHROMEOS)
void AppMenuModel::UpdateSettingsItemState() {
bool is_disabled =
policy::SystemFeaturesDisableListPolicyHandler::IsSystemFeatureDisabled(
policy::SystemFeature::kBrowserSettings,
g_browser_process->local_state());
std::optional<size_t> index = GetIndexOfCommandId(IDC_OPTIONS);
if (index.has_value()) {
SetEnabledAt(index.value(), !is_disabled);
}
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
index = GetIndexOfCommandId(IDC_HELP_MENU);
if (index.has_value()) {
ui::SimpleMenuModel* help_menu =
static_cast<ui::SimpleMenuModel*>(GetSubmenuModelAt(index.value()));
index = help_menu->GetIndexOfCommandId(IDC_ABOUT);
if (index.has_value()) {
help_menu->SetEnabledAt(index.value(), !is_disabled);
}
}
#else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
index = GetIndexOfCommandId(IDC_ABOUT);
if (index.has_value()) {
SetEnabledAt(index.value(), !is_disabled);
}
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
#endif // BUILDFLAG(IS_CHROMEOS)
|