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