Skip to content

Commit d9c47ed

Browse files
sratzfedejeanne
authored andcommitted
Help: Embedded Browser: Make 'needModal' workaround more robust
See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2006
1 parent 4d1314b commit d9c47ed

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

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

Lines changed: 26 additions & 14 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 {
@@ -211,19 +209,33 @@ public EmbeddedBrowser(WindowEvent event, Shell parent) {
211209
initialize(browser);
212210
event.browser = browser;
213211

214-
browser.addLocationListener(new LocationAdapter() {
212+
addNeedModalBrowserFunction(browser);
213+
addResetNeedModalLocationListener(browser);
214+
}
215215

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);
222228
modalRequestTime = System.currentTimeMillis();
229+
return null;
223230
}
224-
}
231+
};
225232
});
226233
}
234+
235+
private void addResetNeedModalLocationListener(Browser browser) {
236+
LocationListener.changingAdapter(e -> modalRequestTime = 0);
237+
}
238+
227239
private static void initializeShell(Shell s) {
228240
s.setText(initialTitle);
229241
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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+
if (typeof top.swtHintNeedModalPopup === "function") top.swtHintNeedModalPopup();
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)