Skip to content

Commit 63da75d

Browse files
open other links in local browser.
1 parent a163366 commit 63da75d

File tree

1 file changed

+31
-4
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/feedback

1 file changed

+31
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/feedback/ProvideFeedbackEditor.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55

66
package com.microsoft.azure.toolkit.intellij.common.feedback;
77

8+
import com.intellij.ide.BrowserUtil;
89
import com.intellij.openapi.fileEditor.FileEditorManager;
910
import com.intellij.openapi.project.DumbAware;
1011
import com.intellij.openapi.project.Project;
1112
import com.intellij.openapi.util.Disposer;
1213
import com.intellij.openapi.vfs.VirtualFile;
1314
import com.intellij.ui.jcef.JBCefBrowser;
1415
import com.intellij.ui.jcef.JBCefBrowserBase;
16+
import com.intellij.ui.jcef.JBCefClient;
1517
import com.intellij.ui.jcef.JBCefJSQuery;
1618
import com.intellij.uiDesigner.core.GridConstraints;
1719
import com.microsoft.azure.toolkit.intellij.common.BaseEditor;
1820
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
1921
import org.cef.browser.CefBrowser;
2022
import org.cef.browser.CefFrame;
2123
import org.cef.handler.CefLoadHandlerAdapter;
24+
import org.cef.handler.CefRequestHandlerAdapter;
25+
import org.cef.network.CefRequest;
2226
import org.jetbrains.annotations.Nls;
2327

2428
import javax.annotation.Nonnull;
@@ -32,6 +36,7 @@ public ProvideFeedbackEditor(final Project project, VirtualFile virtualFile) {
3236
super(virtualFile);
3337
final JBCefBrowser jbCefBrowser = new JBCefBrowser("https://www.surveymonkey.com/r/PNB5NBL?mode=simple");
3438
final CefBrowser browser = jbCefBrowser.getCefBrowser();
39+
final JBCefClient client = jbCefBrowser.getJBCefClient();
3540
pnlRoot.add(jbCefBrowser.getComponent(), new GridConstraints(0, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 3, 3, null, null, null, 0));
3641
// Create a JS query instance
3742
this.myJSQueryOpenInBrowser = JBCefJSQuery.create((JBCefBrowserBase) jbCefBrowser);
@@ -42,11 +47,16 @@ public ProvideFeedbackEditor(final Project project, VirtualFile virtualFile) {
4247
});
4348
return new JBCefJSQuery.Response("ok!");
4449
});
50+
client.addRequestHandler(openLinkWithLocalBrowser(), browser);
51+
client.addLoadHandler(modifySubmitButtonInSurveyCollectionPage(), browser);
52+
}
4553

46-
jbCefBrowser.getJBCefClient().addLoadHandler(new CefLoadHandlerAdapter() {
54+
@Nonnull
55+
private CefLoadHandlerAdapter modifySubmitButtonInSurveyCollectionPage() {
56+
return new CefLoadHandlerAdapter() {
4757
@Override
4858
public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
49-
if (!browser.getURL().contains("https://www.surveymonkey.com/r/PNB5NBL")) {
59+
if (!browser.getURL().contains("www.surveymonkey.com/r/PNB5NBL")) {
5060
return;
5161
}
5262
final String js = "window.JavaPanelBridge = {\n" +
@@ -63,7 +73,23 @@ public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
6373
"}";
6474
browser.executeJavaScript(js, browser.getURL(), 0);
6575
}
66-
}, browser);
76+
};
77+
}
78+
79+
@Nonnull
80+
private CefRequestHandlerAdapter openLinkWithLocalBrowser() {
81+
return new CefRequestHandlerAdapter() {
82+
@Override
83+
public boolean onBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, boolean user_gesture, boolean is_redirect) {
84+
if (request.getURL().contains("survey-thanks")) {
85+
return true;
86+
} else if (!request.getURL().contains("www.surveymonkey.com/r/PNB5NBL")) {
87+
BrowserUtil.browse(request.getURL());
88+
return true;
89+
}
90+
return false;
91+
}
92+
};
6793
}
6894

6995
@Override
@@ -72,7 +98,8 @@ public JComponent getComponent() {
7298
}
7399

74100
@Override
75-
public @Nls(capitalization = Nls.Capitalization.Title) @Nonnull String getName() {
101+
public @Nls(capitalization = Nls.Capitalization.Title)
102+
@Nonnull String getName() {
76103
return "Provide Feedback";
77104
}
78105

0 commit comments

Comments
 (0)