Skip to content

Commit 542d408

Browse files
committed
[Edge] Add fallback when WebView2 runtime is not present eclipse-platform#2000
When using WebView2 as browser engine in SWT without a WebView2 runtime being available on the system, browser initialization fails. In order to more gracefully handle the case that a system has no such runtime installed (like on some Windows 10 systems), this change introduces an automatic fallback to Internet Explorer in case no WebView2 runtime is found. In addition, it shows an error dialog informing about the missing runtime and showing a link to FAQ about it. Fixes eclipse-platform#2000
1 parent 28fdeb6 commit 542d408

File tree

1 file changed

+30
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser

1 file changed

+30
-4
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/Browser.java

+30-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ public Browser (Composite parent, int style) {
9393
}
9494

9595
style = getStyle ();
96-
webBrowser = new BrowserFactory ().createWebBrowser (style);
97-
if (webBrowser != null) {
98-
webBrowser.setBrowser (this);
99-
webBrowser.create (parent, style);
96+
if (createWebBrowser(parent, style)) {
10097
return;
10198
}
10299
dispose ();
@@ -119,6 +116,35 @@ public Browser (Composite parent, int style) {
119116
SWT.error (SWT.ERROR_NO_HANDLES, null, errMsg);
120117
}
121118

119+
private boolean createWebBrowser(Composite parent, int style) {
120+
webBrowser = new BrowserFactory ().createWebBrowser (style);
121+
if (webBrowser == null) {
122+
return false;
123+
}
124+
webBrowser.setBrowser (this);
125+
try {
126+
webBrowser.create (parent, style);
127+
return true;
128+
} catch (SWTError error) {
129+
boolean isEdge = "win32".equals(SWT.getPlatform()) && (style & SWT.IE) == 0;
130+
if (isEdge && error.code == SWT.ERROR_NOT_IMPLEMENTED) {
131+
return fallBackToIE(parent, style);
132+
}
133+
throw error;
134+
}
135+
}
136+
137+
private boolean fallBackToIE(Composite parent, int style) {
138+
getDisplay().asyncExec(() -> {
139+
MessageBox fallbackInto = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR);
140+
fallbackInto.setText("WebView2 runtime not available");
141+
fallbackInto.setMessage("Falling back to Internet Explorer for browser widgets. For information on how to install WebView2, see https://github.com/eclipse-platform/eclipse.platform/tree/master/docs/FAQ/FAQ_How_do_I_use_Edge-IE_as_the_Browser's_underlying_renderer.md");
142+
fallbackInto.open();
143+
});
144+
System.setProperty(PROPERTY_DEFAULTTYPE, "ie");
145+
return createWebBrowser(parent, (style | SWT.IE) & ~SWT.EDGE);
146+
}
147+
122148
static Composite checkParent (Composite parent) {
123149
String platform = SWT.getPlatform ();
124150
if (!"gtk".equals (platform)) return parent; //$NON-NLS-1$

0 commit comments

Comments
 (0)