问题
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