How to perform cookie handler

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.

How to perform cookie handler

Postby LJSong » Thu Feb 26, 2015 9:47 am

Greeting magreenblatt ,and every other good men.

Could you tell me a way to visit and set the cookies for a certain request?
For example:
Now I could intercept the request in OnBeforeResourceLoad function,I can review
The request data,or modify the http header,but how can I visit the cookie of the request?

In CEF3's document I found:
The CefRequestHandler interface provides callbacks for various network-related events incuding authentication, cookie handling, external protocol handling, certificate errors and so on.
<https://code.google.com/p/chromiumembedded/wiki/GeneralUsage>

But which method of CefRequestHandler interface can perform 'cookie handling'?

Sorry for trouble.
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm

Re: How to perform cookie handler

Postby magreenblatt » Fri Feb 27, 2015 11:02 am

Do you want the cookies that are sent with the request when OnBeforeResourceLoad is called or cookies that might be set with the response?
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to perform cookie handler

Postby LJSong » Fri Feb 27, 2015 11:27 am

magreenblatt wrote:Do you want the cookies that are sent with the request when OnBeforeResourceLoad is called or cookies that might be set with the response?

Now I need to read and set cookies with request when OnBeforeResourceLoad is called,and I can read the cookie through CookieManager::VisitUrlCookie to get the cookie of the request in OnBeforeResourceLoad like this:

CefRefPtr<CefCookieManager> cm = CefCookieManger::GetGlobalManager();
cm->VisitUrlCookies(request->GetURL(), true, new Visitor(browser));

Is this a right way? ,now the main problem of mine is the way to set or modify the cookie of the request in OnBeforeResourceLoad.

And furthermore as my app developing ,I guess I need to handle response,so if it's all right,could you please to tell me the both way of handle cookie in request and response?
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm

Re: How to perform cookie handler

Postby magreenblatt » Fri Feb 27, 2015 11:56 am

You should implement CefRequestHandler::GetResourceHandler() and return an implementation of CefResourceHandler. You can then handle the complete request and response. For more information see https://code.google.com/p/chromiumembed ... t_Handling.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to perform cookie handler

Postby LJSong » Thu Apr 02, 2015 3:47 am

magreenblatt wrote:You should implement CefRequestHandler::GetResourceHandler() and return an implementation of CefResourceHandler. You can then handle the complete request and response. For more information see https://code.google.com/p/chromiumembed ... t_Handling.


Hi, magreenblatt :

Maybe I'm a little dull mind, after many days of research ,I still can't implement my own CefResourceHandler class, could you give me a working example of a custom implemention of CefResourceHandler? I had reviewd the implmention of CefStreamResourceHandler,but It handled only local resources.while I had to handle the content from remote server.
Another question: CefResourceHandler contains only four methods:
ProcessRequest
GetResponseHeader
ReadResponse
Cancel

which method inside could I perform cookie handle?

thank your kindly helps!
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm

Re: How to perform cookie handler

Postby LJSong » Thu Apr 02, 2015 4:05 am

Another question:
My app is a browser,after user send the request to the remote server,I need to intercept the response and filter out some content.
In past days ,I had implmented this function in CefLoadHandler::OnLoadingStateChange,I read the source of the browser via CefStringVisitor and parse it's content,modified and load it back,but it is a little trivial and low efficiency, becuase I had to load a same page twice.

So I want to intercept the response through CefResourceHandler,is it possible? or an other more better way?
LJSong
Newbie
 
Posts: 6
Joined: Thu Dec 18, 2014 11:40 pm


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 48 guests

cron