13
13
*******************************************************************************/
14
14
package org .eclipse .swt .browser ;
15
15
16
+ import java .util .*;
17
+
16
18
import org .eclipse .swt .*;
19
+ import org .eclipse .swt .program .*;
17
20
import org .eclipse .swt .widgets .*;
18
21
19
22
/**
@@ -93,10 +96,7 @@ public Browser (Composite parent, int style) {
93
96
}
94
97
95
98
style = getStyle ();
96
- webBrowser = new BrowserFactory ().createWebBrowser (style );
97
- if (webBrowser != null ) {
98
- webBrowser .setBrowser (this );
99
- webBrowser .create (parent , style );
99
+ if (createWebBrowser (parent , style )) {
100
100
return ;
101
101
}
102
102
dispose ();
@@ -119,6 +119,70 @@ public Browser (Composite parent, int style) {
119
119
SWT .error (SWT .ERROR_NO_HANDLES , null , errMsg );
120
120
}
121
121
122
+ private boolean createWebBrowser (Composite parent , int style ) {
123
+ webBrowser = new BrowserFactory ().createWebBrowser (style );
124
+ if (webBrowser == null ) {
125
+ return false ;
126
+ }
127
+ webBrowser .setBrowser (this );
128
+ try {
129
+ webBrowser .create (parent , style );
130
+ return true ;
131
+ } catch (SWTError error ) {
132
+ boolean isEdge = "win32" .equals (SWT .getPlatform ()) && (style & SWT .IE ) == 0 ;
133
+ if (isEdge && error .code == SWT .ERROR_NOT_IMPLEMENTED ) {
134
+ WebViewUnavailableDialog .showAsync (getShell ());
135
+ }
136
+ throw error ;
137
+ }
138
+ }
139
+
140
+ private class WebViewUnavailableDialog {
141
+ private record DialogOption (int index , String message ) {};
142
+ private static final DialogOption USE_IE_OPTION = new DialogOption (SWT .YES , "Use IE" );
143
+ private static final DialogOption MORE_INFORMATION_OPTION = new DialogOption (SWT .NO , "Information" );
144
+ private static final DialogOption CANCEL_OPTION = new DialogOption (SWT .CANCEL , "Cancel" );
145
+
146
+ private static final String DIALOG_TITLE = "WebView2 runtime not available" ;
147
+ private static final String DIALOG_MESSAGE = "Do you want to use the legacy Internet Explorer engine (requires reopening browsers)?" ;
148
+ private static final int DIALOG_OPTION_FLAGS = USE_IE_OPTION .index | MORE_INFORMATION_OPTION .index | CANCEL_OPTION .index ;
149
+ private static final Map <Integer , String > DIALOG_OPTION_LABELS = Map .of ( //
150
+ USE_IE_OPTION .index , USE_IE_OPTION .message , //
151
+ MORE_INFORMATION_OPTION .index , MORE_INFORMATION_OPTION .message , //
152
+ CANCEL_OPTION .index , CANCEL_OPTION .message );
153
+
154
+ private static boolean shownOnce ;
155
+
156
+ static void showAsync (Shell parentShell ) {
157
+ if (shownOnce ) {
158
+ return ;
159
+ }
160
+ shownOnce = true ;
161
+ parentShell .getDisplay ().asyncExec (() -> {
162
+ processDialog (parentShell );
163
+ });
164
+ }
165
+
166
+ static private void processDialog (Shell parentShell ) {
167
+ MessageBox fallbackInfoBox = new MessageBox (parentShell , SWT .ICON_ERROR | DIALOG_OPTION_FLAGS );
168
+ fallbackInfoBox .setText (DIALOG_TITLE );
169
+ fallbackInfoBox .setMessage (DIALOG_MESSAGE );
170
+ fallbackInfoBox .setButtonLabels (DIALOG_OPTION_LABELS );
171
+ boolean completed = true ;
172
+ do {
173
+ int result = fallbackInfoBox .open ();
174
+ if (result == MORE_INFORMATION_OPTION .index ) {
175
+ String faqLink = "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" ;
176
+ Program .launch (faqLink );
177
+ completed = false ;
178
+ } else if (result == USE_IE_OPTION .index ) {
179
+ System .setProperty (PROPERTY_DEFAULTTYPE , "ie" );
180
+ DefaultType = SWT .IE ;
181
+ }
182
+ } while (!completed );
183
+ }
184
+ }
185
+
122
186
static Composite checkParent (Composite parent ) {
123
187
String platform = SWT .getPlatform ();
124
188
if (!"gtk" .equals (platform )) return parent ; //$NON-NLS-1$
0 commit comments