@@ -814,7 +814,7 @@ void browserDispose(Event event) {
814
814
if (inCallback ) {
815
815
ICoreWebView2Controller controller1 = controller ;
816
816
controller .put_IsVisible (false );
817
- browser . getDisplay (). asyncExec (() -> {
817
+ executeAsynchronously (() -> {
818
818
controller1 .Close ();
819
819
controller1 .Release ();
820
820
});
@@ -960,7 +960,7 @@ private String getExposedUrl(String url) {
960
960
}
961
961
962
962
int handleCloseRequested (long pView , long pArgs ) {
963
- browser . getDisplay (). asyncExec (() -> {
963
+ executeAsynchronously (() -> {
964
964
if (browser .isDisposed ()) return ;
965
965
WindowEvent event = new WindowEvent (browser );
966
966
event .display = browser .getDisplay ();
@@ -978,7 +978,7 @@ int handleDocumentTitleChanged(long pView, long pArgs) {
978
978
long [] ppsz = new long [1 ];
979
979
webViewProvider .getWebView (false ).get_DocumentTitle (ppsz );
980
980
String title = wstrToString (ppsz [0 ], true );
981
- browser . getDisplay (). asyncExec (() -> {
981
+ executeAsynchronously (() -> {
982
982
if (browser .isDisposed ()) return ;
983
983
TitleEvent event = new TitleEvent (browser );
984
984
event .display = browser .getDisplay ();
@@ -1031,10 +1031,12 @@ int handleNavigationStarting(long pView, long pArgs, boolean top) {
1031
1031
event .location = url ;
1032
1032
event .top = top ;
1033
1033
event .doit = true ;
1034
- for (LocationListener listener : locationListeners ) {
1035
- listener .changing (event );
1036
- if (browser .isDisposed ()) return COM .S_OK ;
1037
- }
1034
+ executeAsynchronously (() -> {
1035
+ for (LocationListener listener : locationListeners ) {
1036
+ listener .changing (event );
1037
+ if (browser .isDisposed ()) return ;
1038
+ }
1039
+ });
1038
1040
// Save location and top for all events that use navigationId.
1039
1041
// will be eventually cleared again in handleNavigationCompleted().
1040
1042
navigations .put (pNavId [0 ], event );
@@ -1043,11 +1045,13 @@ int handleNavigationStarting(long pView, long pArgs, boolean top) {
1043
1045
settings .put_IsScriptEnabled (jsEnabled );
1044
1046
// Register browser functions in the new document.
1045
1047
if (!functions .isEmpty ()) {
1046
- StringBuilder sb = new StringBuilder ();
1047
- for (BrowserFunction function : functions .values ()) {
1048
- sb .append (function .functionString );
1049
- }
1050
- execute (sb .toString ());
1048
+ executeAsynchronously (() -> {
1049
+ StringBuilder sb = new StringBuilder ();
1050
+ for (BrowserFunction function : functions .values ()) {
1051
+ sb .append (function .functionString );
1052
+ }
1053
+ execute (sb .toString ());
1054
+ });
1051
1055
}
1052
1056
} else {
1053
1057
args .put_Cancel (true );
@@ -1093,7 +1097,7 @@ int handleSourceChanged(long pView, long pArgs) {
1093
1097
} else {
1094
1098
location = url ;
1095
1099
}
1096
- browser . getDisplay (). asyncExec (() -> {
1100
+ executeAsynchronously (() -> {
1097
1101
if (browser .isDisposed ()) return ;
1098
1102
LocationEvent event = new LocationEvent (browser );
1099
1103
event .display = browser .getDisplay ();
@@ -1110,7 +1114,7 @@ int handleSourceChanged(long pView, long pArgs) {
1110
1114
}
1111
1115
1112
1116
void sendProgressCompleted () {
1113
- browser . getDisplay (). asyncExec (() -> {
1117
+ executeAsynchronously (() -> {
1114
1118
if (browser .isDisposed ()) return ;
1115
1119
ProgressEvent event = new ProgressEvent (browser );
1116
1120
event .display = browser .getDisplay ();
@@ -1160,22 +1164,24 @@ int handleBasicAuthenticationRequested(long pView, long pArgs) {
1160
1164
args .get_Uri (ppv );
1161
1165
String uri = wstrToString (ppv [0 ], true );
1162
1166
1163
- for (AuthenticationListener authenticationListener : this .authenticationListeners ) {
1164
- AuthenticationEvent event = new AuthenticationEvent (browser );
1165
- event .location = uri ;
1166
- authenticationListener .authenticate (event );
1167
- if (!event .doit ) {
1168
- args .put_Cancel (true );
1169
- return COM .S_OK ;
1170
- }
1171
- if (event .user != null && event .password != null ) {
1172
- args .get_Response (ppv );
1173
- ICoreWebView2BasicAuthenticationResponse response = new ICoreWebView2BasicAuthenticationResponse (ppv [0 ]);
1174
- response .put_UserName (stringToWstr (event .user ));
1175
- response .put_Password (stringToWstr (event .password ));
1176
- return COM .S_OK ;
1167
+ executeAsynchronously (() -> {
1168
+ for (AuthenticationListener authenticationListener : this .authenticationListeners ) {
1169
+ AuthenticationEvent event = new AuthenticationEvent (browser );
1170
+ event .location = uri ;
1171
+ authenticationListener .authenticate (event );
1172
+ if (!event .doit ) {
1173
+ args .put_Cancel (true );
1174
+ return ;
1175
+ }
1176
+ if (event .user != null && event .password != null ) {
1177
+ args .get_Response (ppv );
1178
+ ICoreWebView2BasicAuthenticationResponse response = new ICoreWebView2BasicAuthenticationResponse (ppv [0 ]);
1179
+ response .put_UserName (stringToWstr (event .user ));
1180
+ response .put_Password (stringToWstr (event .password ));
1181
+ return ;
1182
+ }
1177
1183
}
1178
- }
1184
+ });
1179
1185
1180
1186
return COM .S_OK ;
1181
1187
}
@@ -1236,9 +1242,11 @@ int handleStatusBarTextChanged(long pView, long pArgs) {
1236
1242
statusTextEvent .display = browser .getDisplay ();
1237
1243
statusTextEvent .widget = browser ;
1238
1244
statusTextEvent .text = text ;
1239
- for (StatusTextListener statusTextListener : statusTextListeners ) {
1240
- statusTextListener .changed (statusTextEvent );
1241
- }
1245
+ executeAsynchronously (() -> {
1246
+ for (StatusTextListener statusTextListener : statusTextListeners ) {
1247
+ statusTextListener .changed (statusTextEvent );
1248
+ }
1249
+ });
1242
1250
return COM .S_OK ;
1243
1251
}
1244
1252
@@ -1267,7 +1275,7 @@ int handleNavigationCompleted(long pView, long pArgs, boolean top) {
1267
1275
int [] pIsSuccess = new int [1 ];
1268
1276
args .get_IsSuccess (pIsSuccess );
1269
1277
if (pIsSuccess [0 ] != 0 ) {
1270
- browser . getDisplay (). asyncExec (() -> {
1278
+ executeAsynchronously (() -> {
1271
1279
if (browser .isDisposed ()) return ;
1272
1280
LocationEvent event = new LocationEvent (browser );
1273
1281
event .display = browser .getDisplay ();
@@ -1319,7 +1327,7 @@ int handleNewWindowRequested(long pView, long pArgs) {
1319
1327
args .GetDeferral (ppv );
1320
1328
ICoreWebView2Deferral deferral = new ICoreWebView2Deferral (ppv [0 ]);
1321
1329
inNewWindow = true ;
1322
- browser . getDisplay (). asyncExec (() -> {
1330
+ executeAsynchronously (() -> {
1323
1331
try {
1324
1332
if (browser .isDisposed ()) return ;
1325
1333
WindowEvent openEvent = new WindowEvent (browser );
@@ -1345,6 +1353,7 @@ int handleNewWindowRequested(long pView, long pArgs) {
1345
1353
showListener .show (showEvent );
1346
1354
if (other .browser .isDisposed ()) return ;
1347
1355
}
1356
+
1348
1357
}
1349
1358
} else if (openEvent .required ) {
1350
1359
args .put_Handled (true );
@@ -1426,7 +1435,8 @@ int handleAcceleratorKeyPressed(long pView, long pArgs) {
1426
1435
}
1427
1436
} else {
1428
1437
keyEvent .type = SWT .KeyUp ;
1429
- browser .notifyListeners (keyEvent .type , keyEvent );
1438
+ executeAsynchronously (() -> browser .notifyListeners (keyEvent .type , keyEvent ));
1439
+
1430
1440
if (!keyEvent .doit ) {
1431
1441
args .put_Handled (true );
1432
1442
}
@@ -1500,6 +1510,10 @@ public boolean setText(String html, boolean trusted) {
1500
1510
return setWebpageData (URI_FOR_CUSTOM_TEXT_PAGE .toString (), null , null , html );
1501
1511
}
1502
1512
1513
+ private void executeAsynchronously (Runnable runnable ) {
1514
+ browser .getDisplay ().asyncExec (runnable );
1515
+ }
1516
+
1503
1517
private boolean setWebpageData (String url , String postData , String [] headers , String html ) {
1504
1518
// Feature in WebView2. Partial URLs like "www.example.com" are not accepted.
1505
1519
// Prepend the protocol if it's missing.
0 commit comments