GTW-9956 Add the ability not to follow links on JCEF

GitOrigin-RevId: f7a7ed1e37e4f3d98ea7c53f48a4f6ebcd8512ce
This commit is contained in:
Dmitry Batrak
2024-10-07 13:58:18 +03:00
committed by intellij-monorepo-bot
parent 9767264fbd
commit 33f6503243
3 changed files with 29 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ a:com.intellij.ui.jcef.JBCefBrowserBase
- p:<init>(com.intellij.ui.jcef.JBCefBrowserBuilder):V
- p:createDefaultContextMenuHandler():com.intellij.ui.jcef.JBCefBrowserBase$DefaultCefContextMenuHandler
- createImmediately():V
- disableNavigation():V
- dispose():V
- p:dispose(java.lang.Runnable):V
- getBrowserComponent():java.awt.Component

View File

@@ -25,4 +25,5 @@ public interface CefDelegate {
@NotNull CefClient createClient();
boolean isInitialized(@NotNull CefBrowser browser);
@NotNull CefMessageRouter createMessageRouter(@Nullable CefMessageRouter.CefMessageRouterConfig config);
void disableNavigation(@NotNull CefBrowser browser);
}

View File

@@ -507,6 +507,33 @@ public abstract class JBCefBrowserBase implements JBCefDisposable {
}
}
/**
* Disables navigation in the browser, initiated by user actions (clicks/gestures).
* Equivalent to the following code, but also works in remote development environments:
* <pre>{@code
* browser.getJBCefClient().addRequestHandler(new CefRequestHandlerAdapter() {
* @Override
* public boolean onBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, boolean user_gesture, boolean is_redirect) {
* return user_gesture;
* }
* }, browser.getCefBrowser());
* }</pre>
*/
public void disableNavigation() {
CefDelegate delegate = getCefDelegate();
if (delegate != null) {
delegate.disableNavigation(myCefBrowser);
}
else {
myCefClient.addRequestHandler(new CefRequestHandlerAdapter() {
@Override
public boolean onBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, boolean user_gesture, boolean is_redirect) {
return user_gesture;
}
}, myCefBrowser);
}
}
/**
* Returns the root browser component to be inserted into the UI.
* This component adapts the internal JCEF component to IJ.