Registering Custom ``backend://` scheme is not wor

2019-07-26 16:52发布

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.

1条回答
Melony?
2楼-- · 2019-07-26 17:48

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.

查看更多
登录 后发表回答