|
36 | 36 | import org.eclipse.osgi.util.NLS; |
37 | 37 | import org.eclipse.swt.SWT; |
38 | 38 | import org.eclipse.swt.browser.Browser; |
| 39 | +import org.eclipse.swt.browser.BrowserFunction; |
39 | 40 | import org.eclipse.swt.browser.LocationAdapter; |
40 | 41 | import org.eclipse.swt.browser.LocationEvent; |
41 | 42 | import org.eclipse.swt.browser.LocationListener; |
@@ -166,16 +167,13 @@ public void controlResized(ControlEvent e) { |
166 | 167 | shell.open(); |
167 | 168 | //browser.setUrl("about:blank"); |
168 | 169 |
|
| 170 | + addNeedModalBrowserFunction(browser); |
| 171 | + addResetNeedModalLocationListener(browser); |
| 172 | + |
169 | 173 | browser.addLocationListener(new LocationAdapter() { |
170 | 174 |
|
171 | 175 | @Override |
172 | 176 | public void changing(LocationEvent e) { |
173 | | - // hack to know when help webapp needs modal window |
174 | | - modalRequestTime = 0; |
175 | | - if (e.location != null |
176 | | - && e.location.startsWith("javascript://needModal")) { //$NON-NLS-1$ |
177 | | - modalRequestTime = System.currentTimeMillis(); |
178 | | - } |
179 | 177 | if (!e.doit && e.location != null |
180 | 178 | && e.location.startsWith("https://")) { //$NON-NLS-1$ |
181 | 179 | try { |
@@ -211,19 +209,33 @@ public EmbeddedBrowser(WindowEvent event, Shell parent) { |
211 | 209 | initialize(browser); |
212 | 210 | event.browser = browser; |
213 | 211 |
|
214 | | - browser.addLocationListener(new LocationAdapter() { |
| 212 | + addNeedModalBrowserFunction(browser); |
| 213 | + addResetNeedModalLocationListener(browser); |
| 214 | + } |
215 | 215 |
|
216 | | - @Override |
217 | | - public void changing(LocationEvent e) { |
218 | | - // hack to know when help webapp needs modal window |
219 | | - modalRequestTime = 0; |
220 | | - if (e.location != null |
221 | | - && e.location.startsWith("javascript://needModal")) { //$NON-NLS-1$ |
| 216 | + // hack to know when help webapp needs modal window |
| 217 | + // use a browser function to be more robust |
| 218 | + // see also https://github.com/eclipse-platform/eclipse.platform.swt/issues/2006 |
| 219 | + private void addNeedModalBrowserFunction(Browser browser) { |
| 220 | + browser.getDisplay().asyncExec(() -> { |
| 221 | + if (browser.isDisposed()) { |
| 222 | + return; |
| 223 | + } |
| 224 | + new BrowserFunction(browser, "swtHintNeedModalPopup") { //$NON-NLS-1$ |
| 225 | + @Override |
| 226 | + public Object function(Object[] arguments) { |
| 227 | + super.function(arguments); |
222 | 228 | modalRequestTime = System.currentTimeMillis(); |
| 229 | + return null; |
223 | 230 | } |
224 | | - } |
| 231 | + }; |
225 | 232 | }); |
226 | 233 | } |
| 234 | + |
| 235 | + private void addResetNeedModalLocationListener(Browser browser) { |
| 236 | + LocationListener.changingAdapter(e -> modalRequestTime = 0); |
| 237 | + } |
| 238 | + |
227 | 239 | private static void initializeShell(Shell s) { |
228 | 240 | s.setText(initialTitle); |
229 | 241 | final Image[] shellImages = createImages(); |
|
0 commit comments