1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
//! Low Level Bindings for WebView2 SDK.
#![cfg(windows)]
#![allow(clippy::missing_safety_doc, non_snake_case)]

// Generated by idl2rs.

use com::{
    com_interface,
    interfaces::{iunknown::IUnknownVTable, IUnknown},
};
use std::ffi::c_void;
use winapi::shared::basetsd::*;
use winapi::shared::minwindef::{ULONG, *};
use winapi::shared::ntdef::*;
use winapi::shared::windef::*;
use winapi::um::oaidl::VARIANT;
use winapi::um::objidlbase::STATSTG;

/// Represents a reference to a delegate that receives change notifications.
#[repr(C)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub struct EventRegistrationToken {
    value: i64,
}

#[com_interface("0c733a30-2a1c-11ce-ade5-00aa0044773d")]
pub trait ISequentialStream: IUnknown {
    unsafe fn read(&self, pv: *mut c_void, cb: ULONG, pcbRead: *mut ULONG) -> HRESULT;
    unsafe fn write(&self, pv: *const c_void, cb: ULONG, pcbWritten: *mut ULONG) -> HRESULT;
}

#[com_interface("0000000c-0000-0000-C000-000000000046")]
pub trait IStream: ISequentialStream {
    unsafe fn seek(
        &self,
        dlibMove: LARGE_INTEGER,
        dwOrigin: DWORD,
        plibNewPosition: *mut ULARGE_INTEGER,
    ) -> HRESULT;
    unsafe fn set_size(&self, libNewSize: ULARGE_INTEGER) -> HRESULT;
    unsafe fn copy_to(
        &self,
        pstm: *mut *mut IStreamVTable,
        cb: ULARGE_INTEGER,
        pcbRead: *mut ULARGE_INTEGER,
        pcbWritten: *mut ULARGE_INTEGER,
    ) -> HRESULT;
    unsafe fn commit(&self, grfCommitFlags: DWORD) -> HRESULT;
    unsafe fn revert(&self) -> HRESULT;
    unsafe fn lock_region(
        &self,
        libOffset: ULARGE_INTEGER,
        cb: ULARGE_INTEGER,
        dwLockType: DWORD,
    ) -> HRESULT;
    unsafe fn unlock_region(
        &self,
        libOffset: ULARGE_INTEGER,
        cb: ULARGE_INTEGER,
        dwLockType: DWORD,
    ) -> HRESULT;
    unsafe fn stat(&self, pstatstg: *mut STATSTG, grfStatFlag: DWORD) -> HRESULT;
    unsafe fn clone(&self, ppstm: *mut *mut *mut IStreamVTable) -> HRESULT;
}

/// DLL export to create a WebView2 environment with a custom version of Edge,
/// user data directory and/or additional options.
///
/// browserExecutableFolder is the relative path to the folder that
/// contains the embedded Edge. The embedded Edge can be obtained by
/// copying the version named folder of an installed Edge, like
/// 73.0.52.0 sub folder of an installed 73.0.52.0 Edge. The folder
/// should have msedge.exe, msedge.dll, and so on.
/// Use null or empty string for browserExecutableFolder to create
/// WebView using Edge installed on the machine, in which case the
/// API will try to find a compatible version of Edge installed on the
/// machine according to the channel preference trying to find first
/// per user install and then per machine install.
///
/// The default channel search order is stable, beta, dev, and canary.
/// When there is an override WEBVIEW2_RELEASE_CHANNEL_PREFERENCE environment
/// variable or applicable releaseChannelPreference registry value
/// with the value of 1, the channel search order is reversed.
///
/// userDataFolder can be
/// specified to change the default user data folder location for
/// WebView2. The path can be an absolute file path or a relative file path
/// that is interpreted as relative to the current process's executable.
/// Otherwise, for UWP apps, the default user data folder will be
/// the app data folder for the package; for non-UWP apps,
/// the default user data folder `{Executable File Name}.WebView2`
/// will be created in the same directory next to the app executable.
/// WebView2 creation can fail if the executable is running in a directory
/// that the process doesn't have permission to create a new folder in.
/// The app is responsible to clean up its user data folder
/// when it is done.
///
/// Note that as a browser process might be shared among WebViews,
/// WebView creation will fail with HRESULT_FROM_WIN32(ERROR_INVALID_STATE) if
/// the specified options does not match the options of the WebViews that are
/// currently running in the shared browser process.
///
/// environment_created_handler is the handler result to the async operation
/// which will contain the WebView2Environment that got created.
///
/// The browserExecutableFolder, userDataFolder and additionalBrowserArguments
/// of the environmentOptions may be overridden by
/// values either specified in environment variables or in the registry.
///
/// When creating a WebView2Environment the following environment variables
/// are checked:
///
/// ```
/// WEBVIEW2_BROWSER_EXECUTABLE_FOLDER
/// WEBVIEW2_USER_DATA_FOLDER
/// WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS
/// WEBVIEW2_RELEASE_CHANNEL_PREFERENCE
/// ```
///
/// If an override environment variable is found then we use the
/// browserExecutableFolder, userDataFolder and additionalBrowserArguments
/// values as replacements for the corresponding values in
/// CreateCoreWebView2EnvironmentWithOptions parameters.
///
/// While not strictly overrides, there exists additional environment variables
/// that can be set:
///
/// ```
/// WEBVIEW2_WAIT_FOR_SCRIPT_DEBUGGER
/// ```
///
/// When found with a non-empty value, this indicates that the WebView is being
/// launched under a script debugger. In this case, the WebView will issue a
/// `Page.waitForDebugger` CDP command that will cause script execution inside the
/// WebView to pause on launch, until a debugger issues a corresponding
/// `Runtime.runIfWaitingForDebugger` CDP command to resume execution.
/// Note: There is no registry key equivalent of this environment variable.
///
/// ```
/// WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER
/// ```
///
/// When found with a non-empty value, this indicates that the WebView is being
/// launched under a script debugger that also supports host applications that
/// use multiple WebViews. The value is used as the identifier for a named pipe
/// that will be opened and written to when a new WebView is created by the host
/// application. The payload will match that of the remote-debugging-port JSON
/// target and can be used by the external debugger to attach to a specific
/// WebView instance.
/// The format of the pipe created by the debugger should be:
/// `\\.\pipe\WebView2\Debugger\{app_name}\{pipe_name}`
/// where:
///
/// - `{app_name}` is the host application exe filename, e.g. WebView2Example.exe
/// - `{pipe_name}` is the value set for WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER.
///
/// To enable debugging of the targets identified by the JSON you will also need
/// to set the WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variable to
/// send `--remote-debugging-port={port_num}`
/// where:
///
/// - `{port_num}` is the port on which the CDP server will bind.
///
/// Be aware that setting both the WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER and
/// WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variables will cause the
/// WebViews hosted in your application and their contents to be exposed to
/// 3rd party applications such as debuggers.
///
/// Note: There is no registry key equivalent of this environment variable.
///
/// If none of those environment variables exist, then the registry is examined next.
/// The following registry keys are checked:
///
/// ```
/// [{Root}\Software\Policies\Microsoft\EmbeddedBrowserWebView\LoaderOverride\{AppId}]
/// "releaseChannelPreference"=dword:00000000
/// "browserExecutableFolder"=""
/// "userDataFolder"=""
/// "additionalBrowserArguments"=""
/// ```
///
/// In the unlikely scenario where some instances of WebView are open during
/// a browser update we could end up blocking the deletion of old Edge browsers.
/// To avoid running out of disk space a new WebView creation will fail
/// with the next error if it detects that there are many old versions present.
///
/// ```
/// ERROR_DISK_FULL
/// ```
///
/// The default maximum number of Edge versions allowed is 20.
///
/// The maximum number of old Edge versions allowed can be overwritten with the value
/// of the following environment variable.
///
/// ```
/// WEBVIEW2_MAX_INSTANCES
/// ```
///
/// If the Webview depends on an installed Edge and it is uninstalled
/// any subsequent creation will fail with the next error
///
/// ```
/// ERROR_PRODUCT_UNINSTALLED
/// ```
///
/// First we check with Root as HKLM and then HKCU.
/// AppId is first set to the Application User Model ID of the caller's process,
/// then if there's no corresponding registry key the AppId is
/// set to the executable name of the caller's process, or if that
/// isn't a registry key then '*'. If an override registry key is found then we
/// use the browserExecutableFolder, userDataFolder and additionalBrowserArguments
/// registry values as replacements for the corresponding values in
/// CreateCoreWebView2EnvironmentWithOptions parameters.
pub type FnCreateCoreWebView2EnvironmentWithOptions = unsafe extern "stdcall" fn(browserExecutableFolder: PCWSTR, userDataFolder: PCWSTR, environment_options: *mut *mut ICoreWebView2EnvironmentOptionsVTable, environment_created_handler: *mut *mut ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVTable) -> HRESULT;

/// Get the browser version info including channel name if it is not the stable channel
/// or the Embedded Edge.
/// Channel names are beta, dev, and canary.
/// If an override exists for the browserExecutableFolder or the channel preference,
/// the override will be used.
/// If there isn't an override, then the parameter passed to
/// GetAvailableCoreWebView2BrowserVersionString is used.
pub type FnGetAvailableCoreWebView2BrowserVersionString = unsafe extern "stdcall" fn(
    browser_executable_folder: PCWSTR,
    version_info: *mut LPWSTR,
) -> HRESULT;

/// This method is for anyone want to compare version correctly to determine
/// which version is newer, older or same. It can be used to determine whether
/// to use webview2 or certain feature base on version.
/// Sets the value of result to -1, 0 or 1 if version1 is less than, equal or
/// greater than version2 respectively.
/// Returns E_INVALIDARG if it fails to parse any of the version strings or any
/// input parameter is null.
/// Input can directly use the versionInfo obtained from
/// GetAvailableCoreWebView2BrowserVersionString, channel info will be ignored.
pub type FnCompareBrowserVersions =
    unsafe extern "stdcall" fn(version1: PCWSTR, version2: PCWSTR, result: *mut i32) -> HRESULT;
/// A structure representing the information packed into the LPARAM given
/// to a Win32 key event.  See the documentation for WM_KEYDOWN for details
/// at https://docs.microsoft.com/windows/win32/inputdev/wm-keydown
#[repr(C)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct PhysicalKeyStatus {
    /// The repeat count for the current message.
    pub repeat_count: UINT32,
    /// The scan code.
    pub scan_code: UINT32,
    /// Indicates whether the key is an extended key.
    pub is_extended_key: BOOL,
    /// The context code.
    pub is_menu_key_down: BOOL,
    /// The previous key state.
    pub was_key_down: BOOL,
    /// The transition state.
    pub is_key_released: BOOL,
}

/// Image format used by the ICoreWebView2::CapturePreview method.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum CapturePreviewImageFormat {
    /// PNG image format.
    PNG,
    /// JPEG image format.
    JPEG,
}

/// Kind of JavaScript dialog used in the ICoreWebView2ScriptDialogOpeningEventHandler
/// interface.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ScriptDialogKind {
    /// A dialog invoked via the window.alert JavaScript function.
    Alert,
    /// A dialog invoked via the window.confirm JavaScript function.
    Confirm,
    /// A dialog invoked via the window.prompt JavaScript function.
    Prompt,
    /// A dialog invoked via the beforeunload JavaScript event.
    Beforeunload,
}

/// Kind of process failure used in the ICoreWebView2ProcessFailedEventHandler interface.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ProcessFailedKind {
    /// Indicates the browser process terminated unexpectedly.
    /// The WebView automatically goes into the Closed state.
    /// The app has to recreate a new WebView to recover from this failure.
    BrowserProcessExited,
    /// Indicates the render process terminated unexpectedly.
    /// A new render process will be created automatically and navigated to an
    /// error page.
    /// The app can use Reload to try to recover from this failure.
    RenderProcessExited,
    /// Indicates the render process becomes unresponsive.
    /// The app can try to navigate away from the page to recover from the
    /// failure.
    RenderProcessUnresponsive,
}

/// The type of a permission request.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum PermissionKind {
    /// Unknown permission.
    UnknownPermission,
    /// Permission to capture audio.
    Microphone,
    /// Permission to capture video.
    Camera,
    /// Permission to access geolocation.
    Geolocation,
    /// Permission to send web notifications.
    /// This permission request is currently auto rejected and
    /// no event is fired for it.
    Notifications,
    /// Permission to access generic sensor.
    /// Generic Sensor covering ambient-light-sensor, accelerometer, gyroscope
    /// and magnetometer.
    OtherSensors,
    /// Permission to read system clipboard without a user gesture.
    ClipboardRead,
}

/// Response to a permission request.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum PermissionState {
    /// Use default browser behavior, which normally prompt users for decision.
    Default,
    /// Grant the permission request.
    Allow,
    /// Deny the permission request.
    Deny,
}

/// Error status values for web navigations.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum WebErrorStatus {
    /// An unknown error occurred.
    Unknown,
    /// The SSL certificate common name does not match the web address.
    CertificateCommonNameIsIncorrect,
    /// The SSL certificate has expired.
    CertificateExpired,
    /// The SSL client certificate contains errors.
    ClientCertificateContainsErrors,
    /// The SSL certificate has been revoked.
    CertificateRevoked,
    /// The SSL certificate is invalid -- this could mean the certificate did not
    /// match the public key pins for the host name, the certificate is signed
    /// by an untrusted authority or using a weak sign algorithm, the
    /// certificate claimed DNS names violate name constraints, the certificate
    /// contains a weak key, the certificate's validity period is too long, lack
    /// of revocation information or revocation mechanism, non-unique host name,
    /// lack of certificate transparency information, or the certificate is
    /// chained to a [legacy Symantec
    /// root](https://security.googleblog.com/2018/03/distrust-of-symantec-pki-immediate.html).
    CertificateIsInvalid,
    /// The host is unreachable.
    ServerUnreachable,
    /// The connection has timed out.
    Timeout,
    /// The server returned an invalid or unrecognized response.
    ErrorHttpInvalidServerResponse,
    /// The connection was aborted.
    ConnectionAborted,
    /// The connection was reset.
    ConnectionReset,
    /// The Internet connection has been lost.
    Disconnected,
    /// Cannot connect to destination.
    CannotConnect,
    /// Could not resolve provided host name.
    HostNameNotResolved,
    /// The operation was canceled.
    OperationCanceled,
    /// The request redirect failed.
    RedirectFailed,
    /// An unexpected error occurred.
    UnexpectedError,
}

/// Enum for web resource request contexts.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum WebResourceContext {
    /// All resources
    All,
    /// Document resources
    Document,
    /// CSS resources
    Stylesheet,
    /// Image resources
    Image,
    /// Other media resources such as videos
    Media,
    /// Font resources
    Font,
    /// Script resources
    Script,
    /// XML HTTP requests
    XmlHttpRequest,
    /// Fetch API communication
    Fetch,
    /// TextTrack resources
    TextTrack,
    /// EventSource API communication
    EventSource,
    /// WebSocket API communication
    Websocket,
    /// Web App Manifests
    Manifest,
    /// Signed HTTP Exchanges
    SignedExchange,
    /// Ping requests
    Ping,
    /// CSP Violation Reports
    CspViolationReport,
    /// Other resources
    Other,
}

/// Reason for moving focus.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum MoveFocusReason {
    /// Code setting focus into WebView.
    Programmatic,
    /// Moving focus due to Tab traversal forward.
    Next,
    /// Moving focus due to Tab traversal backward.
    Previous,
}

/// The type of key event that triggered an AcceleratorKeyPressed event.
#[repr(u32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum KeyEventKind {
    /// Correspond to window message WM_KEYDOWN.
    KeyDown,
    /// Correspond to window message WM_KEYUP.
    KeyUp,
    /// Correspond to window message WM_SYSKEYDOWN.
    SystemKeyDown,
    /// Correspond to window message WM_SYSKEYUP.
    SystemKeyUp,
}

/// WebView2 enables you to host web content using the
/// latest Edge web browser technology.
///
/// ## Navigation events
/// The normal sequence of navigation events is NavigationStarting,
/// SourceChanged, ContentLoading and then NavigationCompleted.
/// The following events describe the state of WebView during each navigation:
/// NavigationStarting: WebView is starting to navigate and the navigation will
/// result in a network request. The host can disallow the request at this time.
/// SourceChanged: The source of WebView is changed to a new URL. This may also
/// be due to a navigation that doesn't cause a network request such as a fragment
/// navigation.
/// HistoryChanged: WebView's history has been updated as a result of
/// the navigation.
/// ContentLoading: WebView has started loading new content.
/// NavigationCompleted: WebView has completed loading content on the new page.
/// Developers can track navigations to each new document by the navigation ID.
/// WebView's navigation ID changes every time there is a successful navigation
/// to a new document.
///
///
/// \dot
/// digraph NavigationEvents {
///    node [fontname=Roboto, shape=rectangle]
///    edge [fontname=Roboto]
///
///    NewDocument -> NavigationStarting;
///    NavigationStarting -> SourceChanged -> ContentLoading [label="New Document"];
///    ContentLoading -> HistoryChanged;
///    SameDocument -> SourceChanged;
///    SourceChanged -> HistoryChanged [label="Same Document"];
///    HistoryChanged -> NavigationCompleted;
///    NavigationStarting -> NavigationStarting [label="Redirect"];
///    NavigationStarting -> NavigationCompleted [label="Failure"];
/// }
/// \enddot
///
/// Note that this is for navigation events with the same NavigationId event
/// arg. Navigations events with different NavigationId event args may overlap.
/// For instance, if you start a navigation wait for its NavigationStarting
/// event and then start another navigation you'll see the NavigationStarting
/// for the first navigate followed by the NavigationStarting of the second
/// navigate, followed by the NavigationCompleted for the first navigation and
/// then all the rest of the appropriate navigation events for the second
/// navigation.
/// In error cases there may or may not be a ContentLoading event depending
/// on whether the navigation is continued to an error page.
/// In case of an HTTP redirect, there will be multiple NavigationStarting
/// events in a row, with ones following the first will have their IsRedirect
/// flag set, however navigation ID remains the same. Same document navigations
/// do not result in NavigationStarting event and also do not increment the
/// navigation ID.
///
/// To monitor or cancel navigations inside subframes in the WebView, use
/// FrameNavigationStarting.
///
/// ## Process model
/// WebView2 uses the same process model as the Edge web
/// browser. There is one Edge browser process per specified user data directory
/// in a user session that will serve any WebView2 calling
/// process that specifies that user data directory. This means one Edge browser
/// process may be serving multiple calling processes and one calling
/// process may be using multiple Edge browser processes.
///
/// \dot
/// digraph ProcessModelNClientsNServers {
///     node [fontname=Roboto, shape=rectangle];
///     edge [fontname=Roboto];
///
///     Host1 [label="Calling\nprocess 1"];
///     Host2 [label="Calling\nprocess 2"];
///     Browser1 [label="Edge processes\ngroup 1"];
///     Browser2 [label="Edge processes\ngroup 2"];
///
///     Host1 -> Browser1;
///     Host1 -> Browser2;
///     Host2 -> Browser2;
/// }
/// \enddot
///
/// Off of a browser process there will be some number of renderer processes.
/// These are created as
/// necessary to service potentially multiple frames in different WebViews. The
/// number of renderer processes varies based on the site isolation browser
/// feature and the number of distinct disconnected origins rendered in
/// associated WebViews.
///
/// \dot
/// digraph ProcessModelClientServer {
///     node [fontname=Roboto, shape=rectangle];
///     edge [fontname=Roboto];
///     graph [fontname=Roboto];
///
///     Host [label="Calling process"];
///     subgraph cluster_0 {
///         labeljust = "l";
///         label = "Edge processes group";
///         Browser [label="Edge browser\nprocess"];
///         Render1 [label="Edge render\nprocess 1"];
///         Render2 [label="Edge render\nprocess 2"];
///         RenderN [label="Edge render\nprocess N"];
///         GPU [label="Edge GPU\nprocess"];
///     }
///
///     Host -> Browser;
///     Browser -> Render1;
///     Browser -> Render2;
///     Browser -> RenderN;
///     Browser -> GPU;
/// }
/// \enddot
///
/// You can react to crashes and hangs in these browser and renderer processes
/// using the ProcessFailure event.
///
/// You can safely shutdown associated browser and renderer processes using the
/// Close method.
///
/// ## Threading model
/// The WebView2 must be created on a UI thread. Specifically a
/// thread with a message pump. All callbacks will occur on that thread and
/// calls into the WebView must be done on that thread. It is not safe to use
/// the WebView from another thread.
///
/// Callbacks including event handlers and completion handlers execute serially.
/// That is, if you have an event handler running and begin a message loop no
/// other event handlers or completion callbacks will begin executing
/// reentrantly.
///
/// ## Security
/// Always check the Source property of the WebView before using ExecuteScript,
/// PostWebMessageAsJson, PostWebMessageAsString, or any other method to send
/// information into the WebView. The WebView may have navigated to another page
/// via the end user interacting with the page or script in the page causing
/// navigation. Similarly, be very careful with
/// AddScriptToExecuteOnDocumentCreated. All future navigations will run this
/// script and if it provides access to information intended only for a certain
/// origin, any HTML document may have access.
///
/// When examining the result of an ExecuteScript method call, a
/// WebMessageReceived event, always check the Source of the sender, or any
/// other mechanism of receiving information from an HTML document in a WebView
/// validate the URI of the HTML document is what you expect.
///
/// When constructing a message to send into a WebView, prefer using
/// PostWebMessageAsJson and construct the JSON string parameter using a JSON
/// library. This will avoid any potential accidents of encoding information
/// into a JSON string or script and ensure no attacker controlled input can
/// modify the rest of the JSON message or run arbitrary script.
///
/// ## String types
/// String out parameters are LPWSTR null terminated strings. The callee
/// allocates the string using CoTaskMemAlloc. Ownership is transferred to the
/// caller and it is up to the caller to free the memory using CoTaskMemFree.
///
/// String in parameters are LPCWSTR null terminated strings. The caller ensures
/// the string is valid for the duration of the synchronous function call.
/// If the callee needs to retain that value to some point after the function
/// call completes, the callee must allocate its own copy of the string value.
///
/// ## URI and JSON parsing
/// Various methods provide or accept URIs and JSON as strings. Please use your
/// own preferred library for parsing and generating these strings.
///
/// If WinRT is available for your app you can use `RuntimeClass_Windows_Data_Json_JsonObject`
/// and `IJsonObjectStatics` to parse or produce JSON strings or `RuntimeClass_Windows_Foundation_Uri`
/// and `IUriRuntimeClassFactory` to parse and produce URIs. Both of these work
/// in Win32 apps.
///
/// If you use IUri and CreateUri to parse URIs you may want to use the
/// following URI creation flags to have CreateUri behavior more closely match
/// the URI parsing in the WebView:
/// `Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME | Uri_CREATE_NO_DECODE_EXTRA_INFO`
///
/// ## Debugging
/// Open DevTools with the normal shortcuts: `F12` or `Ctrl+Shift+I`.
/// You can use the `--auto-open-devtools-for-tabs` command argument switch to
/// have the DevTools window open immediately when first creating a WebView. See
/// CreateCoreWebView2Controller documentation for how to provide additional command
/// line arguments to the browser process.
/// Check out the LoaderOverride registry key for trying out different builds of
/// WebView2 without modifying your application in the CreateCoreWebView2Controller
/// documentation.
///
/// ## Versioning
/// After you've used a particular version of the SDK to build your app, your
/// app may end up running with an older or newer version of installed browser
/// binaries. Until version 1.0.0.0 of WebView2 there may be breaking changes
/// during updates that will prevent your SDK from working with different
/// versions of installed browser binaries. After version 1.0.0.0 different
/// versions of the SDK can work with different versions of the installed
/// browser by following these best practices:
///
/// To account for breaking changes to the API be sure to check for failure when
/// calling the DLL export CreateCoreWebView2Environment and when
/// calling QueryInterface on any CoreWebView2 object. A return value of
/// E_NOINTERFACE can indicate the SDK is not compatible with the Edge
/// browser binaries.
///
/// Checking for failure from QueryInterface will also account for cases where
/// the SDK is newer than the version of the Edge browser and your app attempts
/// to use an interface of which the Edge browser is unaware.
///
/// When an interface is unavailable, you can consider disabling the associated
/// feature if possible, or otherwise informing the end user they need to update
/// their browser.
#[com_interface("189B8AAF-0426-4748-B9AD-243F537EB46B")]
pub trait ICoreWebView2: IUnknown {
    /// The ICoreWebView2Settings object contains various modifiable settings for
    /// the running WebView.
    unsafe fn get_settings(
        &self,
        /* out, retval */ settings: *mut *mut *mut ICoreWebView2SettingsVTable,
    ) -> HRESULT;

    /// The URI of the current top level document. This value potentially
    /// changes as a part of the SourceChanged event firing for some cases
    /// such as navigating to a different site or fragment navigations. It will
    /// remain the same for other types of navigations such as page reloads or
    /// history.pushState with the same URL as the current page.
    ///
    /// \snippet ControlComponent.cpp SourceChanged
    unsafe fn get_source(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// Cause a navigation of the top level document to the specified URI. See
    /// the navigation events for more information. Note that this starts a
    /// navigation and the corresponding NavigationStarting event will fire
    /// sometime after this Navigate call completes.
    ///
    /// \snippet ControlComponent.cpp Navigate
    unsafe fn navigate(&self, /* in */ uri: LPCWSTR) -> HRESULT;

    /// Initiates a navigation to htmlContent as source HTML of a new
    /// document. The htmlContent parameter may not be larger than 2 MB of
    /// characters. The origin of the new page will be about:blank.
    ///
    /// \snippet SettingsComponent.cpp NavigateToString
    unsafe fn navigate_to_string(&self, /* in */ html_content: LPCWSTR) -> HRESULT;

    /// Add an event handler for the NavigationStarting event.
    /// NavigationStarting fires when the WebView main frame is
    /// requesting permission to navigate to a different URI. This will fire for
    /// redirects as well.
    ///
    /// \snippet SettingsComponent.cpp NavigationStarting
    unsafe fn add_navigation_starting(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2NavigationStartingEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_NavigationStarting.
    unsafe fn remove_navigation_starting(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the ContentLoading event.
    /// ContentLoading fires before any content is loaded, including scripts added with
    /// AddScriptToExecuteOnDocumentCreated
    /// ContentLoading will not fire if a same page navigation occurs
    /// (such as through fragment navigations or history.pushState navigations).
    /// This follows the NavigationStarting and SourceChanged events and
    /// precedes the HistoryChanged and NavigationCompleted events.
    unsafe fn add_content_loading(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2ContentLoadingEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_ContentLoading.
    unsafe fn remove_content_loading(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// SourceChanged fires when the Source property changes.
    /// SourceChanged fires for navigating to a different site or fragment navigations.
    /// It will not fires for other types of navigations such as page reloads or
    /// history.pushState with the same URL as the current page.
    /// SourceChanged fires before ContentLoading for navigation to a new document.
    /// Add an event handler for the SourceChanged event.
    /// \snippet ControlComponent.cpp SourceChanged
    unsafe fn add_source_changed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2SourceChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_SourceChanged.
    unsafe fn remove_source_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// HistoryChange listen to the change of navigation history for the top level
    /// document. Use HistoryChange to check if CanGoBack/CanGoForward value
    /// has changed. HistoryChanged also fires for using GoBack/GoForward.
    /// HistoryChanged fires after SourceChanged and ContentLoading.
    /// Add an event handler for the HistoryChanged event.
    /// \snippet ControlComponent.cpp HistoryChanged
    unsafe fn add_history_changed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2HistoryChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_HistoryChanged.
    unsafe fn remove_history_changed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// Add an event handler for the NavigationCompleted event.
    /// NavigationCompleted event fires when the WebView has completely loaded
    /// (body.onload has fired) or loading stopped with error.
    ///
    /// \snippet ControlComponent.cpp NavigationCompleted
    unsafe fn add_navigation_completed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2NavigationCompletedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_NavigationCompleted.
    unsafe fn remove_navigation_completed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the FrameNavigationStarting event.
    /// FrameNavigationStarting fires when a child frame in the WebView
    /// requesting permission to navigate to a different URI. This will fire for
    /// redirects as well.
    ///
    /// \snippet SettingsComponent.cpp FrameNavigationStarting
    unsafe fn add_frame_navigation_starting(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2NavigationStartingEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_FrameNavigationStarting.
    unsafe fn remove_frame_navigation_starting(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the FrameNavigationCompleted event.
    /// FrameNavigationCompleted event fires when a child frame has completely
    /// loaded (body.onload has fired) or loading stopped with error.
    ///
    /// \snippet ControlComponent.cpp FrameNavigationCompleted
    unsafe fn add_frame_navigation_completed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2NavigationCompletedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_FrameNavigationCompleted.
    unsafe fn remove_frame_navigation_completed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the ScriptDialogOpening event.
    /// The event fires when a JavaScript dialog (alert, confirm, or prompt) will
    /// show for the webview. This event only fires if the
    /// ICoreWebView2Settings::AreDefaultScriptDialogsEnabled property is set to
    /// false. The ScriptDialogOpening event can be used to suppress dialogs or
    /// replace default dialogs with custom dialogs.
    ///
    /// \snippet SettingsComponent.cpp ScriptDialogOpening
    unsafe fn add_script_dialog_opening(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2ScriptDialogOpeningEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_ScriptDialogOpening.
    unsafe fn remove_script_dialog_opening(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the PermissionRequested event.
    /// Fires when content in a WebView requests permission to access some
    /// privileged resources.
    ///
    /// \snippet SettingsComponent.cpp PermissionRequested
    unsafe fn add_permission_requested(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2PermissionRequestedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_PermissionRequested.
    unsafe fn remove_permission_requested(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the ProcessFailed event.
    /// Fires when a WebView process terminated unexpectedly or
    /// become unresponsive.
    ///
    /// \snippet ProcessComponent.cpp ProcessFailed
    unsafe fn add_process_failed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2ProcessFailedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_ProcessFailed.
    unsafe fn remove_process_failed(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// Add the provided JavaScript to a list of scripts
    /// that should be executed after the global object has been created, but
    /// before the HTML document has been parsed and before any other script
    /// included by the HTML document is executed. The
    /// injected script will apply to all future top level document and child
    /// frame navigations until removed with RemoveScriptToExecuteOnDocumentCreated.
    /// This is applied asynchronously and you must wait for the completion
    /// handler to run before you can be sure that the script is ready to
    /// execute on future navigations.
    /// The handler's Invoke method will be called when the method asynchronously
    /// completes. Invoke will be called with the id associated with the injected
    /// script as a string.
    ///
    /// Note that if an HTML document has sandboxing of some kind via [sandbox](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox)
    /// properties or the [Content-Security-Policy HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)
    /// this will affect the script run here. So, for example, if the
    /// 'allow-modals' keyword is not set then calls to the `alert` function will
    /// be ignored.
    ///
    /// \snippet ScriptComponent.cpp AddScriptToExecuteOnDocumentCreated
    unsafe fn add_script_to_execute_on_document_created(
        &self,
        /* in */ java_script: LPCWSTR,
        /* in */
        handler: *mut *mut ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandlerVTable,
    ) -> HRESULT;

    /// Remove the corresponding JavaScript added via AddScriptToExecuteOnDocumentCreated
    /// with the specified script id.
    unsafe fn remove_script_to_execute_on_document_created(
        &self,
        /* in */ id: LPCWSTR,
    ) -> HRESULT;

    /// Execute JavaScript code from the javascript parameter in the
    /// current top level document rendered in the WebView. This will execute
    /// asynchronously and when complete, if a handler is provided in the
    /// ExecuteScriptCompletedHandler parameter, its Invoke method will be
    /// called with the result of evaluating the provided JavaScript. The result
    /// value is a JSON encoded string.
    /// If the result is undefined, contains a reference cycle, or otherwise
    /// cannot be encoded into JSON, the JSON null value will be returned as the
    /// string 'null'. Note that a function that has no explicit return value
    /// returns undefined.
    /// If the executed script throws an unhandled exception, then the result is
    /// also 'null'.
    /// This method is applied asynchronously. If the method is called after
    /// NavigationStarting event during a navigation, the script will be executed
    /// in the new document when loading it, around the time ContentLoading is fired.
    /// ExecuteScript will work even if IsScriptEnabled is set to FALSE.
    ///
    /// \snippet ScriptComponent.cpp ExecuteScript
    unsafe fn execute_script(
        &self,
        /* in */ java_script: LPCWSTR,
        /* in */ handler: *mut *mut ICoreWebView2ExecuteScriptCompletedHandlerVTable,
    ) -> HRESULT;

    /// Capture an image of what WebView is displaying. Specify the
    /// format of the image with the imageFormat parameter.
    /// The resulting image binary data is written to the provided imageStream
    /// parameter. When CapturePreview finishes writing to the stream, the Invoke
    /// method on the provided handler parameter is called.
    ///
    /// \snippet FileComponent.cpp CapturePreview
    unsafe fn capture_preview(
        &self,
        /* in */ image_format: CapturePreviewImageFormat,
        /* in */ image_stream: *mut *mut IStreamVTable,
        /* in */ handler: *mut *mut ICoreWebView2CapturePreviewCompletedHandlerVTable,
    ) -> HRESULT;

    /// Reload the current page. This is similar to navigating to the URI of
    /// current top level document including all navigation events firing and
    /// respecting any entries in the HTTP cache. But, the back/forward history
    /// will not be modified.
    unsafe fn reload(&self) -> HRESULT;

    /// Post the specified webMessage to the top level document in this WebView.
    /// The top level document's window.chrome.webview's message event fires.
    /// JavaScript in that document may subscribe and unsubscribe to the event
    /// via the following:
    ///
    /// ```
    ///    window.chrome.webview.addEventListener('message', handler)
    ///    window.chrome.webview.removeEventListener('message', handler)
    /// ```
    ///
    /// The event args is an instance of `MessageEvent`.
    /// The ICoreWebView2Settings::IsWebMessageEnabled setting must be true or this method
    /// will fail with E_INVALIDARG.
    /// The event arg's data property is the webMessage string parameter parsed
    /// as a JSON string into a JavaScript object.
    /// The event arg's source property is a reference to the
    /// `window.chrome.webview` object.
    /// See SetWebMessageReceivedEventHandler for information on sending messages
    /// from the HTML document in the webview to the host.
    /// This message is sent asynchronously. If a navigation occurs before the
    /// message is posted to the page, then the message will not be sent.
    ///
    /// \snippet ScenarioWebMessage.cpp WebMessageReceived
    unsafe fn post_web_message_as_json(
        &self,
        /* in */ web_message_as_json: LPCWSTR,
    ) -> HRESULT;

    /// This is a helper for posting a message that is a simple string
    /// rather than a JSON string representation of a JavaScript object. This
    /// behaves in exactly the same manner as PostWebMessageAsJson but the
    /// `window.chrome.webview` message event arg's data property will be a string
    /// with the same value as webMessageAsString. Use this instead of
    /// PostWebMessageAsJson if you want to communicate via simple strings rather
    /// than JSON objects.
    unsafe fn post_web_message_as_string(
        &self,
        /* in */ web_message_as_string: LPCWSTR,
    ) -> HRESULT;

    /// This event fires when the IsWebMessageEnabled setting is set and the top
    /// level document of the webview calls `window.chrome.webview.postMessage`.
    /// The postMessage function is `void postMessage(object)` where
    /// object is any object supported by JSON conversion.
    ///
    /// \snippet ScenarioWebMessage.html chromeWebView
    ///
    /// When postMessage is called, the ICoreWebView2WebMessageReceivedEventHandler set via
    /// this SetWebMessageReceivedEventHandler method will be invoked with the
    /// postMessage's object parameter converted to a JSON string.
    ///
    /// \snippet ScenarioWebMessage.cpp WebMessageReceived
    unsafe fn add_web_message_received(
        &self,
        /* in */ handler: *mut *mut ICoreWebView2WebMessageReceivedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_WebMessageReceived.
    unsafe fn remove_web_message_received(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Call an asynchronous DevToolsProtocol method. See the
    /// [DevTools Protocol Viewer](https://aka.ms/DevToolsProtocolDocs)
    /// for a list and description of available methods.
    /// The methodName parameter is the full name of the method in the format
    /// `{domain}.{method}`.
    /// The parametersAsJson parameter is a JSON formatted string containing
    /// the parameters for the corresponding method.
    /// The handler's Invoke method will be called when the method asynchronously
    /// completes. Invoke will be called with the method's return object as a
    /// JSON string.
    ///
    /// \snippet ScriptComponent.cpp CallDevToolsProtocolMethod
    unsafe fn call_dev_tools_protocol_method(
        &self,
        /* in */ method_name: LPCWSTR,
        /* in */ parameters_as_json: LPCWSTR,
        /* in */
        handler: *mut *mut ICoreWebView2CallDevToolsProtocolMethodCompletedHandlerVTable,
    ) -> HRESULT;

    /// The process id of the browser process that hosts the WebView.
    unsafe fn get_browser_process_id(&self, /* out, retval */ value: *mut UINT32) -> HRESULT;

    /// Returns true if the webview can navigate to a previous page in the navigation history.
    /// The HistoryChanged event will fire if CanGoBack changes value.
    unsafe fn get_can_go_back(&self, /* out, retval */ can_go_back: *mut BOOL) -> HRESULT;

    /// Returns true if the webview can navigate to a next page in the navigation history.
    /// The HistoryChanged event will fire if CanGoForward changes value.
    unsafe fn get_can_go_forward(
        &self,
        /* out, retval */ can_go_forward: *mut BOOL,
    ) -> HRESULT;

    /// Navigates the WebView to the previous page in the navigation history.
    unsafe fn go_back(&self) -> HRESULT;

    /// Navigates the WebView to the next page in the navigation history.
    unsafe fn go_forward(&self) -> HRESULT;

    /// Get a DevTools Protocol event receiver that allows you to subscribe to
    /// a DevTools Protocol event.
    /// The eventName parameter is the full name of the event in the format
    /// `{domain}.{event}`.
    /// See the [DevTools Protocol Viewer](https://aka.ms/DevToolsProtocolDocs)
    /// for a list of DevTools Protocol events description, and event args.
    ///
    /// \snippet ScriptComponent.cpp DevToolsProtocolEventReceived
    unsafe fn get_dev_tools_protocol_event_receiver(
        &self,
        /* in */ event_name: LPCWSTR,
        /* out, retval */
        receiver: *mut *mut *mut ICoreWebView2DevToolsProtocolEventReceiverVTable,
    ) -> HRESULT;

    /// Stop all navigations and pending resource fetches. Does not stop
    /// scripts.
    unsafe fn stop(&self) -> HRESULT;

    /// Add an event handler for the NewWindowRequested event.
    /// Fires when content inside the WebView requested to open a new window,
    /// such as through window.open. The app can pass a target
    /// webview that will be considered the opened window.
    ///
    /// \snippet AppWindow.cpp NewWindowRequested
    unsafe fn add_new_window_requested(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2NewWindowRequestedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_NewWindowRequested.
    unsafe fn remove_new_window_requested(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the DocumentTitleChanged event.
    /// The event fires when the DocumentTitle property of the WebView changes
    /// and may fire before or after the NavigationCompleted event.
    ///
    /// \snippet FileComponent.cpp DocumentTitleChanged
    unsafe fn add_document_title_changed(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2DocumentTitleChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_DocumentTitleChanged.
    unsafe fn remove_document_title_changed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// The title for the current top level document.
    /// If the document has no explicit title or is otherwise empty,
    /// a default that may or may not match the URI of the document will be used.
    unsafe fn get_document_title(&self, /* out, retval */ title: *mut LPWSTR) -> HRESULT;

    /// Add the provided host object to script running in the WebView with the
    /// specified name.
    /// Host objects are exposed as host object proxies via
    /// `window.chrome.webview.hostObjects.<name>`.
    /// Host object proxies are promises and will resolve to an object
    /// representing the host object.
    /// The promise is rejected if the app has not added an object with the name.
    /// When JavaScript code access a property or method of the object, a promise
    /// is return, which will resolve to the value returned from the host for the
    /// property or method, or rejected in case of error such as there is no such
    /// property or method on the object or parameters are invalid.
    /// For example, when the application code does the following:
    ///
    /// ```
    ///    VARIANT object;
    ///    object.vt = VT_DISPATCH;
    ///    object.pdispVal = appObject;
    ///    webview->AddHostObjectToScript(L"host_object", &host);
    /// ```
    ///
    /// JavaScript code in the WebView will be able to access appObject as
    /// following and then access attributes and methods of appObject:
    ///
    /// ```
    ///    let app_object = await window.chrome.webview.hostObjects.host_object;
    ///    let attr1 = await app_object.attr1;
    ///    let result = await app_object.method1(parameters);
    /// ```
    ///
    /// Note that while simple types, IDispatch and array are supported, generic
    /// IUnknown, VT_DECIMAL, or VT_RECORD variant is not supported.
    /// Remote JavaScript objects like callback functions are represented as
    /// an VT_DISPATCH VARIANT with the object implementing IDispatch. The
    /// JavaScript callback method may be invoked using DISPID_VALUE for the
    /// DISPID.
    /// Nested arrays are supported up to a depth of 3.
    /// Arrays of by reference types are not supported.
    /// VT_EMPTY and VT_NULL are mapped into JavaScript as null. In JavaScript
    /// null and undefined are mapped to VT_EMPTY.
    ///
    /// Additionally, all host objects are exposed as
    /// `window.chrome.webview.hostObjects.sync.<name>`. Here the host
    /// objects are exposed as synchronous host object proxies. These are not
    /// promises and calls to functions or property access synchronously block
    /// running script waiting to communicate cross process for the host code to
    /// run. Accordingly this can result in reliability issues and it is
    /// recommended that you use the promise based asynchronous
    /// `window.chrome.webview.hostObjects.<name>` API described above.
    ///
    /// Synchronous host object proxies and asynchronous host object proxies
    /// can both proxy the same host object. Remote changes made by one proxy
    /// will be reflected in any other proxy of that same host object whether
    /// the other proxies and synchronous or asynchronous.
    ///
    /// While JavaScript is blocked on a synchronous call to native code, that
    /// native code is unable to call back to JavaScript. Attempts to do so will
    /// fail with HRESULT_FROM_WIN32(ERROR_POSSIBLE_DEADLOCK).
    ///
    /// Host object proxies are JavaScript Proxy objects that intercept all
    /// property get, property set, and method invocations. Properties or methods
    /// that are a part of the Function or Object prototype are run locally.
    /// Additionally any property or method in the array
    /// `chrome.webview.hostObjects.options.forceLocalProperties` will also be
    /// run locally. This defaults to including optional methods that have
    /// meaning in JavaScript like `toJSON` and `Symbol.toPrimitive`. You can add
    /// more to this array as required.
    ///
    /// There's a method `chrome.webview.hostObjects.cleanupSome` that will best
    /// effort garbage collect host object proxies.
    ///
    /// Host object proxies additionally have the following methods which run
    /// locally:
    ///  * applyHostFunction, getHostProperty, setHostProperty: Perform a
    ///    method invocation, property get, or property set on the host object.
    ///    You can use these to explicitly force a method or property to run
    ///    remotely if there is a conflicting local method or property. For
    ///    instance, `proxy.toString()` will run the local toString method on the
    ///    proxy object. But ``proxy.applyHostFunction('toString')`` runs
    ///    `toString` on the host proxied object instead.
    ///  * getLocalProperty, setLocalProperty: Perform property get, or property
    ///    set locally. You can use these methods to force getting or setting a
    ///    property on the host object proxy itself rather than on the host
    ///    object it represents. For instance, `proxy.unknownProperty` will get the
    ///    property named `unknownProperty` from the host proxied object. But
    ///    ``proxy.getLocalProperty('unknownProperty')`` will get the value of the property
    ///    `unknownProperty` on the proxy object itself.
    ///  * sync: Asynchronous host object proxies expose a sync method which
    ///    returns a promise for a synchronous host object proxy for the same
    ///    host object. For example,
    ///    `chrome.webview.hostObjects.sample.methodCall()` returns an
    ///    asynchronous host object proxy. You can use the `sync` method to
    ///    obtain a synchronous host object proxy instead:
    ///    `const syncProxy = await chrome.webview.hostObjects.sample.methodCall().sync()`
    ///  * async: Synchronous host object proxies expose an async method which
    ///    blocks and returns an asynchronous host object proxy for the same
    ///    host object. For example, `chrome.webview.hostObjects.sync.sample.methodCall()` returns a
    ///    synchronous host object proxy. Calling the `async` method on this blocks
    ///    and then returns an asynchronous host object proxy for the same host object:
    ///    `const asyncProxy = chrome.webview.hostObjects.sync.sample.methodCall().async()`
    ///  * then: Asynchronous host object proxies have a then method. This
    ///    allows them to be awaitable. `then` will return a promise that resolves
    ///    with a representation of the host object. If the proxy represents a
    ///    JavaScript literal then a copy of that is returned locally. If
    ///    the proxy represents a function then a non-awaitable proxy is returned.
    ///    If the proxy represents a JavaScript object with a mix of literal
    ///    properties and function properties, then the a copy of the object is
    ///    returned with some properties as host object proxies.
    ///
    /// All other property and method invocations (other than the above Remote
    /// object proxy methods, forceLocalProperties list, and properties on
    /// Function and Object prototypes) are run remotely. Asynchronous host
    /// object proxies return a promise representing asynchronous completion of
    /// remotely invoking the method, or getting the property.
    /// The promise resolves after the remote operations complete and
    /// the promises resolve to the resulting value of the operation.
    /// Synchronous host object proxies work similarly but block JavaScript
    /// execution and wait for the remote operation to complete.
    ///
    /// Setting a property on an asynchronous host object proxy works slightly
    /// differently. The set returns immediately and the return value is the value
    /// that will be set. This is a requirement of the JavaScript Proxy object.
    /// If you need to asynchronously wait for the property set to complete, use
    /// the setHostProperty method which returns a promise as described above.
    /// Synchronous object property set property synchronously blocks until the
    /// property is set.
    ///
    /// For example, suppose you have a COM object with the following interface
    ///
    /// \snippet HostObjectSample.idl AddHostObjectInterface
    ///
    /// We can add an instance of this interface into our JavaScript with
    /// `AddHostObjectToScript`. In this case we name it `sample`:
    ///
    /// \snippet ScenarioAddHostObject.cpp AddHostObjectToScript
    ///
    /// Then in the HTML document we can use this COM object via `chrome.webview.hostObjects.sample`:
    ///
    /// \snippet ScenarioAddHostObject.html HostObjectUsage
    /// Exposing host objects to script has security risk. Please follow
    /// [best practices](https://docs.microsoft.com/microsoft-edge/webview2/concepts/security).
    unsafe fn add_host_object_to_script(
        &self,
        /* in */ name: LPCWSTR,
        /* in */ object: *mut VARIANT,
    ) -> HRESULT;

    /// Remove the host object specified by the name so that it is no longer
    /// accessible from JavaScript code in the WebView.
    /// While new access attempts will be denied, if the object is already
    /// obtained by JavaScript code in the WebView, the JavaScript code will
    /// continue to have access to that object.
    /// Calling this method for a name that is already removed or never added will
    /// fail.
    unsafe fn remove_host_object_from_script(&self, /* in */ name: LPCWSTR) -> HRESULT;

    /// Opens the DevTools window for the current document in the WebView.
    /// Does nothing if called when the DevTools window is already open
    unsafe fn open_dev_tools_window(&self) -> HRESULT;

    /// Notifies when the ContainsFullScreenElement property changes. This means
    /// that an HTML element inside the WebView is entering fullscreen to the size
    /// of the WebView or leaving fullscreen.
    /// This event is useful when, for example, a video element requests to go
    /// fullscreen. The listener of ContainsFullScreenElementChanged can then
    /// resize the WebView in response.
    ///
    /// \snippet AppWindow.cpp ContainsFullScreenElementChanged
    unsafe fn add_contains_full_screen_element_changed(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2ContainsFullScreenElementChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with the corresponding add_
    /// event method.
    unsafe fn remove_contains_full_screen_element_changed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Indicates if the WebView contains a fullscreen HTML element.
    unsafe fn get_contains_full_screen_element(
        &self,
        /* out, retval */ contains_full_screen_element: *mut BOOL,
    ) -> HRESULT;

    /// Add an event handler for the WebResourceRequested event. Fires when the
    /// WebView is performing a URL request to a matching URL and resource context
    /// filter that was added with AddWebResourceRequestedFilter. At least one
    /// filter must be added for the event to fire.
    ///
    /// \snippet SettingsComponent.cpp WebResourceRequested
    unsafe fn add_web_resource_requested(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2WebResourceRequestedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_WebResourceRequested.
    unsafe fn remove_web_resource_requested(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Adds a URI and resource context filter to the WebResourceRequested event.
    /// URI parameter can be a wildcard string ('': zero or more, '?': exactly one).
    /// nullptr is equivalent to L"".
    /// See COREWEBVIEW2_WEB_RESOURCE_CONTEXT enum for description of resource context filters.
    unsafe fn add_web_resource_requested_filter(
        &self,
        /* in */ uri: LPCWSTR,
        /* in */ resource_context: WebResourceContext,
    ) -> HRESULT;

    /// Removes a matching WebResource filter that was previously added for the
    /// WebResourceRequested event. If the same filter was added multiple times, then it
    /// will need to be removed as many times as it was added for the removal to be
    /// effective. Returns E_INVALIDARG for a filter that was never added.
    unsafe fn remove_web_resource_requested_filter(
        &self,
        /* in */ uri: LPCWSTR,
        /* in */ resource_context: WebResourceContext,
    ) -> HRESULT;

    /// Add an event handler for the WindowCloseRequested event.
    /// Fires when content inside the WebView requested to close the window,
    /// such as after window.close is called. The app should close the WebView
    /// and related app window if that makes sense to the app.
    ///
    /// \snippet AppWindow.cpp WindowCloseRequested
    unsafe fn add_window_close_requested(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2WindowCloseRequestedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_WindowCloseRequested.
    unsafe fn remove_window_close_requested(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;
}

/// This interface is the owner of the CoreWebView2 object, and provides support
/// for resizing, showing and hiding, focusing, and other functionality related
/// to windowing and composition. The CoreWebView2Controller owns the CoreWebView2,
/// and if all references to the CoreWebView2Controller go away, the WebView will
/// be closed.
#[com_interface("7CCC5C7F-8351-4572-9077-9C1C80913835")]
pub trait ICoreWebView2Controller: IUnknown {
    /// The IsVisible property determines whether to show or hide the webview.
    /// If IsVisible is set to false, the webview will be transparent and will
    /// not be rendered.  However, this will not affect the window containing
    /// the webview (the HWND parameter that was passed to CreateCoreWebView2Controller).
    /// If you want that window to disappear too, call ShowWindow on it directly
    /// in addition to modifying the IsVisible property.
    /// WebView as a child window won't get window messages when the top window
    /// is minimized or restored. For performance reason, developer should set
    /// IsVisible property of the WebView to false when the app window is
    /// minimized and back to true when app window is restored. App window can do
    /// this by handling SC_MINIMIZE and SC_RESTORE command upon receiving
    /// WM_SYSCOMMAND message.
    ///
    /// \snippet ViewComponent.cpp ToggleIsVisible
    unsafe fn get_is_visible(&self, /* out, retval */ is_visible: *mut BOOL) -> HRESULT;

    /// Set the IsVisible property.
    ///
    /// \snippet ViewComponent.cpp ToggleIsVisibleOnMinimize
    unsafe fn put_is_visible(&self, /* in */ is_visible: BOOL) -> HRESULT;

    /// The webview bounds.
    /// Bounds are relative to the parent HWND. The app has two ways it can
    /// position a WebView:
    /// 1. Create a child HWND that is the WebView parent HWND. Position this
    ///    window where the WebView should be. In this case, use (0, 0) for the
    ///    WebView's Bound's top left corner (the offset).
    /// 2. Use the app's top most window as the WebView parent HWND. Set the
    ///    WebView's Bound's top left corner so that the WebView is positioned
    ///    correctly in the app.
    /// The Bound's values are in the host's coordinate space.
    unsafe fn get_bounds(&self, /* out, retval */ bounds: *mut RECT) -> HRESULT;

    /// Set the Bounds property.
    ///
    /// \snippet ViewComponent.cpp ResizeWebView
    unsafe fn put_bounds(&self, /* in */ bounds: RECT) -> HRESULT;

    /// The zoom factor for the WebView.
    /// Note that changing zoom factor could cause `window.innerWidth/innerHeight`
    /// and page layout to change.
    /// A zoom factor that is applied by the host by calling ZoomFactor
    /// becomes the new default zoom for the WebView. This zoom factor applies
    /// across navigations and is the zoom factor WebView is returned to when the
    /// user presses ctrl+0. When the zoom factor is changed by the user
    /// (resulting in the app receiving ZoomFactorChanged), that zoom applies
    /// only for the current page. Any user applied zoom is only for the current
    /// page and is reset on a navigation.
    /// Specifying a zoomFactor less than or equal to 0 is not allowed.
    /// WebView also has an internal supported zoom factor range. When a specified
    /// zoom factor is out of that range, it will be normalized to be within the
    /// range, and a ZoomFactorChanged event will be fired for the real
    /// applied zoom factor. When this range normalization happens, the
    /// ZoomFactor property will report the zoom factor specified during the
    /// previous modification of the ZoomFactor property until the
    /// ZoomFactorChanged event is received after webview applies the normalized
    /// zoom factor.
    unsafe fn get_zoom_factor(&self, /* out, retval */ zoom_factor: *mut f64) -> HRESULT;

    /// Set the ZoomFactor property.
    unsafe fn put_zoom_factor(&self, /* in */ zoom_factor: f64) -> HRESULT;

    /// Add an event handler for the ZoomFactorChanged event.
    /// The event fires when the ZoomFactor property of the WebView changes.
    /// The event could fire because the caller modified the ZoomFactor property,
    /// or due to the user manually modifying the zoom. When it is modified by the
    /// caller via the ZoomFactor property, the internal zoom factor is updated
    /// immediately and there will be no ZoomFactorChanged event.
    /// WebView associates the last used zoom factor for each site. Therefore, it
    /// is possible for the zoom factor to change when navigating to a different
    /// page. When the zoom factor changes due to this, the ZoomFactorChanged
    /// event fires right after the ContentLoading event.
    ///
    /// \snippet ViewComponent.cpp ZoomFactorChanged
    unsafe fn add_zoom_factor_changed(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_ZoomFactorChanged.
    unsafe fn remove_zoom_factor_changed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Update Bounds and ZoomFactor properties at the same time. This operation
    /// is atomic from the host's perspective. After returning from this function,
    /// the Bounds and ZoomFactor properties will have both been updated if the
    /// function is successful, or neither will be updated if the function fails.
    /// If Bounds and ZoomFactor are both updated by the same scale (i.e. Bounds
    /// and ZoomFactor are both doubled), then the page will not see a change in
    /// window.innerWidth/innerHeight and the WebView will render the content at
    /// the new size and zoom without intermediate renderings.
    /// This function can also be used to update just one of ZoomFactor or Bounds
    /// by passing in the new value for one and the current value for the other.
    ///
    /// \snippet ViewComponent.cpp SetBoundsAndZoomFactor
    unsafe fn set_bounds_and_zoom_factor(
        &self,
        /* in */ bounds: RECT,
        /* in */ zoom_factor: f64,
    ) -> HRESULT;

    /// Move focus into WebView. WebView will get focus and focus will be set to
    /// correspondent element in the page hosted in the WebView.
    /// For Programmatic reason, focus is set to previously focused element or
    /// the default element if there is no previously focused element.
    /// For Next reason, focus is set to the first element.
    /// For Previous reason, focus is set to the last element.
    /// WebView can also got focus through user interaction like clicking into
    /// WebView or Tab into it.
    /// For tabbing, the app can call MoveFocus with Next or Previous to align
    /// with tab and shift+tab respectively when it decides the WebView is the
    /// next tabbable element. Or, the app can call IsDialogMessage as part of
    /// its message loop to allow the platform to auto handle tabbing. The
    /// platform will rotate through all windows with WS_TABSTOP. When the
    /// WebView gets focus from IsDialogMessage, it will internally put the focus
    /// on the first or last element for tab and shift+tab respectively.
    ///
    /// \snippet App.cpp MoveFocus0
    ///
    /// \snippet ControlComponent.cpp MoveFocus1
    ///
    /// \snippet ControlComponent.cpp MoveFocus2
    unsafe fn move_focus(&self, /* in */ reason: MoveFocusReason) -> HRESULT;

    /// Add an event handler for the MoveFocusRequested event.
    /// MoveFocusRequested fires when user tries to tab out of the WebView.
    /// The WebView's focus has not changed when this event is fired.
    ///
    /// \snippet ControlComponent.cpp MoveFocusRequested
    unsafe fn add_move_focus_requested(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_MoveFocusRequested.
    unsafe fn remove_move_focus_requested(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// Add an event handler for the GotFocus event.
    /// GotFocus fires when WebView got focus.
    unsafe fn add_got_focus(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_GotFocus.
    unsafe fn remove_got_focus(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// Add an event handler for the LostFocus event.
    /// LostFocus fires when WebView lost focus.
    /// In the case where MoveFocusRequested event is fired, the focus is still
    /// on WebView when MoveFocusRequested event fires. Lost focus only fires
    /// afterwards when app's code or default action of MoveFocusRequested event
    /// set focus away from WebView.
    unsafe fn add_lost_focus(
        &self,
        /* in */ event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_LostFocus.
    unsafe fn remove_lost_focus(&self, /* in */ token: EventRegistrationToken) -> HRESULT;

    /// Add an event handler for the AcceleratorKeyPressed event.
    /// AcceleratorKeyPressed fires when an accelerator key or key combo is
    /// pressed or released while the WebView is focused. A key is considered an
    /// accelerator if either:
    ///   1. Ctrl or Alt is currently being held, or
    ///   2. the pressed key does not map to a character.
    /// A few specific keys are never considered accelerators, such as Shift.
    /// The Escape key is always considered an accelerator.
    ///
    /// Autorepeated key events caused by holding the key down will also fire this
    /// event.  You can filter these out by checking the event args'
    /// KeyEventLParam or PhysicalKeyStatus.
    ///
    /// In windowed mode, this event handler is called synchronously. Until you
    /// call Handle() on the event args or the event handler returns, the browser
    /// process will be blocked and outgoing cross-process COM calls will fail
    /// with RPC_E_CANTCALLOUT_ININPUTSYNCCALL. All CoreWebView2 API methods will
    /// work, however.
    ///
    /// In windowless mode, the event handler is called asynchronously.  Further
    /// input will not reach the browser until the event handler returns or
    /// Handle() is called, but the browser process itself will not be blocked,
    /// and outgoing COM calls will work normally.
    ///
    /// It is recommended to call Handle(TRUE) as early as you can know that you want
    /// to handle the accelerator key.
    ///
    /// \snippet ControlComponent.cpp AcceleratorKeyPressed
    unsafe fn add_accelerator_key_pressed(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_AcceleratorKeyPressed.
    unsafe fn remove_accelerator_key_pressed(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;

    /// The parent window provided by the app that this WebView is using to
    /// render content. This API initially returns the window passed into
    /// CreateCoreWebView2Controller.
    unsafe fn get_parent_window(
        &self,
        /* out, retval */ top_level_window: *mut HWND,
    ) -> HRESULT;

    /// Set the parent window for the WebView. This will cause the WebView to
    /// reparent its window to the newly provided window.
    unsafe fn put_parent_window(&self, /* in */ top_level_window: HWND) -> HRESULT;

    /// This is a notification separate from Bounds that tells WebView its
    /// parent (or any ancestor) HWND moved. This is needed for accessibility and
    /// certain dialogs in WebView to work correctly.
    /// \snippet ViewComponent.cpp NotifyParentWindowPositionChanged
    unsafe fn notify_parent_window_position_changed(&self) -> HRESULT;

    /// Closes the WebView and cleans up the underlying browser instance.
    /// Cleaning up the browser instance will release the resources powering the WebView.
    /// The browser instance will be shut down if there are no other WebViews using it.
    ///
    /// After calling Close, all method calls will fail and event handlers
    /// will stop firing. Specifically, the WebView will release its references
    /// to its event handlers when Close is called.
    ///
    /// Close is implicitly called when the CoreWebView2Controller loses its final
    /// reference and is destructed. But it is best practice to explicitly call
    /// Close to avoid any accidental cycle of references between the WebView
    /// and the app code. Specifically, if you capture a reference to the WebView
    /// in an event handler you will create a reference cycle between the WebView
    /// and the event handler. Calling Close will break this cycle by releasing
    /// all event handlers. But to avoid this situation it is best practice both
    /// to explicitly call Close on the WebView and to not capture a reference to
    /// the WebView to ensure the WebView can be cleaned up correctly.
    ///
    /// \snippet AppWindow.cpp Close
    unsafe fn close(&self) -> HRESULT;

    /// Gets the CoreWebView2 associated with this CoreWebView2Controller.
    unsafe fn get_core_web_view2(
        &self,
        /* out, retval */ core_web_view2: *mut *mut *mut ICoreWebView2VTable,
    ) -> HRESULT;
}

/// This interface is used to complete deferrals on event args that
/// support getting deferrals via their GetDeferral method.
#[com_interface("A7ED8BF0-3EC9-4E39-8427-3D6F157BD285")]
pub trait ICoreWebView2Deferral: IUnknown {
    /// Completes the associated deferred event. Complete should only be
    /// called once for each deferral taken.
    unsafe fn complete(&self) -> HRESULT;
}

/// Defines properties that enable, disable, or modify WebView
/// features. Setting changes made after NavigationStarting event will not
/// apply until the next top level navigation.
#[com_interface("203FBA37-6850-4DCC-A25A-58A351AC625D")]
pub trait ICoreWebView2Settings: IUnknown {
    /// Controls if JavaScript execution is enabled in all future
    /// navigations in the WebView.  This only affects scripts in the document;
    /// scripts injected with ExecuteScript will run even if script is disabled.
    /// It is true by default.
    ///
    /// \snippet SettingsComponent.cpp IsScriptEnabled
    unsafe fn get_is_script_enabled(
        &self,
        /* out, retval */ is_script_enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the IsScriptEnabled property.
    unsafe fn put_is_script_enabled(&self, /* in */ is_script_enabled: BOOL) -> HRESULT;

    /// The IsWebMessageEnabled property is used when loading a new
    /// HTML document. If set to true, communication from the host to the
    /// webview's top level HTML document is allowed via PostWebMessageAsJson,
    /// PostWebMessageAsString, and window.chrome.webview's message event
    /// (see PostWebMessageAsJson documentation for details).
    /// Communication from the webview's top level HTML document
    /// to the host is allowed via window.chrome.webview's postMessage function
    /// and the SetWebMessageReceivedEventHandler method (see the
    /// SetWebMessageReceivedEventHandler documentation for details).
    /// If set to false, then communication is disallowed.
    /// PostWebMessageAsJson and PostWebMessageAsString will
    /// fail with E_ACCESSDENIED and window.chrome.webview.postMessage will fail
    /// by throwing an instance of an Error object.
    /// It is true by default.
    ///
    /// \snippet ScenarioWebMessage.cpp IsWebMessageEnabled
    unsafe fn get_is_web_message_enabled(
        &self,
        /* out, retval */ is_web_message_enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the IsWebMessageEnabled property.
    unsafe fn put_is_web_message_enabled(
        &self,
        /* in */ is_web_message_enabled: BOOL,
    ) -> HRESULT;

    /// AreDefaultScriptDialogsEnabled is used when loading a new
    /// HTML document. If set to false, then WebView won't render the default
    /// javascript dialog box (Specifically those shown by the javascript alert,
    /// confirm, prompt functions and beforeunload event). Instead, if an event
    /// handler is set by SetScriptDialogOpeningEventHandler, WebView will send an
    /// event that will contain all of the information for the dialog and allow
    /// the host app to show its own custom UI.
    unsafe fn get_are_default_script_dialogs_enabled(
        &self,
        /* out, retval */ are_default_script_dialogs_enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the AreDefaultScriptDialogsEnabled property.
    unsafe fn put_are_default_script_dialogs_enabled(
        &self,
        /* in */ are_default_script_dialogs_enabled: BOOL,
    ) -> HRESULT;

    /// IsStatusBarEnabled controls whether the status bar will be displayed. The
    /// status bar is usually displayed in the lower left of the WebView and shows
    /// things such as the URI of a link when the user hovers over it and other
    /// information. It is true by default.
    unsafe fn get_is_status_bar_enabled(
        &self,
        /* out, retval */ is_status_bar_enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the IsStatusBarEnabled property.
    unsafe fn put_is_status_bar_enabled(
        &self,
        /* in */ is_status_bar_enabled: BOOL,
    ) -> HRESULT;

    /// AreDevToolsEnabled controls whether the user is able to use the context
    /// menu or keyboard shortcuts to open the DevTools window.
    /// It is true by default.
    unsafe fn get_are_dev_tools_enabled(
        &self,
        /* out, retval */ are_dev_tools_enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the AreDevToolsEnabled property.
    unsafe fn put_are_dev_tools_enabled(
        &self,
        /* in */ are_dev_tools_enabled: BOOL,
    ) -> HRESULT;

    /// The AreDefaultContextMenusEnabled property is used to prevent
    /// default context menus from being shown to user in webview. Defaults to TRUE.
    ///
    /// \snippet SettingsComponent.cpp DisableContextMenu
    unsafe fn get_are_default_context_menus_enabled(
        &self,
        /* out, retval */ enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the AreDefaultContextMenusEnabled property
    unsafe fn put_are_default_context_menus_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;

    /// The AreHostObjectsAllowed property is used to control whether
    /// host objects are accessible from the page in webview. Defaults to TRUE.
    ///
    /// \snippet SettingsComponent.cpp HostObjectsAccess
    unsafe fn get_are_host_objects_allowed(
        &self,
        /* out, retval */ allowed: *mut BOOL,
    ) -> HRESULT;

    /// Set the AreHostObjectsAllowed property
    unsafe fn put_are_host_objects_allowed(&self, /* in */ allowed: BOOL) -> HRESULT;

    /// The IsZoomControlEnabled property is used to prevent the user from
    /// impacting the zoom of the WebView. Defaults to TRUE.
    /// When disabled, user will not be able to zoom using ctrl+/- or
    /// ctrl+mouse wheel, but the zoom can be set via ZoomFactor API.
    ///
    /// \snippet SettingsComponent.cpp DisableZoomControl
    unsafe fn get_is_zoom_control_enabled(
        &self,
        /* out, retval */ enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the IsZoomControlEnabled property
    unsafe fn put_is_zoom_control_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;

    /// The IsBuiltInErrorPageEnabled property is used to disable built in error
    /// page for navigation failure and render process failure. Defaults to TRUE.
    /// When disabled, blank page will be shown when related error happens.
    ///
    /// \snippet SettingsComponent.cpp BuiltInErrorPageEnabled
    unsafe fn get_is_built_in_error_page_enabled(
        &self,
        /* out, retval */ enabled: *mut BOOL,
    ) -> HRESULT;

    /// Set the IsBuiltInErrorPageEnabled property
    unsafe fn put_is_built_in_error_page_enabled(&self, /* in */ enabled: BOOL) -> HRESULT;
}

/// Event args for the ProcessFailed event.
#[com_interface("EA45D1F4-75C0-471F-A6E9-803FBFF8FEF2")]
pub trait ICoreWebView2ProcessFailedEventArgs: IUnknown {
    /// The kind of process failure that has occurred.
    unsafe fn get_process_failed_kind(
        &self,
        /* out, retval */ process_failed_kind: *mut ProcessFailedKind,
    ) -> HRESULT;
}

/// The caller implements this interface to receive ProcessFailed events.
#[com_interface("7D2183F9-CCA8-40F2-91A9-EAFAD32C8A9B")]
pub trait ICoreWebView2ProcessFailedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2ProcessFailedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive ZoomFactorChanged
/// events. Use the ICoreWebView2Controller.ZoomFactor property to get the
/// modified zoom factor.
#[com_interface("F1828246-8B98-4274-B708-ECDB6BF3843A")]
pub trait ICoreWebView2ZoomFactorChangedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event. There are no event args and the args
    /// parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// Iterator for a collection of HTTP headers. See ICoreWebView2HttpRequestHeaders
/// and ICoreWebView2HttpResponseHeaders.
/// \snippet ScenarioWebViewEventMonitor.cpp HttpRequestHeaderIterator
#[com_interface("4212F3A7-0FBC-4C9C-8118-17ED6370C1B3")]
pub trait ICoreWebView2HttpHeadersCollectionIterator: IUnknown {
    /// Get the name and value of the current HTTP header of the iterator. This
    /// method will fail if the last call to MoveNext set has_next to FALSE.
    unsafe fn get_current_header(
        &self,
        /* out */ name: *mut LPWSTR,
        /* out */ value: *mut LPWSTR,
    ) -> HRESULT;

    /// True when the iterator hasn't run out of headers. If the collection over
    /// which the iterator is iterating is empty or if the iterator has gone past
    /// the end of the collection then this is false.
    unsafe fn get_has_current_header(
        &self,
        /* out, retval */ has_current: *mut BOOL,
    ) -> HRESULT;

    /// Move the iterator to the next HTTP header in the collection. The hasNext
    /// parameter will be set to FALSE if there are no more HTTP headers. After
    /// this occurs the GetCurrentHeader method will fail if called.
    unsafe fn move_next(&self, /* out */ has_next: *mut BOOL) -> HRESULT;
}

/// HTTP request headers. Used to inspect the HTTP request on
/// WebResourceRequested event and NavigationStarting event.
/// Note, you can modify the HTTP request headers from a WebResourceRequested event,
/// but not from a NavigationStarting event.
#[com_interface("2C1F04DF-C90E-49E4-BD25-4A659300337B")]
pub trait ICoreWebView2HttpRequestHeaders: IUnknown {
    /// Gets the header value matching the name.
    unsafe fn get_header(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */ value: *mut LPWSTR,
    ) -> HRESULT;

    /// Gets the header value matching the name via an iterator.
    unsafe fn get_headers(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */
        iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
    ) -> HRESULT;

    /// Checks whether the headers contain an entry matching the header name.
    unsafe fn contains(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */ contains: *mut BOOL,
    ) -> HRESULT;

    /// Adds or updates header that matches the name.
    unsafe fn set_header(
        &self,
        /* in */ name: LPCWSTR,
        /* in */ value: LPCWSTR,
    ) -> HRESULT;

    /// Removes header that matches the name.
    unsafe fn remove_header(&self, /* in */ name: LPCWSTR) -> HRESULT;

    /// Gets an iterator over the collection of request headers.
    unsafe fn get_iterator(
        &self,
        /* out, retval */
        iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
    ) -> HRESULT;
}

/// HTTP response headers. Used to construct a WebResourceResponse for the
/// WebResourceRequested event.
#[com_interface("B5F6D4D5-1BFF-4869-85B8-158153017B04")]
pub trait ICoreWebView2HttpResponseHeaders: IUnknown {
    /// Appends header line with name and value.
    unsafe fn append_header(
        &self,
        /* in */ name: LPCWSTR,
        /* in */ value: LPCWSTR,
    ) -> HRESULT;

    /// Checks whether the headers contain entries matching the header name.
    unsafe fn contains(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */ contains: *mut BOOL,
    ) -> HRESULT;

    /// Gets the first header value in the collection matching the name.
    unsafe fn get_header(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */ value: *mut LPWSTR,
    ) -> HRESULT;

    /// Gets the header values matching the name.
    unsafe fn get_headers(
        &self,
        /* in */ name: LPCWSTR,
        /* out, retval */
        iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
    ) -> HRESULT;

    /// Gets an iterator over the collection of entire response headers.
    unsafe fn get_iterator(
        &self,
        /* out, retval */
        iterator: *mut *mut *mut ICoreWebView2HttpHeadersCollectionIteratorVTable,
    ) -> HRESULT;
}

/// An HTTP request used with the WebResourceRequested event.
#[com_interface("11B02254-B827-49F6-8974-30F6E6C55AF6")]
pub trait ICoreWebView2WebResourceRequest: IUnknown {
    /// The request URI.
    unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// Set the Uri property.
    unsafe fn put_uri(&self, /* in */ uri: LPCWSTR) -> HRESULT;

    /// The HTTP request method.
    unsafe fn get_method(&self, /* out, retval */ method: *mut LPWSTR) -> HRESULT;

    /// Set the Method property.
    unsafe fn put_method(&self, /* in */ method: LPCWSTR) -> HRESULT;

    /// The HTTP request message body as stream. POST data would be here.
    /// If a stream is set, which will override the message body, the stream must
    /// have all the content data available by the time this
    /// response's WebResourceRequested event deferral is completed. Stream
    /// should be agile or be created from a background STA to prevent performance
    /// impact to the UI thread. Null means no content data. IStream semantics
    /// apply (return S_OK to Read calls until all data is exhausted)
    unsafe fn get_content(
        &self,
        /* out, retval */ content: *mut *mut *mut IStreamVTable,
    ) -> HRESULT;

    /// Set the Content property.
    unsafe fn put_content(&self, /* in */ content: *mut *mut IStreamVTable) -> HRESULT;

    /// The mutable HTTP request headers
    unsafe fn get_headers(
        &self,
        /* out, retval */ headers: *mut *mut *mut ICoreWebView2HttpRequestHeadersVTable,
    ) -> HRESULT;
}

/// An HTTP response used with the WebResourceRequested event.
#[com_interface("5953D1FC-B08F-46DD-AFD3-66B172419CD0")]
pub trait ICoreWebView2WebResourceResponse: IUnknown {
    /// HTTP response content as stream. Stream must have all the
    /// content data available by the time this response's WebResourceRequested
    /// event deferral is completed. Stream should be agile or be created from
    /// a background thread to prevent performance impact to the UI thread.
    /// Null means no content data. IStream semantics
    /// apply (return S_OK to Read calls until all data is exhausted)
    unsafe fn get_content(
        &self,
        /* out, retval */ content: *mut *mut *mut IStreamVTable,
    ) -> HRESULT;

    /// Set the Content property.
    unsafe fn put_content(&self, /* in */ content: *mut *mut IStreamVTable) -> HRESULT;

    /// Overridden HTTP response headers.
    unsafe fn get_headers(
        &self,
        /* out, retval */ headers: *mut *mut *mut ICoreWebView2HttpResponseHeadersVTable,
    ) -> HRESULT;

    /// The HTTP response status code.
    unsafe fn get_status_code(&self, /* out, retval */ status_code: *mut i32) -> HRESULT;

    /// Set the StatusCode property.
    unsafe fn put_status_code(&self, /* in */ status_code: i32) -> HRESULT;

    /// The HTTP response reason phrase
    unsafe fn get_reason_phrase(
        &self,
        /* out, retval */ reason_phrase: *mut LPWSTR,
    ) -> HRESULT;

    /// Set the ReasonPhrase property.
    unsafe fn put_reason_phrase(&self, /* in */ reason_phrase: LPCWSTR) -> HRESULT;
}

/// Event args for the NavigationStarting event.
#[com_interface("EE1938CE-D385-4CB0-854B-F498F78C3D88")]
pub trait ICoreWebView2NavigationStartingEventArgs: IUnknown {
    /// The uri of the requested navigation.
    unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// True when the navigation was initiated through a user gesture as opposed
    /// to programmatic navigation.
    unsafe fn get_is_user_initiated(
        &self,
        /* out, retval */ is_user_initiated: *mut BOOL,
    ) -> HRESULT;

    /// True when the navigation is redirected.
    unsafe fn get_is_redirected(&self, /* out, retval */ is_redirected: *mut BOOL) -> HRESULT;

    /// The HTTP request headers for the navigation.
    /// Note, you cannot modify the HTTP request headers in a NavigationStarting event.
    unsafe fn get_request_headers(
        &self,
        /* out, retval */
        request_headers: *mut *mut *mut ICoreWebView2HttpRequestHeadersVTable,
    ) -> HRESULT;

    /// The host may set this flag to cancel the navigation.
    /// If set, it will be as if the navigation never happened and the current
    /// page's content will be intact. For performance reasons, GET HTTP requests
    /// may happen, while the host is responding. This means cookies can be set
    /// and used part of a request for the navigation.
    unsafe fn get_cancel(&self, /* out, retval */ cancel: *mut BOOL) -> HRESULT;

    /// Set the Cancel property.
    unsafe fn put_cancel(&self, /* in */ cancel: BOOL) -> HRESULT;

    /// The ID of the navigation.
    unsafe fn get_navigation_id(
        &self,
        /* out, retval */ navigation_id: *mut UINT64,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the NavigationStarting
/// event.
#[com_interface("073337A4-64D2-4C7E-AC9F-987F0F613497")]
pub trait ICoreWebView2NavigationStartingEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2NavigationStartingEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the ContentLoading event.
#[com_interface("2A800835-2179-45D6-A745-6657E9A546B9")]
pub trait ICoreWebView2ContentLoadingEventArgs: IUnknown {
    /// True if the loaded content is an error page.
    unsafe fn get_is_error_page(&self, /* out, retval */ is_error_page: *mut BOOL) -> HRESULT;

    /// The ID of the navigation.
    unsafe fn get_navigation_id(
        &self,
        /* out, retval */ navigation_id: *mut UINT64,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the ContentLoading event.
#[com_interface("7AF5CC82-AE19-4964-BD71-B9BC5F03E85D")]
pub trait ICoreWebView2ContentLoadingEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ webview: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2ContentLoadingEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the SourceChanged event.
#[com_interface("BD9A4BFB-BE19-40BD-968B-EBCF0D727EF3")]
pub trait ICoreWebView2SourceChangedEventArgs: IUnknown {
    /// True if the page being navigated to is a new document.
    unsafe fn get_is_new_document(
        &self,
        /* out, retval */ is_new_document: *mut BOOL,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the SourceChanged event.
#[com_interface("8FEDD1A7-3A33-416F-AF81-881EEB001433")]
pub trait ICoreWebView2SourceChangedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ webview: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2SourceChangedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the HistoryChanged event.
#[com_interface("54C9B7D7-D9E9-4158-861F-F97E1C3C6631")]
pub trait ICoreWebView2HistoryChangedEventHandler: IUnknown {
    /// There are no event args and the args parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ webview: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// Event args for the ScriptDialogOpening event.
#[com_interface("B8F6356E-24DC-4D74-90FE-AD071E11CB91")]
pub trait ICoreWebView2ScriptDialogOpeningEventArgs: IUnknown {
    /// The URI of the page that requested the dialog box.
    unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// The kind of JavaScript dialog box. Accept, confirm, prompt, or
    /// beforeunload.
    unsafe fn get_kind(&self, /* out, retval */ kind: *mut ScriptDialogKind) -> HRESULT;

    /// The message of the dialog box. From JavaScript this is the first parameter
    /// passed to alert, confirm, and prompt and is empty for beforeunload.
    unsafe fn get_message(&self, /* out, retval */ message: *mut LPWSTR) -> HRESULT;

    /// The host may call this to respond with OK to confirm, prompt, and
    /// beforeunload dialogs or not call this method to indicate cancel. From
    /// JavaScript, this means that the confirm and beforeunload function returns
    /// true if Accept is called. And for the prompt function it returns the value
    /// of ResultText if Accept is called and returns false otherwise.
    unsafe fn accept(&self) -> HRESULT;

    /// The second parameter passed to the JavaScript prompt dialog. This is the
    /// default value to use for the result of the prompt JavaScript function.
    unsafe fn get_default_text(&self, /* out, retval */ default_text: *mut LPWSTR) -> HRESULT;

    /// The return value from the JavaScript prompt function if Accept is called.
    /// This is ignored for dialog kinds other than prompt. If Accept is not
    /// called this value is ignored and false is returned from prompt.
    unsafe fn get_result_text(&self, /* out, retval */ result_text: *mut LPWSTR) -> HRESULT;

    /// Set the ResultText property.
    unsafe fn put_result_text(&self, /* in */ result_text: LPCWSTR) -> HRESULT;

    /// GetDeferral can be called to return an ICoreWebView2Deferral object.
    /// You can use this to complete the event at a later time.
    unsafe fn get_deferral(
        &self,
        /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the ScriptDialogOpening
/// event.
#[com_interface("72D93789-2727-4A9B-A4FC-1B2609CBCBE3")]
pub trait ICoreWebView2ScriptDialogOpeningEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2ScriptDialogOpeningEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the NavigationCompleted event.
#[com_interface("361F5621-EA7F-4C55-95EC-3C5E6992EA4A")]
pub trait ICoreWebView2NavigationCompletedEventArgs: IUnknown {
    /// True when the navigation is successful. This
    /// is false for a navigation that ended up in an error page (failures due to
    /// no network, DNS lookup failure, HTTP server responds with 4xx), but could
    /// also be false for additional things such as window.stop() called on
    /// navigated page.
    unsafe fn get_is_success(&self, /* out, retval */ is_success: *mut BOOL) -> HRESULT;

    /// The error code if the navigation failed.
    unsafe fn get_web_error_status(
        &self,
        /* out, retval */ corewebview2_web_error_status: *mut WebErrorStatus,
    ) -> HRESULT;

    /// The ID of the navigation.
    unsafe fn get_navigation_id(
        &self,
        /* out, retval */ navigation_id: *mut UINT64,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the NavigationCompleted
/// event.
#[com_interface("9F921239-20C4-455F-9E3F-6047A50E248B")]
pub trait ICoreWebView2NavigationCompletedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2NavigationCompletedEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the PermissionRequested event.
#[com_interface("774B5EA1-3FAD-435C-B1FC-A77D1ACD5EAF")]
pub trait ICoreWebView2PermissionRequestedEventArgs: IUnknown {
    /// The origin of the web content that requests the permission.
    unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// The type of the permission that is requested.
    unsafe fn get_permission_kind(
        &self,
        /* out, retval */ value: *mut PermissionKind,
    ) -> HRESULT;

    /// True when the permission request was initiated through a user gesture.
    /// Note that being initiated through a user gesture doesn't mean that user
    /// intended to access the associated resource.
    unsafe fn get_is_user_initiated(
        &self,
        /* out, retval */ is_user_initiated: *mut BOOL,
    ) -> HRESULT;

    /// The status of a permission request, i.e. whether the request is granted.
    /// Default value is COREWEBVIEW2_PERMISSION_STATE_DEFAULT.
    unsafe fn get_state(&self, /* out, retval */ value: *mut PermissionState) -> HRESULT;

    /// Set the State property.
    unsafe fn put_state(&self, /* in */ value: PermissionState) -> HRESULT;

    /// GetDeferral can be called to return an ICoreWebView2Deferral object.
    /// Developer can use the deferral object to make the permission decision
    /// at a later time.
    unsafe fn get_deferral(
        &self,
        /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the PermissionRequested
/// event.
#[com_interface("543B4ADE-9B0B-4748-9AB7-D76481B223AA")]
pub trait ICoreWebView2PermissionRequestedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2PermissionRequestedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the result of the
/// AddScriptToExecuteOnDocumentCreated method.
#[com_interface("7082ABED-0591-428F-A722-60C2F814546B")]
pub trait ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status and result
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(
        &self,
        /* in */ error_code: HRESULT,
        /* in */ id: LPCWSTR,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the result of the
/// ExecuteScript method.
#[com_interface("3B717C93-3ED5-4450-9B13-7F56AA367AC7")]
pub trait ICoreWebView2ExecuteScriptCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status and result
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(
        &self,
        /* in */ error_code: HRESULT,
        /* in */ result_object_as_json: LPCWSTR,
    ) -> HRESULT;
}

/// Event args for the WebResourceRequested event.
#[com_interface("2D7B3282-83B1-41CA-8BBF-FF18F6BFE320")]
pub trait ICoreWebView2WebResourceRequestedEventArgs: IUnknown {
    /// The Web resource request. The request object may be missing some headers
    /// that are added by network stack later on.
    unsafe fn get_request(
        &self,
        /* out, retval */ request: *mut *mut *mut ICoreWebView2WebResourceRequestVTable,
    ) -> HRESULT;

    /// A placeholder for the web resource response object. If this object is set, the
    /// web resource request will be completed with this response.
    unsafe fn get_response(
        &self,
        /* out, retval */ response: *mut *mut *mut ICoreWebView2WebResourceResponseVTable,
    ) -> HRESULT;

    /// Set the Response property. An empty Web resource respnose object can be
    /// created with CreateWebResourceResponse and then modified to construct the response.
    unsafe fn put_response(
        &self,
        /* in */ response: *mut *mut ICoreWebView2WebResourceResponseVTable,
    ) -> HRESULT;

    /// Obtain an ICoreWebView2Deferral object and put the event into a deferred state.
    /// You can use the ICoreWebView2Deferral object to complete the request at a
    /// later time.
    unsafe fn get_deferral(
        &self,
        /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
    ) -> HRESULT;

    /// The web resource request context.
    unsafe fn get_resource_context(
        &self,
        /* out, retval */ context: *mut WebResourceContext,
    ) -> HRESULT;
}

/// Fires when a URL request (through network, file etc.) is made in the webview
/// for a Web resource matching resource context filter and URL specified in
/// AddWebResourceRequestedFilter.
/// The host can view and modify the request or provide a response in a similar
/// pattern to HTTP, in which case the request immediately completed.
/// This may not contain any request headers that are added by the network
/// stack, such as Authorization headers.
#[com_interface("F6DC79F2-E1FA-4534-8968-4AFF10BBAA32")]
pub trait ICoreWebView2WebResourceRequestedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2WebResourceRequestedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this method to receive the result of the
/// CapturePreview method. The result is written to the stream provided in
/// the CapturePreview method call.
#[com_interface("DCED64F8-D9C7-4A3C-B9FD-FBBCA0B43496")]
pub trait ICoreWebView2CapturePreviewCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(&self, /* in */ result: HRESULT) -> HRESULT;
}

/// The caller implements this method to receive the GotFocus and LostFocus
/// events. There are no event args for this event.
#[com_interface("76E67C71-663F-4C17-B71A-9381CCF3B94B")]
pub trait ICoreWebView2FocusChangedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event. There are no event args and the args
    /// parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// Event args for the MoveFocusRequested event.
#[com_interface("71922903-B180-49D0-AED2-C9F9D10064B1")]
pub trait ICoreWebView2MoveFocusRequestedEventArgs: IUnknown {
    /// The reason for WebView to fire the MoveFocus Requested event.
    unsafe fn get_reason(&self, /* out, retval */ value: *mut MoveFocusReason) -> HRESULT;

    /// Indicate whether the event has been handled by the app.
    /// If the app has moved the focus to its desired location, it should set
    /// Handled property to TRUE.
    /// When Handled property is false after the event handler returns, default
    /// action will be taken. The default action is to try to find the next tab
    /// stop child window in the app and try to move focus to that window. If
    /// there is no other such window to move focus to, focus will be cycled
    /// within the WebView's web content.
    unsafe fn get_handled(&self, /* out, retval */ value: *mut BOOL) -> HRESULT;

    /// Set the Handled property.
    unsafe fn put_handled(&self, /* in */ value: BOOL) -> HRESULT;
}

/// The caller implements this method to receive the MoveFocusRequested event.
#[com_interface("4B21D6DD-3DE7-47B0-8019-7D3ACE6E3631")]
pub trait ICoreWebView2MoveFocusRequestedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
        /* in */ args: *mut *mut ICoreWebView2MoveFocusRequestedEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the WebMessageReceived event.
#[com_interface("B263B5AE-9C54-4B75-B632-40AE1A0B6912")]
pub trait ICoreWebView2WebMessageReceivedEventArgs: IUnknown {
    /// The URI of the document that sent this web message.
    unsafe fn get_source(&self, /* out, retval */ source: *mut LPWSTR) -> HRESULT;

    /// The message posted from the webview content to the host converted to a
    /// JSON string. Use this to communicate via JavaScript objects.
    ///
    /// For example the following postMessage calls result in the
    /// following WebMessageAsJson values:
    ///
    /// ```
    ///    postMessage({'a': 'b'})      L"{\"a\": \"b\"}"
    ///    postMessage(1.2)             L"1.2"
    ///    postMessage('example')       L"\"example\""
    /// ```
    unsafe fn get_web_message_as_json(
        &self,
        /* out, retval */ web_message_as_json: *mut LPWSTR,
    ) -> HRESULT;

    /// If the message posted from the webview content to the host is a
    /// string type, this method will return the value of that string. If the
    /// message posted is some other kind of JavaScript type this method will fail
    /// with E_INVALIDARG. Use this to communicate via simple strings.
    ///
    /// For example the following postMessage calls result in the
    /// following WebMessageAsString values:
    ///
    /// ```
    ///    postMessage({'a': 'b'})      E_INVALIDARG
    ///    postMessage(1.2)             E_INVALIDARG
    ///    postMessage('example')       L"example"
    /// ```
    unsafe fn try_get_web_message_as_string(
        &self,
        /* out, retval */ web_message_as_string: *mut LPWSTR,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the WebMessageReceived
/// event.
#[com_interface("199328C8-9964-4F5F-84E6-E875B1B763D6")]
pub trait ICoreWebView2WebMessageReceivedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2WebMessageReceivedEventArgsVTable,
    ) -> HRESULT;
}

/// Event args for the DevToolsProtocolEventReceived event.
#[com_interface("F661B1C2-5FF5-4700-B723-C439034539B4")]
pub trait ICoreWebView2DevToolsProtocolEventReceivedEventArgs: IUnknown {
    /// The parameter object of the corresponding DevToolsProtocol event
    /// represented as a JSON string.
    unsafe fn get_parameter_object_as_json(
        &self,
        /* out, retval */ parameter_object_as_json: *mut LPWSTR,
    ) -> HRESULT;
}

/// The caller implements this interface to receive
/// DevToolsProtocolEventReceived events from the WebView.
#[com_interface("8E1DED79-A40B-4271-8BE6-57640C167F4A")]
pub trait ICoreWebView2DevToolsProtocolEventReceivedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2DevToolsProtocolEventReceivedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive CallDevToolsProtocolMethod
/// completion results.
#[com_interface("C20CF895-BA7C-493B-AB2E-8A6E3A3602A2")]
pub trait ICoreWebView2CallDevToolsProtocolMethodCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status and result
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(
        &self,
        /* in */ error_code: HRESULT,
        /* in */ return_object_as_json: LPCWSTR,
    ) -> HRESULT;
}

/// The caller implements this interface to receive the CoreWebView2Controller created
/// via CreateCoreWebView2Controller.
#[com_interface("86EF6808-3C3F-4C6F-975E-8CE0B98F70BA")]
pub trait ICoreWebView2CreateCoreWebView2ControllerCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status and result
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(
        &self,
        result: HRESULT,
        created_controller: *mut *mut ICoreWebView2ControllerVTable,
    ) -> HRESULT;
}

/// Event args for the NewWindowRequested event. The event is fired when content
/// inside webview requested to a open a new window (through window.open() and so on.)
#[com_interface("9EDC7F5F-C6EA-4F3C-827B-A8880794C0A9")]
pub trait ICoreWebView2NewWindowRequestedEventArgs: IUnknown {
    /// The target uri of the NewWindowRequest.
    unsafe fn get_uri(&self, /* out, retval */ uri: *mut LPWSTR) -> HRESULT;

    /// Sets a WebView as a result of the NewWindowRequest. The target
    /// webview should not be navigated. If the NewWindow is set, its top level
    /// window will return as the opened WindowProxy.
    unsafe fn put_new_window(
        &self,
        /* in */ new_window: *mut *mut ICoreWebView2VTable,
    ) -> HRESULT;

    /// Gets the new window.
    unsafe fn get_new_window(
        &self,
        /* out, retval */ new_window: *mut *mut *mut ICoreWebView2VTable,
    ) -> HRESULT;

    /// Sets whether the NewWindowRequestedEvent is handled by host. If this is false
    /// and no NewWindow is set, the WebView will open a popup
    /// window and it will be returned as opened WindowProxy.
    /// If set to true and no NewWindow is set for a window.open call, the opened
    /// WindowProxy will be for an dummy window object and no window will load.
    /// Default is false.
    unsafe fn put_handled(&self, /* in */ handled: BOOL) -> HRESULT;

    /// Gets whether the NewWindowRequestedEvent is handled by host.
    unsafe fn get_handled(&self, /* out, retval */ handled: *mut BOOL) -> HRESULT;

    /// IsUserInitiated is true when the new window request was initiated through
    /// a user gesture such as clicking an anchor tag with target. The Edge
    /// popup blocker is disabled for WebView so the app can use this flag to
    /// block non-user initiated popups.
    unsafe fn get_is_user_initiated(
        &self,
        /* out, retval */ is_user_initiated: *mut BOOL,
    ) -> HRESULT;

    /// Obtain an ICoreWebView2Deferral object and put the event into a deferred state.
    /// You can use the ICoreWebView2Deferral object to complete the window open
    /// request at a later time.
    /// While this event is deferred the opener window will be returned a WindowProxy
    /// to an unnavigated window, which will navigate when the deferral is complete.
    unsafe fn get_deferral(
        &self,
        /* out, retval */ deferral: *mut *mut *mut ICoreWebView2DeferralVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive NewWindowRequested
/// events.
#[com_interface("ACAA30EF-A40C-47BD-9CB9-D9C2AADC9FCB")]
pub trait ICoreWebView2NewWindowRequestedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut ICoreWebView2NewWindowRequestedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive DocumentTitleChanged
/// events. Use the DocumentTitle property to get the modified
/// title.
#[com_interface("6423D6B1-5A57-46C5-BA46-DBB3735EE7C9")]
pub trait ICoreWebView2DocumentTitleChangedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event. There are no event args and the args
    /// parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// Event args for the AcceleratorKeyPressed event.
#[com_interface("9224476E-D8C3-4EB7-BB65-2FD7792B27CE")]
pub trait ICoreWebView2AcceleratorKeyPressedEventArgs: IUnknown {
    /// The key event type that caused the event to be fired.
    unsafe fn get_key_event_kind(
        &self,
        /* out, retval */ key_event_kind: *mut KeyEventKind,
    ) -> HRESULT;

    /// The Win32 virtual key code of the key that was pressed or released.
    /// This will be one of the Win32 virtual key constants such as VK_RETURN or
    /// an (uppercase) ASCII value such as 'A'. You can check whether Ctrl or Alt
    /// are pressed by calling GetKeyState(VK_CONTROL) or GetKeyState(VK_MENU).
    unsafe fn get_virtual_key(&self, /* out, retval */ virtual_key: *mut UINT) -> HRESULT;

    /// The LPARAM value that accompanied the window message. See the
    /// documentation for the WM_KEYDOWN and WM_KEYUP messages.
    unsafe fn get_key_event_lparam(&self, /* out, retval */ l_param: *mut i32) -> HRESULT;

    /// A structure representing the information passed in the LPARAM of the
    /// window message.
    unsafe fn get_physical_key_status(
        &self,
        /* out, retval */ physical_key_status: *mut PhysicalKeyStatus,
    ) -> HRESULT;

    /// During AcceleratorKeyPressedEvent handler invocation the WebView is blocked
    /// waiting for the decision of if the accelerator will be handled by the host
    /// or not. If the Handled property is set to TRUE then this will
    /// prevent the WebView from performing the default action for this
    /// accelerator key. Otherwise the WebView will perform the default action for
    /// the accelerator key.
    unsafe fn get_handled(&self, /* out, retval */ handled: *mut BOOL) -> HRESULT;

    /// Sets the Handled property.
    unsafe fn put_handled(&self, /* in */ handled: BOOL) -> HRESULT;
}

/// The caller implements this interface to receive the AcceleratorKeyPressed
/// event.
#[com_interface("A7D303F9-503C-4B7E-BC40-5C7CE6CABAAA")]
pub trait ICoreWebView2AcceleratorKeyPressedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2ControllerVTable,
        /* in */ args: *mut *mut ICoreWebView2AcceleratorKeyPressedEventArgsVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive NewBrowserVersionAvailable events.
#[com_interface("E82E8242-EE39-4A57-A065-E13256D60342")]
pub trait ICoreWebView2NewBrowserVersionAvailableEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event.
    unsafe fn invoke(
        &self,
        /* in */ webview_environment: *mut *mut ICoreWebView2EnvironmentVTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// The caller implements this method to receive the
/// ContainsFullScreenElementChanged events. There are no event args for this
/// event.
#[com_interface("120888E3-4CAD-4EC2-B627-B2016D05612D")]
pub trait ICoreWebView2ContainsFullScreenElementChangedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event. There are no event args and the args
    /// parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// The caller implements this interface to receive NewWindowRequested
/// events.
#[com_interface("63C89928-AD32-4421-A0E4-EC99B34AA97E")]
pub trait ICoreWebView2WindowCloseRequestedEventHandler: IUnknown {
    /// Called to provide the implementer with the event args for the
    /// corresponding event. There are no event args and the args
    /// parameter will be null.
    unsafe fn invoke(
        &self,
        /* in */ sender: *mut *mut ICoreWebView2VTable,
        /* in */ args: *mut *mut IUnknownVTable,
    ) -> HRESULT;
}

/// This represents the WebView2 Environment. WebViews created from an
/// environment run on the Browser process specified with environment parameters
/// and objects created from an environment should be used in the same environment.
/// Using it in different environments are not guaranteed to be compatible and may fail.
#[com_interface("DA66D884-6DA8-410E-9630-8C48F8B3A40E")]
pub trait ICoreWebView2Environment: IUnknown {
    /// Asynchronously create a new WebView.
    ///
    /// parentWindow is the HWND in which the WebView should be displayed and
    /// from which receive input. The WebView will add a child window to the
    /// provided window during WebView creation. Z-order and other things impacted
    /// by sibling window order will be affected accordingly.
    ///
    /// It is recommended that the application set Application User Model ID for
    /// the process or the application window. If none is set, during WebView
    /// creation a generated Application User Model ID is set to root window of
    /// parentWindow.
    /// \snippet AppWindow.cpp CreateCoreWebView2Controller
    ///
    /// It is recommended that the application handles restart manager messages
    /// so that it can be restarted gracefully in the case when the app is using
    /// Edge for webview from a certain installation and that installation is being
    /// uninstalled. For example, if a user installs Edge from Dev channel and
    /// opts to use Edge from that channel for testing the app, and then uninstalls
    /// Edge from that channel without closing the app, the app will be restarted
    /// to allow uninstallation of the dev channel to succeed.
    /// \snippet AppWindow.cpp RestartManager
    ///
    /// When the application retries CreateCoreWebView2Controller upon failure, it is
    /// recommended that the application restarts from creating a new WebView2
    /// Environment. If an Edge update happens, the version associated with a WebView2
    /// Environment could have been removed and causing the object to no longer work.
    /// Creating a new WebView2 Environment will work as it uses the latest version.
    ///
    /// WebView creation will fail if there is already a running instance using the same
    /// user data folder, and the Environment objects have different EnvironmentOptions.
    /// For example, if there is already a WebView created with one language, trying to
    /// create a WebView with a different language using the same user data folder will
    /// fail.
    unsafe fn create_core_web_view2_controller(
        &self,
        parent_window: HWND,
        handler: *mut *mut ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVTable,
    ) -> HRESULT;

    /// Create a new web resource response object. The headers is the
    /// raw response header string delimited by newline. It's also possible to
    /// create this object with empty headers string and then use the
    /// ICoreWebView2HttpResponseHeaders to construct the headers line by line.
    /// For information on other parameters see ICoreWebView2WebResourceResponse.
    ///
    /// \snippet SettingsComponent.cpp WebResourceRequested
    unsafe fn create_web_resource_response(
        &self,
        /* in */ content: *mut *mut IStreamVTable,
        /* in */ status_code: i32,
        /* in */ reason_phrase: LPCWSTR,
        /* in */ headers: LPCWSTR,
        /* out, retval */ response: *mut *mut *mut ICoreWebView2WebResourceResponseVTable,
    ) -> HRESULT;

    /// The browser version info of the current ICoreWebView2Environment,
    /// including channel name if it is not the stable channel.
    /// This matches the format of the
    /// GetAvailableCoreWebView2BrowserVersionString API.
    /// Channel names are 'beta', 'dev', and 'canary'.
    ///
    /// \snippet AppWindow.cpp GetBrowserVersionString
    unsafe fn get_browser_version_string(
        &self,
        /* out, retval */ version_info: *mut LPWSTR,
    ) -> HRESULT;

    /// The NewBrowserVersionAvailable event fires when a newer version of the
    /// Edge browser is installed and available to use via WebView2.
    /// To use the newer version of the browser you must create a new
    /// environment and WebView.
    /// This event will only be fired for new version from the same Edge channel
    /// that the code is running from. When not running with installed Edge,
    /// no event will be fired.
    ///
    /// Because a user data folder can only be used by one browser process at
    /// a time, if you want to use the same user data folder in the WebViews
    /// using the new version of the browser,
    /// you must close the environment and WebViews that are using the older
    /// version of the browser first. Or simply prompt the user to restart the
    /// app.
    ///
    /// \snippet AppWindow.cpp NewBrowserVersionAvailable
    ///
    unsafe fn add_new_browser_version_available(
        &self,
        /* in */
        event_handler: *mut *mut ICoreWebView2NewBrowserVersionAvailableEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with add_NewBrowserVersionAvailable.
    unsafe fn remove_new_browser_version_available(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;
}

/// Options used to create WebView2 Environment.
/// A default implementation is provided in WebView2EnvironmentOptions.h.
///
/// \snippet AppWindow.cpp CreateCoreWebView2EnvironmentWithOptions
///
#[com_interface("97E9FBD9-646A-4B75-8682-149B71DACE59")]
pub trait ICoreWebView2EnvironmentOptions: IUnknown {
    /// AdditionalBrowserArguments can be specified to change the behavior of the
    /// WebView. These will be passed to the browser process as part of
    /// the command line. See
    /// [Run Chromium with Flags](https://aka.ms/RunChromiumWithFlags)
    /// for more information about command line switches to browser
    /// process. If the app is launched with a command line switch
    /// `--edge-webview-switches=xxx` the value of that switch (xxx in
    /// the above example) will also be appended to the browser
    /// process command line. Certain switches like `--user-data-dir` are
    /// internal and important to WebView. Those switches will be
    /// ignored even if specified. If the same switches are specified
    /// multiple times, the last one wins. There is no attempt to
    /// merge the different values of the same switch, except for disabled
    /// and enabled features.  The features specified by `--enable-features`
    /// and `--disable-features` will be merged with simple logic: the features
    /// will be the union of the specified features and built-in features, and if
    /// a feature is disabled, it will be removed from the enabled features list.
    /// App process's command line `--edge-webview-switches` value are processed
    /// after the additionalBrowserArguments parameter is processed. Certain
    /// features are disabled internally and can't be enabled.
    /// If parsing failed for the specified switches, they will be
    /// ignored. Default is to run browser process with no extra flags.
    unsafe fn get_additional_browser_arguments(
        &self,
        /* out, retval */ value: *mut LPWSTR,
    ) -> HRESULT;

    /// Set the AdditionalBrowserArguments property.
    unsafe fn put_additional_browser_arguments(&self, /* in */ value: LPCWSTR) -> HRESULT;

    /// The default language that WebView will run with. It applies to browser UIs
    /// like context menu and dialogs. It also applies to the accept-languages
    /// HTTP header that WebView sends to web sites.
    /// It is in the format of `language[-country]` where `language` is the 2 letter
    /// code from ISO 639 and `country` is the 2 letter code from ISO 3166.
    unsafe fn get_language(&self, /* out, retval */ value: *mut LPWSTR) -> HRESULT;

    /// Set the Language property.
    unsafe fn put_language(&self, /* in */ value: LPCWSTR) -> HRESULT;

    /// The version of the Edge WebView2 Runtime binaries required to be
    /// compatible with the calling application. This defaults to the Edge
    /// WebView2 Runtime version
    /// that corresponds with the version of the SDK the application is using.
    /// The format of this value is the same as the format of the
    /// BrowserVersionString property and other BrowserVersion values.
    /// Only the version part of the BrowserVersion value is respected. The
    /// channel suffix, if it exists, is ignored.
    /// The version of the Edge WebView2 Runtime binaries actually used may be
    /// different from the specified TargetCompatibleBrowserVersion. They are only
    /// guaranteed to be compatible. You can check the actual version on the
    /// BrowserVersionString property on the ICoreWebView2Environment.
    unsafe fn get_target_compatible_browser_version(
        &self,
        /* out, retval */ value: *mut LPWSTR,
    ) -> HRESULT;

    /// Set the TargetCompatibleBrowserVersion.
    unsafe fn put_target_compatible_browser_version(&self, /* in */ value: LPCWSTR) -> HRESULT;
}

/// The caller implements this interface to receive the WebView2Environment created
/// via CreateCoreWebView2Environment.
#[com_interface("8B4F98CE-DB0D-4E71-85FD-C4C4EF1F2630")]
pub trait ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler: IUnknown {
    /// Called to provide the implementer with the completion status and result
    /// of the corresponding asynchronous method call.
    unsafe fn invoke(
        &self,
        result: HRESULT,
        created_environment: *mut *mut ICoreWebView2EnvironmentVTable,
    ) -> HRESULT;
}

/// A Receiver is created for a particular DevTools Protocol event and allows
/// you to subscribe and unsubscribe from that event.
/// Obtained from the WebView object via GetDevToolsProtocolEventReceiver.
#[com_interface("FE59C48C-540C-4A3C-8898-8E1602E0055D")]
pub trait ICoreWebView2DevToolsProtocolEventReceiver: IUnknown {
    /// Subscribe to a DevToolsProtocol event.
    /// The handler's Invoke method will be called whenever the corresponding
    /// DevToolsProtocol event fires. Invoke will be called with
    /// an event args object containing the DevTools Protocol event's parameter
    /// object as a JSON string.
    ///
    /// \snippet ScriptComponent.cpp DevToolsProtocolEventReceived
    unsafe fn add_dev_tools_protocol_event_received(
        &self,
        /* in */
        handler: *mut *mut ICoreWebView2DevToolsProtocolEventReceivedEventHandlerVTable,
        /* out */ token: *mut EventRegistrationToken,
    ) -> HRESULT;

    /// Remove an event handler previously added with
    /// add_DevToolsProtocolEventReceived.
    unsafe fn remove_dev_tools_protocol_event_received(
        &self,
        /* in */ token: EventRegistrationToken,
    ) -> HRESULT;
}