Skip to content

Commit

Permalink
Avoid callback release before its usage during Edge instantiation ecl…
Browse files Browse the repository at this point in the history
…ipse-platform#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
eclipse-platform#1013
  • Loading branch information
HeikoKlare committed Jan 30, 2024
1 parent 2cdfd97 commit 410bfbc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ static int callAndWait(long[] ppv, ToIntFunction<IUnknown> callable) {
});
ppv[0] = 0;
phr[0] = callable.applyAsInt(completion);
completion.Release();
// "completion" callback may be called asynchronously,
// so keep processing next OS message that may call it
while (phr[0] == COM.S_OK && ppv[0] == 0) {
processNextOSMessage();
}
completion.Release();
return phr[0];
}

Expand All @@ -239,10 +241,12 @@ static int callAndWait(String[] pstr, ToIntFunction<IUnknown> callable) {
});
pstr[0] = null;
phr[0] = callable.applyAsInt(completion);
completion.Release();
// "completion" callback may be called asynchronously,
// so keep processing next OS message that may call it
while (phr[0] == COM.S_OK && pstr[0] == null) {
processNextOSMessage();
}
completion.Release();
return phr[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ public void test_Constructor_asyncParentDisposal() {
assertFalse(browser.isDisposed());
}

@Test
public void test_Constructor_multipleInstantiationsInDifferentShells() {
final int numberOfBrowsers = 5;
for (int i = 0; i < numberOfBrowsers; i++) {
Shell browserShell = new Shell(Display.getCurrent());
Browser browser = createBrowser(browserShell, SWT.EDGE);
assertFalse(browser.isDisposed());
browser.dispose();
assertTrue(browser.isDisposed());
browserShell.dispose();
assertTrue(browserShell.isDisposed());
}
}

@Test
public void test_evalute_Cookies () {
final AtomicBoolean loaded = new AtomicBoolean(false);
Expand Down

0 comments on commit 410bfbc

Please sign in to comment.