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
|
/*
* Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "InjectedBundlePage.h"
#include "InjectedBundle.h"
#include "StringFunctions.h"
#include "WebCoreTestSupport.h"
#include <cmath>
#include <JavaScriptCore/JSRetainPtr.h>
#include <WebKit2/WKArray.h>
#include <WebKit2/WKBundle.h>
#include <WebKit2/WKBundleBackForwardList.h>
#include <WebKit2/WKBundleBackForwardListItem.h>
#include <WebKit2/WKBundleFrame.h>
#include <WebKit2/WKBundleFramePrivate.h>
#include <WebKit2/WKBundleHitTestResult.h>
#include <WebKit2/WKBundleNavigationAction.h>
#include <WebKit2/WKBundleNodeHandlePrivate.h>
#include <WebKit2/WKBundlePagePrivate.h>
#include <WebKit2/WKBundlePrivate.h>
#include <WebKit2/WKSecurityOrigin.h>
#include <WebKit2/WKURLRequest.h>
#include <wtf/HashMap.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
#if USE(CF)
#include "WebArchiveDumpSupport.h"
#endif
using namespace std;
namespace WTR {
static bool hasPrefix(const WTF::String& searchString, const WTF::String& prefix)
{
return searchString.length() >= prefix.length() && searchString.substring(0, prefix.length()) == prefix;
}
static JSValueRef propertyValue(JSContextRef context, JSObjectRef object, const char* propertyName)
{
if (!object)
return 0;
JSRetainPtr<JSStringRef> propertyNameString(Adopt, JSStringCreateWithUTF8CString(propertyName));
return JSObjectGetProperty(context, object, propertyNameString.get(), 0);
}
static double propertyValueDouble(JSContextRef context, JSObjectRef object, const char* propertyName)
{
JSValueRef value = propertyValue(context, object, propertyName);
if (!value)
return 0;
return JSValueToNumber(context, value, 0);
}
static int propertyValueInt(JSContextRef context, JSObjectRef object, const char* propertyName)
{
return static_cast<int>(propertyValueDouble(context, object, propertyName));
}
static double numericWindowPropertyValue(WKBundleFrameRef frame, const char* propertyName)
{
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
return propertyValueDouble(context, JSContextGetGlobalObject(context), propertyName);
}
static WTF::String dumpPath(JSGlobalContextRef context, JSObjectRef nodeValue)
{
JSValueRef nodeNameValue = propertyValue(context, nodeValue, "nodeName");
JSRetainPtr<JSStringRef> jsStringNodeName(Adopt, JSValueToStringCopy(context, nodeNameValue, 0));
WKRetainPtr<WKStringRef> nodeName = toWK(jsStringNodeName);
JSValueRef parentNode = propertyValue(context, nodeValue, "parentNode");
StringBuilder stringBuilder;
stringBuilder.append(toWTFString(nodeName));
if (parentNode && JSValueIsObject(context, parentNode)) {
stringBuilder.appendLiteral(" > ");
stringBuilder.append(dumpPath(context, (JSObjectRef)parentNode));
}
return stringBuilder.toString();
}
static WTF::String dumpPath(WKBundlePageRef page, WKBundleScriptWorldRef world, WKBundleNodeHandleRef node)
{
if (!node)
return "(null)";
WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
JSValueRef nodeValue = WKBundleFrameGetJavaScriptWrapperForNodeForWorld(frame, node, world);
ASSERT(JSValueIsObject(context, nodeValue));
JSObjectRef nodeObject = (JSObjectRef)nodeValue;
return dumpPath(context, nodeObject);
}
static WTF::String rangeToStr(WKBundlePageRef page, WKBundleScriptWorldRef world, WKBundleRangeHandleRef rangeRef)
{
if (!rangeRef)
return "(null)";
WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
JSValueRef rangeValue = WKBundleFrameGetJavaScriptWrapperForRangeForWorld(frame, rangeRef, world);
ASSERT(JSValueIsObject(context, rangeValue));
JSObjectRef rangeObject = (JSObjectRef)rangeValue;
JSValueRef startNodeValue = propertyValue(context, rangeObject, "startContainer");
ASSERT(JSValueIsObject(context, startNodeValue));
JSObjectRef startNodeObject = (JSObjectRef)startNodeValue;
JSValueRef endNodeValue = propertyValue(context, rangeObject, "endContainer");
ASSERT(JSValueIsObject(context, endNodeValue));
JSObjectRef endNodeObject = (JSObjectRef)endNodeValue;
int startOffset = propertyValueInt(context, rangeObject, "startOffset");
int endOffset = propertyValueInt(context, rangeObject, "endOffset");
StringBuilder stringBuilder;
stringBuilder.appendLiteral("range from ");
stringBuilder.appendNumber(startOffset);
stringBuilder.appendLiteral(" of ");
stringBuilder.append(dumpPath(context, startNodeObject));
stringBuilder.appendLiteral(" to ");
stringBuilder.appendNumber(endOffset);
stringBuilder.appendLiteral(" of ");
stringBuilder.append(dumpPath(context, endNodeObject));
return stringBuilder.toString();
}
static WKRetainPtr<WKStringRef> NavigationTypeToString(WKFrameNavigationType type)
{
switch (type) {
case kWKFrameNavigationTypeLinkClicked:
return adoptWK(WKStringCreateWithUTF8CString("link clicked"));
case kWKFrameNavigationTypeFormSubmitted:
return adoptWK(WKStringCreateWithUTF8CString("form submitted"));
case kWKFrameNavigationTypeBackForward:
return adoptWK(WKStringCreateWithUTF8CString("back/forward"));
case kWKFrameNavigationTypeReload:
return adoptWK(WKStringCreateWithUTF8CString("reload"));
case kWKFrameNavigationTypeFormResubmitted:
return adoptWK(WKStringCreateWithUTF8CString("form resubmitted"));
case kWKFrameNavigationTypeOther:
return adoptWK(WKStringCreateWithUTF8CString("other"));
}
return adoptWK(WKStringCreateWithUTF8CString("illegal value"));
}
static WTF::String styleDecToStr(WKBundleCSSStyleDeclarationRef style)
{
// DumpRenderTree calls -[DOMCSSStyleDeclaration description], which just dumps class name and object address.
// No existing tests actually hit this code path at the time of this writing, because WebCore doesn't call
// the editing client if the styling operation source is CommandFromDOM or CommandFromDOMWithUserInterface.
StringBuilder stringBuilder;
stringBuilder.appendLiteral("<DOMCSSStyleDeclaration ADDRESS>");
return stringBuilder.toString();
}
static WTF::String securityOriginToStr(WKSecurityOriginRef origin)
{
StringBuilder stringBuilder;
stringBuilder.append('{');
stringBuilder.append(toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin))));
stringBuilder.appendLiteral(", ");
stringBuilder.append(toWTFString(adoptWK(WKSecurityOriginCopyHost(origin))));
stringBuilder.appendLiteral(", ");
stringBuilder.appendNumber(WKSecurityOriginGetPort(origin));
stringBuilder.append('}');
return stringBuilder.toString();
}
static WTF::String frameToStr(WKBundleFrameRef frame)
{
WKRetainPtr<WKStringRef> name(AdoptWK, WKBundleFrameCopyName(frame));
StringBuilder stringBuilder;
if (WKBundleFrameIsMainFrame(frame)) {
if (!WKStringIsEmpty(name.get())) {
stringBuilder.appendLiteral("main frame \"");
stringBuilder.append(toWTFString(name));
stringBuilder.append('"');
} else
stringBuilder.appendLiteral("main frame");
} else {
if (!WKStringIsEmpty(name.get())) {
stringBuilder.appendLiteral("frame \"");
stringBuilder.append(toWTFString(name));
stringBuilder.append('"');
}
else
stringBuilder.appendLiteral("frame (anonymous)");
}
return stringBuilder.toString();
}
static inline bool isLocalFileScheme(WKStringRef scheme)
{
return WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "file");
}
static const char divider = '/';
static inline WTF::String pathSuitableForTestResult(WKURLRef fileUrl)
{
if (!fileUrl)
return "(null)";
WKRetainPtr<WKStringRef> schemeString = adoptWK(WKURLCopyScheme(fileUrl));
if (!isLocalFileScheme(schemeString.get()))
return toWTFString(adoptWK(WKURLCopyString(fileUrl)));
WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
if (!mainFrameURL)
mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame));
String pathString = toWTFString(adoptWK(WKURLCopyPath(fileUrl)));
String mainFrameURLPathString = toWTFString(adoptWK(WKURLCopyPath(mainFrameURL.get())));
String basePath = mainFrameURLPathString.substring(0, mainFrameURLPathString.reverseFind(divider) + 1);
if (!basePath.isEmpty() && pathString.startsWith(basePath))
return pathString.substring(basePath.length());
return toWTFString(adoptWK(WKURLCopyLastPathComponent(fileUrl))); // We lose some information here, but it's better than exposing a full path, which is always machine specific.
}
static HashMap<uint64_t, String> assignedUrlsCache;
static inline void dumpResourceURL(uint64_t identifier, StringBuilder& stringBuilder)
{
if (assignedUrlsCache.contains(identifier))
stringBuilder.append(assignedUrlsCache.get(identifier));
else
stringBuilder.appendLiteral("<unknown>");
}
InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
: m_page(page)
, m_world(AdoptWK, WKBundleScriptWorldCreateWorld())
{
WKBundlePageLoaderClientV7 loaderClient = {
{ 7, this },
didStartProvisionalLoadForFrame,
didReceiveServerRedirectForProvisionalLoadForFrame,
didFailProvisionalLoadWithErrorForFrame,
didCommitLoadForFrame,
didFinishDocumentLoadForFrame,
didFinishLoadForFrame,
didFailLoadWithErrorForFrame,
didSameDocumentNavigationForFrame,
didReceiveTitleForFrame,
0, // didFirstLayoutForFrame
0, // didFirstVisuallyNonEmptyLayoutForFrame
0, // didRemoveFrameFromHierarchy
didDisplayInsecureContentForFrame,
didRunInsecureContentForFrame,
didClearWindowForFrame,
didCancelClientRedirectForFrame,
willPerformClientRedirectForFrame,
didHandleOnloadEventsForFrame,
0, // didLayoutForFrame
0, // didNewFirstVisuallyNonEmptyLayout_unavailable
didDetectXSSForFrame,
0, // shouldGoToBackForwardListItem
0, // didCreateGlobalObjectForFrame
0, // willDisconnectDOMWindowExtensionFromGlobalObject
0, // didReconnectDOMWindowExtensionToGlobalObject
0, // willDestroyGlobalObjectForDOMWindowExtension
didFinishProgress, // didFinishProgress
0, // shouldForceUniversalAccessFromLocalURL
0, // didReceiveIntentForFrame
0, // registerIntentServiceForFrame
0, // didLayout
0, // featuresUsedInPage
0, // willLoadURLRequest
0, // willLoadDataRequest
0, // willDestroyFrame
};
WKBundlePageSetPageLoaderClient(m_page, &loaderClient.base);
WKBundlePageResourceLoadClientV1 resourceLoadClient = {
{ 1, this },
didInitiateLoadForResource,
willSendRequestForFrame,
didReceiveResponseForResource,
didReceiveContentLengthForResource,
didFinishLoadForResource,
didFailLoadForResource,
shouldCacheResponse,
0 // shouldUseCredentialStorage
};
WKBundlePageSetResourceLoadClient(m_page, &resourceLoadClient.base);
WKBundlePagePolicyClientV0 policyClient = {
{ 0, this },
decidePolicyForNavigationAction,
decidePolicyForNewWindowAction,
decidePolicyForResponse,
unableToImplementPolicy
};
WKBundlePageSetPolicyClient(m_page, &policyClient.base);
WKBundlePageUIClientV2 uiClient = {
{ 2, this },
willAddMessageToConsole,
willSetStatusbarText,
willRunJavaScriptAlert,
willRunJavaScriptConfirm,
willRunJavaScriptPrompt,
0, /*mouseDidMoveOverElement*/
0, /*pageDidScroll*/
0, /*paintCustomOverhangArea*/
0, /*shouldGenerateFileForUpload*/
0, /*generateFileForUpload*/
0, /*shouldRubberBandInDirection*/
0, /*statusBarIsVisible*/
0, /*menuBarIsVisible*/
0, /*toolbarsAreVisible*/
didReachApplicationCacheOriginQuota,
didExceedDatabaseQuota,
0, /*plugInStartLabelTitle*/
0, /*plugInStartLabelSubtitle*/
0, /*plugInExtraStyleSheet*/
0, /*plugInExtraScript*/
};
WKBundlePageSetUIClient(m_page, &uiClient.base);
WKBundlePageEditorClientV1 editorClient = {
{ 1, this },
shouldBeginEditing,
shouldEndEditing,
shouldInsertNode,
shouldInsertText,
shouldDeleteRange,
shouldChangeSelectedRange,
shouldApplyStyle,
didBeginEditing,
didEndEditing,
didChange,
didChangeSelection,
0, /* willWriteToPasteboard */
0, /* getPasteboardDataForRange */
0 /* didWriteToPasteboard */
};
WKBundlePageSetEditorClient(m_page, &editorClient.base);
#if ENABLE(FULLSCREEN_API)
WKBundlePageFullScreenClientV1 fullScreenClient = {
{ 1, this },
supportsFullScreen,
enterFullScreenForElement,
exitFullScreenForElement,
beganEnterFullScreen,
beganExitFullScreen,
closeFullScreen,
};
WKBundlePageSetFullScreenClient(m_page, &fullScreenClient.base);
#endif
}
InjectedBundlePage::~InjectedBundlePage()
{
}
void InjectedBundlePage::stopLoading()
{
WKBundlePageStopLoading(m_page);
}
void InjectedBundlePage::prepare()
{
WKBundlePageClearMainFrameName(m_page);
WKBundlePageSetPageZoomFactor(m_page, 1);
WKBundlePageSetTextZoomFactor(m_page, 1);
WKPoint origin = { 0, 0 };
WKBundlePageSetScaleAtOrigin(m_page, 1, origin);
m_previousTestBackForwardListItem = adoptWK(WKBundleBackForwardListCopyItemAtIndex(WKBundlePageGetBackForwardList(m_page), 0));
WKBundleFrameClearOpener(WKBundlePageGetMainFrame(m_page));
WKBundlePageSetTracksRepaints(m_page, false);
}
void InjectedBundlePage::resetAfterTest()
{
WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
WebCoreTestSupport::resetInternalsObject(context);
assignedUrlsCache.clear();
}
// Loader Client Callbacks
// String output must be identical to -[WebFrame _drt_descriptionSuitableForTestResult].
static void dumpFrameDescriptionSuitableForTestResult(WKBundleFrameRef frame, StringBuilder& stringBuilder)
{
WKRetainPtr<WKStringRef> name(AdoptWK, WKBundleFrameCopyName(frame));
if (WKBundleFrameIsMainFrame(frame)) {
if (WKStringIsEmpty(name.get())) {
stringBuilder.appendLiteral("main frame");
return;
}
stringBuilder.appendLiteral("main frame \"");
stringBuilder.append(toWTFString(name));
stringBuilder.append('"');
return;
}
if (WKStringIsEmpty(name.get())) {
stringBuilder.appendLiteral("frame (anonymous)");
return;
}
stringBuilder.appendLiteral("frame \"");
stringBuilder.append(toWTFString(name));
stringBuilder.append('"');
}
static void dumpLoadEvent(WKBundleFrameRef frame, const char* eventName)
{
StringBuilder stringBuilder;
dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder);
stringBuilder.appendLiteral(" - ");
stringBuilder.append(eventName);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
static inline void dumpRequestDescriptionSuitableForTestResult(WKURLRequestRef request, StringBuilder& stringBuilder)
{
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
WKRetainPtr<WKURLRef> firstParty = adoptWK(WKURLRequestCopyFirstPartyForCookies(request));
WKRetainPtr<WKStringRef> httpMethod = adoptWK(WKURLRequestCopyHTTPMethod(request));
stringBuilder.appendLiteral("<NSURLRequest URL ");
stringBuilder.append(pathSuitableForTestResult(url.get()));
stringBuilder.appendLiteral(", main document URL ");
stringBuilder.append(pathSuitableForTestResult(firstParty.get()));
stringBuilder.appendLiteral(", http method ");
if (WKStringIsEmpty(httpMethod.get()))
stringBuilder.appendLiteral("(none)");
else
stringBuilder.append(toWTFString(httpMethod));
stringBuilder.append('>');
}
static inline void dumpResponseDescriptionSuitableForTestResult(WKURLResponseRef response, StringBuilder& stringBuilder)
{
WKRetainPtr<WKURLRef> url = adoptWK(WKURLResponseCopyURL(response));
if (!url) {
stringBuilder.appendLiteral("(null)");
return;
}
stringBuilder.appendLiteral("<NSURLResponse ");
stringBuilder.append(pathSuitableForTestResult(url.get()));
stringBuilder.appendLiteral(", http status code ");
stringBuilder.appendNumber(WKURLResponseHTTPStatusCode(response));
stringBuilder.append('>');
}
static inline void dumpErrorDescriptionSuitableForTestResult(WKErrorRef error, StringBuilder& stringBuilder)
{
WKRetainPtr<WKStringRef> errorDomain = adoptWK(WKErrorCopyDomain(error));
int errorCode = WKErrorGetErrorCode(error);
// We need to do some error mapping here to match the test expectations (Mac error names are expected).
if (WKStringIsEqualToUTF8CString(errorDomain.get(), "WebKitNetworkError")) {
errorDomain = adoptWK(WKStringCreateWithUTF8CString("NSURLErrorDomain"));
errorCode = -999;
}
if (WKStringIsEqualToUTF8CString(errorDomain.get(), "WebKitPolicyError"))
errorDomain = adoptWK(WKStringCreateWithUTF8CString("WebKitErrorDomain"));
stringBuilder.appendLiteral("<NSError domain ");
stringBuilder.append(toWTFString(errorDomain));
stringBuilder.appendLiteral(", code ");
stringBuilder.appendNumber(errorCode);
WKRetainPtr<WKURLRef> url = adoptWK(WKErrorCopyFailingURL(error));
if (url.get()) {
WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get()));
stringBuilder.appendLiteral(", failing URL \"");
stringBuilder.append(toWTFString(urlString));
stringBuilder.append('"');
}
stringBuilder.append('>');
}
void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didStartProvisionalLoadForFrame(frame);
}
void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveServerRedirectForProvisionalLoadForFrame(frame);
}
void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailProvisionalLoadWithErrorForFrame(frame, error);
}
void InjectedBundlePage::didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didCommitLoadForFrame(frame);
}
void InjectedBundlePage::didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishLoadForFrame(frame);
}
void InjectedBundlePage::didFinishProgress(WKBundlePageRef, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishProgress();
}
void InjectedBundlePage::didFinishDocumentLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishDocumentLoadForFrame(frame);
}
void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailLoadWithErrorForFrame(frame, error);
}
void InjectedBundlePage::didReceiveTitleForFrame(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveTitleForFrame(title, frame);
}
void InjectedBundlePage::didClearWindowForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleScriptWorldRef world, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didClearWindowForFrame(frame, world);
}
void InjectedBundlePage::didCancelClientRedirectForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didCancelClientRedirectForFrame(frame);
}
void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willPerformClientRedirectForFrame(page, frame, url, delay, date);
}
void InjectedBundlePage::didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef*, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didSameDocumentNavigationForFrame(frame, type);
}
void InjectedBundlePage::didHandleOnloadEventsForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didHandleOnloadEventsForFrame(frame);
}
void InjectedBundlePage::didDisplayInsecureContentForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didDisplayInsecureContentForFrame(frame);
}
void InjectedBundlePage::didDetectXSSForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didDetectXSSForFrame(frame);
}
void InjectedBundlePage::didRunInsecureContentForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef*, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didRunInsecureContentForFrame(frame);
}
void InjectedBundlePage::didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool pageLoadIsProvisional, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didInitiateLoadForResource(page, frame, identifier, request, pageLoadIsProvisional);
}
WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willSendRequestForFrame(page, frame, identifier, request, redirectResponse);
}
void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLResponseRef response, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveResponseForResource(page, frame, identifier, response);
}
void InjectedBundlePage::didReceiveContentLengthForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, uint64_t length, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReceiveContentLengthForResource(page, frame, identifier, length);
}
void InjectedBundlePage::didFinishLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishLoadForResource(page, frame, identifier);
}
void InjectedBundlePage::didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKErrorRef error, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFailLoadForResource(page, frame, identifier, error);
}
bool InjectedBundlePage::shouldCacheResponse(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldCacheResponse(page, frame, identifier);
}
void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
platformDidStartProvisionalLoadForFrame(frame);
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didStartProvisionalLoadForFrame");
if (!InjectedBundle::shared().topLoadingFrame())
InjectedBundle::shared().setTopLoadingFrame(frame);
if (InjectedBundle::shared().testRunner()->shouldStopProvisionalFrameLoads())
dumpLoadEvent(frame, "stopping load in didStartProvisionalLoadForFrame callback");
}
void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
return;
dumpLoadEvent(frame, "didReceiveServerRedirectForProvisionalLoadForFrame");
}
void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didFailProvisionalLoadWithError");
frameDidChangeLocation(frame);
}
void InjectedBundlePage::didCommitLoadForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
return;
dumpLoadEvent(frame, "didCommitLoadForFrame");
}
void InjectedBundlePage::didFinishProgress()
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpProgressFinishedCallback())
return;
InjectedBundle::shared().outputText("postProgressFinishedNotification\n");
}
enum FrameNamePolicy { ShouldNotIncludeFrameName, ShouldIncludeFrameName };
static void dumpFrameScrollPosition(WKBundleFrameRef frame, StringBuilder& stringBuilder, FrameNamePolicy shouldIncludeFrameName = ShouldNotIncludeFrameName)
{
double x = numericWindowPropertyValue(frame, "pageXOffset");
double y = numericWindowPropertyValue(frame, "pageYOffset");
if (fabs(x) <= 0.00000001 && fabs(y) <= 0.00000001)
return;
if (shouldIncludeFrameName) {
WKRetainPtr<WKStringRef> name(AdoptWK, WKBundleFrameCopyName(frame));
stringBuilder.appendLiteral("frame '");
stringBuilder.append(toWTFString(name));
stringBuilder.appendLiteral("' ");
}
stringBuilder.appendLiteral("scrolled to ");
stringBuilder.append(WTF::String::number(x));
stringBuilder.append(',');
stringBuilder.append(WTF::String::number(y));
stringBuilder.append('\n');
}
static void dumpDescendantFrameScrollPositions(WKBundleFrameRef frame, StringBuilder& stringBuilder)
{
WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame));
size_t size = WKArrayGetSize(childFrames.get());
for (size_t i = 0; i < size; ++i) {
WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i));
dumpFrameScrollPosition(subframe, stringBuilder, ShouldIncludeFrameName);
dumpDescendantFrameScrollPositions(subframe, stringBuilder);
}
}
void InjectedBundlePage::dumpAllFrameScrollPositions(StringBuilder& stringBuilder)
{
WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
dumpFrameScrollPosition(frame, stringBuilder);
dumpDescendantFrameScrollPositions(frame, stringBuilder);
}
static JSRetainPtr<JSStringRef> toJS(const char* string)
{
return JSRetainPtr<JSStringRef>(Adopt, JSStringCreateWithUTF8CString(string));
}
static bool hasDocumentElement(WKBundleFrameRef frame)
{
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
JSObjectRef globalObject = JSContextGetGlobalObject(context);
JSValueRef documentValue = JSObjectGetProperty(context, globalObject, toJS("document").get(), 0);
if (!documentValue)
return false;
ASSERT(JSValueIsObject(context, documentValue));
JSObjectRef document = JSValueToObject(context, documentValue, 0);
JSValueRef documentElementValue = JSObjectGetProperty(context, document, toJS("documentElement").get(), 0);
if (!documentElementValue)
return false;
return JSValueToBoolean(context, documentElementValue);
}
static void dumpFrameText(WKBundleFrameRef frame, StringBuilder& stringBuilder)
{
// If the frame doesn't have a document element, its inner text will be an empty string, so
// we'll end up just appending a single newline below. But DumpRenderTree doesn't append
// anything in this case, so we shouldn't either.
if (!hasDocumentElement(frame))
return;
WKRetainPtr<WKStringRef> text(AdoptWK, WKBundleFrameCopyInnerText(frame));
stringBuilder.append(toWTFString(text));
stringBuilder.append('\n');
}
static void dumpDescendantFramesText(WKBundleFrameRef frame, StringBuilder& stringBuilder)
{
WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame));
size_t size = WKArrayGetSize(childFrames.get());
for (size_t i = 0; i < size; ++i) {
WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i));
WKRetainPtr<WKStringRef> subframeName(AdoptWK, WKBundleFrameCopyName(subframe));
// DumpRenderTree ignores empty frames, so do the same thing here.
if (!hasDocumentElement(subframe))
continue;
stringBuilder.appendLiteral("\n--------\nFrame: '");
stringBuilder.append(toWTFString(subframeName));
stringBuilder.appendLiteral("'\n--------\n");
dumpFrameText(subframe, stringBuilder);
dumpDescendantFramesText(subframe, stringBuilder);
}
}
void InjectedBundlePage::dumpAllFramesText(StringBuilder& stringBuilder)
{
WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
dumpFrameText(frame, stringBuilder);
dumpDescendantFramesText(frame, stringBuilder);
}
void InjectedBundlePage::dumpDOMAsWebArchive(WKBundleFrameRef frame, StringBuilder& stringBuilder)
{
#if USE(CF)
WKRetainPtr<WKDataRef> wkData = adoptWK(WKBundleFrameCopyWebArchive(frame));
RetainPtr<CFDataRef> cfData = adoptCF(CFDataCreate(0, WKDataGetBytes(wkData.get()), WKDataGetSize(wkData.get())));
RetainPtr<CFStringRef> cfString = adoptCF(createXMLStringFromWebArchiveData(cfData.get()));
stringBuilder.append(cfString.get());
#endif
}
void InjectedBundlePage::dump()
{
ASSERT(InjectedBundle::shared().isTestRunning());
InjectedBundle::shared().testRunner()->invalidateWaitToDumpWatchdogTimer();
// Force a paint before dumping. This matches DumpRenderTree on Windows. (DumpRenderTree on Mac
// does this at a slightly different time.) See <http://webkit.org/b/55469> for details.
WKBundlePageForceRepaint(m_page);
WKBundleFrameRef frame = WKBundlePageGetMainFrame(m_page);
WKRetainPtr<WKURLRef> urlRef = adoptWK(WKBundleFrameCopyURL(frame));
String url = toWTFString(adoptWK(WKURLCopyString(urlRef.get())));
WKRetainPtr<WKStringRef> mimeType = adoptWK(WKBundleFrameCopyMIMETypeForResourceWithURL(frame, urlRef.get()));
if (url.find("dumpAsText/") != notFound || WKStringIsEqualToUTF8CString(mimeType.get(), "text/plain"))
InjectedBundle::shared().testRunner()->dumpAsText(false);
StringBuilder stringBuilder;
switch (InjectedBundle::shared().testRunner()->whatToDump()) {
case TestRunner::RenderTree: {
if (InjectedBundle::shared().testRunner()->isPrinting())
stringBuilder.append(toWTFString(adoptWK(WKBundlePageCopyRenderTreeExternalRepresentationForPrinting(m_page)).get()));
else
stringBuilder.append(toWTFString(adoptWK(WKBundlePageCopyRenderTreeExternalRepresentation(m_page)).get()));
break;
}
case TestRunner::MainFrameText:
dumpFrameText(WKBundlePageGetMainFrame(m_page), stringBuilder);
break;
case TestRunner::AllFramesText:
dumpAllFramesText(stringBuilder);
break;
case TestRunner::Audio:
break;
case TestRunner::DOMAsWebArchive:
dumpDOMAsWebArchive(frame, stringBuilder);
break;
}
if (InjectedBundle::shared().testRunner()->shouldDumpAllFrameScrollPositions())
dumpAllFrameScrollPositions(stringBuilder);
else if (InjectedBundle::shared().testRunner()->shouldDumpMainFrameScrollPosition())
dumpFrameScrollPosition(WKBundlePageGetMainFrame(m_page), stringBuilder);
if (InjectedBundle::shared().testRunner()->shouldDumpBackForwardListsForAllWindows())
InjectedBundle::shared().dumpBackForwardListsForAllPages(stringBuilder);
if (InjectedBundle::shared().shouldDumpPixels() && InjectedBundle::shared().testRunner()->shouldDumpPixels()) {
WKSnapshotOptions options = kWKSnapshotOptionsShareable | kWKSnapshotOptionsInViewCoordinates;
if (InjectedBundle::shared().testRunner()->shouldDumpSelectionRect())
options |= kWKSnapshotOptionsPaintSelectionRectangle;
InjectedBundle::shared().setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page)), options)).get());
if (WKBundlePageIsTrackingRepaints(m_page))
InjectedBundle::shared().setRepaintRects(adoptWK(WKBundlePageCopyTrackedRepaintRects(m_page)).get());
}
InjectedBundle::shared().outputText(stringBuilder.toString());
InjectedBundle::shared().done();
}
void InjectedBundlePage::didFinishLoadForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didFinishLoadForFrame");
frameDidChangeLocation(frame, /*shouldDump*/ true);
}
void InjectedBundlePage::didFailLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didFailLoadWithError");
frameDidChangeLocation(frame);
}
void InjectedBundlePage::didReceiveTitleForFrame(WKStringRef title, WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
StringBuilder stringBuilder;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks()) {
dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder);
stringBuilder.appendLiteral(" - didReceiveTitle: ");
stringBuilder.append(toWTFString(title));
stringBuilder.append('\n');
}
if (InjectedBundle::shared().testRunner()->shouldDumpTitleChanges()) {
stringBuilder.appendLiteral("TITLE CHANGED: '");
stringBuilder.append(toWTFString(title));
stringBuilder.appendLiteral("'\n");
}
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundleScriptWorldRef world)
{
if (!InjectedBundle::shared().isTestRunning())
return;
JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
JSObjectRef window = JSContextGetGlobalObject(context);
if (WKBundleScriptWorldNormalWorld() != world) {
JSObjectSetProperty(context, window, toJS("__worldID").get(), JSValueMakeNumber(context, TestRunner::worldIDForWorld(world)), kJSPropertyAttributeReadOnly, 0);
return;
}
JSValueRef exception = 0;
InjectedBundle::shared().testRunner()->makeWindowObject(context, window, &exception);
InjectedBundle::shared().gcController()->makeWindowObject(context, window, &exception);
InjectedBundle::shared().eventSendingController()->makeWindowObject(context, window, &exception);
InjectedBundle::shared().textInputController()->makeWindowObject(context, window, &exception);
InjectedBundle::shared().accessibilityController()->makeWindowObject(context, window, &exception);
WebCoreTestSupport::injectInternalsObject(context);
}
void InjectedBundlePage::didCancelClientRedirectForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
return;
dumpLoadEvent(frame, "didCancelClientRedirectForFrame");
}
void InjectedBundlePage::willPerformClientRedirectForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKURLRef url, double delay, double date)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
return;
StringBuilder stringBuilder;
dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder);
stringBuilder.appendLiteral(" - willPerformClientRedirectToURL: ");
stringBuilder.append(pathSuitableForTestResult(url));
stringBuilder.appendLiteral(" \n");
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didSameDocumentNavigationForFrame(WKBundleFrameRef frame, WKSameDocumentNavigationType type)
{
}
void InjectedBundlePage::didFinishDocumentLoadForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didFinishDocumentLoadForFrame");
unsigned pendingFrameUnloadEvents = WKBundleFrameGetPendingUnloadCount(frame);
if (pendingFrameUnloadEvents) {
StringBuilder stringBuilder;
stringBuilder.append(frameToStr(frame));
stringBuilder.appendLiteral(" - has ");
stringBuilder.appendNumber(pendingFrameUnloadEvents);
stringBuilder.appendLiteral(" onunload handler(s)\n");
InjectedBundle::shared().outputText(stringBuilder.toString());
}
}
void InjectedBundlePage::didHandleOnloadEventsForFrame(WKBundleFrameRef frame)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
dumpLoadEvent(frame, "didHandleOnloadEventsForFrame");
}
void InjectedBundlePage::didDisplayInsecureContentForFrame(WKBundleFrameRef frame)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
InjectedBundle::shared().outputText("didDisplayInsecureContent\n");
}
void InjectedBundlePage::didRunInsecureContentForFrame(WKBundleFrameRef frame)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
InjectedBundle::shared().outputText("didRunInsecureContent\n");
}
void InjectedBundlePage::didDetectXSSForFrame(WKBundleFrameRef frame)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFrameLoadCallbacks())
InjectedBundle::shared().outputText("didDetectXSS\n");
}
void InjectedBundlePage::didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef request, bool)
{
if (!InjectedBundle::shared().isTestRunning())
return;
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
assignedUrlsCache.add(identifier, pathSuitableForTestResult(url.get()));
}
// Resource Load Client Callbacks
static inline bool isLocalHost(WKStringRef host)
{
return WKStringIsEqualToUTF8CString(host, "127.0.0.1") || WKStringIsEqualToUTF8CString(host, "localhost");
}
static inline bool isHTTPOrHTTPSScheme(WKStringRef scheme)
{
return WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "http") || WKStringIsEqualToUTF8CStringIgnoringCase(scheme, "https");
}
WKURLRequestRef InjectedBundlePage::willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef response)
{
if (InjectedBundle::shared().isTestRunning()
&& InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) {
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - willSendRequest ");
dumpRequestDescriptionSuitableForTestResult(request, stringBuilder);
stringBuilder.appendLiteral(" redirectResponse ");
dumpResponseDescriptionSuitableForTestResult(response, stringBuilder);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
if (InjectedBundle::shared().isTestRunning() && InjectedBundle::shared().testRunner()->willSendRequestReturnsNull())
return 0;
WKRetainPtr<WKURLRef> redirectURL = adoptWK(WKURLResponseCopyURL(response));
if (InjectedBundle::shared().isTestRunning() && InjectedBundle::shared().testRunner()->willSendRequestReturnsNullOnRedirect() && redirectURL) {
InjectedBundle::shared().outputText("Returning null for this redirect\n");
return 0;
}
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
WKRetainPtr<WKStringRef> host = adoptWK(WKURLCopyHostName(url.get()));
WKRetainPtr<WKStringRef> scheme = adoptWK(WKURLCopyScheme(url.get()));
WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get()));
if (host && !WKStringIsEmpty(host.get())
&& isHTTPOrHTTPSScheme(scheme.get())
&& !WKStringIsEqualToUTF8CString(host.get(), "255.255.255.255") // Used in some tests that expect to get back an error.
&& !isLocalHost(host.get())) {
bool mainFrameIsExternal = false;
if (InjectedBundle::shared().isTestRunning()) {
WKBundleFrameRef mainFrame = InjectedBundle::shared().topLoadingFrame();
WKRetainPtr<WKURLRef> mainFrameURL = adoptWK(WKBundleFrameCopyURL(mainFrame));
if (!mainFrameURL || WKStringIsEqualToUTF8CString(adoptWK(WKURLCopyString(mainFrameURL.get())).get(), "about:blank"))
mainFrameURL = adoptWK(WKBundleFrameCopyProvisionalURL(mainFrame));
WKRetainPtr<WKStringRef> mainFrameHost = WKURLCopyHostName(mainFrameURL.get());
WKRetainPtr<WKStringRef> mainFrameScheme = WKURLCopyScheme(mainFrameURL.get());
mainFrameIsExternal = isHTTPOrHTTPSScheme(mainFrameScheme.get()) && !isLocalHost(mainFrameHost.get());
}
if (!mainFrameIsExternal) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("Blocked access to external URL ");
stringBuilder.append(toWTFString(urlString));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
return 0;
}
}
WKRetain(request);
return request;
}
void InjectedBundlePage::didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks()) {
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - didReceiveResponse ");
dumpResponseDescriptionSuitableForTestResult(response, stringBuilder);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
if (!InjectedBundle::shared().testRunner()->shouldDumpResourceResponseMIMETypes())
return;
WKRetainPtr<WKURLRef> url = adoptWK(WKURLResponseCopyURL(response));
WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyLastPathComponent(url.get()));
WKRetainPtr<WKStringRef> mimeTypeString = adoptWK(WKURLResponseCopyMIMEType(response));
StringBuilder stringBuilder;
stringBuilder.append(toWTFString(urlString));
stringBuilder.appendLiteral(" has MIME type ");
stringBuilder.append(toWTFString(mimeTypeString));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didReceiveContentLengthForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t, uint64_t)
{
}
void InjectedBundlePage::didFinishLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks())
return;
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - didFinishLoading\n");
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKErrorRef error)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpResourceLoadCallbacks())
return;
StringBuilder stringBuilder;
dumpResourceURL(identifier, stringBuilder);
stringBuilder.appendLiteral(" - didFailLoadingWithError: ");
dumpErrorDescriptionSuitableForTestResult(error, stringBuilder);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
bool InjectedBundlePage::shouldCacheResponse(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
if (!InjectedBundle::shared().testRunner()->shouldDumpWillCacheResponse())
return true;
StringBuilder stringBuilder;
stringBuilder.appendNumber(identifier);
stringBuilder.appendLiteral(" - willCacheResponse: called\n");
InjectedBundle::shared().outputText(stringBuilder.toString());
// The default behavior is the cache the response.
return true;
}
// Policy Client Callbacks
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNavigationAction(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKTypeRef* userData, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->decidePolicyForNavigationAction(page, frame, navigationAction, request, userData);
}
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNewWindowAction(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKStringRef frameName, WKTypeRef* userData, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->decidePolicyForNewWindowAction(page, frame, navigationAction, request, frameName, userData);
}
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForResponse(WKBundlePageRef page, WKBundleFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKTypeRef* userData, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->decidePolicyForResponse(page, frame, response, request, userData);
}
void InjectedBundlePage::unableToImplementPolicy(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef* userData, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->unableToImplementPolicy(page, frame, error, userData);
}
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNavigationAction(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKTypeRef* userData)
{
if (!InjectedBundle::shared().isTestRunning())
return WKBundlePagePolicyActionUse;
if (!InjectedBundle::shared().testRunner()->isPolicyDelegateEnabled())
return WKBundlePagePolicyActionUse;
WKRetainPtr<WKURLRef> url = adoptWK(WKURLRequestCopyURL(request));
WKRetainPtr<WKStringRef> urlScheme = adoptWK(WKURLCopyScheme(url.get()));
StringBuilder stringBuilder;
stringBuilder.appendLiteral("Policy delegate: attempt to load ");
if (isLocalFileScheme(urlScheme.get())) {
WKRetainPtr<WKStringRef> filename = adoptWK(WKURLCopyLastPathComponent(url.get()));
stringBuilder.append(toWTFString(filename));
} else {
WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(url.get()));
stringBuilder.append(toWTFString(urlString));
}
stringBuilder.appendLiteral(" with navigation type \'");
stringBuilder.append(toWTFString(NavigationTypeToString(WKBundleNavigationActionGetNavigationType(navigationAction))));
stringBuilder.appendLiteral("\'");
WKBundleHitTestResultRef hitTestResultRef = WKBundleNavigationActionCopyHitTestResult(navigationAction);
if (hitTestResultRef) {
stringBuilder.appendLiteral(" originating from ");
stringBuilder.append(dumpPath(m_page, m_world.get(), WKBundleHitTestResultCopyNodeHandle(hitTestResultRef)));
}
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
InjectedBundle::shared().testRunner()->notifyDone();
if (InjectedBundle::shared().testRunner()->isPolicyDelegatePermissive())
return WKBundlePagePolicyActionUse;
return WKBundlePagePolicyActionPassThrough;
}
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForNewWindowAction(WKBundlePageRef, WKBundleFrameRef, WKBundleNavigationActionRef, WKURLRequestRef, WKStringRef, WKTypeRef*)
{
return WKBundlePagePolicyActionUse;
}
WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForResponse(WKBundlePageRef page, WKBundleFrameRef, WKURLResponseRef response, WKURLRequestRef, WKTypeRef*)
{
if (WKURLResponseIsAttachment(response)) {
StringBuilder stringBuilder;
WKRetainPtr<WKStringRef> filename = adoptWK(WKURLResponseCopySuggestedFilename(response));
stringBuilder.appendLiteral("Policy delegate: resource is an attachment, suggested file name \'");
stringBuilder.append(toWTFString(filename));
stringBuilder.appendLiteral("\'\n");
InjectedBundle::shared().outputText(stringBuilder.toString());
}
WKRetainPtr<WKStringRef> mimeType = adoptWK(WKURLResponseCopyMIMEType(response));
return WKBundlePageCanShowMIMEType(page, mimeType.get()) ? WKBundlePagePolicyActionUse : WKBundlePagePolicyActionPassThrough;
}
void InjectedBundlePage::unableToImplementPolicy(WKBundlePageRef, WKBundleFrameRef, WKErrorRef, WKTypeRef*)
{
}
// UI Client Callbacks
void InjectedBundlePage::willAddMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willAddMessageToConsole(message, lineNumber);
}
void InjectedBundlePage::willSetStatusbarText(WKBundlePageRef page, WKStringRef statusbarText, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willSetStatusbarText(statusbarText);
}
void InjectedBundlePage::willRunJavaScriptAlert(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptAlert(message, frame);
}
void InjectedBundlePage::willRunJavaScriptConfirm(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptConfirm(message, frame);
}
void InjectedBundlePage::willRunJavaScriptPrompt(WKBundlePageRef page, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void *clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willRunJavaScriptPrompt(message, defaultValue, frame);
}
void InjectedBundlePage::didReachApplicationCacheOriginQuota(WKBundlePageRef page, WKSecurityOriginRef origin, int64_t totalBytesNeeded, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didReachApplicationCacheOriginQuota(origin, totalBytesNeeded);
}
uint64_t InjectedBundlePage::didExceedDatabaseQuota(WKBundlePageRef page, WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didExceedDatabaseQuota(origin, databaseName, databaseDisplayName, currentQuotaBytes, currentOriginUsageBytes, currentDatabaseUsageBytes, expectedUsageBytes);
}
static WTF::String lastFileURLPathComponent(const WTF::String& path)
{
size_t pos = path.find("file://");
ASSERT(WTF::notFound != pos);
WTF::String tmpPath = path.substring(pos + 7);
if (tmpPath.length() < 2) // Keep the lone slash to avoid empty output.
return tmpPath;
// Remove the trailing delimiter
if (tmpPath[tmpPath.length() - 1] == '/')
tmpPath.remove(tmpPath.length() - 1);
pos = tmpPath.reverseFind('/');
if (WTF::notFound != pos)
return tmpPath.substring(pos + 1);
return tmpPath;
}
void InjectedBundlePage::willAddMessageToConsole(WKStringRef message, uint32_t lineNumber)
{
if (!InjectedBundle::shared().isTestRunning())
return;
WTF::String messageString = toWTFString(message);
size_t nullCharPos = messageString.find(UChar(0));
if (nullCharPos != WTF::notFound)
messageString.truncate(nullCharPos);
size_t fileProtocolStart = messageString.find("file://");
if (fileProtocolStart != WTF::notFound)
// FIXME: The code below does not handle additional text after url nor multiple urls. This matches DumpRenderTree implementation.
messageString = messageString.substring(0, fileProtocolStart) + lastFileURLPathComponent(messageString.substring(fileProtocolStart));
StringBuilder stringBuilder;
stringBuilder.appendLiteral("CONSOLE MESSAGE: ");
if (lineNumber) {
stringBuilder.appendLiteral("line ");
stringBuilder.appendNumber(lineNumber);
stringBuilder.appendLiteral(": ");
}
stringBuilder.append(messageString);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::willSetStatusbarText(WKStringRef statusbarText)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpStatusCallbacks())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("UI DELEGATE STATUS CALLBACK: setStatusText:");
stringBuilder.append(toWTFString(statusbarText));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::willRunJavaScriptAlert(WKStringRef message, WKBundleFrameRef)
{
if (!InjectedBundle::shared().isTestRunning())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("ALERT: ");
stringBuilder.append(toWTFString(message));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef)
{
if (!InjectedBundle::shared().isTestRunning())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("CONFIRM: ");
stringBuilder.append(toWTFString(message));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef)
{
StringBuilder stringBuilder;
stringBuilder.appendLiteral("PROMPT: ");
stringBuilder.append(toWTFString(message));
stringBuilder.appendLiteral(", default text: ");
stringBuilder.append(toWTFString(defaultValue));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didReachApplicationCacheOriginQuota(WKSecurityOriginRef origin, int64_t totalBytesNeeded)
{
if (InjectedBundle::shared().testRunner()->shouldDumpApplicationCacheDelegateCallbacks()) {
// For example, numbers from 30000 - 39999 will output as 30000.
// Rounding up or down does not really matter for these tests. It's
// sufficient to just get a range of 10000 to determine if we were
// above or below a threshold.
int64_t truncatedSpaceNeeded = (totalBytesNeeded / 10000) * 10000;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("UI DELEGATE APPLICATION CACHE CALLBACK: exceededApplicationCacheOriginQuotaForSecurityOrigin:");
stringBuilder.append(securityOriginToStr(origin));
stringBuilder.appendLiteral(" totalSpaceNeeded:~");
stringBuilder.appendNumber(truncatedSpaceNeeded);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
if (InjectedBundle::shared().testRunner()->shouldDisallowIncreaseForApplicationCacheQuota())
return;
// Reset default application cache quota.
WKBundleResetApplicationCacheOriginQuota(InjectedBundle::shared().bundle(), adoptWK(WKSecurityOriginCopyToString(origin)).get());
}
uint64_t InjectedBundlePage::didExceedDatabaseQuota(WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes)
{
if (InjectedBundle::shared().testRunner()->shouldDumpDatabaseCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:");
stringBuilder.append(securityOriginToStr(origin));
stringBuilder.appendLiteral(" database:");
stringBuilder.append(toWTFString(databaseName));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
uint64_t defaultQuota = 5 * 1024 * 1024;
double testDefaultQuota = InjectedBundle::shared().testRunner()->databaseDefaultQuota();
if (testDefaultQuota >= 0)
defaultQuota = testDefaultQuota;
unsigned long long newQuota = defaultQuota;
double maxQuota = InjectedBundle::shared().testRunner()->databaseMaxQuota();
if (maxQuota >= 0) {
if (defaultQuota < expectedUsageBytes && expectedUsageBytes <= maxQuota) {
newQuota = expectedUsageBytes;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("UI DELEGATE DATABASE CALLBACK: increased quota to ");
stringBuilder.appendNumber(newQuota);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
}
return newQuota;
}
// Editor Client Callbacks
bool InjectedBundlePage::shouldBeginEditing(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldBeginEditing(range);
}
bool InjectedBundlePage::shouldEndEditing(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldEndEditing(range);
}
bool InjectedBundlePage::shouldInsertNode(WKBundlePageRef page, WKBundleNodeHandleRef node, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldInsertNode(node, rangeToReplace, action);
}
bool InjectedBundlePage::shouldInsertText(WKBundlePageRef page, WKStringRef text, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldInsertText(text, rangeToReplace, action);
}
bool InjectedBundlePage::shouldDeleteRange(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldDeleteRange(range);
}
bool InjectedBundlePage::shouldChangeSelectedRange(WKBundlePageRef page, WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType affinity, bool stillSelecting, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldChangeSelectedRange(fromRange, toRange, affinity, stillSelecting);
}
bool InjectedBundlePage::shouldApplyStyle(WKBundlePageRef page, WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range, const void* clientInfo)
{
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldApplyStyle(style, range);
}
void InjectedBundlePage::didBeginEditing(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didBeginEditing(notificationName);
}
void InjectedBundlePage::didEndEditing(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didEndEditing(notificationName);
}
void InjectedBundlePage::didChange(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didChange(notificationName);
}
void InjectedBundlePage::didChangeSelection(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo)
{
static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didChangeSelection(notificationName);
}
bool InjectedBundlePage::shouldBeginEditing(WKBundleRangeHandleRef range)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldBeginEditingInDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), range));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldEndEditing(WKBundleRangeHandleRef range)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldEndEditingInDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), range));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldInsertNode(WKBundleNodeHandleRef node, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
static const char* insertactionstring[] = {
"WebViewInsertActionTyped",
"WebViewInsertActionPasted",
"WebViewInsertActionDropped",
};
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldInsertNode:");
stringBuilder.append(dumpPath(m_page, m_world.get(), node));
stringBuilder.appendLiteral(" replacingDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), rangeToReplace));
stringBuilder.appendLiteral(" givenAction:");
stringBuilder.append(insertactionstring[action]);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldInsertText(WKStringRef text, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
static const char *insertactionstring[] = {
"WebViewInsertActionTyped",
"WebViewInsertActionPasted",
"WebViewInsertActionDropped",
};
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldInsertText:");
stringBuilder.append(toWTFString(text));
stringBuilder.appendLiteral(" replacingDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), rangeToReplace));
stringBuilder.appendLiteral(" givenAction:");
stringBuilder.append(insertactionstring[action]);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldDeleteRange(WKBundleRangeHandleRef range)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldDeleteDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), range));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldChangeSelectedRange(WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType affinity, bool stillSelecting)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
static const char *affinitystring[] = {
"NSSelectionAffinityUpstream",
"NSSelectionAffinityDownstream"
};
static const char *boolstring[] = {
"FALSE",
"TRUE"
};
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldChangeSelectedDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), fromRange));
stringBuilder.appendLiteral(" toDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), toRange));
stringBuilder.appendLiteral(" affinity:");
stringBuilder.append(affinitystring[affinity]);
stringBuilder.appendLiteral(" stillSelecting:");
stringBuilder.append(boolstring[stillSelecting]);
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
bool InjectedBundlePage::shouldApplyStyle(WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range)
{
if (!InjectedBundle::shared().isTestRunning())
return true;
if (InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: shouldApplyStyle:");
stringBuilder.append(styleDecToStr(style));
stringBuilder.appendLiteral(" toElementsInDOMRange:");
stringBuilder.append(rangeToStr(m_page, m_world.get(), range));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
return InjectedBundle::shared().testRunner()->shouldAllowEditing();
}
void InjectedBundlePage::didBeginEditing(WKStringRef notificationName)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidBeginEditing:");
stringBuilder.append(toWTFString(notificationName));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didEndEditing(WKStringRef notificationName)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidEndEditing:");
stringBuilder.append(toWTFString(notificationName));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didChange(WKStringRef notificationName)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidChange:");
stringBuilder.append(toWTFString(notificationName));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
void InjectedBundlePage::didChangeSelection(WKStringRef notificationName)
{
if (!InjectedBundle::shared().isTestRunning())
return;
if (!InjectedBundle::shared().testRunner()->shouldDumpEditingCallbacks())
return;
StringBuilder stringBuilder;
stringBuilder.appendLiteral("EDITING DELEGATE: webViewDidChangeSelection:");
stringBuilder.append(toWTFString(notificationName));
stringBuilder.append('\n');
InjectedBundle::shared().outputText(stringBuilder.toString());
}
#if ENABLE(FULLSCREEN_API)
bool InjectedBundlePage::supportsFullScreen(WKBundlePageRef pageRef, WKFullScreenKeyboardRequestType requestType)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("supportsFullScreen() == true\n");
return true;
}
void InjectedBundlePage::enterFullScreenForElement(WKBundlePageRef pageRef, WKBundleNodeHandleRef elementRef)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("enterFullScreenForElement()\n");
if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) {
WKBundlePageWillEnterFullScreen(pageRef);
WKBundlePageDidEnterFullScreen(pageRef);
}
}
void InjectedBundlePage::exitFullScreenForElement(WKBundlePageRef pageRef, WKBundleNodeHandleRef elementRef)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("exitFullScreenForElement()\n");
if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) {
WKBundlePageWillExitFullScreen(pageRef);
WKBundlePageDidExitFullScreen(pageRef);
}
}
void InjectedBundlePage::beganEnterFullScreen(WKBundlePageRef, WKRect, WKRect)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("beganEnterFullScreen()\n");
}
void InjectedBundlePage::beganExitFullScreen(WKBundlePageRef, WKRect, WKRect)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("beganExitFullScreen()\n");
}
void InjectedBundlePage::closeFullScreen(WKBundlePageRef pageRef)
{
if (InjectedBundle::shared().testRunner()->shouldDumpFullScreenCallbacks())
InjectedBundle::shared().outputText("closeFullScreen()\n");
if (!InjectedBundle::shared().testRunner()->hasCustomFullScreenBehavior()) {
WKBundlePageWillExitFullScreen(pageRef);
WKBundlePageDidExitFullScreen(pageRef);
}
}
#endif
static bool compareByTargetName(WKBundleBackForwardListItemRef item1, WKBundleBackForwardListItemRef item2)
{
return toSTD(adoptWK(WKBundleBackForwardListItemCopyTarget(item1))) < toSTD(adoptWK(WKBundleBackForwardListItemCopyTarget(item2)));
}
static void dumpBackForwardListItem(WKBundleBackForwardListItemRef item, unsigned indent, bool isCurrentItem, StringBuilder& stringBuilder)
{
unsigned column = 0;
if (isCurrentItem) {
stringBuilder.appendLiteral("curr->");
column = 6;
}
for (unsigned i = column; i < indent; i++)
stringBuilder.append(' ');
WTF::String url = toWTFString(adoptWK(WKURLCopyString(adoptWK(WKBundleBackForwardListItemCopyURL(item)).get())));
if (hasPrefix(url, "file:")) {
WTF::String directoryName = "/LayoutTests/";
size_t start = url.find(directoryName);
if (start == WTF::notFound)
start = 0;
else
start += directoryName.length();
stringBuilder.appendLiteral("(file test):");
stringBuilder.append(url.substring(start));
} else
stringBuilder.append(url);
WTF::String target = toWTFString(adoptWK(WKBundleBackForwardListItemCopyTarget(item)));
if (target.length()) {
stringBuilder.appendLiteral(" (in frame \"");
stringBuilder.append(target);
stringBuilder.appendLiteral("\")");
}
// FIXME: Need WKBackForwardListItemIsTargetItem.
if (WKBundleBackForwardListItemIsTargetItem(item))
stringBuilder.appendLiteral(" **nav target**");
stringBuilder.append('\n');
if (WKRetainPtr<WKArrayRef> kids = adoptWK(WKBundleBackForwardListItemCopyChildren(item))) {
// Sort to eliminate arbitrary result ordering which defeats reproducible testing.
size_t size = WKArrayGetSize(kids.get());
Vector<WKBundleBackForwardListItemRef> sortedKids(size);
for (size_t i = 0; i < size; ++i)
sortedKids[i] = static_cast<WKBundleBackForwardListItemRef>(WKArrayGetItemAtIndex(kids.get(), i));
stable_sort(sortedKids.begin(), sortedKids.end(), compareByTargetName);
for (size_t i = 0; i < size; ++i)
dumpBackForwardListItem(sortedKids[i], indent + 4, false, stringBuilder);
}
}
void InjectedBundlePage::dumpBackForwardList(StringBuilder& stringBuilder)
{
stringBuilder.appendLiteral("\n============== Back Forward List ==============\n");
WKBundleBackForwardListRef list = WKBundlePageGetBackForwardList(m_page);
// Print out all items in the list after m_previousTestBackForwardListItem.
// Gather items from the end of the list, then print them out from oldest to newest.
Vector<WKRetainPtr<WKBundleBackForwardListItemRef> > itemsToPrint;
for (unsigned i = WKBundleBackForwardListGetForwardListCount(list); i; --i) {
WKRetainPtr<WKBundleBackForwardListItemRef> item = adoptWK(WKBundleBackForwardListCopyItemAtIndex(list, i));
// Something is wrong if the item from the last test is in the forward part of the list.
ASSERT(!WKBundleBackForwardListItemIsSame(item.get(), m_previousTestBackForwardListItem.get()));
itemsToPrint.append(item);
}
ASSERT(!WKBundleBackForwardListItemIsSame(adoptWK(WKBundleBackForwardListCopyItemAtIndex(list, 0)).get(), m_previousTestBackForwardListItem.get()));
itemsToPrint.append(adoptWK(WKBundleBackForwardListCopyItemAtIndex(list, 0)));
int currentItemIndex = itemsToPrint.size() - 1;
int backListCount = WKBundleBackForwardListGetBackListCount(list);
for (int i = -1; i >= -backListCount; --i) {
WKRetainPtr<WKBundleBackForwardListItemRef> item = adoptWK(WKBundleBackForwardListCopyItemAtIndex(list, i));
if (WKBundleBackForwardListItemIsSame(item.get(), m_previousTestBackForwardListItem.get()))
break;
itemsToPrint.append(item);
}
for (int i = itemsToPrint.size() - 1; i >= 0; i--)
dumpBackForwardListItem(itemsToPrint[i].get(), 8, i == currentItemIndex, stringBuilder);
stringBuilder.appendLiteral("===============================================\n");
}
#if !PLATFORM(MAC)
void InjectedBundlePage::platformDidStartProvisionalLoadForFrame(WKBundleFrameRef)
{
}
#endif
void InjectedBundlePage::frameDidChangeLocation(WKBundleFrameRef frame, bool shouldDump)
{
if (frame != InjectedBundle::shared().topLoadingFrame())
return;
InjectedBundle::shared().setTopLoadingFrame(0);
if (InjectedBundle::shared().testRunner()->waitToDump())
return;
if (InjectedBundle::shared().shouldProcessWorkQueue()) {
InjectedBundle::shared().processWorkQueue();
return;
}
if (shouldDump)
InjectedBundle::shared().page()->dump();
else
InjectedBundle::shared().done();
}
} // namespace WTR
|