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 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101
|
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "core/testing/Internals.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptFunction.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/core/v8/SerializedScriptValueFactory.h"
#include "bindings/core/v8/V8IteratorResultValue.h"
#include "bindings/core/v8/V8ThrowException.h"
#include "core/HTMLNames.h"
#include "core/SVGNames.h"
#include "core/animation/DocumentTimeline.h"
#include "core/dom/ClientRect.h"
#include "core/dom/ClientRectList.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMNodeIds.h"
#include "core/dom/DOMPoint.h"
#include "core/dom/DOMStringList.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/Iterator.h"
#include "core/dom/NodeComputedStyle.h"
#include "core/dom/PseudoElement.h"
#include "core/dom/Range.h"
#include "core/dom/StaticNodeList.h"
#include "core/dom/StyleEngine.h"
#include "core/dom/TreeScope.h"
#include "core/dom/ViewportDescription.h"
#include "core/dom/shadow/ElementShadow.h"
#include "core/dom/shadow/ElementShadowV0.h"
#include "core/dom/shadow/FlatTreeTraversal.h"
#include "core/dom/shadow/SelectRuleFeatureSet.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/Editor.h"
#include "core/editing/PlainTextRange.h"
#include "core/editing/SurroundingText.h"
#include "core/editing/iterators/TextIterator.h"
#include "core/editing/markers/DocumentMarker.h"
#include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/serializers/Serialization.h"
#include "core/editing/spellcheck/IdleSpellCheckCallback.h"
#include "core/editing/spellcheck/SpellCheckRequester.h"
#include "core/editing/spellcheck/SpellChecker.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/frame/EventHandlerRegistry.h"
#include "core/frame/FrameConsole.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/frame/VisualViewport.h"
#include "core/html/HTMLContentElement.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLMediaElement.h"
#include "core/html/HTMLSelectElement.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/html/canvas/CanvasFontCache.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/forms/FormController.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/html/shadow/TextControlInnerElements.h"
#include "core/input/EventHandler.h"
#include "core/input/KeyboardEventManager.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/MainThreadDebugger.h"
#include "core/layout/LayoutMenuList.h"
#include "core/layout/LayoutObject.h"
#include "core/layout/LayoutTreeAsText.h"
#include "core/layout/api/LayoutMenuListItem.h"
#include "core/layout/api/LayoutViewItem.h"
#include "core/layout/compositing/CompositedLayerMapping.h"
#include "core/layout/compositing/PaintLayerCompositor.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/HistoryItem.h"
#include "core/page/ChromeClient.h"
#include "core/page/FocusController.h"
#include "core/page/NetworkStateNotifier.h"
#include "core/page/Page.h"
#include "core/page/PrintContext.h"
#include "core/page/scrolling/ScrollState.h"
#include "core/paint/PaintLayer.h"
#include "core/svg/SVGImageElement.h"
#include "core/testing/CallbackFunctionTest.h"
#include "core/testing/DictionaryTest.h"
#include "core/testing/GCObservation.h"
#include "core/testing/InternalRuntimeFlags.h"
#include "core/testing/InternalSettings.h"
#include "core/testing/LayerRect.h"
#include "core/testing/LayerRectList.h"
#include "core/testing/MockHyphenation.h"
#include "core/testing/OriginTrialsTest.h"
#include "core/testing/TypeConversions.h"
#include "core/testing/UnionTypesTest.h"
#include "core/workers/WorkerThread.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "platform/Cursor.h"
#include "platform/InstanceCounters.h"
#include "platform/Language.h"
#include "platform/LayoutLocale.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/geometry/IntRect.h"
#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/heap/Handle.h"
#include "platform/instrumentation/tracing/TraceEvent.h"
#include "platform/network/ResourceLoadPriority.h"
#include "platform/scroll/ProgrammaticScrollAnimator.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "public/platform/Platform.h"
#include "public/platform/WebConnectionType.h"
#include "public/platform/WebGraphicsContext3DProvider.h"
#include "public/platform/WebLayer.h"
#include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h"
#include "wtf/InstanceCounter.h"
#include "wtf/Optional.h"
#include "wtf/PtrUtil.h"
#include "wtf/dtoa.h"
#include "wtf/text/StringBuffer.h"
#include <deque>
#include <memory>
#include <v8.h>
namespace blink {
namespace {
class InternalsIterationSource final
: public ValueIterable<int>::IterationSource {
public:
bool next(ScriptState* scriptState,
int& value,
ExceptionState& exceptionState) override {
if (m_index >= 5)
return false;
value = m_index * m_index;
return true;
}
};
} // namespace
static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom(
const String& markerType) {
if (equalIgnoringCase(markerType, "Spelling"))
return DocumentMarker::Spelling;
if (equalIgnoringCase(markerType, "Grammar"))
return DocumentMarker::Grammar;
if (equalIgnoringCase(markerType, "TextMatch"))
return DocumentMarker::TextMatch;
return WTF::nullopt;
}
static WTF::Optional<DocumentMarker::MarkerTypes> markerTypesFrom(
const String& markerType) {
if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
return DocumentMarker::AllMarkers();
WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType);
if (!type)
return WTF::nullopt;
return DocumentMarker::MarkerTypes(type.value());
}
static SpellCheckRequester* spellCheckRequester(Document* document) {
if (!document || !document->frame())
return 0;
if (!RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
return &document->frame()->spellChecker().spellCheckRequester();
return &document->frame()->idleSpellCheckCallback().spellCheckRequester();
}
static ScrollableArea* scrollableAreaForNode(Node* node) {
if (!node)
return nullptr;
if (node->isDocumentNode()) {
// This can be removed after root layer scrolling is enabled.
if (FrameView* frameView = toDocument(node)->view())
return frameView->layoutViewportScrollableArea();
}
LayoutObject* layoutObject = node->layoutObject();
if (!layoutObject || !layoutObject->isBox())
return nullptr;
return toLayoutBox(layoutObject)->getScrollableArea();
}
static RuntimeEnabledFeatures::Backup* sFeaturesBackup = nullptr;
void Internals::resetToConsistentState(Page* page) {
DCHECK(page);
if (!sFeaturesBackup)
sFeaturesBackup = new RuntimeEnabledFeatures::Backup;
sFeaturesBackup->restore();
page->setIsCursorVisible(true);
page->setPageScaleFactor(1);
page->deprecatedLocalMainFrame()
->view()
->layoutViewportScrollableArea()
->setScrollOffset(ScrollOffset(), ProgrammaticScroll);
overrideUserPreferredLanguages(Vector<AtomicString>());
if (!page->deprecatedLocalMainFrame()
->spellChecker()
.isSpellCheckingEnabled())
page->deprecatedLocalMainFrame()
->spellChecker()
.toggleSpellCheckingEnabled();
if (page->deprecatedLocalMainFrame()->editor().isOverwriteModeEnabled())
page->deprecatedLocalMainFrame()->editor().toggleOverwriteModeEnabled();
if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
scrollingCoordinator->reset();
page->deprecatedLocalMainFrame()->view()->clear();
KeyboardEventManager::setCurrentCapsLockState(OverrideCapsLockState::Default);
}
Internals::Internals(ExecutionContext* context)
: m_runtimeFlags(InternalRuntimeFlags::create()),
m_document(toDocument(context)) {
m_document->fetcher()->enableIsPreloadedForTest();
}
LocalFrame* Internals::frame() const {
if (!m_document)
return nullptr;
return m_document->frame();
}
InternalSettings* Internals::settings() const {
if (!m_document)
return 0;
Page* page = m_document->page();
if (!page)
return 0;
return InternalSettings::from(*page);
}
InternalRuntimeFlags* Internals::runtimeFlags() const {
return m_runtimeFlags.get();
}
unsigned Internals::workerThreadCount() const {
return WorkerThread::workerThreadCount();
}
String Internals::address(Node* node) {
char buf[32];
sprintf(buf, "%p", node);
return String(buf);
}
GCObservation* Internals::observeGC(ScriptValue scriptValue) {
v8::Local<v8::Value> observedValue = scriptValue.v8Value();
DCHECK(!observedValue.IsEmpty());
if (observedValue->IsNull() || observedValue->IsUndefined()) {
V8ThrowException::throwTypeError(v8::Isolate::GetCurrent(),
"value to observe is null or undefined");
return nullptr;
}
return GCObservation::create(observedValue);
}
unsigned Internals::updateStyleAndReturnAffectedElementCount(
ExceptionState& exceptionState) const {
if (!m_document) {
exceptionState.throwDOMException(InvalidAccessError,
"No context document is available.");
return 0;
}
unsigned beforeCount = m_document->styleEngine().styleForElementCount();
m_document->updateStyleAndLayoutTree();
return m_document->styleEngine().styleForElementCount() - beforeCount;
}
unsigned Internals::needsLayoutCount(ExceptionState& exceptionState) const {
LocalFrame* contextFrame = frame();
if (!contextFrame) {
exceptionState.throwDOMException(InvalidAccessError,
"No context frame is available.");
return 0;
}
bool isPartial;
unsigned needsLayoutObjects;
unsigned totalObjects;
contextFrame->view()->countObjectsNeedingLayout(needsLayoutObjects,
totalObjects, isPartial);
return needsLayoutObjects;
}
unsigned Internals::hitTestCount(Document* doc,
ExceptionState& exceptionState) const {
if (!doc) {
exceptionState.throwDOMException(InvalidAccessError,
"Must supply document to check");
return 0;
}
return doc->layoutViewItem().hitTestCount();
}
unsigned Internals::hitTestCacheHits(Document* doc,
ExceptionState& exceptionState) const {
if (!doc) {
exceptionState.throwDOMException(InvalidAccessError,
"Must supply document to check");
return 0;
}
return doc->layoutViewItem().hitTestCacheHits();
}
Element* Internals::elementFromPoint(Document* doc,
double x,
double y,
bool ignoreClipping,
bool allowChildFrameContent,
ExceptionState& exceptionState) const {
if (!doc) {
exceptionState.throwDOMException(InvalidAccessError,
"Must supply document to check");
return 0;
}
if (doc->layoutViewItem().isNull())
return 0;
HitTestRequest::HitTestRequestType hitType =
HitTestRequest::ReadOnly | HitTestRequest::Active;
if (ignoreClipping)
hitType |= HitTestRequest::IgnoreClipping;
if (allowChildFrameContent)
hitType |= HitTestRequest::AllowChildFrameContent;
HitTestRequest request(hitType);
return doc->hitTestPoint(x, y, request);
}
void Internals::clearHitTestCache(Document* doc,
ExceptionState& exceptionState) const {
if (!doc) {
exceptionState.throwDOMException(InvalidAccessError,
"Must supply document to check");
return;
}
if (doc->layoutViewItem().isNull())
return;
doc->layoutViewItem().clearHitTestCache();
}
bool Internals::isPreloaded(const String& url) {
return isPreloadedBy(url, m_document);
}
bool Internals::isPreloadedBy(const String& url, Document* document) {
if (!document)
return false;
return document->fetcher()->isPreloadedForTest(document->completeURL(url));
}
bool Internals::isLoading(const String& url) {
if (!m_document)
return false;
const String cacheIdentifier = m_document->fetcher()->getCacheIdentifier();
Resource* resource = memoryCache()->resourceForURL(
m_document->completeURL(url), cacheIdentifier);
// We check loader() here instead of isLoading(), because a multipart
// ImageResource lies isLoading() == false after the first part is loaded.
return resource && resource->loader();
}
bool Internals::isLoadingFromMemoryCache(const String& url) {
if (!m_document)
return false;
const String cacheIdentifier = m_document->fetcher()->getCacheIdentifier();
Resource* resource = memoryCache()->resourceForURL(
m_document->completeURL(url), cacheIdentifier);
return resource && resource->getStatus() == Resource::Cached;
}
int Internals::getResourcePriority(const String& url, Document* document) {
if (!document)
return ResourceLoadPriority::ResourceLoadPriorityUnresolved;
Resource* resource = document->fetcher()->allResources().get(
URLTestHelpers::toKURL(url.utf8().data()));
if (!resource)
return ResourceLoadPriority::ResourceLoadPriorityUnresolved;
return resource->resourceRequest().priority();
}
String Internals::getResourceHeader(const String& url,
const String& header,
Document* document) {
if (!document)
return String();
Resource* resource = document->fetcher()->allResources().get(
URLTestHelpers::toKURL(url.utf8().data()));
if (!resource)
return String();
return resource->resourceRequest().httpHeaderField(header.utf8().data());
}
bool Internals::isSharingStyle(Element* element1, Element* element2) const {
DCHECK(element1 && element2);
return element1->computedStyle() == element2->computedStyle();
}
bool Internals::isValidContentSelect(Element* insertionPoint,
ExceptionState& exceptionState) {
DCHECK(insertionPoint);
if (!insertionPoint->isInsertionPoint()) {
exceptionState.throwDOMException(InvalidAccessError,
"The element is not an insertion point.");
return false;
}
return isHTMLContentElement(*insertionPoint) &&
toHTMLContentElement(*insertionPoint).isSelectValid();
}
Node* Internals::treeScopeRootNode(Node* node) {
DCHECK(node);
return &node->treeScope().rootNode();
}
Node* Internals::parentTreeScope(Node* node) {
DCHECK(node);
const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
return parentTreeScope ? &parentTreeScope->rootNode() : 0;
}
bool Internals::hasSelectorForIdInShadow(Element* host,
const AtomicString& idValue,
ExceptionState& exceptionState) {
DCHECK(host);
if (!host->shadow() || host->shadow()->isV1()) {
exceptionState.throwDOMException(
InvalidAccessError, "The host element does not have a v0 shadow.");
return false;
}
return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForId(
idValue);
}
bool Internals::hasSelectorForClassInShadow(Element* host,
const AtomicString& className,
ExceptionState& exceptionState) {
DCHECK(host);
if (!host->shadow() || host->shadow()->isV1()) {
exceptionState.throwDOMException(
InvalidAccessError, "The host element does not have a v0 shadow.");
return false;
}
return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForClass(
className);
}
bool Internals::hasSelectorForAttributeInShadow(
Element* host,
const AtomicString& attributeName,
ExceptionState& exceptionState) {
DCHECK(host);
if (!host->shadow() || host->shadow()->isV1()) {
exceptionState.throwDOMException(
InvalidAccessError, "The host element does not have a v0 shadow.");
return false;
}
return host->shadow()->v0().ensureSelectFeatureSet().hasSelectorForAttribute(
attributeName);
}
unsigned short Internals::compareTreeScopePosition(
const Node* node1,
const Node* node2,
ExceptionState& exceptionState) const {
DCHECK(node1 && node2);
const TreeScope* treeScope1 =
node1->isDocumentNode()
? static_cast<const TreeScope*>(toDocument(node1))
: node1->isShadowRoot()
? static_cast<const TreeScope*>(toShadowRoot(node1))
: 0;
const TreeScope* treeScope2 =
node2->isDocumentNode()
? static_cast<const TreeScope*>(toDocument(node2))
: node2->isShadowRoot()
? static_cast<const TreeScope*>(toShadowRoot(node2))
: 0;
if (!treeScope1 || !treeScope2) {
exceptionState.throwDOMException(
InvalidAccessError,
String::format(
"The %s node is neither a document node, nor a shadow root.",
treeScope1 ? "second" : "first"));
return 0;
}
return treeScope1->comparePosition(*treeScope2);
}
void Internals::pauseAnimations(double pauseTime,
ExceptionState& exceptionState) {
if (pauseTime < 0) {
exceptionState.throwDOMException(
InvalidAccessError, ExceptionMessages::indexExceedsMinimumBound(
"pauseTime", pauseTime, 0.0));
return;
}
if (!frame())
return;
frame()->view()->updateAllLifecyclePhases();
frame()->document()->timeline().pauseAnimationsForTesting(pauseTime);
}
bool Internals::isCompositedAnimation(Animation* animation) {
return animation->hasActiveAnimationsOnCompositor();
}
void Internals::disableCompositedAnimation(Animation* animation) {
animation->disableCompositedAnimationForTesting();
}
void Internals::disableCSSAdditiveAnimations() {
RuntimeEnabledFeatures::setCSSAdditiveAnimationsEnabled(false);
}
void Internals::advanceTimeForImage(Element* image,
double deltaTimeInSeconds,
ExceptionState& exceptionState) {
DCHECK(image);
if (deltaTimeInSeconds < 0) {
exceptionState.throwDOMException(
InvalidAccessError, ExceptionMessages::indexExceedsMinimumBound(
"deltaTimeInSeconds", deltaTimeInSeconds, 0.0));
return;
}
ImageResourceContent* resource = nullptr;
if (isHTMLImageElement(*image)) {
resource = toHTMLImageElement(*image).cachedImage();
} else if (isSVGImageElement(*image)) {
resource = toSVGImageElement(*image).cachedImage();
} else {
exceptionState.throwDOMException(
InvalidAccessError, "The element provided is not a image element.");
return;
}
if (!resource || !resource->hasImage()) {
exceptionState.throwDOMException(InvalidAccessError,
"The image resource is not available.");
return;
}
Image* imageData = resource->getImage();
if (!imageData->isBitmapImage()) {
exceptionState.throwDOMException(
InvalidAccessError, "The image resource is not a BitmapImage type.");
return;
}
imageData->advanceTime(deltaTimeInSeconds);
}
void Internals::advanceImageAnimation(Element* image,
ExceptionState& exceptionState) {
DCHECK(image);
ImageResourceContent* resource = nullptr;
if (isHTMLImageElement(*image)) {
resource = toHTMLImageElement(*image).cachedImage();
} else if (isSVGImageElement(*image)) {
resource = toSVGImageElement(*image).cachedImage();
} else {
exceptionState.throwDOMException(
InvalidAccessError, "The element provided is not a image element.");
return;
}
if (!resource || !resource->hasImage()) {
exceptionState.throwDOMException(InvalidAccessError,
"The image resource is not available.");
return;
}
Image* imageData = resource->getImage();
imageData->advanceAnimationForTesting();
}
bool Internals::hasShadowInsertionPoint(const Node* root,
ExceptionState& exceptionState) const {
DCHECK(root);
if (!root->isShadowRoot()) {
exceptionState.throwDOMException(InvalidAccessError,
"The node argument is not a shadow root.");
return false;
}
return toShadowRoot(root)->containsShadowElements();
}
bool Internals::hasContentElement(const Node* root,
ExceptionState& exceptionState) const {
DCHECK(root);
if (!root->isShadowRoot()) {
exceptionState.throwDOMException(InvalidAccessError,
"The node argument is not a shadow root.");
return false;
}
return toShadowRoot(root)->containsContentElements();
}
size_t Internals::countElementShadow(const Node* root,
ExceptionState& exceptionState) const {
DCHECK(root);
if (!root->isShadowRoot()) {
exceptionState.throwDOMException(InvalidAccessError,
"The node argument is not a shadow root.");
return 0;
}
return toShadowRoot(root)->childShadowRootCount();
}
Node* Internals::nextSiblingInFlatTree(Node* node,
ExceptionState& exceptionState) {
DCHECK(node);
if (!node->canParticipateInFlatTree()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The node argument doesn't particite in the flat tree.");
return 0;
}
return FlatTreeTraversal::nextSibling(*node);
}
Node* Internals::firstChildInFlatTree(Node* node,
ExceptionState& exceptionState) {
DCHECK(node);
if (!node->canParticipateInFlatTree()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The node argument doesn't particite in the flat tree");
return 0;
}
return FlatTreeTraversal::firstChild(*node);
}
Node* Internals::lastChildInFlatTree(Node* node,
ExceptionState& exceptionState) {
DCHECK(node);
if (!node->canParticipateInFlatTree()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The node argument doesn't particite in the flat tree.");
return 0;
}
return FlatTreeTraversal::lastChild(*node);
}
Node* Internals::nextInFlatTree(Node* node, ExceptionState& exceptionState) {
DCHECK(node);
if (!node->canParticipateInFlatTree()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The node argument doesn't particite in the flat tree.");
return 0;
}
return FlatTreeTraversal::next(*node);
}
Node* Internals::previousInFlatTree(Node* node,
ExceptionState& exceptionState) {
DCHECK(node);
if (!node->canParticipateInFlatTree()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The node argument doesn't particite in the flat tree.");
return 0;
}
return FlatTreeTraversal::previous(*node);
}
String Internals::elementLayoutTreeAsText(Element* element,
ExceptionState& exceptionState) {
DCHECK(element);
element->document().view()->updateAllLifecyclePhases();
String representation = externalRepresentation(element);
if (representation.isEmpty()) {
exceptionState.throwDOMException(
InvalidAccessError,
"The element provided has no external representation.");
return String();
}
return representation;
}
CSSStyleDeclaration* Internals::computedStyleIncludingVisitedInfo(
Node* node) const {
DCHECK(node);
bool allowVisitedStyle = true;
return CSSComputedStyleDeclaration::create(node, allowVisitedStyle);
}
ShadowRoot* Internals::createUserAgentShadowRoot(Element* host) {
DCHECK(host);
return &host->ensureUserAgentShadowRoot();
}
ShadowRoot* Internals::shadowRoot(Element* host) {
// FIXME: Internals::shadowRoot() in tests should be converted to
// youngestShadowRoot() or oldestShadowRoot().
// https://bugs.webkit.org/show_bug.cgi?id=78465
return youngestShadowRoot(host);
}
ShadowRoot* Internals::youngestShadowRoot(Element* host) {
DCHECK(host);
if (ElementShadow* shadow = host->shadow())
return &shadow->youngestShadowRoot();
return 0;
}
ShadowRoot* Internals::oldestShadowRoot(Element* host) {
DCHECK(host);
if (ElementShadow* shadow = host->shadow())
return &shadow->oldestShadowRoot();
return 0;
}
ShadowRoot* Internals::youngerShadowRoot(Node* shadow,
ExceptionState& exceptionState) {
DCHECK(shadow);
if (!shadow->isShadowRoot()) {
exceptionState.throwDOMException(InvalidAccessError,
"The node provided is not a shadow root.");
return 0;
}
return toShadowRoot(shadow)->youngerShadowRoot();
}
String Internals::shadowRootType(const Node* root,
ExceptionState& exceptionState) const {
DCHECK(root);
if (!root->isShadowRoot()) {
exceptionState.throwDOMException(InvalidAccessError,
"The node provided is not a shadow root.");
return String();
}
switch (toShadowRoot(root)->type()) {
case ShadowRootType::UserAgent:
return String("UserAgentShadowRoot");
case ShadowRootType::V0:
return String("V0ShadowRoot");
case ShadowRootType::Open:
return String("OpenShadowRoot");
case ShadowRootType::Closed:
return String("ClosedShadowRoot");
default:
ASSERT_NOT_REACHED();
return String("Unknown");
}
}
const AtomicString& Internals::shadowPseudoId(Element* element) {
DCHECK(element);
return element->shadowPseudoId();
}
String Internals::visiblePlaceholder(Element* element) {
if (element && isTextControlElement(*element)) {
const TextControlElement& textControlElement =
toTextControlElement(*element);
if (!textControlElement.isPlaceholderVisible())
return String();
if (HTMLElement* placeholderElement =
textControlElement.placeholderElement())
return placeholderElement->textContent();
}
return String();
}
void Internals::selectColorInColorChooser(Element* element,
const String& colorValue) {
DCHECK(element);
if (!isHTMLInputElement(*element))
return;
Color color;
if (!color.setFromString(colorValue))
return;
toHTMLInputElement(*element).selectColorInColorChooser(color);
}
void Internals::endColorChooser(Element* element) {
DCHECK(element);
if (!isHTMLInputElement(*element))
return;
toHTMLInputElement(*element).endColorChooser();
}
bool Internals::hasAutofocusRequest(Document* document) {
if (!document)
document = m_document;
return document->autofocusElement();
}
bool Internals::hasAutofocusRequest() {
return hasAutofocusRequest(0);
}
Vector<String> Internals::formControlStateOfHistoryItem(
ExceptionState& exceptionState) {
HistoryItem* mainItem = nullptr;
if (frame())
mainItem = frame()->loader().currentItem();
if (!mainItem) {
exceptionState.throwDOMException(InvalidAccessError,
"No history item is available.");
return Vector<String>();
}
return mainItem->getDocumentState();
}
void Internals::setFormControlStateOfHistoryItem(
const Vector<String>& state,
ExceptionState& exceptionState) {
HistoryItem* mainItem = nullptr;
if (frame())
mainItem = frame()->loader().currentItem();
if (!mainItem) {
exceptionState.throwDOMException(InvalidAccessError,
"No history item is available.");
return;
}
mainItem->clearDocumentState();
mainItem->setDocumentState(state);
}
DOMWindow* Internals::pagePopupWindow() const {
if (!m_document)
return nullptr;
if (Page* page = m_document->page())
return page->chromeClient().pagePopupWindowForTesting();
return nullptr;
}
ClientRect* Internals::absoluteCaretBounds(ExceptionState& exceptionState) {
if (!frame()) {
exceptionState.throwDOMException(
InvalidAccessError, "The document's frame cannot be retrieved.");
return ClientRect::create();
}
m_document->updateStyleAndLayoutIgnorePendingStylesheets();
return ClientRect::create(frame()->selection().absoluteCaretBounds());
}
ClientRect* Internals::boundingBox(Element* element) {
DCHECK(element);
element->document().updateStyleAndLayoutIgnorePendingStylesheets();
LayoutObject* layoutObject = element->layoutObject();
if (!layoutObject)
return ClientRect::create();
return ClientRect::create(
layoutObject->absoluteBoundingBoxRectIgnoringTransforms());
}
void Internals::setMarker(Document* document,
const Range* range,
const String& markerType,
ExceptionState& exceptionState) {
if (!document) {
exceptionState.throwDOMException(InvalidAccessError,
"No context document is available.");
return;
}
WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType);
if (!type) {
exceptionState.throwDOMException(
SyntaxError,
"The marker type provided ('" + markerType + "') is invalid.");
return;
}
document->updateStyleAndLayoutIgnorePendingStylesheets();
document->markers().addMarker(range->startPosition(), range->endPosition(),
type.value());
}
unsigned Internals::markerCountForNode(Node* node,
const String& markerType,
ExceptionState& exceptionState) {
DCHECK(node);
WTF::Optional<DocumentMarker::MarkerTypes> markerTypes =
markerTypesFrom(markerType);
if (!markerTypes) {
exceptionState.throwDOMException(
SyntaxError,
"The marker type provided ('" + markerType + "') is invalid.");
return 0;
}
return node->document()
.markers()
.markersFor(node, markerTypes.value())
.size();
}
unsigned Internals::activeMarkerCountForNode(Node* node) {
DCHECK(node);
// Only TextMatch markers can be active.
DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
DocumentMarkerVector markers =
node->document().markers().markersFor(node, markerType);
unsigned activeMarkerCount = 0;
for (const auto& marker : markers) {
if (marker->activeMatch())
activeMarkerCount++;
}
return activeMarkerCount;
}
DocumentMarker* Internals::markerAt(Node* node,
const String& markerType,
unsigned index,
ExceptionState& exceptionState) {
DCHECK(node);
WTF::Optional<DocumentMarker::MarkerTypes> markerTypes =
markerTypesFrom(markerType);
if (!markerTypes) {
exceptionState.throwDOMException(
SyntaxError,
"The marker type provided ('" + markerType + "') is invalid.");
return 0;
}
DocumentMarkerVector markers =
node->document().markers().markersFor(node, markerTypes.value());
if (markers.size() <= index)
return 0;
return markers[index];
}
Range* Internals::markerRangeForNode(Node* node,
const String& markerType,
unsigned index,
ExceptionState& exceptionState) {
DCHECK(node);
DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
if (!marker)
return nullptr;
return Range::create(node->document(), node, marker->startOffset(), node,
marker->endOffset());
}
String Internals::markerDescriptionForNode(Node* node,
const String& markerType,
unsigned index,
ExceptionState& exceptionState) {
DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
if (!marker)
return String();
return marker->description();
}
void Internals::addTextMatchMarker(const Range* range, bool isActive) {
DCHECK(range);
range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
range->ownerDocument().markers().addTextMatchMarker(EphemeralRange(range),
isActive);
// This simulates what the production code does after
// DocumentMarkerController::addTextMatchMarker().
range->ownerDocument().view()->invalidatePaintForTickmarks();
}
static bool parseColor(const String& value,
Color& color,
ExceptionState& exceptionState,
String errorMessage) {
if (!color.setFromString(value)) {
exceptionState.throwDOMException(InvalidAccessError, errorMessage);
return false;
}
return true;
}
void Internals::addCompositionMarker(const Range* range,
const String& underlineColorValue,
bool thick,
const String& backgroundColorValue,
ExceptionState& exceptionState) {
DCHECK(range);
range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
Color underlineColor;
Color backgroundColor;
if (parseColor(underlineColorValue, underlineColor, exceptionState,
"Invalid underline color.") &&
parseColor(backgroundColorValue, backgroundColor, exceptionState,
"Invalid background color.")) {
range->ownerDocument().markers().addCompositionMarker(
range->startPosition(), range->endPosition(), underlineColor, thick,
backgroundColor);
}
}
void Internals::setMarkersActive(Node* node,
unsigned startOffset,
unsigned endOffset,
bool active) {
DCHECK(node);
node->document().markers().setMarkersActive(node, startOffset, endOffset,
active);
}
void Internals::setMarkedTextMatchesAreHighlighted(Document* document,
bool highlight) {
if (!document || !document->frame())
return;
document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
}
void Internals::setFrameViewPosition(Document* document,
long x,
long y,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
FrameView* frameView = document->view();
bool scrollbarsSuppressedOldValue = frameView->scrollbarsSuppressed();
frameView->setScrollbarsSuppressed(false);
frameView->updateScrollOffsetFromInternals(IntSize(x, y));
frameView->setScrollbarsSuppressed(scrollbarsSuppressedOldValue);
}
String Internals::viewportAsText(Document* document,
float,
int availableWidth,
int availableHeight,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->page()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return String();
}
document->updateStyleAndLayoutIgnorePendingStylesheets();
Page* page = document->page();
// Update initial viewport size.
IntSize initialViewportSize(availableWidth, availableHeight);
document->page()->deprecatedLocalMainFrame()->view()->setFrameRect(
IntRect(IntPoint::zero(), initialViewportSize));
ViewportDescription description = page->viewportDescription();
PageScaleConstraints constraints =
description.resolve(FloatSize(initialViewportSize), Length());
constraints.fitToContentsWidth(constraints.layoutSize.width(),
availableWidth);
constraints.resolveAutoInitialScale();
StringBuilder builder;
builder.append("viewport size ");
builder.append(String::number(constraints.layoutSize.width()));
builder.append('x');
builder.append(String::number(constraints.layoutSize.height()));
builder.append(" scale ");
builder.append(String::number(constraints.initialScale));
builder.append(" with limits [");
builder.append(String::number(constraints.minimumScale));
builder.append(", ");
builder.append(String::number(constraints.maximumScale));
builder.append("] and userScalable ");
builder.append(description.userZoom ? "true" : "false");
return builder.toString();
}
bool Internals::elementShouldAutoComplete(Element* element,
ExceptionState& exceptionState) {
DCHECK(element);
if (isHTMLInputElement(*element))
return toHTMLInputElement(*element).shouldAutocomplete();
exceptionState.throwDOMException(InvalidNodeTypeError,
"The element provided is not an INPUT.");
return false;
}
String Internals::suggestedValue(Element* element,
ExceptionState& exceptionState) {
DCHECK(element);
if (!element->isFormControlElement()) {
exceptionState.throwDOMException(
InvalidNodeTypeError,
"The element provided is not a form control element.");
return String();
}
String suggestedValue;
if (isHTMLInputElement(*element))
suggestedValue = toHTMLInputElement(*element).suggestedValue();
if (isHTMLTextAreaElement(*element))
suggestedValue = toHTMLTextAreaElement(*element).suggestedValue();
if (isHTMLSelectElement(*element))
suggestedValue = toHTMLSelectElement(*element).suggestedValue();
return suggestedValue;
}
void Internals::setSuggestedValue(Element* element,
const String& value,
ExceptionState& exceptionState) {
DCHECK(element);
if (!element->isFormControlElement()) {
exceptionState.throwDOMException(
InvalidNodeTypeError,
"The element provided is not a form control element.");
return;
}
if (isHTMLInputElement(*element))
toHTMLInputElement(*element).setSuggestedValue(value);
if (isHTMLTextAreaElement(*element))
toHTMLTextAreaElement(*element).setSuggestedValue(value);
if (isHTMLSelectElement(*element))
toHTMLSelectElement(*element).setSuggestedValue(value);
}
void Internals::setEditingValue(Element* element,
const String& value,
ExceptionState& exceptionState) {
DCHECK(element);
if (!isHTMLInputElement(*element)) {
exceptionState.throwDOMException(InvalidNodeTypeError,
"The element provided is not an INPUT.");
return;
}
toHTMLInputElement(*element).setEditingValue(value);
}
void Internals::setAutofilled(Element* element,
bool enabled,
ExceptionState& exceptionState) {
DCHECK(element);
if (!element->isFormControlElement()) {
exceptionState.throwDOMException(
InvalidNodeTypeError,
"The element provided is not a form control element.");
return;
}
toHTMLFormControlElement(element)->setAutofilled(enabled);
}
Range* Internals::rangeFromLocationAndLength(Element* scope,
int rangeLocation,
int rangeLength) {
DCHECK(scope);
// TextIterator depends on Layout information, make sure layout it up to date.
scope->document().updateStyleAndLayoutIgnorePendingStylesheets();
return createRange(PlainTextRange(rangeLocation, rangeLocation + rangeLength)
.createRange(*scope));
}
unsigned Internals::locationFromRange(Element* scope, const Range* range) {
DCHECK(scope && range);
// PlainTextRange depends on Layout information, make sure layout it up to
// date.
scope->document().updateStyleAndLayoutIgnorePendingStylesheets();
return PlainTextRange::create(*scope, *range).start();
}
unsigned Internals::lengthFromRange(Element* scope, const Range* range) {
DCHECK(scope && range);
// PlainTextRange depends on Layout information, make sure layout it up to
// date.
scope->document().updateStyleAndLayoutIgnorePendingStylesheets();
return PlainTextRange::create(*scope, *range).length();
}
String Internals::rangeAsText(const Range* range) {
DCHECK(range);
// Clean layout is required by plain text extraction.
range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
return range->text();
}
// FIXME: The next four functions are very similar - combine them once
// bestClickableNode/bestContextMenuNode have been combined..
DOMPoint* Internals::touchPositionAdjustedToBestClickableNode(
long x,
long y,
long width,
long height,
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return 0;
}
document->updateStyleAndLayout();
IntSize radius(width / 2, height / 2);
IntPoint point(x + radius.width(), y + radius.height());
EventHandler& eventHandler = document->frame()->eventHandler();
IntPoint hitTestPoint = document->frame()->view()->rootFrameToContents(point);
HitTestResult result = eventHandler.hitTestResultAtPoint(
hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active |
HitTestRequest::ListBased,
LayoutSize(radius));
Node* targetNode = 0;
IntPoint adjustedPoint;
bool foundNode = eventHandler.bestClickableNodeForHitTestResult(
result, adjustedPoint, targetNode);
if (foundNode)
return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
return 0;
}
Node* Internals::touchNodeAdjustedToBestClickableNode(
long x,
long y,
long width,
long height,
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return 0;
}
document->updateStyleAndLayout();
IntSize radius(width / 2, height / 2);
IntPoint point(x + radius.width(), y + radius.height());
EventHandler& eventHandler = document->frame()->eventHandler();
IntPoint hitTestPoint = document->frame()->view()->rootFrameToContents(point);
HitTestResult result = eventHandler.hitTestResultAtPoint(
hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active |
HitTestRequest::ListBased,
LayoutSize(radius));
Node* targetNode = 0;
IntPoint adjustedPoint;
document->frame()->eventHandler().bestClickableNodeForHitTestResult(
result, adjustedPoint, targetNode);
return targetNode;
}
DOMPoint* Internals::touchPositionAdjustedToBestContextMenuNode(
long x,
long y,
long width,
long height,
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return 0;
}
document->updateStyleAndLayout();
IntSize radius(width / 2, height / 2);
IntPoint point(x + radius.width(), y + radius.height());
EventHandler& eventHandler = document->frame()->eventHandler();
IntPoint hitTestPoint = document->frame()->view()->rootFrameToContents(point);
HitTestResult result = eventHandler.hitTestResultAtPoint(
hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active |
HitTestRequest::ListBased,
LayoutSize(radius));
Node* targetNode = 0;
IntPoint adjustedPoint;
bool foundNode = eventHandler.bestContextMenuNodeForHitTestResult(
result, adjustedPoint, targetNode);
if (foundNode)
return DOMPoint::create(adjustedPoint.x(), adjustedPoint.y());
return DOMPoint::create(x, y);
}
Node* Internals::touchNodeAdjustedToBestContextMenuNode(
long x,
long y,
long width,
long height,
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return 0;
}
document->updateStyleAndLayout();
IntSize radius(width / 2, height / 2);
IntPoint point(x + radius.width(), y + radius.height());
EventHandler& eventHandler = document->frame()->eventHandler();
IntPoint hitTestPoint = document->frame()->view()->rootFrameToContents(point);
HitTestResult result = eventHandler.hitTestResultAtPoint(
hitTestPoint, HitTestRequest::ReadOnly | HitTestRequest::Active |
HitTestRequest::ListBased,
LayoutSize(radius));
Node* targetNode = 0;
IntPoint adjustedPoint;
eventHandler.bestContextMenuNodeForHitTestResult(result, adjustedPoint,
targetNode);
return targetNode;
}
ClientRect* Internals::bestZoomableAreaForTouchPoint(
long x,
long y,
long width,
long height,
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return nullptr;
}
document->updateStyleAndLayout();
IntSize radius(width / 2, height / 2);
IntPoint point(x + radius.width(), y + radius.height());
Node* targetNode = 0;
IntRect zoomableArea;
bool foundNode =
document->frame()->eventHandler().bestZoomableAreaForTouchPoint(
point, radius, zoomableArea, targetNode);
if (foundNode)
return ClientRect::create(zoomableArea);
return nullptr;
}
int Internals::lastSpellCheckRequestSequence(Document* document,
ExceptionState& exceptionState) {
SpellCheckRequester* requester = spellCheckRequester(document);
if (!requester) {
exceptionState.throwDOMException(
InvalidAccessError,
"No spell check requestor can be obtained for the provided document.");
return -1;
}
return requester->lastRequestSequence();
}
int Internals::lastSpellCheckProcessedSequence(Document* document,
ExceptionState& exceptionState) {
SpellCheckRequester* requester = spellCheckRequester(document);
if (!requester) {
exceptionState.throwDOMException(
InvalidAccessError,
"No spell check requestor can be obtained for the provided document.");
return -1;
}
return requester->lastProcessedSequence();
}
Vector<AtomicString> Internals::userPreferredLanguages() const {
return blink::userPreferredLanguages();
}
// Optimally, the bindings generator would pass a Vector<AtomicString> here but
// this is not supported yet.
void Internals::setUserPreferredLanguages(const Vector<String>& languages) {
Vector<AtomicString> atomicLanguages;
for (size_t i = 0; i < languages.size(); ++i)
atomicLanguages.push_back(AtomicString(languages[i]));
overrideUserPreferredLanguages(atomicLanguages);
}
unsigned Internals::mediaKeysCount() {
return InstanceCounters::counterValue(InstanceCounters::MediaKeysCounter);
}
unsigned Internals::mediaKeySessionCount() {
return InstanceCounters::counterValue(
InstanceCounters::MediaKeySessionCounter);
}
unsigned Internals::suspendableObjectCount(Document* document) {
DCHECK(document);
return document->suspendableObjectCount();
}
static unsigned eventHandlerCount(
Document& document,
EventHandlerRegistry::EventHandlerClass handlerClass) {
if (!document.frameHost())
return 0;
EventHandlerRegistry* registry =
&document.frameHost()->eventHandlerRegistry();
unsigned count = 0;
const EventTargetSet* targets = registry->eventHandlerTargets(handlerClass);
if (targets) {
for (const auto& target : *targets)
count += target.value;
}
return count;
}
unsigned Internals::wheelEventHandlerCount(Document* document) {
DCHECK(document);
return eventHandlerCount(*document, EventHandlerRegistry::WheelEventBlocking);
}
unsigned Internals::scrollEventHandlerCount(Document* document) {
DCHECK(document);
return eventHandlerCount(*document, EventHandlerRegistry::ScrollEvent);
}
unsigned Internals::touchStartOrMoveEventHandlerCount(Document* document) {
DCHECK(document);
return eventHandlerCount(
*document, EventHandlerRegistry::TouchStartOrMoveEventBlocking) +
eventHandlerCount(*document,
EventHandlerRegistry::TouchStartOrMoveEventPassive);
}
unsigned Internals::touchEndOrCancelEventHandlerCount(Document* document) {
DCHECK(document);
return eventHandlerCount(
*document, EventHandlerRegistry::TouchEndOrCancelEventBlocking) +
eventHandlerCount(*document,
EventHandlerRegistry::TouchEndOrCancelEventPassive);
}
static PaintLayer* findLayerForGraphicsLayer(PaintLayer* searchRoot,
GraphicsLayer* graphicsLayer,
IntSize* layerOffset,
String* layerType) {
*layerOffset = IntSize();
if (searchRoot->hasCompositedLayerMapping() &&
graphicsLayer ==
searchRoot->compositedLayerMapping()->mainGraphicsLayer()) {
// If the |graphicsLayer| sets the scrollingContent layer as its
// scroll parent, consider it belongs to the scrolling layer and
// mark the layer type as "scrolling".
if (!searchRoot->layoutObject()->hasTransformRelatedProperty() &&
searchRoot->scrollParent() &&
searchRoot->parent() == searchRoot->scrollParent()) {
*layerType = "scrolling";
// For hit-test rect visualization to work, the hit-test rect should
// be relative to the scrolling layer and in this case the hit-test
// rect is relative to the element's own GraphicsLayer. So we will have
// to adjust the rect to be relative to the scrolling layer here.
// Only when the element's offsetParent == scroller's offsetParent we
// can compute the element's relative position to the scrolling content
// in this way.
if (searchRoot->layoutObject()->offsetParent() ==
searchRoot->parent()->layoutObject()->offsetParent()) {
LayoutBoxModelObject* current = searchRoot->layoutObject();
LayoutBoxModelObject* parent = searchRoot->parent()->layoutObject();
layerOffset->setWidth((parent->offsetLeft(parent->offsetParent()) -
current->offsetLeft(parent->offsetParent()))
.toInt());
layerOffset->setHeight((parent->offsetTop(parent->offsetParent()) -
current->offsetTop(parent->offsetParent()))
.toInt());
return searchRoot->parent();
}
}
LayoutRect rect;
PaintLayer::mapRectInPaintInvalidationContainerToBacking(
*searchRoot->layoutObject(), rect);
rect.move(searchRoot->compositedLayerMapping()
->contentOffsetInCompositingLayer());
*layerOffset = IntSize(rect.x().toInt(), rect.y().toInt());
return searchRoot;
}
// If the |graphicsLayer| is a scroller's scrollingContent layer,
// consider this is a scrolling layer.
GraphicsLayer* layerForScrolling =
searchRoot->getScrollableArea()
? searchRoot->getScrollableArea()->layerForScrolling()
: 0;
if (graphicsLayer == layerForScrolling) {
*layerType = "scrolling";
return searchRoot;
}
if (searchRoot->compositingState() == PaintsIntoGroupedBacking) {
GraphicsLayer* squashingLayer =
searchRoot->groupedMapping()->squashingLayer();
if (graphicsLayer == squashingLayer) {
*layerType = "squashing";
LayoutRect rect;
PaintLayer::mapRectInPaintInvalidationContainerToBacking(
*searchRoot->layoutObject(), rect);
*layerOffset = IntSize(rect.x().toInt(), rect.y().toInt());
return searchRoot;
}
}
GraphicsLayer* layerForHorizontalScrollbar =
searchRoot->getScrollableArea()
? searchRoot->getScrollableArea()->layerForHorizontalScrollbar()
: 0;
if (graphicsLayer == layerForHorizontalScrollbar) {
*layerType = "horizontalScrollbar";
return searchRoot;
}
GraphicsLayer* layerForVerticalScrollbar =
searchRoot->getScrollableArea()
? searchRoot->getScrollableArea()->layerForVerticalScrollbar()
: 0;
if (graphicsLayer == layerForVerticalScrollbar) {
*layerType = "verticalScrollbar";
return searchRoot;
}
GraphicsLayer* layerForScrollCorner =
searchRoot->getScrollableArea()
? searchRoot->getScrollableArea()->layerForScrollCorner()
: 0;
if (graphicsLayer == layerForScrollCorner) {
*layerType = "scrollCorner";
return searchRoot;
}
// Search right to left to increase the chances that we'll choose the top-most
// layers in a grouped mapping for squashing.
for (PaintLayer* child = searchRoot->lastChild(); child;
child = child->previousSibling()) {
PaintLayer* foundLayer =
findLayerForGraphicsLayer(child, graphicsLayer, layerOffset, layerType);
if (foundLayer)
return foundLayer;
}
return 0;
}
// Given a vector of rects, merge those that are adjacent, leaving empty rects
// in the place of no longer used slots. This is intended to simplify the list
// of rects returned by an SkRegion (which have been split apart for sorting
// purposes). No attempt is made to do this efficiently (eg. by relying on the
// sort criteria of SkRegion).
static void mergeRects(WebVector<blink::WebRect>& rects) {
for (size_t i = 0; i < rects.size(); ++i) {
if (rects[i].isEmpty())
continue;
bool updated;
do {
updated = false;
for (size_t j = i + 1; j < rects.size(); ++j) {
if (rects[j].isEmpty())
continue;
// Try to merge rects[j] into rects[i] along the 4 possible edges.
if (rects[i].y == rects[j].y && rects[i].height == rects[j].height) {
if (rects[i].x + rects[i].width == rects[j].x) {
rects[i].width += rects[j].width;
rects[j] = blink::WebRect();
updated = true;
} else if (rects[i].x == rects[j].x + rects[j].width) {
rects[i].x = rects[j].x;
rects[i].width += rects[j].width;
rects[j] = blink::WebRect();
updated = true;
}
} else if (rects[i].x == rects[j].x &&
rects[i].width == rects[j].width) {
if (rects[i].y + rects[i].height == rects[j].y) {
rects[i].height += rects[j].height;
rects[j] = blink::WebRect();
updated = true;
} else if (rects[i].y == rects[j].y + rects[j].height) {
rects[i].y = rects[j].y;
rects[i].height += rects[j].height;
rects[j] = blink::WebRect();
updated = true;
}
}
}
} while (updated);
}
}
static void accumulateLayerRectList(PaintLayerCompositor* compositor,
GraphicsLayer* graphicsLayer,
LayerRectList* rects) {
WebVector<blink::WebRect> layerRects =
graphicsLayer->platformLayer()->touchEventHandlerRegion();
if (!layerRects.isEmpty()) {
mergeRects(layerRects);
String layerType;
IntSize layerOffset;
PaintLayer* paintLayer = findLayerForGraphicsLayer(
compositor->rootLayer(), graphicsLayer, &layerOffset, &layerType);
Node* node = paintLayer ? paintLayer->layoutObject()->node() : 0;
for (size_t i = 0; i < layerRects.size(); ++i) {
if (!layerRects[i].isEmpty()) {
rects->append(node, layerType, layerOffset.width(),
layerOffset.height(), ClientRect::create(layerRects[i]));
}
}
}
size_t numChildren = graphicsLayer->children().size();
for (size_t i = 0; i < numChildren; ++i)
accumulateLayerRectList(compositor, graphicsLayer->children()[i], rects);
}
LayerRectList* Internals::touchEventTargetLayerRects(
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view() || !document->page() || document != m_document) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return nullptr;
}
if (ScrollingCoordinator* scrollingCoordinator =
document->page()->scrollingCoordinator())
scrollingCoordinator->updateAfterCompositingChangeIfNeeded();
LayoutViewItem view = document->layoutViewItem();
if (!view.isNull()) {
if (PaintLayerCompositor* compositor = view.compositor()) {
if (GraphicsLayer* rootLayer = compositor->rootGraphicsLayer()) {
LayerRectList* rects = LayerRectList::create();
accumulateLayerRectList(compositor, rootLayer, rects);
return rects;
}
}
}
return nullptr;
}
bool Internals::executeCommand(Document* document,
const String& name,
const String& value,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return false;
}
LocalFrame* frame = document->frame();
return frame->editor().executeCommand(name, value);
}
AtomicString Internals::htmlNamespace() {
return HTMLNames::xhtmlNamespaceURI;
}
Vector<AtomicString> Internals::htmlTags() {
Vector<AtomicString> tags(HTMLNames::HTMLTagsCount);
std::unique_ptr<const HTMLQualifiedName* []> qualifiedNames =
HTMLNames::getHTMLTags();
for (size_t i = 0; i < HTMLNames::HTMLTagsCount; ++i)
tags[i] = qualifiedNames[i]->localName();
return tags;
}
AtomicString Internals::svgNamespace() {
return SVGNames::svgNamespaceURI;
}
Vector<AtomicString> Internals::svgTags() {
Vector<AtomicString> tags(SVGNames::SVGTagsCount);
std::unique_ptr<const SVGQualifiedName* []> qualifiedNames =
SVGNames::getSVGTags();
for (size_t i = 0; i < SVGNames::SVGTagsCount; ++i)
tags[i] = qualifiedNames[i]->localName();
return tags;
}
StaticNodeList* Internals::nodesFromRect(Document* document,
int centerX,
int centerY,
unsigned topPadding,
unsigned rightPadding,
unsigned bottomPadding,
unsigned leftPadding,
bool ignoreClipping,
bool allowChildFrameContent,
ExceptionState& exceptionState) const {
DCHECK(document);
if (!document->frame() || !document->frame()->view()) {
exceptionState.throwDOMException(
InvalidAccessError,
"No view can be obtained from the provided document.");
return nullptr;
}
LocalFrame* frame = document->frame();
FrameView* frameView = document->view();
LayoutViewItem layoutViewItem = document->layoutViewItem();
if (layoutViewItem.isNull())
return nullptr;
float zoomFactor = frame->pageZoomFactor();
LayoutPoint point =
LayoutPoint(FloatPoint(centerX * zoomFactor + frameView->scrollX(),
centerY * zoomFactor + frameView->scrollY()));
HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly |
HitTestRequest::Active |
HitTestRequest::ListBased;
if (ignoreClipping)
hitType |= HitTestRequest::IgnoreClipping;
if (allowChildFrameContent)
hitType |= HitTestRequest::AllowChildFrameContent;
HitTestRequest request(hitType);
// When ignoreClipping is false, this method returns null for coordinates
// outside of the viewport.
if (!request.ignoreClipping() &&
!frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(
point, topPadding, rightPadding, bottomPadding, leftPadding)))
return nullptr;
HeapVector<Member<Node>> matches;
HitTestResult result(request, point, topPadding, rightPadding, bottomPadding,
leftPadding);
layoutViewItem.hitTest(result);
copyToVector(result.listBasedTestResult(), matches);
return StaticNodeList::adopt(matches);
}
bool Internals::hasSpellingMarker(Document* document,
int from,
int length,
ExceptionState& exceptionState) {
if (!document || !document->frame()) {
exceptionState.throwDOMException(
InvalidAccessError,
"No frame can be obtained from the provided document.");
return false;
}
document->updateStyleAndLayoutIgnorePendingStylesheets();
return document->frame()->spellChecker().selectionStartHasMarkerFor(
DocumentMarker::Spelling, from, length);
}
void Internals::setSpellCheckingEnabled(bool enabled,
ExceptionState& exceptionState) {
if (!frame()) {
exceptionState.throwDOMException(
InvalidAccessError,
"No frame can be obtained from the provided document.");
return;
}
if (enabled != frame()->spellChecker().isSpellCheckingEnabled())
frame()->spellChecker().toggleSpellCheckingEnabled();
}
void Internals::replaceMisspelled(Document* document,
const String& replacement,
ExceptionState& exceptionState) {
if (!document || !document->frame()) {
exceptionState.throwDOMException(
InvalidAccessError,
"No frame can be obtained from the provided document.");
return;
}
document->updateStyleAndLayoutIgnorePendingStylesheets();
document->frame()->spellChecker().replaceMisspelledRange(replacement);
}
bool Internals::canHyphenate(const AtomicString& locale) {
return LayoutLocale::valueOrDefault(LayoutLocale::get(locale))
.getHyphenation();
}
void Internals::setMockHyphenation(const AtomicString& locale) {
LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation));
}
bool Internals::isOverwriteModeEnabled(Document* document) {
DCHECK(document);
if (!document->frame())
return false;
return document->frame()->editor().isOverwriteModeEnabled();
}
void Internals::toggleOverwriteModeEnabled(Document* document) {
DCHECK(document);
if (!document->frame())
return;
document->frame()->editor().toggleOverwriteModeEnabled();
}
unsigned Internals::numberOfLiveNodes() const {
return InstanceCounters::counterValue(InstanceCounters::NodeCounter);
}
unsigned Internals::numberOfLiveDocuments() const {
return InstanceCounters::counterValue(InstanceCounters::DocumentCounter);
}
String Internals::dumpRefCountedInstanceCounts() const {
return WTF::dumpRefCountedInstanceCounts();
}
bool Internals::hasGrammarMarker(Document* document,
int from,
int length,
ExceptionState& exceptionState) {
if (!document || !document->frame()) {
exceptionState.throwDOMException(
InvalidAccessError,
"No frame can be obtained from the provided document.");
return false;
}
document->updateStyleAndLayoutIgnorePendingStylesheets();
return document->frame()->spellChecker().selectionStartHasMarkerFor(
DocumentMarker::Grammar, from, length);
}
unsigned Internals::numberOfScrollableAreas(Document* document) {
DCHECK(document);
if (!document->frame())
return 0;
unsigned count = 0;
LocalFrame* frame = document->frame();
if (frame->view()->scrollableAreas())
count += frame->view()->scrollableAreas()->size();
for (Frame* child = frame->tree().firstChild(); child;
child = child->tree().nextSibling()) {
if (child->isLocalFrame() && toLocalFrame(child)->view() &&
toLocalFrame(child)->view()->scrollableAreas())
count += toLocalFrame(child)->view()->scrollableAreas()->size();
}
return count;
}
bool Internals::isPageBoxVisible(Document* document, int pageNumber) {
DCHECK(document);
return document->isPageBoxVisible(pageNumber);
}
String Internals::layerTreeAsText(Document* document,
ExceptionState& exceptionState) const {
return layerTreeAsText(document, 0, exceptionState);
}
String Internals::elementLayerTreeAsText(Element* element,
ExceptionState& exceptionState) const {
DCHECK(element);
FrameView* frameView = element->document().view();
frameView->updateAllLifecyclePhases();
return elementLayerTreeAsText(element, 0, exceptionState);
}
bool Internals::scrollsWithRespectTo(Element* element1,
Element* element2,
ExceptionState& exceptionState) {
DCHECK(element1 && element2);
element1->document().view()->updateAllLifecyclePhases();
LayoutObject* layoutObject1 = element1->layoutObject();
LayoutObject* layoutObject2 = element2->layoutObject();
if (!layoutObject1 || !layoutObject1->isBox()) {
exceptionState.throwDOMException(
InvalidAccessError,
layoutObject1
? "The first provided element's layoutObject is not a box."
: "The first provided element has no layoutObject.");
return false;
}
if (!layoutObject2 || !layoutObject2->isBox()) {
exceptionState.throwDOMException(
InvalidAccessError,
layoutObject2
? "The second provided element's layoutObject is not a box."
: "The second provided element has no layoutObject.");
return false;
}
PaintLayer* layer1 = toLayoutBox(layoutObject1)->layer();
PaintLayer* layer2 = toLayoutBox(layoutObject2)->layer();
if (!layer1 || !layer2) {
exceptionState.throwDOMException(
InvalidAccessError,
String::format(
"No PaintLayer can be obtained from the %s provided element.",
layer1 ? "second" : "first"));
return false;
}
return layer1->scrollsWithRespectTo(layer2);
}
String Internals::layerTreeAsText(Document* document,
unsigned flags,
ExceptionState& exceptionState) const {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return String();
}
document->view()->updateAllLifecyclePhases();
return document->frame()->layerTreeAsText(flags);
}
String Internals::elementLayerTreeAsText(Element* element,
unsigned flags,
ExceptionState& exceptionState) const {
DCHECK(element);
element->document().updateStyleAndLayout();
LayoutObject* layoutObject = element->layoutObject();
if (!layoutObject || !layoutObject->isBox()) {
exceptionState.throwDOMException(
InvalidAccessError,
layoutObject ? "The provided element's layoutObject is not a box."
: "The provided element has no layoutObject.");
return String();
}
PaintLayer* layer = toLayoutBox(layoutObject)->layer();
if (!layer || !layer->hasCompositedLayerMapping() ||
!layer->compositedLayerMapping()->mainGraphicsLayer()) {
// Don't raise exception in these cases which may be normally used in tests.
return String();
}
return layer->compositedLayerMapping()->mainGraphicsLayer()->layerTreeAsText(
flags);
}
String Internals::scrollingStateTreeAsText(Document*) const {
return String();
}
String Internals::mainThreadScrollingReasons(
Document* document,
ExceptionState& exceptionState) const {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return String();
}
document->frame()->view()->updateAllLifecyclePhases();
return document->frame()->view()->mainThreadScrollingReasonsAsText();
}
ClientRectList* Internals::nonFastScrollableRects(
Document* document,
ExceptionState& exceptionState) const {
DCHECK(document);
if (!document->frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return nullptr;
}
Page* page = document->page();
if (!page)
return nullptr;
return page->nonFastScrollableRects(document->frame());
}
void Internals::evictAllResources() const {
memoryCache()->evictResources();
}
String Internals::counterValue(Element* element) {
if (!element)
return String();
return counterValueForElement(element);
}
int Internals::pageNumber(Element* element,
float pageWidth,
float pageHeight,
ExceptionState& exceptionState) {
if (!element)
return 0;
if (pageWidth <= 0 || pageHeight <= 0) {
exceptionState.throwDOMException(
V8TypeError, "Page width and height must be larger than 0.");
return 0;
}
return PrintContext::pageNumberForElement(element,
FloatSize(pageWidth, pageHeight));
}
Vector<String> Internals::iconURLs(Document* document,
int iconTypesMask) const {
Vector<IconURL> iconURLs = document->iconURLs(iconTypesMask);
Vector<String> array;
for (auto& iconURL : iconURLs)
array.push_back(iconURL.m_iconURL.getString());
return array;
}
Vector<String> Internals::shortcutIconURLs(Document* document) const {
return iconURLs(document, Favicon);
}
Vector<String> Internals::allIconURLs(Document* document) const {
return iconURLs(document, Favicon | TouchIcon | TouchPrecomposedIcon);
}
int Internals::numberOfPages(float pageWidth,
float pageHeight,
ExceptionState& exceptionState) {
if (!frame())
return -1;
if (pageWidth <= 0 || pageHeight <= 0) {
exceptionState.throwDOMException(
V8TypeError, "Page width and height must be larger than 0.");
return -1;
}
return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
}
String Internals::pageProperty(String propertyName,
int pageNumber,
ExceptionState& exceptionState) const {
if (!frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"No frame is available.");
return String();
}
return PrintContext::pageProperty(frame(), propertyName.utf8().data(),
pageNumber);
}
String Internals::pageSizeAndMarginsInPixels(
int pageNumber,
int width,
int height,
int marginTop,
int marginRight,
int marginBottom,
int marginLeft,
ExceptionState& exceptionState) const {
if (!frame()) {
exceptionState.throwDOMException(InvalidAccessError,
"No frame is available.");
return String();
}
return PrintContext::pageSizeAndMarginsInPixels(
frame(), pageNumber, width, height, marginTop, marginRight, marginBottom,
marginLeft);
}
float Internals::pageScaleFactor(ExceptionState& exceptionState) {
if (!m_document->page()) {
exceptionState.throwDOMException(
InvalidAccessError, "The document's page cannot be retrieved.");
return 0;
}
Page* page = m_document->page();
return page->frameHost().visualViewport().pageScale();
}
void Internals::setPageScaleFactor(float scaleFactor,
ExceptionState& exceptionState) {
if (scaleFactor <= 0)
return;
if (!m_document->page()) {
exceptionState.throwDOMException(
InvalidAccessError, "The document's page cannot be retrieved.");
return;
}
Page* page = m_document->page();
page->frameHost().visualViewport().setScale(scaleFactor);
}
void Internals::setPageScaleFactorLimits(float minScaleFactor,
float maxScaleFactor,
ExceptionState& exceptionState) {
if (!m_document->page()) {
exceptionState.throwDOMException(
InvalidAccessError, "The document's page cannot be retrieved.");
return;
}
Page* page = m_document->page();
page->frameHost().setDefaultPageScaleLimits(minScaleFactor, maxScaleFactor);
}
bool Internals::magnifyScaleAroundAnchor(float scaleFactor, float x, float y) {
if (!frame())
return false;
return frame()->host()->visualViewport().magnifyScaleAroundAnchor(
scaleFactor, FloatPoint(x, y));
}
void Internals::setIsCursorVisible(Document* document,
bool isVisible,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->page()) {
exceptionState.throwDOMException(InvalidAccessError,
"No context document can be obtained.");
return;
}
document->page()->setIsCursorVisible(isVisible);
}
String Internals::effectivePreload(HTMLMediaElement* mediaElement) {
DCHECK(mediaElement);
return mediaElement->effectivePreload();
}
void Internals::mediaPlayerRemoteRouteAvailabilityChanged(
HTMLMediaElement* mediaElement,
bool available) {
DCHECK(mediaElement);
mediaElement->remoteRouteAvailabilityChanged(
available ? WebRemotePlaybackAvailability::DeviceAvailable
: WebRemotePlaybackAvailability::SourceNotSupported);
}
void Internals::mediaPlayerPlayingRemotelyChanged(
HTMLMediaElement* mediaElement,
bool remote) {
DCHECK(mediaElement);
if (remote)
mediaElement->connectedToRemoteDevice();
else
mediaElement->disconnectedFromRemoteDevice();
}
void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(
const String& scheme) {
SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(scheme);
}
void Internals::registerURLSchemeAsBypassingContentSecurityPolicy(
const String& scheme,
const Vector<String>& policyAreas) {
uint32_t policyAreasEnum = SchemeRegistry::PolicyAreaNone;
for (const auto& policyArea : policyAreas) {
if (policyArea == "img")
policyAreasEnum |= SchemeRegistry::PolicyAreaImage;
else if (policyArea == "style")
policyAreasEnum |= SchemeRegistry::PolicyAreaStyle;
}
SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy(
scheme, static_cast<SchemeRegistry::PolicyAreas>(policyAreasEnum));
}
void Internals::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(
const String& scheme) {
SchemeRegistry::removeURLSchemeRegisteredAsBypassingContentSecurityPolicy(
scheme);
}
TypeConversions* Internals::typeConversions() const {
return TypeConversions::create();
}
DictionaryTest* Internals::dictionaryTest() const {
return DictionaryTest::create();
}
UnionTypesTest* Internals::unionTypesTest() const {
return UnionTypesTest::create();
}
OriginTrialsTest* Internals::originTrialsTest() const {
return OriginTrialsTest::create();
}
CallbackFunctionTest* Internals::callbackFunctionTest() const {
return CallbackFunctionTest::create();
}
Vector<String> Internals::getReferencedFilePaths() const {
if (!frame())
return Vector<String>();
return frame()->loader().currentItem()->getReferencedFilePaths();
}
void Internals::startStoringCompositedLayerDebugInfo(
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
FrameView* frameView = document->view();
frameView->setIsStoringCompositedLayerDebugInfo(true);
frameView->updateAllLifecyclePhases();
}
void Internals::stopStoringCompositedLayerDebugInfo(
Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
FrameView* frameView = document->view();
frameView->setIsStoringCompositedLayerDebugInfo(false);
frameView->updateAllLifecyclePhases();
}
void Internals::startTrackingRepaints(Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
FrameView* frameView = document->view();
frameView->updateAllLifecyclePhases();
frameView->setTracksPaintInvalidations(true);
}
void Internals::stopTrackingRepaints(Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
FrameView* frameView = document->view();
frameView->updateAllLifecyclePhases();
frameView->setTracksPaintInvalidations(false);
}
void Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(
Node* node,
ExceptionState& exceptionState) {
Document* document = nullptr;
if (!node) {
document = m_document;
} else if (node->isDocumentNode()) {
document = toDocument(node);
} else if (isHTMLIFrameElement(*node)) {
document = toHTMLIFrameElement(*node).contentDocument();
}
if (!document) {
exceptionState.throwTypeError(
"The node provided is neither a document nor an IFrame.");
return;
}
document->updateStyleAndLayoutIgnorePendingStylesheets(
Document::RunPostLayoutTasksSynchronously);
}
void Internals::forceFullRepaint(Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
LayoutViewItem layoutViewItem = document->layoutViewItem();
if (!layoutViewItem.isNull())
layoutViewItem.invalidatePaintForViewAndCompositedLayers();
}
ClientRectList* Internals::draggableRegions(Document* document,
ExceptionState& exceptionState) {
return annotatedRegions(document, true, exceptionState);
}
ClientRectList* Internals::nonDraggableRegions(Document* document,
ExceptionState& exceptionState) {
return annotatedRegions(document, false, exceptionState);
}
ClientRectList* Internals::annotatedRegions(Document* document,
bool draggable,
ExceptionState& exceptionState) {
DCHECK(document);
if (!document->view()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return ClientRectList::create();
}
document->updateStyleAndLayout();
document->view()->updateDocumentAnnotatedRegions();
Vector<AnnotatedRegionValue> regions = document->annotatedRegions();
Vector<FloatQuad> quads;
for (size_t i = 0; i < regions.size(); ++i) {
if (regions[i].draggable == draggable)
quads.push_back(FloatQuad(FloatRect(regions[i].bounds)));
}
return ClientRectList::create(quads);
}
static const char* cursorTypeToString(Cursor::Type cursorType) {
switch (cursorType) {
case Cursor::Pointer:
return "Pointer";
case Cursor::Cross:
return "Cross";
case Cursor::Hand:
return "Hand";
case Cursor::IBeam:
return "IBeam";
case Cursor::Wait:
return "Wait";
case Cursor::Help:
return "Help";
case Cursor::EastResize:
return "EastResize";
case Cursor::NorthResize:
return "NorthResize";
case Cursor::NorthEastResize:
return "NorthEastResize";
case Cursor::NorthWestResize:
return "NorthWestResize";
case Cursor::SouthResize:
return "SouthResize";
case Cursor::SouthEastResize:
return "SouthEastResize";
case Cursor::SouthWestResize:
return "SouthWestResize";
case Cursor::WestResize:
return "WestResize";
case Cursor::NorthSouthResize:
return "NorthSouthResize";
case Cursor::EastWestResize:
return "EastWestResize";
case Cursor::NorthEastSouthWestResize:
return "NorthEastSouthWestResize";
case Cursor::NorthWestSouthEastResize:
return "NorthWestSouthEastResize";
case Cursor::ColumnResize:
return "ColumnResize";
case Cursor::RowResize:
return "RowResize";
case Cursor::MiddlePanning:
return "MiddlePanning";
case Cursor::EastPanning:
return "EastPanning";
case Cursor::NorthPanning:
return "NorthPanning";
case Cursor::NorthEastPanning:
return "NorthEastPanning";
case Cursor::NorthWestPanning:
return "NorthWestPanning";
case Cursor::SouthPanning:
return "SouthPanning";
case Cursor::SouthEastPanning:
return "SouthEastPanning";
case Cursor::SouthWestPanning:
return "SouthWestPanning";
case Cursor::WestPanning:
return "WestPanning";
case Cursor::Move:
return "Move";
case Cursor::VerticalText:
return "VerticalText";
case Cursor::Cell:
return "Cell";
case Cursor::ContextMenu:
return "ContextMenu";
case Cursor::Alias:
return "Alias";
case Cursor::Progress:
return "Progress";
case Cursor::NoDrop:
return "NoDrop";
case Cursor::Copy:
return "Copy";
case Cursor::None:
return "None";
case Cursor::NotAllowed:
return "NotAllowed";
case Cursor::ZoomIn:
return "ZoomIn";
case Cursor::ZoomOut:
return "ZoomOut";
case Cursor::Grab:
return "Grab";
case Cursor::Grabbing:
return "Grabbing";
case Cursor::Custom:
return "Custom";
}
ASSERT_NOT_REACHED();
return "UNKNOWN";
}
String Internals::getCurrentCursorInfo() {
if (!frame())
return String();
Cursor cursor = frame()->page()->chromeClient().lastSetCursorForTesting();
StringBuilder result;
result.append("type=");
result.append(cursorTypeToString(cursor.getType()));
result.append(" hotSpot=");
result.appendNumber(cursor.hotSpot().x());
result.append(',');
result.appendNumber(cursor.hotSpot().y());
if (cursor.getImage()) {
IntSize size = cursor.getImage()->size();
result.append(" image=");
result.appendNumber(size.width());
result.append('x');
result.appendNumber(size.height());
}
if (cursor.imageScaleFactor() != 1) {
result.append(" scale=");
result.appendNumber(cursor.imageScaleFactor(), 8);
}
return result.toString();
}
bool Internals::cursorUpdatePending() const {
if (!frame())
return false;
return frame()->eventHandler().cursorUpdatePending();
}
DOMArrayBuffer* Internals::serializeObject(
PassRefPtr<SerializedScriptValue> value) const {
String stringValue = value->toWireString();
DOMArrayBuffer* buffer =
DOMArrayBuffer::createUninitialized(stringValue.length(), sizeof(UChar));
stringValue.copyTo(static_cast<UChar*>(buffer->data()), 0,
stringValue.length());
return buffer;
}
PassRefPtr<SerializedScriptValue> Internals::deserializeBuffer(
DOMArrayBuffer* buffer) const {
String value(static_cast<const UChar*>(buffer->data()),
buffer->byteLength() / sizeof(UChar));
return SerializedScriptValue::create(value);
}
void Internals::forceReload(bool bypassCache) {
if (!frame())
return;
frame()->reload(
bypassCache ? FrameLoadTypeReloadBypassingCache : FrameLoadTypeReload,
ClientRedirectPolicy::NotClientRedirect);
}
ClientRect* Internals::selectionBounds(ExceptionState& exceptionState) {
if (!frame()) {
exceptionState.throwDOMException(
InvalidAccessError, "The document's frame cannot be retrieved.");
return nullptr;
}
return ClientRect::create(FloatRect(frame()->selection().bounds()));
}
String Internals::markerTextForListItem(Element* element) {
DCHECK(element);
return blink::markerTextForListItem(element);
}
String Internals::getImageSourceURL(Element* element) {
DCHECK(element);
return element->imageSourceURL();
}
String Internals::selectMenuListText(HTMLSelectElement* select) {
DCHECK(select);
LayoutObject* layoutObject = select->layoutObject();
if (!layoutObject || !layoutObject->isMenuList())
return String();
LayoutMenuListItem menuListItem =
LayoutMenuListItem(toLayoutMenuList(layoutObject));
return menuListItem.text();
}
bool Internals::isSelectPopupVisible(Node* node) {
DCHECK(node);
if (!isHTMLSelectElement(*node))
return false;
return toHTMLSelectElement(*node).popupIsVisible();
}
bool Internals::selectPopupItemStyleIsRtl(Node* node, int itemIndex) {
if (!node || !isHTMLSelectElement(*node))
return false;
HTMLSelectElement& select = toHTMLSelectElement(*node);
if (itemIndex < 0 ||
static_cast<size_t>(itemIndex) >= select.listItems().size())
return false;
const ComputedStyle* itemStyle =
select.itemComputedStyle(*select.listItems()[itemIndex]);
return itemStyle && itemStyle->direction() == TextDirection::kRtl;
}
int Internals::selectPopupItemStyleFontHeight(Node* node, int itemIndex) {
if (!node || !isHTMLSelectElement(*node))
return false;
HTMLSelectElement& select = toHTMLSelectElement(*node);
if (itemIndex < 0 ||
static_cast<size_t>(itemIndex) >= select.listItems().size())
return false;
const ComputedStyle* itemStyle =
select.itemComputedStyle(*select.listItems()[itemIndex]);
if (itemStyle) {
const SimpleFontData* fontData = itemStyle->font().primaryFont();
DCHECK(fontData);
return fontData ? fontData->getFontMetrics().height() : 0;
}
return 0;
}
void Internals::resetTypeAheadSession(HTMLSelectElement* select) {
DCHECK(select);
select->resetTypeAheadSessionForTesting();
}
bool Internals::loseSharedGraphicsContext3D() {
std::unique_ptr<WebGraphicsContext3DProvider> sharedProvider =
WTF::wrapUnique(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider());
if (!sharedProvider)
return false;
gpu::gles2::GLES2Interface* sharedGL = sharedProvider->contextGL();
sharedGL->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_EXT,
GL_INNOCENT_CONTEXT_RESET_EXT);
// To prevent tests that call loseSharedGraphicsContext3D from being
// flaky, we call finish so that the context is guaranteed to be lost
// synchronously (i.e. before returning).
sharedGL->Finish();
return true;
}
void Internals::forceCompositingUpdate(Document* document,
ExceptionState& exceptionState) {
DCHECK(document);
if (document->layoutViewItem().isNull()) {
exceptionState.throwDOMException(InvalidAccessError,
"The document provided is invalid.");
return;
}
document->frame()->view()->updateAllLifecyclePhases();
}
void Internals::setZoomFactor(float factor) {
if (!frame())
return;
frame()->setPageZoomFactor(factor);
}
void Internals::setShouldRevealPassword(Element* element,
bool reveal,
ExceptionState& exceptionState) {
DCHECK(element);
if (!isHTMLInputElement(element)) {
exceptionState.throwDOMException(InvalidNodeTypeError,
"The element provided is not an INPUT.");
return;
}
return toHTMLInputElement(*element).setShouldRevealPassword(reveal);
}
namespace {
class AddOneFunction : public ScriptFunction {
public:
static v8::Local<v8::Function> createFunction(ScriptState* scriptState) {
AddOneFunction* self = new AddOneFunction(scriptState);
return self->bindToV8Function();
}
private:
explicit AddOneFunction(ScriptState* scriptState)
: ScriptFunction(scriptState) {}
ScriptValue call(ScriptValue value) override {
v8::Local<v8::Value> v8Value = value.v8Value();
DCHECK(v8Value->IsNumber());
int intValue = v8Value.As<v8::Integer>()->Value();
return ScriptValue(
getScriptState(),
v8::Integer::New(getScriptState()->isolate(), intValue + 1));
}
};
} // namespace
ScriptPromise Internals::createResolvedPromise(ScriptState* scriptState,
ScriptValue value) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
resolver->resolve(value);
return promise;
}
ScriptPromise Internals::createRejectedPromise(ScriptState* scriptState,
ScriptValue value) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
resolver->reject(value);
return promise;
}
ScriptPromise Internals::addOneToPromise(ScriptState* scriptState,
ScriptPromise promise) {
return promise.then(AddOneFunction::createFunction(scriptState));
}
ScriptPromise Internals::promiseCheck(ScriptState* scriptState,
long arg1,
bool arg2,
const Dictionary& arg3,
const String& arg4,
const Vector<String>& arg5,
ExceptionState& exceptionState) {
if (arg2)
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
exceptionState.throwDOMException(InvalidStateError,
"Thrown from the native implementation.");
return ScriptPromise();
}
ScriptPromise Internals::promiseCheckWithoutExceptionState(
ScriptState* scriptState,
const Dictionary& arg1,
const String& arg2,
const Vector<String>& arg3) {
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
}
ScriptPromise Internals::promiseCheckRange(ScriptState* scriptState,
long arg1) {
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
}
ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState,
Location*) {
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
}
ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState,
Document*) {
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
}
ScriptPromise Internals::promiseCheckOverload(ScriptState* scriptState,
Location*,
long,
long) {
return ScriptPromise::cast(scriptState,
v8String(scriptState->isolate(), "done"));
}
DEFINE_TRACE(Internals) {
visitor->trace(m_runtimeFlags);
visitor->trace(m_document);
}
void Internals::setValueForUser(HTMLInputElement* element,
const String& value) {
element->setValueForUser(value);
}
String Internals::textSurroundingNode(Node* node,
int x,
int y,
unsigned long maxLength) {
if (!node)
return String();
// VisiblePosition and SurroundingText must be created with clean layout.
node->document().updateStyleAndLayoutIgnorePendingStylesheets();
DocumentLifecycle::DisallowTransitionScope disallowTransition(
node->document().lifecycle());
if (!node->layoutObject())
return String();
blink::WebPoint point(x, y);
SurroundingText surroundingText(
createVisiblePosition(
node->layoutObject()->positionForPoint(static_cast<IntPoint>(point)))
.deepEquivalent()
.parentAnchoredEquivalent(),
maxLength);
return surroundingText.content();
}
void Internals::setFocused(bool focused) {
if (!frame())
return;
frame()->page()->focusController().setFocused(focused);
}
void Internals::setInitialFocus(bool reverse) {
if (!frame())
return;
frame()->document()->clearFocusedElement();
frame()->page()->focusController().setInitialFocus(
reverse ? WebFocusTypeBackward : WebFocusTypeForward);
}
bool Internals::ignoreLayoutWithPendingStylesheets(Document* document) {
DCHECK(document);
return document->ignoreLayoutWithPendingStylesheets();
}
void Internals::setNetworkConnectionInfoOverride(
bool onLine,
const String& type,
double downlinkMaxMbps,
ExceptionState& exceptionState) {
WebConnectionType webtype;
if (type == "cellular2g") {
webtype = WebConnectionTypeCellular2G;
} else if (type == "cellular3g") {
webtype = WebConnectionTypeCellular3G;
} else if (type == "cellular4g") {
webtype = WebConnectionTypeCellular4G;
} else if (type == "bluetooth") {
webtype = WebConnectionTypeBluetooth;
} else if (type == "ethernet") {
webtype = WebConnectionTypeEthernet;
} else if (type == "wifi") {
webtype = WebConnectionTypeWifi;
} else if (type == "wimax") {
webtype = WebConnectionTypeWimax;
} else if (type == "other") {
webtype = WebConnectionTypeOther;
} else if (type == "none") {
webtype = WebConnectionTypeNone;
} else if (type == "unknown") {
webtype = WebConnectionTypeUnknown;
} else {
exceptionState.throwDOMException(
NotFoundError,
ExceptionMessages::failedToEnumerate("connection type", type));
return;
}
networkStateNotifier().setOverride(onLine, webtype, downlinkMaxMbps);
}
void Internals::clearNetworkConnectionInfoOverride() {
networkStateNotifier().clearOverride();
}
unsigned Internals::countHitRegions(CanvasRenderingContext* context) {
return context->hitRegionsCount();
}
bool Internals::isInCanvasFontCache(Document* document,
const String& fontString) {
return document->canvasFontCache()->isInCache(fontString);
}
unsigned Internals::canvasFontCacheMaxFonts() {
return CanvasFontCache::maxFonts();
}
void Internals::setScrollChain(ScrollState* scrollState,
const HeapVector<Member<Element>>& elements,
ExceptionState&) {
std::deque<int> scrollChain;
for (size_t i = 0; i < elements.size(); ++i)
scrollChain.push_back(DOMNodeIds::idForNode(elements[i].get()));
scrollState->setScrollChain(scrollChain);
}
void Internals::forceBlinkGCWithoutV8GC() {
ThreadState::current()->setGCState(ThreadState::FullGCScheduled);
}
String Internals::selectedHTMLForClipboard() {
if (!frame())
return String();
// Selection normalization and markup generation require clean layout.
frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
return frame()->selection().selectedHTMLForClipboard();
}
String Internals::selectedTextForClipboard() {
if (!frame() || !frame()->document())
return String();
// Clean layout is required for extracting plain text from selection.
frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
return frame()->selection().selectedTextForClipboard();
}
void Internals::setVisualViewportOffset(int x, int y) {
if (!frame())
return;
frame()->host()->visualViewport().setLocation(FloatPoint(x, y));
}
int Internals::visualViewportHeight() {
if (!frame())
return 0;
return expandedIntSize(frame()->host()->visualViewport().visibleRect().size())
.height();
}
int Internals::visualViewportWidth() {
if (!frame())
return 0;
return expandedIntSize(frame()->host()->visualViewport().visibleRect().size())
.width();
}
float Internals::visualViewportScrollX() {
if (!frame())
return 0;
return frame()->view()->getScrollableArea()->getScrollOffset().width();
}
float Internals::visualViewportScrollY() {
if (!frame())
return 0;
return frame()->view()->getScrollableArea()->getScrollOffset().height();
}
ValueIterable<int>::IterationSource* Internals::startIteration(
ScriptState*,
ExceptionState&) {
return new InternalsIterationSource();
}
bool Internals::isUseCounted(Document* document, int useCounterId) {
if (useCounterId < 0 || useCounterId >= UseCounter::NumberOfFeatures)
return false;
return UseCounter::isCounted(*document,
static_cast<UseCounter::Feature>(useCounterId));
}
bool Internals::isCSSPropertyUseCounted(Document* document,
const String& propertyName) {
return UseCounter::isCounted(*document, propertyName);
}
String Internals::unscopableAttribute() {
return "unscopableAttribute";
}
String Internals::unscopableMethod() {
return "unscopableMethod";
}
ClientRectList* Internals::focusRingRects(Element* element) {
Vector<LayoutRect> rects;
if (element && element->layoutObject())
element->layoutObject()->addOutlineRects(
rects, LayoutPoint(), LayoutObject::IncludeBlockVisualOverflow);
return ClientRectList::create(rects);
}
ClientRectList* Internals::outlineRects(Element* element) {
Vector<LayoutRect> rects;
if (element && element->layoutObject())
element->layoutObject()->addOutlineRects(
rects, LayoutPoint(), LayoutObject::DontIncludeBlockVisualOverflow);
return ClientRectList::create(rects);
}
void Internals::setCapsLockState(bool enabled) {
KeyboardEventManager::setCurrentCapsLockState(
enabled ? OverrideCapsLockState::On : OverrideCapsLockState::Off);
}
bool Internals::setScrollbarVisibilityInScrollableArea(Node* node,
bool visible) {
if (ScrollableArea* scrollableArea = scrollableAreaForNode(node)) {
scrollableArea->setScrollbarsHidden(!visible);
scrollableArea->scrollAnimator().setScrollbarsVisibleForTesting(visible);
return ScrollbarTheme::theme().usesOverlayScrollbars();
}
return false;
}
double Internals::monotonicTimeToZeroBasedDocumentTime(
double platformTime,
ExceptionState& exceptionState) {
return m_document->loader()->timing().monotonicTimeToZeroBasedDocumentTime(
platformTime);
}
void Internals::setMediaElementNetworkState(HTMLMediaElement* mediaElement,
int state) {
DCHECK(mediaElement);
DCHECK(state >= WebMediaPlayer::NetworkState::NetworkStateEmpty);
DCHECK(state <= WebMediaPlayer::NetworkState::NetworkStateDecodeError);
mediaElement->setNetworkState(
static_cast<WebMediaPlayer::NetworkState>(state));
}
String Internals::getScrollAnimationState(Node* node) const {
if (ScrollableArea* scrollableArea = scrollableAreaForNode(node))
return scrollableArea->scrollAnimator().runStateAsText();
return String();
}
String Internals::getProgrammaticScrollAnimationState(Node* node) const {
if (ScrollableArea* scrollableArea = scrollableAreaForNode(node))
return scrollableArea->programmaticScrollAnimator().runStateAsText();
return String();
}
ClientRect* Internals::visualRect(Node* node) {
if (!node || !node->layoutObject())
return ClientRect::create();
return ClientRect::create(FloatRect(node->layoutObject()->visualRect()));
}
void Internals::crash() {
CHECK(false) << "Intentional crash";
}
void Internals::setIsLowEndDevice(bool isLowEndDevice) {
MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice);
}
} // namespace blink
|