CEF3: intercepting a form content

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.

CEF3: intercepting a form content

Postby BadJerry » Thu Feb 14, 2013 11:11 am

Hello,

I am trying to build an ActiveX control using Cef3 - and more particularly trapping the submission of a form, read its content and generate a new html page. I was waiting for the new version of CEF3 because I needed to override OnBeforeBrowse (like I did in CEF1)... unfortunately the new version (3.1364.1094) still does not have it.
Going through the forum, I found that I was meant to use OnBeforeNavigation, return false and navigate to the new content.


But ClientApp::OnBeforeNavigation does not get called in the activeX control. I am setting browser_subprocess_path to CefClient.exe (to avoid the executable that uses the ocx to be started). Should I override ClientApp::OnBeforeNavigation in the CefClient.Exe? But then how do I transmit the form content to the activeX control?

Any pointers (very) welcome!
Jerry
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Re: CEF3: intercepting a form content

Postby magreenblatt » Thu Feb 14, 2013 11:18 am

OnBeforeNavigation is called in the render process. See http://www.chromium.org/developers/how-tos/debugging for debugging tips.

See viewtopic.php?f=6&t=10394 for a discussion of how to use OnBeforeNavigation to filter requests.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3: intercepting a form content

Postby BadJerry » Thu Feb 14, 2013 11:55 am

Thanks for the usefull info and I am reading this

1. Cancel all requests on OnBeforeNavigation.
2. Send a message to the browser process with the relevant request information (URL, headers, etc).
3. Evaluate the information in the browser process and either:
A. Open the link in an external browser, or
B. Ignore the request, or
C. Call CefBrowser::LoadRequest to re-start the request.


2. seems to be the challenging bit ( I am looking at this http://www.chromium.org/developers/design-documents/inter-process-communication )
So I receive the query in the renderer app
I declare a message with one of the IPC_SYNC_MESSAGE_* macros
Is there a way to send binary data with these?
How do I refer to the browser process? something like BrowserThread::current()->Send(new MyMessage(...)); ?
Where do I add IPC_MESSAGE_HANDLER in the broswer side (my activeX)?

I suspect these are very basic questions - sorry about this! But thanks for your continuing help!

Kind regards,
Jerry
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Re: CEF3: intercepting a form content

Postby magreenblatt » Thu Feb 14, 2013 12:04 pm

CEF provides SendProcessMessage / OnProcessMessageReceived functions. See example usage in cefclient.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3: intercepting a form content

Postby BadJerry » Fri Feb 15, 2013 6:19 am

Thanks again for this! I am getting there: I have managed to intercept the form submission in the renderer process, send a message through SendProcessMessage) to the browser, and receive it! Excellent!

Now 2 problems
1) Although I return false in ClientApp::OnBeforeNavigation, I still get redirected to the Form. How can I prevent that? I could delay the message processing but then I get an ugly flash
2) The curse of the CefInitialize /CefShutdown() restart... I thought using Cef3 would handle this better but it does not seem to work
My exe initialises the ActiveX control, and later, when it does not need it, the OS decides to free it and ExitInstance is called in the activeX. If I call CefShutDown() the system hangs and does not return. If I don't call it, the system crashes at the next time I need a chromium browser and call CefInitialize

Amy idea on those 2 points?

Kind regards,
Jerry
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Re: CEF3: intercepting a form content

Postby BadJerry » Fri Feb 15, 2013 11:14 am

First point solved - I should return true in OnBeforeNavigation as indicated in the doc - that I had not read properly - sorry!
I still have that CefInitialize / CefShutdown problem!
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Re: CEF3: intercepting a form content

Postby magreenblatt » Fri Feb 15, 2013 11:29 am

BadJerry wrote:2) The curse of the CefInitialize /CefShutdown() restart... I thought using Cef3 would handle this better but it does not seem to work
My exe initialises the ActiveX control, and later, when it does not need it, the OS decides to free it and ExitInstance is called in the activeX. If I call CefShutDown() the system hangs and does not return. If I don't call it, the system crashes at the next time I need a chromium browser and call CefInitialize

You can't shut down and re-initialize CEF in the same process. You'll have to find some way to work around that.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3: intercepting a form content

Postby BadJerry » Fri Feb 15, 2013 12:13 pm

OK understood - harsh but such is life :)

So I have prevented the unload of all activeX during the run of my exe (in MFC : AfxGetThread()->m_lpfnOleTermOrFreeLib = NULL; ) - that's a bit dirty but it works...

But I have another problem: I suppose it's related to the CefShutdown that hangs (although I do not call it), my application simply does not terminate... no threads are active but it's left in a locked / dormant mode

Any idea? Thaks in advance
Jerry
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Re: CEF3: intercepting a form content

Postby magreenblatt » Fri Feb 15, 2013 12:48 pm

If CEF is keeping your process alive and you're using CefRunMessageLoop() you can call CefQuitMessageLoop() to quit the message loop.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3: intercepting a form content

Postby BadJerry » Mon Feb 18, 2013 6:14 am

Thanks for this.
I am indeed using multi_threaded_message_loop to true but
A call to CefQuitMessageLoop triggers a crash ( in AfxOleTerm) whereas CefShutdown hangs...
BadJerry
Techie
 
Posts: 28
Joined: Fri Nov 02, 2012 7:32 am

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 118 guests