From 3827f817c728d60361a9934030780ba9ee92017d Mon Sep 17 00:00:00 2001 From: Ananyo Maiti Date: Tue, 7 May 2019 16:22:16 +0000 Subject: [PATCH] Support override of client id for file scanning (fixes issue #2368). --- include/cef_api_hash.h | 10 +++++----- include/internal/cef_types.h | 8 ++++++++ include/internal/cef_types_wrappers.h | 4 ++++ libcef/browser/download_manager_delegate.cc | 12 ++++++++++++ libcef/browser/download_manager_delegate.h | 1 + tests/cefclient/cefclient_win.cc | 4 ++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 1d0be326f..c1f28bb5a 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -34,7 +34,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=dd6129d832b33b4da283d86722ba5a7b743a15a5$ +// $hash=e9ff73cc80e162b173ecd1a62b0cb48f9e46de99$ // #ifndef CEF_INCLUDE_API_HASH_H_ @@ -47,13 +47,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "91bb58af264779076e95dfd1a63033bc7da296cd" +#define CEF_API_HASH_UNIVERSAL "fa535acbd95d3d7a25e43b015dfea09700d7bf72" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "7cacaf3f958d22f84e4ee6b5216dc5ccc4c18e31" +#define CEF_API_HASH_PLATFORM "a729d5a21d1f3655db514d47093abe59794f5f26" #elif defined(OS_MACOSX) -#define CEF_API_HASH_PLATFORM "b471cf826966f5917fd3855996c8998898df2334" +#define CEF_API_HASH_PLATFORM "6b77f0976c19ba6b15a8a054fe35bde0ba2cf89d" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "1b0a73214b4f50b23e2dab96d7a1d6def2c195dc" +#define CEF_API_HASH_PLATFORM "c21503860303873c2148e3740d6c407ae6ece32b" #endif #ifdef __cplusplus diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 9d5d2dc0e..8e654126d 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -412,6 +412,14 @@ typedef struct _cef_settings_t { // CefRequestContextSettings.accept_language_list value. /// cef_string_t accept_language_list; + + /// + // GUID string used for identifying the application. This is passed to the + // system AV function for scanning downloaded files. By default, the GUID + // will be an empty string and the file will be treated as an untrusted + // file when the GUID is empty. + /// + cef_string_t application_client_id_for_file_scanning; } cef_settings_t; /// diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index 8144c4e52..8ac97800c 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -553,6 +553,7 @@ struct CefSettingsTraits { cef_string_clear(&s->resources_dir_path); cef_string_clear(&s->locales_dir_path); cef_string_clear(&s->accept_language_list); + cef_string_clear(&s->application_client_id_for_file_scanning); } static inline void set(const struct_type* src, @@ -603,6 +604,9 @@ struct CefSettingsTraits { cef_string_set(src->accept_language_list.str, src->accept_language_list.length, &target->accept_language_list, copy); + cef_string_set(src->application_client_id_for_file_scanning.str, + src->application_client_id_for_file_scanning.length, + &target->application_client_id_for_file_scanning, copy); } }; diff --git a/libcef/browser/download_manager_delegate.cc b/libcef/browser/download_manager_delegate.cc index d189a64d6..1151c5a00 100644 --- a/libcef/browser/download_manager_delegate.cc +++ b/libcef/browser/download_manager_delegate.cc @@ -5,6 +5,7 @@ #include "libcef/browser/download_manager_delegate.h" #include "include/cef_download_handler.h" +#include "libcef/browser/context.h" #include "libcef/browser/download_item_impl.h" #include "libcef/browser/thread_util.h" @@ -14,6 +15,7 @@ #include "base/path_service.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/common/chrome_constants.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/download_item_utils.h" #include "content/public/browser/web_contents.h" @@ -387,6 +389,16 @@ void CefDownloadManagerDelegate::GetNextId( callback.Run(next_id++); } +std::string CefDownloadManagerDelegate::ApplicationClientIdForFileScanning() + const { + const CefSettings& settings = CefContext::Get()->settings(); + if (settings.application_client_id_for_file_scanning.length > 0) { + return CefString(&settings.application_client_id_for_file_scanning) + .ToString(); + } + return std::string(); +} + void CefDownloadManagerDelegate::OnBrowserDestroyed( CefBrowserHostImpl* browser) { ItemBrowserMap::iterator it = item_browser_map_.begin(); diff --git a/libcef/browser/download_manager_delegate.h b/libcef/browser/download_manager_delegate.h index 4fb07253c..058c28301 100644 --- a/libcef/browser/download_manager_delegate.h +++ b/libcef/browser/download_manager_delegate.h @@ -39,6 +39,7 @@ class CefDownloadManagerDelegate : public download::DownloadItem::Observer, download::DownloadItem* item, const content::DownloadTargetCallback& callback) override; void GetNextId(const content::DownloadIdCallback& callback) override; + std::string ApplicationClientIdForFileScanning() const override; // CefBrowserHostImpl::Observer methods. void OnBrowserDestroyed(CefBrowserHostImpl* browser) override; diff --git a/tests/cefclient/cefclient_win.cc b/tests/cefclient/cefclient_win.cc index dc04f575b..c6e8a5c81 100644 --- a/tests/cefclient/cefclient_win.cc +++ b/tests/cefclient/cefclient_win.cc @@ -76,6 +76,10 @@ int RunMain(HINSTANCE hInstance, int nCmdShow) { settings.no_sandbox = true; #endif + // Applications should specify a unique GUID here to enable trusted downloads. + CefString(&settings.application_client_id_for_file_scanning) + .FromString("9A8DE24D-B822-4C6C-8259-5A848FEA1E68"); + // Populate the settings based on command line arguments. context->PopulateSettings(&settings);