From 5bfcfaab7376dee7fafb00af64400fa3b95d33d4 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 9 Apr 2021 14:34:45 -0400 Subject: [PATCH] Move cookieable scheme configuration to settings (see issue #2969) The Chrome runtime requires that cookieable scheme information be available at Profile initialization time because it also triggers NetworkContext creation at the same time. To make this possible, and to avoid various race conditions when setting state, the cookieable scheme configuration has been added as |cookieable_schemes_list| and |cookieable_schemes_exclude_defaults| in CefSettings and CefBrowserContextSettings. The CefCookieManager:: SetSupportedSchemes and CefBrowserProcessHandler::GetCookieableSchemes methods are no longer required and have been removed. This change also modifies chrome to delay OffTheRecordProfileImpl initialization so that |ChromeBrowserContext::profile_| can be set before ChromeContentBrowserClientCef::ConfigureNetworkContextParams calls CefBrowserContext::FromBrowserContext to retrieve the ChromeBrowserContext and associated cookieable scheme information. Otherwise, the ChromeBrowserContext will not be matched and the NetworkContext will not be configured correctly. The CookieTest suite now passes with the Chrome runtime enabled. --- .../capi/cef_browser_process_handler_capi.h | 21 +-- include/capi/cef_cookie_capi.h | 17 +-- include/cef_api_hash.h | 8 +- include/cef_browser_process_handler.h | 17 --- include/cef_cookie.h | 15 -- include/internal/cef_types.h | 28 +++- include/internal/cef_types_wrappers.h | 15 ++ libcef/browser/browser_context.cc | 53 ++++++- libcef/browser/browser_context.h | 6 +- .../browser/chrome/chrome_browser_context.cc | 29 +++- .../chrome_content_browser_client_cef.cc | 2 +- libcef/browser/context.cc | 5 + .../net_service/cookie_manager_impl.cc | 64 -------- .../browser/net_service/cookie_manager_impl.h | 6 - .../cpptoc/browser_process_handler_cpptoc.cc | 42 +----- libcef_dll/cpptoc/cookie_manager_cpptoc.cc | 30 +--- .../ctocpp/browser_process_handler_ctocpp.cc | 34 +---- .../ctocpp/browser_process_handler_ctocpp.h | 5 +- libcef_dll/ctocpp/cookie_manager_ctocpp.cc | 31 +--- libcef_dll/ctocpp/cookie_manager_ctocpp.h | 6 +- patch/patch.cfg | 1 + patch/patches/chrome_browser_profiles.patch | 62 +++++++- .../browser/client_app_delegates_browser.cc | 4 + tests/cefclient/browser/main_context_impl.cc | 11 +- .../common/client_app_delegates_common.cc | 6 +- tests/cefclient/common/scheme_test_common.cc | 3 +- tests/cefclient/common/scheme_test_common.h | 3 +- tests/ceftests/client_app_delegates.cc | 52 ++++--- tests/ceftests/cookie_unittest.cc | 138 +++++++----------- .../resource_request_handler_unittest.cc | 3 +- tests/ceftests/scheme_handler_unittest.cc | 14 +- tests/ceftests/test_suite.cc | 13 +- tests/ceftests/urlrequest_unittest.cc | 33 ++--- tests/shared/browser/client_app_browser.cc | 34 ++++- tests/shared/browser/client_app_browser.h | 12 +- tests/shared/common/client_app.cc | 2 +- tests/shared/common/client_app.h | 7 +- 37 files changed, 359 insertions(+), 473 deletions(-) diff --git a/include/capi/cef_browser_process_handler_capi.h b/include/capi/cef_browser_process_handler_capi.h index 87c405802..43f804772 100644 --- a/include/capi/cef_browser_process_handler_capi.h +++ b/include/capi/cef_browser_process_handler_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=54c5210924095c7e43173a2843bd28729645922b$ +// $hash=ade537f836add7fe0b5fd94ceba26d678abb3e43$ // #ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_ @@ -60,25 +60,6 @@ typedef struct _cef_browser_process_handler_t { /// cef_base_ref_counted_t base; - /// - // Called on the browser process UI thread to retrieve the list of schemes - // that should support cookies. If |include_defaults| is true (1) the default - // schemes ("http", "https", "ws" and "wss") will also be supported. Providing - // an NULL |schemes| value and setting |include_defaults| to false (0) will - // disable all loading and saving of cookies. - // - // This state will apply to the cef_cookie_manager_t associated with the - // global cef_request_context_t. It will also be used as the initial state for - // any new cef_request_context_ts created by the client. After creating a new - // cef_request_context_t the cef_cookie_manager_t::SetSupportedSchemes - // function may be called on the associated cef_cookie_manager_t to futher - // override these values. - /// - void(CEF_CALLBACK* get_cookieable_schemes)( - struct _cef_browser_process_handler_t* self, - cef_string_list_t schemes, - int* include_defaults); - /// // Called on the browser process UI thread immediately after the CEF context // has been initialized. diff --git a/include/capi/cef_cookie_capi.h b/include/capi/cef_cookie_capi.h index 10af18910..d6f7cb68b 100644 --- a/include/capi/cef_cookie_capi.h +++ b/include/capi/cef_cookie_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=20ba58ac3e861344ee738b58433869223c757e24$ +// $hash=b19ef1c8a781f8d59276357609fe64370bb8a107$ // #ifndef CEF_INCLUDE_CAPI_CEF_COOKIE_CAPI_H_ @@ -61,21 +61,6 @@ typedef struct _cef_cookie_manager_t { /// cef_base_ref_counted_t base; - /// - // Set the schemes supported by this manager. If |include_defaults| is true - // (1) the default schemes ("http", "https", "ws" and "wss") will also be - // supported. Calling this function with an NULL |schemes| value and - // |include_defaults| set to false (0) will disable all loading and saving of - // cookies for this manager. If |callback| is non-NULL it will be executed - // asnychronously on the UI thread after the change has been applied. Must be - // called before any cookies are accessed. - /// - void(CEF_CALLBACK* set_supported_schemes)( - struct _cef_cookie_manager_t* self, - cef_string_list_t schemes, - int include_defaults, - struct _cef_completion_callback_t* callback); - /// // Visit all cookies on the UI thread. The returned cookies are ordered by // longest path, then by earliest creation date. Returns false (0) if cookies diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 708f25457..c5365492d 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 "4291ac099ef9b3f618e9343acf4deb7e36bb5508" +#define CEF_API_HASH_UNIVERSAL "09fa2caf6574279a82c1293ab731add98d6124fd" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "0637d7a76f9339dc446c364b3fc7c1a317b0460a" +#define CEF_API_HASH_PLATFORM "1cf8e3e6d8163fc9f600b919bec62dbd3687a481" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "83c4d72b1190a35bac919806c7e9b27b6a1efcf6" +#define CEF_API_HASH_PLATFORM "74b89a1b187e5bb5ecd4b97aa21d4abc80d3dcbe" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "f57499977f5166862b1f39ce22374b8e506b317b" +#define CEF_API_HASH_PLATFORM "b78332272b672f9d3db77a83af92857b226bb294" #endif #ifdef __cplusplus diff --git a/include/cef_browser_process_handler.h b/include/cef_browser_process_handler.h index e55c1430c..335c5cf72 100644 --- a/include/cef_browser_process_handler.h +++ b/include/cef_browser_process_handler.h @@ -50,23 +50,6 @@ /*--cef(source=client,no_debugct_check)--*/ class CefBrowserProcessHandler : public virtual CefBaseRefCounted { public: - /// - // Called on the browser process UI thread to retrieve the list of schemes - // that should support cookies. If |include_defaults| is true the default - // schemes ("http", "https", "ws" and "wss") will also be supported. Providing - // an empty |schemes| value and setting |include_defaults| to false will - // disable all loading and saving of cookies. - // - // This state will apply to the CefCookieManager associated with the global - // CefRequestContext. It will also be used as the initial state for any new - // CefRequestContexts created by the client. After creating a new - // CefRequestContext the CefCookieManager::SetSupportedSchemes method may be - // called on the associated CefCookieManager to futher override these values. - /// - /*--cef()--*/ - virtual void GetCookieableSchemes(std::vector& schemes, - bool& include_defaults) {} - /// // Called on the browser process UI thread immediately after the CEF context // has been initialized. diff --git a/include/cef_cookie.h b/include/cef_cookie.h index f48c7df40..bea152ce9 100644 --- a/include/cef_cookie.h +++ b/include/cef_cookie.h @@ -64,21 +64,6 @@ class CefCookieManager : public virtual CefBaseRefCounted { static CefRefPtr GetGlobalManager( CefRefPtr callback); - /// - // Set the schemes supported by this manager. If |include_defaults| is true - // the default schemes ("http", "https", "ws" and "wss") will also be - // supported. Calling this method with an empty |schemes| value and - // |include_defaults| set to false will disable all loading and saving of - // cookies for this manager. If |callback| is non-NULL it will be executed - // asnychronously on the UI thread after the change has been applied. Must be - // called before any cookies are accessed. - /// - /*--cef(optional_param=callback)--*/ - virtual void SetSupportedSchemes( - const std::vector& schemes, - bool include_defaults, - CefRefPtr callback) = 0; - /// // Visit all cookies on the UI thread. The returned cookies are ordered by // longest path, then by earliest creation date. Returns false if cookies diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 595d0fbb2..4ad3832df 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -422,6 +422,20 @@ typedef struct _cef_settings_t { /// cef_string_t accept_language_list; + /// + // 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 + // |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 + // CefRequestContextSettings.cookieable_schemes_exclude_defaults values. + /// + cef_string_t cookieable_schemes_list; + int cookieable_schemes_exclude_defaults; + /// // GUID string used for identifying the application. This is passed to the // system AV function for scanning downloaded files. By default, the GUID @@ -490,6 +504,18 @@ typedef struct _cef_request_context_settings_t { // ignored if |cache_path| matches the CefSettings.cache_path value. /// cef_string_t accept_language_list; + + /// + // 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 + // |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. + /// + cef_string_t cookieable_schemes_list; + int cookieable_schemes_exclude_defaults; } cef_request_context_settings_t; /// @@ -654,7 +680,7 @@ typedef struct _cef_browser_settings_t { /// // Comma delimited ordered list of language codes without any whitespace that // will be used in the "Accept-Language" HTTP header. May be set globally - // using the CefBrowserSettings.accept_language_list value. If both values are + // using the CefSettings.accept_language_list value. If both values are // empty then "en-US,en" will be used. /// cef_string_t accept_language_list; diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index 71b95b7fc..0e2c195a3 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -555,6 +555,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->cookieable_schemes_list); cef_string_clear(&s->application_client_id_for_file_scanning); } @@ -609,6 +610,13 @@ struct CefSettingsTraits { cef_string_set(src->accept_language_list.str, src->accept_language_list.length, &target->accept_language_list, copy); + + cef_string_set(src->cookieable_schemes_list.str, + src->cookieable_schemes_list.length, + &target->cookieable_schemes_list, copy); + target->cookieable_schemes_exclude_defaults = + src->cookieable_schemes_exclude_defaults; + 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); @@ -628,6 +636,7 @@ struct CefRequestContextSettingsTraits { static inline void clear(struct_type* s) { cef_string_clear(&s->cache_path); cef_string_clear(&s->accept_language_list); + cef_string_clear(&s->cookieable_schemes_list); } static inline void set(const struct_type* src, @@ -641,6 +650,12 @@ struct CefRequestContextSettingsTraits { cef_string_set(src->accept_language_list.str, src->accept_language_list.length, &target->accept_language_list, copy); + + cef_string_set(src->cookieable_schemes_list.str, + src->cookieable_schemes_list.length, + &target->cookieable_schemes_list, copy); + target->cookieable_schemes_exclude_defaults = + src->cookieable_schemes_exclude_defaults; } }; diff --git a/libcef/browser/browser_context.cc b/libcef/browser/browser_context.cc index d0cefec41..2d3ad2e27 100644 --- a/libcef/browser/browser_context.cc +++ b/libcef/browser/browser_context.cc @@ -7,6 +7,7 @@ #include #include +#include "libcef/browser/context.h" #include "libcef/browser/media_router/media_router_manager.h" #include "libcef/browser/request_context_impl.h" #include "libcef/browser/thread_util.h" @@ -16,6 +17,8 @@ #include "base/files/file_util.h" #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/no_destructor.h" +#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_context.h" @@ -142,6 +145,28 @@ CefBrowserContext* GetSelf(base::WeakPtr self) { return self.get(); } +CefBrowserContext::CookieableSchemes MakeSupportedSchemes( + const CefString& schemes_list, + bool include_defaults) { + std::vector all_schemes; + if (!schemes_list.empty()) { + all_schemes = + base::SplitString(schemes_list.ToString(), std::string(","), + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); + } + + if (include_defaults) { + // Add default schemes that should always support cookies. + // This list should match CookieMonster::kDefaultCookieableSchemes. + all_schemes.push_back("http"); + all_schemes.push_back("https"); + all_schemes.push_back("ws"); + all_schemes.push_back("wss"); + } + + return base::make_optional(all_schemes); +} + } // namespace CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings) @@ -164,6 +189,13 @@ void CefBrowserContext::Initialize() { g_manager.Get().SetImplPath(this, cache_path_); iothread_state_ = base::MakeRefCounted(); + + 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() { @@ -468,5 +500,24 @@ CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes() if (cookieable_schemes_) return cookieable_schemes_; - return CefCookieManagerImpl::GetGlobalCookieableSchemes(); + return GetGlobalCookieableSchemes(); +} + +// static +CefBrowserContext::CookieableSchemes +CefBrowserContext::GetGlobalCookieableSchemes() { + CEF_REQUIRE_UIT(); + + static base::NoDestructor 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 base::nullopt; + }()); + return *schemes; } diff --git a/libcef/browser/browser_context.h b/libcef/browser/browser_context.h index 75cbd1534..310590d3c 100644 --- a/libcef/browser/browser_context.h +++ b/libcef/browser/browser_context.h @@ -198,11 +198,7 @@ class CefBrowserContext { // Returns the schemes associated with this context specifically, or the // global configuration if unset. CookieableSchemes GetCookieableSchemes() const; - - // Set the schemes associated with this context specifically. - void set_cookieable_schemes(const CookieableSchemes& schemes) { - cookieable_schemes_ = schemes; - } + static CookieableSchemes GetGlobalCookieableSchemes(); // These accessors are safe to call from any thread because the values don't // change during this object's lifespan. diff --git a/libcef/browser/chrome/chrome_browser_context.cc b/libcef/browser/chrome/chrome_browser_context.cc index 01fd852eb..4d6f4d17a 100644 --- a/libcef/browser/chrome/chrome_browser_context.cc +++ b/libcef/browser/chrome/chrome_browser_context.cc @@ -7,6 +7,7 @@ #include "libcef/browser/prefs/browser_prefs.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/off_the_record_profile_impl.h" ChromeBrowserContext::ChromeBrowserContext( const CefRequestContextSettings& settings) @@ -33,8 +34,9 @@ void ChromeBrowserContext::InitializeAsync(base::OnceClosure initialized_cb) { if (cache_path_ == user_data_dir) { // Use the default disk-based profile. - ProfileCreated(profile_manager->GetActiveUserProfile(), - Profile::CreateStatus::CREATE_STATUS_INITIALIZED); + auto profile = profile_manager->GetActiveUserProfile(); + ProfileCreated(profile, Profile::CreateStatus::CREATE_STATUS_CREATED); + ProfileCreated(profile, Profile::CreateStatus::CREATE_STATUS_INITIALIZED); return; } else if (cache_path_.DirName() == user_data_dir) { // Create or load a specific disk-based profile. May continue @@ -69,26 +71,41 @@ void ChromeBrowserContext::Shutdown() { void ChromeBrowserContext::ProfileCreated(Profile* profile, Profile::CreateStatus status) { + Profile* parent_profile = nullptr; + OffTheRecordProfileImpl* otr_profile = nullptr; + if (status != Profile::CreateStatus::CREATE_STATUS_CREATED && status != Profile::CreateStatus::CREATE_STATUS_INITIALIZED) { DCHECK(!profile); + DCHECK(!profile_); // Creation of a disk-based profile failed for some reason. Create a // new/unique OffTheRecord profile instead. const auto& profile_id = Profile::OTRProfileID::CreateUniqueForCEF(); - profile = g_browser_process->profile_manager() - ->GetActiveUserProfile() - ->GetOffTheRecordProfile(profile_id); + parent_profile = + g_browser_process->profile_manager()->GetActiveUserProfile(); + profile_ = parent_profile->GetOffTheRecordProfile(profile_id); + otr_profile = static_cast(profile_); status = Profile::CreateStatus::CREATE_STATUS_INITIALIZED; should_destroy_ = true; } - if (status == Profile::CreateStatus::CREATE_STATUS_INITIALIZED) { + if (status == Profile::CreateStatus::CREATE_STATUS_CREATED) { DCHECK(profile); DCHECK(!profile_); profile_ = profile; + } else if (status == Profile::CreateStatus::CREATE_STATUS_INITIALIZED) { + DCHECK(profile_); browser_prefs::SetLanguagePrefs(profile_); + // Must set |profile_| before Init() calls + // ChromeContentBrowserClientCef::ConfigureNetworkContextParams so that + // CefBrowserContext::FromBrowserContext can find us. + if (otr_profile) { + otr_profile->Init(); + parent_profile->NotifyOffTheRecordProfileCreated(otr_profile); + } + std::move(initialized_cb_).Run(); } } diff --git a/libcef/browser/chrome/chrome_content_browser_client_cef.cc b/libcef/browser/chrome/chrome_content_browser_client_cef.cc index b334fa1b8..c2aa900f8 100644 --- a/libcef/browser/chrome/chrome_content_browser_client_cef.cc +++ b/libcef/browser/chrome/chrome_content_browser_client_cef.cc @@ -258,7 +258,7 @@ void ChromeContentBrowserClientCef::ConfigureNetworkContextParams( auto cef_context = CefBrowserContext::FromBrowserContext(context); network_context_params->cookieable_schemes = cef_context ? cef_context->GetCookieableSchemes() - : CefCookieManagerImpl::GetGlobalCookieableSchemes(); + : CefBrowserContext::GetGlobalCookieableSchemes(); } std::unique_ptr diff --git a/libcef/browser/context.cc b/libcef/browser/context.cc index 0dac9a1eb..8dcb40da3 100644 --- a/libcef/browser/context.cc +++ b/libcef/browser/context.cc @@ -436,6 +436,11 @@ void CefContext::PopulateGlobalRequestContextSettings( command_line->HasSwitch(switches::kIgnoreCertificateErrors); CefString(&settings->accept_language_list) = CefString(&settings_.accept_language_list); + + CefString(&settings->cookieable_schemes_list) = + CefString(&settings_.cookieable_schemes_list); + settings->cookieable_schemes_exclude_defaults = + settings_.cookieable_schemes_exclude_defaults; } void CefContext::NormalizeRequestContextSettings( diff --git a/libcef/browser/net_service/cookie_manager_impl.cc b/libcef/browser/net_service/cookie_manager_impl.cc index 1ea753e49..632c4acd3 100644 --- a/libcef/browser/net_service/cookie_manager_impl.cc +++ b/libcef/browser/net_service/cookie_manager_impl.cc @@ -4,13 +4,11 @@ #include "libcef/browser/net_service/cookie_manager_impl.h" -#include "libcef/common/app_manager.h" #include "libcef/common/net_service/net_service_util.h" #include "libcef/common/time_util.h" #include "base/bind.h" #include "base/logging.h" -#include "base/no_destructor.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/storage_partition.h" #include "services/network/public/mojom/cookie_manager.mojom.h" @@ -117,25 +115,6 @@ void GetCookiesCallbackImpl( GetAllCookiesCallbackImpl(visitor, browser_context_getter, cookies); } -CefCookieManagerImpl::CookieableSchemes MakeSupportedSchemes( - const std::vector& schemes, - bool include_defaults) { - std::vector all_schemes; - for (const auto& scheme : schemes) - all_schemes.push_back(scheme); - - if (include_defaults) { - // Add default schemes that should always support cookies. - // This list should match CookieMonster::kDefaultCookieableSchemes. - all_schemes.push_back("http"); - all_schemes.push_back("https"); - all_schemes.push_back("ws"); - all_schemes.push_back("wss"); - } - - return base::make_optional(all_schemes); -} - } // namespace CefCookieManagerImpl::CefCookieManagerImpl() {} @@ -150,29 +129,6 @@ void CefCookieManagerImpl::Initialize( RunAsyncCompletionOnUIThread(callback); } -void CefCookieManagerImpl::SetSupportedSchemes( - const std::vector& schemes, - bool include_defaults, - CefRefPtr callback) { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefCookieManagerImpl::SetSupportedSchemes, this, - schemes, include_defaults, callback)); - return; - } - - auto browser_context = GetBrowserContext(browser_context_getter_); - if (!browser_context) - return; - - // This will be forwarded to the CookieMonster that lives in the - // NetworkService process when the NetworkContext is created via - // AlloyContentBrowserClient::CreateNetworkContext. - browser_context->set_cookieable_schemes( - MakeSupportedSchemes(schemes, include_defaults)); - RunAsyncCompletionOnUIThread(callback); -} - bool CefCookieManagerImpl::VisitAllCookies( CefRefPtr visitor) { if (!visitor.get()) @@ -352,26 +308,6 @@ bool CefCookieManagerImpl::FlushStore( return true; } -// static -CefCookieManagerImpl::CookieableSchemes -CefCookieManagerImpl::GetGlobalCookieableSchemes() { - CEF_REQUIRE_UIT(); - - static base::NoDestructor schemes( - []() -> CefCookieManagerImpl::CookieableSchemes { - if (auto application = CefAppManager::Get()->GetApplication()) { - if (auto handler = application->GetBrowserProcessHandler()) { - std::vector schemes; - bool include_defaults = true; - handler->GetCookieableSchemes(schemes, include_defaults); - return MakeSupportedSchemes(schemes, include_defaults); - } - } - return base::nullopt; - }()); - return *schemes; -} - // CefCookieManager methods ---------------------------------------------------- // static diff --git a/libcef/browser/net_service/cookie_manager_impl.h b/libcef/browser/net_service/cookie_manager_impl.h index c9a53b550..3892693c2 100644 --- a/libcef/browser/net_service/cookie_manager_impl.h +++ b/libcef/browser/net_service/cookie_manager_impl.h @@ -23,9 +23,6 @@ class CefCookieManagerImpl : public CefCookieManager { CefRefPtr callback); // CefCookieManager methods. - void SetSupportedSchemes(const std::vector& schemes, - bool include_defaults, - CefRefPtr callback) override; bool VisitAllCookies(CefRefPtr visitor) override; bool VisitUrlCookies(const CefString& url, bool includeHttpOnly, @@ -38,9 +35,6 @@ class CefCookieManagerImpl : public CefCookieManager { CefRefPtr callback) override; bool FlushStore(CefRefPtr callback) override; - using CookieableSchemes = base::Optional>; - static CookieableSchemes GetGlobalCookieableSchemes(); - private: // Only accessed on the UI thread. Will be non-null after Initialize(). CefBrowserContext::Getter browser_context_getter_; diff --git a/libcef_dll/cpptoc/browser_process_handler_cpptoc.cc b/libcef_dll/cpptoc/browser_process_handler_cpptoc.cc index 26a26e844..908e0f7b2 100644 --- a/libcef_dll/cpptoc/browser_process_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_process_handler_cpptoc.cc @@ -9,55 +9,17 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=deb93b82f75f2e3f59cccf3a82ce8e47b400f5c1$ +// $hash=160f499a80898e5b6934960c4f41764c0610458e$ // #include "libcef_dll/cpptoc/browser_process_handler_cpptoc.h" #include "libcef_dll/cpptoc/client_cpptoc.h" #include "libcef_dll/ctocpp/command_line_ctocpp.h" -#include "libcef_dll/transfer_util.h" namespace { // MEMBER FUNCTIONS - Body may be edited by hand. -void CEF_CALLBACK browser_process_handler_get_cookieable_schemes( - struct _cef_browser_process_handler_t* self, - cef_string_list_t schemes, - int* include_defaults) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return; - // Verify param: schemes; type: string_vec_byref - DCHECK(schemes); - if (!schemes) - return; - // Verify param: include_defaults; type: bool_byref - DCHECK(include_defaults); - if (!include_defaults) - return; - - // Translate param: schemes; type: string_vec_byref - std::vector schemesList; - transfer_string_list_contents(schemes, schemesList); - // Translate param: include_defaults; type: bool_byref - bool include_defaultsBool = - (include_defaults && *include_defaults) ? true : false; - - // Execute - CefBrowserProcessHandlerCppToC::Get(self)->GetCookieableSchemes( - schemesList, include_defaultsBool); - - // Restore param: schemes; type: string_vec_byref - cef_string_list_clear(schemes); - transfer_string_list_contents(schemesList, schemes); - // Restore param: include_defaults; type: bool_byref - if (include_defaults) - *include_defaults = include_defaultsBool ? true : false; -} - void CEF_CALLBACK browser_process_handler_on_context_initialized( struct _cef_browser_process_handler_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -123,8 +85,6 @@ struct _cef_client_t* CEF_CALLBACK browser_process_handler_get_default_client( // CONSTRUCTOR - Do not edit by hand. CefBrowserProcessHandlerCppToC::CefBrowserProcessHandlerCppToC() { - GetStruct()->get_cookieable_schemes = - browser_process_handler_get_cookieable_schemes; GetStruct()->on_context_initialized = browser_process_handler_on_context_initialized; GetStruct()->on_before_child_process_launch = diff --git a/libcef_dll/cpptoc/cookie_manager_cpptoc.cc b/libcef_dll/cpptoc/cookie_manager_cpptoc.cc index 2bcb1e8b4..53caa6c4f 100644 --- a/libcef_dll/cpptoc/cookie_manager_cpptoc.cc +++ b/libcef_dll/cpptoc/cookie_manager_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=5136747d18b12c6b1d50f74d7f74dbad147c4401$ +// $hash=0307287ed355556f7c6dab1e4a4fd188ce11d919$ // #include "libcef_dll/cpptoc/cookie_manager_cpptoc.h" @@ -17,7 +17,6 @@ #include "libcef_dll/ctocpp/cookie_visitor_ctocpp.h" #include "libcef_dll/ctocpp/delete_cookies_callback_ctocpp.h" #include "libcef_dll/ctocpp/set_cookie_callback_ctocpp.h" -#include "libcef_dll/transfer_util.h" // GLOBAL FUNCTIONS - Body may be edited by hand. @@ -39,32 +38,6 @@ namespace { // MEMBER FUNCTIONS - Body may be edited by hand. -void CEF_CALLBACK -cookie_manager_set_supported_schemes(struct _cef_cookie_manager_t* self, - cef_string_list_t schemes, - int include_defaults, - cef_completion_callback_t* callback) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return; - // Verify param: schemes; type: string_vec_byref_const - DCHECK(schemes); - if (!schemes) - return; - // Unverified params: callback - - // Translate param: schemes; type: string_vec_byref_const - std::vector schemesList; - transfer_string_list_contents(schemes, schemesList); - - // Execute - CefCookieManagerCppToC::Get(self)->SetSupportedSchemes( - schemesList, include_defaults ? true : false, - CefCompletionCallbackCToCpp::Wrap(callback)); -} - int CEF_CALLBACK cookie_manager_visit_all_cookies(struct _cef_cookie_manager_t* self, struct _cef_cookie_visitor_t* visitor) { @@ -191,7 +164,6 @@ cookie_manager_flush_store(struct _cef_cookie_manager_t* self, // CONSTRUCTOR - Do not edit by hand. CefCookieManagerCppToC::CefCookieManagerCppToC() { - GetStruct()->set_supported_schemes = cookie_manager_set_supported_schemes; GetStruct()->visit_all_cookies = cookie_manager_visit_all_cookies; GetStruct()->visit_url_cookies = cookie_manager_visit_url_cookies; GetStruct()->set_cookie = cookie_manager_set_cookie; diff --git a/libcef_dll/ctocpp/browser_process_handler_ctocpp.cc b/libcef_dll/ctocpp/browser_process_handler_ctocpp.cc index d095739c9..e2cd36eef 100644 --- a/libcef_dll/ctocpp/browser_process_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_process_handler_ctocpp.cc @@ -9,47 +9,15 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=f70d18a15f7c01ce5171d781577312fa7d2fb93b$ +// $hash=5efe4243d536139501e58591c6f875e08001c8b7$ // #include "libcef_dll/ctocpp/browser_process_handler_ctocpp.h" #include "libcef_dll/cpptoc/command_line_cpptoc.h" #include "libcef_dll/ctocpp/client_ctocpp.h" -#include "libcef_dll/transfer_util.h" // VIRTUAL METHODS - Body may be edited by hand. -NO_SANITIZE("cfi-icall") -void CefBrowserProcessHandlerCToCpp::GetCookieableSchemes( - std::vector& schemes, - bool& include_defaults) { - cef_browser_process_handler_t* _struct = GetStruct(); - if (CEF_MEMBER_MISSING(_struct, get_cookieable_schemes)) - return; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Translate param: schemes; type: string_vec_byref - cef_string_list_t schemesList = cef_string_list_alloc(); - DCHECK(schemesList); - if (schemesList) - transfer_string_list_contents(schemes, schemesList); - // Translate param: include_defaults; type: bool_byref - int include_defaultsInt = include_defaults; - - // Execute - _struct->get_cookieable_schemes(_struct, schemesList, &include_defaultsInt); - - // Restore param:schemes; type: string_vec_byref - if (schemesList) { - schemes.clear(); - transfer_string_list_contents(schemesList, schemes); - cef_string_list_free(schemesList); - } - // Restore param:include_defaults; type: bool_byref - include_defaults = include_defaultsInt ? true : false; -} - NO_SANITIZE("cfi-icall") void CefBrowserProcessHandlerCToCpp::OnContextInitialized() { cef_browser_process_handler_t* _struct = GetStruct(); diff --git a/libcef_dll/ctocpp/browser_process_handler_ctocpp.h b/libcef_dll/ctocpp/browser_process_handler_ctocpp.h index a411c0535..5b2ff68b7 100644 --- a/libcef_dll/ctocpp/browser_process_handler_ctocpp.h +++ b/libcef_dll/ctocpp/browser_process_handler_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=e6881fab8b5f8b46c08f0b472abdc8508edaed52$ +// $hash=719a890627d0b2ba0746415c0dd8631e387567fe$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_PROCESS_HANDLER_CTOCPP_H_ @@ -20,7 +20,6 @@ #error This file can be included DLL-side only #endif -#include #include "include/capi/cef_browser_process_handler_capi.h" #include "include/cef_browser_process_handler.h" #include "libcef_dll/ctocpp/ctocpp_ref_counted.h" @@ -36,8 +35,6 @@ class CefBrowserProcessHandlerCToCpp virtual ~CefBrowserProcessHandlerCToCpp(); // CefBrowserProcessHandler methods. - void GetCookieableSchemes(std::vector& schemes, - bool& include_defaults) override; void OnContextInitialized() override; void OnBeforeChildProcessLaunch( CefRefPtr command_line) override; diff --git a/libcef_dll/ctocpp/cookie_manager_ctocpp.cc b/libcef_dll/ctocpp/cookie_manager_ctocpp.cc index f76f9f897..3873685fb 100644 --- a/libcef_dll/ctocpp/cookie_manager_ctocpp.cc +++ b/libcef_dll/ctocpp/cookie_manager_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=ca2d5effc1d414cebf46e33d1282a8e6d04bc317$ +// $hash=2682019770bd002410e9e292747e861c907d3c0c$ // #include "libcef_dll/ctocpp/cookie_manager_ctocpp.h" @@ -17,7 +17,6 @@ #include "libcef_dll/cpptoc/cookie_visitor_cpptoc.h" #include "libcef_dll/cpptoc/delete_cookies_callback_cpptoc.h" #include "libcef_dll/cpptoc/set_cookie_callback_cpptoc.h" -#include "libcef_dll/transfer_util.h" // STATIC METHODS - Body may be edited by hand. @@ -38,34 +37,6 @@ CefRefPtr CefCookieManager::GetGlobalManager( // VIRTUAL METHODS - Body may be edited by hand. -NO_SANITIZE("cfi-icall") -void CefCookieManagerCToCpp::SetSupportedSchemes( - const std::vector& schemes, - bool include_defaults, - CefRefPtr callback) { - cef_cookie_manager_t* _struct = GetStruct(); - if (CEF_MEMBER_MISSING(_struct, set_supported_schemes)) - return; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: callback - - // Translate param: schemes; type: string_vec_byref_const - cef_string_list_t schemesList = cef_string_list_alloc(); - DCHECK(schemesList); - if (schemesList) - transfer_string_list_contents(schemes, schemesList); - - // Execute - _struct->set_supported_schemes(_struct, schemesList, include_defaults, - CefCompletionCallbackCppToC::Wrap(callback)); - - // Restore param:schemes; type: string_vec_byref_const - if (schemesList) - cef_string_list_free(schemesList); -} - NO_SANITIZE("cfi-icall") bool CefCookieManagerCToCpp::VisitAllCookies( CefRefPtr visitor) { diff --git a/libcef_dll/ctocpp/cookie_manager_ctocpp.h b/libcef_dll/ctocpp/cookie_manager_ctocpp.h index a3d4d752b..ce8e6def0 100644 --- a/libcef_dll/ctocpp/cookie_manager_ctocpp.h +++ b/libcef_dll/ctocpp/cookie_manager_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=f90075499dbca71125c6ec1746fd2d3168699ee1$ +// $hash=86450b60ca929d794339574809c956ab0fec709e$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_COOKIE_MANAGER_CTOCPP_H_ @@ -20,7 +20,6 @@ #error This file can be included wrapper-side only #endif -#include #include "include/capi/cef_cookie_capi.h" #include "include/cef_cookie.h" #include "libcef_dll/ctocpp/ctocpp_ref_counted.h" @@ -36,9 +35,6 @@ class CefCookieManagerCToCpp virtual ~CefCookieManagerCToCpp(); // CefCookieManager methods. - void SetSupportedSchemes(const std::vector& schemes, - bool include_defaults, - CefRefPtr callback) OVERRIDE; bool VisitAllCookies(CefRefPtr visitor) OVERRIDE; bool VisitUrlCookies(const CefString& url, bool includeHttpOnly, diff --git a/patch/patch.cfg b/patch/patch.cfg index d1f9a3e14..ebfc5675d 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -239,6 +239,7 @@ patches = [ # https://bitbucket.org/chromiumembedded/cef/issues/1917 # # chrome: Support CEF incognito Profiles that allow Browser creation. + # chrome: Allow CEF to delay OffTheRecordProfileImpl initialization. # https://bitbucket.org/chromiumembedded/cef/issues/2969 'name': 'chrome_browser_profiles', }, diff --git a/patch/patches/chrome_browser_profiles.patch b/patch/patches/chrome_browser_profiles.patch index 2d024cbde..1d10a60e2 100644 --- a/patch/patches/chrome_browser_profiles.patch +++ b/patch/patches/chrome_browser_profiles.patch @@ -1,5 +1,20 @@ +diff --git chrome/browser/profiles/off_the_record_profile_impl.cc chrome/browser/profiles/off_the_record_profile_impl.cc +index 921fedb0cc6b..9a05fad976e1 100644 +--- chrome/browser/profiles/off_the_record_profile_impl.cc ++++ chrome/browser/profiles/off_the_record_profile_impl.cc +@@ -625,7 +625,9 @@ std::unique_ptr Profile::CreateOffTheRecordProfile( + #endif + if (!profile) + profile.reset(new OffTheRecordProfileImpl(parent, otr_profile_id)); +- profile->Init(); ++ // With CEF we want to delay initialization. ++ if (!otr_profile_id.IsUniqueForCEF()) ++ profile->Init(); + return std::move(profile); + } + diff --git chrome/browser/profiles/profile.cc chrome/browser/profiles/profile.cc -index 8e8a7abdcf17..89c47d18d379 100644 +index 8e8a7abdcf17..15822ab615eb 100644 --- chrome/browser/profiles/profile.cc +++ chrome/browser/profiles/profile.cc @@ -77,6 +77,7 @@ base::LazyInstance>::Leaky @@ -19,7 +34,7 @@ index 8e8a7abdcf17..89c47d18d379 100644 base::StartsWith(profile_id_, kDevToolsOTRProfileIDPrefix, base::CompareCase::SENSITIVE) || base::StartsWith(profile_id_, kMediaRouterOTRProfileIDPrefix, -@@ -111,6 +114,11 @@ Profile::OTRProfileID Profile::OTRProfileID::CreateUnique( +@@ -111,6 +114,16 @@ Profile::OTRProfileID Profile::OTRProfileID::CreateUnique( first_unused_index_++)); } @@ -27,24 +42,63 @@ index 8e8a7abdcf17..89c47d18d379 100644 +Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForCEF() { + return CreateUnique(kCEFOTRProfileIDPrefix); +} ++ ++bool Profile::OTRProfileID::IsUniqueForCEF() const { ++ return base::StartsWith(profile_id_, kCEFOTRProfileIDPrefix, ++ base::CompareCase::SENSITIVE); ++} + // static Profile::OTRProfileID Profile::OTRProfileID::CreateUniqueForDevTools() { return CreateUnique(kDevToolsOTRProfileIDPrefix); diff --git chrome/browser/profiles/profile.h chrome/browser/profiles/profile.h -index e77f4b15ce32..13569302c96b 100644 +index e77f4b15ce32..3f5d61aeabe5 100644 --- chrome/browser/profiles/profile.h +++ chrome/browser/profiles/profile.h -@@ -116,6 +116,9 @@ class Profile : public content::BrowserContext { +@@ -116,6 +116,10 @@ class Profile : public content::BrowserContext { // Creates a unique OTR profile id with the given profile id prefix. static OTRProfileID CreateUnique(const std::string& profile_id_prefix); + // Creates a unique OTR profile id to be used for CEF browser contexts. + static OTRProfileID CreateUniqueForCEF(); ++ bool IsUniqueForCEF() const; + // Creates a unique OTR profile id to be used for DevTools browser contexts. static OTRProfileID CreateUniqueForDevTools(); +@@ -523,6 +527,8 @@ class Profile : public content::BrowserContext { + std::vector block_patterns, + base::OnceClosure closure) override; + ++ void NotifyOffTheRecordProfileCreated(Profile* off_the_record); ++ + protected: + void set_is_guest_profile(bool is_guest_profile) { + is_guest_profile_ = is_guest_profile; +@@ -542,8 +548,6 @@ class Profile : public content::BrowserContext { + static PrefStore* CreateExtensionPrefStore(Profile*, + bool incognito_pref_store); + +- void NotifyOffTheRecordProfileCreated(Profile* off_the_record); +- + // Returns whether the user has signed in this profile to an account. + virtual bool IsSignedIn() = 0; + +diff --git chrome/browser/profiles/profile_impl.cc chrome/browser/profiles/profile_impl.cc +index e33b9cff8827..50b89735481e 100644 +--- chrome/browser/profiles/profile_impl.cc ++++ chrome/browser/profiles/profile_impl.cc +@@ -953,7 +953,9 @@ Profile* ProfileImpl::GetOffTheRecordProfile( + + otr_profiles_[otr_profile_id] = std::move(otr_profile); + +- NotifyOffTheRecordProfileCreated(raw_otr_profile); ++ // With CEF we want to delay initialization. ++ if (!otr_profile_id.IsUniqueForCEF()) ++ NotifyOffTheRecordProfileCreated(raw_otr_profile); + + return raw_otr_profile; + } diff --git chrome/browser/profiles/profile_manager.cc chrome/browser/profiles/profile_manager.cc index 7037c1375d9c..2b1c7911e597 100644 --- chrome/browser/profiles/profile_manager.cc diff --git a/tests/cefclient/browser/client_app_delegates_browser.cc b/tests/cefclient/browser/client_app_delegates_browser.cc index 4a192917d..2d6fc64de 100644 --- a/tests/cefclient/browser/client_app_delegates_browser.cc +++ b/tests/cefclient/browser/client_app_delegates_browser.cc @@ -8,6 +8,10 @@ namespace client { +// static +void ClientAppBrowser::RegisterCookieableSchemes( + std::vector& cookieable_schemes) {} + // static void ClientAppBrowser::CreateDelegates(DelegateSet& delegates) { browser::CreateDelegates(delegates); diff --git a/tests/cefclient/browser/main_context_impl.cc b/tests/cefclient/browser/main_context_impl.cc index 77995d592..980c51ff3 100644 --- a/tests/cefclient/browser/main_context_impl.cc +++ b/tests/cefclient/browser/main_context_impl.cc @@ -6,6 +6,7 @@ #include "include/cef_parser.h" #include "include/cef_web_plugin.h" +#include "tests/shared/browser/client_app_browser.h" #include "tests/shared/common/client_switches.h" namespace client { @@ -188,15 +189,7 @@ bool MainContextImpl::TouchEventsEnabled() { } void MainContextImpl::PopulateSettings(CefSettings* settings) { -#if defined(OS_WIN) || defined(OS_LINUX) - settings->multi_threaded_message_loop = - command_line_->HasSwitch(switches::kMultiThreadedMessageLoop); -#endif - - if (!settings->multi_threaded_message_loop) { - settings->external_message_pump = - command_line_->HasSwitch(switches::kExternalMessagePump); - } + client::ClientAppBrowser::PopulateSettings(command_line_, *settings); if (use_chrome_runtime_) settings->chrome_runtime = true; diff --git a/tests/cefclient/common/client_app_delegates_common.cc b/tests/cefclient/common/client_app_delegates_common.cc index 99c3b86c0..493f3e1ed 100644 --- a/tests/cefclient/common/client_app_delegates_common.cc +++ b/tests/cefclient/common/client_app_delegates_common.cc @@ -8,10 +8,8 @@ namespace client { // static -void ClientApp::RegisterCustomSchemes( - CefRawPtr registrar, - std::vector& cookiable_schemes) { - scheme_test::RegisterCustomSchemes(registrar, cookiable_schemes); +void ClientApp::RegisterCustomSchemes(CefRawPtr registrar) { + scheme_test::RegisterCustomSchemes(registrar); } } // namespace client diff --git a/tests/cefclient/common/scheme_test_common.cc b/tests/cefclient/common/scheme_test_common.cc index 4cf337a4d..7eb1eb66f 100644 --- a/tests/cefclient/common/scheme_test_common.cc +++ b/tests/cefclient/common/scheme_test_common.cc @@ -9,8 +9,7 @@ namespace client { namespace scheme_test { -void RegisterCustomSchemes(CefRawPtr registrar, - std::vector& cookiable_schemes) { +void RegisterCustomSchemes(CefRawPtr registrar) { registrar->AddCustomScheme( "client", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED); } diff --git a/tests/cefclient/common/scheme_test_common.h b/tests/cefclient/common/scheme_test_common.h index 859623d91..7eb282150 100644 --- a/tests/cefclient/common/scheme_test_common.h +++ b/tests/cefclient/common/scheme_test_common.h @@ -17,8 +17,7 @@ namespace scheme_test { // See browser/scheme_test.h for creation/registration of the custom scheme // handler which only occurs in the browser process. Called from // client_app_delegates_common.cc. -void RegisterCustomSchemes(CefRawPtr registrar, - std::vector& cookiable_schemes); +void RegisterCustomSchemes(CefRawPtr registrar); } // namespace scheme_test } // namespace client diff --git a/tests/ceftests/client_app_delegates.cc b/tests/ceftests/client_app_delegates.cc index f89cb459d..80529c1ce 100644 --- a/tests/ceftests/client_app_delegates.cc +++ b/tests/ceftests/client_app_delegates.cc @@ -84,31 +84,43 @@ void CreateRenderDelegates(ClientAppRenderer::DelegateSet& delegates) { CreateV8RendererTests(delegates); } -void RegisterCustomSchemes(CefRawPtr registrar, - std::vector& cookiable_schemes) { +void RegisterCustomSchemes(CefRawPtr registrar) { // Bring in the scheme handler tests. extern void RegisterSchemeHandlerCustomSchemes( - CefRawPtr registrar, - std::vector & cookiable_schemes); - RegisterSchemeHandlerCustomSchemes(registrar, cookiable_schemes); + CefRawPtr registrar); + RegisterSchemeHandlerCustomSchemes(registrar); // Bring in the cookie tests. extern void RegisterCookieCustomSchemes( - CefRawPtr registrar, - std::vector & cookiable_schemes); - RegisterCookieCustomSchemes(registrar, cookiable_schemes); + CefRawPtr registrar); + RegisterCookieCustomSchemes(registrar); // Bring in the URLRequest tests. extern void RegisterURLRequestCustomSchemes( - CefRawPtr registrar, - std::vector & cookiable_schemes); - RegisterURLRequestCustomSchemes(registrar, cookiable_schemes); + CefRawPtr registrar); + RegisterURLRequestCustomSchemes(registrar); // Bring in the resource request handler tests. extern void RegisterResourceRequestHandlerCustomSchemes( - CefRawPtr registrar, - std::vector & cookiable_schemes); - RegisterResourceRequestHandlerCustomSchemes(registrar, cookiable_schemes); + CefRawPtr registrar); + RegisterResourceRequestHandlerCustomSchemes(registrar); +} + +void RegisterCookieableSchemes(std::vector& cookieable_schemes) { + // Bring in the scheme handler tests. + extern void RegisterSchemeHandlerCookieableSchemes(std::vector & + cookieable_schemes); + RegisterSchemeHandlerCookieableSchemes(cookieable_schemes); + + // Bring in the cookie tests. + extern void RegisterCookieCookieableSchemes(std::vector & + cookieable_schemes); + RegisterCookieCookieableSchemes(cookieable_schemes); + + // Bring in the URLRequest tests. + extern void RegisterURLRequestCookieableSchemes(std::vector & + cookieable_schemes); + RegisterURLRequestCookieableSchemes(cookieable_schemes); } namespace client { @@ -124,10 +136,14 @@ void ClientAppRenderer::CreateDelegates(DelegateSet& delegates) { } // static -void ClientApp::RegisterCustomSchemes( - CefRawPtr registrar, - std::vector& cookiable_schemes) { - ::RegisterCustomSchemes(registrar, cookiable_schemes); +void ClientApp::RegisterCustomSchemes(CefRawPtr registrar) { + ::RegisterCustomSchemes(registrar); +} + +// static +void ClientAppBrowser::RegisterCookieableSchemes( + std::vector& cookieable_schemes) { + ::RegisterCookieableSchemes(cookieable_schemes); } } // namespace client diff --git a/tests/ceftests/cookie_unittest.cc b/tests/ceftests/cookie_unittest.cc index 832f6ad90..e3e136bd4 100644 --- a/tests/ceftests/cookie_unittest.cc +++ b/tests/ceftests/cookie_unittest.cc @@ -28,6 +28,11 @@ const char* kTestPath = "/path/to/cookietest"; const int kIgnoreNumDeleted = -2; +bool IgnoreURL(const std::string& url) { + return IsChromeRuntimeEnabled() && + url.find("/favicon.ico") != std::string::npos; +} + typedef std::vector CookieVector; class TestCompletionCallback : public CefCompletionCallback { @@ -843,36 +848,31 @@ class CookieTestSchemeHandler : public TestHandler { } else { // Create the request context that will use an in-memory cache. CefRequestContextSettings settings; + + if (scheme_ == kCustomCookieScheme || block_cookies_) { + if (!block_cookies_) { + CefString(&settings.cookieable_schemes_list) = kCustomCookieScheme; + } else { + settings.cookieable_schemes_exclude_defaults = true; + } + } + request_context_ = CefRequestContext::CreateContext(settings, nullptr); } // Register the scheme handler. request_context_->RegisterSchemeHandlerFactory( scheme_, "cookie-tests", new SchemeHandlerFactory(this)); - manager_ = request_context_->GetCookieManager(nullptr); - if (!use_global_ && (scheme_ == kCustomCookieScheme || block_cookies_)) { - std::vector schemes; - if (!block_cookies_) - schemes.push_back(kCustomCookieScheme); - // Need to wait for completion before creating the browser. - manager_->SetSupportedSchemes( - schemes, !block_cookies_ /* include_defaults */, - new CompletionCallback(base::Bind( - &CookieTestSchemeHandler::CreateBrowserContinue, this))); - } else { - CreateBrowserContinue(); - } + manager_ = request_context_->GetCookieManager(nullptr); + + // Create the browser. + CreateBrowser(url1_, request_context_); // Time out the test after a reasonable period of time. SetTestTimeout(); } - void CreateBrowserContinue() { - // Create the browser. - CreateBrowser(url1_, request_context_); - } - // Go to the next URL. void LoadNextURL(CefRefPtr frame, const std::string& url) { if (!CefCurrentlyOn(TID_UI)) { @@ -1220,7 +1220,9 @@ class CookieAccessSchemeHandlerFactory : public CefSchemeHandlerFactory, } // Unknown test. - ADD_FAILURE() << "Unexpected url: " << url; + if (!IgnoreURL(url)) { + ADD_FAILURE() << "Unexpected url: " << url; + } return nullptr; } @@ -1253,8 +1255,6 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, public: CookieAccessServerHandler() : initialized_(false), - expected_connection_ct_(-1), - actual_connection_ct_(0), expected_http_request_ct_(-1), actual_http_request_ct_(0) {} @@ -1269,7 +1269,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, // Must be called before CreateServer(). void SetExpectedRequestCount(int count) { EXPECT_FALSE(initialized_); - expected_connection_ct_ = expected_http_request_ct_ = count; + expected_http_request_ct_ = count; } // |complete_callback| will be executed on the UI thread after the server is @@ -1277,7 +1277,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, void CreateServer(const base::Closure& complete_callback) { EXPECT_UI_THREAD(); - if (expected_connection_ct_ < 0) { + if (expected_http_request_ct_ < 0) { // Default to the assumption of one request per registered URL. SetExpectedRequestCount(static_cast(data_map_.size())); } @@ -1325,36 +1325,11 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, delete this; } - bool OnClientConnected(CefRefPtr server, - int connection_id) override { - EXPECT_UI_THREAD(); - - EXPECT_TRUE(connection_id_set_.find(connection_id) == - connection_id_set_.end()); - connection_id_set_.insert(connection_id); - - actual_connection_ct_++; - - return true; - } - - bool OnClientDisconnected(CefRefPtr server, - int connection_id) override { - EXPECT_UI_THREAD(); - - ConnectionIdSet::iterator it = connection_id_set_.find(connection_id); - EXPECT_TRUE(it != connection_id_set_.end()); - connection_id_set_.erase(it); - - return true; - } - bool OnHttpRequest(CefRefPtr server, int connection_id, const CefString& client_address, CefRefPtr request) override { EXPECT_UI_THREAD(); - EXPECT_TRUE(VerifyConnection(connection_id)); EXPECT_FALSE(client_address.empty()); // Log the requests for better error reporting. @@ -1369,15 +1344,9 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, } private: - bool VerifyConnection(int connection_id) { - return connection_id_set_.find(connection_id) != connection_id_set_.end(); - } - void VerifyResults() { EXPECT_TRUE(got_server_created_); EXPECT_TRUE(got_server_destroyed_); - EXPECT_TRUE(connection_id_set_.empty()); - EXPECT_EQ(expected_connection_ct_, actual_connection_ct_) << request_log_; EXPECT_EQ(expected_http_request_ct_, actual_http_request_ct_) << request_log_; } @@ -1400,7 +1369,9 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, it->second->response_data); } else { // Unknown test. - ADD_FAILURE() << "Unexpected url: " << url; + if (!IgnoreURL(url)) { + ADD_FAILURE() << "Unexpected url: " << url; + } server->SendHttp500Response(connection_id, "Unknown test"); } } @@ -1461,11 +1432,6 @@ class CookieAccessServerHandler : public test_server::ObserverHelper, TrackCallback got_server_created_; TrackCallback got_server_destroyed_; - typedef std::set ConnectionIdSet; - ConnectionIdSet connection_id_set_; - - int expected_connection_ct_; - int actual_connection_ct_; int expected_http_request_ct_; int actual_http_request_ct_; @@ -1484,9 +1450,9 @@ class CookieAccessTestHandler : public RoutingTestHandler, BLOCK_READ_WRITE = BLOCK_READ | BLOCK_WRITE, ALLOW_NO_FILTER = 1 << 2, - // Block all cookies using SetSupportedSchemes. Can only be used with a - // non-global request context because it's too late (during test execution) - // to call this method on the global context. + // Block all cookies using CefRequestContextSettings. Can only be used with + // a non-global request context because it's too late (during test + // execution) to call this method on the global context. BLOCK_ALL_COOKIES = 1 << 3, // Return nullptr from GetResourceRequestHandler. Can only be used in @@ -1528,27 +1494,23 @@ class CookieAccessTestHandler : public RoutingTestHandler, } else { // Create the request context that will use an in-memory cache. CefRequestContextSettings settings; + + const bool block_cookies = (test_mode_ == BLOCK_ALL_COOKIES); + if (scheme_ == kCustomCookieScheme || block_cookies) { + if (!block_cookies) { + CefString(&settings.cookieable_schemes_list) = kCustomCookieScheme; + } else { + settings.cookieable_schemes_exclude_defaults = true; + } + } + context_ = CefRequestContext::CreateContext(settings, nullptr); } - cookie_manager_ = context_->GetCookieManager(nullptr); - SetTestTimeout(); - const bool block_cookies = (test_mode_ == BLOCK_ALL_COOKIES); - if (!use_global_ && (scheme_ == kCustomCookieScheme || block_cookies)) { - std::vector schemes; - if (!block_cookies) - schemes.push_back(kCustomCookieScheme); - - // Need to wait for completion before creating the browser. - cookie_manager_->SetSupportedSchemes( - schemes, !block_cookies /* include_defaults */, - new CompletionCallback(base::Bind( - &CookieAccessTestHandler::RunTestSetupContinue, this))); - } else { - RunTestSetupContinue(); - } + cookie_manager_ = context_->GetCookieManager(nullptr); + RunTestSetupContinue(); } void DestroyTest() override { @@ -1665,7 +1627,7 @@ class CookieAccessTestHandler : public RoutingTestHandler, CefRefPtr browser, CefRefPtr frame, CefRefPtr request) override { - if (test_backend_ == RESOURCE_HANDLER) { + if (test_backend_ == RESOURCE_HANDLER && scheme_factory_) { return scheme_factory_->Create(browser, frame, scheme_, request); } @@ -1681,7 +1643,7 @@ class CookieAccessTestHandler : public RoutingTestHandler, const std::string& url = request->GetURL(); if (url == GetCookieAccessUrl2(scheme_, test_backend_ == SERVER)) { can_send_cookie2_ct_++; - } else { + } else if (!IgnoreURL(url)) { ADD_FAILURE() << "Unexpected url: " << url; } @@ -1702,7 +1664,7 @@ class CookieAccessTestHandler : public RoutingTestHandler, const std::string& url = request->GetURL(); if (url == GetCookieAccessUrl1(scheme_, test_backend_ == SERVER)) { can_save_cookie1_ct_++; - } else { + } else if (!IgnoreURL(url)) { ADD_FAILURE() << "Unexpected url: " << url; } @@ -2367,11 +2329,17 @@ TEST(CookieTest, RestartInMemory) { // Entry point for registering custom schemes. // Called from client_app_delegates.cc. -void RegisterCookieCustomSchemes(CefRawPtr registrar, - std::vector& cookiable_schemes) { +void RegisterCookieCustomSchemes(CefRawPtr registrar) { // Used by GetCookieManagerCustom* tests. registrar->AddCustomScheme( kCustomCookieScheme, CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED); - cookiable_schemes.push_back(kCustomCookieScheme); +} + +// Entry point for registering cookieable schemes. +// Called from client_app_delegates.cc. +void RegisterCookieCookieableSchemes( + std::vector& cookieable_schemes) { + // Used by GetCookieManagerCustom* tests. + cookieable_schemes.push_back(kCustomCookieScheme); } diff --git a/tests/ceftests/resource_request_handler_unittest.cc b/tests/ceftests/resource_request_handler_unittest.cc index be5fe50b7..b8ae6b1bc 100644 --- a/tests/ceftests/resource_request_handler_unittest.cc +++ b/tests/ceftests/resource_request_handler_unittest.cc @@ -3943,8 +3943,7 @@ TEST(ResourceRequestHandlerTest, FilterError) { // Entry point for registering custom schemes. // Called from client_app_delegates.cc. void RegisterResourceRequestHandlerCustomSchemes( - CefRawPtr registrar, - std::vector& cookiable_schemes) { + CefRawPtr registrar) { // Add a custom standard scheme. registrar->AddCustomScheme( "rrhcustom", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED); diff --git a/tests/ceftests/scheme_handler_unittest.cc b/tests/ceftests/scheme_handler_unittest.cc index 1407f2772..617885a6b 100644 --- a/tests/ceftests/scheme_handler_unittest.cc +++ b/tests/ceftests/scheme_handler_unittest.cc @@ -2579,8 +2579,7 @@ TEST(SchemeHandlerTest, AcceptLanguage) { // Entry point for registering custom schemes. // Called from client_app_delegates.cc. void RegisterSchemeHandlerCustomSchemes( - CefRawPtr registrar, - std::vector& cookiable_schemes) { + CefRawPtr registrar) { // Registering the custom standard schemes as secure because requests from // non-secure origins to the loopback address will be blocked by // https://chromestatus.com/feature/5436853517811712. @@ -2589,15 +2588,22 @@ void RegisterSchemeHandlerCustomSchemes( registrar->AddCustomScheme("customstd", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_SECURE | CEF_SCHEME_OPTION_CORS_ENABLED); - cookiable_schemes.push_back("customstd"); // Also used in cors_unittest.cc. registrar->AddCustomScheme( "customstdfetch", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_SECURE | CEF_SCHEME_OPTION_CORS_ENABLED | CEF_SCHEME_OPTION_FETCH_ENABLED); - cookiable_schemes.push_back("customstdfetch"); // Add a custom non-standard scheme. registrar->AddCustomScheme("customnonstd", CEF_SCHEME_OPTION_NONE); registrar->AddCustomScheme("customnonstdfetch", CEF_SCHEME_OPTION_FETCH_ENABLED); } + +// Entry point for registering cookieable schemes. +// Called from client_app_delegates.cc. +void RegisterSchemeHandlerCookieableSchemes( + std::vector& cookieable_schemes) { + cookieable_schemes.push_back("customstd"); + // Also used in cors_unittest.cc. + cookieable_schemes.push_back("customstdfetch"); +} diff --git a/tests/ceftests/test_suite.cc b/tests/ceftests/test_suite.cc index 66cc63dc3..63aebd6a3 100644 --- a/tests/ceftests/test_suite.cc +++ b/tests/ceftests/test_suite.cc @@ -7,6 +7,7 @@ #include "include/cef_file_util.h" #include "include/wrapper/cef_scoped_temp_dir.h" #include "tests/gtest/include/gtest/gtest.h" +#include "tests/shared/browser/client_app_browser.h" #include "tests/shared/common/client_switches.h" namespace { @@ -132,20 +133,12 @@ int CefTestSuite::Run() { } void CefTestSuite::GetSettings(CefSettings& settings) const { + client::ClientAppBrowser::PopulateSettings(command_line_, settings); + // Enable the experimental Chrome runtime. See issue #2969 for details. settings.chrome_runtime = command_line_->HasSwitch(client::switches::kEnableChromeRuntime); -#if (defined(OS_WIN) || defined(OS_LINUX)) - settings.multi_threaded_message_loop = - command_line_->HasSwitch(client::switches::kMultiThreadedMessageLoop); -#endif - - if (!settings.multi_threaded_message_loop) { - settings.external_message_pump = - command_line_->HasSwitch(client::switches::kExternalMessagePump); - } - CefString(&settings.cache_path) = root_cache_path_; CefString(&settings.root_cache_path) = root_cache_path_; CefString(&settings.user_data_path) = root_cache_path_; diff --git a/tests/ceftests/urlrequest_unittest.cc b/tests/ceftests/urlrequest_unittest.cc index c06f80676..acdab2abe 100644 --- a/tests/ceftests/urlrequest_unittest.cc +++ b/tests/ceftests/urlrequest_unittest.cc @@ -2900,6 +2900,11 @@ class RequestTestHandler : public TestHandler { CefString(&settings.cache_path) = context_tmpdir_path_; } + if (!test_server_backend_) { + // Set the schemes that are allowed to store cookies. + CefString(&settings.cookieable_schemes_list) = GetRequestScheme(false); + } + // Create a new temporary request context. Calls OnContextInitialized. CefRequestContext::CreateContext(settings, new RequestContextHandler(this)); @@ -2910,20 +2915,7 @@ class RequestTestHandler : public TestHandler { EXPECT_TRUE(CefCurrentlyOn(TID_UI)); EXPECT_TRUE(request_context.get()); test_runner_->SetRequestContext(request_context); - - if (!test_server_backend_) { - // Set the schemes that are allowed to store cookies. - std::vector supported_schemes; - supported_schemes.push_back(GetRequestScheme(false)); - - // Continue the test once supported schemes has been set. - request_context->GetCookieManager(nullptr)->SetSupportedSchemes( - supported_schemes, true, - new TestCompletionCallback( - base::Bind(&RequestTestHandler::PreSetupComplete, this))); - } else { - PreSetupComplete(); - } + PreSetupComplete(); } void PreSetupComplete() { @@ -3269,13 +3261,18 @@ void CreateURLRequestRendererTests(ClientAppRenderer::DelegateSet& delegates) { // Entry point for registering custom schemes. // Called from client_app_delegates.cc. -void RegisterURLRequestCustomSchemes( - CefRawPtr registrar, - std::vector& cookiable_schemes) { +void RegisterURLRequestCustomSchemes(CefRawPtr registrar) { const std::string& scheme = GetRequestScheme(false); registrar->AddCustomScheme( scheme, CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED); - cookiable_schemes.push_back(scheme); +} + +// Entry point for registering cookieable schemes. +// Called from client_app_delegates.cc. +void RegisterURLRequestCookieableSchemes( + std::vector& cookieable_schemes) { + const std::string& scheme = GetRequestScheme(false); + cookieable_schemes.push_back(scheme); } // Helpers for defining URLRequest tests. diff --git a/tests/shared/browser/client_app_browser.cc b/tests/shared/browser/client_app_browser.cc index a69f26cd9..430b5ddf9 100644 --- a/tests/shared/browser/client_app_browser.cc +++ b/tests/shared/browser/client_app_browser.cc @@ -15,6 +15,32 @@ ClientAppBrowser::ClientAppBrowser() { CreateDelegates(delegates_); } +// static +void ClientAppBrowser::PopulateSettings(CefRefPtr command_line, + CefSettings& settings) { +#if (defined(OS_WIN) || defined(OS_LINUX)) + settings.multi_threaded_message_loop = + command_line->HasSwitch(client::switches::kMultiThreadedMessageLoop); +#endif + + if (!settings.multi_threaded_message_loop) { + settings.external_message_pump = + command_line->HasSwitch(client::switches::kExternalMessagePump); + } + + std::vector cookieable_schemes; + RegisterCookieableSchemes(cookieable_schemes); + if (!cookieable_schemes.empty()) { + std::string list_str; + for (const auto& scheme : cookieable_schemes) { + if (!list_str.empty()) + list_str += ","; + list_str += scheme; + } + CefString(&settings.cookieable_schemes_list) = list_str; + } +} + void ClientAppBrowser::OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr command_line) { @@ -61,14 +87,6 @@ void ClientAppBrowser::OnBeforeCommandLineProcessing( } } -void ClientAppBrowser::GetCookieableSchemes(std::vector& schemes, - bool& include_defaults) { - if (!cookieable_schemes_.empty()) { - schemes = cookieable_schemes_; - include_defaults = true; - } -} - void ClientAppBrowser::OnContextInitialized() { DelegateSet::iterator it = delegates_.begin(); for (; it != delegates_.end(); ++it) diff --git a/tests/shared/browser/client_app_browser.h b/tests/shared/browser/client_app_browser.h index 79c22c68e..ba09765be 100644 --- a/tests/shared/browser/client_app_browser.h +++ b/tests/shared/browser/client_app_browser.h @@ -35,7 +35,17 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler { ClientAppBrowser(); + // Called to populate |settings| based on |command_line| and other global + // state. + static void PopulateSettings(CefRefPtr command_line, + CefSettings& settings); + private: + // Registers cookieable schemes. Implemented by cefclient in + // client_app_delegates_browser.cc + static void RegisterCookieableSchemes( + std::vector& cookieable_schemes); + // Creates all of the Delegate objects. Implemented by cefclient in // client_app_delegates_browser.cc static void CreateDelegates(DelegateSet& delegates); @@ -49,8 +59,6 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler { } // CefBrowserProcessHandler methods. - void GetCookieableSchemes(std::vector& schemes, - bool& include_defaults) OVERRIDE; void OnContextInitialized() OVERRIDE; void OnBeforeChildProcessLaunch( CefRefPtr command_line) OVERRIDE; diff --git a/tests/shared/common/client_app.cc b/tests/shared/common/client_app.cc index 1a76d4b87..48bb6afb2 100644 --- a/tests/shared/common/client_app.cc +++ b/tests/shared/common/client_app.cc @@ -41,7 +41,7 @@ ClientApp::ProcessType ClientApp::GetProcessType( void ClientApp::OnRegisterCustomSchemes( CefRawPtr registrar) { - RegisterCustomSchemes(registrar, cookieable_schemes_); + RegisterCustomSchemes(registrar); } } // namespace client diff --git a/tests/shared/common/client_app.h b/tests/shared/common/client_app.h index 225f80805..4be9c63a0 100644 --- a/tests/shared/common/client_app.h +++ b/tests/shared/common/client_app.h @@ -27,15 +27,10 @@ class ClientApp : public CefApp { // Determine the process type based on command-line arguments. static ProcessType GetProcessType(CefRefPtr command_line); - protected: - // Schemes that will be registered with the global cookie manager. - std::vector cookieable_schemes_; - private: // Registers custom schemes. Implemented by cefclient in // client_app_delegates_common.cc - static void RegisterCustomSchemes(CefRawPtr registrar, - std::vector& cookiable_schemes); + static void RegisterCustomSchemes(CefRawPtr registrar); // CefApp methods. void OnRegisterCustomSchemes(