Gabriel
Gabriel

Reputation: 9442

Registering Custom ``backend://` scheme is not working in CEF

In my CEF Application

I register a custom scheme handler for the scheme backend://. As done in scheme_handler example I call in every process (Rendere Process and Browser-Process) AddCustomScheme :

void registerCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
    {
        for(auto& scheme : getCustomSchemes()) // "backend" and "client"
        {
            registrar->AddCustomScheme(scheme,
                                       true /* is standart*/,
                                       false /* is local */,
                                       false /* is display_isolated */,
                                       true /* is secure */,
                                       true /* is cors enabled*/,
                                       false /* is_csp_bypassing*/);
        }
    }

The client:// scheme has also a handler installed.

When I dont call AddCustomScheme with both client and backend. The backend:// handler works (as well as the client handler), but I dont receive any post request data (I send some binary data).

When I use the AddCustomScheme the scheme handlers for client and backend are no more triggered.

How should I setup the custom handler backend such that it receivs post data requests? I also tried to play around with the bools in AddCustomHandler which did not help.

Update: Solution Don't use capital letters in the host name!!

CefRegisterSchemeHandlerFactory("http", "your-host-name", new ... )

Upvotes: 1

Views: 3313

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38814

You are attempting a cross-origin XmlHttpRequest (XHR). You need to configure Cross-origin resource sharing (CORS). Look at CefAddCrossOriginWhitelistEntry.

WebKit does not pass POST data to the request for synchronous XHRs executed on non-HTTP schemes. See the AreMethodAndURLValidForSend() checks in XMLHttpRequest::send() in third_party/WebKit/Source/core/XMLHttpRequest.cpp.

bool XMLHttpRequest::AreMethodAndURLValidForSend() {
  return method_ != HTTPNames::GET && method_ != HTTPNames::HEAD &&
         url_.ProtocolIsInHTTPFamily();
}

If you need to use XHR POST requests you should register your custom handler using the HTTP or HTTPS protocol. Since this is an intentional WebKit design feature it is likely not changed for CEF3.

Upvotes: 2

Related Questions