Then using request handler web-page do not loading...

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.

Then using request handler web-page do not loading...

Postby senya » Sun Oct 28, 2018 10:48 am

Hello again.
My previous problem solved: 'Create method of class CefSchemeHandlerFactory not called'
viewtopic.php?f=6&t=16344

But immediately a new difficulty appeared.

If i use request handling
Code: Select all
SerfiumCefApp::OnContextInitialized() {
CefRegisterSchemeHandlerFactory(CefString("https"),CefString(""),new SerfiumCefSchemeHandlerFactory());
}

then web-page do not load into browser's rect, only blank white space seeing.

Screencast illustrating the situation (42 sec video):
https://drive.google.com/file/d/1px98wp ... sp=sharing

Without call 'CefRegisterSchemeHandlerFactory' everything works well. Web-pages do not load to browser also with minimal amount of code required for request handling.

Again I have difficulty and seek advice 0_0
Sergey, developer from Moscow region.
It's hot here today
https://docs.zoho.eu/file/40henad156481 ... 29fb3a8ebe
senya
Mentor
 
Posts: 54
Joined: Mon Sep 18, 2017 2:58 pm

Re: Then using request handler web-page do not loading...

Postby Czarek » Sun Oct 28, 2018 12:09 pm

You have to provide an implementation for SerfiumSchemeHandler methods. Currently they are empty thus you get a null request. What are you trying to accomplish?
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: Then using request handler web-page do not loading...

Postby senya » Sun Oct 28, 2018 1:32 pm

Czarek wrote:You have to provide an implementation for SerfiumSchemeHandler methods. Currently they are empty thus you get a null request. What are you trying to accomplish?


I'm trying to edit User-Agent string of request header.

Code: Select all
bool SerfiumSchemeHandler::ProcessRequest(CefRefPtr<CefRequest> request,
                                          CefRefPtr<CefCallback> callback) {
    CEF_REQUIRE_IO_THREAD();

    bool handled = true;

    // Get request header
    CefRequest::HeaderMap vHeaderMap;
    request->GetHeaderMap(vHeaderMap);
    qDebug() << Q_FUNC_INFO;
    qDebug() << "vHeaderMap";
    CefRequest::HeaderMap::iterator i = vHeaderMap.begin();
    int c {0};
    while (i != vHeaderMap.end())
    {
        qDebug() << "c" << c++ << "first" << SerfiumCefMisc::utils::cefStringToQString(i->first) <<
                    "second" << SerfiumCefMisc::utils::cefStringToQString(i->second);
        i++;
    }

    // Indicate that the headers are available.
    callback->Continue();   

    return true;
}
//------------------


Code: Select all
// Implementation of the scheme handler for ... requests.
class SerfiumSchemeHandler : public CefResourceHandler {
public:
    SerfiumSchemeHandler() {}
    ~SerfiumSchemeHandler() OVERRIDE {qDebug() << Q_FUNC_INFO;}

    bool ProcessRequest(CefRefPtr<CefRequest> request,
                        CefRefPtr<CefCallback> callback) OVERRIDE;

    void Cancel() OVERRIDE { CEF_REQUIRE_IO_THREAD(); qDebug() << Q_FUNC_INFO;}

    void GetResponseHeaders(CefRefPtr<CefResponse> response,
                            int64& response_length,
                            CefString& redirectUrl) OVERRIDE {qDebug() << Q_FUNC_INFO;}

    bool ReadResponse(void* data_out,
                      int bytes_to_read,
                      int& bytes_read,
                      CefRefPtr<CefCallback> callback) OVERRIDE {qDebug() << Q_FUNC_INFO; return false; }

    virtual bool CanGetCookie(const CefCookie& cookie) OVERRIDE {qDebug() << Q_FUNC_INFO; return true; }
    virtual bool CanSetCookie(const CefCookie& cookie) OVERRIDE {qDebug() << Q_FUNC_INFO; return true; }

private:
    IMPLEMENT_REFCOUNTING(SerfiumSchemeHandler);
    DISALLOW_COPY_AND_ASSIGN(SerfiumSchemeHandler);
};
//------------------


I got null request? I think if i call
Code: Select all
callback->Continue();
and return true in 'CefResourceHandler::ProcessRequest' method then it will be normal request.
Sergey, developer from Moscow region.
It's hot here today
https://docs.zoho.eu/file/40henad156481 ... 29fb3a8ebe
senya
Mentor
 
Posts: 54
Joined: Mon Sep 18, 2017 2:58 pm

Re: Then using request handler web-page do not loading...

Postby Czarek » Sun Oct 28, 2018 2:07 pm

You have to implement all methods. Read documentation comments in cef_resource_handler.h.
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: Then using request handler web-page do not loading...

Postby senya » Mon Oct 29, 2018 1:34 pm

Czarek wrote:You have to implement all methods. Read documentation comments in cef_resource_handler.h.

Aah, now I understand - the chromium framework is designed so that you need to manually make a request to the site within the method. :)
When I look at such classes, I think that you can just add a few lines of code. But it turns out that you need to fully implement sending a request to the web-site and getting the result.
Sergey, developer from Moscow region.
It's hot here today
https://docs.zoho.eu/file/40henad156481 ... 29fb3a8ebe
senya
Mentor
 
Posts: 54
Joined: Mon Sep 18, 2017 2:58 pm


Return to Support Forum

Who is online

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