CEF C++ Implementing download handler

我怕爱的太早我们不能终老 提交于 2020-07-23 08:18:05

问题


I am trying to implement the CefDownloadHandler to allow file downloads in my application. When I click a link, the javascript code will redirect the user to a the download link of an excel file. But when I run my application via the CEF, the download does not happen. I have implemented the CefDownloadHandler but that function never seems to call.

Following is the code I have so far

class SimpleHandler : public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler,
public CefDownloadHandler{
public: 
virtual void OnBeforeDownload(CefRefPtr< CefBrowser > browser, CefRefPtr< CefDownloadItem > download_item, const CefString& suggested_name, CefRefPtr< CefBeforeDownloadCallback > callback) OVERRIDE;

}

void SimpleHandler::OnBeforeDownload(CefRefPtr< CefBrowser > browser, CefRefPtr< CefDownloadItem > download_item, const CefString& suggested_name, CefRefPtr< CefBeforeDownloadCallback > callback) {
CEF_REQUIRE_UI_THREAD();
cef_log("simple Hanlder", 200, 1, "download");

callback->Continue(suggested_name, true);
//UNREFERENCED_PARAMETER(browser);
//UNREFERENCED_PARAMETER(download_item);

}

回答1:


FOUND IT!!!!!

It was a stupid mistake. I hope this answer will help someone.

I forgot to get the download handler.

virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() OVERRIDE {
    return this;
}


来源:https://stackoverflow.com/questions/57198461/cef-c-implementing-download-handler

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