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 /// Comma delimited list of schemes supported by the associated
/// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0) /// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0)
/// the default schemes ("http", "https", "ws" and "wss") will also be /// 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 /// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
/// and saving of cookies for this manager. Can be overridden /// and saving of cookies. These settings will only impact the global
/// for individual CefRequestContext instances via the /// CefRequestContext. Individual CefRequestContext instances can be
/// CefRequestContextSettings.cookieable_schemes_list and /// configured via the CefRequestContextSettings.cookieable_schemes_list and
/// CefRequestContextSettings.cookieable_schemes_exclude_defaults values. /// CefRequestContextSettings.cookieable_schemes_exclude_defaults values.
/// ///
cef_string_t cookieable_schemes_list; 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 /// Comma delimited list of schemes supported by the associated
/// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0) /// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0)
/// the default schemes ("http", "https", "ws" and "wss") will also be /// 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 /// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
/// and saving of cookies for this manager. These values will be ignored if /// and saving of cookies. These values will be ignored if |cache_path|
/// |cache_path| matches the CefSettings.cache_path value. /// matches the CefSettings.cache_path value.
/// ///
cef_string_t cookieable_schemes_list; cef_string_t cookieable_schemes_list;
int cookieable_schemes_exclude_defaults; int cookieable_schemes_exclude_defaults;

View File

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