From b5386249bd9075982db0874d3a981c44adc4c420 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 6 Jun 2023 17:41:53 +0300 Subject: [PATCH] alloy: Remove CefSettings.user_data_path (fixes #3511) This change replaces existing CefSettings.user_data_path usage with CefSettings.root_cache_path for better alignment with the Chrome runtime. All files should now be written inside the root_cache_path directory. --- include/capi/cef_crash_util_capi.h | 4 +-- include/cef_api_hash.h | 8 +++--- include/cef_crash_util.h | 2 +- include/internal/cef_types.h | 20 +++++--------- include/internal/cef_types_wrappers.h | 3 --- libcef/browser/alloy/alloy_browser_main.cc | 7 ++++- .../alloy/alloy_content_browser_client.cc | 26 +++++-------------- .../alloy/chrome_browser_process_alloy.cc | 11 ++++---- libcef/browser/context.cc | 1 - libcef/common/resource_util.cc | 16 ++++-------- tests/ceftests/test_suite.cc | 1 - 11 files changed, 37 insertions(+), 62 deletions(-) diff --git a/include/capi/cef_crash_util_capi.h b/include/capi/cef_crash_util_capi.h index f6272ab0d..ce6ce0496 100644 --- a/include/capi/cef_crash_util_capi.h +++ b/include/capi/cef_crash_util_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=5c6e0b9e37b8103a182f200fccdf5973104fcd70$ +// $hash=22cfd717df9032a01214d9abfe3e0e51949b3319$ // #ifndef CEF_INCLUDE_CAPI_CEF_CRASH_UTIL_CAPI_H_ @@ -90,7 +90,7 @@ extern "C" { /// If "AppName" is set on Windows then crash report information (metrics, /// database and dumps) will be stored locally on disk under the /// "C:\Users\[CurrentUser]\AppData\Local\[AppName]\User Data" folder. On other -/// platforms the cef_settings_t.user_data_path value will be used. +/// platforms the cef_settings_t.root_cache_path value will be used. /// /// If "ExternalHandler" is set on Windows then the specified exe will be /// launched as the crashpad-handler instead of re-launching the main process diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 41553d1f4..4c1089674 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,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 "19ae20c25645845eb850e794d6a5720e62ca0da2" +#define CEF_API_HASH_UNIVERSAL "5ee382b5a4b7a02d0285f9af00e9205e03b456d0" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "c9755cb731be425f3e92c7be23908ca3c8ac26b4" +#define CEF_API_HASH_PLATFORM "f4db8c7c65b7a95af22e0adf0c6b86c087d988f1" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "794acfa185a6be3edea15de4a8bbafebccc7e34c" +#define CEF_API_HASH_PLATFORM "932566b79377996c56a3d97128404491f94699cf" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "39de0cd2c1d9b526c77deb72a77bbeaa5254c309" +#define CEF_API_HASH_PLATFORM "ae753fb624eec885a3dc64c815360f9bca58f17e" #endif #ifdef __cplusplus diff --git a/include/cef_crash_util.h b/include/cef_crash_util.h index f9f87ee38..956b5ffbc 100644 --- a/include/cef_crash_util.h +++ b/include/cef_crash_util.h @@ -82,7 +82,7 @@ /// If "AppName" is set on Windows then crash report information (metrics, /// database and dumps) will be stored locally on disk under the /// "C:\Users\[CurrentUser]\AppData\Local\[AppName]\User Data" folder. On other -/// platforms the cef_settings_t.user_data_path value will be used. +/// platforms the cef_settings_t.root_cache_path value will be used. /// /// If "ExternalHandler" is set on Windows then the specified exe will be /// launched as the crashpad-handler instead of re-launching the main process diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 613bd72cd..55524cb5b 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -260,24 +260,16 @@ typedef struct _cef_settings_t { /// The root directory that all CefSettings.cache_path and /// CefRequestContextSettings.cache_path values must have in common. If this /// value is empty and CefSettings.cache_path is non-empty then it will - /// default to the CefSettings.cache_path value. If this value is non-empty - /// then it must be an absolute path. Failure to set this value correctly may - /// result in the sandbox blocking read/write access to the cache_path - /// directory. - /// - cef_string_t root_cache_path; - - /// - /// The location where user data such as the Widevine CDM module and spell - /// checking dictionary files will be stored on disk. If this value is empty - /// then the default platform-specific user data directory will be used + /// default to the CefSettings.cache_path value. If both values are empty + /// then the default platform-specific directory will be used /// ("~/.config/cef_user_data" directory on Linux, "~/Library/Application /// Support/CEF/User Data" directory on MacOS, "AppData\Local\CEF\User Data" /// directory under the user profile directory on Windows). If this value is - /// non-empty then it must be an absolute path. When using the Chrome runtime - /// this value will be ignored in favor of the |root_cache_path| value. + /// non-empty then it must be an absolute path. Failure to set this value + /// correctly may result in the sandbox blocking read/write access to certain + /// files. /// - cef_string_t user_data_path; + cef_string_t root_cache_path; /// /// To persist session cookies (cookies without an expiry date or validity diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index 53e07cd48..ec84b4c75 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -364,7 +364,6 @@ struct CefSettingsTraits { cef_string_clear(&s->main_bundle_path); cef_string_clear(&s->cache_path); cef_string_clear(&s->root_cache_path); - cef_string_clear(&s->user_data_path); cef_string_clear(&s->user_agent); cef_string_clear(&s->user_agent_product); cef_string_clear(&s->locale); @@ -397,8 +396,6 @@ struct CefSettingsTraits { &target->cache_path, copy); cef_string_set(src->root_cache_path.str, src->root_cache_path.length, &target->root_cache_path, copy); - cef_string_set(src->user_data_path.str, src->user_data_path.length, - &target->user_data_path, copy); target->persist_session_cookies = src->persist_session_cookies; target->persist_user_preferences = src->persist_user_preferences; diff --git a/libcef/browser/alloy/alloy_browser_main.cc b/libcef/browser/alloy/alloy_browser_main.cc index e6c8ba394..9bbe3d3e0 100644 --- a/libcef/browser/alloy/alloy_browser_main.cc +++ b/libcef/browser/alloy/alloy_browser_main.cc @@ -32,6 +32,7 @@ #include "chrome/browser/ui/color/chrome_color_mixers.h" #include "chrome/browser/ui/javascript_dialogs/chrome_javascript_app_modal_dialog_view_factory.h" #include "chrome/browser/ui/ui_features.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "components/constrained_window/constrained_window_views.h" #include "content/public/browser/gpu_data_manager.h" @@ -58,6 +59,7 @@ #if BUILDFLAG(IS_WIN) #include "base/enterprise_util.h" +#include "base/files/file_util.h" #include "chrome/browser/chrome_browser_main_win.h" #include "chrome/browser/win/parental_controls.h" #endif @@ -82,7 +84,6 @@ #include "base/path_service.h" #include "chrome/browser/themes/theme_service_aura_linux.h" #include "chrome/browser/ui/views/theme_profile_key.h" -#include "chrome/common/chrome_paths.h" #include "chrome/grit/chromium_strings.h" #include "components/os_crypt/sync/key_storage_config_linux.h" #include "libcef/browser/printing/print_dialog_linux.h" @@ -241,6 +242,10 @@ void AlloyBrowserMainParts::PostCreateMainMessageLoop() { DCHECK(!config->user_data_path.empty()); OSCrypt::SetConfig(std::move(config)); #endif // BUILDFLAG(IS_LINUX) + +#if BUILDFLAG(IS_WIN) + base::SetExtraNoExecuteAllowedPath(chrome::DIR_USER_DATA); +#endif } int AlloyBrowserMainParts::PreCreateThreads() { diff --git a/libcef/browser/alloy/alloy_content_browser_client.cc b/libcef/browser/alloy/alloy_content_browser_client.cc index b5307572d..ed4111ff4 100644 --- a/libcef/browser/alloy/alloy_content_browser_client.cc +++ b/libcef/browser/alloy/alloy_content_browser_client.cc @@ -300,11 +300,11 @@ void BindNetworkHintsHandler( predictors::NetworkHintsHandlerImpl::Create(frame_host, std::move(receiver)); } -base::FilePath GetRootCachePath() { - // The CefContext::ValidateCachePath method enforces the requirement that all - // cache_path values be either equal to or a child of root_cache_path. - return base::FilePath( - CefString(&CefContext::Get()->settings().root_cache_path)); +base::FilePath GetUserDataPath() { + base::FilePath user_data_path; + base::PathService::Get(chrome::DIR_USER_DATA, &user_data_path); + DCHECK(!user_data_path.empty()); + return user_data_path; } const extensions::Extension* GetEnabledExtensionFromSiteURL( @@ -1159,19 +1159,7 @@ bool AlloyContentBrowserClient::ConfigureNetworkContextParams( // directories that are not returned by this method. std::vector AlloyContentBrowserClient::GetNetworkContextsParentDirectory() { - base::FilePath user_data_path; - base::PathService::Get(chrome::DIR_USER_DATA, &user_data_path); - DCHECK(!user_data_path.empty()); - - const auto& root_cache_path = GetRootCachePath(); - - // root_cache_path may sometimes be empty or a child of user_data_path, so - // only return the one path in that case. - if (root_cache_path.empty() || user_data_path.IsParent(root_cache_path)) { - return {user_data_path}; - } - - return {user_data_path, root_cache_path}; + return {GetUserDataPath()}; } bool AlloyContentBrowserClient::HandleExternalProtocol( @@ -1282,7 +1270,7 @@ void AlloyContentBrowserClient::RegisterBrowserInterfaceBindersForServiceWorker( base::FilePath AlloyContentBrowserClient::GetSandboxedStorageServiceDataDirectory() { - return GetRootCachePath(); + return GetUserDataPath(); } std::string AlloyContentBrowserClient::GetProduct() { diff --git a/libcef/browser/alloy/chrome_browser_process_alloy.cc b/libcef/browser/alloy/chrome_browser_process_alloy.cc index c1a6eae8f..0cd357a4e 100644 --- a/libcef/browser/alloy/chrome_browser_process_alloy.cc +++ b/libcef/browser/alloy/chrome_browser_process_alloy.cc @@ -16,6 +16,7 @@ #include "libcef/common/extensions/extensions_util.h" #include "base/command_line.h" +#include "base/path_service.h" #include "chrome/browser/component_updater/chrome_component_updater_configurator.h" #include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/permissions/chrome_permissions_client.h" @@ -24,6 +25,7 @@ #include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/printing/print_preview_dialog_controller.h" #include "chrome/browser/ui/prefs/pref_watcher.h" +#include "chrome/common/chrome_paths.h" #include "components/component_updater/component_updater_service.h" #include "components/component_updater/timer_update_scheduler.h" #include "components/net_log/chrome_net_log.h" @@ -186,16 +188,15 @@ ProfileManager* ChromeBrowserProcessAlloy::profile_manager() { PrefService* ChromeBrowserProcessAlloy::local_state() { DCHECK(initialized_); if (!local_state_) { - // Use a location that is shared by all request contexts. - const CefSettings& settings = CefContext::Get()->settings(); - const base::FilePath& root_cache_path = - base::FilePath(CefString(&settings.root_cache_path)); + base::FilePath user_data_path; + base::PathService::Get(chrome::DIR_USER_DATA, &user_data_path); + DCHECK(!user_data_path.empty()); // Used for very early NetworkService initialization. // Always persist preferences for this PrefService if possible because it // contains the cookie encryption key on Windows. local_state_ = - browser_prefs::CreatePrefService(nullptr /* profile */, root_cache_path, + browser_prefs::CreatePrefService(nullptr /* profile */, user_data_path, true /* persist_user_preferences */); } return local_state_.get(); diff --git a/libcef/browser/context.cc b/libcef/browser/context.cc index 22a2d83c7..5e0d6f7f0 100644 --- a/libcef/browser/context.cc +++ b/libcef/browser/context.cc @@ -462,7 +462,6 @@ bool CefContext::Initialize(const CefMainArgs& args, "browser_subprocess_path"); NormalizePathAndSet(settings_.framework_dir_path, "framework_dir_path"); NormalizePathAndSet(settings_.main_bundle_path, "main_bundle_path"); - NormalizePathAndSet(settings_.user_data_path, "user_data_path"); NormalizePathAndSet(settings_.resources_dir_path, "resources_dir_path"); NormalizePathAndSet(settings_.locales_dir_path, "locales_dir_path"); diff --git a/libcef/common/resource_util.cc b/libcef/common/resource_util.cc index 616b8fd56..c525ec336 100644 --- a/libcef/common/resource_util.cc +++ b/libcef/common/resource_util.cc @@ -83,18 +83,12 @@ base::FilePath GetUserDataPath(CefSettings* settings, const base::CommandLine* command_line) { // |settings| will be non-nullptr in the main process only. if (settings) { - // With the Chrome runtime Profile paths must always be relative to the - // user data directory, so defaulting to |root_cache_path| first is - // appropriate. - CefString user_data_path; - if (cef::IsChromeRuntimeEnabled() && settings->root_cache_path.length > 0) { - user_data_path = CefString(&settings->root_cache_path); + CefString root_cache_path; + if (settings->root_cache_path.length > 0) { + root_cache_path = CefString(&settings->root_cache_path); } - if (user_data_path.empty() && settings->user_data_path.length > 0) { - user_data_path = CefString(&settings->user_data_path); - } - if (!user_data_path.empty()) { - return base::FilePath(user_data_path); + if (!root_cache_path.empty()) { + return base::FilePath(root_cache_path); } } diff --git a/tests/ceftests/test_suite.cc b/tests/ceftests/test_suite.cc index d7cf1b4d4..1f95506a5 100644 --- a/tests/ceftests/test_suite.cc +++ b/tests/ceftests/test_suite.cc @@ -150,7 +150,6 @@ void CefTestSuite::GetSettings(CefSettings& settings) const { CefString(&settings.cache_path) = root_cache_path_; CefString(&settings.root_cache_path) = root_cache_path_; - CefString(&settings.user_data_path) = root_cache_path_; // Always expose the V8 gc() function to give tests finer-grained control over // memory management.