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 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/browser_view.h"
#include <algorithm>
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/bookmarks/bookmark_stats.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/native_window_notification_source.h"
#include "chrome/browser/profiles/avatar_menu.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_info_cache.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/search.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
#include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
#include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window_state.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/search_delegate.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_ui.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/accelerator_table.h"
#include "chrome/browser/ui/views/accessibility/invert_bubble_view.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
#include "chrome/browser/ui/views/download/download_shelf_view.h"
#include "chrome/browser/ui/views/exclusive_access_bubble_views.h"
#include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
#include "chrome/browser/ui/views/frame/contents_layout_manager.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/frame/web_contents_close_handler.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h"
#include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
#include "chrome/browser/ui/views/profiles/profile_reset_bubble_view.h"
#include "chrome/browser/ui/views/session_crashed_bubble_view.h"
#include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
#include "chrome/browser/ui/views/status_bubble_views.h"
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
#include "chrome/browser/ui/views/translate/translate_bubble_view.h"
#include "chrome/browser/ui/views/update_recommended_message_box.h"
#include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h"
#include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
#include "components/app_modal/app_modal_dialog.h"
#include "components/app_modal/app_modal_dialog_queue.h"
#include "components/app_modal/native_app_modal_dialog.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "components/translate/core/browser/language_state.h"
#include "content/app/resources/grit/content_resources.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_service.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/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "grit/theme_resources.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/content_accelerators/accelerator_util.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/native_widget.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if defined(USE_AURA)
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#endif
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/jumplist_win.h"
#include "ui/views/win/scoped_fullscreen_visibility.h"
#endif
#if defined(ENABLE_ONE_CLICK_SIGNIN)
#include "chrome/browser/ui/sync/one_click_signin_bubble_delegate.h"
#include "chrome/browser/ui/sync/one_click_signin_bubble_links_delegate.h"
#include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#endif
using base::TimeDelta;
using base::UserMetricsAction;
using content::NativeWebKeyboardEvent;
using content::SSLStatus;
using content::WebContents;
using views::ColumnSet;
using views::GridLayout;
using web_modal::WebContentsModalDialogHost;
namespace {
// The name of a key to store on the window handle so that other code can
// locate this object using just the handle.
const char* const kBrowserViewKey = "__BROWSER_VIEW__";
// The number of milliseconds between loading animation frames.
const int kLoadingAnimationFrameTimeMs = 30;
// Paints the horizontal border separating the Bookmarks Bar from the Toolbar
// or page content according to |at_top| with |color|.
void PaintHorizontalBorder(gfx::Canvas* canvas,
BookmarkBarView* view,
bool at_top,
SkColor color) {
int thickness = views::NonClientFrameView::kClientEdgeThickness;
int y = at_top ? 0 : (view->height() - thickness);
canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color);
}
// TODO(kuan): These functions are temporarily for the bookmark bar while its
// detached state is at the top of the page; it'll be moved to float on the
// content page in the very near future, at which time, these local functions
// will be removed.
void PaintDetachedBookmarkBar(gfx::Canvas* canvas,
BookmarkBarView* view,
ThemeService* theme_service) {
// Paint background for detached state; if animating, this is fade in/out.
canvas->DrawColor(
chrome::GetDetachedBookmarkBarBackgroundColor(theme_service));
// Draw the separators above and below bookmark bar;
// if animating, these are fading in/out.
SkColor separator_color =
chrome::GetDetachedBookmarkBarSeparatorColor(theme_service);
PaintHorizontalBorder(canvas, view, true, separator_color);
// The bottom border needs to be 1-px thick in both regular and retina
// displays, so we can't use PaintHorizontalBorder which paints a 2-px thick
// border in retina display.
SkPaint paint;
paint.setAntiAlias(false);
// Sets border to 1-px thick regardless of scale factor.
paint.setStrokeWidth(0);
// Bottom border is at 50% opacity of top border.
paint.setColor(SkColorSetA(separator_color,
SkColorGetA(separator_color) / 2));
// Calculate thickness of bottom border as per current scale factor to
// determine where to draw the 1-px thick border.
float thickness = views::NonClientFrameView::kClientEdgeThickness /
canvas->image_scale();
SkScalar y = SkIntToScalar(view->height()) - SkFloatToScalar(thickness);
canvas->sk_canvas()->drawLine(SkIntToScalar(0), y,
SkIntToScalar(view->width()), y, paint);
}
// Paints the background (including the theme image behind content area) for
// the Bookmarks Bar when it is attached to the Toolbar into |bounds|.
// |background_origin| is the origin to use for painting the theme image.
void PaintBackgroundAttachedMode(gfx::Canvas* canvas,
ui::ThemeProvider* theme_provider,
const gfx::Rect& bounds,
const gfx::Point& background_origin,
chrome::HostDesktopType host_desktop_type) {
canvas->FillRect(bounds,
theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR));
canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
background_origin.x(),
background_origin.y(),
bounds.x(),
bounds.y(),
bounds.width(),
bounds.height());
if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) {
// Ash provides additional lightening at the edges of the toolbar.
gfx::ImageSkia* toolbar_left =
theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
canvas->TileImageInt(*toolbar_left,
bounds.x(),
bounds.y(),
toolbar_left->width(),
bounds.height());
gfx::ImageSkia* toolbar_right =
theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
canvas->TileImageInt(*toolbar_right,
bounds.right() - toolbar_right->width(),
bounds.y(),
toolbar_right->width(),
bounds.height());
}
}
void PaintAttachedBookmarkBar(gfx::Canvas* canvas,
BookmarkBarView* view,
BrowserView* browser_view,
chrome::HostDesktopType host_desktop_type,
int toolbar_overlap) {
// Paint background for attached state, this is fade in/out.
gfx::Point background_image_offset =
browser_view->OffsetPointForToolbarBackgroundImage(
gfx::Point(view->GetMirroredX(), view->y()));
PaintBackgroundAttachedMode(canvas,
view->GetThemeProvider(),
view->GetLocalBounds(),
background_image_offset,
host_desktop_type);
if (view->height() >= toolbar_overlap) {
// Draw the separator below the Bookmarks Bar; this is fading in/out.
PaintHorizontalBorder(canvas,
view,
false,
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
}
}
} // namespace
///////////////////////////////////////////////////////////////////////////////
// Delegate implementation for BrowserViewLayout. Usually just forwards calls
// into BrowserView.
class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate {
public:
explicit BrowserViewLayoutDelegateImpl(BrowserView* browser_view)
: browser_view_(browser_view) {}
~BrowserViewLayoutDelegateImpl() override {}
// BrowserViewLayoutDelegate overrides:
views::View* GetContentsWebView() const override {
return browser_view_->contents_web_view_;
}
bool DownloadShelfNeedsLayout() const override {
DownloadShelfView* download_shelf = browser_view_->download_shelf_.get();
// Re-layout the shelf either if it is visible or if its close animation
// is currently running.
return download_shelf &&
(download_shelf->IsShowing() || download_shelf->IsClosing());
}
bool IsTabStripVisible() const override {
return browser_view_->IsTabStripVisible();
}
gfx::Rect GetBoundsForTabStripInBrowserView() const override {
gfx::RectF bounds_f(browser_view_->frame()->GetBoundsForTabStrip(
browser_view_->tabstrip()));
views::View::ConvertRectToTarget(browser_view_->parent(), browser_view_,
&bounds_f);
return gfx::ToEnclosingRect(bounds_f);
}
int GetTopInsetInBrowserView() const override {
return browser_view_->frame()->GetTopInset() -
browser_view_->y();
}
int GetThemeBackgroundXInset() const override {
// TODO(pkotwicz): Return the inset with respect to the left edge of the
// BrowserView.
return browser_view_->frame()->GetThemeBackgroundXInset();
}
bool IsToolbarVisible() const override {
return browser_view_->IsToolbarVisible();
}
bool IsBookmarkBarVisible() const override {
return browser_view_->IsBookmarkBarVisible();
}
ExclusiveAccessBubbleViews* GetExclusiveAccessBubble() const override {
return browser_view_->exclusive_access_bubble();
}
private:
BrowserView* browser_view_;
DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutDelegateImpl);
};
// This class is used to paint the background for Bookmarks Bar.
class BookmarkBarViewBackground : public views::Background {
public:
BookmarkBarViewBackground(BrowserView* browser_view,
BookmarkBarView* bookmark_bar_view,
Browser* browser);
// views:Background:
void Paint(gfx::Canvas* canvas, views::View* view) const override;
private:
BrowserView* browser_view_;
// The view hosting this background.
BookmarkBarView* bookmark_bar_view_;
Browser* browser_;
DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewBackground);
};
BookmarkBarViewBackground::BookmarkBarViewBackground(
BrowserView* browser_view,
BookmarkBarView* bookmark_bar_view,
Browser* browser)
: browser_view_(browser_view),
bookmark_bar_view_(bookmark_bar_view),
browser_(browser) {
}
void BookmarkBarViewBackground::Paint(gfx::Canvas* canvas,
views::View* view) const {
int toolbar_overlap = bookmark_bar_view_->GetToolbarOverlap();
if (!bookmark_bar_view_->IsDetached()) {
PaintAttachedBookmarkBar(canvas,
bookmark_bar_view_,
browser_view_,
browser_->host_desktop_type(),
toolbar_overlap);
return;
}
// As 'hidden' according to the animation is the full in-tab state, we invert
// the value - when current_state is at '0', we expect the bar to be docked.
double current_state = 1 - bookmark_bar_view_->GetAnimationValue();
ThemeService* ts = ThemeServiceFactory::GetForProfile(browser_->profile());
if (current_state == 0.0 || current_state == 1.0) {
PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, ts);
return;
}
// While animating, set opacity to cross-fade between attached and detached
// backgrounds including their respective separators.
int detached_alpha = static_cast<uint8>(current_state * 255);
int attached_alpha = 255 - detached_alpha;
if (browser_->bookmark_bar_state() == BookmarkBar::DETACHED) {
// To animate from attached to detached state:
// - fade out attached background
// - fade in detached background.
canvas->SaveLayerAlpha(attached_alpha);
PaintAttachedBookmarkBar(canvas,
bookmark_bar_view_,
browser_view_,
browser_->host_desktop_type(),
toolbar_overlap);
canvas->Restore();
canvas->SaveLayerAlpha(detached_alpha);
PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, ts);
} else {
// To animate from detached to attached state:
// - fade out detached background
// - fade in attached background.
canvas->SaveLayerAlpha(detached_alpha);
PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, ts);
canvas->Restore();
canvas->SaveLayerAlpha(attached_alpha);
PaintAttachedBookmarkBar(canvas,
bookmark_bar_view_,
browser_view_,
browser_->host_desktop_type(),
toolbar_overlap);
}
canvas->Restore();
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, public:
// static
const char BrowserView::kViewClassName[] = "BrowserView";
BrowserView::BrowserView()
: views::ClientView(nullptr, nullptr),
last_focused_view_storage_id_(
views::ViewStorage::GetInstance()->CreateStorageID()),
frame_(nullptr),
top_container_(nullptr),
tabstrip_(nullptr),
toolbar_(nullptr),
find_bar_host_view_(nullptr),
infobar_container_(nullptr),
contents_web_view_(nullptr),
contents_container_(nullptr),
initialized_(false),
in_process_fullscreen_(false),
#if defined(OS_WIN)
hung_window_detector_(&hung_plugin_action_),
ticker_(0),
#endif
force_location_bar_focus_(false),
activate_modal_dialog_factory_(this) {
}
BrowserView::~BrowserView() {
// All the tabs should have been destroyed already. If we were closed by the
// OS with some tabs than the NativeBrowserFrame should have destroyed them.
DCHECK_EQ(0, browser_->tab_strip_model()->count());
// Immersive mode may need to reparent views before they are removed/deleted.
immersive_mode_controller_.reset();
browser_->tab_strip_model()->RemoveObserver(this);
#if defined(OS_WIN)
// Stop hung plugin monitoring.
ticker_.Stop();
ticker_.UnregisterTickHandler(&hung_window_detector_);
// Terminate the jumplist (must be called before browser_->profile() is
// destroyed.
if (jumplist_.get()) {
jumplist_->Terminate();
}
#endif
// We destroy the download shelf before |browser_| to remove its child
// download views from the set of download observers (since the observed
// downloads can be destroyed along with |browser_| and the observer
// notifications will call back into deleted objects).
BrowserViewLayout* browser_view_layout = GetBrowserViewLayout();
if (browser_view_layout)
browser_view_layout->set_download_shelf(nullptr);
download_shelf_.reset();
// The TabStrip attaches a listener to the model. Make sure we shut down the
// TabStrip first so that it can cleanly remove the listener.
if (tabstrip_) {
tabstrip_->parent()->RemoveChildView(tabstrip_);
if (browser_view_layout)
browser_view_layout->set_tab_strip(nullptr);
delete tabstrip_;
tabstrip_ = nullptr;
}
// Child views maintain PrefMember attributes that point to
// OffTheRecordProfile's PrefService which gets deleted by ~Browser.
RemoveAllChildViews(true);
toolbar_ = nullptr;
// Explicitly set browser_ to null.
browser_.reset();
}
void BrowserView::Init(Browser* browser) {
browser_.reset(browser);
browser_->tab_strip_model()->AddObserver(this);
immersive_mode_controller_.reset(
chrome::CreateImmersiveModeController(browser_->host_desktop_type()));
}
// static
BrowserView* BrowserView::GetBrowserViewForNativeWindow(
gfx::NativeWindow window) {
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
return widget ?
reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty(
kBrowserViewKey)) : nullptr;
}
// static
BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) {
return static_cast<BrowserView*>(browser->window());
}
void BrowserView::InitStatusBubble() {
status_bubble_.reset(new StatusBubbleViews(contents_web_view_));
contents_web_view_->SetStatusBubble(status_bubble_.get());
}
void BrowserView::InitPermissionBubbleView() {
permission_bubble_view_.reset(new PermissionBubbleViewViews(
GetLocationBarView()->location_icon_view()));
}
gfx::Rect BrowserView::GetToolbarBounds() const {
gfx::Rect toolbar_bounds(toolbar_->bounds());
if (toolbar_bounds.IsEmpty())
return toolbar_bounds;
// The apparent toolbar edges are outside the "real" toolbar edges.
toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
return toolbar_bounds;
}
gfx::Rect BrowserView::GetFindBarBoundingBox() const {
return GetBrowserViewLayout()->GetFindBarBoundingBox();
}
int BrowserView::GetTabStripHeight() const {
// We want to return tabstrip_->height(), but we might be called in the midst
// of layout, when that hasn't yet been updated to reflect the current state.
// So return what the tabstrip height _ought_ to be right now.
return IsTabStripVisible() ? tabstrip_->GetPreferredSize().height() : 0;
}
gfx::Point BrowserView::OffsetPointForToolbarBackgroundImage(
const gfx::Point& point) const {
// The background image starts tiling horizontally at the window left edge and
// vertically at the top edge of the horizontal tab strip (or where it would
// be). We expect our parent's origin to be the window origin.
gfx::Point window_point(point + GetMirroredPosition().OffsetFromOrigin());
window_point.Offset(frame_->GetThemeBackgroundXInset(),
-frame_->GetTopInset());
return window_point;
}
bool BrowserView::IsTabStripVisible() const {
if (immersive_mode_controller_->ShouldHideTopViews() &&
immersive_mode_controller_->ShouldHideTabIndicators())
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
}
bool BrowserView::IsOffTheRecord() const {
return browser_->profile()->IsOffTheRecord();
}
bool BrowserView::IsGuestSession() const {
return browser_->profile()->IsGuestSession();
}
bool BrowserView::IsRegularOrGuestSession() const {
return profiles::IsRegularOrGuestSession(browser_.get());
}
bool BrowserView::ShouldShowAvatar() const {
#if defined(OS_CHROMEOS)
if (!browser_->is_type_tabbed() && !browser_->is_app())
return false;
// Don't show incognito avatar in the guest session.
if (IsOffTheRecord() && !IsGuestSession())
return true;
// This function is called via BrowserNonClientFrameView::UpdateAvatarInfo
// during the creation of the BrowserWindow, so browser->window() will not
// yet be set. In this case we can safely return false.
if (!browser_->window())
return false;
return chrome::MultiUserWindowManager::ShouldShowAvatar(
browser_->window()->GetNativeWindow());
#else
if (!IsBrowserTypeNormal())
return false;
if (IsOffTheRecord()) // Desktop guest is incognito and needs avatar.
return true;
// Tests may not have a profile manager.
if (!g_browser_process->profile_manager())
return false;
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) ==
std::string::npos) {
return false;
}
return AvatarMenu::ShouldShowAvatarMenu();
#endif
}
bool BrowserView::GetAccelerator(int cmd_id,
ui::Accelerator* accelerator) const {
// We retrieve the accelerator information for standard accelerators
// for cut, copy and paste.
if (chrome::GetStandardAcceleratorForCommandId(cmd_id, accelerator))
return true;
// Else, we retrieve the accelerator information from the accelerator table.
for (std::map<ui::Accelerator, int>::const_iterator it =
accelerator_table_.begin(); it != accelerator_table_.end(); ++it) {
if (it->second == cmd_id) {
*accelerator = it->first;
return true;
}
}
// Else, we retrieve the accelerator information from Ash (if applicable).
return chrome::GetAshAcceleratorForCommandId(
cmd_id, browser_->host_desktop_type(), accelerator);
}
bool BrowserView::IsAcceleratorRegistered(const ui::Accelerator& accelerator) {
return accelerator_table_.find(accelerator) != accelerator_table_.end();
}
WebContents* BrowserView::GetActiveWebContents() const {
return browser_->tab_strip_model()->GetActiveWebContents();
}
gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const {
return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, BrowserWindow implementation:
void BrowserView::Show() {
// If the window is already visible, just activate it.
if (frame_->IsVisible()) {
frame_->Activate();
return;
}
// Showing the window doesn't make the browser window active right away.
// This can cause SetFocusToLocationBar() to skip setting focus to the
// location bar. To avoid this we explicilty let SetFocusToLocationBar()
// know that it's ok to steal focus.
force_location_bar_focus_ = true;
// Setting the focus doesn't work when the window is invisible, so any focus
// initialization that happened before this will be lost.
//
// We really "should" restore the focus whenever the window becomes unhidden,
// but I think initializing is the only time where this can happen where
// there is some focus change we need to pick up, and this is easier than
// plumbing through an un-hide message all the way from the frame.
//
// If we do find there are cases where we need to restore the focus on show,
// that should be added and this should be removed.
RestoreFocus();
frame_->Show();
force_location_bar_focus_ = false;
browser()->OnWindowDidShow();
chrome::MaybeShowInvertBubbleView(this);
}
void BrowserView::ShowInactive() {
if (!frame_->IsVisible())
frame_->ShowInactive();
}
void BrowserView::Hide() {
// Not implemented.
}
void BrowserView::SetBounds(const gfx::Rect& bounds) {
ExitFullscreen();
GetWidget()->SetBounds(bounds);
}
void BrowserView::Close() {
frame_->Close();
}
void BrowserView::Activate() {
frame_->Activate();
}
void BrowserView::Deactivate() {
frame_->Deactivate();
}
bool BrowserView::IsActive() const {
return frame_->IsActive();
}
void BrowserView::FlashFrame(bool flash) {
frame_->FlashFrame(flash);
}
bool BrowserView::IsAlwaysOnTop() const {
return false;
}
void BrowserView::SetAlwaysOnTop(bool always_on_top) {
// Not implemented for browser windows.
NOTIMPLEMENTED();
}
gfx::NativeWindow BrowserView::GetNativeWindow() const {
// While the browser destruction is going on, the widget can already be gone,
// but utility functions like FindBrowserWithWindow will come here and crash.
// We short circuit therefore.
if (!GetWidget())
return nullptr;
return GetWidget()->GetTopLevelWidget()->GetNativeWindow();
}
StatusBubble* BrowserView::GetStatusBubble() {
return status_bubble_.get();
}
namespace {
// Only used by ToolbarSizeChanged() below, but placed here because template
// arguments (to base::AutoReset<>) must have external linkage.
enum CallState { NORMAL, REENTRANT, REENTRANT_FORCE_FAST_RESIZE };
}
void BrowserView::UpdateTitleBar() {
frame_->UpdateWindowTitle();
if (ShouldShowWindowIcon() && !loading_animation_timer_.IsRunning())
frame_->UpdateWindowIcon();
}
void BrowserView::BookmarkBarStateChanged(
BookmarkBar::AnimateChangeType change_type) {
if (bookmark_bar_view_.get()) {
BookmarkBar::State new_state = browser_->bookmark_bar_state();
// We don't properly support animating the bookmark bar to and from the
// detached state in immersive fullscreen.
bool detached_changed = (new_state == BookmarkBar::DETACHED) ||
bookmark_bar_view_->IsDetached();
if (detached_changed && immersive_mode_controller_->IsEnabled())
change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
bookmark_bar_view_->SetBookmarkBarState(new_state, change_type);
}
if (MaybeShowBookmarkBar(GetActiveWebContents()))
Layout();
}
void BrowserView::UpdateDevTools() {
UpdateDevToolsForContents(GetActiveWebContents(), true);
Layout();
}
void BrowserView::UpdateLoadingAnimations(bool should_animate) {
if (should_animate) {
if (!loading_animation_timer_.IsRunning()) {
// Loads are happening, and the timer isn't running, so start it.
last_animation_time_ = base::TimeTicks::Now();
loading_animation_timer_.Start(FROM_HERE,
TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
&BrowserView::LoadingAnimationCallback);
}
} else {
if (loading_animation_timer_.IsRunning()) {
last_animation_time_ = base::TimeTicks();
loading_animation_timer_.Stop();
// Loads are now complete, update the state if a task was scheduled.
LoadingAnimationCallback();
}
}
}
void BrowserView::SetStarredState(bool is_starred) {
GetLocationBarView()->SetStarToggled(is_starred);
}
void BrowserView::SetTranslateIconToggled(bool is_lit) {
GetLocationBarView()->SetTranslateIconToggled(is_lit);
}
void BrowserView::OnActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
DCHECK(new_contents);
// If |contents_container_| already has the correct WebContents, we can save
// some work. This also prevents extra events from being reported by the
// Visibility API under Windows, as ChangeWebContents will briefly hide
// the WebContents window.
bool change_tab_contents =
contents_web_view_->web_contents() != new_contents;
// Update various elements that are interested in knowing the current
// WebContents.
// When we toggle the NTP floating bookmarks bar and/or the info bar,
// we don't want any WebContents to be attached, so that we
// avoid an unnecessary resize and re-layout of a WebContents.
if (change_tab_contents) {
contents_web_view_->SetWebContents(nullptr);
devtools_web_view_->SetWebContents(nullptr);
}
// Do this before updating InfoBarContainer as the InfoBarContainer may
// callback to us and trigger layout.
if (bookmark_bar_view_.get()) {
bookmark_bar_view_->SetBookmarkBarState(
browser_->bookmark_bar_state(),
BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
}
infobar_container_->ChangeInfoBarManager(
InfoBarService::FromWebContents(new_contents));
if (old_contents && PermissionBubbleManager::FromWebContents(old_contents))
PermissionBubbleManager::FromWebContents(old_contents)->SetView(nullptr);
if (new_contents && PermissionBubbleManager::FromWebContents(new_contents)) {
PermissionBubbleManager::FromWebContents(new_contents)->SetView(
permission_bubble_view_.get());
}
UpdateUIForContents(new_contents);
// Layout for DevTools _before_ setting the both main and devtools WebContents
// to avoid toggling the size of any of them.
UpdateDevToolsForContents(new_contents, !change_tab_contents);
if (change_tab_contents) {
web_contents_close_handler_->ActiveTabChanged();
contents_web_view_->SetWebContents(new_contents);
// The second layout update should be no-op. It will just set the
// DevTools WebContents.
UpdateDevToolsForContents(new_contents, true);
}
if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
GetWidget()->IsVisible()) {
// We only restore focus if our window is visible, to avoid invoking blur
// handlers when we are eventually shown.
new_contents->RestoreFocus();
}
// Update all the UI bits.
UpdateTitleBar();
TranslateBubbleView::CloseBubble();
ZoomBubbleView::CloseBubble();
}
void BrowserView::ZoomChangedForActiveTab(bool can_show_bubble) {
GetLocationBarView()->ZoomChangedForActiveTab(
can_show_bubble && !toolbar_->IsWrenchMenuShowing());
}
gfx::Rect BrowserView::GetRestoredBounds() const {
gfx::Rect bounds;
ui::WindowShowState state;
frame_->GetWindowPlacement(&bounds, &state);
return bounds;
}
ui::WindowShowState BrowserView::GetRestoredState() const {
gfx::Rect bounds;
ui::WindowShowState state;
frame_->GetWindowPlacement(&bounds, &state);
return state;
}
gfx::Rect BrowserView::GetBounds() const {
return frame_->GetWindowBoundsInScreen();
}
bool BrowserView::IsMaximized() const {
return frame_->IsMaximized();
}
bool BrowserView::IsMinimized() const {
return frame_->IsMinimized();
}
void BrowserView::Maximize() {
frame_->Maximize();
}
void BrowserView::Minimize() {
frame_->Minimize();
}
void BrowserView::Restore() {
frame_->Restore();
}
void BrowserView::EnterFullscreen(const GURL& url,
ExclusiveAccessBubbleType bubble_type,
bool with_toolbar) {
if (IsFullscreen())
return; // Nothing to do.
ProcessFullscreen(true, NORMAL_FULLSCREEN, url, bubble_type);
}
void BrowserView::ExitFullscreen() {
if (!IsFullscreen())
return; // Nothing to do.
ProcessFullscreen(false, NORMAL_FULLSCREEN, GURL(),
EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
}
void BrowserView::UpdateFullscreenExitBubbleContent(
const GURL& url,
ExclusiveAccessBubbleType bubble_type) {
// Immersive mode has no exit bubble because it has a visible strip at the
// top that gives the user a hover target.
// TODO(jamescook): Figure out what to do with mouse-lock.
if (bubble_type == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE ||
ShouldUseImmersiveFullscreenForUrl(url)) {
exclusive_access_bubble_.reset();
} else if (exclusive_access_bubble_.get()) {
exclusive_access_bubble_->UpdateContent(url, bubble_type);
} else {
exclusive_access_bubble_.reset(
new ExclusiveAccessBubbleViews(this, url, bubble_type));
}
}
bool BrowserView::ShouldHideUIForFullscreen() const {
// Immersive mode needs UI for the slide-down top panel.
if (immersive_mode_controller_->IsEnabled())
return false;
return IsFullscreen();
}
bool BrowserView::IsFullscreen() const {
return frame_->IsFullscreen();
}
bool BrowserView::IsFullscreenBubbleVisible() const {
return exclusive_access_bubble_ != nullptr;
}
bool BrowserView::SupportsFullscreenWithToolbar() const {
return false;
}
void BrowserView::UpdateFullscreenWithToolbar(bool with_toolbar) {
// This is currently a Mac only feature.
NOTIMPLEMENTED();
}
bool BrowserView::IsFullscreenWithToolbar() const {
return false;
}
#if defined(OS_WIN)
void BrowserView::SetMetroSnapMode(bool enable) {
LOCAL_HISTOGRAM_COUNTS("Metro.SnapModeToggle", enable);
ProcessFullscreen(enable, METRO_SNAP_FULLSCREEN, GURL(),
EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
}
bool BrowserView::IsInMetroSnapMode() const {
return false;
}
#endif // defined(OS_WIN)
void BrowserView::RestoreFocus() {
WebContents* selected_web_contents = GetActiveWebContents();
if (selected_web_contents)
selected_web_contents->RestoreFocus();
}
void BrowserView::FullscreenStateChanged() {
CHECK(!IsFullscreen());
ProcessFullscreen(false, NORMAL_FULLSCREEN, GURL(),
EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
}
void BrowserView::ToolbarSizeChanged(bool is_animating) {
// The call to SetMaxTopArrowHeight() below can result in reentrancy;
// |call_state| tracks whether we're reentrant. We can't just early-return in
// this case because we need to layout again so the infobar container's bounds
// are set correctly.
static CallState call_state = NORMAL;
// A reentrant call can (and should) use the fast resize path unless both it
// and the normal call are both non-animating.
bool use_fast_resize =
is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE);
if (use_fast_resize)
contents_web_view_->SetFastResize(true);
UpdateUIForContents(GetActiveWebContents());
if (use_fast_resize)
contents_web_view_->SetFastResize(false);
// Inform the InfoBarContainer that the distance to the location icon may have
// changed. We have to do this after the block above so that the toolbars are
// laid out correctly for calculating the maximum arrow height below.
{
base::AutoReset<CallState> resetter(&call_state,
is_animating ? REENTRANT_FORCE_FAST_RESIZE : REENTRANT);
SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_);
}
// When transitioning from animating to not animating we need to make sure the
// contents_container_ gets layed out. If we don't do this and the bounds
// haven't changed contents_container_ won't get a Layout out and we'll end up
// with a gray rect because the clip wasn't updated. Note that a reentrant
// call never needs to do this, because after it returns, the normal call
// wrapping it will do it.
if ((call_state == NORMAL) && !is_animating) {
contents_web_view_->InvalidateLayout();
contents_container_->Layout();
}
}
LocationBar* BrowserView::GetLocationBar() const {
return GetLocationBarView();
}
void BrowserView::SetFocusToLocationBar(bool select_all) {
// On Windows, changing focus to the location bar causes the browser
// window to become active. This can steal focus if the user has
// another window open already. On ChromeOS, changing focus makes a
// view believe it has a focus even if the widget doens't have a
// focus. Either cases, we need to ignore this when the browser
// window isn't active.
if (!force_location_bar_focus_ && !IsActive())
return;
// Temporarily reveal the top-of-window views (if not already revealed) so
// that the location bar view is visible and is considered focusable. If the
// location bar view gains focus, |immersive_mode_controller_| will keep the
// top-of-window views revealed.
scoped_ptr<ImmersiveRevealedLock> focus_reveal_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_YES));
LocationBarView* location_bar = GetLocationBarView();
if (location_bar->omnibox_view()->IsFocusable()) {
// Location bar got focus.
//
// select_all is true when it's expected that the user may want to copy
// the URL to the clipboard. If the URL is not being shown because the
// origin chip is enabled, show it now to support the same functionality.
if (select_all &&
location_bar->GetToolbarModel()->WouldOmitURLDueToOriginChip())
location_bar->ShowURL();
else
location_bar->FocusLocation(select_all);
} else {
// If none of location bar got focus, then clear focus.
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
focus_manager->ClearFocus();
}
}
void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
toolbar_->reload_button()->ChangeMode(
is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force);
}
void BrowserView::UpdateToolbar(content::WebContents* contents) {
// We may end up here during destruction.
if (toolbar_)
toolbar_->Update(contents);
frame_->UpdateToolbar();
}
void BrowserView::ResetToolbarTabState(content::WebContents* contents) {
// We may end up here during destruction.
if (toolbar_)
toolbar_->ResetTabState(contents);
}
void BrowserView::FocusToolbar() {
// Temporarily reveal the top-of-window views (if not already revealed) so
// that the toolbar is visible and is considered focusable. If the
// toolbar gains focus, |immersive_mode_controller_| will keep the
// top-of-window views revealed.
scoped_ptr<ImmersiveRevealedLock> focus_reveal_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_YES));
// Start the traversal within the main toolbar. SetPaneFocus stores
// the current focused view before changing focus.
toolbar_->SetPaneFocus(nullptr);
}
void BrowserView::FocusBookmarksToolbar() {
DCHECK(!immersive_mode_controller_->IsEnabled());
if (bookmark_bar_view_.get() &&
bookmark_bar_view_->visible() &&
bookmark_bar_view_->GetPreferredSize().height() != 0) {
bookmark_bar_view_->SetPaneFocusAndFocusDefault();
}
}
void BrowserView::FocusInfobars() {
if (infobar_container_->child_count() > 0)
infobar_container_->SetPaneFocusAndFocusDefault();
}
void BrowserView::FocusAppMenu() {
// Chrome doesn't have a traditional menu bar, but it has a menu button in the
// main toolbar that plays the same role. If the user presses a key that
// would typically focus the menu bar, tell the toolbar to focus the menu
// button. If the user presses the key again, return focus to the previous
// location.
//
// Not used on the Mac, which has a normal menu bar.
if (toolbar_->IsAppMenuFocused()) {
RestoreFocus();
} else {
DCHECK(!immersive_mode_controller_->IsEnabled());
toolbar_->SetPaneFocusAndFocusAppMenu();
}
}
void BrowserView::RotatePaneFocus(bool forwards) {
GetWidget()->GetFocusManager()->RotatePaneFocus(
forwards ?
views::FocusManager::kForward : views::FocusManager::kBackward,
views::FocusManager::kWrap);
}
void BrowserView::DestroyBrowser() {
// After this returns other parts of Chrome are going to be shutdown. Close
// the window now so that we are deleted immediately and aren't left holding
// references to deleted objects.
GetWidget()->RemoveObserver(this);
GetLocationBar()->GetOmniboxView()->model()->popup_model()->RemoveObserver(
this);
frame_->CloseNow();
}
bool BrowserView::IsBookmarkBarVisible() const {
if (!browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR))
return false;
if (!bookmark_bar_view_.get())
return false;
if (bookmark_bar_view_->GetPreferredSize().height() == 0)
return false;
// New tab page needs visible bookmarks even when top-views are hidden.
if (immersive_mode_controller_->ShouldHideTopViews() &&
!bookmark_bar_view_->IsDetached())
return false;
return true;
}
bool BrowserView::IsBookmarkBarAnimating() const {
return bookmark_bar_view_.get() && bookmark_bar_view_->is_animating();
}
bool BrowserView::IsTabStripEditable() const {
return tabstrip_->IsTabStripEditable();
}
bool BrowserView::IsToolbarVisible() const {
if (immersive_mode_controller_->ShouldHideTopViews())
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
}
gfx::Rect BrowserView::GetRootWindowResizerRect() const {
// Views does not support resizer rects because they caused page cycler
// performance regressions when they were added. See crrev.com/9654
return gfx::Rect();
}
void BrowserView::ConfirmAddSearchProvider(TemplateURL* template_url,
Profile* profile) {
chrome::EditSearchEngine(GetWidget()->GetNativeWindow(), template_url,
nullptr, profile);
}
void BrowserView::ShowUpdateChromeDialog() {
UpdateRecommendedMessageBox::Show(GetWidget()->GetNativeWindow());
}
void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
scoped_ptr<BookmarkBubbleDelegate> delegate;
delegate.reset(new BookmarkBubbleSignInDelegate(browser_.get()));
BookmarkBubbleView::ShowBubble(GetToolbarView()->GetBookmarkBubbleAnchor(),
bookmark_bar_view_.get(),
delegate.Pass(),
browser_->profile(),
url,
!already_bookmarked);
}
void BrowserView::ShowBookmarkAppBubble(
const WebApplicationInfo& web_app_info,
const std::string& extension_id) {
BookmarkAppBubbleView::ShowBubble(GetToolbarView(),
browser_->profile(),
web_app_info,
extension_id);
}
void BrowserView::ShowTranslateBubble(
content::WebContents* web_contents,
translate::TranslateStep step,
translate::TranslateErrors::Type error_type,
bool is_user_gesture) {
if (contents_web_view_->HasFocus() &&
!GetLocationBarView()->IsMouseHovered()) {
content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
if (rvh->IsFocusedElementEditable())
return;
}
ChromeTranslateClient* chrome_translate_client =
ChromeTranslateClient::FromWebContents(web_contents);
translate::LanguageState& language_state =
chrome_translate_client->GetLanguageState();
language_state.SetTranslateEnabled(true);
if (IsMinimized())
return;
TranslateBubbleView::ShowBubble(
GetToolbarView()->GetTranslateBubbleAnchor(), web_contents, step,
error_type, is_user_gesture);
}
bool BrowserView::ShowSessionCrashedBubble() {
return SessionCrashedBubbleView::Show(browser_.get());
}
bool BrowserView::IsProfileResetBubbleSupported() const {
return true;
}
GlobalErrorBubbleViewBase* BrowserView::ShowProfileResetBubble(
const base::WeakPtr<ProfileResetGlobalError>& global_error) {
return ProfileResetBubbleView::ShowBubble(global_error, browser_.get());
}
#if defined(ENABLE_ONE_CLICK_SIGNIN)
void BrowserView::ShowOneClickSigninBubble(
OneClickSigninBubbleType type,
const base::string16& email,
const base::string16& error_message,
const StartSyncCallback& start_sync_callback) {
scoped_ptr<OneClickSigninBubbleDelegate> delegate;
delegate.reset(new OneClickSigninBubbleLinksDelegate(browser()));
views::View* anchor_view;
if (type == BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE)
anchor_view = toolbar_->app_menu();
else
anchor_view = toolbar_->location_bar();
OneClickSigninBubbleView::ShowBubble(type, email, error_message,
delegate.Pass(), anchor_view,
start_sync_callback);
}
#endif
void BrowserView::SetDownloadShelfVisible(bool visible) {
// This can be called from the superclass destructor, when it destroys our
// child views. At that point, browser_ is already gone.
if (!browser_)
return;
if (visible && IsDownloadShelfVisible() != visible) {
// Invoke GetDownloadShelf to force the shelf to be created.
GetDownloadShelf();
}
browser_->UpdateDownloadShelfVisibility(visible);
// SetDownloadShelfVisible can force-close the shelf, so make sure we lay out
// everything correctly, as if the animation had finished. This doesn't
// matter for showing the shelf, as the show animation will do it.
ToolbarSizeChanged(false);
}
bool BrowserView::IsDownloadShelfVisible() const {
return download_shelf_.get() && download_shelf_->IsShowing();
}
DownloadShelf* BrowserView::GetDownloadShelf() {
if (!download_shelf_.get()) {
download_shelf_.reset(new DownloadShelfView(browser_.get(), this));
download_shelf_->set_owned_by_client();
GetBrowserViewLayout()->set_download_shelf(download_shelf_.get());
}
return download_shelf_.get();
}
void BrowserView::ConfirmBrowserCloseWithPendingDownloads(
int download_count,
Browser::DownloadClosePreventionType dialog_type,
bool app_modal,
const base::Callback<void(bool)>& callback) {
DownloadInProgressDialogView::Show(
GetNativeWindow(), download_count, dialog_type, app_modal, callback);
}
void BrowserView::UserChangedTheme() {
frame_->FrameTypeChanged();
}
int BrowserView::GetExtraRenderViewHeight() const {
// Currently this is only used on linux.
return 0;
}
void BrowserView::WebContentsFocused(WebContents* contents) {
if (contents_web_view_->GetWebContents() == contents)
contents_web_view_->OnWebContentsFocused(contents);
else
devtools_web_view_->OnWebContentsFocused(contents);
}
void BrowserView::ShowWebsiteSettings(Profile* profile,
content::WebContents* web_contents,
const GURL& url,
const content::SSLStatus& ssl) {
// Some browser windows have a location icon embedded in the frame. Try to
// use that if it exists. If it doesn't exist, use the location icon from
// the location bar.
views::View* popup_anchor = frame_->GetLocationIconView();
if (!popup_anchor)
popup_anchor = GetLocationBarView()->location_icon_view();
WebsiteSettingsPopupView::ShowPopup(popup_anchor, profile, web_contents, url,
ssl, browser_.get());
}
void BrowserView::ShowAppMenu() {
// Keep the top-of-window views revealed as long as the app menu is visible.
scoped_ptr<ImmersiveRevealedLock> revealed_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO));
toolbar_->app_menu()->Activate();
}
bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
*is_keyboard_shortcut = false;
if ((event.type != blink::WebInputEvent::RawKeyDown) &&
(event.type != blink::WebInputEvent::KeyUp)) {
return false;
}
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
if (focus_manager->shortcut_handling_suspended())
return false;
ui::Accelerator accelerator =
ui::GetAcceleratorFromNativeWebKeyboardEvent(event);
// What we have to do here is as follows:
// - If the |browser_| is for an app, do nothing.
// - If the |browser_| is not for an app, and the |accelerator| is not
// associated with the browser (e.g. an Ash shortcut), process it.
// - If the |browser_| is not for an app, and the |accelerator| is associated
// with the browser, and it is a reserved one (e.g. Ctrl+w), process it.
// - If the |browser_| is not for an app, and the |accelerator| is associated
// with the browser, and it is not a reserved one, do nothing.
if (browser_->is_app()) {
// Let all keys fall through to a v1 app's web content, even accelerators.
// We don't have to flip |is_keyboard_shortcut| here. If we do that, the app
// might not be able to see a subsequent Char event. See OnHandleInputEvent
// in content/renderer/render_widget.cc for details.
return false;
}
chrome::BrowserCommandController* controller = browser_->command_controller();
// Here we need to retrieve the command id (if any) associated to the
// keyboard event. Instead of looking up the command id in the
// |accelerator_table_| by ourselves, we block the command execution of
// the |browser_| object then send the keyboard event to the
// |focus_manager| as if we are activating an accelerator key.
// Then we can retrieve the command id from the |browser_| object.
bool original_block_command_state = controller->block_command_execution();
controller->SetBlockCommandExecution(true);
// If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the
// command execution cannot be blocked and true is returned. However, it is
// okay as long as is_app() is false. See comments in this function.
const bool processed = focus_manager->ProcessAccelerator(accelerator);
const int id = controller->GetLastBlockedCommand(nullptr);
controller->SetBlockCommandExecution(original_block_command_state);
// Executing the command may cause |this| object to be destroyed.
if (controller->IsReservedCommandOrKey(id, event)) {
UpdateAcceleratorMetrics(accelerator, id);
return chrome::ExecuteCommand(browser_.get(), id);
}
if (id != -1) {
// |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+f).
if (event.type == blink::WebInputEvent::RawKeyDown)
*is_keyboard_shortcut = true;
} else if (processed) {
// |accelerator| is a non-browser shortcut (e.g. F4-F10 on Ash). Report
// that we handled it.
return true;
}
return false;
}
void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
GetFocusManager());
}
// TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always
// enabled in the page menu regardless of whether the command will do
// anything. When someone selects the menu item, we just act as if they hit
// the keyboard shortcut for the command by sending the associated key press
// to windows. The real fix to this bug is to disable the commands when they
// won't do anything. We'll need something like an overall clipboard command
// manager to do that.
void BrowserView::Cut() {
// If a WebContent is focused, call WebContents::Cut. Otherwise, e.g. if
// Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface
// rather than the fake key event for a WebContent is important since the fake
// event might be consumed by the web content (crbug.com/137908).
DoCutCopyPaste(&content::WebContents::Cut, IDS_APP_CUT);
}
void BrowserView::Copy() {
DoCutCopyPaste(&content::WebContents::Copy, IDS_APP_COPY);
}
void BrowserView::Paste() {
DoCutCopyPaste(&content::WebContents::Paste, IDS_APP_PASTE);
}
WindowOpenDisposition BrowserView::GetDispositionForPopupBounds(
const gfx::Rect& bounds) {
return NEW_POPUP;
}
FindBar* BrowserView::CreateFindBar() {
return chrome::CreateFindBar(this);
}
WebContentsModalDialogHost* BrowserView::GetWebContentsModalDialogHost() {
return GetBrowserViewLayout()->GetWebContentsModalDialogHost();
}
BookmarkBarView* BrowserView::GetBookmarkBarView() const {
return bookmark_bar_view_.get();
}
LocationBarView* BrowserView::GetLocationBarView() const {
return toolbar_ ? toolbar_->location_bar() : nullptr;
}
views::View* BrowserView::GetTabContentsContainerView() const {
return contents_web_view_;
}
ToolbarView* BrowserView::GetToolbarView() const {
return toolbar_;
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, TabStripModelObserver implementation:
void BrowserView::TabInsertedAt(WebContents* contents,
int index,
bool foreground) {
#if defined(USE_AURA)
// WebContents inserted in tabs might not have been added to the root
// window yet. Per http://crbug/342672 add them now since drawing the
// WebContents requires root window specific data - information about
// the screen the WebContents is drawn on, for example.
if (!contents->GetNativeView()->GetRootWindow()) {
aura::Window* window = contents->GetNativeView();
aura::Window* root_window = GetNativeWindow()->GetRootWindow();
aura::client::ParentWindowWithContext(
window, root_window, root_window->GetBoundsInScreen());
DCHECK(contents->GetNativeView()->GetRootWindow());
}
#endif
web_contents_close_handler_->TabInserted();
if (foreground)
extensions::MaybeShowExtensionControlledNewTabPage(browser(), contents);
}
void BrowserView::TabDetachedAt(WebContents* contents, int index) {
if (PermissionBubbleManager::FromWebContents(contents))
PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr);
// We use index here rather than comparing |contents| because by this time
// the model has already removed |contents| from its list, so
// browser_->GetActiveWebContents() will return null or something else.
if (index == browser_->tab_strip_model()->active_index()) {
// We need to reset the current tab contents to null before it gets
// freed. This is because the focus manager performs some operations
// on the selected WebContents when it is removed.
web_contents_close_handler_->ActiveTabChanged();
contents_web_view_->SetWebContents(nullptr);
infobar_container_->ChangeInfoBarManager(nullptr);
UpdateDevToolsForContents(nullptr, true);
}
}
void BrowserView::TabDeactivated(WebContents* contents) {
if (PermissionBubbleManager::FromWebContents(contents))
PermissionBubbleManager::FromWebContents(contents)->SetView(nullptr);
// We do not store the focus when closing the tab to work-around bug 4633.
// Some reports seem to show that the focus manager and/or focused view can
// be garbage at that point, it is not clear why.
if (!contents->IsBeingDestroyed())
contents->StoreFocus();
}
void BrowserView::TabStripEmpty() {
// Make sure all optional UI is removed before we are destroyed, otherwise
// there will be consequences (since our view hierarchy will still have
// references to freed views).
UpdateUIForContents(nullptr);
}
void BrowserView::WillCloseAllTabs() {
web_contents_close_handler_->WillCloseAllTabs();
}
void BrowserView::CloseAllTabsCanceled() {
web_contents_close_handler_->CloseAllTabsCanceled();
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, ui::AcceleratorProvider implementation:
bool BrowserView::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
// Let's let the ToolbarView own the canonical implementation of this method.
return toolbar_->GetAcceleratorForCommandId(command_id, accelerator);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, views::WidgetDelegate implementation:
bool BrowserView::CanResize() const {
return true;
}
bool BrowserView::CanMaximize() const {
return true;
}
bool BrowserView::CanMinimize() const {
return true;
}
bool BrowserView::CanActivate() const {
app_modal::AppModalDialogQueue* queue =
app_modal::AppModalDialogQueue::GetInstance();
if (!queue->active_dialog() || !queue->active_dialog()->native_dialog() ||
!queue->active_dialog()->native_dialog()->IsShowing()) {
return true;
}
#if defined(USE_AURA) && defined(OS_CHROMEOS)
// On Aura window manager controls all windows so settings focus via PostTask
// will make only worse because posted task will keep trying to steal focus.
queue->ActivateModalDialog();
#else
// If another browser is app modal, flash and activate the modal browser. This
// has to be done in a post task, otherwise if the user clicked on a window
// that doesn't have the modal dialog the windows keep trying to get the focus
// from each other on Windows. http://crbug.com/141650.
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&BrowserView::ActivateAppModalDialog,
activate_modal_dialog_factory_.GetWeakPtr()));
#endif
return false;
}
base::string16 BrowserView::GetWindowTitle() const {
return browser_->GetWindowTitleForCurrentTab();
}
base::string16 BrowserView::GetAccessibleWindowTitle() const {
if (IsOffTheRecord()) {
return l10n_util::GetStringFUTF16(
IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT,
GetWindowTitle());
}
return GetWindowTitle();
}
views::View* BrowserView::GetInitiallyFocusedView() {
return nullptr;
}
bool BrowserView::ShouldShowWindowTitle() const {
// For Ash only, trusted windows (apps and settings) do not show a title,
// crbug.com/119411. Child windows (i.e. popups) do show a title.
if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH &&
browser_->is_trusted_source() &&
!browser_->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME))
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
gfx::ImageSkia BrowserView::GetWindowAppIcon() {
if (browser_->is_app()) {
WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
extensions::TabHelper* extensions_tab_helper =
contents ? extensions::TabHelper::FromWebContents(contents) : nullptr;
if (extensions_tab_helper && extensions_tab_helper->GetExtensionAppIcon())
return gfx::ImageSkia::CreateFrom1xBitmap(
*extensions_tab_helper->GetExtensionAppIcon());
}
return GetWindowIcon();
}
gfx::ImageSkia BrowserView::GetWindowIcon() {
if (browser_->is_app() || browser_->is_type_popup())
return browser_->GetCurrentPageIcon().AsImageSkia();
return gfx::ImageSkia();
}
bool BrowserView::ShouldShowWindowIcon() const {
// For Ash only, trusted windows (apps and settings) do not show an icon,
// crbug.com/119411. Child windows (i.e. popups) do show an icon.
if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH &&
browser_->is_trusted_source() &&
!browser_->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME))
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
bool BrowserView::ExecuteWindowsCommand(int command_id) {
// This function handles WM_SYSCOMMAND, WM_APPCOMMAND, and WM_COMMAND.
#if defined(OS_WIN)
if (command_id == IDC_DEBUG_FRAME_TOGGLE)
GetWidget()->DebugToggleFrameType();
#endif
// Translate WM_APPCOMMAND command ids into a command id that the browser
// knows how to handle.
int command_id_from_app_command = GetCommandIDForAppCommandID(command_id);
if (command_id_from_app_command != -1)
command_id = command_id_from_app_command;
return chrome::ExecuteCommand(browser_.get(), command_id);
}
std::string BrowserView::GetWindowName() const {
return chrome::GetWindowName(browser_.get());
}
void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
ui::WindowShowState show_state) {
// If IsFullscreen() is true, we've just changed into fullscreen mode, and
// we're catching the going-into-fullscreen sizing and positioning calls,
// which we want to ignore.
if (!IsFullscreen() && frame_->ShouldSaveWindowPlacement() &&
chrome::ShouldSaveWindowPlacement(browser_.get())) {
WidgetDelegate::SaveWindowPlacement(bounds, show_state);
chrome::SaveWindowPlacement(browser_.get(), bounds, show_state);
}
}
bool BrowserView::GetSavedWindowPlacement(
const views::Widget* widget,
gfx::Rect* bounds,
ui::WindowShowState* show_state) const {
chrome::GetSavedWindowBoundsAndShowState(browser_.get(), bounds, show_state);
if (browser_->is_type_popup() &&
!browser_->is_app() &&
!browser_->is_trusted_source()) {
// This is normal non-app popup window. The value passed in |bounds|
// represents two pieces of information:
// - the position of the window, in screen coordinates (outer position).
// - the size of the content area (inner size).
// We need to use these values to determine the appropriate size and
// position of the resulting window.
if (IsToolbarVisible()) {
// If we're showing the toolbar, we need to adjust |*bounds| to include
// its desired height, since the toolbar is considered part of the
// window's client area as far as GetWindowBoundsForClientBounds is
// concerned...
bounds->set_height(
bounds->height() + toolbar_->GetPreferredSize().height());
}
gfx::Rect window_rect = frame_->non_client_view()->
GetWindowBoundsForClientBounds(*bounds);
window_rect.set_origin(bounds->origin());
// When we are given x/y coordinates of 0 on a created popup window,
// assume none were given by the window.open() command.
if (window_rect.x() == 0 && window_rect.y() == 0) {
gfx::Size size = window_rect.size();
window_rect.set_origin(
WindowSizer::GetDefaultPopupOrigin(size,
browser_->host_desktop_type()));
}
*bounds = window_rect;
*show_state = ui::SHOW_STATE_NORMAL;
}
// We return true because we can _always_ locate reasonable bounds using the
// WindowSizer, and we don't want to trigger the Window's built-in "size to
// default" handling because the browser window has no default preferred
// size.
return true;
}
views::View* BrowserView::GetContentsView() {
return contents_web_view_;
}
views::ClientView* BrowserView::CreateClientView(views::Widget* widget) {
return this;
}
void BrowserView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (active)
BrowserList::SetLastActive(browser_.get());
}
void BrowserView::OnWindowBeginUserBoundsChange() {
WebContents* web_contents = GetActiveWebContents();
if (!web_contents)
return;
web_contents->GetRenderViewHost()->NotifyMoveOrResizeStarted();
}
void BrowserView::OnWidgetMove() {
if (!initialized_) {
// Creating the widget can trigger a move. Ignore it until we've initialized
// things.
return;
}
// Cancel any tabstrip animations, some of them may be invalidated by the
// window being repositioned.
// Comment out for one cycle to see if this fixes dist tests.
// tabstrip_->DestroyDragController();
// status_bubble_ may be null if this is invoked during construction.
if (status_bubble_.get())
status_bubble_->Reposition();
BookmarkBubbleView::Hide();
// Close the omnibox popup, if any.
LocationBarView* location_bar_view = GetLocationBarView();
if (location_bar_view)
location_bar_view->GetOmniboxView()->CloseOmniboxPopup();
}
views::Widget* BrowserView::GetWidget() {
return View::GetWidget();
}
const views::Widget* BrowserView::GetWidget() const {
return View::GetWidget();
}
void BrowserView::GetAccessiblePanes(std::vector<views::View*>* panes) {
// This should be in the order of pane traversal of the panes using F6
// (Windows) or Ctrl+Back/Forward (Chrome OS). If one of these is
// invisible or has no focusable children, it will be automatically
// skipped.
panes->push_back(toolbar_);
if (bookmark_bar_view_.get())
panes->push_back(bookmark_bar_view_.get());
if (infobar_container_)
panes->push_back(infobar_container_);
if (download_shelf_.get())
panes->push_back(download_shelf_.get());
panes->push_back(GetTabContentsContainerView());
if (devtools_web_view_->visible())
panes->push_back(devtools_web_view_);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, views::ClientView overrides:
bool BrowserView::CanClose() {
// You cannot close a frame for which there is an active originating drag
// session.
if (tabstrip_ && !tabstrip_->IsTabStripCloseable())
return false;
// Give beforeunload handlers the chance to cancel the close before we hide
// the window below.
if (!browser_->ShouldCloseWindow())
return false;
bool fast_tab_closing_enabled =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableFastUnload);
if (!browser_->tab_strip_model()->empty()) {
// Tab strip isn't empty. Hide the frame (so it appears to have closed
// immediately) and close all the tabs, allowing the renderers to shut
// down. When the tab strip is empty we'll be called back again.
frame_->Hide();
browser_->OnWindowClosing();
if (fast_tab_closing_enabled)
browser_->tab_strip_model()->CloseAllTabs();
return false;
} else if (fast_tab_closing_enabled &&
!browser_->HasCompletedUnloadProcessing()) {
// The browser needs to finish running unload handlers.
// Hide the frame (so it appears to have closed immediately), and
// the browser will call us back again when it is ready to close.
frame_->Hide();
return false;
}
// Empty TabStripModel, it's now safe to allow the Window to be closed.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WINDOW_CLOSED,
content::Source<gfx::NativeWindow>(frame_->GetNativeWindow()),
content::NotificationService::NoDetails());
return true;
}
int BrowserView::NonClientHitTest(const gfx::Point& point) {
return GetBrowserViewLayout()->NonClientHitTest(point);
}
gfx::Size BrowserView::GetMinimumSize() const {
return GetBrowserViewLayout()->GetMinimumSize();
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, views::View overrides:
const char* BrowserView::GetClassName() const {
return kViewClassName;
}
void BrowserView::Layout() {
if (!initialized_ || in_process_fullscreen_)
return;
views::View::Layout();
// TODO(jamescook): Why was this in the middle of layout code?
toolbar_->location_bar()->omnibox_view()->SetFocusable(IsToolbarVisible());
}
void BrowserView::PaintChildren(gfx::Canvas* canvas,
const views::CullSet& cull_set) {
// Paint the |infobar_container_| last so that it may paint its
// overlapping tabs.
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
if (child != infobar_container_ && !child->layer())
child->Paint(canvas, cull_set);
}
infobar_container_->Paint(canvas, cull_set);
}
void BrowserView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
if (!initialized_ && details.is_add && details.child == this && GetWidget()) {
InitViews();
initialized_ = true;
}
}
void BrowserView::ChildPreferredSizeChanged(View* child) {
Layout();
}
void BrowserView::GetAccessibleState(ui::AXViewState* state) {
state->role = ui::AX_ROLE_CLIENT;
}
void BrowserView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
// Do not handle native theme changes before the browser view is initialized.
if (!initialized_)
return;
ClientView::OnNativeThemeChanged(theme);
UserChangedTheme();
chrome::MaybeShowInvertBubbleView(this);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, ui::AcceleratorTarget overrides:
bool BrowserView::AcceleratorPressed(const ui::Accelerator& accelerator) {
#if defined(OS_CHROMEOS)
// If accessibility is enabled, stop speech and return false so that key
// combinations involving Search can be used for extra accessibility
// functionality.
if (accelerator.key_code() == ui::VKEY_LWIN &&
g_browser_process->local_state()->GetBoolean(
prefs::kAccessibilitySpokenFeedbackEnabled)) {
TtsController::GetInstance()->Stop();
return false;
}
#endif
std::map<ui::Accelerator, int>::const_iterator iter =
accelerator_table_.find(accelerator);
DCHECK(iter != accelerator_table_.end());
int command_id = iter->second;
chrome::BrowserCommandController* controller = browser_->command_controller();
if (!controller->block_command_execution())
UpdateAcceleratorMetrics(accelerator, command_id);
return chrome::ExecuteCommand(browser_.get(), command_id);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, OmniboxPopupModelObserver overrides:
void BrowserView::OnOmniboxPopupShownOrHidden() {
SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_);
}
///////////////////////////////////////////////////////////////////////////////
// BrowserView, InfoBarContainerDelegate overrides:
SkColor BrowserView::GetInfoBarSeparatorColor() const {
// NOTE: Keep this in sync with ToolbarView::OnPaint()!
return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ?
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR) :
SK_ColorBLACK;
}
void BrowserView::InfoBarContainerStateChanged(bool is_animating) {
ToolbarSizeChanged(is_animating);
}
bool BrowserView::DrawInfoBarArrows(int* x) const {
if (x) {
gfx::Point anchor(toolbar_->location_bar()->GetLocationBarAnchorPoint());
ConvertPointToTarget(toolbar_->location_bar(), this, &anchor);
*x = anchor.x();
}
return true;
}
void BrowserView::InitViews() {
GetWidget()->AddObserver(this);
// Stow a pointer to this object onto the window handle so that we can get at
// it later when all we have is a native view.
GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this);
// Stow a pointer to the browser's profile onto the window handle so that we
// can get it later when all we have is a native view.
GetWidget()->SetNativeWindowProperty(Profile::kProfileKey,
browser_->profile());
// Start a hung plugin window detector for this browser object (as long as
// hang detection is not disabled).
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableHangMonitor)) {
InitHangMonitor();
}
LoadAccelerators();
infobar_container_ = new InfoBarContainerView(this);
AddChildView(infobar_container_);
contents_web_view_ = new ContentsWebView(browser_->profile());
contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER);
contents_web_view_->SetEmbedFullscreenWidgetMode(true);
web_contents_close_handler_.reset(
new WebContentsCloseHandler(contents_web_view_));
devtools_web_view_ = new views::WebView(browser_->profile());
devtools_web_view_->set_id(VIEW_ID_DEV_TOOLS_DOCKED);
devtools_web_view_->SetVisible(false);
contents_container_ = new views::View();
contents_container_->set_background(views::Background::CreateSolidBackground(
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_CONTROL_BACKGROUND)));
contents_container_->AddChildView(devtools_web_view_);
contents_container_->AddChildView(contents_web_view_);
contents_container_->SetLayoutManager(new ContentsLayoutManager(
devtools_web_view_, contents_web_view_));
AddChildView(contents_container_);
set_contents_view(contents_container_);
// Top container holds tab strip and toolbar and lives at the front of the
// view hierarchy.
top_container_ = new TopContainerView(this);
AddChildView(top_container_);
// TabStrip takes ownership of the controller.
BrowserTabStripController* tabstrip_controller =
new BrowserTabStripController(browser_.get(),
browser_->tab_strip_model());
tabstrip_ = new TabStrip(tabstrip_controller);
top_container_->AddChildView(tabstrip_);
tabstrip_controller->InitFromModel(tabstrip_);
toolbar_ = new ToolbarView(browser_.get());
top_container_->AddChildView(toolbar_);
toolbar_->Init();
InitStatusBubble();
InitPermissionBubbleView();
// Create do-nothing view for the sake of controlling the z-order of the find
// bar widget.
find_bar_host_view_ = new View();
AddChildView(find_bar_host_view_);
immersive_mode_controller_->Init(this);
BrowserViewLayout* browser_view_layout = new BrowserViewLayout;
browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this),
browser(),
this,
top_container_,
tabstrip_,
toolbar_,
infobar_container_,
contents_container_,
GetContentsLayoutManager(),
immersive_mode_controller_.get());
SetLayoutManager(browser_view_layout);
#if defined(OS_WIN)
// Create a custom JumpList and add it to an observer of TabRestoreService
// so we can update the custom JumpList when a tab is added or removed.
if (JumpList::Enabled()) {
load_complete_listener_.reset(new LoadCompleteListener(this));
}
#endif
GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this);
}
void BrowserView::LoadingAnimationCallback() {
base::TimeTicks now = base::TimeTicks::Now();
if (!last_animation_time_.is_null()) {
UMA_HISTOGRAM_TIMES(
"Tabs.LoadingAnimationTime",
now - last_animation_time_);
}
last_animation_time_ = now;
if (browser_->is_type_tabbed()) {
// Loading animations are shown in the tab for tabbed windows. We check the
// browser type instead of calling IsTabStripVisible() because the latter
// will return false for fullscreen windows, but we still need to update
// their animations (so that when they come out of fullscreen mode they'll
// be correct).
tabstrip_->UpdateLoadingAnimations();
} else if (ShouldShowWindowIcon()) {
// ... or in the window icon area for popups and app windows.
WebContents* web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
// GetActiveWebContents can return null for example under Purify when
// the animations are running slowly and this function is called on a timer
// through LoadingAnimationCallback.
frame_->UpdateThrobber(web_contents && web_contents->IsLoading());
}
}
void BrowserView::OnLoadCompleted() {
#if defined(OS_WIN)
DCHECK(!jumplist_.get());
jumplist_ = new JumpList(browser_->profile());
#endif
}
BrowserViewLayout* BrowserView::GetBrowserViewLayout() const {
return static_cast<BrowserViewLayout*>(GetLayoutManager());
}
ContentsLayoutManager* BrowserView::GetContentsLayoutManager() const {
return static_cast<ContentsLayoutManager*>(
contents_container_->GetLayoutManager());
}
bool BrowserView::MaybeShowBookmarkBar(WebContents* contents) {
bool show_bookmark_bar = contents &&
browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR);
if (!show_bookmark_bar && !bookmark_bar_view_.get())
return false;
if (!bookmark_bar_view_.get()) {
bookmark_bar_view_.reset(new BookmarkBarView(browser_.get(), this));
bookmark_bar_view_->set_owned_by_client();
bookmark_bar_view_->set_background(new BookmarkBarViewBackground(
this, bookmark_bar_view_.get(), browser_.get()));
bookmark_bar_view_->SetBookmarkBarState(
browser_->bookmark_bar_state(),
BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
GetBrowserViewLayout()->set_bookmark_bar(bookmark_bar_view_.get());
}
// Don't change the visibility of the BookmarkBarView. BrowserViewLayout
// handles it.
bookmark_bar_view_->SetPageNavigator(GetActiveWebContents());
// Update parenting for the bookmark bar. This may detach it from all views.
bool needs_layout = false;
views::View* new_parent = nullptr;
if (show_bookmark_bar) {
if (bookmark_bar_view_->IsDetached())
new_parent = this;
else
new_parent = top_container_;
}
if (new_parent != bookmark_bar_view_->parent()) {
SetBookmarkBarParent(new_parent);
needs_layout = true;
}
// Check for updates to the desired size.
if (bookmark_bar_view_->GetPreferredSize().height() !=
bookmark_bar_view_->height())
needs_layout = true;
return needs_layout;
}
void BrowserView::SetBookmarkBarParent(views::View* new_parent) {
if (new_parent == this) {
// Add it underneath |top_container_| or at the end if top container isn't
// found.
int top_container_index = GetIndexOf(top_container_);
if (top_container_index >= 0)
AddChildViewAt(bookmark_bar_view_.get(), top_container_index);
else
AddChildView(bookmark_bar_view_.get());
} else if (new_parent) {
// No special stacking is required for other parents.
new_parent->AddChildView(bookmark_bar_view_.get());
} else {
// Bookmark bar is being detached from all views because it is hidden.
bookmark_bar_view_->parent()->RemoveChildView(bookmark_bar_view_.get());
}
}
bool BrowserView::MaybeShowInfoBar(WebContents* contents) {
// TODO(beng): Remove this function once the interface between
// InfoBarContainer, DownloadShelfView and WebContents and this
// view is sorted out.
return true;
}
void BrowserView::UpdateDevToolsForContents(
WebContents* web_contents, bool update_devtools_web_contents) {
DevToolsContentsResizingStrategy strategy;
WebContents* devtools = DevToolsWindow::GetInTabWebContents(
web_contents, &strategy);
if (!devtools_web_view_->web_contents() && devtools &&
!devtools_focus_tracker_.get()) {
// Install devtools focus tracker when dev tools window is shown for the
// first time.
devtools_focus_tracker_.reset(
new views::ExternalFocusTracker(devtools_web_view_,
GetFocusManager()));
}
// Restore focus to the last focused view when hiding devtools window.
if (devtools_web_view_->web_contents() && !devtools &&
devtools_focus_tracker_.get()) {
devtools_focus_tracker_->FocusLastFocusedExternalView();
devtools_focus_tracker_.reset();
}
// Replace devtools WebContents.
if (devtools_web_view_->web_contents() != devtools &&
update_devtools_web_contents) {
devtools_web_view_->SetWebContents(devtools);
}
if (devtools) {
devtools_web_view_->SetVisible(true);
GetContentsLayoutManager()->SetContentsResizingStrategy(strategy);
} else {
devtools_web_view_->SetVisible(false);
GetContentsLayoutManager()->SetContentsResizingStrategy(
DevToolsContentsResizingStrategy());
}
contents_container_->Layout();
if (devtools) {
// When strategy.hide_inspected_contents() returns true, we are hiding
// contents_web_view_ behind the devtools_web_view_. Otherwise,
// contents_web_view_ should be right above the devtools_web_view_.
int devtools_index = contents_container_->GetIndexOf(devtools_web_view_);
int contents_index = contents_container_->GetIndexOf(contents_web_view_);
bool devtools_is_on_top = devtools_index > contents_index;
if (strategy.hide_inspected_contents() != devtools_is_on_top)
contents_container_->ReorderChildView(contents_web_view_, devtools_index);
}
}
void BrowserView::UpdateUIForContents(WebContents* contents) {
bool needs_layout = MaybeShowBookmarkBar(contents);
// TODO(jamescook): This function always returns true. Remove it and figure
// out when layout is actually required.
needs_layout |= MaybeShowInfoBar(contents);
if (needs_layout)
Layout();
}
void BrowserView::ProcessFullscreen(bool fullscreen,
FullscreenMode mode,
const GURL& url,
ExclusiveAccessBubbleType bubble_type) {
if (in_process_fullscreen_)
return;
in_process_fullscreen_ = true;
// Reduce jankiness during the following position changes by:
// * Hiding the window until it's in the final position
// * Ignoring all intervening Layout() calls, which resize the webpage and
// thus are slow and look ugly (enforced via |in_process_fullscreen_|).
LocationBarView* location_bar = GetLocationBarView();
if (mode == METRO_SNAP_FULLSCREEN || !fullscreen) {
// Hide the fullscreen bubble as soon as possible, since the mode toggle can
// take enough time for the user to notice.
exclusive_access_bubble_.reset();
}
if (fullscreen) {
// Move focus out of the location bar if necessary.
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
// Look for focus in the location bar itself or any child view.
if (location_bar->Contains(focus_manager->GetFocusedView()))
focus_manager->ClearFocus();
}
// Toggle fullscreen mode.
frame_->SetFullscreen(fullscreen);
// Enable immersive before the browser refreshes its list of enabled commands.
if (mode != METRO_SNAP_FULLSCREEN && ShouldUseImmersiveFullscreenForUrl(url))
immersive_mode_controller_->SetEnabled(fullscreen);
browser_->WindowFullscreenStateChanged();
if (fullscreen && !chrome::IsRunningInAppMode() &&
mode != METRO_SNAP_FULLSCREEN) {
UpdateFullscreenExitBubbleContent(url, bubble_type);
}
// Undo our anti-jankiness hacks and force a re-layout. We also need to
// recompute the height of the infobar top arrow because toggling in and out
// of fullscreen changes it. Calling ToolbarSizeChanged() will do both these
// things since it computes the arrow height directly and forces a layout
// indirectly via UpdateUIForContents(). Reset |in_process_fullscreen_| in
// order to let the layout occur.
in_process_fullscreen_ = false;
ToolbarSizeChanged(false);
}
bool BrowserView::ShouldUseImmersiveFullscreenForUrl(const GURL& url) const {
// Kiosk mode needs the whole screen, and if we're not in an Ash desktop
// immersive fullscreen doesn't exist.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) ||
browser()->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) {
return false;
}
return url.is_empty();
}
void BrowserView::LoadAccelerators() {
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
// Let's fill our own accelerator table.
const bool is_app_mode = chrome::IsRunningInForcedAppMode();
const std::vector<chrome::AcceleratorMapping> accelerator_list(
chrome::GetAcceleratorList());
for (std::vector<chrome::AcceleratorMapping>::const_iterator it =
accelerator_list.begin(); it != accelerator_list.end(); ++it) {
// In app mode, only allow accelerators of white listed commands to pass
// through.
if (is_app_mode && !chrome::IsCommandAllowedInAppMode(it->command_id))
continue;
ui::Accelerator accelerator(it->keycode, it->modifiers);
accelerator_table_[accelerator] = it->command_id;
// Also register with the focus manager.
focus_manager->RegisterAccelerator(
accelerator, ui::AcceleratorManager::kNormalPriority, this);
}
}
int BrowserView::GetCommandIDForAppCommandID(int app_command_id) const {
#if defined(OS_WIN)
switch (app_command_id) {
// NOTE: The order here matches the APPCOMMAND declaration order in the
// Windows headers.
case APPCOMMAND_BROWSER_BACKWARD: return IDC_BACK;
case APPCOMMAND_BROWSER_FORWARD: return IDC_FORWARD;
case APPCOMMAND_BROWSER_REFRESH: return IDC_RELOAD;
case APPCOMMAND_BROWSER_HOME: return IDC_HOME;
case APPCOMMAND_BROWSER_STOP: return IDC_STOP;
case APPCOMMAND_BROWSER_SEARCH: return IDC_FOCUS_SEARCH;
case APPCOMMAND_HELP: return IDC_HELP_PAGE_VIA_KEYBOARD;
case APPCOMMAND_NEW: return IDC_NEW_TAB;
case APPCOMMAND_OPEN: return IDC_OPEN_FILE;
case APPCOMMAND_CLOSE: return IDC_CLOSE_TAB;
case APPCOMMAND_SAVE: return IDC_SAVE_PAGE;
case APPCOMMAND_PRINT: return IDC_PRINT;
case APPCOMMAND_COPY: return IDC_COPY;
case APPCOMMAND_CUT: return IDC_CUT;
case APPCOMMAND_PASTE: return IDC_PASTE;
// TODO(pkasting): http://b/1113069 Handle these.
case APPCOMMAND_UNDO:
case APPCOMMAND_REDO:
case APPCOMMAND_SPELL_CHECK:
default: return -1;
}
#else
// App commands are Windows-specific so there's nothing to do here.
return -1;
#endif
}
void BrowserView::InitHangMonitor() {
#if defined(OS_WIN)
PrefService* pref_service = g_browser_process->local_state();
if (!pref_service)
return;
int plugin_message_response_timeout =
pref_service->GetInteger(prefs::kPluginMessageResponseTimeout);
int hung_plugin_detect_freq =
pref_service->GetInteger(prefs::kHungPluginDetectFrequency);
HWND window = GetWidget()->GetNativeView()->GetHost()->
GetAcceleratedWidget();
if ((hung_plugin_detect_freq > 0) &&
hung_window_detector_.Initialize(window,
plugin_message_response_timeout)) {
ticker_.set_tick_interval(hung_plugin_detect_freq);
ticker_.RegisterTickHandler(&hung_window_detector_);
ticker_.Start();
pref_service->SetInteger(prefs::kPluginMessageResponseTimeout,
plugin_message_response_timeout);
pref_service->SetInteger(prefs::kHungPluginDetectFrequency,
hung_plugin_detect_freq);
}
#endif
}
void BrowserView::UpdateAcceleratorMetrics(const ui::Accelerator& accelerator,
int command_id) {
const ui::KeyboardCode key_code = accelerator.key_code();
if (command_id == IDC_HELP_PAGE_VIA_KEYBOARD && key_code == ui::VKEY_F1)
content::RecordAction(UserMetricsAction("ShowHelpTabViaF1"));
if (command_id == IDC_BOOKMARK_PAGE)
UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
BOOKMARK_ENTRY_POINT_ACCELERATOR,
BOOKMARK_ENTRY_POINT_LIMIT);
#if defined(OS_CHROMEOS)
// Collect information about the relative popularity of various accelerators
// on Chrome OS.
switch (command_id) {
case IDC_BACK:
if (key_code == ui::VKEY_BACK)
content::RecordAction(UserMetricsAction("Accel_Back_Backspace"));
else if (key_code == ui::VKEY_BROWSER_BACK)
content::RecordAction(UserMetricsAction("Accel_Back_F1"));
else if (key_code == ui::VKEY_LEFT)
content::RecordAction(UserMetricsAction("Accel_Back_Left"));
break;
case IDC_FORWARD:
if (key_code == ui::VKEY_BACK)
content::RecordAction(UserMetricsAction("Accel_Forward_Backspace"));
else if (key_code == ui::VKEY_BROWSER_FORWARD)
content::RecordAction(UserMetricsAction("Accel_Forward_F2"));
else if (key_code == ui::VKEY_RIGHT)
content::RecordAction(UserMetricsAction("Accel_Forward_Right"));
break;
case IDC_RELOAD:
case IDC_RELOAD_IGNORING_CACHE:
if (key_code == ui::VKEY_R)
content::RecordAction(UserMetricsAction("Accel_Reload_R"));
else if (key_code == ui::VKEY_BROWSER_REFRESH)
content::RecordAction(UserMetricsAction("Accel_Reload_F3"));
break;
case IDC_FOCUS_LOCATION:
if (key_code == ui::VKEY_D)
content::RecordAction(UserMetricsAction("Accel_FocusLocation_D"));
else if (key_code == ui::VKEY_L)
content::RecordAction(UserMetricsAction("Accel_FocusLocation_L"));
break;
case IDC_FOCUS_SEARCH:
if (key_code == ui::VKEY_E)
content::RecordAction(UserMetricsAction("Accel_FocusSearch_E"));
else if (key_code == ui::VKEY_K)
content::RecordAction(UserMetricsAction("Accel_FocusSearch_K"));
break;
default:
// Do nothing.
break;
}
#endif
}
void BrowserView::ShowAvatarBubbleFromAvatarButton(
AvatarBubbleMode mode,
const signin::ManageAccountsParams& manage_accounts_params) {
views::BubbleBorder::Arrow arrow = views::BubbleBorder::TOP_RIGHT;
views::BubbleBorder::BubbleAlignment alignment =
views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR;
views::View* anchor_view = frame_->GetAvatarMenuButton();
if (!anchor_view)
anchor_view = toolbar_->app_menu();
else if (!frame_->GetAvatarMenuButton()->button_on_right())
arrow = views::BubbleBorder::TOP_LEFT;
if (switches::IsNewAvatarMenu()) {
NewAvatarButton* button = frame_->GetNewAvatarMenuButton();
if (button) {
anchor_view = button;
arrow = views::BubbleBorder::TOP_RIGHT;
alignment = views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE;
}
profiles::BubbleViewMode bubble_view_mode;
profiles::TutorialMode tutorial_mode;
profiles::BubbleViewModeFromAvatarBubbleMode(
mode, &bubble_view_mode, &tutorial_mode);
ProfileChooserView::ShowBubble(
bubble_view_mode, tutorial_mode,
manage_accounts_params, anchor_view, arrow, alignment, browser());
} else {
gfx::Point origin;
views::View::ConvertPointToScreen(anchor_view, &origin);
gfx::Rect bounds(origin, anchor_view->size());
views::BubbleBorder::ArrowPaintType arrow_paint_type =
ShouldHideUIForFullscreen() ? views::BubbleBorder::PAINT_TRANSPARENT :
views::BubbleBorder::PAINT_NORMAL;
AvatarMenuBubbleView::ShowBubble(anchor_view, arrow, arrow_paint_type,
alignment, bounds, browser());
}
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
}
int BrowserView::GetRenderViewHeightInsetWithDetachedBookmarkBar() {
if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED ||
!bookmark_bar_view_.get() || !bookmark_bar_view_->IsDetached()) {
return 0;
}
// Don't use bookmark_bar_view_->height() which won't be the final height if
// the bookmark bar is animating.
return chrome::kNTPBookmarkBarHeight -
bookmark_bar_view_->GetFullyDetachedToolbarOverlap();
}
void BrowserView::ExecuteExtensionCommand(
const extensions::Extension* extension,
const extensions::Command& command) {
toolbar_->ExecuteExtensionCommand(extension, command);
}
void BrowserView::DoCutCopyPaste(void (WebContents::*method)(),
int command_id) {
WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
if (!contents)
return;
if (DoCutCopyPasteForWebContents(contents, method))
return;
WebContents* devtools = DevToolsWindow::GetInTabWebContents(contents,
nullptr);
if (devtools && DoCutCopyPasteForWebContents(devtools, method))
return;
views::FocusManager* focus_manager = GetFocusManager();
views::View* focused = focus_manager->GetFocusedView();
if (focused &&
(!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) ||
!strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) {
views::Textfield* textfield = static_cast<views::Textfield*>(focused);
textfield->ExecuteCommand(command_id);
}
}
bool BrowserView::DoCutCopyPasteForWebContents(
WebContents* contents,
void (WebContents::*method)()) {
if (contents->GetRenderWidgetHostView()->HasFocus()) {
(contents->*method)();
return true;
}
return false;
}
void BrowserView::ActivateAppModalDialog() const {
// If another browser is app modal, flash and activate the modal browser.
app_modal::AppModalDialog* active_dialog =
app_modal::AppModalDialogQueue::GetInstance()->active_dialog();
if (!active_dialog)
return;
Browser* modal_browser =
chrome::FindBrowserWithWebContents(active_dialog->web_contents());
if (modal_browser && (browser_ != modal_browser)) {
modal_browser->window()->FlashFrame(true);
modal_browser->window()->Activate();
}
app_modal::AppModalDialogQueue::GetInstance()->ActivateModalDialog();
}
int BrowserView::GetMaxTopInfoBarArrowHeight() {
int top_arrow_height = 0;
// Only show the arrows when not in fullscreen and when there's no omnibox
// popup.
if (!IsFullscreen() &&
!GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) {
gfx::Point icon_bottom(
toolbar_->location_bar()->GetLocationBarAnchorPoint());
ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom);
gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(nullptr));
ConvertPointToTarget(infobar_container_, this, &infobar_top);
top_arrow_height = infobar_top.y() - icon_bottom.y();
}
return top_arrow_height;
}
|