Open new browser window with POST data? (can't window.open)

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Open new browser window with POST data? (can't window.open)

Postby HarmlessDave » Fri Jul 11, 2014 6:36 pm

Is it possible to open a new browser window that will pass data using POST instead of GET?

The CEFClient sample creates its popup by executing a JavaScript window.open command, but that will use GET not POST.

https://code.google.com/p/chromiumembed ... m_Requests

The general usage page explains how to set up a request with POST data for the current window, but I don't see the equivalent of IE's navOpenInNewWindow in cef_urlrequest_flags_t to cause the request to spawn a new window.

I've poked around in the CEFClient source a bit, but didn't find any code to directly launch a new process and pass it a CefRequest object.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Open new browser window with POST data? (can't window.op

Postby magreenblatt » Fri Jul 11, 2014 6:45 pm

You can create a new window using CreateBrowser and then load a POST request using browser->GetMainFrame()->LoadRequest.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Open new browser window with POST data? (can't window.op

Postby HarmlessDave » Fri Jul 11, 2014 7:53 pm

Thanks, but will that work to create a new popup window once the main window already exists? I'm very new to CEF but I thought I need to launch a new process with its own host object.

CefBrowserHost::GetBrowser() docs imply the host only supports a single browser object, and CreateBrowser() returns success not a new browser object.

For testing, I'm trying to replace the code in the Tests > Popup Window menu item in CefClient2010:

void RunPopupTest(CefRefPtr<CefBrowser> browser) {

CefWindowInfo info; // probably need to set parent window
CefBrowserHost::CreateBrowser(info, g_handler.get() ); // returns bool not browser object
// ...? ...

I'd expect that to fail since there is an existing browser object. If not, I'd expect GetBrowser() to return the existing window not a new one. Also, without an actual host object I can't call host->GetBrowser().

Sorry if I'm missing something obvious. I did read the Getting Started page as well as doing a Google search.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Open new browser window with POST data? (can't window.op

Postby magreenblatt » Fri Jul 11, 2014 8:07 pm

You can create any number of browser windows using CefBrowserHost::CreateBrowser provided they don't need to script each other via JavaScript. If they do need to script each other than you can use window.open handled via OnBeforePopup or define custom JavaScript bindings that you route via the browser process. Note the CefClient instance passed to CreateBrowser -- that's where you'll do all of your custom processing for that browser instance. See the GeneralUsage wiki page for complete details.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Open new browser window with POST data? (can't window.op

Postby HarmlessDave » Mon Jul 14, 2014 6:11 pm

> You can create a new window using CreateBrowser and then load a POST request using browser->GetMainFrame()->LoadRequest.

Thanks again, I missed that CefBrowserHost::CreateBrowser was asynchronous so I was trying to figure out how I'd do both of those together instead of in separate parts of the code.

I'm used to working with IE's Navigate2() which would let you pass the LoadRequest data as part of the window creation. Instead if I'm understanding things correctly I need to create the new browser with a marker URL like "dopost://post-tasknumber-1234" or "http://cancel-me-then-POST.com?tasknumber=1234" that the new browser detects and then replaces with the real POST.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Open new browser window with POST data? (can't window.op

Postby magreenblatt » Mon Jul 14, 2014 6:18 pm

HarmlessDave wrote: Instead if I'm understanding things correctly I need to create the new browser with a marker URL like "dopost://post-tasknumber-1234" or "http://cancel-me-then-POST.com?tasknumber=1234" that the new browser detects and then replaces with the real POST.

If you're using a 1916 branch build at revision 1766 or newer you can create a browser with an empty URL and call LoadRequest from your handler's OnAfterCreated method. You can associate whatever state you need with the handler instead of encoding it in a dummy URL.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 34 guests