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
|
/*
* Copyright (C) 2006-2009, 2011, 2013 Apple Inc. All rights reserved.
* Copyright (C) Research In Motion Limited 2009. 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
* 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 "WebKitDLL.h"
#include "WebFrame.h"
#include "CFDictionaryPropertyBag.h"
#include "COMPropertyBag.h"
#include "DOMCoreClasses.h"
#include "DefaultPolicyDelegate.h"
#include "HTMLFrameOwnerElement.h"
#include "MarshallingHelpers.h"
#include "WebActionPropertyBag.h"
#include "WebChromeClient.h"
#include "WebDataSource.h"
#include "WebDocumentLoader.h"
#include "WebDownload.h"
#include "WebEditorClient.h"
#include "WebError.h"
#include "WebFrameNetworkingContext.h"
#include "WebFramePolicyListener.h"
#include "WebHistory.h"
#include "WebHistoryItem.h"
#include "WebKit.h"
#include "WebKitStatisticsPrivate.h"
#include "WebMutableURLRequest.h"
#include "WebNotificationCenter.h"
#include "WebScriptWorld.h"
#include "WebURLResponse.h"
#include "WebView.h"
#include <WebCore/AnimationController.h>
#include <WebCore/BString.h>
#include <WebCore/COMPtr.h>
#include <WebCore/MemoryCache.h>
#include <WebCore/Document.h>
#include <WebCore/DocumentLoader.h>
#include <WebCore/DocumentMarkerController.h>
#include <WebCore/DOMImplementation.h>
#include <WebCore/DOMWindow.h>
#include <WebCore/Editor.h>
#include <WebCore/Event.h>
#include <WebCore/EventHandler.h>
#include <WebCore/FormState.h>
#include <WebCore/Frame.h>
#include <WebCore/FrameLoader.h>
#include <WebCore/FrameLoadRequest.h>
#include <WebCore/FrameTree.h>
#include <WebCore/FrameView.h>
#include <WebCore/FrameWin.h>
#include <WebCore/GDIObjectCounter.h>
#include <WebCore/GraphicsContext.h>
#include <WebCore/HistoryItem.h>
#include <WebCore/HTMLAppletElement.h>
#include <WebCore/HTMLFormElement.h>
#include <WebCore/HTMLFormControlElement.h>
#include <WebCore/HTMLInputElement.h>
#include <WebCore/HTMLNames.h>
#include <WebCore/HTMLPlugInElement.h>
#include <WebCore/JSDOMWindow.h>
#include <WebCore/KeyboardEvent.h>
#include <WebCore/MouseRelatedEvent.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/Page.h>
#include <WebCore/PlatformKeyboardEvent.h>
#include <WebCore/PluginData.h>
#include <WebCore/PluginDatabase.h>
#include <WebCore/PluginView.h>
#include <WebCore/PolicyChecker.h>
#include <WebCore/PrintContext.h>
#include <WebCore/ResourceHandle.h>
#include <WebCore/ResourceLoader.h>
#include <WebCore/ResourceRequest.h>
#include <WebCore/RenderView.h>
#include <WebCore/RenderTreeAsText.h>
#include <WebCore/Settings.h>
#include <WebCore/TextIterator.h>
#include <WebCore/JSDOMBinding.h>
#include <WebCore/ScriptController.h>
#include <WebCore/ScriptValue.h>
#include <WebCore/SecurityOrigin.h>
#include <JavaScriptCore/APICast.h>
#include <JavaScriptCore/JSCJSValue.h>
#include <JavaScriptCore/JSLock.h>
#include <JavaScriptCore/JSObject.h>
#include <wtf/MathExtras.h>
#if USE(CG)
#include <CoreGraphics/CoreGraphics.h>
#elif USE(CAIRO)
#include "PlatformContextCairo.h"
#include <cairo-win32.h>
#endif
#if USE(CG)
// CG SPI used for printing
extern "C" {
CGAffineTransform CGContextGetBaseCTM(CGContextRef c);
void CGContextSetBaseCTM(CGContextRef c, CGAffineTransform m);
}
#endif
using namespace WebCore;
using namespace HTMLNames;
using namespace std;
using JSC::JSGlobalObject;
using JSC::JSLock;
using JSC::JSValue;
#define FLASH_REDRAW 0
// By imaging to a width a little wider than the available pixels,
// thin pages will be scaled down a little, matching the way they
// print in IE and Camino. This lets them use fewer sheets than they
// would otherwise, which is presumably why other browsers do this.
// Wide pages will be scaled down more than this.
const float PrintingMinimumShrinkFactor = 1.25f;
// This number determines how small we are willing to reduce the page content
// in order to accommodate the widest line. If the page would have to be
// reduced smaller to make the widest line fit, we just clip instead (this
// behavior matches MacIE and Mozilla, at least)
const float PrintingMaximumShrinkFactor = 2.0f;
//-----------------------------------------------------------------------------
// Helpers to convert from WebCore to WebKit type
WebFrame* kit(Frame* frame)
{
if (!frame)
return 0;
FrameLoaderClient* frameLoaderClient = frame->loader()->client();
if (frameLoaderClient)
return static_cast<WebFrame*>(frameLoaderClient); // eek, is there a better way than static cast?
return 0;
}
Frame* core(WebFrame* webFrame)
{
if (!webFrame)
return 0;
return webFrame->impl();
}
// This function is not in WebFrame.h because we don't want to advertise the ability to get a non-const Frame from a const WebFrame
Frame* core(const WebFrame* webFrame)
{
if (!webFrame)
return 0;
return const_cast<WebFrame*>(webFrame)->impl();
}
//-----------------------------------------------------------------------------
static Element *elementFromDOMElement(IDOMElement *element)
{
if (!element)
return 0;
COMPtr<IDOMElementPrivate> elePriv;
HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
if (SUCCEEDED(hr)) {
Element* ele;
hr = elePriv->coreElement((void**)&ele);
if (SUCCEEDED(hr))
return ele;
}
return 0;
}
static HTMLFormElement *formElementFromDOMElement(IDOMElement *element)
{
if (!element)
return 0;
IDOMElementPrivate* elePriv;
HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
if (SUCCEEDED(hr)) {
Element* ele;
hr = elePriv->coreElement((void**)&ele);
elePriv->Release();
if (SUCCEEDED(hr) && ele && isHTMLFormElement(ele))
return toHTMLFormElement(ele);
}
return 0;
}
static HTMLInputElement* inputElementFromDOMElement(IDOMElement* element)
{
if (!element)
return 0;
IDOMElementPrivate* elePriv;
HRESULT hr = element->QueryInterface(IID_IDOMElementPrivate, (void**) &elePriv);
if (SUCCEEDED(hr)) {
Element* ele;
hr = elePriv->coreElement((void**)&ele);
elePriv->Release();
if (SUCCEEDED(hr) && ele && isHTMLInputElement(ele))
return toHTMLInputElement(ele);
}
return 0;
}
// WebFramePrivate ------------------------------------------------------------
class WebFrame::WebFramePrivate {
public:
WebFramePrivate()
: frame(0)
, webView(0)
, m_policyFunction(0)
{
}
~WebFramePrivate() { }
FrameView* frameView() { return frame ? frame->view() : 0; }
Frame* frame;
WebView* webView;
FramePolicyFunction m_policyFunction;
COMPtr<WebFramePolicyListener> m_policyListener;
};
// WebFrame ----------------------------------------------------------------
WebFrame::WebFrame()
: WebFrameLoaderClient(this)
, m_refCount(0)
, d(new WebFrame::WebFramePrivate)
, m_quickRedirectComing(false)
, m_inPrintingMode(false)
, m_pageHeight(0)
{
WebFrameCount++;
gClassCount++;
gClassNameCount.add("WebFrame");
}
WebFrame::~WebFrame()
{
delete d;
WebFrameCount--;
gClassCount--;
gClassNameCount.remove("WebFrame");
}
WebFrame* WebFrame::createInstance()
{
WebFrame* instance = new WebFrame();
instance->AddRef();
return instance;
}
HRESULT STDMETHODCALLTYPE WebFrame::setAllowsScrolling(
/* [in] */ BOOL flag)
{
if (Frame* frame = core(this))
if (FrameView* view = frame->view())
view->setCanHaveScrollbars(!!flag);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::allowsScrolling(
/* [retval][out] */ BOOL *flag)
{
if (flag)
if (Frame* frame = core(this))
if (FrameView* view = frame->view())
*flag = view->canHaveScrollbars();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::setIsDisconnected(
/* [in] */ BOOL flag)
{
return E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebFrame::setExcludeFromTextSearch(
/* [in] */ BOOL flag)
{
return E_FAIL;
}
HRESULT WebFrame::reloadFromOrigin()
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
coreFrame->loader()->reload(true);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::paintDocumentRectToContext(
/* [in] */ RECT rect,
/* [in] */ OLE_HANDLE deviceContext)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
// We can't paint with a layout still pending.
view->updateLayoutAndStyleIfNeededRecursive();
HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
GraphicsContext gc(dc);
gc.setShouldIncludeChildWindows(true);
gc.save();
LONG width = rect.right - rect.left;
LONG height = rect.bottom - rect.top;
FloatRect dirtyRect;
dirtyRect.setWidth(width);
dirtyRect.setHeight(height);
gc.clip(dirtyRect);
gc.translate(-rect.left, -rect.top);
view->paintContents(&gc, rect);
gc.restore();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::paintScrollViewRectToContextAtPoint(
/* [in] */ RECT rect,
/* [in] */ POINT pt,
/* [in] */ OLE_HANDLE deviceContext)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
// We can't paint with a layout still pending.
view->updateLayoutAndStyleIfNeededRecursive();
HDC dc = reinterpret_cast<HDC>(static_cast<ULONG64>(deviceContext));
GraphicsContext gc(dc);
gc.setShouldIncludeChildWindows(true);
gc.save();
IntRect dirtyRect(rect);
dirtyRect.move(-pt.x, -pt.y);
view->paint(&gc, dirtyRect);
gc.restore();
return S_OK;
}
// IUnknown -------------------------------------------------------------------
HRESULT STDMETHODCALLTYPE WebFrame::QueryInterface(REFIID riid, void** ppvObject)
{
*ppvObject = 0;
if (IsEqualGUID(riid, __uuidof(WebFrame)))
*ppvObject = this;
else if (IsEqualGUID(riid, IID_IUnknown))
*ppvObject = static_cast<IWebFrame*>(this);
else if (IsEqualGUID(riid, IID_IWebFrame))
*ppvObject = static_cast<IWebFrame*>(this);
else if (IsEqualGUID(riid, IID_IWebFramePrivate))
*ppvObject = static_cast<IWebFramePrivate*>(this);
else if (IsEqualGUID(riid, IID_IWebDocumentText))
*ppvObject = static_cast<IWebDocumentText*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
ULONG STDMETHODCALLTYPE WebFrame::AddRef(void)
{
return ++m_refCount;
}
ULONG STDMETHODCALLTYPE WebFrame::Release(void)
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
// IWebFrame -------------------------------------------------------------------
HRESULT STDMETHODCALLTYPE WebFrame::name(
/* [retval][out] */ BSTR* frameName)
{
if (!frameName) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*frameName = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*frameName = BString(coreFrame->tree()->uniqueName()).release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::webView(
/* [retval][out] */ IWebView** view)
{
*view = 0;
if (!d->webView)
return E_FAIL;
*view = d->webView;
(*view)->AddRef();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::frameView(
/* [retval][out] */ IWebFrameView** /*view*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE WebFrame::DOMDocument(
/* [retval][out] */ IDOMDocument** result)
{
if (!result) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*result = 0;
if (Frame* coreFrame = core(this))
if (Document* document = coreFrame->document())
*result = DOMDocument::createInstance(document);
return *result ? S_OK : E_FAIL;
}
HRESULT WebFrame::DOMWindow(/* [retval][out] */ IDOMWindow** window)
{
if (!window) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*window = 0;
if (Frame* coreFrame = core(this)) {
if (WebCore::DOMWindow* coreWindow = coreFrame->document()->domWindow())
*window = ::DOMWindow::createInstance(coreWindow);
}
return *window ? S_OK : E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebFrame::frameElement(
/* [retval][out] */ IDOMHTMLElement** frameElement)
{
if (!frameElement)
return E_POINTER;
*frameElement = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
COMPtr<IDOMElement> domElement(AdoptCOM, DOMElement::createInstance(coreFrame->ownerElement()));
COMPtr<IDOMHTMLElement> htmlElement(Query, domElement);
if (!htmlElement)
return E_FAIL;
return htmlElement.copyRefTo(frameElement);
}
HRESULT STDMETHODCALLTYPE WebFrame::currentForm(
/* [retval][out] */ IDOMElement **currentForm)
{
if (!currentForm) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*currentForm = 0;
if (Frame* coreFrame = core(this)) {
if (HTMLFormElement* formElement = coreFrame->selection()->currentForm())
*currentForm = DOMElement::createInstance(formElement);
}
return *currentForm ? S_OK : E_FAIL;
}
JSGlobalContextRef STDMETHODCALLTYPE WebFrame::globalContext()
{
Frame* coreFrame = core(this);
if (!coreFrame)
return 0;
return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec());
}
JSGlobalContextRef WebFrame::globalContextForScriptWorld(IWebScriptWorld* iWorld)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return 0;
COMPtr<WebScriptWorld> world(Query, iWorld);
if (!world)
return 0;
return toGlobalRef(coreFrame->script()->globalObject(world->world())->globalExec());
}
HRESULT STDMETHODCALLTYPE WebFrame::loadRequest(
/* [in] */ IWebURLRequest* request)
{
COMPtr<WebMutableURLRequest> requestImpl;
HRESULT hr = request->QueryInterface(&requestImpl);
if (FAILED(hr))
return hr;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
coreFrame->loader()->load(FrameLoadRequest(coreFrame, requestImpl->resourceRequest()));
return S_OK;
}
void WebFrame::loadData(PassRefPtr<WebCore::SharedBuffer> data, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL)
{
String mimeTypeString(mimeType, SysStringLen(mimeType));
if (!mimeType)
mimeTypeString = "text/html";
String encodingString(textEncodingName, SysStringLen(textEncodingName));
// FIXME: We should really be using MarshallingHelpers::BSTRToKURL here,
// but that would turn a null BSTR into a null KURL, and we crash inside of
// WebCore if we use a null KURL in constructing the ResourceRequest.
KURL baseKURL = KURL(KURL(), String(baseURL ? baseURL : L"", SysStringLen(baseURL)));
KURL failingKURL = MarshallingHelpers::BSTRToKURL(failingURL);
ResourceRequest request(baseKURL);
SubstituteData substituteData(data, mimeTypeString, encodingString, failingKURL);
// This method is only called from IWebFrame methods, so don't ASSERT that the Frame pointer isn't null.
if (Frame* coreFrame = core(this))
coreFrame->loader()->load(FrameLoadRequest(coreFrame, request, substituteData));
}
HRESULT STDMETHODCALLTYPE WebFrame::loadData(
/* [in] */ IStream* data,
/* [in] */ BSTR mimeType,
/* [in] */ BSTR textEncodingName,
/* [in] */ BSTR url)
{
RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
STATSTG stat;
if (SUCCEEDED(data->Stat(&stat, STATFLAG_NONAME))) {
if (!stat.cbSize.HighPart && stat.cbSize.LowPart) {
Vector<char> dataBuffer(stat.cbSize.LowPart);
ULONG read;
// FIXME: this does a needless copy, would be better to read right into the SharedBuffer
// or adopt the Vector or something.
if (SUCCEEDED(data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read)))
sharedBuffer->append(dataBuffer.data(), static_cast<int>(dataBuffer.size()));
}
}
loadData(sharedBuffer, mimeType, textEncodingName, url, 0);
return S_OK;
}
HRESULT WebFrame::loadPlainTextString(
/* [in] */ BSTR string,
/* [in] */ BSTR url)
{
RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
BString plainTextMimeType(TEXT("text/plain"), 10);
BString utf16Encoding(TEXT("utf-16"), 6);
loadData(sharedBuffer.release(), plainTextMimeType, utf16Encoding, url, 0);
return S_OK;
}
void WebFrame::loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL)
{
RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string));
BString utf16Encoding(TEXT("utf-16"), 6);
loadData(sharedBuffer.release(), 0, utf16Encoding, baseURL, unreachableURL);
}
HRESULT STDMETHODCALLTYPE WebFrame::loadHTMLString(
/* [in] */ BSTR string,
/* [in] */ BSTR baseURL)
{
loadHTMLString(string, baseURL, 0);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::loadAlternateHTMLString(
/* [in] */ BSTR str,
/* [in] */ BSTR baseURL,
/* [in] */ BSTR unreachableURL)
{
loadHTMLString(str, baseURL, unreachableURL);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::loadArchive(
/* [in] */ IWebArchive* /*archive*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
static inline WebDataSource *getWebDataSource(DocumentLoader* loader)
{
return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
}
HRESULT STDMETHODCALLTYPE WebFrame::dataSource(
/* [retval][out] */ IWebDataSource** source)
{
if (!source) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*source = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->documentLoader());
*source = webDataSource;
if (webDataSource)
webDataSource->AddRef();
return *source ? S_OK : E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebFrame::provisionalDataSource(
/* [retval][out] */ IWebDataSource** source)
{
if (!source) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*source = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->provisionalDocumentLoader());
*source = webDataSource;
if (webDataSource)
webDataSource->AddRef();
return *source ? S_OK : E_FAIL;
}
KURL WebFrame::url() const
{
Frame* coreFrame = core(this);
if (!coreFrame)
return KURL();
return coreFrame->document()->url();
}
HRESULT STDMETHODCALLTYPE WebFrame::stopLoading( void)
{
if (Frame* coreFrame = core(this))
coreFrame->loader()->stopAllLoaders();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::reload( void)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
coreFrame->loader()->reload();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::findFrameNamed(
/* [in] */ BSTR name,
/* [retval][out] */ IWebFrame** frame)
{
if (!frame) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*frame = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
Frame* foundFrame = coreFrame->tree()->find(AtomicString(name, SysStringLen(name)));
if (!foundFrame)
return S_OK;
WebFrame* foundWebFrame = kit(foundFrame);
if (!foundWebFrame)
return E_FAIL;
return foundWebFrame->QueryInterface(IID_IWebFrame, (void**)frame);
}
HRESULT STDMETHODCALLTYPE WebFrame::parentFrame(
/* [retval][out] */ IWebFrame** frame)
{
HRESULT hr = S_OK;
*frame = 0;
if (Frame* coreFrame = core(this))
if (WebFrame* webFrame = kit(coreFrame->tree()->parent()))
hr = webFrame->QueryInterface(IID_IWebFrame, (void**) frame);
return hr;
}
class EnumChildFrames : public IEnumVARIANT
{
public:
EnumChildFrames(Frame* f) : m_refCount(1), m_frame(f), m_curChild(f ? f->tree()->firstChild() : 0) { }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
{
*ppvObject = 0;
if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
*ppvObject = this;
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
virtual ULONG STDMETHODCALLTYPE AddRef(void)
{
return ++m_refCount;
}
virtual ULONG STDMETHODCALLTYPE Release(void)
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
{
if (pCeltFetched)
*pCeltFetched = 0;
if (!rgVar)
return E_POINTER;
VariantInit(rgVar);
if (!celt || celt > 1)
return S_FALSE;
if (!m_frame || !m_curChild)
return S_FALSE;
WebFrame* webFrame = kit(m_curChild);
IUnknown* unknown;
HRESULT hr = webFrame->QueryInterface(IID_IUnknown, (void**)&unknown);
if (FAILED(hr))
return hr;
V_VT(rgVar) = VT_UNKNOWN;
V_UNKNOWN(rgVar) = unknown;
m_curChild = m_curChild->tree()->nextSibling();
if (pCeltFetched)
*pCeltFetched = 1;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
{
if (!m_frame)
return S_FALSE;
for (unsigned i = 0; i < celt && m_curChild; i++)
m_curChild = m_curChild->tree()->nextSibling();
return m_curChild ? S_OK : S_FALSE;
}
virtual HRESULT STDMETHODCALLTYPE Reset(void)
{
if (!m_frame)
return S_FALSE;
m_curChild = m_frame->tree()->firstChild();
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**)
{
return E_NOTIMPL;
}
private:
ULONG m_refCount;
Frame* m_frame;
Frame* m_curChild;
};
HRESULT STDMETHODCALLTYPE WebFrame::childFrames(
/* [retval][out] */ IEnumVARIANT **enumFrames)
{
if (!enumFrames)
return E_POINTER;
*enumFrames = new EnumChildFrames(core(this));
return S_OK;
}
// IWebFramePrivate ------------------------------------------------------
HRESULT WebFrame::renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result)
{
if (!result)
return E_POINTER;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*result = BString(externalRepresentation(coreFrame, forPrinting ? RenderAsTextPrintingMode : RenderAsTextBehaviorNormal)).release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::pageNumberForElementById(
/* [in] */ BSTR id,
/* [in] */ float pageWidthInPixels,
/* [in] */ float pageHeightInPixels,
/* [retval][out] */ int* result)
{
// TODO: Please remove this function if not needed as this is LTC specific function
// and has been moved to Internals.
notImplemented();
return E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebFrame::numberOfPages(
/* [in] */ float pageWidthInPixels,
/* [in] */ float pageHeightInPixels,
/* [retval][out] */ int* result)
{
// TODO: Please remove this function if not needed as this is LTC specific function
// and has been moved to Internals.
notImplemented();
return E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebFrame::scrollOffset(
/* [retval][out] */ SIZE* offset)
{
if (!offset) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
*offset = view->scrollOffset();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::layout()
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
view->layout();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::firstLayoutDone(
/* [retval][out] */ BOOL* result)
{
if (!result) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*result = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*result = coreFrame->loader()->stateMachine()->firstLayoutDone();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::loadType(
/* [retval][out] */ WebFrameLoadType* type)
{
if (!type) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*type = (WebFrameLoadType)0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*type = (WebFrameLoadType)coreFrame->loader()->loadType();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::pendingFrameUnloadEventCount(
/* [retval][out] */ UINT* result)
{
if (!result) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*result = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*result = coreFrame->document()->domWindow()->pendingUnloadEventListeners();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::unused2()
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE WebFrame::hasSpellingMarker(
/* [in] */ UINT from,
/* [in] */ UINT length,
/* [retval][out] */ BOOL* result)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*result = coreFrame->editor().selectionStartHasMarkerFor(DocumentMarker::Spelling, from, length);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::clearOpener()
{
HRESULT hr = S_OK;
if (Frame* coreFrame = core(this))
coreFrame->loader()->setOpener(0);
return hr;
}
HRESULT WebFrame::setTextDirection(BSTR direction)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
String directionString(direction, SysStringLen(direction));
if (directionString == "auto")
coreFrame->editor().setBaseWritingDirection(NaturalWritingDirection);
else if (directionString == "ltr")
coreFrame->editor().setBaseWritingDirection(LeftToRightWritingDirection);
else if (directionString == "rtl")
coreFrame->editor().setBaseWritingDirection(RightToLeftWritingDirection);
return S_OK;
}
// IWebDocumentText -----------------------------------------------------------
HRESULT STDMETHODCALLTYPE WebFrame::supportsTextEncoding(
/* [retval][out] */ BOOL* result)
{
*result = FALSE;
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE WebFrame::selectedString(
/* [retval][out] */ BSTR* result)
{
*result = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
String text = coreFrame->displayStringModifiedByEncoding(coreFrame->editor().selectedText());
*result = BString(text).release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::selectAll()
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
if (!coreFrame->editor().command("SelectAll").execute())
return E_FAIL;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::deselectAll()
{
return E_NOTIMPL;
}
// WebFrame ---------------------------------------------------------------
PassRefPtr<Frame> WebFrame::init(IWebView* webView, Page* page, HTMLFrameOwnerElement* ownerElement)
{
webView->QueryInterface(&d->webView);
d->webView->Release(); // don't hold the extra ref
HWND viewWindow;
d->webView->viewWindow((OLE_HANDLE*)&viewWindow);
this->AddRef(); // We release this ref in frameLoaderDestroyed()
RefPtr<Frame> frame = Frame::create(page, ownerElement, this);
d->frame = frame.get();
return frame.release();
}
Frame* WebFrame::impl()
{
return d->frame;
}
void WebFrame::invalidate()
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
if (Document* document = coreFrame->document())
document->recalcStyle(Node::Force);
}
HRESULT WebFrame::inViewSourceMode(BOOL* flag)
{
if (!flag) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*flag = FALSE;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
*flag = coreFrame->inViewSourceMode() ? TRUE : FALSE;
return S_OK;
}
HRESULT WebFrame::setInViewSourceMode(BOOL flag)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
coreFrame->setInViewSourceMode(!!flag);
return S_OK;
}
HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** element)
{
if (!form)
return E_INVALIDARG;
HTMLFormElement* formElement = formElementFromDOMElement(form);
if (formElement) {
const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
AtomicString targetName((UChar*)name, SysStringLen(name));
for (unsigned int i = 0; i < elements.size(); i++) {
if (!elements[i]->isFormControlElement())
continue;
HTMLFormControlElement* elt = static_cast<HTMLFormControlElement*>(elements[i]);
// Skip option elements, other duds
if (elt->name() == targetName) {
*element = DOMElement::createInstance(elt);
return S_OK;
}
}
}
return E_FAIL;
}
HRESULT WebFrame::formForElement(IDOMElement* element, IDOMElement** form)
{
if (!element)
return E_INVALIDARG;
HTMLInputElement *inputElement = inputElementFromDOMElement(element);
if (!inputElement)
return E_FAIL;
HTMLFormElement *formElement = inputElement->form();
if (!formElement)
return E_FAIL;
*form = DOMElement::createInstance(formElement);
return S_OK;
}
HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result)
{
*result = false;
if (!element)
return E_INVALIDARG;
HTMLInputElement *inputElement = inputElementFromDOMElement(element);
if (!inputElement)
*result = false;
else
*result = inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::resumeAnimations()
{
Frame* frame = core(this);
if (!frame)
return E_FAIL;
frame->animation()->resumeAnimations();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::suspendAnimations()
{
Frame* frame = core(this);
if (!frame)
return E_FAIL;
frame->animation()->suspendAnimations();
return S_OK;
}
HRESULT WebFrame::pauseAnimation(BSTR animationName, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning)
{
if (!node || !animationWasRunning)
return E_POINTER;
*animationWasRunning = FALSE;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
AnimationController* controller = frame->animation();
if (!controller)
return E_FAIL;
COMPtr<DOMNode> domNode(Query, node);
if (!domNode)
return E_FAIL;
*animationWasRunning = controller->pauseAnimationAtTime(domNode->node()->renderer(), String(animationName, SysStringLen(animationName)), secondsFromNow);
return S_OK;
}
HRESULT WebFrame::pauseTransition(BSTR propertyName, IDOMNode* node, double secondsFromNow, BOOL* transitionWasRunning)
{
if (!node || !transitionWasRunning)
return E_POINTER;
*transitionWasRunning = FALSE;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
AnimationController* controller = frame->animation();
if (!controller)
return E_FAIL;
COMPtr<DOMNode> domNode(Query, node);
if (!domNode)
return E_FAIL;
*transitionWasRunning = controller->pauseTransitionAtTime(domNode->node()->renderer(), String(propertyName, SysStringLen(propertyName)), secondsFromNow);
return S_OK;
}
HRESULT WebFrame::visibleContentRect(RECT* rect)
{
if (!rect)
return E_POINTER;
SetRectEmpty(rect);
Frame* frame = core(this);
if (!frame)
return E_FAIL;
FrameView* view = frame->view();
if (!view)
return E_FAIL;
*rect = view->visibleContentRect();
return S_OK;
}
HRESULT WebFrame::numberOfActiveAnimations(UINT* number)
{
if (!number)
return E_POINTER;
*number = 0;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
AnimationController* controller = frame->animation();
if (!controller)
return E_FAIL;
*number = controller->numberOfActiveAnimations(frame->document());
return S_OK;
}
HRESULT WebFrame::isDisplayingStandaloneImage(BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
Document* document = frame->document();
*result = document && document->isImageDocument();
return S_OK;
}
HRESULT WebFrame::allowsFollowingLink(BSTR url, BOOL* result)
{
if (!result)
return E_POINTER;
*result = TRUE;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
*result = frame->document()->securityOrigin()->canDisplay(MarshallingHelpers::BSTRToKURL(url));
return S_OK;
}
HRESULT WebFrame::controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls)
{
if (!form)
return E_INVALIDARG;
HTMLFormElement* formElement = formElementFromDOMElement(form);
if (!formElement)
return E_FAIL;
int inCount = *cControls;
int count = (int) formElement->associatedElements().size();
*cControls = count;
if (!controls)
return S_OK;
if (inCount < count)
return E_FAIL;
*cControls = 0;
const Vector<FormAssociatedElement*>& elements = formElement->associatedElements();
for (int i = 0; i < count; i++) {
if (elements.at(i)->isEnumeratable()) { // Skip option elements, other duds
controls[*cControls] = DOMElement::createInstance(toHTMLElement(elements.at(i)));
(*cControls)++;
}
}
return S_OK;
}
HRESULT WebFrame::elementIsPassword(IDOMElement *element, bool *result)
{
HTMLInputElement* inputElement = inputElementFromDOMElement(element);
*result = inputElement && inputElement->isPasswordField();
return S_OK;
}
HRESULT WebFrame::searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* outResultDistance, BOOL* outResultIsInCellAbove, BSTR* result)
{
if (!result) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
if (outResultDistance)
*outResultDistance = 0;
if (outResultIsInCellAbove)
*outResultIsInCellAbove = FALSE;
*result = 0;
if (!cLabels)
return S_OK;
if (cLabels < 1)
return E_INVALIDARG;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
Vector<String> labelStrings(cLabels);
for (int i=0; i<cLabels; i++)
labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
Element *coreElement = elementFromDOMElement(beforeElement);
if (!coreElement)
return E_FAIL;
size_t resultDistance;
bool resultIsInCellAbove;
String label = coreFrame->searchForLabelsBeforeElement(labelStrings, coreElement, &resultDistance, &resultIsInCellAbove);
*result = SysAllocStringLen(label.characters(), label.length());
if (label.length() && !*result)
return E_OUTOFMEMORY;
if (outResultDistance)
*outResultDistance = resultDistance;
if (outResultIsInCellAbove)
*outResultIsInCellAbove = resultIsInCellAbove;
return S_OK;
}
HRESULT WebFrame::matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result)
{
if (!result) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*result = 0;
if (!cLabels)
return S_OK;
if (cLabels < 1)
return E_INVALIDARG;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
Vector<String> labelStrings(cLabels);
for (int i=0; i<cLabels; i++)
labelStrings[i] = String(labels[i], SysStringLen(labels[i]));
Element *coreElement = elementFromDOMElement(againstElement);
if (!coreElement)
return E_FAIL;
String label = coreFrame->matchLabelsAgainstElement(labelStrings, coreElement);
*result = SysAllocStringLen(label.characters(), label.length());
if (label.length() && !*result)
return E_OUTOFMEMORY;
return S_OK;
}
HRESULT WebFrame::canProvideDocumentSource(bool* result)
{
HRESULT hr = S_OK;
*result = false;
COMPtr<IWebDataSource> dataSource;
hr = WebFrame::dataSource(&dataSource);
if (FAILED(hr))
return hr;
COMPtr<IWebURLResponse> urlResponse;
hr = dataSource->response(&urlResponse);
if (SUCCEEDED(hr) && urlResponse) {
BString mimeTypeBStr;
if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) {
String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr));
*result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType);
}
}
return hr;
}
HRESULT STDMETHODCALLTYPE WebFrame::layerTreeAsText(BSTR* result)
{
if (!result)
return E_POINTER;
*result = 0;
Frame* frame = core(this);
if (!frame)
return E_FAIL;
String text = frame->layerTreeAsText();
*result = BString(text).release();
return S_OK;
}
void WebFrame::frameLoaderDestroyed()
{
// The FrameLoader going away is equivalent to the Frame going away,
// so we now need to clear our frame pointer.
d->frame = 0;
this->Release();
}
void WebFrame::makeRepresentation(DocumentLoader*)
{
notImplemented();
}
void WebFrame::forceLayoutForNonHTML()
{
notImplemented();
}
void WebFrame::setCopiesOnScroll()
{
notImplemented();
}
void WebFrame::detachedFromParent2()
{
notImplemented();
}
void WebFrame::detachedFromParent3()
{
notImplemented();
}
void WebFrame::cancelPolicyCheck()
{
if (d->m_policyListener) {
d->m_policyListener->invalidate();
d->m_policyListener = 0;
}
d->m_policyFunction = 0;
}
void WebFrame::dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState>)
{
}
void WebFrame::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
COMPtr<IWebFormDelegate> formDelegate;
if (FAILED(d->webView->formDelegate(&formDelegate))) {
(coreFrame->loader()->policyChecker()->*function)(PolicyUse);
return;
}
COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form()));
HashMap<String, String> formValuesMap;
const StringPairVector& textFieldValues = formState->textFieldValues();
size_t size = textFieldValues.size();
for (size_t i = 0; i < size; ++i)
formValuesMap.add(textFieldValues[i].first, textFieldValues[i].second);
COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formValuesMap));
COMPtr<WebFrame> sourceFrame(kit(formState->sourceDocument()->frame()));
if (SUCCEEDED(formDelegate->willSubmitForm(this, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get())))
return;
// FIXME: Add a sane default implementation
(coreFrame->loader()->policyChecker()->*function)(PolicyUse);
}
void WebFrame::revertToProvisionalState(DocumentLoader*)
{
notImplemented();
}
void WebFrame::setMainFrameDocumentReady(bool)
{
notImplemented();
}
void WebFrame::willChangeTitle(DocumentLoader*)
{
notImplemented();
}
void WebFrame::didChangeTitle(DocumentLoader*)
{
notImplemented();
}
void WebFrame::didChangeIcons(DocumentLoader*)
{
notImplemented();
}
bool WebFrame::canHandleRequest(const ResourceRequest& request) const
{
return WebView::canHandleRequest(request);
}
bool WebFrame::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
{
notImplemented();
return true;
}
bool WebFrame::canShowMIMEType(const String& /*MIMEType*/) const
{
notImplemented();
return true;
}
bool WebFrame::representationExistsForURLScheme(const String& /*URLScheme*/) const
{
notImplemented();
return false;
}
String WebFrame::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
{
notImplemented();
ASSERT_NOT_REACHED();
return String();
}
void WebFrame::frameLoadCompleted()
{
}
void WebFrame::restoreViewState()
{
}
void WebFrame::provisionalLoadStarted()
{
notImplemented();
}
bool WebFrame::shouldTreatURLAsSameAsCurrent(const KURL&) const
{
notImplemented();
return false;
}
void WebFrame::addHistoryItemForFragmentScroll()
{
notImplemented();
}
void WebFrame::didFinishLoad()
{
notImplemented();
}
void WebFrame::prepareForDataSourceReplacement()
{
notImplemented();
}
String WebFrame::userAgent(const KURL& url)
{
return d->webView->userAgentForKURL(url);
}
void WebFrame::saveViewStateToItem(HistoryItem*)
{
}
ResourceError WebFrame::cancelledError(const ResourceRequest& request)
{
// FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
// Alternatively, we could create our own error domain/codes.
return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());
}
ResourceError WebFrame::blockedError(const ResourceRequest& request)
{
// FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());
}
ResourceError WebFrame::cannotShowURLError(const ResourceRequest& request)
{
// FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotShowURL, request.url().string(), String());
}
ResourceError WebFrame::interruptedForPolicyChangeError(const ResourceRequest& request)
{
// FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
return ResourceError(String(WebKitErrorDomain), WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), String());
}
ResourceError WebFrame::cannotShowMIMETypeError(const ResourceResponse&)
{
notImplemented();
return ResourceError();
}
ResourceError WebFrame::fileDoesNotExistError(const ResourceResponse&)
{
notImplemented();
return ResourceError();
}
ResourceError WebFrame::pluginWillHandleLoadError(const ResourceResponse& response)
{
return ResourceError(String(WebKitErrorDomain), WebKitErrorPlugInWillHandleLoad, response.url().string(), String());
}
bool WebFrame::shouldFallBack(const ResourceError& error)
{
if (error.errorCode() == WebURLErrorCancelled && error.domain() == String(WebURLErrorDomain))
return false;
if (error.errorCode() == WebKitErrorPlugInWillHandleLoad && error.domain() == String(WebKitErrorDomain))
return false;
return true;
}
COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function)
{
// FIXME: <rdar://5634381> We need to support multiple active policy listeners.
if (d->m_policyListener)
d->m_policyListener->invalidate();
Frame* coreFrame = core(this);
ASSERT(coreFrame);
d->m_policyListener.adoptRef(WebFramePolicyListener::createInstance(coreFrame));
d->m_policyFunction = function;
return d->m_policyListener;
}
void WebFrame::receivedPolicyDecision(PolicyAction action)
{
ASSERT(d->m_policyListener);
ASSERT(d->m_policyFunction);
FramePolicyFunction function = d->m_policyFunction;
d->m_policyListener = 0;
d->m_policyFunction = 0;
Frame* coreFrame = core(this);
ASSERT(coreFrame);
(coreFrame->loader()->policyChecker()->*function)(action);
}
void WebFrame::dispatchDecidePolicyForResponse(FramePolicyFunction function, const ResourceResponse& response, const ResourceRequest& request)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
COMPtr<IWebPolicyDelegate> policyDelegate;
if (FAILED(d->webView->policyDelegate(&policyDelegate)))
policyDelegate = DefaultPolicyDelegate::sharedInstance();
COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
if (SUCCEEDED(policyDelegate->decidePolicyForMIMEType(d->webView, BString(response.mimeType()), urlRequest.get(), this, setUpPolicyListener(function).get())))
return;
(coreFrame->loader()->policyChecker()->*function)(PolicyUse);
}
void WebFrame::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
COMPtr<IWebPolicyDelegate> policyDelegate;
if (FAILED(d->webView->policyDelegate(&policyDelegate)))
policyDelegate = DefaultPolicyDelegate::sharedInstance();
COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
if (SUCCEEDED(policyDelegate->decidePolicyForNewWindowAction(d->webView, actionInformation.get(), urlRequest.get(), BString(frameName), setUpPolicyListener(function).get())))
return;
(coreFrame->loader()->policyChecker()->*function)(PolicyUse);
}
void WebFrame::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
COMPtr<IWebPolicyDelegate> policyDelegate;
if (FAILED(d->webView->policyDelegate(&policyDelegate)))
policyDelegate = DefaultPolicyDelegate::sharedInstance();
COMPtr<IWebURLRequest> urlRequest(AdoptCOM, WebMutableURLRequest::createInstance(request));
COMPtr<WebActionPropertyBag> actionInformation(AdoptCOM, WebActionPropertyBag::createInstance(action, formState ? formState->form() : 0, coreFrame));
if (SUCCEEDED(policyDelegate->decidePolicyForNavigationAction(d->webView, actionInformation.get(), urlRequest.get(), this, setUpPolicyListener(function).get())))
return;
(coreFrame->loader()->policyChecker()->*function)(PolicyUse);
}
void WebFrame::dispatchUnableToImplementPolicy(const ResourceError& error)
{
COMPtr<IWebPolicyDelegate> policyDelegate;
if (FAILED(d->webView->policyDelegate(&policyDelegate)))
policyDelegate = DefaultPolicyDelegate::sharedInstance();
COMPtr<IWebError> webError(AdoptCOM, WebError::createInstance(error));
policyDelegate->unableToImplementPolicyWithError(d->webView, webError.get(), this);
}
void WebFrame::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
{
COMPtr<IWebDownloadDelegate> downloadDelegate;
COMPtr<IWebView> webView;
if (SUCCEEDED(this->webView(&webView))) {
if (FAILED(webView->downloadDelegate(&downloadDelegate))) {
// If the WebView doesn't successfully provide a download delegate we'll pass a null one
// into the WebDownload - which may or may not decide to use a DefaultDownloadDelegate
LOG_ERROR("Failed to get downloadDelegate from WebView");
downloadDelegate = 0;
}
}
// Its the delegate's job to ref the WebDownload to keep it alive - otherwise it will be destroyed
// when this method returns
COMPtr<WebDownload> download;
download.adoptRef(WebDownload::createInstance(documentLoader->mainResourceLoader()->handle(), request, response, downloadDelegate.get()));
}
bool WebFrame::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
{
notImplemented();
return false;
}
void WebFrame::dispatchDidFailProvisionalLoad(const ResourceError& error)
{
COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
COMPtr<IWebError> webError;
webError.adoptRef(WebError::createInstance(error));
frameLoadDelegate->didFailProvisionalLoadWithError(d->webView, webError.get(), this);
}
}
void WebFrame::dispatchDidFailLoad(const ResourceError& error)
{
COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {
COMPtr<IWebError> webError;
webError.adoptRef(WebError::createInstance(error));
frameLoadDelegate->didFailLoadWithError(d->webView, webError.get(), this);
}
}
void WebFrame::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
{
d->webView->downloadURL(request.url());
}
PassRefPtr<Widget> WebFrame::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues)
{
RefPtr<PluginView> pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);
// Check if the plugin can be loaded successfully
if (pluginView->plugin() && pluginView->plugin()->load())
return pluginView;
COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))
return pluginView;
COMPtr<CFDictionaryPropertyBag> userInfoBag = CFDictionaryPropertyBag::createInstance();
ResourceError resourceError(String(WebKitErrorDomain), WebKitErrorJavaUnavailable, String(), String());
COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));
return pluginView;
}
ObjectContentType WebFrame::objectContentType(const KURL& url, const String& mimeType, bool shouldPreferPlugInsForImages)
{
return WebCore::FrameLoader::defaultObjectContentType(url, mimeType, shouldPreferPlugInsForImages);
}
String WebFrame::overrideMediaType() const
{
notImplemented();
return String();
}
void WebFrame::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
Settings* settings = coreFrame->settings();
if (!settings || !settings->isScriptEnabled())
return;
COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
if (FAILED(d->webView->frameLoadDelegate(&frameLoadDelegate)))
return;
COMPtr<IWebFrameLoadDelegatePrivate2> delegatePrivate(Query, frameLoadDelegate);
if (delegatePrivate && delegatePrivate->didClearWindowObjectForFrameInScriptWorld(d->webView, this, WebScriptWorld::findOrCreateWorld(world).get()) != E_NOTIMPL)
return;
if (world != mainThreadNormalWorld())
return;
JSContextRef context = toRef(coreFrame->script()->globalObject(world)->globalExec());
JSObjectRef windowObject = toRef(coreFrame->script()->globalObject(world));
ASSERT(windowObject);
if (FAILED(frameLoadDelegate->didClearWindowObject(d->webView, context, windowObject, this)))
frameLoadDelegate->windowScriptObjectAvailable(d->webView, context, windowObject);
}
void WebFrame::documentElementAvailable()
{
}
void WebFrame::didPerformFirstNavigation() const
{
COMPtr<IWebPreferences> preferences;
if (FAILED(d->webView->preferences(&preferences)))
return;
COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);
if (!preferencesPrivate)
return;
BOOL automaticallyDetectsCacheModel;
if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))
return;
WebCacheModel cacheModel;
if (FAILED(preferences->cacheModel(&cacheModel)))
return;
if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)
preferences->setCacheModel(WebCacheModelDocumentBrowser);
}
void WebFrame::registerForIconNotification(bool listen)
{
d->webView->registerForIconNotification(listen);
}
static IntRect printerRect(HDC printDC)
{
return IntRect(0, 0,
GetDeviceCaps(printDC, PHYSICALWIDTH) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETX),
GetDeviceCaps(printDC, PHYSICALHEIGHT) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETY));
}
void WebFrame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot adjustViewSize)
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
coreFrame->setPrinting(printing, pageSize, originalPageSize, maximumShrinkRatio, adjustViewSize ? AdjustViewSize : DoNotAdjustViewSize);
}
HRESULT STDMETHODCALLTYPE WebFrame::setInPrintingMode(
/* [in] */ BOOL value,
/* [in] */ HDC printDC)
{
if (m_inPrintingMode == !!value)
return S_OK;
Frame* coreFrame = core(this);
if (!coreFrame || !coreFrame->document())
return E_FAIL;
m_inPrintingMode = !!value;
// If we are a frameset just print with the layout we have onscreen, otherwise relayout
// according to the paper size
FloatSize minLayoutSize(0.0, 0.0);
FloatSize originalPageSize(0.0, 0.0);
if (m_inPrintingMode && !coreFrame->document()->isFrameSet()) {
if (!printDC) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
const int desiredPixelsPerInch = 72;
IntRect printRect = printerRect(printDC);
int paperHorizontalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSX);
int paperVerticalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSY);
int paperWidth = printRect.width() * desiredPixelsPerInch / paperHorizontalPixelsPerInch;
int paperHeight = printRect.height() * desiredPixelsPerInch / paperVerticalPixelsPerInch;
originalPageSize = FloatSize(paperWidth, paperHeight);
Frame* coreFrame = core(this);
minLayoutSize = coreFrame->resizePageRectsKeepingRatio(originalPageSize, FloatSize(paperWidth * PrintingMinimumShrinkFactor, paperHeight * PrintingMinimumShrinkFactor));
}
setPrinting(m_inPrintingMode, minLayoutSize, originalPageSize, PrintingMaximumShrinkFactor / PrintingMinimumShrinkFactor, AdjustViewSize);
if (!m_inPrintingMode)
m_pageRects.clear();
return S_OK;
}
void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight)
{
if (headerHeight)
*headerHeight = 0;
if (footerHeight)
*footerHeight = 0;
float height = 0;
COMPtr<IWebUIDelegate> ui;
if (FAILED(d->webView->uiDelegate(&ui)))
return;
if (headerHeight && SUCCEEDED(ui->webViewHeaderHeight(d->webView, &height)))
*headerHeight = height;
if (footerHeight && SUCCEEDED(ui->webViewFooterHeight(d->webView, &height)))
*footerHeight = height;
}
IntRect WebFrame::printerMarginRect(HDC printDC)
{
IntRect emptyRect(0, 0, 0, 0);
COMPtr<IWebUIDelegate> ui;
if (FAILED(d->webView->uiDelegate(&ui)))
return emptyRect;
RECT rect;
if (FAILED(ui->webViewPrintingMarginRect(d->webView, &rect)))
return emptyRect;
rect.left = MulDiv(rect.left, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
rect.top = MulDiv(rect.top, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
rect.right = MulDiv(rect.right, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);
rect.bottom = MulDiv(rect.bottom, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);
return IntRect(rect.left, rect.top, (rect.right - rect.left), rect.bottom - rect.top);
}
const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC)
{
ASSERT(m_inPrintingMode);
Frame* coreFrame = core(this);
ASSERT(coreFrame);
ASSERT(coreFrame->document());
if (!printDC)
return m_pageRects;
// adjust the page rect by the header and footer
float headerHeight = 0, footerHeight = 0;
headerAndFooterHeights(&headerHeight, &footerHeight);
IntRect pageRect = printerRect(printDC);
IntRect marginRect = printerMarginRect(printDC);
IntRect adjustedRect = IntRect(
pageRect.x() + marginRect.x(),
pageRect.y() + marginRect.y(),
pageRect.width() - marginRect.x() - marginRect.maxX(),
pageRect.height() - marginRect.y() - marginRect.maxY());
computePageRectsForFrame(coreFrame, adjustedRect, headerHeight, footerHeight, 1.0,m_pageRects, m_pageHeight);
return m_pageRects;
}
HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(
/* [in] */ HDC printDC,
/* [retval][out] */ UINT *pageCount)
{
if (!pageCount || !printDC) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
*pageCount = 0;
if (!m_inPrintingMode) {
ASSERT_NOT_REACHED();
return E_FAIL;
}
Frame* coreFrame = core(this);
if (!coreFrame || !coreFrame->document())
return E_FAIL;
const Vector<IntRect>& pages = computePageRects(printDC);
*pageCount = (UINT) pages.size();
return S_OK;
}
#if USE(CG)
void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
{
int x = pageRect.x();
int y = 0;
RECT headerRect = {x, y, x+pageRect.width(), y+static_cast<int>(headerHeight)};
ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)));
}
void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
{
int x = pageRect.x();
int y = max((int)headerHeight+pageRect.height(), m_pageHeight-static_cast<int>(footerHeight));
RECT footerRect = {x, y, x+pageRect.width(), y+static_cast<int>(footerHeight)};
ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)), page+1, pageCount);
}
void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
{
Frame* coreFrame = core(this);
IntRect pageRect = m_pageRects[page];
CGContextSaveGState(pctx);
IntRect printRect = printerRect(printDC);
CGRect mediaBox = CGRectMake(CGFloat(0),
CGFloat(0),
CGFloat(printRect.width()),
CGFloat(printRect.height()));
CGContextBeginPage(pctx, &mediaBox);
CGFloat scale = static_cast<float>(mediaBox.size.width)/static_cast<float>(pageRect.width());
CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
ctm = CGAffineTransformScale(ctm, -scale, -scale);
ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
CGContextScaleCTM(pctx, scale, scale);
CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
CGContextSetBaseCTM(pctx, ctm);
coreFrame->view()->paintContents(spoolCtx, pageRect);
CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);
if (headerHeight)
drawHeader(pctx, ui, pageRect, headerHeight);
if (footerHeight)
drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
CGContextEndPage(pctx);
CGContextRestoreGState(pctx);
}
#elif USE(CAIRO)
static float scaleFactor(HDC printDC, const IntRect& marginRect, const IntRect& pageRect)
{
const IntRect& printRect = printerRect(printDC);
IntRect adjustedRect = IntRect(
printRect.x() + marginRect.x(),
printRect.y() + marginRect.y(),
printRect.width() - marginRect.x() - marginRect.maxX(),
printRect.height() - marginRect.y() - marginRect.maxY());
float scale = static_cast<float>(adjustedRect.width()) / static_cast<float>(pageRect.width());
if (!scale)
scale = 1.0;
return scale;
}
static HDC hdcFromContext(PlatformGraphicsContext* pctx)
{
return cairo_win32_surface_get_dc(cairo_get_target(pctx->cr()));
}
void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
{
HDC hdc = hdcFromContext(pctx);
int x = pageRect.x();
int y = 0;
RECT headerRect = {x, y, x + pageRect.width(), y + static_cast<int>(headerHeight)};
ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)));
}
void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
{
HDC hdc = hdcFromContext(pctx);
int x = pageRect.x();
int y = max(static_cast<int>(headerHeight) + pageRect.height(), m_pageHeight -static_cast<int>(footerHeight));
RECT footerRect = {x, y, x + pageRect.width(), y + static_cast<int>(footerHeight)};
ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)), page+1, pageCount);
}
static XFORM buildXFORMFromCairo(HDC targetDC, cairo_t* previewContext)
{
XFORM scaled;
GetWorldTransform(targetDC, &scaled);
cairo_matrix_t ctm;
cairo_get_matrix(previewContext, &ctm);
// Scale to the preview screen bounds
scaled.eM11 = ctm.xx;
scaled.eM22 = ctm.yy;
return scaled;
}
void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
{
Frame* coreFrame = core(this);
const IntRect& pageRect = m_pageRects[page];
const IntRect& marginRect = printerMarginRect(printDC);
// In preview, the printDC is a placeholder, so just always use the HDC backing the graphics context.
HDC hdc = hdcFromContext(pctx);
spoolCtx->save();
XFORM original, scaled;
GetWorldTransform(hdc, &original);
cairo_t* cr = pctx->cr();
bool preview = (hdc != printDC);
if (preview) {
// If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo will
// draw correctly. We need to retain the correct preview scale here for use when the Cairo
// drawing completes so that we can scale our GDI-based header/footer calls. This is a
// workaround for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
scaled = buildXFORMFromCairo(hdc, cr);
}
float scale = scaleFactor(printDC, marginRect, pageRect);
IntRect cairoMarginRect(marginRect);
cairoMarginRect.scale(1 / scale);
// We cannot scale the display HDC because the print surface also scales fonts,
// resulting in invalid printing (and print preview)
cairo_scale(cr, scale, scale);
cairo_translate(cr, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
// Modify Cairo (only) to account for page position.
cairo_translate(cr, -pageRect.x(), -pageRect.y());
coreFrame->view()->paintContents(spoolCtx, pageRect);
cairo_translate(cr, pageRect.x(), pageRect.y());
if (preview) {
// If this is a preview, the Windows HDC was set to a non-scaled state so that Cairo would
// draw correctly. We need to rescale the HDC to the correct preview scale so our GDI-based
// header/footer calls will draw properly. This is a workaround for a bug in Cairo.
// (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
SetWorldTransform(hdc, &scaled);
}
XFORM xform = TransformationMatrix().translate(marginRect.x(), marginRect.y()).scale(scale);
ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
if (headerHeight)
drawHeader(pctx, ui, pageRect, headerHeight);
if (footerHeight)
drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
SetWorldTransform(hdc, &original);
cairo_show_page(cr);
ASSERT(!cairo_status(cr));
spoolCtx->restore();
}
static void setCairoTransformToPreviewHDC(cairo_t* previewCtx, HDC previewDC)
{
XFORM passedCTM;
GetWorldTransform(previewDC, &passedCTM);
// Reset HDC WorldTransform to unscaled state. Scaling must be
// done in Cairo to avoid drawing errors.
XFORM unscaledCTM = passedCTM;
unscaledCTM.eM11 = 1.0;
unscaledCTM.eM22 = 1.0;
SetWorldTransform(previewDC, &unscaledCTM);
// Make the Cairo transform match the information passed to WebKit
// in the HDC's WorldTransform.
cairo_matrix_t ctm = { passedCTM.eM11, passedCTM.eM12, passedCTM.eM21,
passedCTM.eM22, passedCTM.eDx, passedCTM.eDy };
cairo_set_matrix(previewCtx, &ctm);
}
#endif
HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
/* [in] */ HDC printDC,
/* [in] */ UINT startPage,
/* [in] */ UINT endPage,
/* [retval][out] */ void* ctx)
{
#if USE(CG)
if (!printDC || !ctx) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
#elif USE(CAIRO)
if (!printDC) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
HDC targetDC = (ctx) ? (HDC)ctx : printDC;
cairo_surface_t* printSurface = 0;
if (ctx)
printSurface = cairo_win32_surface_create(targetDC); // in-memory
else
printSurface = cairo_win32_printing_surface_create(targetDC); // metafile
cairo_t* cr = cairo_create(printSurface);
if (!cr) {
cairo_surface_destroy(printSurface);
return E_FAIL;
}
PlatformContextCairo platformContext(cr);
PlatformGraphicsContext* pctx = &platformContext;
cairo_destroy(cr);
if (ctx) {
// If this is a preview, the Windows HDC was sent with scaling information.
// Retrieve it and reset it so that it draws properly. This is a workaround
// for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
setCairoTransformToPreviewHDC(cr, targetDC);
}
cairo_surface_set_fallback_resolution(printSurface, 72.0, 72.0);
#endif
if (!m_inPrintingMode) {
ASSERT_NOT_REACHED();
return E_FAIL;
}
Frame* coreFrame = core(this);
if (!coreFrame || !coreFrame->document())
return E_FAIL;
UINT pageCount = (UINT) m_pageRects.size();
#if USE(CG)
PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;
#endif
if (!pageCount || startPage > pageCount) {
ASSERT_NOT_REACHED();
return E_FAIL;
}
if (startPage > 0)
startPage--;
if (endPage == 0)
endPage = pageCount;
COMPtr<IWebUIDelegate> ui;
if (FAILED(d->webView->uiDelegate(&ui)))
return E_FAIL;
float headerHeight = 0, footerHeight = 0;
headerAndFooterHeights(&headerHeight, &footerHeight);
GraphicsContext spoolCtx(pctx);
spoolCtx.setShouldIncludeChildWindows(true);
for (UINT ii = startPage; ii < endPage; ii++)
spoolPage(pctx, &spoolCtx, printDC, ui.get(), headerHeight, footerHeight, ii, pageCount);
#if USE(CAIRO)
cairo_surface_finish(printSurface);
ASSERT(!cairo_surface_status(printSurface));
cairo_surface_destroy(printSurface);
#endif
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::isFrameSet(
/* [retval][out] */ BOOL* result)
{
*result = FALSE;
Frame* coreFrame = core(this);
if (!coreFrame || !coreFrame->document())
return E_FAIL;
*result = coreFrame->document()->isFrameSet() ? TRUE : FALSE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::string(
/* [retval][out] */ BSTR *result)
{
*result = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
RefPtr<Range> allRange(rangeOfContents(coreFrame->document()));
String allString = plainText(allRange.get());
*result = BString(allString).release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::size(
/* [retval][out] */ SIZE *size)
{
if (!size)
return E_POINTER;
size->cx = size->cy = 0;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
size->cx = view->width();
size->cy = view->height();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::hasScrollBars(
/* [retval][out] */ BOOL *result)
{
if (!result)
return E_POINTER;
*result = FALSE;
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
if (view->horizontalScrollbar() || view->verticalScrollbar())
*result = TRUE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::contentBounds(
/* [retval][out] */ RECT *result)
{
if (!result)
return E_POINTER;
::SetRectEmpty(result);
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
result->bottom = view->contentsHeight();
result->right = view->contentsWidth();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::frameBounds(
/* [retval][out] */ RECT *result)
{
if (!result)
return E_POINTER;
::SetRectEmpty(result);
Frame* coreFrame = core(this);
if (!coreFrame)
return E_FAIL;
FrameView* view = coreFrame->view();
if (!view)
return E_FAIL;
FloatRect bounds = view->visibleContentRect(ScrollableArea::IncludeScrollbars);
result->bottom = (LONG) bounds.height();
result->right = (LONG) bounds.width();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebFrame::isDescendantOfFrame(
/* [in] */ IWebFrame *ancestor,
/* [retval][out] */ BOOL *result)
{
if (!result)
return E_POINTER;
*result = FALSE;
Frame* coreFrame = core(this);
COMPtr<WebFrame> ancestorWebFrame(Query, ancestor);
if (!ancestorWebFrame)
return S_OK;
*result = (coreFrame && coreFrame->tree()->isDescendantOf(core(ancestorWebFrame.get()))) ? TRUE : FALSE;
return S_OK;
}
HRESULT WebFrame::stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld* iWorld, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult)
{
if (!evaluationResult)
return E_POINTER;
*evaluationResult = 0;
if (!iWorld)
return E_POINTER;
COMPtr<WebScriptWorld> world(Query, iWorld);
if (!world)
return E_INVALIDARG;
Frame* coreFrame = core(this);
String string = String(script, SysStringLen(script));
// Start off with some guess at a frame and a global object, we'll try to do better...!
JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());
// The global object is probably a shell object? - if so, we know how to use this!
JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
// Get the frame frome the global object we've settled on.
Frame* frame = anyWorldGlobalObject->impl()->frame();
ASSERT(frame->document());
JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();
if (!frame) // In case the script removed our frame from the page.
return S_OK;
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
// JSEvaluateScript instead, since they have less surprising semantics.
if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
return S_OK;
JSC::ExecState* exec = anyWorldGlobalObject->globalExec();
JSC::JSLockHolder lock(exec);
String resultString = result.toWTFString(exec);
*evaluationResult = BString(resultString).release();
return S_OK;
}
void WebFrame::unmarkAllMisspellings()
{
Frame* coreFrame = core(this);
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
Document *doc = frame->document();
if (!doc)
return;
doc->markers()->removeMarkers(DocumentMarker::Spelling);
}
}
void WebFrame::unmarkAllBadGrammar()
{
Frame* coreFrame = core(this);
for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
Document *doc = frame->document();
if (!doc)
return;
doc->markers()->removeMarkers(DocumentMarker::Grammar);
}
}
WebView* WebFrame::webView() const
{
return d->webView;
}
void WebFrame::setWebView(WebView* webView)
{
d->webView = webView;
}
COMPtr<IAccessible> WebFrame::accessible() const
{
Frame* coreFrame = core(this);
ASSERT(coreFrame);
Document* currentDocument = coreFrame->document();
if (!currentDocument)
m_accessible = 0;
else if (!m_accessible || m_accessible->document() != currentDocument) {
// Either we've never had a wrapper for this frame's top-level Document,
// the Document renderer was destroyed and its wrapper was detached, or
// the previous Document is in the page cache, and the current document
// needs to be wrapped.
m_accessible = new AccessibleDocument(currentDocument, webView()->viewWindow());
}
return m_accessible.get();
}
void WebFrame::updateBackground()
{
Color backgroundColor = webView()->transparent() ? Color::transparent : Color::white;
Frame* coreFrame = core(this);
if (!coreFrame || !coreFrame->view())
return;
coreFrame->view()->updateBackgroundRecursively(backgroundColor, webView()->transparent());
}
PassRefPtr<FrameNetworkingContext> WebFrame::createNetworkingContext()
{
return WebFrameNetworkingContext::create(core(this), userAgent(url()));
}
|