Registering custom schema handlers with CEF 2357

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.

Registering custom schema handlers with CEF 2357

Postby nambi » Tue Aug 18, 2015 6:57 am

Hi,

We are working in a application which uses CEF.

We have schema handler added for "qrc" URL schema in our application. In order to register the schema to URL context, we called the function CefRegisterSchemeHandlerFactory() from our application to CEF. This automatically add our schema handler to CefUrlRequestManager. This worked with 2062.

When we used the same API with CEF 2357, the registration is happening with CEF global context and not with the URL request manager. Due to this, we are failing with error code -302 in chromium.

Please share do we have any API from CEF 2357 which can be used to register our custom schema handlers. Thanks.

Regards,
Nambi
nambi
Newbie
 
Posts: 2
Joined: Mon Jun 23, 2014 6:34 am

Re: Registering custom schema handlers with CEF 2357

Postby magreenblatt » Tue Aug 18, 2015 10:24 am

You also need to implement CefApp::OnRegisterCustomSchemes in all processes.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Registering custom schema handlers with CEF 2357

Postby magreenblatt » Tue Aug 18, 2015 11:55 am

How are you implementing OnRegisterCustomSchemes currently? Where are you calling CefRegisterSchemeHandlerFactory from currently and how is that implemented?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Registering custom schema handlers with CEF 2357

Postby azam » Tue Aug 18, 2015 12:37 pm

void ClientApp::OnRegisterCustomSchemes(
CefRefPtr<CefSchemeRegistrar> registrar) {
registrar->AddCustomScheme(
"custom", false, false, false);
}

class ClientSchemeHandler : public CefResourceHandler {

bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) OVERRIDE {
...
}

void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& responseLength,
CefString& redirectUrl) OVERRIDE {
...
}

bool ReadResponse(void* dataOut,
int bytesToRead,
int& bytesRead,
CefRefPtr<CefCallback> callback) OVERRIDE {
...
}

bool CanGetCookie(const CefCookie& cookie) OVERRIDE {
return false;
}

bool CanSetCookie(const CefCookie& cookie) OVERRIDE {
return false;
}

void Cancel() OVERRIDE {
...
}

private:
...
IMPLEMENT_REFCOUNTING(ClientSchemeHandler);

}

class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
virtual CefRefPtr<CefResourceHandler> Create(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE {
if (scheme_name == "custom")
return new ClientSchemeHandler;
return NULL;
}
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory);
};


void ClientCEFSchemeHandler::registerSchemeHandlerFactory() {
CefRegisterSchemeHandlerFactory(
"custom",
"resources",
new ClientSchemeHandlerFactory);
}

ClientCEFSchemeHandler::registerSchemeHandlerFactory() function is called from the browser thread immediately after CefInitialize() call.
azam
Techie
 
Posts: 11
Joined: Wed Jun 04, 2014 4:31 am

Re: Registering custom schema handlers with CEF 2357

Postby magreenblatt » Tue Aug 18, 2015 12:44 pm

azam wrote:void ClientApp::OnRegisterCustomSchemes(
CefRefPtr<CefSchemeRegistrar> registrar) {
registrar->AddCustomScheme(
"custom", false, false, false);
}

You are registering the scheme as non-standard (first boolean value), which is likely your issue. See the documentation for AddCustomScheme.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Registering custom schema handlers with CEF 2357

Postby azam » Tue Aug 18, 2015 1:02 pm

I modified the code as below but still same problem.

void ClientApp::OnRegisterCustomSchemes(
CefRefPtr<CefSchemeRegistrar> registrar) {
registrar->AddCustomScheme(
"custom", true, false, false);
}
azam
Techie
 
Posts: 11
Joined: Wed Jun 04, 2014 4:31 am

Re: Registering custom schema handlers with CEF 2357

Postby azam » Tue Aug 18, 2015 1:05 pm

in CEF1916 the same code worked fine. We saw this problem only when we moved to CEF 2357.
azam
Techie
 
Posts: 11
Joined: Wed Jun 04, 2014 4:31 am

Re: Registering custom schema handlers with CEF 2357

Postby magreenblatt » Tue Aug 18, 2015 1:08 pm

Your original post mentions "qrc" URL schema, however the above code lists "custom" as the schema. What URL are you loading and what schema are you registering?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Registering custom schema handlers with CEF 2357

Postby azam » Tue Aug 18, 2015 1:15 pm

We use "qrc" and same is being used in our code. I have just replaced the "qrc" with "custom" in the code that I posted here.

The url that we use is

qrc://resources/test.html
azam
Techie
 
Posts: 11
Joined: Wed Jun 04, 2014 4:31 am

Re: Registering custom schema handlers with CEF 2357

Postby magreenblatt » Tue Aug 18, 2015 1:20 pm

azam wrote:The url that we use is

qrc://resources/test.html

How are you loading this URL?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 50 guests