Issues with CefResourceHandler

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.

Issues with CefResourceHandler

Postby anlumo » Tue Dec 10, 2019 6:34 pm

Hello,

I'm trying to implement my own custom scheme handler, but I'm running into problems. The process flow I have right now is:

Code: Select all
CefSchemeHandlerFactory::Create(browser, frame, "foo", request)
    return new FooResourceHandler
FooResourceHandler.Open(request, handle_request, callback)
    handle_request = true
    return true
FooResourceHandler.GetResponseHeaders(response, response_length, redirect_url)
    response.SetStatus(200)
    response.SetStatusText("OK")
    response.SetMimeType("text/html")
    response_length = 179
FooResourceHandler.Read(buffer, 65536 bytes to read, bytes_read, callback)
    copied 179 bytes into buffer
    bytes_read = 179
    return true
FooResourceHandler.Read(buffer, 65357 bytes to read, bytes_read, callback)
    bytes_read = 0
    return false
FooResourceHandler.Cancel()


Is there something wrong with this flow? Why is Read called twice, even though according to the documentation, the API should know that there's nothing left to read? Why is the operation canceled?

I've verified everything that I'm really setting the values as described above.

In case it's relevant, I'm using the C API, the pseudocode above is translated to the C++ naming scheme.
anlumo
Techie
 
Posts: 14
Joined: Wed Aug 28, 2019 5:34 pm

Re: Issues with CefResourceHandler

Postby Czarek » Tue Dec 10, 2019 10:23 pm

The Read/Skip methods have a bug, I wrote about it in this comment: viewtopic.php?p=43543#p43543
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Issues with CefResourceHandler

Postby anlumo » Wed Dec 11, 2019 8:34 am

Ah, thank you! I'd never have connected the dots there on that post.

So, this sounds like the async API should work, right? The only issue is that the synchronous API doesn't call the async callbacks correctly.
anlumo
Techie
 
Posts: 14
Joined: Wed Aug 28, 2019 5:34 pm

Re: Issues with CefResourceHandler

Postby Czarek » Wed Dec 11, 2019 11:34 am

Try setting bytes_read, call callback->Continue(bytes_read) and return true.

Or use the old ReadResponse() method.

Best to report issue in the tracker.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Issues with CefResourceHandler

Postby anlumo » Thu Dec 12, 2019 12:13 am

Still doesn't work. Now I have:

Code: Select all
CefSchemeHandlerFactory::Create(browser, frame, "foo", request)
    return new FooResourceHandler
FooResourceHandler.Open(request, handle_request, callback)
    handle_request = false
    return false
FooResourceHandler.ProcessRequest(request, callback)
    callback.Continue()
    return true
FooResourceHandler.GetResponseHeaders(response, response_length, redirect_url)
    response.SetStatus(200)
    response.SetStatusText("OK")
    response.SetMimeType("text/html")
    response_length = 179
FooResourceHandler.Cancel()


If I reenable my Read implementation, it gets called before the Cancel call, with the same behavior as in my initial post. I seems that I can't get the API to switch to the old flow. I do implement ReadResponse, but it's never called.

If I implement what you told me (calling Continue from Read and returning true), there's no change in behavior at all.
anlumo
Techie
 
Posts: 14
Joined: Wed Aug 28, 2019 5:34 pm

Re: Issues with CefResourceHandler

Postby Czarek » Thu Dec 12, 2019 3:10 am

People are coming back with the issue, but I don't see anyone taking time to report the issue in the tracker.

See also viewtopic.php?f=6&t=17072
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Issues with CefResourceHandler

Postby anlumo » Thu Dec 12, 2019 9:05 am

Czarek wrote:People are coming back with the issue, but I don't see anyone taking time to report the issue in the tracker.


Here: https://bitbucket.org/chromiumembedded/ ... chemes-non
anlumo
Techie
 
Posts: 14
Joined: Wed Aug 28, 2019 5:34 pm

Re: Issues with CefResourceHandler

Postby Czarek » Thu Dec 12, 2019 12:34 pm

ReadResponse works fine in unit tests, so you must be doing something wrong. Make sure you override the method, check method signature and use the "override" keyword, see: https://github.com/chromiumembedded/cef ... st.cc#L323
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Issues with CefResourceHandler

Postby anlumo » Thu Dec 12, 2019 1:53 pm

As I already mentioned, I'm using the C API, which doesn't have an override keyword. The compiler would also scream at me if the signature wouldn't match.

Maybe the bug is in the cpptoc wrapper?
anlumo
Techie
 
Posts: 14
Joined: Wed Aug 28, 2019 5:34 pm

Re: Issues with CefResourceHandler

Postby salvadordf » Thu Dec 12, 2019 4:21 pm

I'm sorry to intrude but perhaps this could be relevant to this conversation.

The Delphi and Lazarus wrapper called CEF4Delphi also uses the C API and its CefResourceHandler demos work correctly with the ReadResponse method.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain


Return to Support Forum

Who is online

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