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

匆匆过客 提交于 2019-12-24 14:21:50

问题


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:


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.



来源:https://stackoverflow.com/questions/48811756/registering-custom-backend-scheme-is-not-working-in-cef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!