CEF3 can start an URLRequest in render process?

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 can start an URLRequest in render process?

Postby androidriver » Wed Mar 06, 2013 3:55 am

Hi all,
I'm new here. Thanks for the great work!

I'm using CEF3 cef_binary_3.1364.1094_windows for my little app.

Is there some way to init/ start an URLRequest/Request in the render process? I want to get data from an URL when the main browser is browsing some other more important pages.
so this request has to be requested and processed in background and not associated with any browser or frames.

I've searched all the API docs and sample codes in cefclient and urlrequest_unittest.cc and found that all requests are started from LoadURL() LoadRequest() and LoadString() in the CefFrame class.
those methods will lead main browser to load the URL(I think), that is not what I want.

Am I missing something? Or I have to finish this using Winhttp API ?
androidriver
Newbie
 
Posts: 5
Joined: Wed Mar 06, 2013 3:32 am

Re: CEF3 can start an URLRequest in render process?

Postby magreenblatt » Wed Mar 06, 2013 11:49 am

The best source of documentation are the header files. From cef_urlrequest.h:
Code: Select all
///
// Class used to make a URL request. URL requests are not associated with a
// browser instance so no CefClient callbacks will be executed. URL requests
// can be created on any valid CEF thread in either the browser or render
// process. Once created the methods of the URL request object must be accessed
// on the same thread that created it.
///
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 can start an URLRequest in render process?

Postby androidriver » Wed Mar 06, 2013 9:01 pm

Thank you magreenblatt!

I ever notice that sentence in urlrequest header file. but I'm not quite understand.

Is that mean once a CefURLRequest created, it will be automatically send?
like this:
myCefURLrequest = CefURLRequest::Create(myCefrequest,myCefURLrequestclient);
then get response
myCefURLrequest.GetResponse();
androidriver
Newbie
 
Posts: 5
Joined: Wed Mar 06, 2013 3:32 am

Re: CEF3 can start an URLRequest in render process?

Postby magreenblatt » Wed Mar 06, 2013 9:28 pm

androidriver wrote:Thank you magreenblatt!

I ever notice that sentence in urlrequest header file. but I'm not quite understand.

Is that mean once a CefURLRequest created, it will be automatically send?
like this:
myCefURLrequest = CefURLRequest::Create(myCefrequest,myCefURLrequestclient);
then get response
myCefURLrequest.GetResponse();

The CefURLRequestClient callbacks will be executed asynchronously.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 can start an URLRequest in render process?

Postby androidriver » Thu Mar 07, 2013 9:24 am

Thank you for your direction, magreenblatt

I've got my right data from myCefURLRequestClient callback OnRequestComplete()!

But I got trouble next, How do I re-send the same URL request previsous created?

My URL returns different data each time I request it.
I tried recreate a new request with the same URL, but I have only one myCefURLRequestClient , so my app hangs the second time it create the CefURLReqeuset.
Code: Select all
CefRefPtr<CefRequest> myrequest = CefRequest::Create();
tmprequest->SetURL(myurl.str());
CefURLRequest::Create(myprequest, myCefURLRequestClient );
androidriver
Newbie
 
Posts: 5
Joined: Wed Mar 06, 2013 3:32 am

Re: CEF3 can start an URLRequest in render process?

Postby magreenblatt » Thu Mar 07, 2013 12:17 pm

You should be able to re-use the same CefRequest object. Whether you can re-use your CefURLRequestClient object depends on how you implemented it.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF3 can start an URLRequest in render process?

Postby androidriver » Fri Mar 08, 2013 12:59 am

I'm afraid I can't reuse myCefURLRequestClient, I can only judge to create next URL request in Its own delegate's method, or my app will not run in a loop to get my data.
So I may still needs an Load(CefRefPtr<CefURLRequest> request) or ReLoad(CefRefPtr<CefURLRequest> request) method which is not associated with any browser instance either in CefURLRequestClient API.

I've tried using browser->LoadRequest(myRequest) in a loop, my data can always be got in myCefURLRequestClient 's callback. the side effect is my browser got my data shown too!
androidriver
Newbie
 
Posts: 5
Joined: Wed Mar 06, 2013 3:32 am

Re: CEF3 can start an URLRequest in render process?

Postby androidriver » Sat Mar 09, 2013 4:33 am

I've made a reusable myCefURLRequestClient version and finished my function all in render process.

Finally I see memory cost grow when I call CefURLRequest::Create(myprequest, myCefURLRequestClient ) in loop.
So I have to deal with it by hand.

A reload() method is preferred if possible!

Thanks for all your help!
androidriver
Newbie
 
Posts: 5
Joined: Wed Mar 06, 2013 3:32 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 215 guests