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
|
/*
* Copyright (C) 2010, 2015 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 INC. 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 INC. 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; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (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 "config.h"
#include "WKPage.h"
#include "WKPagePrivate.h"
#include "APIArray.h"
#include "APIContextMenuClient.h"
#include "APIData.h"
#include "APIDictionary.h"
#include "APIFindClient.h"
#include "APIFindMatchesClient.h"
#include "APIFrameHandle.h"
#include "APIFrameInfo.h"
#include "APIGeometry.h"
#include "APIHitTestResult.h"
#include "APILoaderClient.h"
#include "APINavigationAction.h"
#include "APINavigationClient.h"
#include "APINavigationResponse.h"
#include "APIOpenPanelParameters.h"
#include "APIPageConfiguration.h"
#include "APIPolicyClient.h"
#include "APISessionState.h"
#include "APIUIClient.h"
#include "APIWebsitePolicies.h"
#include "APIWindowFeatures.h"
#include "AuthenticationChallengeProxy.h"
#include "LegacySessionStateCoding.h"
#include "Logging.h"
#include "NativeWebKeyboardEvent.h"
#include "NativeWebWheelEvent.h"
#include "NavigationActionData.h"
#include "PluginInformation.h"
#include "PrintInfo.h"
#include "WKAPICast.h"
#include "WKPagePolicyClientInternal.h"
#include "WKPageRenderingProgressEventsInternal.h"
#include "WKPluginInformation.h"
#include "WebBackForwardList.h"
#include "WebFormClient.h"
#include "WebImage.h"
#include "WebInspectorProxy.h"
#include "WebOpenPanelResultListenerProxy.h"
#include "WebPageGroup.h"
#include "WebPageMessages.h"
#include "WebPageProxy.h"
#include "WebProcessPool.h"
#include "WebProcessProxy.h"
#include "WebProtectionSpace.h"
#include <WebCore/Page.h>
#include <WebCore/SecurityOriginData.h>
#include <WebCore/SerializedCryptoKeyWrap.h>
#include <WebCore/WindowFeatures.h>
#ifdef __BLOCKS__
#include <Block.h>
#endif
#if ENABLE(CONTEXT_MENUS)
#include "WebContextMenuItem.h"
#endif
#if ENABLE(VIBRATION)
#include "WebVibrationProxy.h"
#endif
#if ENABLE(MEDIA_SESSION)
#include "WebMediaSessionMetadata.h"
#include <WebCore/MediaSessionEvents.h>
#endif
using namespace WebCore;
using namespace WebKit;
namespace API {
template<> struct ClientTraits<WKPageLoaderClientBase> {
typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
};
template<> struct ClientTraits<WKPageNavigationClientBase> {
typedef std::tuple<WKPageNavigationClientV0> Versions;
};
template<> struct ClientTraits<WKPagePolicyClientBase> {
typedef std::tuple<WKPagePolicyClientV0, WKPagePolicyClientV1, WKPagePolicyClientInternal> Versions;
};
template<> struct ClientTraits<WKPageUIClientBase> {
typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7, WKPageUIClientV8, WKPageUIClientV9> Versions;
};
#if ENABLE(CONTEXT_MENUS)
template<> struct ClientTraits<WKPageContextMenuClientBase> {
typedef std::tuple<WKPageContextMenuClientV0, WKPageContextMenuClientV1, WKPageContextMenuClientV2, WKPageContextMenuClientV3, WKPageContextMenuClientV4> Versions;
};
#endif
template<> struct ClientTraits<WKPageFindClientBase> {
typedef std::tuple<WKPageFindClientV0> Versions;
};
template<> struct ClientTraits<WKPageFindMatchesClientBase> {
typedef std::tuple<WKPageFindMatchesClientV0> Versions;
};
}
WKTypeID WKPageGetTypeID()
{
return toAPI(WebPageProxy::APIType);
}
WKContextRef WKPageGetContext(WKPageRef pageRef)
{
return toAPI(&toImpl(pageRef)->process().processPool());
}
WKPageGroupRef WKPageGetPageGroup(WKPageRef pageRef)
{
return toAPI(&toImpl(pageRef)->pageGroup());
}
WKPageConfigurationRef WKPageCopyPageConfiguration(WKPageRef pageRef)
{
return toAPI(&toImpl(pageRef)->configuration().copy().leakRef());
}
void WKPageLoadURL(WKPageRef pageRef, WKURLRef URLRef)
{
toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)));
}
void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef pageRef, WKURLRef URLRef, bool shouldOpenExternalURLs)
{
ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLs ? ShouldOpenExternalURLsPolicy::ShouldAllow : ShouldOpenExternalURLsPolicy::ShouldNotAllow;
toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), shouldOpenExternalURLsPolicy);
}
void WKPageLoadURLWithUserData(WKPageRef pageRef, WKURLRef URLRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadRequest(URL(URL(), toWTFString(URLRef)), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
}
void WKPageLoadURLRequest(WKPageRef pageRef, WKURLRequestRef urlRequestRef)
{
toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest());
}
void WKPageLoadURLRequestWithUserData(WKPageRef pageRef, WKURLRequestRef urlRequestRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadRequest(toImpl(urlRequestRef)->resourceRequest(), ShouldOpenExternalURLsPolicy::ShouldNotAllow, toImpl(userDataRef));
}
void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
{
toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
}
void WKPageLoadFileWithUserData(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL), toImpl(userDataRef));
}
void WKPageLoadData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef)
{
toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef));
}
void WKPageLoadDataWithUserData(WKPageRef pageRef, WKDataRef dataRef, WKStringRef MIMETypeRef, WKStringRef encodingRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadData(toImpl(dataRef), toWTFString(MIMETypeRef), toWTFString(encodingRef), toWTFString(baseURLRef), toImpl(userDataRef));
}
void WKPageLoadHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef)
{
toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef));
}
void WKPageLoadHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toImpl(userDataRef));
}
void WKPageLoadAlternateHTMLString(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef)
{
toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef));
}
void WKPageLoadAlternateHTMLStringWithUserData(WKPageRef pageRef, WKStringRef htmlStringRef, WKURLRef baseURLRef, WKURLRef unreachableURLRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadAlternateHTMLString(toWTFString(htmlStringRef), toWTFString(baseURLRef), toWTFString(unreachableURLRef), toImpl(userDataRef));
}
void WKPageLoadPlainTextString(WKPageRef pageRef, WKStringRef plainTextStringRef)
{
toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef));
}
void WKPageLoadPlainTextStringWithUserData(WKPageRef pageRef, WKStringRef plainTextStringRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadPlainTextString(toWTFString(plainTextStringRef), toImpl(userDataRef));
}
void WKPageLoadWebArchiveData(WKPageRef pageRef, WKDataRef webArchiveDataRef)
{
toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef));
}
void WKPageLoadWebArchiveDataWithUserData(WKPageRef pageRef, WKDataRef webArchiveDataRef, WKTypeRef userDataRef)
{
toImpl(pageRef)->loadWebArchiveData(toImpl(webArchiveDataRef), toImpl(userDataRef));
}
void WKPageStopLoading(WKPageRef pageRef)
{
toImpl(pageRef)->stopLoading();
}
void WKPageReload(WKPageRef pageRef)
{
const bool reloadFromOrigin = false;
const bool contentBlockersEnabled = true;
toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
}
void WKPageReloadWithoutContentBlockers(WKPageRef pageRef)
{
const bool reloadFromOrigin = false;
const bool contentBlockersEnabled = false;
toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
}
void WKPageReloadFromOrigin(WKPageRef pageRef)
{
const bool reloadFromOrigin = true;
const bool contentBlockersEnabled = true;
toImpl(pageRef)->reload(reloadFromOrigin, contentBlockersEnabled);
}
bool WKPageTryClose(WKPageRef pageRef)
{
return toImpl(pageRef)->tryClose();
}
void WKPageClose(WKPageRef pageRef)
{
toImpl(pageRef)->close();
}
bool WKPageIsClosed(WKPageRef pageRef)
{
return toImpl(pageRef)->isClosed();
}
void WKPageGoForward(WKPageRef pageRef)
{
toImpl(pageRef)->goForward();
}
bool WKPageCanGoForward(WKPageRef pageRef)
{
return toImpl(pageRef)->backForwardList().forwardItem();
}
void WKPageGoBack(WKPageRef pageRef)
{
toImpl(pageRef)->goBack();
}
bool WKPageCanGoBack(WKPageRef pageRef)
{
return toImpl(pageRef)->backForwardList().backItem();
}
void WKPageGoToBackForwardListItem(WKPageRef pageRef, WKBackForwardListItemRef itemRef)
{
toImpl(pageRef)->goToBackForwardItem(toImpl(itemRef));
}
void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
{
toImpl(pageRef)->tryRestoreScrollPosition();
}
WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
{
return toAPI(&toImpl(pageRef)->backForwardList());
}
bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
{
return toImpl(pageRef)->willHandleHorizontalScrollEvents();
}
void WKPageUpdateWebsitePolicies(WKPageRef pageRef, WKWebsitePoliciesRef websitePoliciesRef)
{
toImpl(pageRef)->updateWebsitePolicies(toImpl(websitePoliciesRef)->websitePolicies());
}
WKStringRef WKPageCopyTitle(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->pageLoadState().title());
}
WKFrameRef WKPageGetMainFrame(WKPageRef pageRef)
{
return toAPI(toImpl(pageRef)->mainFrame());
}
WKFrameRef WKPageGetFocusedFrame(WKPageRef pageRef)
{
return toAPI(toImpl(pageRef)->focusedFrame());
}
WKFrameRef WKPageGetFrameSetLargestFrame(WKPageRef pageRef)
{
return toAPI(toImpl(pageRef)->frameSetLargestFrame());
}
uint64_t WKPageGetRenderTreeSize(WKPageRef page)
{
return toImpl(page)->renderTreeSize();
}
WKInspectorRef WKPageGetInspector(WKPageRef pageRef)
{
return toAPI(toImpl(pageRef)->inspector());
}
WKVibrationRef WKPageGetVibration(WKPageRef page)
{
#if ENABLE(VIBRATION)
return toAPI(toImpl(page)->vibration());
#else
UNUSED_PARAM(page);
return 0;
#endif
}
double WKPageGetEstimatedProgress(WKPageRef pageRef)
{
return toImpl(pageRef)->estimatedProgress();
}
WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->userAgent());
}
WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
}
void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
{
toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
}
WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->customUserAgent());
}
void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
{
toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
}
void WKPageSetUserContentExtensionsEnabled(WKPageRef pageRef, bool enabled)
{
// FIXME: Remove this function once it is no longer used.
}
bool WKPageSupportsTextEncoding(WKPageRef pageRef)
{
return toImpl(pageRef)->supportsTextEncoding();
}
WKStringRef WKPageCopyCustomTextEncodingName(WKPageRef pageRef)
{
return toCopiedAPI(toImpl(pageRef)->customTextEncodingName());
}
void WKPageSetCustomTextEncodingName(WKPageRef pageRef, WKStringRef encodingNameRef)
{
toImpl(pageRef)->setCustomTextEncodingName(toWTFString(encodingNameRef));
}
void WKPageTerminate(WKPageRef pageRef)
{
toImpl(pageRef)->terminateProcess();
}
WKStringRef WKPageGetSessionHistoryURLValueType()
{
static API::String& sessionHistoryURLValueType = API::String::create("SessionHistoryURL").leakRef();
return toAPI(&sessionHistoryURLValueType);
}
WKStringRef WKPageGetSessionBackForwardListItemValueType()
{
static API::String& sessionBackForwardListValueType = API::String::create("SessionBackForwardListItem").leakRef();
return toAPI(&sessionBackForwardListValueType);
}
WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
{
// FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
if (filter) {
if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
return false;
if (!filter(pageRef, WKPageGetSessionHistoryURLValueType(), toURLRef(item.originalURL().impl()), context))
return false;
}
return true;
});
if (shouldReturnData)
return toAPI(encodeLegacySessionState(sessionState).leakRef());
return toAPI(&API::SessionState::create(WTFMove(sessionState)).leakRef());
}
static void restoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef, bool navigate)
{
SessionState sessionState;
// FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
if (!decodeLegacySessionState(toImpl(static_cast<WKDataRef>(sessionStateRef))->bytes(), toImpl(static_cast<WKDataRef>(sessionStateRef))->size(), sessionState))
return;
} else {
ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
}
toImpl(pageRef)->restoreFromSessionState(WTFMove(sessionState), navigate);
}
void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
{
restoreFromSessionState(pageRef, sessionStateRef, true);
}
void WKPageRestoreFromSessionStateWithoutNavigation(WKPageRef pageRef, WKTypeRef sessionStateRef)
{
restoreFromSessionState(pageRef, sessionStateRef, false);
}
double WKPageGetTextZoomFactor(WKPageRef pageRef)
{
return toImpl(pageRef)->textZoomFactor();
}
double WKPageGetBackingScaleFactor(WKPageRef pageRef)
{
return toImpl(pageRef)->deviceScaleFactor();
}
void WKPageSetCustomBackingScaleFactor(WKPageRef pageRef, double customScaleFactor)
{
toImpl(pageRef)->setCustomDeviceScaleFactor(customScaleFactor);
}
bool WKPageSupportsTextZoom(WKPageRef pageRef)
{
return toImpl(pageRef)->supportsTextZoom();
}
void WKPageSetTextZoomFactor(WKPageRef pageRef, double zoomFactor)
{
toImpl(pageRef)->setTextZoomFactor(zoomFactor);
}
double WKPageGetPageZoomFactor(WKPageRef pageRef)
{
return toImpl(pageRef)->pageZoomFactor();
}
void WKPageSetPageZoomFactor(WKPageRef pageRef, double zoomFactor)
{
toImpl(pageRef)->setPageZoomFactor(zoomFactor);
}
void WKPageSetPageAndTextZoomFactors(WKPageRef pageRef, double pageZoomFactor, double textZoomFactor)
{
toImpl(pageRef)->setPageAndTextZoomFactors(pageZoomFactor, textZoomFactor);
}
void WKPageSetScaleFactor(WKPageRef pageRef, double scale, WKPoint origin)
{
toImpl(pageRef)->scalePage(scale, toIntPoint(origin));
}
double WKPageGetScaleFactor(WKPageRef pageRef)
{
return toImpl(pageRef)->pageScaleFactor();
}
void WKPageSetUseFixedLayout(WKPageRef pageRef, bool fixed)
{
toImpl(pageRef)->setUseFixedLayout(fixed);
}
void WKPageSetFixedLayoutSize(WKPageRef pageRef, WKSize size)
{
toImpl(pageRef)->setFixedLayoutSize(toIntSize(size));
}
bool WKPageUseFixedLayout(WKPageRef pageRef)
{
return toImpl(pageRef)->useFixedLayout();
}
WKSize WKPageFixedLayoutSize(WKPageRef pageRef)
{
return toAPI(toImpl(pageRef)->fixedLayoutSize());
}
void WKPageListenForLayoutMilestones(WKPageRef pageRef, WKLayoutMilestones milestones)
{
toImpl(pageRef)->listenForLayoutMilestones(toLayoutMilestones(milestones));
}
bool WKPageHasHorizontalScrollbar(WKPageRef pageRef)
{
return toImpl(pageRef)->hasHorizontalScrollbar();
}
bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
{
return toImpl(pageRef)->hasVerticalScrollbar();
}
void WKPageSetSuppressScrollbarAnimations(WKPageRef pageRef, bool suppressAnimations)
{
toImpl(pageRef)->setSuppressScrollbarAnimations(suppressAnimations);
}
bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef pageRef)
{
return toImpl(pageRef)->areScrollbarAnimationsSuppressed();
}
bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
{
return toImpl(pageRef)->isPinnedToLeftSide();
}
bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
{
return toImpl(pageRef)->isPinnedToRightSide();
}
bool WKPageIsPinnedToTopSide(WKPageRef pageRef)
{
return toImpl(pageRef)->isPinnedToTopSide();
}
bool WKPageIsPinnedToBottomSide(WKPageRef pageRef)
{
return toImpl(pageRef)->isPinnedToBottomSide();
}
bool WKPageRubberBandsAtLeft(WKPageRef pageRef)
{
return toImpl(pageRef)->rubberBandsAtLeft();
}
void WKPageSetRubberBandsAtLeft(WKPageRef pageRef, bool rubberBandsAtLeft)
{
toImpl(pageRef)->setRubberBandsAtLeft(rubberBandsAtLeft);
}
bool WKPageRubberBandsAtRight(WKPageRef pageRef)
{
return toImpl(pageRef)->rubberBandsAtRight();
}
void WKPageSetRubberBandsAtRight(WKPageRef pageRef, bool rubberBandsAtRight)
{
toImpl(pageRef)->setRubberBandsAtRight(rubberBandsAtRight);
}
bool WKPageRubberBandsAtTop(WKPageRef pageRef)
{
return toImpl(pageRef)->rubberBandsAtTop();
}
void WKPageSetRubberBandsAtTop(WKPageRef pageRef, bool rubberBandsAtTop)
{
toImpl(pageRef)->setRubberBandsAtTop(rubberBandsAtTop);
}
bool WKPageRubberBandsAtBottom(WKPageRef pageRef)
{
return toImpl(pageRef)->rubberBandsAtBottom();
}
void WKPageSetRubberBandsAtBottom(WKPageRef pageRef, bool rubberBandsAtBottom)
{
toImpl(pageRef)->setRubberBandsAtBottom(rubberBandsAtBottom);
}
bool WKPageVerticalRubberBandingIsEnabled(WKPageRef pageRef)
{
return toImpl(pageRef)->verticalRubberBandingIsEnabled();
}
void WKPageSetEnableVerticalRubberBanding(WKPageRef pageRef, bool enableVerticalRubberBanding)
{
toImpl(pageRef)->setEnableVerticalRubberBanding(enableVerticalRubberBanding);
}
bool WKPageHorizontalRubberBandingIsEnabled(WKPageRef pageRef)
{
return toImpl(pageRef)->horizontalRubberBandingIsEnabled();
}
void WKPageSetEnableHorizontalRubberBanding(WKPageRef pageRef, bool enableHorizontalRubberBanding)
{
toImpl(pageRef)->setEnableHorizontalRubberBanding(enableHorizontalRubberBanding);
}
void WKPageSetBackgroundExtendsBeyondPage(WKPageRef pageRef, bool backgroundExtendsBeyondPage)
{
toImpl(pageRef)->setBackgroundExtendsBeyondPage(backgroundExtendsBeyondPage);
}
bool WKPageBackgroundExtendsBeyondPage(WKPageRef pageRef)
{
return toImpl(pageRef)->backgroundExtendsBeyondPage();
}
void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
{
Pagination::Mode mode;
switch (paginationMode) {
case kWKPaginationModeUnpaginated:
mode = Pagination::Unpaginated;
break;
case kWKPaginationModeLeftToRight:
mode = Pagination::LeftToRightPaginated;
break;
case kWKPaginationModeRightToLeft:
mode = Pagination::RightToLeftPaginated;
break;
case kWKPaginationModeTopToBottom:
mode = Pagination::TopToBottomPaginated;
break;
case kWKPaginationModeBottomToTop:
mode = Pagination::BottomToTopPaginated;
break;
default:
return;
}
toImpl(pageRef)->setPaginationMode(mode);
}
WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
{
switch (toImpl(pageRef)->paginationMode()) {
case Pagination::Unpaginated:
return kWKPaginationModeUnpaginated;
case Pagination::LeftToRightPaginated:
return kWKPaginationModeLeftToRight;
case Pagination::RightToLeftPaginated:
return kWKPaginationModeRightToLeft;
case Pagination::TopToBottomPaginated:
return kWKPaginationModeTopToBottom;
case Pagination::BottomToTopPaginated:
return kWKPaginationModeBottomToTop;
}
ASSERT_NOT_REACHED();
return kWKPaginationModeUnpaginated;
}
void WKPageSetPaginationBehavesLikeColumns(WKPageRef pageRef, bool behavesLikeColumns)
{
toImpl(pageRef)->setPaginationBehavesLikeColumns(behavesLikeColumns);
}
bool WKPageGetPaginationBehavesLikeColumns(WKPageRef pageRef)
{
return toImpl(pageRef)->paginationBehavesLikeColumns();
}
void WKPageSetPageLength(WKPageRef pageRef, double pageLength)
{
toImpl(pageRef)->setPageLength(pageLength);
}
double WKPageGetPageLength(WKPageRef pageRef)
{
return toImpl(pageRef)->pageLength();
}
void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
{
toImpl(pageRef)->setGapBetweenPages(gap);
}
double WKPageGetGapBetweenPages(WKPageRef pageRef)
{
return toImpl(pageRef)->gapBetweenPages();
}
void WKPageSetPaginationLineGridEnabled(WKPageRef pageRef, bool lineGridEnabled)
{
toImpl(pageRef)->setPaginationLineGridEnabled(lineGridEnabled);
}
bool WKPageGetPaginationLineGridEnabled(WKPageRef pageRef)
{
return toImpl(pageRef)->paginationLineGridEnabled();
}
unsigned WKPageGetPageCount(WKPageRef pageRef)
{
return toImpl(pageRef)->pageCount();
}
bool WKPageCanDelete(WKPageRef pageRef)
{
return toImpl(pageRef)->canDelete();
}
bool WKPageHasSelectedRange(WKPageRef pageRef)
{
return toImpl(pageRef)->hasSelectedRange();
}
bool WKPageIsContentEditable(WKPageRef pageRef)
{
return toImpl(pageRef)->isContentEditable();
}
void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
{
return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
}
void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
{
return toImpl(pageRef)->centerSelectionInVisibleArea();
}
void WKPageFindStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
{
toImpl(pageRef)->findStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
}
void WKPageGetImageForFindMatch(WKPageRef pageRef, int32_t matchIndex)
{
toImpl(pageRef)->getImageForFindMatch(matchIndex);
}
void WKPageSelectFindMatch(WKPageRef pageRef, int32_t matchIndex)
{
toImpl(pageRef)->selectFindMatch(matchIndex);
}
void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
{
toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
}
void WKPageHideFindUI(WKPageRef pageRef)
{
toImpl(pageRef)->hideFindUI();
}
void WKPageCountStringMatches(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
{
toImpl(pageRef)->countStringMatches(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
}
void WKPageSetPageContextMenuClient(WKPageRef pageRef, const WKPageContextMenuClientBase* wkClient)
{
#if ENABLE(CONTEXT_MENUS)
class ContextMenuClient final : public API::Client<WKPageContextMenuClientBase>, public API::ContextMenuClient {
public:
explicit ContextMenuClient(const WKPageContextMenuClientBase* client)
{
initialize(client);
}
private:
bool getContextMenuFromProposedMenu(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, Vector<RefPtr<WebKit::WebContextMenuItem>>& customMenu, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
{
if (!m_client.getContextMenuFromProposedMenu && !m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0)
return false;
if (m_client.base.version >= 2 && !m_client.getContextMenuFromProposedMenu)
return false;
Vector<RefPtr<API::Object>> proposedMenuItems;
proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
for (const auto& menuItem : proposedMenuVector)
proposedMenuItems.uncheckedAppend(menuItem);
WKArrayRef newMenu = nullptr;
if (m_client.base.version >= 2) {
RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
m_client.getContextMenuFromProposedMenu(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
} else
m_client.getContextMenuFromProposedMenu_deprecatedForUseWithV0(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), &newMenu, toAPI(userData), m_client.base.clientInfo);
RefPtr<API::Array> array = adoptRef(toImpl(newMenu));
customMenu.clear();
size_t newSize = array ? array->size() : 0;
for (size_t i = 0; i < newSize; ++i) {
WebContextMenuItem* item = array->at<WebContextMenuItem>(i);
if (!item) {
LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i);
continue;
}
customMenu.append(item);
}
return true;
}
bool getContextMenuFromProposedMenuAsync(WebPageProxy& page, const Vector<RefPtr<WebKit::WebContextMenuItem>>& proposedMenuVector, WebKit::WebContextMenuListenerProxy* contextMenuListener, const WebHitTestResultData& hitTestResultData, API::Object* userData) override
{
if (m_client.base.version < 4 || !m_client.getContextMenuFromProposedMenuAsync)
return false;
Vector<RefPtr<API::Object>> proposedMenuItems;
proposedMenuItems.reserveInitialCapacity(proposedMenuVector.size());
for (const auto& menuItem : proposedMenuVector)
proposedMenuItems.uncheckedAppend(menuItem);
RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(hitTestResultData);
m_client.getContextMenuFromProposedMenuAsync(toAPI(&page), toAPI(API::Array::create(WTFMove(proposedMenuItems)).ptr()), toAPI(contextMenuListener), toAPI(webHitTestResult.get()), toAPI(userData), m_client.base.clientInfo);
return true;
}
void customContextMenuItemSelected(WebPageProxy& page, const WebContextMenuItemData& itemData) override
{
if (!m_client.customContextMenuItemSelected)
return;
m_client.customContextMenuItemSelected(toAPI(&page), toAPI(WebContextMenuItem::create(itemData).ptr()), m_client.base.clientInfo);
}
bool showContextMenu(WebPageProxy& page, const WebCore::IntPoint& menuLocation, const Vector<RefPtr<WebContextMenuItem>>& menuItemsVector) override
{
if (!m_client.showContextMenu)
return false;
Vector<RefPtr<API::Object>> menuItems;
menuItems.reserveInitialCapacity(menuItemsVector.size());
for (const auto& menuItem : menuItemsVector)
menuItems.uncheckedAppend(menuItem);
m_client.showContextMenu(toAPI(&page), toAPI(menuLocation), toAPI(API::Array::create(WTFMove(menuItems)).ptr()), m_client.base.clientInfo);
return true;
}
bool hideContextMenu(WebPageProxy& page) override
{
if (!m_client.hideContextMenu)
return false;
m_client.hideContextMenu(toAPI(&page), m_client.base.clientInfo);
return true;
}
};
toImpl(pageRef)->setContextMenuClient(std::make_unique<ContextMenuClient>(wkClient));
#else
UNUSED_PARAM(pageRef);
UNUSED_PARAM(wkClient);
#endif
}
void WKPageSetPageDiagnosticLoggingClient(WKPageRef pageRef, const WKPageDiagnosticLoggingClientBase* wkClient)
{
toImpl(pageRef)->setDiagnosticLoggingClient(std::make_unique<WebPageDiagnosticLoggingClient>(wkClient));
}
void WKPageSetPageFindClient(WKPageRef pageRef, const WKPageFindClientBase* wkClient)
{
class FindClient : public API::Client<WKPageFindClientBase>, public API::FindClient {
public:
explicit FindClient(const WKPageFindClientBase* client)
{
initialize(client);
}
private:
void didFindString(WebPageProxy* page, const String& string, const Vector<WebCore::IntRect>&, uint32_t matchCount, int32_t) override
{
if (!m_client.didFindString)
return;
m_client.didFindString(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
}
void didFailToFindString(WebPageProxy* page, const String& string) override
{
if (!m_client.didFailToFindString)
return;
m_client.didFailToFindString(toAPI(page), toAPI(string.impl()), m_client.base.clientInfo);
}
void didCountStringMatches(WebPageProxy* page, const String& string, uint32_t matchCount) override
{
if (!m_client.didCountStringMatches)
return;
m_client.didCountStringMatches(toAPI(page), toAPI(string.impl()), matchCount, m_client.base.clientInfo);
}
};
toImpl(pageRef)->setFindClient(std::make_unique<FindClient>(wkClient));
}
void WKPageSetPageFindMatchesClient(WKPageRef pageRef, const WKPageFindMatchesClientBase* wkClient)
{
class FindMatchesClient : public API::Client<WKPageFindMatchesClientBase>, public API::FindMatchesClient {
public:
explicit FindMatchesClient(const WKPageFindMatchesClientBase* client)
{
initialize(client);
}
private:
void didFindStringMatches(WebPageProxy* page, const String& string, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t index) override
{
if (!m_client.didFindStringMatches)
return;
Vector<RefPtr<API::Object>> matches;
matches.reserveInitialCapacity(matchRects.size());
for (const auto& rects : matchRects) {
Vector<RefPtr<API::Object>> apiRects;
apiRects.reserveInitialCapacity(rects.size());
for (const auto& rect : rects)
apiRects.uncheckedAppend(API::Rect::create(toAPI(rect)));
matches.uncheckedAppend(API::Array::create(WTFMove(apiRects)));
}
m_client.didFindStringMatches(toAPI(page), toAPI(string.impl()), toAPI(API::Array::create(WTFMove(matches)).ptr()), index, m_client.base.clientInfo);
}
void didGetImageForMatchResult(WebPageProxy* page, WebImage* image, int32_t index) override
{
if (!m_client.didGetImageForMatchResult)
return;
m_client.didGetImageForMatchResult(toAPI(page), toAPI(image), index, m_client.base.clientInfo);
}
};
toImpl(pageRef)->setFindMatchesClient(std::make_unique<FindMatchesClient>(wkClient));
}
void WKPageSetPageInjectedBundleClient(WKPageRef pageRef, const WKPageInjectedBundleClientBase* wkClient)
{
toImpl(pageRef)->setInjectedBundleClient(wkClient);
}
void WKPageSetPageFormClient(WKPageRef pageRef, const WKPageFormClientBase* wkClient)
{
toImpl(pageRef)->setFormClient(std::make_unique<WebFormClient>(wkClient));
}
void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase* wkClient)
{
class LoaderClient : public API::Client<WKPageLoaderClientBase>, public API::LoaderClient {
public:
explicit LoaderClient(const WKPageLoaderClientBase* client)
{
initialize(client);
}
private:
void didStartProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
{
if (!m_client.didStartProvisionalLoadForFrame)
return;
m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didReceiveServerRedirectForProvisionalLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
{
if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame)
return;
m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFailProvisionalLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
{
if (!m_client.didFailProvisionalLoadWithErrorForFrame)
return;
m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
void didCommitLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
{
if (!m_client.didCommitLoadForFrame)
return;
m_client.didCommitLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFinishDocumentLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
{
if (!m_client.didFinishDocumentLoadForFrame)
return;
m_client.didFinishDocumentLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFinishLoadForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, API::Object* userData) override
{
if (!m_client.didFinishLoadForFrame)
return;
m_client.didFinishLoadForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFailLoadWithErrorForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, const ResourceError& error, API::Object* userData) override
{
if (!m_client.didFailLoadWithErrorForFrame)
return;
m_client.didFailLoadWithErrorForFrame(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
void didSameDocumentNavigationForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Navigation*, SameDocumentNavigationType type, API::Object* userData) override
{
if (!m_client.didSameDocumentNavigationForFrame)
return;
m_client.didSameDocumentNavigationForFrame(toAPI(&page), toAPI(&frame), toAPI(type), toAPI(userData), m_client.base.clientInfo);
}
void didReceiveTitleForFrame(WebPageProxy& page, const String& title, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didReceiveTitleForFrame)
return;
m_client.didReceiveTitleForFrame(toAPI(&page), toAPI(title.impl()), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFirstLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didFirstLayoutForFrame)
return;
m_client.didFirstLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didFirstVisuallyNonEmptyLayoutForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame)
return;
m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didReachLayoutMilestone(WebPageProxy& page, LayoutMilestones milestones) override
{
if (!m_client.didLayout)
return;
m_client.didLayout(toAPI(&page), toWKLayoutMilestones(milestones), nullptr, m_client.base.clientInfo);
}
void didDisplayInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didDisplayInsecureContentForFrame)
return;
m_client.didDisplayInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didRunInsecureContentForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didRunInsecureContentForFrame)
return;
m_client.didRunInsecureContentForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
void didDetectXSSForFrame(WebPageProxy& page, WebFrameProxy& frame, API::Object* userData) override
{
if (!m_client.didDetectXSSForFrame)
return;
m_client.didDetectXSSForFrame(toAPI(&page), toAPI(&frame), toAPI(userData), m_client.base.clientInfo);
}
bool canAuthenticateAgainstProtectionSpaceInFrame(WebPageProxy& page, WebFrameProxy& frame, WebProtectionSpace* protectionSpace) override
{
if (!m_client.canAuthenticateAgainstProtectionSpaceInFrame)
return false;
return m_client.canAuthenticateAgainstProtectionSpaceInFrame(toAPI(&page), toAPI(&frame), toAPI(protectionSpace), m_client.base.clientInfo);
}
void didReceiveAuthenticationChallengeInFrame(WebPageProxy& page, WebFrameProxy& frame, AuthenticationChallengeProxy* authenticationChallenge) override
{
if (!m_client.didReceiveAuthenticationChallengeInFrame)
return;
m_client.didReceiveAuthenticationChallengeInFrame(toAPI(&page), toAPI(&frame), toAPI(authenticationChallenge), m_client.base.clientInfo);
}
void didStartProgress(WebPageProxy& page) override
{
if (!m_client.didStartProgress)
return;
m_client.didStartProgress(toAPI(&page), m_client.base.clientInfo);
}
void didChangeProgress(WebPageProxy& page) override
{
if (!m_client.didChangeProgress)
return;
m_client.didChangeProgress(toAPI(&page), m_client.base.clientInfo);
}
void didFinishProgress(WebPageProxy& page) override
{
if (!m_client.didFinishProgress)
return;
m_client.didFinishProgress(toAPI(&page), m_client.base.clientInfo);
}
void processDidBecomeUnresponsive(WebPageProxy& page) override
{
if (!m_client.processDidBecomeUnresponsive)
return;
m_client.processDidBecomeUnresponsive(toAPI(&page), m_client.base.clientInfo);
}
void processDidBecomeResponsive(WebPageProxy& page) override
{
if (!m_client.processDidBecomeResponsive)
return;
m_client.processDidBecomeResponsive(toAPI(&page), m_client.base.clientInfo);
}
void processDidCrash(WebPageProxy& page) override
{
if (!m_client.processDidCrash)
return;
m_client.processDidCrash(toAPI(&page), m_client.base.clientInfo);
}
void didChangeBackForwardList(WebPageProxy& page, WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removedItems) override
{
if (!m_client.didChangeBackForwardList)
return;
RefPtr<API::Array> removedItemsArray;
if (!removedItems.isEmpty()) {
Vector<RefPtr<API::Object>> removedItemsVector;
removedItemsVector.reserveInitialCapacity(removedItems.size());
for (auto& removedItem : removedItems)
removedItemsVector.append(WTFMove(removedItem));
removedItemsArray = API::Array::create(WTFMove(removedItemsVector));
}
m_client.didChangeBackForwardList(toAPI(&page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
}
bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy& page, WebKit::WebBackForwardListItem* item) override
{
if (!m_client.shouldKeepCurrentBackForwardListItemInList)
return true;
return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(&page), toAPI(item), m_client.base.clientInfo);
}
void willGoToBackForwardListItem(WebPageProxy& page, WebBackForwardListItem* item, API::Object* userData) override
{
if (m_client.willGoToBackForwardListItem)
m_client.willGoToBackForwardListItem(toAPI(&page), toAPI(item), toAPI(userData), m_client.base.clientInfo);
}
void navigationGestureDidBegin(WebPageProxy& page) override
{
if (m_client.navigationGestureDidBegin)
m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
}
void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
{
if (m_client.navigationGestureWillEnd)
m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
}
void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
{
if (m_client.navigationGestureDidEnd)
m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
}
#if ENABLE(NETSCAPE_PLUGIN_API)
void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
{
if (m_client.didFailToInitializePlugin_deprecatedForUseWithV0)
m_client.didFailToInitializePlugin_deprecatedForUseWithV0(toAPI(&page), toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), m_client.base.clientInfo);
if (m_client.pluginDidFail_deprecatedForUseWithV1)
m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), 0, 0, m_client.base.clientInfo);
if (m_client.pluginDidFail)
m_client.pluginDidFail(toAPI(&page), kWKErrorCodeCannotLoadPlugIn, toAPI(pluginInformation), m_client.base.clientInfo);
}
void didBlockInsecurePluginVersion(WebPageProxy& page, API::Dictionary* pluginInformation) override
{
if (m_client.pluginDidFail_deprecatedForUseWithV1)
m_client.pluginDidFail_deprecatedForUseWithV1(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleIdentifierKey())), toAPI(pluginInformation->get<API::String>(pluginInformationBundleVersionKey())), m_client.base.clientInfo);
if (m_client.pluginDidFail)
m_client.pluginDidFail(toAPI(&page), kWKErrorCodeInsecurePlugInVersion, toAPI(pluginInformation), m_client.base.clientInfo);
}
PluginModuleLoadPolicy pluginLoadPolicy(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
{
WKStringRef unavailabilityDescriptionOut = 0;
PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
if (m_client.pluginLoadPolicy_deprecatedForUseWithV2)
loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy_deprecatedForUseWithV2(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), m_client.base.clientInfo));
else if (m_client.pluginLoadPolicy)
loadPolicy = toPluginModuleLoadPolicy(m_client.pluginLoadPolicy(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
if (unavailabilityDescriptionOut) {
RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
unavailabilityDescription = webUnavailabilityDescription->string();
}
return loadPolicy;
}
#endif // ENABLE(NETSCAPE_PLUGIN_API)
#if ENABLE(WEBGL)
WebCore::WebGLLoadPolicy webGLLoadPolicy(WebPageProxy& page, const String& url) const override
{
WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
if (m_client.webGLLoadPolicy)
loadPolicy = toWebGLLoadPolicy(m_client.webGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
return loadPolicy;
}
WebCore::WebGLLoadPolicy resolveWebGLLoadPolicy(WebPageProxy& page, const String& url) const override
{
WebCore::WebGLLoadPolicy loadPolicy = WebGLAllowCreation;
if (m_client.resolveWebGLLoadPolicy)
loadPolicy = toWebGLLoadPolicy(m_client.resolveWebGLLoadPolicy(toAPI(&page), toAPI(url.impl()), m_client.base.clientInfo));
return loadPolicy;
}
#endif // ENABLE(WEBGL)
};
WebPageProxy* webPageProxy = toImpl(pageRef);
auto loaderClient = std::make_unique<LoaderClient>(wkClient);
// It would be nice to get rid of this code and transition all clients to using didLayout instead of
// didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required
// for backwards compatibility.
WebCore::LayoutMilestones milestones = 0;
if (loaderClient->client().didFirstLayoutForFrame)
milestones |= WebCore::DidFirstLayout;
if (loaderClient->client().didFirstVisuallyNonEmptyLayoutForFrame)
milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
if (milestones)
webPageProxy->process().send(Messages::WebPage::ListenForLayoutMilestones(milestones), webPageProxy->pageID());
webPageProxy->setLoaderClient(WTFMove(loaderClient));
}
void WKPageSetPagePolicyClient(WKPageRef pageRef, const WKPagePolicyClientBase* wkClient)
{
class PolicyClient : public API::Client<WKPagePolicyClientBase>, public API::PolicyClient {
public:
explicit PolicyClient(const WKPagePolicyClientBase* client)
{
initialize(client);
}
private:
void decidePolicyForNavigationAction(WebPageProxy& page, WebFrameProxy* frame, const NavigationActionData& navigationActionData, WebFrameProxy* originatingFrame, const WebCore::ResourceRequest& originalResourceRequest, const WebCore::ResourceRequest& resourceRequest, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
{
if (!m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0 && !m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1 && !m_client.decidePolicyForNavigationAction) {
listener->use({ });
return;
}
Ref<API::URLRequest> originalRequest = API::URLRequest::create(originalResourceRequest);
Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0)
m_client.decidePolicyForNavigationAction_deprecatedForUseWithV0(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
else if (m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1)
m_client.decidePolicyForNavigationAction_deprecatedForUseWithV1(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
else
m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(originatingFrame), toAPI(originalRequest.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
}
void decidePolicyForNewWindowAction(WebPageProxy& page, WebFrameProxy& frame, const NavigationActionData& navigationActionData, const ResourceRequest& resourceRequest, const String& frameName, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
{
if (!m_client.decidePolicyForNewWindowAction) {
listener->use({ });
return;
}
Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
m_client.decidePolicyForNewWindowAction(toAPI(&page), toAPI(&frame), toAPI(navigationActionData.navigationType), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), toAPI(request.ptr()), toAPI(frameName.impl()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
}
void decidePolicyForResponse(WebPageProxy& page, WebFrameProxy& frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, bool canShowMIMEType, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
{
if (!m_client.decidePolicyForResponse_deprecatedForUseWithV0 && !m_client.decidePolicyForResponse) {
listener->use({ });
return;
}
Ref<API::URLResponse> response = API::URLResponse::create(resourceResponse);
Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
if (m_client.decidePolicyForResponse_deprecatedForUseWithV0)
m_client.decidePolicyForResponse_deprecatedForUseWithV0(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
else
m_client.decidePolicyForResponse(toAPI(&page), toAPI(&frame), toAPI(response.ptr()), toAPI(request.ptr()), canShowMIMEType, toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
}
void unableToImplementPolicy(WebPageProxy& page, WebFrameProxy& frame, const ResourceError& error, API::Object* userData) override
{
if (!m_client.unableToImplementPolicy)
return;
m_client.unableToImplementPolicy(toAPI(&page), toAPI(&frame), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
};
toImpl(pageRef)->setPolicyClient(std::make_unique<PolicyClient>(wkClient));
}
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
static void fixUpBotchedPageUIClient(WKPageRef pageRef, const WKPageUIClientBase& wkClient)
{
struct BotchedWKPageUIClientV4 {
WKPageUIClientBase base;
// Version 0.
WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0;
WKPageUIClientCallback showPage;
WKPageUIClientCallback close;
WKPageTakeFocusCallback takeFocus;
WKPageFocusCallback focus;
WKPageUnfocusCallback unfocus;
WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0;
WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0;
WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0;
WKPageSetStatusTextCallback setStatusText;
WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0;
WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0;
WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent;
WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent;
WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible;
WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible;
WKPageGetMenuBarIsVisibleCallback menuBarIsVisible;
WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible;
WKPageGetStatusBarIsVisibleCallback statusBarIsVisible;
WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible;
WKPageGetIsResizableCallback isResizable;
WKPageSetIsResizableCallback setIsResizable;
WKPageGetWindowFrameCallback getWindowFrame;
WKPageSetWindowFrameCallback setWindowFrame;
WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel;
WKPageUIClientCallback didDraw;
WKPageUIClientCallback pageDidScroll;
WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota;
WKPageRunOpenPanelCallback runOpenPanel;
WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest;
WKPageHeaderHeightCallback headerHeight;
WKPageFooterHeightCallback footerHeight;
WKPageDrawHeaderCallback drawHeader;
WKPageDrawFooterCallback drawFooter;
WKPagePrintFrameCallback printFrame;
WKPageUIClientCallback runModal;
void* unused1; // Used to be didCompleteRubberBandForMainFrame
WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder;
void* shouldInterruptJavaScript_unavailable;
// Version 1.
WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage;
WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement;
WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest;
WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1;
// Version 2.
WKPageShowColorPickerCallback showColorPicker;
WKPageHideColorPickerCallback hideColorPicker;
WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked;
// Version 3.
WKPagePinnedStateDidChangeCallback pinnedStateDidChange;
// Version 4.
WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert;
WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm;
WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt;
};
const auto& botchedPageUIClient = reinterpret_cast<const BotchedWKPageUIClientV4&>(wkClient);
WKPageUIClientV5 fixedPageUIClient = {
{ 5, botchedPageUIClient.base.clientInfo },
botchedPageUIClient.createNewPage_deprecatedForUseWithV0,
botchedPageUIClient.showPage,
botchedPageUIClient.close,
botchedPageUIClient.takeFocus,
botchedPageUIClient.focus,
botchedPageUIClient.unfocus,
botchedPageUIClient.runJavaScriptAlert_deprecatedForUseWithV0,
botchedPageUIClient.runJavaScriptConfirm_deprecatedForUseWithV0,
botchedPageUIClient.runJavaScriptPrompt_deprecatedForUseWithV0,
botchedPageUIClient.setStatusText,
botchedPageUIClient.mouseDidMoveOverElement_deprecatedForUseWithV0,
botchedPageUIClient.missingPluginButtonClicked_deprecatedForUseWithV0,
botchedPageUIClient.didNotHandleKeyEvent,
botchedPageUIClient.didNotHandleWheelEvent,
botchedPageUIClient.toolbarsAreVisible,
botchedPageUIClient.setToolbarsAreVisible,
botchedPageUIClient.menuBarIsVisible,
botchedPageUIClient.setMenuBarIsVisible,
botchedPageUIClient.statusBarIsVisible,
botchedPageUIClient.setStatusBarIsVisible,
botchedPageUIClient.isResizable,
botchedPageUIClient.setIsResizable,
botchedPageUIClient.getWindowFrame,
botchedPageUIClient.setWindowFrame,
botchedPageUIClient.runBeforeUnloadConfirmPanel,
botchedPageUIClient.didDraw,
botchedPageUIClient.pageDidScroll,
botchedPageUIClient.exceededDatabaseQuota,
botchedPageUIClient.runOpenPanel,
botchedPageUIClient.decidePolicyForGeolocationPermissionRequest,
botchedPageUIClient.headerHeight,
botchedPageUIClient.footerHeight,
botchedPageUIClient.drawHeader,
botchedPageUIClient.drawFooter,
botchedPageUIClient.printFrame,
botchedPageUIClient.runModal,
botchedPageUIClient.unused1,
botchedPageUIClient.saveDataToFileInDownloadsFolder,
botchedPageUIClient.shouldInterruptJavaScript_unavailable,
botchedPageUIClient.createNewPage,
botchedPageUIClient.mouseDidMoveOverElement,
botchedPageUIClient.decidePolicyForNotificationPermissionRequest,
botchedPageUIClient.unavailablePluginButtonClicked_deprecatedForUseWithV1,
botchedPageUIClient.showColorPicker,
botchedPageUIClient.hideColorPicker,
botchedPageUIClient.unavailablePluginButtonClicked,
botchedPageUIClient.pinnedStateDidChange,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
botchedPageUIClient.runJavaScriptAlert,
botchedPageUIClient.runJavaScriptConfirm,
botchedPageUIClient.runJavaScriptPrompt,
nullptr,
};
WKPageSetPageUIClient(pageRef, &fixedPageUIClient.base);
}
#endif
namespace WebKit {
class RunBeforeUnloadConfirmPanelResultListener : public API::ObjectImpl<API::Object::Type::RunBeforeUnloadConfirmPanelResultListener> {
public:
static PassRefPtr<RunBeforeUnloadConfirmPanelResultListener> create(Function<void (bool)>&& completionHandler)
{
return adoptRef(new RunBeforeUnloadConfirmPanelResultListener(WTFMove(completionHandler)));
}
virtual ~RunBeforeUnloadConfirmPanelResultListener()
{
}
void call(bool result)
{
m_completionHandler(result);
}
private:
explicit RunBeforeUnloadConfirmPanelResultListener(Function<void (bool)>&& completionHandler)
: m_completionHandler(WTFMove(completionHandler))
{
}
Function<void (bool)> m_completionHandler;
};
class RunJavaScriptAlertResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptAlertResultListener> {
public:
static PassRefPtr<RunJavaScriptAlertResultListener> create(Function<void ()>&& completionHandler)
{
return adoptRef(new RunJavaScriptAlertResultListener(WTFMove(completionHandler)));
}
virtual ~RunJavaScriptAlertResultListener()
{
}
void call()
{
m_completionHandler();
}
private:
explicit RunJavaScriptAlertResultListener(Function<void ()>&& completionHandler)
: m_completionHandler(WTFMove(completionHandler))
{
}
Function<void ()> m_completionHandler;
};
class RunJavaScriptConfirmResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptConfirmResultListener> {
public:
static PassRefPtr<RunJavaScriptConfirmResultListener> create(Function<void (bool)>&& completionHandler)
{
return adoptRef(new RunJavaScriptConfirmResultListener(WTFMove(completionHandler)));
}
virtual ~RunJavaScriptConfirmResultListener()
{
}
void call(bool result)
{
m_completionHandler(result);
}
private:
explicit RunJavaScriptConfirmResultListener(Function<void (bool)>&& completionHandler)
: m_completionHandler(WTFMove(completionHandler))
{
}
Function<void (bool)> m_completionHandler;
};
class RunJavaScriptPromptResultListener : public API::ObjectImpl<API::Object::Type::RunJavaScriptPromptResultListener> {
public:
static PassRefPtr<RunJavaScriptPromptResultListener> create(Function<void (const String&)>&& completionHandler)
{
return adoptRef(new RunJavaScriptPromptResultListener(WTFMove(completionHandler)));
}
virtual ~RunJavaScriptPromptResultListener()
{
}
void call(const String& result)
{
m_completionHandler(result);
}
private:
explicit RunJavaScriptPromptResultListener(Function<void (const String&)>&& completionHandler)
: m_completionHandler(WTFMove(completionHandler))
{
}
Function<void (const String&)> m_completionHandler;
};
WK_ADD_API_MAPPING(WKPageRunBeforeUnloadConfirmPanelResultListenerRef, RunBeforeUnloadConfirmPanelResultListener)
WK_ADD_API_MAPPING(WKPageRunJavaScriptAlertResultListenerRef, RunJavaScriptAlertResultListener)
WK_ADD_API_MAPPING(WKPageRunJavaScriptConfirmResultListenerRef, RunJavaScriptConfirmResultListener)
WK_ADD_API_MAPPING(WKPageRunJavaScriptPromptResultListenerRef, RunJavaScriptPromptResultListener)
}
WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID()
{
return toAPI(RunBeforeUnloadConfirmPanelResultListener::APIType);
}
void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result)
{
toImpl(listener)->call(result);
}
WKTypeID WKPageRunJavaScriptAlertResultListenerGetTypeID()
{
return toAPI(RunJavaScriptAlertResultListener::APIType);
}
void WKPageRunJavaScriptAlertResultListenerCall(WKPageRunJavaScriptAlertResultListenerRef listener)
{
toImpl(listener)->call();
}
WKTypeID WKPageRunJavaScriptConfirmResultListenerGetTypeID()
{
return toAPI(RunJavaScriptConfirmResultListener::APIType);
}
void WKPageRunJavaScriptConfirmResultListenerCall(WKPageRunJavaScriptConfirmResultListenerRef listener, bool result)
{
toImpl(listener)->call(result);
}
WKTypeID WKPageRunJavaScriptPromptResultListenerGetTypeID()
{
return toAPI(RunJavaScriptPromptResultListener::APIType);
}
void WKPageRunJavaScriptPromptResultListenerCall(WKPageRunJavaScriptPromptResultListenerRef listener, WKStringRef result)
{
toImpl(listener)->call(toWTFString(result));
}
void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient)
{
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
if (wkClient && wkClient->version == 4) {
fixUpBotchedPageUIClient(pageRef, *wkClient);
return;
}
#endif
class UIClient : public API::Client<WKPageUIClientBase>, public API::UIClient {
public:
explicit UIClient(const WKPageUIClientBase* client)
{
initialize(client);
}
private:
PassRefPtr<WebPageProxy> createNewPage(WebPageProxy* page, WebFrameProxy* initiatingFrame, const SecurityOriginData& securityOriginData, const ResourceRequest& resourceRequest, const WindowFeatures& windowFeatures, const NavigationActionData& navigationActionData) override
{
if (m_client.createNewPage) {
auto configuration = page->configuration().copy();
configuration->setRelatedPage(page);
auto sourceFrameInfo = API::FrameInfo::create(*initiatingFrame, securityOriginData.securityOrigin());
auto userInitiatedActivity = page->process().userInitiatedActivity(navigationActionData.userGestureTokenIdentifier);
bool shouldOpenAppLinks = !hostsAreEqual(WebCore::URL(WebCore::ParsedURLString, initiatingFrame->url()), resourceRequest.url());
auto apiNavigationAction = API::NavigationAction::create(navigationActionData, sourceFrameInfo.ptr(), nullptr, resourceRequest, WebCore::URL(), shouldOpenAppLinks, userInitiatedActivity);
auto apiWindowFeatures = API::WindowFeatures::create(windowFeatures);
return adoptRef(toImpl(m_client.createNewPage(toAPI(page), toAPI(configuration.ptr()), toAPI(apiNavigationAction.ptr()), toAPI(apiWindowFeatures.ptr()), m_client.base.clientInfo)));
}
if (m_client.createNewPage_deprecatedForUseWithV1 || m_client.createNewPage_deprecatedForUseWithV0) {
API::Dictionary::MapType map;
if (windowFeatures.x)
map.set("x", API::Double::create(*windowFeatures.x));
if (windowFeatures.y)
map.set("y", API::Double::create(*windowFeatures.y));
if (windowFeatures.width)
map.set("width", API::Double::create(*windowFeatures.width));
if (windowFeatures.height)
map.set("height", API::Double::create(*windowFeatures.height));
map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
map.set("toolBarVisible", API::Boolean::create(windowFeatures.toolBarVisible));
map.set("locationBarVisible", API::Boolean::create(windowFeatures.locationBarVisible));
map.set("scrollbarsVisible", API::Boolean::create(windowFeatures.scrollbarsVisible));
map.set("resizable", API::Boolean::create(windowFeatures.resizable));
map.set("fullscreen", API::Boolean::create(windowFeatures.fullscreen));
map.set("dialog", API::Boolean::create(windowFeatures.dialog));
Ref<API::Dictionary> featuresMap = API::Dictionary::create(WTFMove(map));
if (m_client.createNewPage_deprecatedForUseWithV1) {
Ref<API::URLRequest> request = API::URLRequest::create(resourceRequest);
return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV1(toAPI(page), toAPI(request.ptr()), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
}
ASSERT(m_client.createNewPage_deprecatedForUseWithV0);
return adoptRef(toImpl(m_client.createNewPage_deprecatedForUseWithV0(toAPI(page), toAPI(featuresMap.ptr()), toAPI(navigationActionData.modifiers), toAPI(navigationActionData.mouseButton), m_client.base.clientInfo)));
}
return nullptr;
}
void showPage(WebPageProxy* page) override
{
if (!m_client.showPage)
return;
m_client.showPage(toAPI(page), m_client.base.clientInfo);
}
void fullscreenMayReturnToInline(WebPageProxy* page) override
{
if (!m_client.fullscreenMayReturnToInline)
return;
m_client.fullscreenMayReturnToInline(toAPI(page), m_client.base.clientInfo);
}
void close(WebPageProxy* page) override
{
if (!m_client.close)
return;
m_client.close(toAPI(page), m_client.base.clientInfo);
}
void takeFocus(WebPageProxy* page, WKFocusDirection direction) override
{
if (!m_client.takeFocus)
return;
m_client.takeFocus(toAPI(page), direction, m_client.base.clientInfo);
}
void focus(WebPageProxy* page) override
{
if (!m_client.focus)
return;
m_client.focus(toAPI(page), m_client.base.clientInfo);
}
void unfocus(WebPageProxy* page) override
{
if (!m_client.unfocus)
return;
m_client.unfocus(toAPI(page), m_client.base.clientInfo);
}
void runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void ()>&& completionHandler) override
{
if (m_client.runJavaScriptAlert) {
RefPtr<RunJavaScriptAlertResultListener> listener = RunJavaScriptAlertResultListener::create(WTFMove(completionHandler));
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
m_client.runJavaScriptAlert(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
return;
}
if (m_client.runJavaScriptAlert_deprecatedForUseWithV5) {
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
m_client.runJavaScriptAlert_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
completionHandler();
return;
}
if (m_client.runJavaScriptAlert_deprecatedForUseWithV0) {
m_client.runJavaScriptAlert_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
completionHandler();
return;
}
completionHandler();
}
void runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void (bool)>&& completionHandler) override
{
if (m_client.runJavaScriptConfirm) {
RefPtr<RunJavaScriptConfirmResultListener> listener = RunJavaScriptConfirmResultListener::create(WTFMove(completionHandler));
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
m_client.runJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
return;
}
if (m_client.runJavaScriptConfirm_deprecatedForUseWithV5) {
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo);
completionHandler(result);
return;
}
if (m_client.runJavaScriptConfirm_deprecatedForUseWithV0) {
bool result = m_client.runJavaScriptConfirm_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
completionHandler(result);
return;
}
completionHandler(false);
}
void runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame, const SecurityOriginData& securityOriginData, Function<void (const String&)>&& completionHandler) override
{
if (m_client.runJavaScriptPrompt) {
RefPtr<RunJavaScriptPromptResultListener> listener = RunJavaScriptPromptResultListener::create(WTFMove(completionHandler));
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
m_client.runJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), toAPI(listener.get()), m_client.base.clientInfo);
return;
}
if (m_client.runJavaScriptPrompt_deprecatedForUseWithV5) {
RefPtr<API::SecurityOrigin> securityOrigin = API::SecurityOrigin::create(securityOriginData.protocol, securityOriginData.host, securityOriginData.port);
RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV5(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), toAPI(securityOrigin.get()), m_client.base.clientInfo)));
if (string)
completionHandler(string->string());
else
completionHandler(String());
return;
}
if (m_client.runJavaScriptPrompt_deprecatedForUseWithV0) {
RefPtr<API::String> string = adoptRef(toImpl(m_client.runJavaScriptPrompt_deprecatedForUseWithV0(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo)));
if (string)
completionHandler(string->string());
else
completionHandler(String());
return;
}
completionHandler(String());
}
void setStatusText(WebPageProxy* page, const String& text) override
{
if (!m_client.setStatusText)
return;
m_client.setStatusText(toAPI(page), toAPI(text.impl()), m_client.base.clientInfo);
}
void mouseDidMoveOverElement(WebPageProxy* page, const WebHitTestResultData& data, WebKit::WebEvent::Modifiers modifiers, API::Object* userData) override
{
if (!m_client.mouseDidMoveOverElement && !m_client.mouseDidMoveOverElement_deprecatedForUseWithV0)
return;
if (m_client.base.version > 0 && !m_client.mouseDidMoveOverElement)
return;
if (!m_client.base.version) {
m_client.mouseDidMoveOverElement_deprecatedForUseWithV0(toAPI(page), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
return;
}
RefPtr<API::HitTestResult> webHitTestResult = API::HitTestResult::create(data);
m_client.mouseDidMoveOverElement(toAPI(page), toAPI(webHitTestResult.get()), toAPI(modifiers), toAPI(userData), m_client.base.clientInfo);
}
#if ENABLE(NETSCAPE_PLUGIN_API)
void unavailablePluginButtonClicked(WebPageProxy* page, WKPluginUnavailabilityReason pluginUnavailabilityReason, API::Dictionary* pluginInformation) override
{
if (pluginUnavailabilityReason == kWKPluginUnavailabilityReasonPluginMissing) {
if (m_client.missingPluginButtonClicked_deprecatedForUseWithV0)
m_client.missingPluginButtonClicked_deprecatedForUseWithV0(
toAPI(page),
toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
m_client.base.clientInfo);
}
if (m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1)
m_client.unavailablePluginButtonClicked_deprecatedForUseWithV1(
toAPI(page),
pluginUnavailabilityReason,
toAPI(pluginInformation->get<API::String>(pluginInformationMIMETypeKey())),
toAPI(pluginInformation->get<API::String>(pluginInformationPluginURLKey())),
toAPI(pluginInformation->get<API::String>(pluginInformationPluginspageAttributeURLKey())),
m_client.base.clientInfo);
if (m_client.unavailablePluginButtonClicked)
m_client.unavailablePluginButtonClicked(
toAPI(page),
pluginUnavailabilityReason,
toAPI(pluginInformation),
m_client.base.clientInfo);
}
#endif // ENABLE(NETSCAPE_PLUGIN_API)
bool implementsDidNotHandleKeyEvent() const override
{
return m_client.didNotHandleKeyEvent;
}
void didNotHandleKeyEvent(WebPageProxy* page, const NativeWebKeyboardEvent& event) override
{
if (!m_client.didNotHandleKeyEvent)
return;
m_client.didNotHandleKeyEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
}
bool implementsDidNotHandleWheelEvent() const override
{
return m_client.didNotHandleWheelEvent;
}
void didNotHandleWheelEvent(WebPageProxy* page, const NativeWebWheelEvent& event) override
{
if (!m_client.didNotHandleWheelEvent)
return;
m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
}
bool toolbarsAreVisible(WebPageProxy* page) override
{
if (!m_client.toolbarsAreVisible)
return true;
return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
}
void setToolbarsAreVisible(WebPageProxy* page, bool visible) override
{
if (!m_client.setToolbarsAreVisible)
return;
m_client.setToolbarsAreVisible(toAPI(page), visible, m_client.base.clientInfo);
}
bool menuBarIsVisible(WebPageProxy* page) override
{
if (!m_client.menuBarIsVisible)
return true;
return m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo);
}
void setMenuBarIsVisible(WebPageProxy* page, bool visible) override
{
if (!m_client.setMenuBarIsVisible)
return;
m_client.setMenuBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
}
bool statusBarIsVisible(WebPageProxy* page) override
{
if (!m_client.statusBarIsVisible)
return true;
return m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo);
}
void setStatusBarIsVisible(WebPageProxy* page, bool visible) override
{
if (!m_client.setStatusBarIsVisible)
return;
m_client.setStatusBarIsVisible(toAPI(page), visible, m_client.base.clientInfo);
}
bool isResizable(WebPageProxy* page) override
{
if (!m_client.isResizable)
return true;
return m_client.isResizable(toAPI(page), m_client.base.clientInfo);
}
void setIsResizable(WebPageProxy* page, bool resizable) override
{
if (!m_client.setIsResizable)
return;
m_client.setIsResizable(toAPI(page), resizable, m_client.base.clientInfo);
}
void setWindowFrame(WebPageProxy* page, const FloatRect& frame) override
{
if (!m_client.setWindowFrame)
return;
m_client.setWindowFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
}
FloatRect windowFrame(WebPageProxy* page) override
{
if (!m_client.getWindowFrame)
return FloatRect();
return toFloatRect(m_client.getWindowFrame(toAPI(page), m_client.base.clientInfo));
}
bool canRunBeforeUnloadConfirmPanel() const override
{
return m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6 || m_client.runBeforeUnloadConfirmPanel;
}
void runBeforeUnloadConfirmPanel(WebKit::WebPageProxy* page, const WTF::String& message, WebKit::WebFrameProxy* frame, Function<void (bool)>&& completionHandler) override
{
if (m_client.runBeforeUnloadConfirmPanel) {
RefPtr<RunBeforeUnloadConfirmPanelResultListener> listener = RunBeforeUnloadConfirmPanelResultListener::create(WTFMove(completionHandler));
m_client.runBeforeUnloadConfirmPanel(toAPI(page), toAPI(message.impl()), toAPI(frame), toAPI(listener.get()), m_client.base.clientInfo);
return;
}
if (m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6) {
bool result = m_client.runBeforeUnloadConfirmPanel_deprecatedForUseWithV6(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo);
completionHandler(result);
return;
}
completionHandler(true);
}
void pageDidScroll(WebPageProxy* page) override
{
if (!m_client.pageDidScroll)
return;
m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo);
}
void exceededDatabaseQuota(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, Function<void (unsigned long long)>&& completionHandler) override
{
if (!m_client.exceededDatabaseQuota) {
completionHandler(currentQuota);
return;
}
completionHandler(m_client.exceededDatabaseQuota(toAPI(page), toAPI(frame), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage, m_client.base.clientInfo));
}
bool runOpenPanel(WebPageProxy* page, WebFrameProxy* frame, const WebCore::SecurityOriginData&, API::OpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener) override
{
if (!m_client.runOpenPanel)
return false;
m_client.runOpenPanel(toAPI(page), toAPI(frame), toAPI(parameters), toAPI(listener), m_client.base.clientInfo);
return true;
}
bool decidePolicyForGeolocationPermissionRequest(WebPageProxy* page, WebFrameProxy* frame, API::SecurityOrigin* origin, GeolocationPermissionRequestProxy* permissionRequest) override
{
if (!m_client.decidePolicyForGeolocationPermissionRequest)
return false;
m_client.decidePolicyForGeolocationPermissionRequest(toAPI(page), toAPI(frame), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
return true;
}
bool decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionRequestProxy& permissionRequest) override
{
if (!m_client.decidePolicyForUserMediaPermissionRequest)
return false;
m_client.decidePolicyForUserMediaPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&userMediaDocumentOrigin), toAPI(&topLevelDocumentOrigin), toAPI(&permissionRequest), m_client.base.clientInfo);
return true;
}
bool checkUserMediaPermissionForOrigin(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionCheckProxy& request) override
{
if (!m_client.checkUserMediaPermissionForOrigin)
return false;
m_client.checkUserMediaPermissionForOrigin(toAPI(&page), toAPI(&frame), toAPI(&userMediaDocumentOrigin), toAPI(&topLevelDocumentOrigin), toAPI(&request), m_client.base.clientInfo);
return true;
}
bool decidePolicyForNotificationPermissionRequest(WebPageProxy* page, API::SecurityOrigin* origin, NotificationPermissionRequest* permissionRequest) override
{
if (!m_client.decidePolicyForNotificationPermissionRequest)
return false;
m_client.decidePolicyForNotificationPermissionRequest(toAPI(page), toAPI(origin), toAPI(permissionRequest), m_client.base.clientInfo);
return true;
}
// Printing.
float headerHeight(WebPageProxy* page, WebFrameProxy* frame) override
{
if (!m_client.headerHeight)
return 0;
return m_client.headerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
}
float footerHeight(WebPageProxy* page, WebFrameProxy* frame) override
{
if (!m_client.footerHeight)
return 0;
return m_client.footerHeight(toAPI(page), toAPI(frame), m_client.base.clientInfo);
}
void drawHeader(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
{
if (!m_client.drawHeader)
return;
m_client.drawHeader(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
}
void drawFooter(WebPageProxy* page, WebFrameProxy* frame, const WebCore::FloatRect& rect) override
{
if (!m_client.drawFooter)
return;
m_client.drawFooter(toAPI(page), toAPI(frame), toAPI(rect), m_client.base.clientInfo);
}
void printFrame(WebPageProxy* page, WebFrameProxy* frame) override
{
if (!m_client.printFrame)
return;
m_client.printFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
}
bool canRunModal() const override
{
return m_client.runModal;
}
void runModal(WebPageProxy* page) override
{
if (!m_client.runModal)
return;
m_client.runModal(toAPI(page), m_client.base.clientInfo);
}
void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) override
{
if (!m_client.saveDataToFileInDownloadsFolder)
return;
m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
}
void pinnedStateDidChange(WebPageProxy& page) override
{
if (!m_client.pinnedStateDidChange)
return;
m_client.pinnedStateDidChange(toAPI(&page), m_client.base.clientInfo);
}
void isPlayingAudioDidChange(WebPageProxy& page) override
{
if (!m_client.isPlayingAudioDidChange)
return;
m_client.isPlayingAudioDidChange(toAPI(&page), m_client.base.clientInfo);
}
void didClickAutoFillButton(WebPageProxy& page, API::Object* userInfo) override
{
if (!m_client.didClickAutoFillButton)
return;
m_client.didClickAutoFillButton(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo);
}
#if ENABLE(MEDIA_SESSION)
void mediaSessionMetadataDidChange(WebPageProxy& page, WebMediaSessionMetadata* metadata) override
{
if (!m_client.mediaSessionMetadataDidChange)
return;
m_client.mediaSessionMetadataDidChange(toAPI(&page), toAPI(metadata), m_client.base.clientInfo);
}
#endif
#if ENABLE(POINTER_LOCK)
void requestPointerLock(WebPageProxy* page) override
{
if (!m_client.requestPointerLock)
return;
m_client.requestPointerLock(toAPI(page), m_client.base.clientInfo);
}
void didLosePointerLock(WebPageProxy* page) override
{
if (!m_client.didLosePointerLock)
return;
m_client.didLosePointerLock(toAPI(page), m_client.base.clientInfo);
}
#endif
void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebPageProxy& page) override
{
if (!m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture)
return;
m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture(toAPI(&page), m_client.base.clientInfo);
}
};
toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));
}
void WKPageSetPageNavigationClient(WKPageRef pageRef, const WKPageNavigationClientBase* wkClient)
{
class NavigationClient : public API::Client<WKPageNavigationClientBase>, public API::NavigationClient {
public:
explicit NavigationClient(const WKPageNavigationClientBase* client)
{
initialize(client);
}
private:
void decidePolicyForNavigationAction(WebPageProxy& page, API::NavigationAction& navigationAction, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
{
if (!m_client.decidePolicyForNavigationAction)
return;
m_client.decidePolicyForNavigationAction(toAPI(&page), toAPI(&navigationAction), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
}
void decidePolicyForNavigationResponse(WebPageProxy& page, API::NavigationResponse& navigationResponse, Ref<WebKit::WebFramePolicyListenerProxy>&& listener, API::Object* userData) override
{
if (!m_client.decidePolicyForNavigationResponse)
return;
m_client.decidePolicyForNavigationResponse(toAPI(&page), toAPI(&navigationResponse), toAPI(listener.ptr()), toAPI(userData), m_client.base.clientInfo);
}
void didStartProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
{
if (!m_client.didStartProvisionalNavigation)
return;
m_client.didStartProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
}
void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
{
if (!m_client.didReceiveServerRedirectForProvisionalNavigation)
return;
m_client.didReceiveServerRedirectForProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
}
void didFailProvisionalNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
{
if (!m_client.didFailProvisionalNavigation)
return;
m_client.didFailProvisionalNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
void didCommitNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
{
if (!m_client.didCommitNavigation)
return;
m_client.didCommitNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
}
void didFinishNavigation(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
{
if (!m_client.didFinishNavigation)
return;
m_client.didFinishNavigation(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
}
void didFailNavigationWithError(WebPageProxy& page, WebFrameProxy&, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
{
if (!m_client.didFailNavigation)
return;
m_client.didFailNavigation(toAPI(&page), toAPI(navigation), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
void didFailProvisionalLoadInSubframeWithError(WebPageProxy& page, WebFrameProxy& subframe, const WebCore::SecurityOriginData& securityOriginData, API::Navigation* navigation, const WebCore::ResourceError& error, API::Object* userData) override
{
if (!m_client.didFailProvisionalLoadInSubframe)
return;
m_client.didFailProvisionalLoadInSubframe(toAPI(&page), toAPI(navigation), toAPI(API::FrameInfo::create(subframe, securityOriginData.securityOrigin()).ptr()), toAPI(error), toAPI(userData), m_client.base.clientInfo);
}
void didFinishDocumentLoad(WebPageProxy& page, API::Navigation* navigation, API::Object* userData) override
{
if (!m_client.didFinishDocumentLoad)
return;
m_client.didFinishDocumentLoad(toAPI(&page), toAPI(navigation), toAPI(userData), m_client.base.clientInfo);
}
void didSameDocumentNavigation(WebPageProxy& page, API::Navigation* navigation, WebKit::SameDocumentNavigationType navigationType, API::Object* userData) override
{
if (!m_client.didSameDocumentNavigation)
return;
m_client.didSameDocumentNavigation(toAPI(&page), toAPI(navigation), toAPI(navigationType), toAPI(userData), m_client.base.clientInfo);
}
void renderingProgressDidChange(WebPageProxy& page, WebCore::LayoutMilestones milestones) override
{
if (!m_client.renderingProgressDidChange)
return;
m_client.renderingProgressDidChange(toAPI(&page), pageRenderingProgressEvents(milestones), nullptr, m_client.base.clientInfo);
}
bool canAuthenticateAgainstProtectionSpace(WebPageProxy& page, WebProtectionSpace* protectionSpace) override
{
if (!m_client.canAuthenticateAgainstProtectionSpace)
return false;
return m_client.canAuthenticateAgainstProtectionSpace(toAPI(&page), toAPI(protectionSpace), m_client.base.clientInfo);
}
void didReceiveAuthenticationChallenge(WebPageProxy& page, AuthenticationChallengeProxy* authenticationChallenge) override
{
if (!m_client.didReceiveAuthenticationChallenge)
return;
m_client.didReceiveAuthenticationChallenge(toAPI(&page), toAPI(authenticationChallenge), m_client.base.clientInfo);
}
void processDidCrash(WebPageProxy& page) override
{
if (!m_client.webProcessDidCrash)
return;
m_client.webProcessDidCrash(toAPI(&page), m_client.base.clientInfo);
}
RefPtr<API::Data> webCryptoMasterKey(WebPageProxy& page) override
{
if (m_client.copyWebCryptoMasterKey)
return adoptRef(toImpl(m_client.copyWebCryptoMasterKey(toAPI(&page), m_client.base.clientInfo)));
Vector<uint8_t> masterKey;
#if ENABLE(SUBTLE_CRYPTO)
if (!getDefaultWebCryptoMasterKey(masterKey))
return nullptr;
#endif
return API::Data::create(masterKey.data(), masterKey.size());
}
void didBeginNavigationGesture(WebPageProxy& page) override
{
if (!m_client.didBeginNavigationGesture)
return;
m_client.didBeginNavigationGesture(toAPI(&page), m_client.base.clientInfo);
}
void didEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
{
if (!m_client.didEndNavigationGesture)
return;
m_client.didEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
}
void willEndNavigationGesture(WebPageProxy& page, bool willNavigate, WebKit::WebBackForwardListItem& item) override
{
if (!m_client.willEndNavigationGesture)
return;
m_client.willEndNavigationGesture(toAPI(&page), willNavigate ? toAPI(&item) : nullptr, m_client.base.clientInfo);
}
void didRemoveNavigationGestureSnapshot(WebPageProxy& page) override
{
if (!m_client.didRemoveNavigationGestureSnapshot)
return;
m_client.didRemoveNavigationGestureSnapshot(toAPI(&page), m_client.base.clientInfo);
}
#if ENABLE(NETSCAPE_PLUGIN_API)
PluginModuleLoadPolicy decidePolicyForPluginLoad(WebPageProxy& page, PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary* pluginInformation, String& unavailabilityDescription) override
{
WKStringRef unavailabilityDescriptionOut = 0;
PluginModuleLoadPolicy loadPolicy = currentPluginLoadPolicy;
if (m_client.decidePolicyForPluginLoad)
loadPolicy = toPluginModuleLoadPolicy(m_client.decidePolicyForPluginLoad(toAPI(&page), toWKPluginLoadPolicy(currentPluginLoadPolicy), toAPI(pluginInformation), &unavailabilityDescriptionOut, m_client.base.clientInfo));
if (unavailabilityDescriptionOut) {
RefPtr<API::String> webUnavailabilityDescription = adoptRef(toImpl(unavailabilityDescriptionOut));
unavailabilityDescription = webUnavailabilityDescription->string();
}
return loadPolicy;
}
#endif
};
WebPageProxy* webPageProxy = toImpl(pageRef);
auto navigationClient = std::make_unique<NavigationClient>(wkClient);
webPageProxy->setNavigationClient(WTFMove(navigationClient));
}
void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
{
toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), [context, callback](API::SerializedScriptValue* returnValue, bool, const WebCore::ExceptionDetails&, CallbackBase::Error error) {
callback(toAPI(returnValue), (error != CallbackBase::Error::None) ? toAPI(API::Error::create().ptr()) : 0, context);
});
}
#ifdef __BLOCKS__
static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
{
WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
block(resultValue, error);
Block_release(block);
}
void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef, WKPageRunJavaScriptBlock block)
{
WKPageRunJavaScriptInMainFrame(pageRef, scriptRef, Block_copy(block), callRunJavaScriptBlockAndRelease);
}
#endif
static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
{
return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
};
}
void WKPageRenderTreeExternalRepresentation(WKPageRef pageRef, void* context, WKPageRenderTreeExternalRepresentationFunction callback)
{
toImpl(pageRef)->getRenderTreeExternalRepresentation(toGenericCallbackFunction(context, callback));
}
void WKPageGetSourceForFrame(WKPageRef pageRef, WKFrameRef frameRef, void* context, WKPageGetSourceForFrameFunction callback)
{
toImpl(pageRef)->getSourceForFrame(toImpl(frameRef), toGenericCallbackFunction(context, callback));
}
void WKPageGetContentsAsString(WKPageRef pageRef, void* context, WKPageGetContentsAsStringFunction callback)
{
toImpl(pageRef)->getContentsAsString(toGenericCallbackFunction(context, callback));
}
void WKPageGetBytecodeProfile(WKPageRef pageRef, void* context, WKPageGetBytecodeProfileFunction callback)
{
toImpl(pageRef)->getBytecodeProfile(toGenericCallbackFunction(context, callback));
}
void WKPageGetSamplingProfilerOutput(WKPageRef pageRef, void* context, WKPageGetSamplingProfilerOutputFunction callback)
{
toImpl(pageRef)->getSamplingProfilerOutput(toGenericCallbackFunction(context, callback));
}
void WKPageIsWebProcessResponsive(WKPageRef pageRef, void* context, WKPageIsWebProcessResponsiveFunction callback)
{
toImpl(pageRef)->isWebProcessResponsive([context, callback](bool isWebProcessResponsive) {
callback(isWebProcessResponsive, context);
});
}
void WKPageGetSelectionAsWebArchiveData(WKPageRef pageRef, void* context, WKPageGetSelectionAsWebArchiveDataFunction callback)
{
toImpl(pageRef)->getSelectionAsWebArchiveData(toGenericCallbackFunction(context, callback));
}
void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, void* context, WKPageGetContentsAsMHTMLDataFunction callback)
{
#if ENABLE(MHTML)
toImpl(pageRef)->getContentsAsMHTMLData(toGenericCallbackFunction(context, callback));
#else
UNUSED_PARAM(pageRef);
UNUSED_PARAM(context);
UNUSED_PARAM(callback);
#endif
}
void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
{
toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
}));
}
WK_EXPORT WKURLRef WKPageCopyPendingAPIRequestURL(WKPageRef pageRef)
{
const String& pendingAPIRequestURL = toImpl(pageRef)->pageLoadState().pendingAPIRequestURL();
if (pendingAPIRequestURL.isNull())
return nullptr;
return toCopiedURLAPI(pendingAPIRequestURL);
}
WKURLRef WKPageCopyActiveURL(WKPageRef pageRef)
{
return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().activeURL());
}
WKURLRef WKPageCopyProvisionalURL(WKPageRef pageRef)
{
return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().provisionalURL());
}
WKURLRef WKPageCopyCommittedURL(WKPageRef pageRef)
{
return toCopiedURLAPI(toImpl(pageRef)->pageLoadState().url());
}
WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicationName)
{
return toCopiedAPI(WebPageProxy::standardUserAgent(toImpl(applicationName)->string()));
}
void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
{
toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
});
}
void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
{
toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
}
#if PLATFORM(COCOA)
static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
{
PrintInfo result;
result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
result.availablePaperWidth = printInfo.availablePaperWidth;
result.availablePaperHeight = printInfo.availablePaperHeight;
return result;
}
void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
{
toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create([context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, WebKit::CallbackBase::Error error) {
Vector<WKRect> wkRects(rects.size());
for (size_t i = 0; i < rects.size(); ++i)
wkRects[i] = toAPI(rects[i]);
callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
}));
}
void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo)
{
toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
}
void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
{
toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(toGenericCallbackFunction(context, callback)));
}
void WKPageEndPrinting(WKPageRef page)
{
toImpl(page)->endPrinting();
}
#endif
bool WKPageGetIsControlledByAutomation(WKPageRef page)
{
return toImpl(page)->isControlledByAutomation();
}
void WKPageSetControlledByAutomation(WKPageRef page, bool controlled)
{
toImpl(page)->setControlledByAutomation(controlled);
}
bool WKPageGetAllowsRemoteInspection(WKPageRef page)
{
#if ENABLE(REMOTE_INSPECTOR)
return toImpl(page)->allowsRemoteInspection();
#else
UNUSED_PARAM(page);
return false;
#endif
}
void WKPageSetAllowsRemoteInspection(WKPageRef page, bool allow)
{
#if ENABLE(REMOTE_INSPECTOR)
toImpl(page)->setAllowsRemoteInspection(allow);
#else
UNUSED_PARAM(page);
UNUSED_PARAM(allow);
#endif
}
void WKPageSetMediaVolume(WKPageRef page, float volume)
{
toImpl(page)->setMediaVolume(volume);
}
void WKPageSetMuted(WKPageRef page, WKMediaMutedState muted)
{
toImpl(page)->setMuted(muted);
}
void WKPageDidAllowPointerLock(WKPageRef page)
{
#if ENABLE(POINTER_LOCK)
toImpl(page)->didAllowPointerLock();
#else
UNUSED_PARAM(page);
#endif
}
void WKPageClearUserMediaState(WKPageRef page)
{
#if ENABLE(MEDIA_STREAM)
toImpl(page)->clearUserMediaState();
#else
UNUSED_PARAM(page);
#endif
}
void WKPageDidDenyPointerLock(WKPageRef page)
{
#if ENABLE(POINTER_LOCK)
toImpl(page)->didDenyPointerLock();
#else
UNUSED_PARAM(page);
#endif
}
bool WKPageHasMediaSessionWithActiveMediaElements(WKPageRef page)
{
#if ENABLE(MEDIA_SESSION)
return toImpl(page)->hasMediaSessionWithActiveMediaElements();
#else
UNUSED_PARAM(page);
return false;
#endif
}
void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType)
{
#if ENABLE(MEDIA_SESSION)
MediaEventType eventType;
switch (wkEventType) {
case kWKMediaEventTypePlayPause:
eventType = MediaEventType::PlayPause;
break;
case kWKMediaEventTypeTrackNext:
eventType = MediaEventType::TrackNext;
break;
case kWKMediaEventTypeTrackPrevious:
eventType = MediaEventType::TrackPrevious;
break;
default:
ASSERT_NOT_REACHED();
return;
}
toImpl(page)->handleMediaEvent(eventType);
#else
UNUSED_PARAM(page);
UNUSED_PARAM(wkEventType);
#endif
}
void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
{
toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
}
WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef)
{
Vector<RefPtr<API::Object>> relatedPages;
for (auto& page : toImpl(pageRef)->process().pages()) {
if (page != toImpl(pageRef))
relatedPages.append(page);
}
return toAPI(&API::Array::create(WTFMove(relatedPages)).leakRef());
}
WKFrameRef WKPageLookUpFrameFromHandle(WKPageRef pageRef, WKFrameHandleRef handleRef)
{
auto page = toImpl(pageRef);
auto frame = page->process().webFrame(toImpl(handleRef)->frameID());
if (!frame || frame->page() != page)
return nullptr;
return toAPI(frame);
}
void WKPageSetMayStartMediaWhenInWindow(WKPageRef pageRef, bool mayStartMedia)
{
toImpl(pageRef)->setMayStartMediaWhenInWindow(mayStartMedia);
}
void WKPageSelectContextMenuItem(WKPageRef page, WKContextMenuItemRef item)
{
#if ENABLE(CONTEXT_MENUS)
toImpl(page)->contextMenuItemSelected((toImpl(item)->data()));
#else
UNUSED_PARAM(page);
UNUSED_PARAM(item);
#endif
}
WKScrollPinningBehavior WKPageGetScrollPinningBehavior(WKPageRef page)
{
ScrollPinningBehavior pinning = toImpl(page)->scrollPinningBehavior();
switch (pinning) {
case WebCore::ScrollPinningBehavior::DoNotPin:
return kWKScrollPinningBehaviorDoNotPin;
case WebCore::ScrollPinningBehavior::PinToTop:
return kWKScrollPinningBehaviorPinToTop;
case WebCore::ScrollPinningBehavior::PinToBottom:
return kWKScrollPinningBehaviorPinToBottom;
}
ASSERT_NOT_REACHED();
return kWKScrollPinningBehaviorDoNotPin;
}
void WKPageSetScrollPinningBehavior(WKPageRef page, WKScrollPinningBehavior pinning)
{
ScrollPinningBehavior corePinning = ScrollPinningBehavior::DoNotPin;
switch (pinning) {
case kWKScrollPinningBehaviorDoNotPin:
corePinning = ScrollPinningBehavior::DoNotPin;
break;
case kWKScrollPinningBehaviorPinToTop:
corePinning = ScrollPinningBehavior::PinToTop;
break;
case kWKScrollPinningBehaviorPinToBottom:
corePinning = ScrollPinningBehavior::PinToBottom;
break;
default:
ASSERT_NOT_REACHED();
}
toImpl(page)->setScrollPinningBehavior(corePinning);
}
bool WKPageGetAddsVisitedLinks(WKPageRef page)
{
return toImpl(page)->addsVisitedLinks();
}
void WKPageSetAddsVisitedLinks(WKPageRef page, bool addsVisitedLinks)
{
toImpl(page)->setAddsVisitedLinks(addsVisitedLinks);
}
bool WKPageIsPlayingAudio(WKPageRef page)
{
return toImpl(page)->isPlayingAudio();
}
WKMediaState WKPageGetMediaState(WKPageRef page)
{
WebCore::MediaProducer::MediaStateFlags coreState = toImpl(page)->mediaStateFlags();
WKMediaState state = kWKMediaIsNotPlaying;
if (coreState & WebCore::MediaProducer::IsPlayingAudio)
state |= kWKMediaIsPlayingAudio;
if (coreState & WebCore::MediaProducer::IsPlayingVideo)
state |= kWKMediaIsPlayingVideo;
if (coreState & WebCore::MediaProducer::HasActiveAudioCaptureDevice)
state |= kWKMediaHasActiveAudioCaptureDevice;
if (coreState & WebCore::MediaProducer::HasActiveVideoCaptureDevice)
state |= kWKMediaHasActiveVideoCaptureDevice;
return state;
}
void WKPageClearWheelEventTestTrigger(WKPageRef pageRef)
{
toImpl(pageRef)->clearWheelEventTestTrigger();
}
void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback)
{
toImpl(pageRef)->callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) {
callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
});
}
bool WKPageGetResourceCachingDisabled(WKPageRef page)
{
return toImpl(page)->isResourceCachingDisabled();
}
void WKPageSetResourceCachingDisabled(WKPageRef page, bool disabled)
{
toImpl(page)->setResourceCachingDisabled(disabled);
}
void WKPageSetIgnoresViewportScaleLimits(WKPageRef page, bool ignoresViewportScaleLimits)
{
#if PLATFORM(IOS)
toImpl(page)->setForceAlwaysUserScalable(ignoresViewportScaleLimits);
#endif
}
pid_t WKPageGetProcessIdentifier(WKPageRef page)
{
return toImpl(page)->processIdentifier();
}
#if ENABLE(NETSCAPE_PLUGIN_API)
// -- DEPRECATED --
WKStringRef WKPageGetPluginInformationBundleIdentifierKey()
{
return WKPluginInformationBundleIdentifierKey();
}
WKStringRef WKPageGetPluginInformationBundleVersionKey()
{
return WKPluginInformationBundleVersionKey();
}
WKStringRef WKPageGetPluginInformationDisplayNameKey()
{
return WKPluginInformationDisplayNameKey();
}
WKStringRef WKPageGetPluginInformationFrameURLKey()
{
return WKPluginInformationFrameURLKey();
}
WKStringRef WKPageGetPluginInformationMIMETypeKey()
{
return WKPluginInformationMIMETypeKey();
}
WKStringRef WKPageGetPluginInformationPageURLKey()
{
return WKPluginInformationPageURLKey();
}
WKStringRef WKPageGetPluginInformationPluginspageAttributeURLKey()
{
return WKPluginInformationPluginspageAttributeURLKey();
}
WKStringRef WKPageGetPluginInformationPluginURLKey()
{
return WKPluginInformationPluginURLKey();
}
// -- DEPRECATED --
#endif // ENABLE(NETSCAPE_PLUGIN_API)
|