Add permission callback for user-initated downloads (fixes issue #3183)

This change adds a CefDownloadHandler::CanDownload callback for optionally
blocking user-initiated downloads (e.g. alt + link click or link click that
returns a `Content-Disposition: attachment` response from the server).

To test:
- Run `ceftests --gtest_filter=DownloadTest.*`.
- Run `cefclient --hide-controls`. User-initiated downloads will be blocked.
This commit is contained in:
Marshall Greenblatt
2022-03-22 17:40:28 -04:00
parent 2f5838eaaa
commit 6d7a680187
16 changed files with 280 additions and 38 deletions

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=496b226297ba7d5fa5e7e7bd4117c417e26fae59$
// $hash=89f651178065dbc03e70e763085bf9125dda6640$
//
#include "libcef_dll/cpptoc/download_handler_cpptoc.h"
@ -23,6 +23,40 @@ namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK
download_handler_can_download(struct _cef_download_handler_t* self,
cef_browser_t* browser,
const cef_string_t* url,
const cef_string_t* request_method) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return 0;
// Verify param: request_method; type: string_byref_const
DCHECK(request_method);
if (!request_method)
return 0;
// Execute
bool _retval = CefDownloadHandlerCppToC::Get(self)->CanDownload(
CefBrowserCToCpp::Wrap(browser), CefString(url),
CefString(request_method));
// Return type: bool
return _retval;
}
void CEF_CALLBACK
download_handler_on_before_download(struct _cef_download_handler_t* self,
cef_browser_t* browser,
@ -97,6 +131,7 @@ download_handler_on_download_updated(struct _cef_download_handler_t* self,
// CONSTRUCTOR - Do not edit by hand.
CefDownloadHandlerCppToC::CefDownloadHandlerCppToC() {
GetStruct()->can_download = download_handler_can_download;
GetStruct()->on_before_download = download_handler_on_before_download;
GetStruct()->on_download_updated = download_handler_on_download_updated;
}