Skip to content

Commit ac555f6

Browse files
committed
Fix "no more handles" exception during Edge browser creation
The Edge browser creation uses Display.readAndDispath() to process the OS events for browser instantiation. When there are other asynchronous executions scheduled while the browser is being initialized, they may be processed in between the processing of browser-instantiating OS events if too much time elapses between them. In case such an asynchronous execution changes a state that makes the browser instantiation fail, such as disposing the composite parent of the browser, an exception occurs. In order to avoid the processing of asynchronous executions during browser instantiation, the change ensures that readAndDisplay() is only called when an OS event is present to be processed.
1 parent 2b9b6b4 commit ac555f6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static int callAndWait(long[] ppv, ToIntFunction<IUnknown> callable) {
224224
completion.Release();
225225
Display display = Display.getCurrent();
226226
while (phr[0] == COM.S_OK && ppv[0] == 0) {
227-
if (!display.readAndDispatch()) display.sleep();
227+
processNextOSMessage();
228228
}
229229
return phr[0];
230230
}
@@ -243,11 +243,20 @@ static int callAndWait(String[] pstr, ToIntFunction<IUnknown> callable) {
243243
completion.Release();
244244
Display display = Display.getCurrent();
245245
while (phr[0] == COM.S_OK && pstr[0] == null) {
246-
if (!display.readAndDispatch()) display.sleep();
246+
processNextOSMessage();
247247
}
248248
return phr[0];
249249
}
250250

251+
private static void processNextOSMessage() {
252+
Display display = Display.getCurrent();
253+
MSG msg = new MSG();
254+
while (!OS.PeekMessage (msg, 0, 0, 0, OS.PM_NOREMOVE)) {
255+
display.sleep();
256+
}
257+
display.readAndDispatch();
258+
}
259+
251260
static ICoreWebView2CookieManager getCookieManager() {
252261
if (Instances.isEmpty()) {
253262
SWT.error(SWT.ERROR_NOT_IMPLEMENTED, null, " [WebView2: cookie access requires a Browser instance]");

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
268268
browser = createBrowser(null, SWT.NONE); // Should throw.
269269
}
270270

271+
/**
272+
* Regression test for issue #339: [Edge] No more handle exceptions from Edge browser
273+
*/
274+
@Test
275+
public void test_Contructor_asyncParentDisposal() {
276+
Display.getCurrent().asyncExec(() -> {
277+
shell.dispose();
278+
});
279+
Browser browser = createBrowser(shell, SWT.EDGE);
280+
assertFalse(browser.isDisposed());
281+
}
271282

272283
@Test
273284
public void test_evalute_Cookies () {

0 commit comments

Comments
 (0)