TL;DR - what is the best way to listen to navigation in a browser popup and cancel navigation *before* they happen (if some condition is met) and close the popup?
Long version:
I have spent a fair amount of time trying out various options to do the following:
- Given a URL, load the URL using web contents
- If the URL redirects to a specific URL, I am done; I don't need to create any popups / windows.
- If the URL returns content (200), then create a browser popup and load the WebContents.
- Observe the navigation happening in the popup web contents and *before* navigation happens to a specific URL, cancel the navigation and close the popup.
I am able to do everything except the last step.
For the last step I tried numerous things:
1. WebContentsObserver: tried listening to events like DidStartProvisionalLoadForFrame and ProvisionalChangeToMainFrameUrl. There are two problems with this approach:
- I am not getting a callback for some redirects
- I am not sure if "Obserers" are designed to be able to stop navigation in such callbacks
2. Listening to content::NOTIFICATION_LOAD_START. Again, the same two problems as above - did not get notification for some redirects and not sure if this is designed to cancel navigation.
3. Looked at what extension WebRequest API does: this seems to be hooking up at a very low level than what I need.
4. Looked at
this patch for Clank (thanks to creis@ for the pointer). But again this is hooking up at a very low level, and probably also does things in the renderer while I need to do this in the browser.
5. Tried being a WebContentsDelegate, but cannot be a delegate once I tell the browser to navigate to open existing web contents (since Browser will be the delegate after that point).
Note that I have a
working implementation of this already, but the current implementation uses platform specific window implementations. It works but the problem is that I need to show the URL bar and SSL certificate UI in the window. So I was hoping to use Browser::Navigate method to just open a browser popup. And that is when I ran into the above issues.
Any help or pointers will be greatly appreciated.
-Munjal