1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465
|
/*
* Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2012 Intel Corporation. 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 "WebPageProxy.h"
#include "AuthenticationChallengeProxy.h"
#include "AuthenticationDecisionListener.h"
#include "DataReference.h"
#include "DownloadProxy.h"
#include "DrawingAreaProxy.h"
#include "DrawingAreaProxyMessages.h"
#include "EventDispatcherMessages.h"
#include "FindIndicator.h"
#include "ImmutableArray.h"
#include "Logging.h"
#include "NativeWebKeyboardEvent.h"
#include "NativeWebMouseEvent.h"
#include "NativeWebWheelEvent.h"
#include "NotificationPermissionRequest.h"
#include "NotificationPermissionRequestManager.h"
#include "PageClient.h"
#include "PluginInformation.h"
#include "PluginProcessManager.h"
#include "PrintInfo.h"
#include "SessionState.h"
#include "TextChecker.h"
#include "TextCheckerState.h"
#include "WKContextPrivate.h"
#include "WebBackForwardList.h"
#include "WebBackForwardListItem.h"
#include "WebCertificateInfo.h"
#include "WebColorPickerResultListenerProxy.h"
#include "WebContext.h"
#include "WebContextMenuProxy.h"
#include "WebContextUserMessageCoders.h"
#include "WebCoreArgumentCoders.h"
#include "WebData.h"
#include "WebEditCommandProxy.h"
#include "WebEvent.h"
#include "WebFormSubmissionListenerProxy.h"
#include "WebFramePolicyListenerProxy.h"
#include "WebFullScreenManagerProxy.h"
#include "WebFullScreenManagerProxyMessages.h"
#include "WebInspectorProxy.h"
#include "WebInspectorProxyMessages.h"
#include "WebNotificationManagerProxy.h"
#include "WebOpenPanelResultListenerProxy.h"
#include "WebPageCreationParameters.h"
#include "WebPageGroup.h"
#include "WebPageGroupData.h"
#include "WebPageMessages.h"
#include "WebPageProxyMessages.h"
#include "WebPopupItem.h"
#include "WebPopupMenuProxy.h"
#include "WebPreferences.h"
#include "WebProcessMessages.h"
#include "WebProcessProxy.h"
#include "WebProtectionSpace.h"
#include "WebSecurityOrigin.h"
#include "WebURLRequest.h"
#include <WebCore/DragController.h>
#include <WebCore/DragData.h>
#include <WebCore/DragSession.h>
#include <WebCore/FloatRect.h>
#include <WebCore/FocusDirection.h>
#include <WebCore/MIMETypeRegistry.h>
#include <WebCore/RenderEmbeddedObject.h>
#include <WebCore/TextCheckerClient.h>
#include <WebCore/WindowFeatures.h>
#include <stdio.h>
#if USE(COORDINATED_GRAPHICS)
#include "CoordinatedLayerTreeHostProxyMessages.h"
#endif
#if PLATFORM(QT)
#include "ArgumentCodersQt.h"
#endif
#if PLATFORM(GTK)
#include "ArgumentCodersGtk.h"
#endif
#if USE(SOUP)
#include "WebSoupRequestManagerProxy.h"
#endif
#if ENABLE(VIBRATION)
#include "WebVibrationProxy.h"
#endif
#ifndef NDEBUG
#include <wtf/RefCountedLeakCounter.h>
#endif
// This controls what strategy we use for mouse wheel coalescing.
#define MERGE_WHEEL_EVENTS 1
#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
#define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
using namespace WebCore;
// Represents the number of wheel events we can hold in the queue before we start pushing them preemptively.
static const unsigned wheelEventQueueSizeThreshold = 10;
namespace WebKit {
WKPageDebugPaintFlags WebPageProxy::s_debugPaintFlags = 0;
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webPageProxyCounter, ("WebPageProxy"));
class ExceededDatabaseQuotaRecords {
WTF_MAKE_NONCOPYABLE(ExceededDatabaseQuotaRecords); WTF_MAKE_FAST_ALLOCATED;
public:
struct Record {
uint64_t frameID;
String originIdentifier;
String databaseName;
String displayName;
uint64_t currentQuota;
uint64_t currentOriginUsage;
uint64_t currentDatabaseUsage;
uint64_t expectedUsage;
RefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply;
};
static ExceededDatabaseQuotaRecords& shared();
PassOwnPtr<Record> createRecord(uint64_t frameID, String originIdentifier,
String databaseName, String displayName, uint64_t currentQuota,
uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage,
PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>);
void add(PassOwnPtr<Record>);
bool areBeingProcessed() const { return m_currentRecord; }
Record* next();
private:
ExceededDatabaseQuotaRecords() { }
~ExceededDatabaseQuotaRecords() { }
Deque<OwnPtr<Record> > m_records;
OwnPtr<Record> m_currentRecord;
};
ExceededDatabaseQuotaRecords& ExceededDatabaseQuotaRecords::shared()
{
DEFINE_STATIC_LOCAL(ExceededDatabaseQuotaRecords, records, ());
return records;
}
PassOwnPtr<ExceededDatabaseQuotaRecords::Record> ExceededDatabaseQuotaRecords::createRecord(
uint64_t frameID, String originIdentifier, String databaseName, String displayName,
uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage,
uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply)
{
OwnPtr<Record> record = adoptPtr(new Record);
record->frameID = frameID;
record->originIdentifier = originIdentifier;
record->databaseName = databaseName;
record->displayName = displayName;
record->currentQuota = currentQuota;
record->currentOriginUsage = currentOriginUsage;
record->currentDatabaseUsage = currentDatabaseUsage;
record->expectedUsage = expectedUsage;
record->reply = reply;
return record.release();
}
void ExceededDatabaseQuotaRecords::add(PassOwnPtr<ExceededDatabaseQuotaRecords::Record> record)
{
m_records.append(record);
}
ExceededDatabaseQuotaRecords::Record* ExceededDatabaseQuotaRecords::next()
{
m_currentRecord.clear();
if (!m_records.isEmpty())
m_currentRecord = m_records.takeFirst();
return m_currentRecord.get();
}
#if !LOG_DISABLED
static const char* webKeyboardEventTypeString(WebEvent::Type type)
{
switch (type) {
case WebEvent::KeyDown:
return "KeyDown";
case WebEvent::KeyUp:
return "KeyUp";
case WebEvent::RawKeyDown:
return "RawKeyDown";
case WebEvent::Char:
return "Char";
default:
ASSERT_NOT_REACHED();
return "<unknown>";
}
}
#endif // !LOG_DISABLED
PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
{
return adoptRef(new WebPageProxy(pageClient, process, pageGroup, pageID));
}
WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
: m_pageClient(pageClient)
, m_process(process)
, m_pageGroup(pageGroup)
, m_mainFrame(0)
, m_userAgent(standardUserAgent())
, m_geolocationPermissionRequestManager(this)
, m_notificationPermissionRequestManager(this)
, m_estimatedProgress(0)
, m_isInWindow(m_pageClient->isViewInWindow())
, m_isVisible(m_pageClient->isViewVisible())
, m_backForwardList(WebBackForwardList::create(this))
, m_loadStateAtProcessExit(WebFrameProxy::LoadStateFinished)
, m_temporarilyClosedComposition(false)
, m_textZoomFactor(1)
, m_pageZoomFactor(1)
, m_pageScaleFactor(1)
, m_intrinsicDeviceScaleFactor(1)
, m_customDeviceScaleFactor(0)
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
, m_layerHostingMode(LayerHostingModeInWindowServer)
#else
, m_layerHostingMode(LayerHostingModeDefault)
#endif
, m_drawsBackground(true)
, m_drawsTransparentBackground(false)
, m_areMemoryCacheClientCallsEnabled(true)
, m_useFixedLayout(false)
, m_suppressScrollbarAnimations(false)
, m_paginationMode(Pagination::Unpaginated)
, m_paginationBehavesLikeColumns(false)
, m_pageLength(0)
, m_gapBetweenPages(0)
, m_isValid(true)
, m_isClosed(false)
, m_canRunModal(false)
, m_isInPrintingMode(false)
, m_isPerformingDOMPrintOperation(false)
, m_inDecidePolicyForResponseSync(false)
, m_decidePolicyForResponseRequest(0)
, m_syncMimeTypePolicyActionIsValid(false)
, m_syncMimeTypePolicyAction(PolicyUse)
, m_syncMimeTypePolicyDownloadID(0)
, m_inDecidePolicyForNavigationAction(false)
, m_syncNavigationActionPolicyActionIsValid(false)
, m_syncNavigationActionPolicyAction(PolicyUse)
, m_syncNavigationActionPolicyDownloadID(0)
, m_processingMouseMoveEvent(false)
#if ENABLE(TOUCH_EVENTS)
, m_needTouchEvents(false)
#endif
, m_pageID(pageID)
, m_isPageSuspended(false)
#if PLATFORM(MAC)
, m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
#endif
, m_spellDocumentTag(0)
, m_hasSpellDocumentTag(false)
, m_pendingLearnOrIgnoreWordMessageCount(0)
, m_mainFrameHasHorizontalScrollbar(false)
, m_mainFrameHasVerticalScrollbar(false)
, m_canShortCircuitHorizontalWheelEvents(true)
, m_mainFrameIsPinnedToLeftSide(false)
, m_mainFrameIsPinnedToRightSide(false)
, m_mainFrameIsPinnedToTopSide(false)
, m_mainFrameIsPinnedToBottomSide(false)
, m_rubberBandsAtBottom(false)
, m_rubberBandsAtTop(false)
, m_mainFrameInViewSourceMode(false)
, m_pageCount(0)
, m_renderTreeSize(0)
, m_shouldSendEventsSynchronously(false)
, m_suppressVisibilityUpdates(false)
, m_mediaVolume(1)
, m_mayStartMediaWhenInWindow(true)
, m_waitingForDidUpdateInWindowState(false)
#if PLATFORM(MAC)
, m_exposedRectChangedTimer(this, &WebPageProxy::exposedRectChangedTimerFired)
, m_clipsToExposedRect(false)
, m_lastSentClipsToExposedRect(false)
#endif
#if ENABLE(PAGE_VISIBILITY_API)
, m_visibilityState(PageVisibilityStateVisible)
#endif
, m_scrollPinningBehavior(DoNotPin)
{
#if ENABLE(PAGE_VISIBILITY_API)
if (!m_isVisible)
m_visibilityState = PageVisibilityStateHidden;
#endif
#ifndef NDEBUG
webPageProxyCounter.increment();
#endif
WebContext::statistics().wkPageCount++;
m_pageGroup->addPage(this);
#if ENABLE(INSPECTOR)
m_inspector = WebInspectorProxy::create(this);
#endif
#if ENABLE(FULLSCREEN_API)
m_fullScreenManager = WebFullScreenManagerProxy::create(this);
#endif
#if ENABLE(VIBRATION)
m_vibration = WebVibrationProxy::create(this);
#endif
#if ENABLE(THREADED_SCROLLING)
m_rubberBandsAtBottom = true;
m_rubberBandsAtTop = true;
#endif
m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, this);
// FIXME: If we ever expose the session storage size as a preference, we need to pass it here.
m_process->context()->storageManager().createSessionStorageNamespace(m_pageID, m_process->isValid() ? m_process->connection() : 0, std::numeric_limits<unsigned>::max());
}
WebPageProxy::~WebPageProxy()
{
if (!m_isClosed)
close();
WebContext::statistics().wkPageCount--;
if (m_hasSpellDocumentTag)
TextChecker::closeSpellDocumentWithTag(m_spellDocumentTag);
m_pageGroup->removePage(this);
#ifndef NDEBUG
webPageProxyCounter.decrement();
#endif
}
WebProcessProxy* WebPageProxy::process() const
{
return m_process.get();
}
PlatformProcessIdentifier WebPageProxy::processIdentifier() const
{
if (m_isClosed)
return 0;
return m_process->processIdentifier();
}
bool WebPageProxy::isValid() const
{
// A page that has been explicitly closed is never valid.
if (m_isClosed)
return false;
return m_isValid;
}
PassRefPtr<ImmutableArray> WebPageProxy::relatedPages() const
{
// pages() returns a list of pages in WebProcess, so this page may or may not be among them - a client can use a reference to WebPageProxy after the page has closed.
Vector<WebPageProxy*> pages = m_process->pages();
Vector<RefPtr<APIObject> > result;
result.reserveCapacity(pages.size());
for (size_t i = 0; i < pages.size(); ++i) {
if (pages[i] != this)
result.append(pages[i]);
}
return ImmutableArray::adopt(result);
}
void WebPageProxy::initializeLoaderClient(const WKPageLoaderClient* loadClient)
{
m_loaderClient.initialize(loadClient);
if (!loadClient)
return;
// 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 (loadClient->didFirstLayoutForFrame)
milestones |= WebCore::DidFirstLayout;
if (loadClient->didFirstVisuallyNonEmptyLayoutForFrame)
milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
if (loadClient->didNewFirstVisuallyNonEmptyLayout)
milestones |= WebCore::DidHitRelevantRepaintedObjectsAreaThreshold;
if (milestones)
m_process->send(Messages::WebPage::ListenForLayoutMilestones(milestones), m_pageID);
m_process->send(Messages::WebPage::SetWillGoToBackForwardItemCallbackEnabled(loadClient->version > 0), m_pageID);
}
void WebPageProxy::initializePolicyClient(const WKPagePolicyClient* policyClient)
{
m_policyClient.initialize(policyClient);
}
void WebPageProxy::initializeFormClient(const WKPageFormClient* formClient)
{
m_formClient.initialize(formClient);
}
void WebPageProxy::initializeUIClient(const WKPageUIClient* client)
{
if (!isValid())
return;
m_uiClient.initialize(client);
m_process->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient.canRunBeforeUnloadConfirmPanel()), m_pageID);
setCanRunModal(m_uiClient.canRunModal());
}
void WebPageProxy::initializeFindClient(const WKPageFindClient* client)
{
m_findClient.initialize(client);
}
void WebPageProxy::initializeFindMatchesClient(const WKPageFindMatchesClient* client)
{
m_findMatchesClient.initialize(client);
}
#if ENABLE(CONTEXT_MENUS)
void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClient* client)
{
m_contextMenuClient.initialize(client);
}
#endif
void WebPageProxy::reattachToWebProcess()
{
ASSERT(!isValid());
ASSERT(m_process);
ASSERT(!m_process->isValid());
ASSERT(!m_process->isLaunching());
m_isValid = true;
if (m_process->context()->processModel() == ProcessModelSharedSecondaryProcess)
m_process = m_process->context()->ensureSharedWebProcess();
else
m_process = m_process->context()->createNewWebProcessRespectingProcessCountLimit();
m_process->addExistingWebPage(this, m_pageID);
m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, this);
#if ENABLE(INSPECTOR)
m_inspector = WebInspectorProxy::create(this);
#endif
#if ENABLE(FULLSCREEN_API)
m_fullScreenManager = WebFullScreenManagerProxy::create(this);
#endif
initializeWebPage();
m_pageClient->didRelaunchProcess();
m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
}
void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
{
if (item && item != m_backForwardList->currentItem())
m_backForwardList->goToItem(item);
reattachToWebProcess();
if (!item)
return;
m_process->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::initializeWebPage()
{
ASSERT(isValid());
BackForwardListItemVector items = m_backForwardList->entries();
for (size_t i = 0; i < items.size(); ++i)
m_process->registerNewWebBackForwardListItem(items[i].get());
m_drawingArea = m_pageClient->createDrawingAreaProxy();
ASSERT(m_drawingArea);
#if ENABLE(INSPECTOR_SERVER)
if (m_pageGroup->preferences()->developerExtrasEnabled())
inspector()->enableRemoteInspection();
#endif
m_process->send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
#if ENABLE(PAGE_VISIBILITY_API)
m_process->send(Messages::WebPage::SetVisibilityState(m_visibilityState, /* isInitialState */ true), m_pageID);
#elif ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
m_process->send(Messages::WebPage::SetVisibilityState(m_isVisible ? PageVisibilityStateVisible : PageVisibilityStateHidden, /* isInitialState */ true), m_pageID);
#endif
#if PLATFORM(MAC)
m_process->send(Messages::WebPage::SetSmartInsertDeleteEnabled(m_isSmartInsertDeleteEnabled), m_pageID);
#endif
}
void WebPageProxy::close()
{
if (!isValid())
return;
m_isClosed = true;
m_backForwardList->pageClosed();
m_pageClient->pageClosed();
m_process->disconnectFramesFromPage(this);
m_mainFrame = 0;
#if ENABLE(INSPECTOR)
if (m_inspector) {
m_inspector->invalidate();
m_inspector = 0;
}
#endif
#if ENABLE(FULLSCREEN_API)
if (m_fullScreenManager) {
m_fullScreenManager->invalidate();
m_fullScreenManager = 0;
}
#endif
#if ENABLE(VIBRATION)
m_vibration->invalidate();
#endif
if (m_openPanelResultListener) {
m_openPanelResultListener->invalidate();
m_openPanelResultListener = 0;
}
#if ENABLE(INPUT_TYPE_COLOR)
if (m_colorPicker) {
m_colorPicker->invalidate();
m_colorPicker = nullptr;
}
if (m_colorPickerResultListener) {
m_colorPickerResultListener->invalidate();
m_colorPickerResultListener = nullptr;
}
#endif
#if ENABLE(GEOLOCATION)
m_geolocationPermissionRequestManager.invalidateRequests();
#endif
m_notificationPermissionRequestManager.invalidateRequests();
m_process->context()->supplement<WebNotificationManagerProxy>()->clearNotifications(this);
m_toolTip = String();
m_mainFrameHasHorizontalScrollbar = false;
m_mainFrameHasVerticalScrollbar = false;
m_mainFrameIsPinnedToLeftSide = false;
m_mainFrameIsPinnedToRightSide = false;
m_mainFrameIsPinnedToTopSide = false;
m_mainFrameIsPinnedToBottomSide = false;
m_visibleScrollerThumbRect = IntRect();
invalidateCallbackMap(m_voidCallbacks);
invalidateCallbackMap(m_dataCallbacks);
invalidateCallbackMap(m_imageCallbacks);
invalidateCallbackMap(m_stringCallbacks);
m_loadDependentStringCallbackIDs.clear();
invalidateCallbackMap(m_scriptValueCallbacks);
invalidateCallbackMap(m_computedPagesCallbacks);
#if PLATFORM(GTK)
invalidateCallbackMap(m_printFinishedCallbacks);
#endif
Vector<WebEditCommandProxy*> editCommandVector;
copyToVector(m_editCommandSet, editCommandVector);
m_editCommandSet.clear();
for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
editCommandVector[i]->invalidate();
m_activePopupMenu = 0;
m_estimatedProgress = 0.0;
m_loaderClient.initialize(0);
m_policyClient.initialize(0);
m_formClient.initialize(0);
m_uiClient.initialize(0);
#if PLATFORM(EFL)
m_uiPopupMenuClient.initialize(0);
#endif
m_findClient.initialize(0);
m_findMatchesClient.initialize(0);
#if ENABLE(CONTEXT_MENUS)
m_contextMenuClient.initialize(0);
#endif
m_drawingArea = nullptr;
#if PLATFORM(MAC)
m_exposedRectChangedTimer.stop();
#endif
m_process->send(Messages::WebPage::Close(), m_pageID);
m_process->removeWebPage(m_pageID);
m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
m_process->context()->storageManager().destroySessionStorageNamespace(m_pageID);
}
bool WebPageProxy::tryClose()
{
if (!isValid())
return true;
m_process->send(Messages::WebPage::TryClose(), m_pageID);
m_process->responsivenessTimer()->start();
return false;
}
bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
{
if (!url.isLocalFile())
return false;
#if ENABLE(INSPECTOR)
// Don't give the inspector full access to the file system.
if (WebInspectorProxy::isInspectorPage(this))
return false;
#endif
SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
return true;
}
void WebPageProxy::loadURL(const String& url, APIObject* userData)
{
setPendingAPIRequestURL(url);
if (!isValid())
reattachToWebProcess();
SandboxExtension::Handle sandboxExtensionHandle;
bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
if (createdExtension)
m_process->willAcquireUniversalFileReadSandboxExtension();
m_process->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest, APIObject* userData)
{
setPendingAPIRequestURL(urlRequest->resourceRequest().url());
if (!isValid())
reattachToWebProcess();
SandboxExtension::Handle sandboxExtensionHandle;
bool createdExtension = maybeInitializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
if (createdExtension)
m_process->willAcquireUniversalFileReadSandboxExtension();
m_process->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
KURL fileURL = KURL(KURL(), fileURLString);
if (!fileURL.isLocalFile())
return;
KURL resourceDirectoryURL;
if (resourceDirectoryURLString.isNull())
resourceDirectoryURL = KURL(ParsedURLString, ASCIILiteral("file:///"));
else {
resourceDirectoryURL = KURL(KURL(), resourceDirectoryURLString);
if (!resourceDirectoryURL.isLocalFile())
return;
}
String resourceDirectoryPath = resourceDirectoryURL.fileSystemPath();
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
m_process->assumeReadAccessToBaseURL(resourceDirectoryURL);
m_process->send(Messages::WebPage::LoadURL(fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadData(WebData* data, const String& MIMEType, const String& encoding, const String& baseURL, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
m_process->assumeReadAccessToBaseURL(baseURL);
m_process->send(Messages::WebPage::LoadData(data->dataReference(), MIMEType, encoding, baseURL, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseURL, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
m_process->assumeReadAccessToBaseURL(baseURL);
m_process->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
if (m_mainFrame)
m_mainFrame->setUnreachableURL(unreachableURL);
m_process->assumeReadAccessToBaseURL(baseURL);
m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadPlainTextString(const String& string, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
m_process->send(Messages::WebPage::LoadPlainTextString(string, WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::loadWebArchiveData(const WebData* webArchiveData, APIObject* userData)
{
if (!isValid())
reattachToWebProcess();
m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), WebContextUserMessageEncoder(userData)), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::stopLoading()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::StopLoading(), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::reload(bool reloadFromOrigin)
{
SandboxExtension::Handle sandboxExtensionHandle;
if (m_backForwardList->currentItem()) {
String url = m_backForwardList->currentItem()->url();
setPendingAPIRequestURL(url);
// We may not have an extension yet if back/forward list was reinstated after a WebProcess crash or a browser relaunch
bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
if (createdExtension)
m_process->willAcquireUniversalFileReadSandboxExtension();
}
if (!isValid()) {
reattachToWebProcessWithItem(m_backForwardList->currentItem());
return;
}
m_process->send(Messages::WebPage::Reload(reloadFromOrigin, sandboxExtensionHandle), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::goForward()
{
if (isValid() && !canGoForward())
return;
WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
if (!forwardItem)
return;
setPendingAPIRequestURL(forwardItem->url());
if (!isValid()) {
reattachToWebProcessWithItem(forwardItem);
return;
}
m_process->send(Messages::WebPage::GoForward(forwardItem->itemID()), m_pageID);
m_process->responsivenessTimer()->start();
}
bool WebPageProxy::canGoForward() const
{
return m_backForwardList->forwardItem();
}
void WebPageProxy::goBack()
{
if (isValid() && !canGoBack())
return;
WebBackForwardListItem* backItem = m_backForwardList->backItem();
if (!backItem)
return;
setPendingAPIRequestURL(backItem->url());
if (!isValid()) {
reattachToWebProcessWithItem(backItem);
return;
}
m_process->send(Messages::WebPage::GoBack(backItem->itemID()), m_pageID);
m_process->responsivenessTimer()->start();
}
bool WebPageProxy::canGoBack() const
{
return m_backForwardList->backItem();
}
void WebPageProxy::goToBackForwardItem(WebBackForwardListItem* item)
{
if (!isValid()) {
reattachToWebProcessWithItem(item);
return;
}
setPendingAPIRequestURL(item->url());
m_process->send(Messages::WebPage::GoToBackForwardItem(item->itemID()), m_pageID);
m_process->responsivenessTimer()->start();
}
void WebPageProxy::tryRestoreScrollPosition()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::TryRestoreScrollPosition(), m_pageID);
}
void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vector<RefPtr<APIObject> >* removed)
{
m_loaderClient.didChangeBackForwardList(this, added, removed);
}
void WebPageProxy::shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardItem)
{
WebBackForwardListItem* item = m_process->webBackForwardItem(itemID);
shouldGoToBackForwardItem = item && m_loaderClient.shouldGoToBackForwardListItem(this, item);
}
void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
if (WebBackForwardListItem* item = m_process->webBackForwardItem(itemID))
m_loaderClient.willGoToBackForwardListItem(this, item, userData.get());
}
String WebPageProxy::activeURL() const
{
// If there is a currently pending url, it is the active URL,
// even when there's no main frame yet, as it might be the
// first API request.
if (!m_pendingAPIRequestURL.isNull())
return m_pendingAPIRequestURL;
if (!m_mainFrame)
return String();
if (!m_mainFrame->unreachableURL().isEmpty())
return m_mainFrame->unreachableURL();
switch (m_mainFrame->loadState()) {
case WebFrameProxy::LoadStateProvisional:
return m_mainFrame->provisionalURL();
case WebFrameProxy::LoadStateCommitted:
case WebFrameProxy::LoadStateFinished:
return m_mainFrame->url();
}
ASSERT_NOT_REACHED();
return String();
}
String WebPageProxy::provisionalURL() const
{
if (!m_mainFrame)
return String();
return m_mainFrame->provisionalURL();
}
String WebPageProxy::committedURL() const
{
if (!m_mainFrame)
return String();
return m_mainFrame->url();
}
bool WebPageProxy::canShowMIMEType(const String& mimeType) const
{
if (MIMETypeRegistry::canShowMIMEType(mimeType))
return true;
#if ENABLE(NETSCAPE_PLUGIN_API)
String newMimeType = mimeType;
PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL());
if (!plugin.path.isNull() && m_pageGroup->preferences()->pluginsEnabled())
return true;
#endif // ENABLE(NETSCAPE_PLUGIN_API)
#if PLATFORM(MAC)
// On Mac, we can show PDFs.
if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(mimeType) && !WebContext::omitPDFSupport())
return true;
#endif // PLATFORM(MAC)
return false;
}
void WebPageProxy::setDrawsBackground(bool drawsBackground)
{
if (m_drawsBackground == drawsBackground)
return;
m_drawsBackground = drawsBackground;
if (isValid())
m_process->send(Messages::WebPage::SetDrawsBackground(drawsBackground), m_pageID);
}
void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground)
{
if (m_drawsTransparentBackground == drawsTransparentBackground)
return;
m_drawsTransparentBackground = drawsTransparentBackground;
if (isValid())
m_process->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
}
void WebPageProxy::setUnderlayColor(const Color& color)
{
if (m_underlayColor == color)
return;
m_underlayColor = color;
if (isValid())
m_process->send(Messages::WebPage::SetUnderlayColor(color), m_pageID);
}
void WebPageProxy::viewWillStartLiveResize()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ViewWillStartLiveResize(), m_pageID);
}
void WebPageProxy::viewWillEndLiveResize()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ViewWillEndLiveResize(), m_pageID);
}
void WebPageProxy::setViewNeedsDisplay(const IntRect& rect)
{
m_pageClient->setViewNeedsDisplay(rect);
}
void WebPageProxy::displayView()
{
m_pageClient->displayView();
}
bool WebPageProxy::canScrollView()
{
return m_pageClient->canScrollView();
}
void WebPageProxy::scrollView(const IntRect& scrollRect, const IntSize& scrollOffset)
{
m_pageClient->scrollView(scrollRect, scrollOffset);
}
void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
{
if (!isValid())
return;
if (flags & ViewIsFocused)
m_process->send(Messages::WebPage::SetFocused(m_pageClient->isViewFocused()), m_pageID);
if (flags & ViewWindowIsActive)
m_process->send(Messages::WebPage::SetActive(m_pageClient->isViewWindowActive()), m_pageID);
if (flags & ViewIsVisible) {
bool isVisible = m_pageClient->isViewVisible();
if (isVisible != m_isVisible) {
m_isVisible = isVisible;
m_process->pageVisibilityChanged(this);
m_drawingArea->visibilityDidChange();
if (!m_isVisible) {
// If we've started the responsiveness timer as part of telling the web process to update the backing store
// state, it might not send back a reply (since it won't paint anything if the web page is hidden) so we
// stop the unresponsiveness timer here.
m_process->responsivenessTimer()->stop();
}
#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING) && !ENABLE(PAGE_VISIBILITY_API)
PageVisibilityState visibilityState = m_isVisible ? PageVisibilityStateVisible : PageVisibilityStateHidden;
m_process->send(Messages::WebPage::SetVisibilityState(visibilityState, false), m_pageID);
#endif
}
}
if (flags & ViewIsInWindow) {
bool isInWindow = m_pageClient->isViewInWindow();
if (m_isInWindow != isInWindow) {
m_isInWindow = isInWindow;
m_process->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
}
if (isInWindow) {
LayerHostingMode layerHostingMode = m_pageClient->viewLayerHostingMode();
if (m_layerHostingMode != layerHostingMode) {
m_layerHostingMode = layerHostingMode;
m_drawingArea->layerHostingModeDidChange();
}
}
}
#if ENABLE(PAGE_VISIBILITY_API)
PageVisibilityState visibilityState = PageVisibilityStateHidden;
if (m_isVisible)
visibilityState = PageVisibilityStateVisible;
if (visibilityState != m_visibilityState) {
m_visibilityState = visibilityState;
m_process->send(Messages::WebPage::SetVisibilityState(visibilityState, false), m_pageID);
}
#endif
updateBackingStoreDiscardableState();
}
void WebPageProxy::waitForDidUpdateInWindowState()
{
// If we have previously timed out with no response from the WebProcess, don't block the UIProcess again until it starts responding.
if (m_waitingForDidUpdateInWindowState)
return;
if (!isValid())
return;
m_waitingForDidUpdateInWindowState = true;
if (!m_process->isLaunching()) {
const double inWindowStateUpdateTimeout = 0.25;
m_process->connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DidUpdateInWindowState>(m_pageID, inWindowStateUpdateTimeout);
}
}
IntSize WebPageProxy::viewSize() const
{
return m_pageClient->viewSize();
}
void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent), m_pageID);
}
void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::SetWindowResizerSize(windowResizerSize), m_pageID);
}
void WebPageProxy::clearSelection()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ClearSelection(), m_pageID);
}
void WebPageProxy::validateCommand(const String& commandName, PassRefPtr<ValidateCommandCallback> callback)
{
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_validateCommandCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID);
}
void WebPageProxy::setMaintainsInactiveSelection(bool newValue)
{
m_maintainsInactiveSelection = newValue;
}
void WebPageProxy::executeEditCommand(const String& commandName)
{
if (!isValid())
return;
DEFINE_STATIC_LOCAL(String, ignoreSpellingCommandName, (ASCIILiteral("ignoreSpelling")));
if (commandName == ignoreSpellingCommandName)
++m_pendingLearnOrIgnoreWordMessageCount;
m_process->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
}
#if USE(TILED_BACKING_STORE)
void WebPageProxy::commitPageTransitionViewport()
{
if (!isValid())
return;
process()->send(Messages::WebPage::CommitPageTransitionViewport(), m_pageID);
}
#endif
#if ENABLE(DRAG_SUPPORT)
void WebPageProxy::dragEntered(DragData* dragData, const String& dragStorageName)
{
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
performDragControllerAction(DragControllerActionEntered, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
}
void WebPageProxy::dragUpdated(DragData* dragData, const String& dragStorageName)
{
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
performDragControllerAction(DragControllerActionUpdated, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
}
void WebPageProxy::dragExited(DragData* dragData, const String& dragStorageName)
{
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::HandleArray sandboxExtensionHandleEmptyArray;
performDragControllerAction(DragControllerActionExited, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionHandleEmptyArray);
}
void WebPageProxy::performDrag(DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
{
performDragControllerAction(DragControllerActionPerformDrag, dragData, dragStorageName, sandboxExtensionHandle, sandboxExtensionsForUpload);
}
void WebPageProxy::performDragControllerAction(DragControllerAction action, DragData* dragData, const String& dragStorageName, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsForUpload)
{
if (!isValid())
return;
#if PLATFORM(QT) || PLATFORM(GTK)
m_process->send(Messages::WebPage::PerformDragControllerAction(action, *dragData), m_pageID);
#else
m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(), dragData->draggingSourceOperationMask(), dragStorageName, dragData->flags(), sandboxExtensionHandle, sandboxExtensionsForUpload), m_pageID);
#endif
}
void WebPageProxy::didPerformDragControllerAction(WebCore::DragSession dragSession)
{
m_currentDragSession = dragSession;
}
#if PLATFORM(QT) || PLATFORM(GTK)
void WebPageProxy::startDrag(const DragData& dragData, const ShareableBitmap::Handle& dragImageHandle)
{
RefPtr<ShareableBitmap> dragImage = 0;
if (!dragImageHandle.isNull()) {
dragImage = ShareableBitmap::create(dragImageHandle);
if (!dragImage)
return;
}
m_pageClient->startDrag(dragData, dragImage.release());
}
#endif
void WebPageProxy::dragEnded(const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t operation)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::DragEnded(clientPosition, globalPosition, operation), m_pageID);
}
#endif // ENABLE(DRAG_SUPPORT)
void WebPageProxy::handleMouseEvent(const NativeWebMouseEvent& event)
{
if (!isValid())
return;
// NOTE: This does not start the responsiveness timer because mouse move should not indicate interaction.
if (event.type() != WebEvent::MouseMove)
m_process->responsivenessTimer()->start();
else {
if (m_processingMouseMoveEvent) {
m_nextMouseMoveEvent = adoptPtr(new NativeWebMouseEvent(event));
return;
}
m_processingMouseMoveEvent = true;
}
// <https://bugs.webkit.org/show_bug.cgi?id=57904> We need to keep track of the mouse down event in the case where we
// display a popup menu for select elements. When the user changes the selected item,
// we fake a mouse up event by using this stored down event. This event gets cleared
// when the mouse up message is received from WebProcess.
if (event.type() == WebEvent::MouseDown)
m_currentlyProcessedMouseDownEvent = adoptPtr(new NativeWebMouseEvent(event));
if (m_shouldSendEventsSynchronously) {
bool handled = false;
m_process->sendSync(Messages::WebPage::MouseEventSyncForTesting(event), Messages::WebPage::MouseEventSyncForTesting::Reply(handled), m_pageID);
didReceiveEvent(event.type(), handled);
} else
m_process->send(Messages::WebPage::MouseEvent(event), m_pageID);
}
#if MERGE_WHEEL_EVENTS
static bool canCoalesce(const WebWheelEvent& a, const WebWheelEvent& b)
{
if (a.position() != b.position())
return false;
if (a.globalPosition() != b.globalPosition())
return false;
if (a.modifiers() != b.modifiers())
return false;
if (a.granularity() != b.granularity())
return false;
#if PLATFORM(MAC)
if (a.phase() != b.phase())
return false;
if (a.momentumPhase() != b.momentumPhase())
return false;
if (a.hasPreciseScrollingDeltas() != b.hasPreciseScrollingDeltas())
return false;
#endif
return true;
}
static WebWheelEvent coalesce(const WebWheelEvent& a, const WebWheelEvent& b)
{
ASSERT(canCoalesce(a, b));
FloatSize mergedDelta = a.delta() + b.delta();
FloatSize mergedWheelTicks = a.wheelTicks() + b.wheelTicks();
#if PLATFORM(MAC)
FloatSize mergedUnacceleratedScrollingDelta = a.unacceleratedScrollingDelta() + b.unacceleratedScrollingDelta();
return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.directionInvertedFromDevice(), b.phase(), b.momentumPhase(), b.hasPreciseScrollingDeltas(), b.scrollCount(), mergedUnacceleratedScrollingDelta, b.modifiers(), b.timestamp());
#else
return WebWheelEvent(WebEvent::Wheel, b.position(), b.globalPosition(), mergedDelta, mergedWheelTicks, b.granularity(), b.modifiers(), b.timestamp());
#endif
}
#endif // MERGE_WHEEL_EVENTS
static WebWheelEvent coalescedWheelEvent(Deque<NativeWebWheelEvent>& queue, Vector<NativeWebWheelEvent>& coalescedEvents)
{
ASSERT(!queue.isEmpty());
ASSERT(coalescedEvents.isEmpty());
#if MERGE_WHEEL_EVENTS
NativeWebWheelEvent firstEvent = queue.takeFirst();
coalescedEvents.append(firstEvent);
WebWheelEvent event = firstEvent;
while (!queue.isEmpty() && canCoalesce(event, queue.first())) {
NativeWebWheelEvent firstEvent = queue.takeFirst();
coalescedEvents.append(firstEvent);
event = coalesce(event, firstEvent);
}
return event;
#else
while (!queue.isEmpty())
coalescedEvents.append(queue.takeFirst());
return coalescedEvents.last();
#endif
}
void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
{
if (!isValid())
return;
if (!m_currentlyProcessedWheelEvents.isEmpty()) {
m_wheelEventQueue.append(event);
if (m_wheelEventQueue.size() < wheelEventQueueSizeThreshold)
return;
// The queue has too many wheel events, so push a new event.
}
if (!m_wheelEventQueue.isEmpty()) {
processNextQueuedWheelEvent();
return;
}
OwnPtr<Vector<NativeWebWheelEvent> > coalescedWheelEvent = adoptPtr(new Vector<NativeWebWheelEvent>);
coalescedWheelEvent->append(event);
m_currentlyProcessedWheelEvents.append(coalescedWheelEvent.release());
sendWheelEvent(event);
}
void WebPageProxy::processNextQueuedWheelEvent()
{
OwnPtr<Vector<NativeWebWheelEvent> > nextCoalescedEvent = adoptPtr(new Vector<NativeWebWheelEvent>);
WebWheelEvent nextWheelEvent = coalescedWheelEvent(m_wheelEventQueue, *nextCoalescedEvent.get());
m_currentlyProcessedWheelEvents.append(nextCoalescedEvent.release());
sendWheelEvent(nextWheelEvent);
}
void WebPageProxy::sendWheelEvent(const WebWheelEvent& event)
{
m_process->responsivenessTimer()->start();
if (m_shouldSendEventsSynchronously) {
bool handled = false;
m_process->sendSync(Messages::WebPage::WheelEventSyncForTesting(event), Messages::WebPage::WheelEventSyncForTesting::Reply(handled), m_pageID);
didReceiveEvent(event.type(), handled);
return;
}
m_process->send(Messages::EventDispatcher::WheelEvent(m_pageID, event, canGoBack(), canGoForward()), 0);
}
void WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
{
if (!isValid())
return;
LOG(KeyHandling, "WebPageProxy::handleKeyboardEvent: %s", webKeyboardEventTypeString(event.type()));
m_keyEventQueue.append(event);
m_process->responsivenessTimer()->start();
if (m_shouldSendEventsSynchronously) {
bool handled = false;
m_process->sendSync(Messages::WebPage::KeyEventSyncForTesting(event), Messages::WebPage::KeyEventSyncForTesting::Reply(handled), m_pageID);
didReceiveEvent(event.type(), handled);
} else if (m_keyEventQueue.size() == 1) // Otherwise, sent from DidReceiveEvent message handler.
m_process->send(Messages::WebPage::KeyEvent(event), m_pageID);
}
#if ENABLE(NETSCAPE_PLUGIN_API)
void WebPageProxy::findPlugin(const String& mimeType, uint32_t processType, const String& urlString, const String& frameURLString, const String& pageURLString, bool allowOnlyApplicationPlugins, uint64_t& pluginProcessToken, String& newMimeType, uint32_t& pluginLoadPolicy, String& unavailabilityDescription)
{
MESSAGE_CHECK_URL(urlString);
newMimeType = mimeType.lower();
pluginLoadPolicy = PluginModuleLoadNormally;
PluginData::AllowedPluginTypes allowedPluginTypes = allowOnlyApplicationPlugins ? PluginData::OnlyApplicationPlugins : PluginData::AllPlugins;
PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), urlString), allowedPluginTypes);
if (!plugin.path) {
pluginProcessToken = 0;
return;
}
pluginLoadPolicy = PluginInfoStore::defaultLoadPolicyForPlugin(plugin);
#if PLATFORM(MAC)
RefPtr<ImmutableDictionary> pluginInformation = createPluginInformationDictionary(plugin, frameURLString, String(), pageURLString, String(), String());
pluginLoadPolicy = m_loaderClient.pluginLoadPolicy(this, static_cast<PluginModuleLoadPolicy>(pluginLoadPolicy), pluginInformation.get(), unavailabilityDescription);
#else
UNUSED_PARAM(frameURLString);
UNUSED_PARAM(pageURLString);
#endif
PluginProcessSandboxPolicy pluginProcessSandboxPolicy = PluginProcessSandboxPolicyNormal;
switch (pluginLoadPolicy) {
case PluginModuleLoadNormally:
pluginProcessSandboxPolicy = PluginProcessSandboxPolicyNormal;
break;
case PluginModuleLoadUnsandboxed:
pluginProcessSandboxPolicy = PluginProcessSandboxPolicyUnsandboxed;
break;
case PluginModuleBlocked:
pluginProcessToken = 0;
return;
}
pluginProcessToken = PluginProcessManager::shared().pluginProcessToken(plugin, static_cast<PluginProcessType>(processType), pluginProcessSandboxPolicy);
}
#endif // ENABLE(NETSCAPE_PLUGIN_API)
#if ENABLE(GESTURE_EVENTS)
void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
{
if (!isValid())
return;
m_gestureEventQueue.append(event);
m_process->responsivenessTimer()->start();
m_process->send(Messages::EventDispatcher::GestureEvent(m_pageID, event), 0);
}
#endif
#if ENABLE(TOUCH_EVENTS)
#if PLATFORM(QT)
void WebPageProxy::handlePotentialActivation(const IntPoint& touchPoint, const IntSize& touchArea)
{
m_process->send(Messages::WebPage::HighlightPotentialActivation(touchPoint, touchArea), m_pageID);
}
#endif
void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event)
{
if (!isValid())
return;
// If the page is suspended, which should be the case during panning, pinching
// and animation on the page itself (kinetic scrolling, tap to zoom) etc, then
// we do not send any of the events to the page even if is has listeners.
if (m_needTouchEvents && !m_isPageSuspended) {
m_touchEventQueue.append(event);
m_process->responsivenessTimer()->start();
if (m_shouldSendEventsSynchronously) {
bool handled = false;
m_process->sendSync(Messages::WebPage::TouchEventSyncForTesting(event), Messages::WebPage::TouchEventSyncForTesting::Reply(handled), m_pageID);
didReceiveEvent(event.type(), handled);
} else
m_process->send(Messages::WebPage::TouchEvent(event), m_pageID);
} else {
if (m_touchEventQueue.isEmpty()) {
bool isEventHandled = false;
m_pageClient->doneWithTouchEvent(event, isEventHandled);
} else {
// We attach the incoming events to the newest queued event so that all
// the events are delivered in the correct order when the event is dequed.
QueuedTouchEvents& lastEvent = m_touchEventQueue.last();
lastEvent.deferredTouchEvents.append(event);
}
}
}
#endif
void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granularity)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ScrollBy(direction, granularity), m_pageID);
}
void WebPageProxy::centerSelectionInVisibleArea()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::CenterSelectionInVisibleArea(), m_pageID);
}
void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
{
if (!isValid())
return;
if (action == PolicyIgnore)
clearPendingAPIRequestURL();
uint64_t downloadID = 0;
if (action == PolicyDownload) {
// Create a download proxy.
DownloadProxy* download = m_process->context()->createDownloadProxy();
downloadID = download->downloadID();
#if PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
// Our design does not suppport downloads without a WebPage.
handleDownloadRequest(download);
#endif
}
// If we received a policy decision while in decidePolicyForResponse the decision will
// be sent back to the web process by decidePolicyForResponse.
if (m_inDecidePolicyForResponseSync) {
m_syncMimeTypePolicyActionIsValid = true;
m_syncMimeTypePolicyAction = action;
m_syncMimeTypePolicyDownloadID = downloadID;
return;
}
// If we received a policy decision while in decidePolicyForNavigationAction the decision will
// be sent back to the web process by decidePolicyForNavigationAction.
if (m_inDecidePolicyForNavigationAction) {
m_syncNavigationActionPolicyActionIsValid = true;
m_syncNavigationActionPolicyAction = action;
m_syncNavigationActionPolicyDownloadID = downloadID;
return;
}
m_process->send(Messages::WebPage::DidReceivePolicyDecision(frame->frameID(), listenerID, action, downloadID), m_pageID);
}
String WebPageProxy::pageTitle() const
{
// Return the null string if there is no main frame (e.g. nothing has been loaded in the page yet, WebProcess has
// crashed, page has been closed).
if (!m_mainFrame)
return String();
return m_mainFrame->title();
}
void WebPageProxy::setUserAgent(const String& userAgent)
{
if (m_userAgent == userAgent)
return;
m_userAgent = userAgent;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
}
void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
{
if (m_applicationNameForUserAgent == applicationName)
return;
m_applicationNameForUserAgent = applicationName;
if (!m_customUserAgent.isEmpty())
return;
setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
}
void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
{
if (m_customUserAgent == customUserAgent)
return;
m_customUserAgent = customUserAgent;
if (m_customUserAgent.isEmpty()) {
setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
return;
}
setUserAgent(m_customUserAgent);
}
void WebPageProxy::resumeActiveDOMObjectsAndAnimations()
{
if (!isValid() || !m_isPageSuspended)
return;
m_isPageSuspended = false;
m_process->send(Messages::WebPage::ResumeActiveDOMObjectsAndAnimations(), m_pageID);
}
void WebPageProxy::suspendActiveDOMObjectsAndAnimations()
{
if (!isValid() || m_isPageSuspended)
return;
m_isPageSuspended = true;
m_process->send(Messages::WebPage::SuspendActiveDOMObjectsAndAnimations(), m_pageID);
}
bool WebPageProxy::supportsTextEncoding() const
{
// FIXME (118840): We should probably only support this for text documents, not all non-image documents.
return m_mainFrame && !m_mainFrame->isDisplayingStandaloneImageDocument();
}
void WebPageProxy::setCustomTextEncodingName(const String& encodingName)
{
if (m_customTextEncodingName == encodingName)
return;
m_customTextEncodingName = encodingName;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetCustomTextEncodingName(encodingName), m_pageID);
}
void WebPageProxy::terminateProcess()
{
// NOTE: This uses a check of m_isValid rather than calling isValid() since
// we want this to run even for pages being closed or that already closed.
if (!m_isValid)
return;
m_process->requestTermination();
resetStateAfterProcessExited();
}
#if !USE(CF) || defined(BUILDING_QT__)
PassRefPtr<WebData> WebPageProxy::sessionStateData(WebPageProxySessionStateFilterCallback, void* /*context*/) const
{
// FIXME: Return session state data for saving Page state.
return 0;
}
void WebPageProxy::restoreFromSessionStateData(WebData*)
{
// FIXME: Restore the Page from the passed in session state data.
}
#endif
bool WebPageProxy::supportsTextZoom() const
{
// FIXME (118840): This should also return false for standalone media and plug-in documents.
if (!m_mainFrame || m_mainFrame->isDisplayingStandaloneImageDocument())
return false;
return true;
}
void WebPageProxy::setTextZoomFactor(double zoomFactor)
{
if (!isValid())
return;
if (m_textZoomFactor == zoomFactor)
return;
m_textZoomFactor = zoomFactor;
m_process->send(Messages::WebPage::SetTextZoomFactor(m_textZoomFactor), m_pageID);
}
void WebPageProxy::setPageZoomFactor(double zoomFactor)
{
if (!isValid())
return;
if (m_pageZoomFactor == zoomFactor)
return;
m_pageZoomFactor = zoomFactor;
m_process->send(Messages::WebPage::SetPageZoomFactor(m_pageZoomFactor), m_pageID);
}
void WebPageProxy::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
{
if (!isValid())
return;
if (m_pageZoomFactor == pageZoomFactor && m_textZoomFactor == textZoomFactor)
return;
m_pageZoomFactor = pageZoomFactor;
m_textZoomFactor = textZoomFactor;
m_process->send(Messages::WebPage::SetPageAndTextZoomFactors(m_pageZoomFactor, m_textZoomFactor), m_pageID);
}
void WebPageProxy::scalePage(double scale, const IntPoint& origin)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ScalePage(scale, origin), m_pageID);
}
void WebPageProxy::setIntrinsicDeviceScaleFactor(float scaleFactor)
{
if (m_intrinsicDeviceScaleFactor == scaleFactor)
return;
m_intrinsicDeviceScaleFactor = scaleFactor;
if (m_drawingArea)
m_drawingArea->deviceScaleFactorDidChange();
}
void WebPageProxy::windowScreenDidChange(PlatformDisplayID displayID)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::WindowScreenDidChange(displayID), m_pageID);
}
float WebPageProxy::deviceScaleFactor() const
{
if (m_customDeviceScaleFactor)
return m_customDeviceScaleFactor;
return m_intrinsicDeviceScaleFactor;
}
void WebPageProxy::setCustomDeviceScaleFactor(float customScaleFactor)
{
if (!isValid())
return;
if (m_customDeviceScaleFactor == customScaleFactor)
return;
float oldScaleFactor = deviceScaleFactor();
m_customDeviceScaleFactor = customScaleFactor;
if (deviceScaleFactor() != oldScaleFactor)
m_drawingArea->deviceScaleFactorDidChange();
}
void WebPageProxy::setUseFixedLayout(bool fixed)
{
if (!isValid())
return;
// This check is fine as the value is initialized in the web
// process as part of the creation parameters.
if (fixed == m_useFixedLayout)
return;
m_useFixedLayout = fixed;
if (!fixed)
m_fixedLayoutSize = IntSize();
m_process->send(Messages::WebPage::SetUseFixedLayout(fixed), m_pageID);
}
void WebPageProxy::setFixedLayoutSize(const IntSize& size)
{
if (!isValid())
return;
if (size == m_fixedLayoutSize)
return;
m_fixedLayoutSize = size;
m_process->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
}
void WebPageProxy::listenForLayoutMilestones(WebCore::LayoutMilestones milestones)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::ListenForLayoutMilestones(milestones), m_pageID);
}
void WebPageProxy::setVisibilityState(WebCore::PageVisibilityState visibilityState, bool isInitialState)
{
if (!isValid())
return;
#if ENABLE(PAGE_VISIBILITY_API)
if (visibilityState != m_visibilityState || isInitialState) {
m_visibilityState = visibilityState;
m_process->send(Messages::WebPage::SetVisibilityState(visibilityState, isInitialState), m_pageID);
}
#endif
}
void WebPageProxy::setSuppressScrollbarAnimations(bool suppressAnimations)
{
if (!isValid())
return;
if (suppressAnimations == m_suppressScrollbarAnimations)
return;
m_suppressScrollbarAnimations = suppressAnimations;
m_process->send(Messages::WebPage::SetSuppressScrollbarAnimations(suppressAnimations), m_pageID);
}
void WebPageProxy::setRubberBandsAtBottom(bool rubberBandsAtBottom)
{
if (rubberBandsAtBottom == m_rubberBandsAtBottom)
return;
m_rubberBandsAtBottom = rubberBandsAtBottom;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetRubberBandsAtBottom(rubberBandsAtBottom), m_pageID);
}
void WebPageProxy::setRubberBandsAtTop(bool rubberBandsAtTop)
{
if (rubberBandsAtTop == m_rubberBandsAtTop)
return;
m_rubberBandsAtTop = rubberBandsAtTop;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetRubberBandsAtTop(rubberBandsAtTop), m_pageID);
}
void WebPageProxy::setPaginationMode(WebCore::Pagination::Mode mode)
{
if (mode == m_paginationMode)
return;
m_paginationMode = mode;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetPaginationMode(mode), m_pageID);
}
void WebPageProxy::setPaginationBehavesLikeColumns(bool behavesLikeColumns)
{
if (behavesLikeColumns == m_paginationBehavesLikeColumns)
return;
m_paginationBehavesLikeColumns = behavesLikeColumns;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetPaginationBehavesLikeColumns(behavesLikeColumns), m_pageID);
}
void WebPageProxy::setPageLength(double pageLength)
{
if (pageLength == m_pageLength)
return;
m_pageLength = pageLength;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetPageLength(pageLength), m_pageID);
}
void WebPageProxy::setGapBetweenPages(double gap)
{
if (gap == m_gapBetweenPages)
return;
m_gapBetweenPages = gap;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetGapBetweenPages(gap), m_pageID);
}
void WebPageProxy::pageScaleFactorDidChange(double scaleFactor)
{
m_pageScaleFactor = scaleFactor;
}
void WebPageProxy::pageZoomFactorDidChange(double zoomFactor)
{
m_pageZoomFactor = zoomFactor;
}
void WebPageProxy::setMemoryCacheClientCallsEnabled(bool memoryCacheClientCallsEnabled)
{
if (!isValid())
return;
if (m_areMemoryCacheClientCallsEnabled == memoryCacheClientCallsEnabled)
return;
m_areMemoryCacheClientCallsEnabled = memoryCacheClientCallsEnabled;
m_process->send(Messages::WebPage::SetMemoryCacheMessagesEnabled(memoryCacheClientCallsEnabled), m_pageID);
}
void WebPageProxy::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
{
if (string.isEmpty()) {
didFindStringMatches(string, Vector<Vector<WebCore::IntRect> > (), 0);
return;
}
m_process->send(Messages::WebPage::FindStringMatches(string, options, maxMatchCount), m_pageID);
}
void WebPageProxy::findString(const String& string, FindOptions options, unsigned maxMatchCount)
{
m_process->send(Messages::WebPage::FindString(string, options, maxMatchCount), m_pageID);
}
void WebPageProxy::getImageForFindMatch(int32_t matchIndex)
{
m_process->send(Messages::WebPage::GetImageForFindMatch(matchIndex), m_pageID);
}
void WebPageProxy::selectFindMatch(int32_t matchIndex)
{
m_process->send(Messages::WebPage::SelectFindMatch(matchIndex), m_pageID);
}
void WebPageProxy::hideFindUI()
{
m_process->send(Messages::WebPage::HideFindUI(), m_pageID);
}
void WebPageProxy::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
}
void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<ScriptValueCallback> prpCallback)
{
RefPtr<ScriptValueCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_scriptValueCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
}
void WebPageProxy::getRenderTreeExternalRepresentation(PassRefPtr<StringCallback> prpCallback)
{
RefPtr<StringCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_stringCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_pageID);
}
void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, PassRefPtr<StringCallback> prpCallback)
{
RefPtr<StringCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_loadDependentStringCallbackIDs.add(callbackID);
m_stringCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_pageID);
}
void WebPageProxy::getContentsAsString(PassRefPtr<StringCallback> prpCallback)
{
RefPtr<StringCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_loadDependentStringCallbackIDs.add(callbackID);
m_stringCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
}
#if ENABLE(MHTML)
void WebPageProxy::getContentsAsMHTMLData(PassRefPtr<DataCallback> prpCallback, bool useBinaryEncoding)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetContentsAsMHTMLData(callbackID, useBinaryEncoding), m_pageID);
}
#endif
void WebPageProxy::getSelectionOrContentsAsString(PassRefPtr<StringCallback> prpCallback)
{
RefPtr<StringCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_stringCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_pageID);
}
void WebPageProxy::getSelectionAsWebArchiveData(PassRefPtr<DataCallback> prpCallback)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetSelectionAsWebArchiveData(callbackID), m_pageID);
}
void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
}
void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, WebURL* resourceURL, PassRefPtr<DataCallback> prpCallback)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
}
void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
}
void WebPageProxy::forceRepaint(PassRefPtr<VoidCallback> prpCallback)
{
RefPtr<VoidCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_voidCallbacks.set(callbackID, callback.get());
m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
m_process->send(Messages::WebPage::ForceRepaint(callbackID), m_pageID);
}
void WebPageProxy::preferencesDidChange()
{
if (!isValid())
return;
#if ENABLE(INSPECTOR_SERVER)
if (m_pageGroup->preferences()->developerExtrasEnabled())
inspector()->enableRemoteInspection();
#endif
m_process->pagePreferencesChanged(this);
m_pageClient->preferencesDidChange();
// FIXME: It probably makes more sense to send individual preference changes.
// However, WebKitTestRunner depends on getting a preference change notification
// even if nothing changed in UI process, so that overrides get removed.
// Preferences need to be updated during synchronous printing to make "print backgrounds" preference work when toggled from a print dialog checkbox.
m_process->send(Messages::WebPage::PreferencesDidChange(pageGroup()->preferences()->store()), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
void WebPageProxy::didCreateMainFrame(uint64_t frameID)
{
MESSAGE_CHECK(!m_mainFrame);
MESSAGE_CHECK(m_process->canCreateFrame(frameID));
m_mainFrame = WebFrameProxy::create(this, frameID);
// Add the frame to the process wide map.
m_process->frameCreated(frameID, m_mainFrame.get());
}
void WebPageProxy::didCreateSubframe(uint64_t frameID)
{
MESSAGE_CHECK(m_mainFrame);
MESSAGE_CHECK(m_process->canCreateFrame(frameID));
RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
// Add the frame to the process wide map.
m_process->frameCreated(frameID, subFrame.get());
}
// Always start progress at initialProgressValue. This helps provide feedback as
// soon as a load starts.
static const double initialProgressValue = 0.1;
double WebPageProxy::estimatedProgress() const
{
if (!pendingAPIRequestURL().isNull())
return initialProgressValue;
return m_estimatedProgress;
}
void WebPageProxy::didStartProgress()
{
m_estimatedProgress = initialProgressValue;
m_loaderClient.didStartProgress(this);
}
void WebPageProxy::didChangeProgress(double value)
{
m_estimatedProgress = value;
m_loaderClient.didChangeProgress(this);
}
void WebPageProxy::didFinishProgress()
{
m_estimatedProgress = 1.0;
m_loaderClient.didFinishProgress(this);
}
void WebPageProxy::didStartProvisionalLoadForFrame(uint64_t frameID, const String& url, const String& unreachableURL, CoreIPC::MessageDecoder& decoder)
{
clearPendingAPIRequestURL();
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(url);
frame->setUnreachableURL(unreachableURL);
frame->didStartProvisionalLoad(url);
m_loaderClient.didStartProvisionalLoadForFrame(this, frame, userData.get());
}
void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, const String& url, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(url);
frame->didReceiveServerRedirectForProvisionalLoad(url);
m_loaderClient.didReceiveServerRedirectForProvisionalLoadForFrame(this, frame, userData.get());
}
void WebPageProxy::didFailProvisionalLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
frame->didFailProvisionalLoad();
m_loaderClient.didFailProvisionalLoadWithErrorForFrame(this, frame, error, userData.get());
}
void WebPageProxy::clearLoadDependentCallbacks()
{
Vector<uint64_t> callbackIDsCopy;
copyToVector(m_loadDependentStringCallbackIDs, callbackIDsCopy);
m_loadDependentStringCallbackIDs.clear();
for (size_t i = 0; i < callbackIDsCopy.size(); ++i) {
RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackIDsCopy[i]);
if (callback)
callback->invalidate();
}
}
void WebPageProxy::didCommitLoadForFrame(uint64_t frameID, const String& mimeType, uint32_t opaqueFrameLoadType, const PlatformCertificateInfo& certificateInfo, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
#if PLATFORM(MAC)
// FIXME (bug 59111): didCommitLoadForFrame comes too late when restoring a page from b/f cache, making us disable secure event mode in password fields.
// FIXME: A load going on in one frame shouldn't affect text editing in other frames on the page.
m_pageClient->resetSecureInputState();
dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
m_pageClient->dismissDictionaryLookupPanel();
#endif
clearLoadDependentCallbacks();
frame->didCommitLoad(mimeType, certificateInfo);
// Even if WebPage has the default pageScaleFactor (and therefore doesn't reset it),
// WebPageProxy's cache of the value can get out of sync (e.g. in the case where a
// plugin is handling page scaling itself) so we should reset it to the default
// for standard main frame loads.
if (frame->isMainFrame() && static_cast<FrameLoadType>(opaqueFrameLoadType) == FrameLoadTypeStandard)
m_pageScaleFactor = 1;
m_loaderClient.didCommitLoadForFrame(this, frame, userData.get());
}
void WebPageProxy::didFinishDocumentLoadForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didFinishDocumentLoadForFrame(this, frame, userData.get());
}
void WebPageProxy::didFinishLoadForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
frame->didFinishLoad();
m_loaderClient.didFinishLoadForFrame(this, frame, userData.get());
}
void WebPageProxy::didFailLoadForFrame(uint64_t frameID, const ResourceError& error, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
clearLoadDependentCallbacks();
frame->didFailLoad();
m_loaderClient.didFailLoadWithErrorForFrame(this, frame, error, userData.get());
}
void WebPageProxy::didSameDocumentNavigationForFrame(uint64_t frameID, uint32_t opaqueSameDocumentNavigationType, const String& url, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(url);
clearPendingAPIRequestURL();
frame->didSameDocumentNavigation(url);
m_loaderClient.didSameDocumentNavigationForFrame(this, frame, static_cast<SameDocumentNavigationType>(opaqueSameDocumentNavigationType), userData.get());
}
void WebPageProxy::didReceiveTitleForFrame(uint64_t frameID, const String& title, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
frame->didChangeTitle(title);
m_loaderClient.didReceiveTitleForFrame(this, title, frame, userData.get());
}
void WebPageProxy::didFirstLayoutForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didFirstLayoutForFrame(this, frame, userData.get());
}
void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didFirstVisuallyNonEmptyLayoutForFrame(this, frame, userData.get());
}
void WebPageProxy::didNewFirstVisuallyNonEmptyLayout(CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
m_loaderClient.didNewFirstVisuallyNonEmptyLayout(this, userData.get());
}
void WebPageProxy::didLayout(uint32_t layoutMilestones, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
m_loaderClient.didLayout(this, static_cast<LayoutMilestones>(layoutMilestones), userData.get());
}
void WebPageProxy::didRemoveFrameFromHierarchy(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didRemoveFrameFromHierarchy(this, frame, userData.get());
}
void WebPageProxy::didDisplayInsecureContentForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didDisplayInsecureContentForFrame(this, frame, userData.get());
}
void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
}
void WebPageProxy::didDetectXSSForFrame(uint64_t frameID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_loaderClient.didDetectXSSForFrame(this, frame, userData.get());
}
void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
frame->setIsFrameSet(value);
if (frame->isMainFrame())
m_frameSetLargestFrame = value ? m_mainFrame : 0;
}
// PolicyClient
void WebPageProxy::decidePolicyForNavigationAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, uint64_t listenerID, CoreIPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
if (request.url() != pendingAPIRequestURL())
clearPendingAPIRequestURL();
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(request.url());
NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
ASSERT(!m_inDecidePolicyForNavigationAction);
m_inDecidePolicyForNavigationAction = true;
m_syncNavigationActionPolicyActionIsValid = false;
if (!m_policyClient.decidePolicyForNavigationAction(this, frame, navigationType, modifiers, mouseButton, request, listener.get(), userData.get()))
listener->use();
m_inDecidePolicyForNavigationAction = false;
// Check if we received a policy decision already. If we did, we can just pass it back.
receivedPolicyAction = m_syncNavigationActionPolicyActionIsValid;
if (m_syncNavigationActionPolicyActionIsValid) {
policyAction = m_syncNavigationActionPolicyAction;
downloadID = m_syncNavigationActionPolicyDownloadID;
}
}
void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, uint32_t opaqueNavigationType, uint32_t opaqueModifiers, int32_t opaqueMouseButton, const ResourceRequest& request, const String& frameName, uint64_t listenerID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(request.url());
NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
WebMouseEvent::Button mouseButton = static_cast<WebMouseEvent::Button>(opaqueMouseButton);
RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
if (!m_policyClient.decidePolicyForNewWindowAction(this, frame, navigationType, modifiers, mouseButton, request, frameName, listener.get(), userData.get()))
listener->use();
}
void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, uint64_t listenerID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
MESSAGE_CHECK_URL(request.url());
MESSAGE_CHECK_URL(response.url());
RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
if (!m_policyClient.decidePolicyForResponse(this, frame, response, request, listener.get(), userData.get()))
listener->use();
}
void WebPageProxy::decidePolicyForResponseSync(uint64_t frameID, const ResourceResponse& response, const ResourceRequest& request, uint64_t listenerID, CoreIPC::MessageDecoder& decoder, bool& receivedPolicyAction, uint64_t& policyAction, uint64_t& downloadID)
{
ASSERT(!m_inDecidePolicyForResponseSync);
m_inDecidePolicyForResponseSync = true;
m_decidePolicyForResponseRequest = &request;
m_syncMimeTypePolicyActionIsValid = false;
decidePolicyForResponse(frameID, response, request, listenerID, decoder);
m_inDecidePolicyForResponseSync = false;
m_decidePolicyForResponseRequest = 0;
// Check if we received a policy decision already. If we did, we can just pass it back.
receivedPolicyAction = m_syncMimeTypePolicyActionIsValid;
if (m_syncMimeTypePolicyActionIsValid) {
policyAction = m_syncMimeTypePolicyAction;
downloadID = m_syncMimeTypePolicyDownloadID;
}
}
void WebPageProxy::unableToImplementPolicy(uint64_t frameID, const ResourceError& error, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_policyClient.unableToImplementPolicy(this, frame, error, userData.get());
}
// FormClient
void WebPageProxy::willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String> >& textFieldValues, uint64_t listenerID, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
WebFrameProxy* sourceFrame = m_process->webFrame(sourceFrameID);
MESSAGE_CHECK(sourceFrame);
RefPtr<WebFormSubmissionListenerProxy> listener = frame->setUpFormSubmissionListenerProxy(listenerID);
if (!m_formClient.willSubmitForm(this, frame, sourceFrame, textFieldValues, userData.get(), listener.get()))
listener->continueSubmission();
}
// UIClient
void WebPageProxy::createNewPage(const ResourceRequest& request, const WindowFeatures& windowFeatures, uint32_t opaqueModifiers, int32_t opaqueMouseButton, uint64_t& newPageID, WebPageCreationParameters& newPageParameters)
{
RefPtr<WebPageProxy> newPage = m_uiClient.createNewPage(this, request, windowFeatures, static_cast<WebEvent::Modifiers>(opaqueModifiers), static_cast<WebMouseEvent::Button>(opaqueMouseButton));
if (!newPage) {
newPageID = 0;
return;
}
newPageID = newPage->pageID();
newPageParameters = newPage->creationParameters();
process()->context()->storageManager().cloneSessionStorageNamespace(m_pageID, newPage->pageID());
}
void WebPageProxy::showPage()
{
m_uiClient.showPage(this);
}
void WebPageProxy::closePage(bool stopResponsivenessTimer)
{
if (stopResponsivenessTimer)
m_process->responsivenessTimer()->stop();
m_pageClient->clearAllEditCommands();
m_uiClient.close(this);
}
void WebPageProxy::runJavaScriptAlert(uint64_t frameID, const String& message)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
// Since runJavaScriptAlert() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
m_uiClient.runJavaScriptAlert(this, message, frame);
}
void WebPageProxy::runJavaScriptConfirm(uint64_t frameID, const String& message, bool& result)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
// Since runJavaScriptConfirm() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
result = m_uiClient.runJavaScriptConfirm(this, message, frame);
}
void WebPageProxy::runJavaScriptPrompt(uint64_t frameID, const String& message, const String& defaultValue, String& result)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
// Since runJavaScriptPrompt() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
result = m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame);
}
void WebPageProxy::shouldInterruptJavaScript(bool& result)
{
// Since shouldInterruptJavaScript() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
result = m_uiClient.shouldInterruptJavaScript(this);
}
void WebPageProxy::setStatusText(const String& text)
{
m_uiClient.setStatusText(this, text);
}
void WebPageProxy::mouseDidMoveOverElement(const WebHitTestResult::Data& hitTestResultData, uint32_t opaqueModifiers, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
m_uiClient.mouseDidMoveOverElement(this, hitTestResultData, modifiers, userData.get());
}
void WebPageProxy::connectionWillOpen(CoreIPC::Connection* connection)
{
ASSERT(connection == m_process->connection());
m_process->context()->storageManager().setAllowedSessionStorageNamespaceConnection(m_pageID, connection);
}
void WebPageProxy::connectionWillClose(CoreIPC::Connection* connection)
{
ASSERT_UNUSED(connection, connection == m_process->connection());
m_process->context()->storageManager().setAllowedSessionStorageNamespaceConnection(m_pageID, 0);
}
void WebPageProxy::unavailablePluginButtonClicked(uint32_t opaquePluginUnavailabilityReason, const String& mimeType, const String& pluginURLString, const String& pluginspageAttributeURLString, const String& frameURLString, const String& pageURLString)
{
MESSAGE_CHECK_URL(pluginURLString);
MESSAGE_CHECK_URL(pluginspageAttributeURLString);
MESSAGE_CHECK_URL(frameURLString);
MESSAGE_CHECK_URL(pageURLString);
RefPtr<ImmutableDictionary> pluginInformation;
#if ENABLE(NETSCAPE_PLUGIN_API)
String newMimeType = mimeType;
PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), pluginURLString));
pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, pluginspageAttributeURLString, pluginURLString);
#endif
WKPluginUnavailabilityReason pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing;
switch (static_cast<RenderEmbeddedObject::PluginUnavailabilityReason>(opaquePluginUnavailabilityReason)) {
case RenderEmbeddedObject::PluginMissing:
pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginMissing;
break;
case RenderEmbeddedObject::InsecurePluginVersion:
pluginUnavailabilityReason = kWKPluginUnavailabilityReasonInsecurePluginVersion;
break;
case RenderEmbeddedObject::PluginCrashed:
pluginUnavailabilityReason = kWKPluginUnavailabilityReasonPluginCrashed;
break;
case RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy:
ASSERT_NOT_REACHED();
}
m_uiClient.unavailablePluginButtonClicked(this, pluginUnavailabilityReason, pluginInformation.get());
}
void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
{
m_uiClient.setToolbarsAreVisible(this, toolbarsAreVisible);
}
void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
{
toolbarsAreVisible = m_uiClient.toolbarsAreVisible(this);
}
void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
{
m_uiClient.setMenuBarIsVisible(this, menuBarIsVisible);
}
void WebPageProxy::getMenuBarIsVisible(bool& menuBarIsVisible)
{
menuBarIsVisible = m_uiClient.menuBarIsVisible(this);
}
void WebPageProxy::setStatusBarIsVisible(bool statusBarIsVisible)
{
m_uiClient.setStatusBarIsVisible(this, statusBarIsVisible);
}
void WebPageProxy::getStatusBarIsVisible(bool& statusBarIsVisible)
{
statusBarIsVisible = m_uiClient.statusBarIsVisible(this);
}
void WebPageProxy::setIsResizable(bool isResizable)
{
m_uiClient.setIsResizable(this, isResizable);
}
void WebPageProxy::getIsResizable(bool& isResizable)
{
isResizable = m_uiClient.isResizable(this);
}
void WebPageProxy::setWindowFrame(const FloatRect& newWindowFrame)
{
m_uiClient.setWindowFrame(this, m_pageClient->convertToDeviceSpace(newWindowFrame));
}
void WebPageProxy::getWindowFrame(FloatRect& newWindowFrame)
{
newWindowFrame = m_pageClient->convertToUserSpace(m_uiClient.windowFrame(this));
}
void WebPageProxy::screenToWindow(const IntPoint& screenPoint, IntPoint& windowPoint)
{
windowPoint = m_pageClient->screenToWindow(screenPoint);
}
void WebPageProxy::windowToScreen(const IntRect& viewRect, IntRect& result)
{
result = m_pageClient->windowToScreen(viewRect);
}
void WebPageProxy::runBeforeUnloadConfirmPanel(const String& message, uint64_t frameID, bool& shouldClose)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
// Since runBeforeUnloadConfirmPanel() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
shouldClose = m_uiClient.runBeforeUnloadConfirmPanel(this, message, frame);
}
#if USE(TILED_BACKING_STORE)
void WebPageProxy::pageDidRequestScroll(const IntPoint& point)
{
m_pageClient->pageDidRequestScroll(point);
}
void WebPageProxy::pageTransitionViewportReady()
{
m_pageClient->pageTransitionViewportReady();
}
void WebPageProxy::didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect)
{
m_pageClient->didRenderFrame(contentsSize, coveredRect);
}
#endif
void WebPageProxy::didChangeViewportProperties(const ViewportAttributes& attr)
{
m_pageClient->didChangeViewportProperties(attr);
}
void WebPageProxy::pageDidScroll()
{
m_uiClient.pageDidScroll(this);
#if PLATFORM(MAC)
dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
#endif
}
void WebPageProxy::runOpenPanel(uint64_t frameID, const FileChooserSettings& settings)
{
if (m_openPanelResultListener) {
m_openPanelResultListener->invalidate();
m_openPanelResultListener = 0;
}
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
RefPtr<WebOpenPanelParameters> parameters = WebOpenPanelParameters::create(settings);
m_openPanelResultListener = WebOpenPanelResultListenerProxy::create(this);
// Since runOpenPanel() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
if (!m_uiClient.runOpenPanel(this, frame, parameters.get(), m_openPanelResultListener.get()))
didCancelForOpenPanel();
}
void WebPageProxy::printFrame(uint64_t frameID)
{
ASSERT(!m_isPerformingDOMPrintOperation);
m_isPerformingDOMPrintOperation = true;
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_uiClient.printFrame(this, frame);
endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
m_isPerformingDOMPrintOperation = false;
}
void WebPageProxy::printMainFrame()
{
printFrame(m_mainFrame->frameID());
}
void WebPageProxy::setMediaVolume(float volume)
{
if (volume == m_mediaVolume)
return;
m_mediaVolume = volume;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetMediaVolume(volume), m_pageID);
}
void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
{
if (mayStartMedia == m_mayStartMediaWhenInWindow)
return;
m_mayStartMediaWhenInWindow = mayStartMedia;
if (!isValid())
return;
process()->send(Messages::WebPage::SetMayStartMediaWhenInWindow(mayStartMedia), m_pageID);
}
#if PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
void WebPageProxy::handleDownloadRequest(DownloadProxy* download)
{
m_pageClient->handleDownloadRequest(download);
}
#endif // PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
#if PLATFORM(QT) || PLATFORM(EFL)
void WebPageProxy::didChangeContentsSize(const IntSize& size)
{
m_pageClient->didChangeContentsSize(size);
}
#endif
#if ENABLE(TOUCH_EVENTS)
void WebPageProxy::needTouchEvents(bool needTouchEvents)
{
m_needTouchEvents = needTouchEvents;
}
#endif
#if ENABLE(INPUT_TYPE_COLOR)
void WebPageProxy::showColorChooser(const WebCore::Color& initialColor, const IntRect& elementRect)
{
ASSERT(!m_colorPicker);
if (m_colorPickerResultListener) {
m_colorPickerResultListener->invalidate();
m_colorPickerResultListener = nullptr;
}
m_colorPickerResultListener = WebColorPickerResultListenerProxy::create(this);
m_colorPicker = WebColorPicker::create(this);
if (m_uiClient.showColorPicker(this, initialColor.serialized(), m_colorPickerResultListener.get()))
return;
m_colorPicker = m_pageClient->createColorPicker(this, initialColor, elementRect);
if (!m_colorPicker)
didEndColorChooser();
}
void WebPageProxy::setColorChooserColor(const WebCore::Color& color)
{
ASSERT(m_colorPicker);
m_colorPicker->setSelectedColor(color);
}
void WebPageProxy::endColorChooser()
{
ASSERT(m_colorPicker);
m_colorPicker->endChooser();
}
void WebPageProxy::didChooseColor(const WebCore::Color& color)
{
if (!isValid())
return;
m_process->send(Messages::WebPage::DidChooseColor(color), m_pageID);
}
void WebPageProxy::didEndColorChooser()
{
if (!isValid())
return;
if (m_colorPicker) {
m_colorPicker->invalidate();
m_colorPicker = nullptr;
}
m_process->send(Messages::WebPage::DidEndColorChooser(), m_pageID);
m_colorPickerResultListener->invalidate();
m_colorPickerResultListener = nullptr;
m_uiClient.hideColorPicker(this);
}
#endif
void WebPageProxy::didDraw()
{
m_uiClient.didDraw(this);
}
// Inspector
#if ENABLE(INSPECTOR)
WebInspectorProxy* WebPageProxy::inspector()
{
if (isClosed() || !isValid())
return 0;
return m_inspector.get();
}
#endif
#if ENABLE(FULLSCREEN_API)
WebFullScreenManagerProxy* WebPageProxy::fullScreenManager()
{
return m_fullScreenManager.get();
}
#endif
// BackForwardList
void WebPageProxy::backForwardAddItem(uint64_t itemID)
{
m_backForwardList->addItem(m_process->webBackForwardItem(itemID));
}
void WebPageProxy::backForwardGoToItem(uint64_t itemID, SandboxExtension::Handle& sandboxExtensionHandle)
{
WebBackForwardListItem* item = m_process->webBackForwardItem(itemID);
if (!item)
return;
bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
if (createdExtension)
m_process->willAcquireUniversalFileReadSandboxExtension();
m_backForwardList->goToItem(item);
}
void WebPageProxy::backForwardItemAtIndex(int32_t index, uint64_t& itemID)
{
WebBackForwardListItem* item = m_backForwardList->itemAtIndex(index);
itemID = item ? item->itemID() : 0;
}
void WebPageProxy::backForwardBackListCount(int32_t& count)
{
count = m_backForwardList->backListCount();
}
void WebPageProxy::backForwardForwardListCount(int32_t& count)
{
count = m_backForwardList->forwardListCount();
}
void WebPageProxy::editorStateChanged(const EditorState& editorState)
{
#if PLATFORM(MAC)
bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition);
m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition;
#endif
m_editorState = editorState;
#if PLATFORM(MAC)
// Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
if (couldChangeSecureInputState && !editorState.selectionIsNone)
m_pageClient->updateSecureInputState();
if (editorState.shouldIgnoreCompositionSelectionChange)
return;
if (closedComposition)
m_pageClient->notifyInputContextAboutDiscardedComposition();
if (editorState.hasComposition) {
// Abandon the current inline input session if selection changed for any other reason but an input method changing the composition.
// FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition.
cancelComposition();
m_pageClient->notifyInputContextAboutDiscardedComposition();
}
#elif PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(GTK)
m_pageClient->updateTextInputState();
#endif
}
// Undo management
void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
{
registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), Undo);
}
void WebPageProxy::canUndoRedo(uint32_t action, bool& result)
{
result = m_pageClient->canUndoRedo(static_cast<UndoOrRedo>(action));
}
void WebPageProxy::executeUndoRedo(uint32_t action, bool& result)
{
m_pageClient->executeUndoRedo(static_cast<UndoOrRedo>(action));
result = true;
}
void WebPageProxy::clearAllEditCommands()
{
m_pageClient->clearAllEditCommands();
}
void WebPageProxy::didCountStringMatches(const String& string, uint32_t matchCount)
{
m_findClient.didCountStringMatches(this, string, matchCount);
}
void WebPageProxy::didGetImageForFindMatch(const ShareableBitmap::Handle& contentImageHandle, uint32_t matchIndex)
{
m_findMatchesClient.didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex);
}
void WebPageProxy::setFindIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate)
{
RefPtr<FindIndicator> findIndicator = FindIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImageHandle);
m_pageClient->setFindIndicator(findIndicator.release(), fadeOut, animate);
}
void WebPageProxy::didFindString(const String& string, uint32_t matchCount)
{
m_findClient.didFindString(this, string, matchCount);
}
void WebPageProxy::didFindStringMatches(const String& string, Vector<Vector<WebCore::IntRect> > matchRects, int32_t firstIndexAfterSelection)
{
Vector<RefPtr<APIObject> > matches;
matches.reserveInitialCapacity(matchRects.size());
for (size_t i = 0; i < matchRects.size(); ++i) {
const Vector<WebCore::IntRect>& rects = matchRects[i];
size_t numRects = matchRects[i].size();
Vector<RefPtr<APIObject> > apiRects;
apiRects.reserveInitialCapacity(numRects);
for (size_t i = 0; i < numRects; ++i)
apiRects.uncheckedAppend(WebRect::create(toAPI(rects[i])));
matches.uncheckedAppend(ImmutableArray::adopt(apiRects));
}
m_findMatchesClient.didFindStringMatches(this, string, ImmutableArray::adopt(matches).get(), firstIndexAfterSelection);
}
void WebPageProxy::didFailToFindString(const String& string)
{
m_findClient.didFailToFindString(this, string);
}
void WebPageProxy::valueChangedForPopupMenu(WebPopupMenuProxy*, int32_t newSelectedIndex)
{
m_process->send(Messages::WebPage::DidChangeSelectedIndexForActivePopupMenu(newSelectedIndex), m_pageID);
}
void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index)
{
m_process->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
}
NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent()
{
return m_currentlyProcessedMouseDownEvent.get();
}
void WebPageProxy::postMessageToInjectedBundle(const String& messageName, APIObject* messageBody)
{
process()->send(Messages::WebPage::PostInjectedBundleMessage(messageName, WebContextUserMessageEncoder(messageBody)), m_pageID);
}
#if PLATFORM(GTK)
void WebPageProxy::failedToShowPopupMenu()
{
m_process->send(Messages::WebPage::FailedToShowPopupMenu(), m_pageID);
}
#endif
void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
{
if (m_activePopupMenu) {
#if PLATFORM(EFL)
m_uiPopupMenuClient.hidePopupMenu(this);
#else
m_activePopupMenu->hidePopupMenu();
#endif
m_activePopupMenu->invalidate();
m_activePopupMenu = 0;
}
m_activePopupMenu = m_pageClient->createPopupMenuProxy(this);
if (!m_activePopupMenu)
return;
// Since showPopupMenu() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
#if PLATFORM(EFL)
UNUSED_PARAM(data);
m_uiPopupMenuClient.showPopupMenu(this, m_activePopupMenu.get(), rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, selectedIndex);
#else
RefPtr<WebPopupMenuProxy> protectedActivePopupMenu = m_activePopupMenu;
protectedActivePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), m_pageScaleFactor, items, data, selectedIndex);
// Since Qt and Efl doesn't use a nested mainloop to show the popup and get the answer, we need to keep the client pointer valid.
#if !PLATFORM(QT)
protectedActivePopupMenu->invalidate();
#endif
protectedActivePopupMenu = 0;
#endif
}
void WebPageProxy::hidePopupMenu()
{
if (!m_activePopupMenu)
return;
#if PLATFORM(EFL)
m_uiPopupMenuClient.hidePopupMenu(this);
#else
m_activePopupMenu->hidePopupMenu();
#endif
m_activePopupMenu->invalidate();
m_activePopupMenu = 0;
}
#if ENABLE(CONTEXT_MENUS)
void WebPageProxy::showContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::MessageDecoder& decoder)
{
internalShowContextMenu(menuLocation, hitTestResultData, proposedItems, decoder);
// No matter the result of internalShowContextMenu, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
m_process->send(Messages::WebPage::ContextMenuHidden(), m_pageID);
}
void WebPageProxy::internalShowContextMenu(const IntPoint& menuLocation, const WebHitTestResult::Data& hitTestResultData, const Vector<WebContextMenuItemData>& proposedItems, CoreIPC::MessageDecoder& decoder)
{
RefPtr<APIObject> userData;
WebContextUserMessageDecoder messageDecoder(userData, m_process.get());
if (!decoder.decode(messageDecoder))
return;
m_activeContextMenuHitTestResultData = hitTestResultData;
if (!m_contextMenuClient.hideContextMenu(this) && m_activeContextMenu) {
m_activeContextMenu->hideContextMenu();
m_activeContextMenu = 0;
}
m_activeContextMenu = m_pageClient->createContextMenuProxy(this);
if (!m_activeContextMenu)
return;
// Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
// Give the PageContextMenuClient one last swipe at changing the menu.
Vector<WebContextMenuItemData> items;
if (!m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, hitTestResultData, userData.get())) {
if (!m_contextMenuClient.showContextMenu(this, menuLocation, proposedItems))
m_activeContextMenu->showContextMenu(menuLocation, proposedItems);
} else if (!m_contextMenuClient.showContextMenu(this, menuLocation, items))
m_activeContextMenu->showContextMenu(menuLocation, items);
m_contextMenuClient.contextMenuDismissed(this);
}
void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
{
// Application custom items don't need to round-trip through to WebCore in the WebProcess.
if (item.action() >= ContextMenuItemBaseApplicationTag) {
m_contextMenuClient.customContextMenuItemSelected(this, item);
return;
}
#if PLATFORM(MAC)
if (item.action() == ContextMenuItemTagSmartCopyPaste) {
setSmartInsertDeleteEnabled(!isSmartInsertDeleteEnabled());
return;
}
if (item.action() == ContextMenuItemTagSmartQuotes) {
TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagSmartDashes) {
TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagSmartLinks) {
TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagTextReplacement) {
TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagCorrectSpellingAutomatically) {
TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagShowSubstitutions) {
TextChecker::toggleSubstitutionsPanelIsShowing();
return;
}
#endif
if (item.action() == ContextMenuItemTagDownloadImageToDisk) {
m_process->context()->download(this, KURL(KURL(), m_activeContextMenuHitTestResultData.absoluteImageURL));
return;
}
if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
m_process->context()->download(this, KURL(KURL(), m_activeContextMenuHitTestResultData.absoluteLinkURL));
return;
}
if (item.action() == ContextMenuItemTagDownloadMediaToDisk) {
m_process->context()->download(this, KURL(KURL(), m_activeContextMenuHitTestResultData.absoluteMediaURL));
return;
}
if (item.action() == ContextMenuItemTagCheckSpellingWhileTyping) {
TextChecker::setContinuousSpellCheckingEnabled(!TextChecker::state().isContinuousSpellCheckingEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagCheckGrammarWithSpelling) {
TextChecker::setGrammarCheckingEnabled(!TextChecker::state().isGrammarCheckingEnabled);
m_process->updateTextCheckerState();
return;
}
if (item.action() == ContextMenuItemTagShowSpellingPanel) {
if (!TextChecker::spellingUIIsShowing())
advanceToNextMisspelling(true);
TextChecker::toggleSpellingUIIsShowing();
return;
}
if (item.action() == ContextMenuItemTagLearnSpelling || item.action() == ContextMenuItemTagIgnoreSpelling)
++m_pendingLearnOrIgnoreWordMessageCount;
m_process->send(Messages::WebPage::DidSelectItemFromActiveContextMenu(item), m_pageID);
}
#endif // ENABLE(CONTEXT_MENUS)
void WebPageProxy::didChooseFilesForOpenPanel(const Vector<String>& fileURLs)
{
if (!isValid())
return;
#if ENABLE(WEB_PROCESS_SANDBOX)
// FIXME: The sandbox extensions should be sent with the DidChooseFilesForOpenPanel message. This
// is gated on a way of passing SandboxExtension::Handles in a Vector.
for (size_t i = 0; i < fileURLs.size(); ++i) {
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::createHandle(fileURLs[i], SandboxExtension::ReadOnly, sandboxExtensionHandle);
m_process->send(Messages::WebPage::ExtendSandboxForFileFromOpenPanel(sandboxExtensionHandle), m_pageID);
}
#endif
m_process->send(Messages::WebPage::DidChooseFilesForOpenPanel(fileURLs), m_pageID);
m_openPanelResultListener->invalidate();
m_openPanelResultListener = 0;
}
void WebPageProxy::didCancelForOpenPanel()
{
if (!isValid())
return;
m_process->send(Messages::WebPage::DidCancelForOpenPanel(), m_pageID);
m_openPanelResultListener->invalidate();
m_openPanelResultListener = 0;
}
void WebPageProxy::advanceToNextMisspelling(bool startBeforeSelection) const
{
m_process->send(Messages::WebPage::AdvanceToNextMisspelling(startBeforeSelection), m_pageID);
}
void WebPageProxy::changeSpellingToWord(const String& word) const
{
if (word.isEmpty())
return;
m_process->send(Messages::WebPage::ChangeSpellingToWord(word), m_pageID);
}
void WebPageProxy::registerEditCommand(PassRefPtr<WebEditCommandProxy> commandProxy, UndoOrRedo undoOrRedo)
{
m_pageClient->registerEditCommand(commandProxy, undoOrRedo);
}
void WebPageProxy::addEditCommand(WebEditCommandProxy* command)
{
m_editCommandSet.add(command);
}
void WebPageProxy::removeEditCommand(WebEditCommandProxy* command)
{
m_editCommandSet.remove(command);
if (!isValid())
return;
m_process->send(Messages::WebPage::DidRemoveEditCommand(command->commandID()), m_pageID);
}
bool WebPageProxy::isValidEditCommand(WebEditCommandProxy* command)
{
return m_editCommandSet.find(command) != m_editCommandSet.end();
}
int64_t WebPageProxy::spellDocumentTag()
{
if (!m_hasSpellDocumentTag) {
m_spellDocumentTag = TextChecker::uniqueSpellDocumentTag(this);
m_hasSpellDocumentTag = true;
}
return m_spellDocumentTag;
}
#if USE(UNIFIED_TEXT_CHECKING)
void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results)
{
results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.characters(), text.length(), checkingTypes);
}
#endif
void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength)
{
TextChecker::checkSpellingOfString(spellDocumentTag(), text.characters(), text.length(), misspellingLocation, misspellingLength);
}
void WebPageProxy::checkGrammarOfString(const String& text, Vector<GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
{
TextChecker::checkGrammarOfString(spellDocumentTag(), text.characters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
}
void WebPageProxy::spellingUIIsShowing(bool& isShowing)
{
isShowing = TextChecker::spellingUIIsShowing();
}
void WebPageProxy::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
{
TextChecker::updateSpellingUIWithMisspelledWord(spellDocumentTag(), misspelledWord);
}
void WebPageProxy::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
{
TextChecker::updateSpellingUIWithGrammarString(spellDocumentTag(), badGrammarPhrase, grammarDetail);
}
void WebPageProxy::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
{
TextChecker::getGuessesForWord(spellDocumentTag(), word, context, guesses);
}
void WebPageProxy::learnWord(const String& word)
{
MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
--m_pendingLearnOrIgnoreWordMessageCount;
TextChecker::learnWord(spellDocumentTag(), word);
}
void WebPageProxy::ignoreWord(const String& word)
{
MESSAGE_CHECK(m_pendingLearnOrIgnoreWordMessageCount);
--m_pendingLearnOrIgnoreWordMessageCount;
TextChecker::ignoreWord(spellDocumentTag(), word);
}
void WebPageProxy::requestCheckingOfString(uint64_t requestID, const TextCheckingRequestData& request)
{
TextChecker::requestCheckingOfString(TextCheckerCompletion::create(requestID, request, this));
}
void WebPageProxy::didFinishCheckingText(uint64_t requestID, const Vector<WebCore::TextCheckingResult>& result) const
{
m_process->send(Messages::WebPage::DidFinishCheckingText(requestID, result), m_pageID);
}
void WebPageProxy::didCancelCheckingText(uint64_t requestID) const
{
m_process->send(Messages::WebPage::DidCancelCheckingText(requestID), m_pageID);
}
// Other
void WebPageProxy::setFocus(bool focused)
{
if (focused)
m_uiClient.focus(this);
else
m_uiClient.unfocus(this);
}
void WebPageProxy::takeFocus(uint32_t direction)
{
m_uiClient.takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward);
}
void WebPageProxy::setToolTip(const String& toolTip)
{
String oldToolTip = m_toolTip;
m_toolTip = toolTip;
m_pageClient->toolTipChanged(oldToolTip, m_toolTip);
}
void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
{
// The Web process may have asked to change the cursor when the view was in an active window, but
// if it is no longer in a window or the window is not active, then the cursor should not change.
if (m_pageClient->isViewWindowActive())
m_pageClient->setCursor(cursor);
}
void WebPageProxy::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
{
m_pageClient->setCursorHiddenUntilMouseMoves(hiddenUntilMouseMoves);
}
void WebPageProxy::didReceiveEvent(uint32_t opaqueType, bool handled)
{
WebEvent::Type type = static_cast<WebEvent::Type>(opaqueType);
switch (type) {
case WebEvent::NoType:
case WebEvent::MouseMove:
break;
case WebEvent::MouseDown:
case WebEvent::MouseUp:
case WebEvent::Wheel:
case WebEvent::KeyDown:
case WebEvent::KeyUp:
case WebEvent::RawKeyDown:
case WebEvent::Char:
#if ENABLE(GESTURE_EVENTS)
case WebEvent::GestureScrollBegin:
case WebEvent::GestureScrollEnd:
case WebEvent::GestureSingleTap:
#endif
#if ENABLE(TOUCH_EVENTS)
case WebEvent::TouchStart:
case WebEvent::TouchMove:
case WebEvent::TouchEnd:
case WebEvent::TouchCancel:
#endif
m_process->responsivenessTimer()->stop();
break;
}
switch (type) {
case WebEvent::NoType:
break;
case WebEvent::MouseMove:
m_processingMouseMoveEvent = false;
if (m_nextMouseMoveEvent) {
handleMouseEvent(*m_nextMouseMoveEvent);
m_nextMouseMoveEvent = nullptr;
}
break;
case WebEvent::MouseDown:
break;
#if ENABLE(GESTURE_EVENTS)
case WebEvent::GestureScrollBegin:
case WebEvent::GestureScrollEnd:
case WebEvent::GestureSingleTap: {
WebGestureEvent event = m_gestureEventQueue.first();
MESSAGE_CHECK(type == event.type());
m_gestureEventQueue.removeFirst();
m_pageClient->doneWithGestureEvent(event, handled);
break;
}
#endif
case WebEvent::MouseUp:
m_currentlyProcessedMouseDownEvent = nullptr;
break;
case WebEvent::Wheel: {
ASSERT(!m_currentlyProcessedWheelEvents.isEmpty());
OwnPtr<Vector<NativeWebWheelEvent> > oldestCoalescedEvent = m_currentlyProcessedWheelEvents.takeFirst();
// FIXME: Dispatch additional events to the didNotHandleWheelEvent client function.
if (!handled && m_uiClient.implementsDidNotHandleWheelEvent())
m_uiClient.didNotHandleWheelEvent(this, oldestCoalescedEvent->last());
if (!m_wheelEventQueue.isEmpty())
processNextQueuedWheelEvent();
break;
}
case WebEvent::KeyDown:
case WebEvent::KeyUp:
case WebEvent::RawKeyDown:
case WebEvent::Char: {
LOG(KeyHandling, "WebPageProxy::didReceiveEvent: %s", webKeyboardEventTypeString(type));
NativeWebKeyboardEvent event = m_keyEventQueue.first();
MESSAGE_CHECK(type == event.type());
m_keyEventQueue.removeFirst();
if (!m_keyEventQueue.isEmpty())
m_process->send(Messages::WebPage::KeyEvent(m_keyEventQueue.first()), m_pageID);
m_pageClient->doneWithKeyEvent(event, handled);
if (handled)
break;
if (m_uiClient.implementsDidNotHandleKeyEvent())
m_uiClient.didNotHandleKeyEvent(this, event);
break;
}
#if ENABLE(TOUCH_EVENTS)
case WebEvent::TouchStart:
case WebEvent::TouchMove:
case WebEvent::TouchEnd:
case WebEvent::TouchCancel: {
QueuedTouchEvents queuedEvents = m_touchEventQueue.first();
MESSAGE_CHECK(type == queuedEvents.forwardedEvent.type());
m_touchEventQueue.removeFirst();
m_pageClient->doneWithTouchEvent(queuedEvents.forwardedEvent, handled);
for (size_t i = 0; i < queuedEvents.deferredTouchEvents.size(); ++i) {
bool isEventHandled = false;
m_pageClient->doneWithTouchEvent(queuedEvents.deferredTouchEvents.at(i), isEventHandled);
}
break;
}
#endif
}
}
void WebPageProxy::stopResponsivenessTimer()
{
m_process->responsivenessTimer()->stop();
}
void WebPageProxy::voidCallback(uint64_t callbackID)
{
RefPtr<VoidCallback> callback = m_voidCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
callback->performCallback();
}
void WebPageProxy::dataCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
{
RefPtr<DataCallback> callback = m_dataCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
callback->performCallbackWithReturnValue(WebData::create(dataReference.data(), dataReference.size()).get());
}
void WebPageProxy::imageCallback(const ShareableBitmap::Handle& bitmapHandle, uint64_t callbackID)
{
RefPtr<ImageCallback> callback = m_imageCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
callback->performCallbackWithReturnValue(bitmapHandle);
}
void WebPageProxy::stringCallback(const String& resultString, uint64_t callbackID)
{
RefPtr<StringCallback> callback = m_stringCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
// this can validly happen if a load invalidated the callback, though
return;
}
m_loadDependentStringCallbackIDs.remove(callbackID);
callback->performCallbackWithReturnValue(resultString.impl());
}
void WebPageProxy::scriptValueCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
{
RefPtr<ScriptValueCallback> callback = m_scriptValueCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
Vector<uint8_t> data;
data.reserveInitialCapacity(dataReference.size());
data.append(dataReference.data(), dataReference.size());
callback->performCallbackWithReturnValue(data.size() ? WebSerializedScriptValue::adopt(data).get() : 0);
}
void WebPageProxy::computedPagesCallback(const Vector<IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
{
RefPtr<ComputedPagesCallback> callback = m_computedPagesCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
callback->performCallbackWithReturnValue(pageRects, totalScaleFactorForPrinting);
}
void WebPageProxy::validateCommandCallback(const String& commandName, bool isEnabled, int state, uint64_t callbackID)
{
RefPtr<ValidateCommandCallback> callback = m_validateCommandCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
callback->performCallbackWithReturnValue(commandName.impl(), isEnabled, state);
}
#if PLATFORM(GTK)
void WebPageProxy::printFinishedCallback(const ResourceError& printError, uint64_t callbackID)
{
RefPtr<PrintFinishedCallback> callback = m_printFinishedCallbacks.take(callbackID);
if (!callback) {
// FIXME: Log error or assert.
return;
}
RefPtr<WebError> error = WebError::create(printError);
callback->performCallbackWithReturnValue(error.get());
}
#endif
void WebPageProxy::focusedFrameChanged(uint64_t frameID)
{
if (!frameID) {
m_focusedFrame = 0;
return;
}
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_focusedFrame = frame;
}
void WebPageProxy::frameSetLargestFrameChanged(uint64_t frameID)
{
if (!frameID) {
m_frameSetLargestFrame = 0;
return;
}
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
m_frameSetLargestFrame = frame;
}
void WebPageProxy::processDidBecomeUnresponsive()
{
if (!isValid())
return;
updateBackingStoreDiscardableState();
m_loaderClient.processDidBecomeUnresponsive(this);
}
void WebPageProxy::interactionOccurredWhileProcessUnresponsive()
{
if (!isValid())
return;
m_loaderClient.interactionOccurredWhileProcessUnresponsive(this);
}
void WebPageProxy::processDidBecomeResponsive()
{
if (!isValid())
return;
updateBackingStoreDiscardableState();
m_loaderClient.processDidBecomeResponsive(this);
}
void WebPageProxy::processDidCrash()
{
ASSERT(m_isValid);
resetStateAfterProcessExited();
m_pageClient->processDidCrash();
m_loaderClient.processDidCrash(this);
}
void WebPageProxy::resetStateAfterProcessExited()
{
if (!isValid())
return;
ASSERT(m_pageClient);
m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
m_isValid = false;
m_isPageSuspended = false;
m_waitingForDidUpdateInWindowState = false;
if (m_mainFrame) {
m_urlAtProcessExit = m_mainFrame->url();
m_loadStateAtProcessExit = m_mainFrame->loadState();
}
m_mainFrame = nullptr;
m_drawingArea = nullptr;
#if ENABLE(INSPECTOR)
m_inspector->invalidate();
m_inspector = nullptr;
#endif
#if ENABLE(FULLSCREEN_API)
m_fullScreenManager->invalidate();
m_fullScreenManager = nullptr;
#endif
#if ENABLE(VIBRATION)
m_vibration->invalidate();
#endif
if (m_openPanelResultListener) {
m_openPanelResultListener->invalidate();
m_openPanelResultListener = nullptr;
}
#if ENABLE(INPUT_TYPE_COLOR)
if (m_colorPicker) {
m_colorPicker->invalidate();
m_colorPicker = nullptr;
}
if (m_colorPickerResultListener) {
m_colorPickerResultListener->invalidate();
m_colorPickerResultListener = nullptr;
}
#endif
#if ENABLE(GEOLOCATION)
m_geolocationPermissionRequestManager.invalidateRequests();
#endif
m_notificationPermissionRequestManager.invalidateRequests();
m_toolTip = String();
m_mainFrameHasHorizontalScrollbar = false;
m_mainFrameHasVerticalScrollbar = false;
m_mainFrameIsPinnedToLeftSide = false;
m_mainFrameIsPinnedToRightSide = false;
m_mainFrameIsPinnedToTopSide = false;
m_mainFrameIsPinnedToBottomSide = false;
m_visibleScrollerThumbRect = IntRect();
invalidateCallbackMap(m_voidCallbacks);
invalidateCallbackMap(m_dataCallbacks);
invalidateCallbackMap(m_stringCallbacks);
m_loadDependentStringCallbackIDs.clear();
invalidateCallbackMap(m_scriptValueCallbacks);
invalidateCallbackMap(m_computedPagesCallbacks);
invalidateCallbackMap(m_validateCommandCallbacks);
#if PLATFORM(GTK)
invalidateCallbackMap(m_printFinishedCallbacks);
#endif
Vector<WebEditCommandProxy*> editCommandVector;
copyToVector(m_editCommandSet, editCommandVector);
m_editCommandSet.clear();
for (size_t i = 0, size = editCommandVector.size(); i < size; ++i)
editCommandVector[i]->invalidate();
m_pageClient->clearAllEditCommands();
m_activePopupMenu = 0;
m_estimatedProgress = 0.0;
m_pendingLearnOrIgnoreWordMessageCount = 0;
// If the call out to the loader client didn't cause the web process to be relaunched,
// we'll call setNeedsDisplay on the view so that we won't have the old contents showing.
// If the call did cause the web process to be relaunched, we'll keep the old page contents showing
// until the new web process has painted its contents.
setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
// Can't expect DidReceiveEvent notifications from a crashed web process.
#if ENABLE(GESTURE_EVENTS)
m_gestureEventQueue.clear();
#endif
m_keyEventQueue.clear();
m_wheelEventQueue.clear();
m_currentlyProcessedWheelEvents.clear();
m_nextMouseMoveEvent = nullptr;
m_currentlyProcessedMouseDownEvent = nullptr;
m_processingMouseMoveEvent = false;
#if ENABLE(TOUCH_EVENTS)
m_needTouchEvents = false;
m_touchEventQueue.clear();
#endif
// FIXME: Reset m_editorState.
// FIXME: Notify input methods about abandoned composition.
m_temporarilyClosedComposition = false;
#if PLATFORM(MAC)
dismissCorrectionPanel(ReasonForDismissingAlternativeTextIgnored);
m_pageClient->dismissDictionaryLookupPanel();
#endif
}
WebPageCreationParameters WebPageProxy::creationParameters() const
{
WebPageCreationParameters parameters;
parameters.viewSize = m_pageClient->viewSize();
parameters.isActive = m_pageClient->isViewWindowActive();
parameters.isFocused = m_pageClient->isViewFocused();
parameters.isVisible = m_pageClient->isViewVisible();
parameters.isInWindow = m_pageClient->isViewInWindow();
parameters.drawingAreaType = m_drawingArea->type();
parameters.store = m_pageGroup->preferences()->store();
parameters.pageGroupData = m_pageGroup->data();
parameters.drawsBackground = m_drawsBackground;
parameters.drawsTransparentBackground = m_drawsTransparentBackground;
parameters.underlayColor = m_underlayColor;
parameters.areMemoryCacheClientCallsEnabled = m_areMemoryCacheClientCallsEnabled;
parameters.useFixedLayout = m_useFixedLayout;
parameters.fixedLayoutSize = m_fixedLayoutSize;
parameters.suppressScrollbarAnimations = m_suppressScrollbarAnimations;
parameters.paginationMode = m_paginationMode;
parameters.paginationBehavesLikeColumns = m_paginationBehavesLikeColumns;
parameters.pageLength = m_pageLength;
parameters.gapBetweenPages = m_gapBetweenPages;
parameters.userAgent = userAgent();
parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
parameters.canRunBeforeUnloadConfirmPanel = m_uiClient.canRunBeforeUnloadConfirmPanel();
parameters.canRunModal = m_canRunModal;
parameters.deviceScaleFactor = deviceScaleFactor();
parameters.mediaVolume = m_mediaVolume;
parameters.mayStartMediaWhenInWindow = m_mayStartMediaWhenInWindow;
parameters.minimumLayoutSize = m_minimumLayoutSize;
parameters.scrollPinningBehavior = m_scrollPinningBehavior;
#if PLATFORM(MAC)
parameters.layerHostingMode = m_layerHostingMode;
parameters.colorSpace = m_pageClient->colorSpace();
#endif
return parameters;
}
#if USE(ACCELERATED_COMPOSITING)
void WebPageProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
m_pageClient->enterAcceleratedCompositingMode(layerTreeContext);
}
void WebPageProxy::exitAcceleratedCompositingMode()
{
m_pageClient->exitAcceleratedCompositingMode();
}
void WebPageProxy::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
m_pageClient->updateAcceleratedCompositingMode(layerTreeContext);
}
#endif // USE(ACCELERATED_COMPOSITING)
void WebPageProxy::backForwardClear()
{
m_backForwardList->clear();
}
void WebPageProxy::canAuthenticateAgainstProtectionSpaceInFrame(uint64_t frameID, const ProtectionSpace& coreProtectionSpace, bool& canAuthenticate)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
RefPtr<WebProtectionSpace> protectionSpace = WebProtectionSpace::create(coreProtectionSpace);
canAuthenticate = m_loaderClient.canAuthenticateAgainstProtectionSpaceInFrame(this, frame, protectionSpace.get());
}
void WebPageProxy::didReceiveAuthenticationChallenge(uint64_t frameID, const AuthenticationChallenge& coreChallenge, uint64_t challengeID)
{
didReceiveAuthenticationChallengeProxy(frameID, AuthenticationChallengeProxy::create(coreChallenge, challengeID, m_process->connection()));
}
void WebPageProxy::didReceiveAuthenticationChallengeProxy(uint64_t frameID, PassRefPtr<AuthenticationChallengeProxy> prpAuthenticationChallenge)
{
ASSERT(prpAuthenticationChallenge);
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
RefPtr<AuthenticationChallengeProxy> authenticationChallenge = prpAuthenticationChallenge;
m_loaderClient.didReceiveAuthenticationChallengeInFrame(this, frame, authenticationChallenge.get());
}
void WebPageProxy::exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply> reply)
{
ExceededDatabaseQuotaRecords& records = ExceededDatabaseQuotaRecords::shared();
OwnPtr<ExceededDatabaseQuotaRecords::Record> newRecord = records.createRecord(frameID,
originIdentifier, databaseName, displayName, currentQuota, currentOriginUsage,
currentDatabaseUsage, expectedUsage, reply);
records.add(newRecord.release());
if (records.areBeingProcessed())
return;
ExceededDatabaseQuotaRecords::Record* record = records.next();
while (record) {
WebFrameProxy* frame = m_process->webFrame(record->frameID);
MESSAGE_CHECK(frame);
RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(record->originIdentifier);
uint64_t newQuota = m_uiClient.exceededDatabaseQuota(this, frame, origin.get(),
record->databaseName, record->displayName, record->currentQuota,
record->currentOriginUsage, record->currentDatabaseUsage, record->expectedUsage);
record->reply->send(newQuota);
record = records.next();
}
}
void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
{
WebFrameProxy* frame = m_process->webFrame(frameID);
MESSAGE_CHECK(frame);
// FIXME: Geolocation should probably be using toString() as its string representation instead of databaseIdentifier().
RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
RefPtr<GeolocationPermissionRequestProxy> request = m_geolocationPermissionRequestManager.createRequest(geolocationID);
if (!m_uiClient.decidePolicyForGeolocationPermissionRequest(this, frame, origin.get(), request.get()))
request->deny();
}
void WebPageProxy::requestNotificationPermission(uint64_t requestID, const String& originString)
{
if (!isRequestIDValid(requestID))
return;
RefPtr<WebSecurityOrigin> origin = WebSecurityOrigin::createFromString(originString);
RefPtr<NotificationPermissionRequest> request = m_notificationPermissionRequestManager.createRequest(requestID);
if (!m_uiClient.decidePolicyForNotificationPermissionRequest(this, origin.get(), request.get()))
request->deny();
}
void WebPageProxy::showNotification(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, const String& dir, const String& originString, uint64_t notificationID)
{
m_process->context()->supplement<WebNotificationManagerProxy>()->show(this, title, body, iconURL, tag, lang, dir, originString, notificationID);
}
void WebPageProxy::cancelNotification(uint64_t notificationID)
{
m_process->context()->supplement<WebNotificationManagerProxy>()->cancel(this, notificationID);
}
void WebPageProxy::clearNotifications(const Vector<uint64_t>& notificationIDs)
{
m_process->context()->supplement<WebNotificationManagerProxy>()->clearNotifications(this, notificationIDs);
}
void WebPageProxy::didDestroyNotification(uint64_t notificationID)
{
m_process->context()->supplement<WebNotificationManagerProxy>()->didDestroyNotification(this, notificationID);
}
float WebPageProxy::headerHeight(WebFrameProxy* frame)
{
if (frame->isDisplayingPDFDocument())
return 0;
return m_uiClient.headerHeight(this, frame);
}
float WebPageProxy::footerHeight(WebFrameProxy* frame)
{
if (frame->isDisplayingPDFDocument())
return 0;
return m_uiClient.footerHeight(this, frame);
}
void WebPageProxy::drawHeader(WebFrameProxy* frame, const FloatRect& rect)
{
if (frame->isDisplayingPDFDocument())
return;
m_uiClient.drawHeader(this, frame, rect);
}
void WebPageProxy::drawFooter(WebFrameProxy* frame, const FloatRect& rect)
{
if (frame->isDisplayingPDFDocument())
return;
m_uiClient.drawFooter(this, frame, rect);
}
void WebPageProxy::runModal()
{
// Since runModal() can (and probably will) spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();
// Our Connection's run loop might have more messages waiting to be handled after this RunModal message.
// To make sure they are handled inside of the the nested modal run loop we must first signal the Connection's
// run loop so we're guaranteed that it has a chance to wake up.
// See http://webkit.org/b/89590 for more discussion.
m_process->connection()->wakeUpRunLoop();
m_uiClient.runModal(this);
}
void WebPageProxy::notifyScrollerThumbIsVisibleInRect(const IntRect& scrollerThumb)
{
m_visibleScrollerThumbRect = scrollerThumb;
}
void WebPageProxy::recommendedScrollbarStyleDidChange(int32_t newStyle)
{
#if PLATFORM(MAC)
m_pageClient->recommendedScrollbarStyleDidChange(newStyle);
#else
UNUSED_PARAM(newStyle);
#endif
}
void WebPageProxy::didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
{
m_mainFrameHasHorizontalScrollbar = hasHorizontalScrollbar;
m_mainFrameHasVerticalScrollbar = hasVerticalScrollbar;
}
void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide, bool pinnedToTopSide, bool pinnedToBottomSide)
{
m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
m_mainFrameIsPinnedToTopSide = pinnedToTopSide;
m_mainFrameIsPinnedToBottomSide = pinnedToBottomSide;
}
void WebPageProxy::didChangePageCount(unsigned pageCount)
{
m_pageCount = pageCount;
}
void WebPageProxy::didFailToInitializePlugin(const String& mimeType, const String& frameURLString, const String& pageURLString)
{
m_loaderClient.didFailToInitializePlugin(this, createPluginInformationDictionary(mimeType, frameURLString, pageURLString).get());
}
void WebPageProxy::didBlockInsecurePluginVersion(const String& mimeType, const String& pluginURLString, const String& frameURLString, const String& pageURLString, bool replacementObscured)
{
RefPtr<ImmutableDictionary> pluginInformation;
#if PLATFORM(MAC) && ENABLE(NETSCAPE_PLUGIN_API)
String newMimeType = mimeType;
PluginModuleInfo plugin = m_process->context()->pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), pluginURLString));
pluginInformation = createPluginInformationDictionary(plugin, frameURLString, mimeType, pageURLString, String(), String(), replacementObscured);
#else
UNUSED_PARAM(pluginURLString);
#endif
m_loaderClient.didBlockInsecurePluginVersion(this, pluginInformation.get());
}
bool WebPageProxy::willHandleHorizontalScrollEvents() const
{
return !m_canShortCircuitHorizontalWheelEvents;
}
void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
{
m_process->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
}
void WebPageProxy::setCanRunModal(bool canRunModal)
{
if (!isValid())
return;
// It's only possible to change the state for a WebPage which
// already qualifies for running modal child web pages, otherwise
// there's no other possibility than not allowing it.
m_canRunModal = m_uiClient.canRunModal() && canRunModal;
m_process->send(Messages::WebPage::SetCanRunModal(m_canRunModal), m_pageID);
}
bool WebPageProxy::canRunModal()
{
return isValid() ? m_canRunModal : false;
}
void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInfo)
{
if (m_isInPrintingMode)
return;
m_isInPrintingMode = true;
m_process->send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
void WebPageProxy::endPrinting()
{
if (!m_isInPrintingMode)
return;
m_isInPrintingMode = false;
m_process->send(Messages::WebPage::EndPrinting(), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<ComputedPagesCallback> prpCallback)
{
RefPtr<ComputedPagesCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_computedPagesCallbacks.set(callbackID, callback.get());
m_isInPrintingMode = true;
m_process->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
#if PLATFORM(MAC)
void WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, PassRefPtr<ImageCallback> prpCallback)
{
RefPtr<ImageCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_imageCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
{
RefPtr<DataCallback> callback = prpCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_dataCallbacks.set(callbackID, callback.get());
m_process->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
#elif PLATFORM(GTK)
void WebPageProxy::drawPagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, PassRefPtr<PrintFinishedCallback> didPrintCallback)
{
RefPtr<PrintFinishedCallback> callback = didPrintCallback;
if (!isValid()) {
callback->invalidate();
return;
}
uint64_t callbackID = callback->callbackID();
m_printFinishedCallbacks.set(callbackID, callback.get());
m_isInPrintingMode = true;
m_process->send(Messages::WebPage::DrawPagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
}
#endif
void WebPageProxy::flashBackingStoreUpdates(const Vector<IntRect>& updateRects)
{
m_pageClient->flashBackingStoreUpdates(updateRects);
}
void WebPageProxy::updateBackingStoreDiscardableState()
{
ASSERT(isValid());
bool isDiscardable;
if (!m_process->responsivenessTimer()->isResponsive())
isDiscardable = false;
else
isDiscardable = !m_pageClient->isViewWindowActive() || !isViewVisible();
m_drawingArea->setBackingStoreIsDiscardable(isDiscardable);
}
Color WebPageProxy::viewUpdatesFlashColor()
{
return Color(0, 200, 255);
}
Color WebPageProxy::backingStoreUpdatesFlashColor()
{
return Color(200, 0, 255);
}
void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData* data)
{
m_uiClient.saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data);
}
void WebPageProxy::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const CoreIPC::DataReference& data)
{
if (!suggestedFilename.endsWith(".pdf", false))
return;
RefPtr<WebData> webData = WebData::create(data.data(), data.size());
saveDataToFileInDownloadsFolder(suggestedFilename, "application/pdf", originatingURLString, webData.get());
}
void WebPageProxy::linkClicked(const String& url, const WebMouseEvent& event)
{
m_process->send(Messages::WebPage::LinkClicked(url, event), m_pageID, 0);
}
void WebPageProxy::setMinimumLayoutSize(const IntSize& minimumLayoutSize)
{
if (m_minimumLayoutSize == minimumLayoutSize)
return;
m_minimumLayoutSize = minimumLayoutSize;
if (!isValid())
return;
m_process->send(Messages::WebPage::SetMinimumLayoutSize(minimumLayoutSize), m_pageID, 0);
m_drawingArea->minimumLayoutSizeDidChange();
#if PLATFORM(MAC)
if (m_minimumLayoutSize.width() <= 0)
intrinsicContentSizeDidChange(IntSize(-1, -1));
#endif
}
#if PLATFORM(MAC)
void WebPageProxy::substitutionsPanelIsShowing(bool& isShowing)
{
isShowing = TextChecker::substitutionsPanelIsShowing();
}
void WebPageProxy::showCorrectionPanel(int32_t panelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
{
m_pageClient->showCorrectionPanel((AlternativeTextType)panelType, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
}
void WebPageProxy::dismissCorrectionPanel(int32_t reason)
{
m_pageClient->dismissCorrectionPanel((ReasonForDismissingAlternativeText)reason);
}
void WebPageProxy::dismissCorrectionPanelSoon(int32_t reason, String& result)
{
result = m_pageClient->dismissCorrectionPanelSoon((ReasonForDismissingAlternativeText)reason);
}
void WebPageProxy::recordAutocorrectionResponse(int32_t responseType, const String& replacedString, const String& replacementString)
{
m_pageClient->recordAutocorrectionResponse((AutocorrectionResponseType)responseType, replacedString, replacementString);
}
void WebPageProxy::handleAlternativeTextUIResult(const String& result)
{
if (!isClosed())
m_process->send(Messages::WebPage::HandleAlternativeTextUIResult(result), m_pageID, 0);
}
#if USE(DICTATION_ALTERNATIVES)
void WebPageProxy::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
{
m_pageClient->showDictationAlternativeUI(boundingBoxOfDictatedText, dictationContext);
}
void WebPageProxy::removeDictationAlternatives(uint64_t dictationContext)
{
m_pageClient->removeDictationAlternatives(dictationContext);
}
void WebPageProxy::dictationAlternatives(uint64_t dictationContext, Vector<String>& result)
{
result = m_pageClient->dictationAlternatives(dictationContext);
}
#endif
#endif // PLATFORM(MAC)
#if USE(SOUP)
void WebPageProxy::didReceiveURIRequest(String uriString, uint64_t requestID)
{
m_process->context()->supplement<WebSoupRequestManagerProxy>()->didReceiveURIRequest(uriString, this, requestID);
}
#endif
#if PLATFORM(QT) || PLATFORM(GTK)
void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
{
// FIXME: We need to find out how to proper handle the crashes case.
if (!isValid())
return;
process()->send(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), m_pageID);
}
void WebPageProxy::confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength)
{
if (!isValid())
return;
process()->send(Messages::WebPage::ConfirmComposition(compositionString, selectionStart, selectionLength), m_pageID);
}
void WebPageProxy::cancelComposition()
{
if (!isValid())
return;
process()->send(Messages::WebPage::CancelComposition(), m_pageID);
}
#endif // PLATFORM(QT) || PLATFORM(GTK)
void WebPageProxy::setMainFrameInViewSourceMode(bool mainFrameInViewSourceMode)
{
if (m_mainFrameInViewSourceMode == mainFrameInViewSourceMode)
return;
m_mainFrameInViewSourceMode = mainFrameInViewSourceMode;
if (isValid())
m_process->send(Messages::WebPage::SetMainFrameInViewSourceMode(mainFrameInViewSourceMode), m_pageID);
}
void WebPageProxy::didSaveToPageCache()
{
m_process->didSaveToPageCache();
}
void WebPageProxy::setScrollPinningBehavior(ScrollPinningBehavior pinning)
{
if (m_scrollPinningBehavior == pinning)
return;
m_scrollPinningBehavior = pinning;
if (isValid())
m_process->send(Messages::WebPage::SetScrollPinningBehavior(pinning), m_pageID);
}
} // namespace WebKit
|