Skip to content

Commit afa88d8

Browse files
committed
Edge callback listeners execute asyncly eclipse-platform#1466
This commit cotributes to executing the registered listeners of Edge browser on Browser callbacks in a asynchronous fashion making sure no WebView related task is executed while a WebView callback is already executing making sure there's no deadlock. contributes to eclipse-platform#1771 and eclipse-platform#1919
1 parent 5eb3ba2 commit afa88d8

File tree

1 file changed

+49
-35
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

1 file changed

+49
-35
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

+49-35
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ void browserDispose(Event event) {
814814
if (inCallback) {
815815
ICoreWebView2Controller controller1 = controller;
816816
controller.put_IsVisible(false);
817-
browser.getDisplay().asyncExec(() -> {
817+
executeAsynchronously(() -> {
818818
controller1.Close();
819819
controller1.Release();
820820
});
@@ -960,7 +960,7 @@ private String getExposedUrl(String url) {
960960
}
961961

962962
int handleCloseRequested(long pView, long pArgs) {
963-
browser.getDisplay().asyncExec(() -> {
963+
executeAsynchronously(() -> {
964964
if (browser.isDisposed()) return;
965965
WindowEvent event = new WindowEvent(browser);
966966
event.display = browser.getDisplay();
@@ -978,7 +978,7 @@ int handleDocumentTitleChanged(long pView, long pArgs) {
978978
long[] ppsz = new long[1];
979979
webViewProvider.getWebView(false).get_DocumentTitle(ppsz);
980980
String title = wstrToString(ppsz[0], true);
981-
browser.getDisplay().asyncExec(() -> {
981+
executeAsynchronously(() -> {
982982
if (browser.isDisposed()) return;
983983
TitleEvent event = new TitleEvent(browser);
984984
event.display = browser.getDisplay();
@@ -1031,10 +1031,12 @@ int handleNavigationStarting(long pView, long pArgs, boolean top) {
10311031
event.location = url;
10321032
event.top = top;
10331033
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+
});
10381040
// Save location and top for all events that use navigationId.
10391041
// will be eventually cleared again in handleNavigationCompleted().
10401042
navigations.put(pNavId[0], event);
@@ -1043,11 +1045,13 @@ int handleNavigationStarting(long pView, long pArgs, boolean top) {
10431045
settings.put_IsScriptEnabled(jsEnabled);
10441046
// Register browser functions in the new document.
10451047
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+
});
10511055
}
10521056
} else {
10531057
args.put_Cancel(true);
@@ -1093,7 +1097,7 @@ int handleSourceChanged(long pView, long pArgs) {
10931097
} else {
10941098
location = url;
10951099
}
1096-
browser.getDisplay().asyncExec(() -> {
1100+
executeAsynchronously(() -> {
10971101
if (browser.isDisposed()) return;
10981102
LocationEvent event = new LocationEvent(browser);
10991103
event.display = browser.getDisplay();
@@ -1110,7 +1114,7 @@ int handleSourceChanged(long pView, long pArgs) {
11101114
}
11111115

11121116
void sendProgressCompleted() {
1113-
browser.getDisplay().asyncExec(() -> {
1117+
executeAsynchronously(() -> {
11141118
if (browser.isDisposed()) return;
11151119
ProgressEvent event = new ProgressEvent(browser);
11161120
event.display = browser.getDisplay();
@@ -1160,22 +1164,24 @@ int handleBasicAuthenticationRequested(long pView, long pArgs) {
11601164
args.get_Uri(ppv);
11611165
String uri = wstrToString(ppv[0], true);
11621166

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+
}
11771183
}
1178-
}
1184+
});
11791185

11801186
return COM.S_OK;
11811187
}
@@ -1236,9 +1242,11 @@ int handleStatusBarTextChanged(long pView, long pArgs) {
12361242
statusTextEvent.display = browser.getDisplay();
12371243
statusTextEvent.widget = browser;
12381244
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+
});
12421250
return COM.S_OK;
12431251
}
12441252

@@ -1267,7 +1275,7 @@ int handleNavigationCompleted(long pView, long pArgs, boolean top) {
12671275
int[] pIsSuccess = new int[1];
12681276
args.get_IsSuccess(pIsSuccess);
12691277
if (pIsSuccess[0] != 0) {
1270-
browser.getDisplay().asyncExec(() -> {
1278+
executeAsynchronously(() -> {
12711279
if (browser.isDisposed()) return;
12721280
LocationEvent event = new LocationEvent(browser);
12731281
event.display = browser.getDisplay();
@@ -1319,7 +1327,7 @@ int handleNewWindowRequested(long pView, long pArgs) {
13191327
args.GetDeferral(ppv);
13201328
ICoreWebView2Deferral deferral = new ICoreWebView2Deferral(ppv[0]);
13211329
inNewWindow = true;
1322-
browser.getDisplay().asyncExec(() -> {
1330+
executeAsynchronously(() -> {
13231331
try {
13241332
if (browser.isDisposed()) return;
13251333
WindowEvent openEvent = new WindowEvent(browser);
@@ -1345,6 +1353,7 @@ int handleNewWindowRequested(long pView, long pArgs) {
13451353
showListener.show(showEvent);
13461354
if (other.browser.isDisposed()) return;
13471355
}
1356+
13481357
}
13491358
} else if (openEvent.required) {
13501359
args.put_Handled(true);
@@ -1426,7 +1435,8 @@ int handleAcceleratorKeyPressed(long pView, long pArgs) {
14261435
}
14271436
} else {
14281437
keyEvent.type = SWT.KeyUp;
1429-
browser.notifyListeners (keyEvent.type, keyEvent);
1438+
executeAsynchronously(() -> browser.notifyListeners (keyEvent.type, keyEvent));
1439+
14301440
if (!keyEvent.doit) {
14311441
args.put_Handled(true);
14321442
}
@@ -1500,6 +1510,10 @@ public boolean setText(String html, boolean trusted) {
15001510
return setWebpageData(URI_FOR_CUSTOM_TEXT_PAGE.toString(), null, null, html);
15011511
}
15021512

1513+
private void executeAsynchronously(Runnable runnable) {
1514+
browser.getDisplay().asyncExec(runnable);
1515+
}
1516+
15031517
private boolean setWebpageData(String url, String postData, String[] headers, String html) {
15041518
// Feature in WebView2. Partial URLs like "www.example.com" are not accepted.
15051519
// Prepend the protocol if it's missing.

0 commit comments

Comments
 (0)