Navigation from PDF is not triggering OnBeforeBrowse

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Navigation from PDF is not triggering OnBeforeBrowse

Postby AdishreeM » Fri Jul 10, 2020 7:52 am

My question is related to this issue:

My requirement is to check any url being loaded and see if they are whitelisted. That functionality is added in OnBeforeBrowse, but currently the pdf links are escaping the whitelist checks.

I am not very familiar with the control flow in CEF, so I am posting what I found, in case anybody identifies the issue or can provide a fix or workaround.

Currently CEF (since 3945) navigates to a pdf link in a different path than what is used in (3904 or before) without hitting OnBeforeBrowse or any other CEF functions that are re-defined in client browser code that I looked into.
The URL bar still shows the pdf url instead of the linked url where we navigated to.
The DevTools show the html corresponding to the pdf even after the linked site is loaded.
If the PDF is inside an iframe, the new page opens inside the iframe. Expected behaviour is new page always loading in main frame.
And when we press the Back/Reload/Close button, RemoveFrame function is called to remove a non-existing frame.

The path difference in 3904 vs 4044 I could find (on clicking pdf link):

1. In 3904, on clicking the link, RenderFrameHostImpl::OnOpenURL is called which in turn calls CefBrowserHostImpl::OpenURLFromTab
and goes through NavigationControllerImpl::LoadURL ---> FrameTreeNode::CreatedNavigationRequest to ClientAppBrowser::OnBeforeChildProcessLaunch.
But in 4044, RenderFrameHostImpl::BeginNavigation is called which calls NavigatorImpl::OnBeginNavigation ---> FrameTreeNode::CreatedNavigationRequest and reaches ClientAppBrowser::OnBeforeChildProcessLaunch.

2. After this, in 3904, the call trace is FrameTreeNode::DidStartLoading ---> WebContentsImpl::LoadingStateChanged ---> CefBrowserHostImpl::LoadingStateChanged ---> ClientHandler::OnLoadingStateChange
For 4044, it is mostly same but the last call to client handler's OnLoadingStateChanged is not triggered.

3. After load related calls, OnBeforeBrowse is called due to FrameHostMsg_BeforeUnload_ACK in 3904 which goes through other functions like OnBeforeResourceLoad etc. But these calls are not made in 4044.

4. Next, ClientAppBrowser::OnRenderProcessThreadCreated is called in a similar way for both 3904 and 4044. After that the path taken looks different.
In 3904 there are a bunch of calls to RenderFrameHostImpl::DidCommitNaviagtion, RenderFrameHostManager::SwapOutOldFrame, RenderFrameDeleted, BrowserInfo::RemoveFrame, in that order.
In 4044, there are calls to RenderFrameHostImpl::DidCommitNaviagtion and RenderFrameHostManager::UnloadFrame (new implementation of SwapOutOldFrame) but no calls to RenderFrameDeleted etc.

Is there a potential workaround for this?
Posts: 4
Joined: Tue Jan 14, 2020 5:23 am

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 38 guests