Skip to content

Commit 44432b2

Browse files
HeikoKlarevogella
authored andcommitted
Avoid callback release before its usage during Edge instantiation #1013
The handle to a newly instantiated Edge browser is provided via a callback. This callback may be either be invoked synchronously when creating a WebView2 controller (happens on first creation of an Edge browser instance in an application) or asynchronously via a processed OS event (from second creation of an Edge browser instance onwards). The callback is currently released before the OS events are processed, which may cause issues when instantiating more than one Edge browser in a single application. With this change, the callback is only released when it is not required and may not be called anymore. A test instantiating multiple (Edge) browsers in a single application is added to ensure that the asynchronous callback invocation is executed in a test. Contributes to #1013
1 parent 94e9fe5 commit 44432b2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@ static int callAndWait(long[] ppv, ToIntFunction<IUnknown> callable) {
221221
});
222222
ppv[0] = 0;
223223
phr[0] = callable.applyAsInt(completion);
224-
completion.Release();
224+
// "completion" callback may be called asynchronously,
225+
// so keep processing next OS message that may call it
225226
while (phr[0] == COM.S_OK && ppv[0] == 0) {
226227
processNextOSMessage();
227228
}
229+
completion.Release();
228230
return phr[0];
229231
}
230232

@@ -239,10 +241,12 @@ static int callAndWait(String[] pstr, ToIntFunction<IUnknown> callable) {
239241
});
240242
pstr[0] = null;
241243
phr[0] = callable.applyAsInt(completion);
242-
completion.Release();
244+
// "completion" callback may be called asynchronously,
245+
// so keep processing next OS message that may call it
243246
while (phr[0] == COM.S_OK && pstr[0] == null) {
244247
processNextOSMessage();
245248
}
249+
completion.Release();
246250
return phr[0];
247251
}
248252

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,20 @@ public void test_Constructor_asyncParentDisposal() {
280280
assertFalse(browser.isDisposed());
281281
}
282282

283+
@Test
284+
public void test_Constructor_multipleInstantiationsInDifferentShells() {
285+
final int numberOfBrowsers = 5;
286+
for (int i = 0; i < numberOfBrowsers; i++) {
287+
Shell browserShell = new Shell(Display.getCurrent());
288+
Browser browser = createBrowser(browserShell, SWT.EDGE);
289+
assertFalse(browser.isDisposed());
290+
browser.dispose();
291+
assertTrue(browser.isDisposed());
292+
browserShell.dispose();
293+
assertTrue(browserShell.isDisposed());
294+
}
295+
}
296+
283297
@Test
284298
public void test_evalute_Cookies () {
285299
final AtomicBoolean loaded = new AtomicBoolean(false);

0 commit comments

Comments
 (0)