We have already disabled backspace on non-text input using javascript so that we don't navigate to the previous page of our application. The issue is that our CEF application can load an iframe that we have no control over (so disabling backspace through the javascript won't work here). We don't care if they use backwards navigation to go through the iframe, but if they launch an iframe and hit backspace on the first page of that iframe, they are incorrectly taken to the previous page of our CEF application. I know CEF3 doesn't support disabling history so I have looked through the forums for a couple of different approaches:
1. OnBeforeNavigation: http://www.magpcss.org/ceforum/viewtopi ... =6&t=10780
Tried this: "For CEF3 return true if navigation_type == NAVIGATION_BACK_FORWARD in CefRenderProcessHandler::OnBeforeNavigate." which didn't quite work. The call was being hit and I was returning true, but backwards navigation was still allowed. Here is the actual code used.
- Code: Select all
bool SimpleApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRenderProcessHandler::NavigationType navigation_type, bool is_redirect)
{
if (navigation_type == NAVIGATION_BACK_FORWARD)
{
return true;
}
return false;
}
2. OnPreKeyEvent: http://www.magpcss.org/ceforum/viewtopi ... =6&t=10312
Tried to catch the backspace key event, which worked, but have no way of knowing what UI element the focus is on from CEF. While I can disable backspace as a whole, I can't find a good way to allow it on text input or other appropriate places. Was trying to think of ways to get that information from the js, but seemed too hacky for what we wanted.
3. OnBeforeBrowse: http://www.magpcss.org/ceforum/viewtopi ... =6&t=11626
Similar to OnBeforeNavigation, I attempt to disable backwards navigation by returning true.
- Code: Select all
bool CefSimpleHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool is_redirect)
{
CefRequest::TransitionType type = request->GetTransitionType();
if ((unsigned int)type & TT_FORWARD_BACK_FLAG)
{
return true;
}
return false;
}
#3 OnBeforeBrowse is actually the closest one to a working solution that I have tried. If we traverse through the iframe to another page, pressing backspace doesn't trigger backwards navigation. The problem is when we first launch the iframe and hit backspace, we are incorrectly taken to the previous page of our CEF application. Not sure why it works for the first case but not the second, but any insight or advice would be greatly appreciated! Please let me know if there is another approach I can take, if it looks like the above attempts should have worked.
Thanks!