Use default cookie scheme settings for non-global request contexts

The CefSettings cookie scheme configuration will now only impact the global
request context. Custom behavior for other request contexts must now be
configured via CefRequestContextSettings.
This commit is contained in:
Marshall Greenblatt 2023-01-26 13:50:30 -05:00
parent c3c5d6ff37
commit 36ee304ed4
2 changed files with 21 additions and 29 deletions

View File

@ -420,11 +420,11 @@ typedef struct _cef_settings_t {
/// Comma delimited list of schemes supported by the associated
/// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0)
/// the default schemes ("http", "https", "ws" and "wss") will also be
/// supported. Specifying a |cookieable_schemes_list| value and setting
/// supported. Not specifying a |cookieable_schemes_list| value and setting
/// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
/// and saving of cookies for this manager. Can be overridden
/// for individual CefRequestContext instances via the
/// CefRequestContextSettings.cookieable_schemes_list and
/// and saving of cookies. These settings will only impact the global
/// CefRequestContext. Individual CefRequestContext instances can be
/// configured via the CefRequestContextSettings.cookieable_schemes_list and
/// CefRequestContextSettings.cookieable_schemes_exclude_defaults values.
///
cef_string_t cookieable_schemes_list;
@ -486,10 +486,10 @@ typedef struct _cef_request_context_settings_t {
/// Comma delimited list of schemes supported by the associated
/// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0)
/// the default schemes ("http", "https", "ws" and "wss") will also be
/// supported. Specifying a |cookieable_schemes_list| value and setting
/// supported. Not specifying a |cookieable_schemes_list| value and setting
/// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
/// and saving of cookies for this manager. These values will be ignored if
/// |cache_path| matches the CefSettings.cache_path value.
/// and saving of cookies. These values will be ignored if |cache_path|
/// matches the CefSettings.cache_path value.
///
cef_string_t cookieable_schemes_list;
int cookieable_schemes_exclude_defaults;

View File

@ -155,6 +155,11 @@ CefBrowserContext* GetSelf(base::WeakPtr<CefBrowserContext> self) {
CefBrowserContext::CookieableSchemes MakeSupportedSchemes(
const CefString& schemes_list,
bool include_defaults) {
if (schemes_list.empty() && include_defaults) {
// No explicit registration of schemes.
return absl::nullopt;
}
std::vector<std::string> all_schemes;
if (!schemes_list.empty()) {
all_schemes =
@ -174,6 +179,12 @@ CefBrowserContext::CookieableSchemes MakeSupportedSchemes(
return absl::make_optional(all_schemes);
}
template <typename T>
CefBrowserContext::CookieableSchemes MakeSupportedSchemes(const T& settings) {
return MakeSupportedSchemes(CefString(&settings.cookieable_schemes_list),
!settings.cookieable_schemes_exclude_defaults);
}
} // namespace
CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings)
@ -197,13 +208,7 @@ void CefBrowserContext::Initialize() {
}
iothread_state_ = base::MakeRefCounted<CefIOThreadState>();
if (settings_.cookieable_schemes_list.length > 0 ||
settings_.cookieable_schemes_exclude_defaults) {
cookieable_schemes_ =
MakeSupportedSchemes(CefString(&settings_.cookieable_schemes_list),
!settings_.cookieable_schemes_exclude_defaults);
}
cookieable_schemes_ = MakeSupportedSchemes(settings_);
}
void CefBrowserContext::Shutdown() {
@ -426,11 +431,7 @@ CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() {
CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
const {
CEF_REQUIRE_UIT();
if (cookieable_schemes_) {
return cookieable_schemes_;
}
return GetGlobalCookieableSchemes();
return cookieable_schemes_;
}
// static
@ -439,15 +440,6 @@ CefBrowserContext::GetGlobalCookieableSchemes() {
CEF_REQUIRE_UIT();
static base::NoDestructor<CookieableSchemes> schemes(
[]() -> CookieableSchemes {
const auto& settings = CefContext::Get()->settings();
if (settings.cookieable_schemes_list.length > 0 ||
settings.cookieable_schemes_exclude_defaults) {
return MakeSupportedSchemes(
CefString(&settings.cookieable_schemes_list),
!settings.cookieable_schemes_exclude_defaults);
}
return absl::nullopt;
}());
[]() { return MakeSupportedSchemes(CefContext::Get()->settings()); }());
return *schemes;
}