diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java index 24b1c431c53..0ffba2d3ede 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java @@ -297,6 +297,10 @@ ICoreWebView2 initializeWebView(ICoreWebView2Controller controller) { return webView; } + private void abortInitialization() { + webViewFuture.cancel(true); + } + private void initializeWebView_2(ICoreWebView2 webView) { long[] ppv = new long[1]; int hr = webView.QueryInterface(COM.IID_ICoreWebView2_2, ppv); @@ -486,14 +490,36 @@ public void create(Composite parent, int style) { int hr = containingEnvironment.environment().QueryInterface(COM.IID_ICoreWebView2Environment2, ppv); if (hr == COM.S_OK) environment2 = new ICoreWebView2Environment2(ppv[0]); // The webview calls are queued to be executed when it is done executing the current task. - IUnknown setupBrowserCallback = newCallback((result, pv) -> { - if ((int)result == COM.S_OK) { + containingEnvironment.environment().CreateCoreWebView2Controller(browser.handle, getSetupCallback()); +} + +private IUnknown getSetupCallback() { + return newCallback((result, pv) -> { + if (result == OS.HRESULT_FROM_WIN32(OS.ERROR_INVALID_STATE)) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " Edge instance with same data folder but different environment options already exists"); + } + switch ((int) result) { + case COM.S_OK: new IUnknown(pv).AddRef(); + setupBrowser((int)result, pv); + break; + case COM.E_WRONG_THREAD: + error(SWT.ERROR_THREAD_INVALID_ACCESS, (int)result); + break; + case COM.E_ABORT: + webViewProvider.abortInitialization(); + break; + default: + System.err.println("Edge initialization failed, retrying"); + webViewProvider.abortInitialization(); + if (environment2 != null) { + environment2.Release(); + } + create(null, 0); + break; } - setupBrowser((int)result, pv); return COM.S_OK; }); - containingEnvironment.environment().CreateCoreWebView2Controller(browser.handle, setupBrowserCallback); } void setupBrowser(int hr, long pv) { @@ -501,15 +527,6 @@ void setupBrowser(int hr, long pv) { browserDispose(new Event()); return; } - switch (hr) { - case COM.S_OK: - break; - case COM.E_WRONG_THREAD: - error(SWT.ERROR_THREAD_INVALID_ACCESS, hr); - break; - default: - error(SWT.ERROR_NO_HANDLES, hr); - } long[] ppv = new long[] {pv}; controller = new ICoreWebView2Controller(ppv[0]); final ICoreWebView2 webView = webViewProvider.initializeWebView(controller); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/COM.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/COM.java index 6416ab2a38a..49a192c6605 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/COM.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/COM.java @@ -180,6 +180,7 @@ public class COM extends OS { public static final int DV_E_STGMEDIUM = -2147221402; public static final int DV_E_TYMED = -2147221399; public static final int DVASPECT_CONTENT = 1; + public static final int E_ABORT = 0x80004004; public static final int E_ACCESSDENIED = 0x80070005; public static final int E_FAIL = -2147467259; public static final int E_INVALIDARG = -2147024809; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java index c7b704ddcab..ec5e045c114 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java @@ -456,6 +456,7 @@ public class OS extends C { public static final int EN_CHANGE = 0x300; public static final int EP_EDITTEXT = 1; public static final int ERROR_FILE_NOT_FOUND = 0x2; + public static final int ERROR_INVALID_STATE = 0x139F; public static final int ERROR_NO_MORE_ITEMS = 0x103; public static final int ERROR_CANCELED = 0x4C7; public static final int ESB_DISABLE_BOTH = 0x3; diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java index a01ae59d453..4b8c1c6132a 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java @@ -241,16 +241,16 @@ public void tearDown() { printThreadsInfo(); } } -// if (isEdge) { -// // wait for and process pending events to properly cleanup Edge browser resources -// do { -// processUiEvents(); -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// } -// } while (Display.getCurrent().readAndDispatch()); -// } + if (isEdge) { + // wait for and process pending events to properly cleanup Edge browser resources + do { + processUiEvents(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } while (Display.getCurrent().readAndDispatch()); + } if (SwtTestUtil.isGTK) { int descriptorDiff = reportOpenedDescriptors(); if(descriptorDiff > 0) {