Skip to content

Commit 04a8552

Browse files
committed
Help: Embedded Browser: Make 'needModal' workaround more robust
See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2006
1 parent 9e339b2 commit 04a8552

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/browser/embedded/EmbeddedBrowser.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.osgi.util.NLS;
3737
import org.eclipse.swt.SWT;
3838
import org.eclipse.swt.browser.Browser;
39+
import org.eclipse.swt.browser.BrowserFunction;
3940
import org.eclipse.swt.browser.LocationAdapter;
4041
import org.eclipse.swt.browser.LocationEvent;
4142
import org.eclipse.swt.browser.LocationListener;
@@ -166,16 +167,13 @@ public void controlResized(ControlEvent e) {
166167
shell.open();
167168
//browser.setUrl("about:blank");
168169

170+
addNeedModalBrowserFunction(browser);
171+
addResetNeedModalLocationListener(browser);
172+
169173
browser.addLocationListener(new LocationAdapter() {
170174

171175
@Override
172176
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-
}
179177
if (!e.doit && e.location != null
180178
&& e.location.startsWith("https://")) { //$NON-NLS-1$
181179
try {
@@ -224,6 +222,30 @@ public void changing(LocationEvent e) {
224222
}
225223
});
226224
}
225+
226+
// hack to know when help webapp needs modal window
227+
// use a browser function to be more robust
228+
// see also https://github.com/eclipse-platform/eclipse.platform.swt/issues/2006
229+
private void addNeedModalBrowserFunction(Browser browser) {
230+
browser.getDisplay().asyncExec(() -> {
231+
if (browser.isDisposed()) {
232+
return;
233+
}
234+
new BrowserFunction(browser, "needModal") { //$NON-NLS-1$
235+
@Override
236+
public Object function(Object[] arguments) {
237+
super.function(arguments);
238+
modalRequestTime = System.currentTimeMillis();
239+
return null;
240+
}
241+
};
242+
});
243+
}
244+
245+
private void addResetNeedModalLocationListener(Browser browser) {
246+
LocationListener.changingAdapter(e -> modalRequestTime = 0);
247+
}
248+
227249
private static void initializeShell(Shell s) {
228250
s.setText(initialTitle);
229251
final Image[] shellImages = createImages();

ua/org.eclipse.help.webapp/advanced/navActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function quickSearch(quickSearchType, errorMsg) { //search this topic and all s
193193
}
194194
// move the dialog just a bit higher than the middle
195195
if (t-50 > 0) t = t-50;
196-
window.location="javascript://needModal";
196+
top.needModal();
197197
// Defect 593 ends
198198

199199
var quickSearchWindow = window.open("quickSearch.jsp" + parameters, "QuickSearch", "location=no, status=no,resizable=yes,height="+h+",width="+w +",left="+l+",top="+t);

ua/org.eclipse.help.webapp/advanced/searchScoped.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ if (data.isIE()){
183183
// move the dialog just a bit higher than the middle
184184
if (t-50 > 0) t = t-50;
185185
186-
window.location="javascript://needModal";
186+
top.needModal();
187187
advancedDialog = window.open("workingSetManager.jsp?workingSet="+encodeURIComponent(workingSet), "advancedDialog", "resizable=yes,height="+h+",width="+w+",left="+l+",top="+t );
188188
advancedDialog.focus();
189189
}

ua/org.eclipse.help.webapp/advanced/searchSimple.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function saveSelectedBooks(books)
144144
145145
function openAdvanced()
146146
{
147-
window.location="javascript://needModal";
147+
top.needModal();
148148
advancedDialog = window.open("advanced.jsp?searchWord="+encodeURIComponent(document.getElementById("searchWord").value), "advancedDialog", "resizable=yes,height="+h+",width="+w );
149149
advancedDialog.focus();
150150
}

ua/org.eclipse.help.webapp/advanced/views.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if (data.isIE()){
8989
// move the dialog just a bit higher than the middle
9090
if (t-50 > 0) t = t-50;
9191
92-
window.location="javascript://needModal";
92+
top.needModal();
9393
confirmShowAllDialog = window.open("confirmShowAll.jsp", "confirmShowAllDialog", "resizable=no,height="+h+",width="+w+",left="+l+",top="+t );
9494
confirmShowAllDialog.focus();
9595
}
@@ -112,7 +112,7 @@ if (data.isIE()){
112112
// move the dialog just a bit higher than the middle
113113
if (t-50 > 0) t = t-50;
114114
115-
window.location="javascript://needModal";
115+
top.needModal();
116116
selectScopeDialog = window.open("selectScope.jsp", "selectScopeDialog", "resizable=no,height="+h+",width="+w+",left="+l+",top="+t );
117117
selectScopeDialog.focus();
118118
}

ua/org.eclipse.help.webapp/advanced/workingSetManager.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function newWorkingSet() {
224224
%>
225225
// move the dialog just a bit higher than the middle
226226
if (t-50 > 0) t = t-50;
227-
window.location="javascript://needModal";
227+
top.needModal();
228228
workingSetDialog = window.open("workingSet.jsp?operation=add&workingSet="+encodeURIComponent(getWorkingSet()), "workingSetDialog", "resizable=yes,height="+h+",width="+w +",left="+l+",top="+t);
229229
workingSetDialog.focus();
230230
}
@@ -247,7 +247,7 @@ function editWorkingSet() {
247247
// move the dialog just a bit higher than the middle
248248
if (t-50 > 0) t = t-50;
249249
250-
window.location="javascript://needModal";
250+
top.needModal();
251251
workingSetDialog = window.open("workingSet.jsp?operation=edit&workingSet="+encodeURIComponent(getWorkingSet()), "workingSetDialog", "resizable=no,height="+h+",width="+w+",left="+l+",top="+t );
252252
workingSetDialog.focus();
253253
}

0 commit comments

Comments
 (0)