diff --git a/include/capi/cef_cookie_capi.h b/include/capi/cef_cookie_capi.h index eb62b1f14..27e99ca36 100644 --- a/include/capi/cef_cookie_capi.h +++ b/include/capi/cef_cookie_capi.h @@ -60,10 +60,10 @@ typedef struct _cef_cookie_manager_t { cef_base_t base; /// - // Set the schemes supported by this manager. By default only "http" and - // "https" schemes are supported. If |callback| is non-NULL it will be - // executed asnychronously on the IO thread after the change has been applied. - // Must be called before any cookies are accessed. + // Set the schemes supported by this manager. The default schemes ("http", + // "https", "ws" and "wss") will always be supported. If |callback| is non- + // NULL it will be executed asnychronously on the IO 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, struct _cef_completion_callback_t* callback); diff --git a/include/cef_cookie.h b/include/cef_cookie.h index e1eb0e4bf..b4cb33cb5 100644 --- a/include/cef_cookie.h +++ b/include/cef_cookie.h @@ -80,10 +80,10 @@ class CefCookieManager : public virtual CefBase { CefRefPtr callback); /// - // Set the schemes supported by this manager. By default only "http" and - // "https" schemes are supported. If |callback| is non-NULL it will be - // executed asnychronously on the IO thread after the change has been applied. - // Must be called before any cookies are accessed. + // Set the schemes supported by this manager. The default schemes ("http", + // "https", "ws" and "wss") will always be supported. If |callback| is non- + // NULL it will be executed asnychronously on the IO thread after the change + // has been applied. Must be called before any cookies are accessed. /// /*--cef(optional_param=callback)--*/ virtual void SetSupportedSchemes( diff --git a/libcef/browser/cookie_manager_impl.cc b/libcef/browser/cookie_manager_impl.cc index 90325b899..fcefd6890 100644 --- a/libcef/browser/cookie_manager_impl.cc +++ b/libcef/browser/cookie_manager_impl.cc @@ -174,8 +174,7 @@ CefCookieManagerImpl::GetExistingCookieMonster() { return cookie_monster_; } else if (request_context_impl_.get()) { scoped_refptr cookie_monster = - request_context_impl_->GetURLRequestContext()->cookie_store()-> - GetCookieMonster(); + request_context_impl_->GetCookieMonster(); DCHECK(cookie_monster.get()); return cookie_monster; } @@ -194,39 +193,12 @@ void CefCookieManagerImpl::SetSupportedSchemes( return; } - if (HasContext()) { - RunMethodWithContext( - base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, this, - schemes, callback)); - return; - } - - DCHECK(cookie_monster_.get()); - if (!cookie_monster_.get()) - return; - - supported_schemes_ = schemes; - - if (supported_schemes_.empty()) { - supported_schemes_.push_back("http"); - supported_schemes_.push_back("https"); - } - std::set scheme_set; - std::vector::const_iterator it = supported_schemes_.begin(); - for (; it != supported_schemes_.end(); ++it) + std::vector::const_iterator it = schemes.begin(); + for (; it != schemes.end(); ++it) scheme_set.insert(*it); - const char** arr = new const char*[scheme_set.size()]; - std::set::const_iterator it2 = scheme_set.begin(); - for (int i = 0; it2 != scheme_set.end(); ++it2, ++i) - arr[i] = it2->c_str(); - - cookie_monster_->SetCookieableSchemes(arr, scheme_set.size()); - - delete [] arr; - - RunAsyncCompletionOnIOThread(callback); + SetSupportedSchemesInternal(scheme_set, callback); } bool CefCookieManagerImpl::VisitAllCookies( @@ -339,7 +311,7 @@ bool CefCookieManagerImpl::SetStoragePath( storage_path_ = new_path; // Restore the previously supported schemes. - SetSupportedSchemes(supported_schemes_, callback); + SetSupportedSchemesInternal(supported_schemes_, callback); return true; } @@ -403,6 +375,30 @@ bool CefCookieManagerImpl::GetCefCookie(const GURL& url, return true; } +// static +void CefCookieManagerImpl::SetCookieMonsterSchemes( + net::CookieMonster* cookie_monster, + const std::set& schemes) { + CEF_REQUIRE_IOT(); + + std::set all_schemes = schemes; + + // Add default schemes that should always support cookies. + all_schemes.insert("http"); + all_schemes.insert("https"); + all_schemes.insert("ws"); + all_schemes.insert("wss"); + + const char** arr = new const char*[all_schemes.size()]; + std::set::const_iterator it2 = all_schemes.begin(); + for (int i = 0; it2 != all_schemes.end(); ++it2, ++i) + arr[i] = it2->c_str(); + + cookie_monster->SetCookieableSchemes(arr, all_schemes.size()); + + delete [] arr; +} + bool CefCookieManagerImpl::HasContext() { CEF_REQUIRE_IOT(); return (request_context_impl_.get() || request_context_.get()); @@ -457,17 +453,12 @@ void CefCookieManagerImpl::SetStoragePathWithContext( } void CefCookieManagerImpl::SetSupportedSchemesWithContext( - const std::vector& schemes, + const std::set& schemes, CefRefPtr callback, scoped_refptr request_context) { CEF_REQUIRE_IOT(); - std::vector scheme_vec; - std::vector::const_iterator it = schemes.begin(); - for (; it != schemes.end(); ++it) - scheme_vec.push_back(it->ToString()); - - request_context->SetCookieSupportedSchemes(scheme_vec); + request_context->SetCookieSupportedSchemes(schemes); RunAsyncCompletionOnIOThread(callback); } @@ -479,8 +470,7 @@ void CefCookieManagerImpl::GetCookieMonsterWithContext( CEF_REQUIRE_IOT(); scoped_refptr cookie_monster = - request_context->GetURLRequestContext()->cookie_store()-> - GetCookieMonster(); + request_context->GetCookieMonster(); if (task_runner->BelongsToCurrentThread()) { // Execute the callback immediately. @@ -491,6 +481,28 @@ void CefCookieManagerImpl::GetCookieMonsterWithContext( } } +void CefCookieManagerImpl::SetSupportedSchemesInternal( + const std::set& schemes, + CefRefPtr callback){ + CEF_REQUIRE_IOT(); + + if (HasContext()) { + RunMethodWithContext( + base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, this, + schemes, callback)); + return; + } + + DCHECK(cookie_monster_.get()); + if (!cookie_monster_.get()) + return; + + supported_schemes_ = schemes; + SetCookieMonsterSchemes(cookie_monster_.get(), supported_schemes_); + + RunAsyncCompletionOnIOThread(callback); +} + void CefCookieManagerImpl::VisitAllCookiesInternal( CefRefPtr visitor, scoped_refptr cookie_monster) { diff --git a/libcef/browser/cookie_manager_impl.h b/libcef/browser/cookie_manager_impl.h index 09b0ce3ff..e5ecce4bf 100644 --- a/libcef/browser/cookie_manager_impl.h +++ b/libcef/browser/cookie_manager_impl.h @@ -5,6 +5,8 @@ #ifndef CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_ #define CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_ +#include + #include "include/cef_cookie.h" #include "libcef/browser/request_context_impl.h" @@ -58,6 +60,11 @@ class CefCookieManagerImpl : public CefCookieManager { static bool GetCefCookie(const GURL& url, const std::string& cookie_line, CefCookie& cookie); + // Set the schemes supported by |cookie_monster|. Default schemes will always + // be supported. + static void SetCookieMonsterSchemes(net::CookieMonster* cookie_monster, + const std::set& schemes); + private: // Returns true if a context is or will be available. bool HasContext(); @@ -75,7 +82,7 @@ class CefCookieManagerImpl : public CefCookieManager { CefRefPtr callback, scoped_refptr request_context); void SetSupportedSchemesWithContext( - const std::vector& schemes, + const std::set& schemes, CefRefPtr callback, scoped_refptr request_context); void GetCookieMonsterWithContext( @@ -83,6 +90,9 @@ class CefCookieManagerImpl : public CefCookieManager { const CookieMonsterCallback& callback, scoped_refptr request_context); + void SetSupportedSchemesInternal( + const std::set& schemes, + CefRefPtr callback); void VisitAllCookiesInternal( CefRefPtr visitor, scoped_refptr cookie_monster); @@ -111,7 +121,7 @@ class CefCookieManagerImpl : public CefCookieManager { // Used for cookie monsters owned by this object. base::FilePath storage_path_; - std::vector supported_schemes_; + std::set supported_schemes_; scoped_refptr cookie_monster_; IMPLEMENT_REFCOUNTING(CefCookieManagerImpl); diff --git a/libcef/browser/url_request_context_getter_impl.cc b/libcef/browser/url_request_context_getter_impl.cc index ec857c019..32b2cbdc9 100644 --- a/libcef/browser/url_request_context_getter_impl.cc +++ b/libcef/browser/url_request_context_getter_impl.cc @@ -10,6 +10,7 @@ #include #include +#include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/scheme_handler.h" #include "libcef/browser/thread_util.h" #include "libcef/browser/url_network_delegate.h" @@ -326,35 +327,17 @@ void CefURLRequestContextGetterImpl::SetCookieStoragePath( cookie_store_path_ = path; // Restore the previously supported schemes. - SetCookieSupportedSchemes(cookie_supported_schemes_); + CefCookieManagerImpl::SetCookieMonsterSchemes(cookie_monster.get(), + cookie_supported_schemes_); } void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes( - const std::vector& schemes) { + const std::set& schemes) { CEF_REQUIRE_IOT(); cookie_supported_schemes_ = schemes; - - if (cookie_supported_schemes_.empty()) { - cookie_supported_schemes_.push_back("http"); - cookie_supported_schemes_.push_back("https"); - } - - std::set scheme_set; - std::vector::const_iterator it = - cookie_supported_schemes_.begin(); - for (; it != cookie_supported_schemes_.end(); ++it) - scheme_set.insert(*it); - - const char** arr = new const char*[scheme_set.size()]; - std::set::const_iterator it2 = scheme_set.begin(); - for (int i = 0; it2 != scheme_set.end(); ++it2, ++i) - arr[i] = it2->c_str(); - - url_request_context_->cookie_store()->GetCookieMonster()-> - SetCookieableSchemes(arr, scheme_set.size()); - - delete [] arr; + CefCookieManagerImpl::SetCookieMonsterSchemes(GetCookieMonster(), + cookie_supported_schemes_); } void CefURLRequestContextGetterImpl::AddHandler( @@ -367,6 +350,11 @@ void CefURLRequestContextGetterImpl::AddHandler( handler_list_.push_back(handler); } +net::CookieMonster* CefURLRequestContextGetterImpl::GetCookieMonster() const { + CEF_REQUIRE_IOT(); + return url_request_context_->cookie_store()->GetCookieMonster(); +} + void CefURLRequestContextGetterImpl::CreateProxyConfigService() { if (proxy_config_service_.get()) return; diff --git a/libcef/browser/url_request_context_getter_impl.h b/libcef/browser/url_request_context_getter_impl.h index 3c1466130..b5d39cf17 100644 --- a/libcef/browser/url_request_context_getter_impl.h +++ b/libcef/browser/url_request_context_getter_impl.h @@ -6,8 +6,8 @@ #define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ #pragma once +#include #include -#include #include "include/internal/cef_types_wrappers.h" #include "libcef/browser/url_request_context_getter.h" @@ -26,6 +26,7 @@ class MessageLoop; } namespace net { +class CookieMonster; class FtpTransactionFactory; class ProxyConfigService; class URLRequestContextStorage; @@ -59,12 +60,14 @@ class CefURLRequestContextGetterImpl : public CefURLRequestContextGetter { void SetCookieStoragePath(const base::FilePath& path, bool persist_session_cookies); - void SetCookieSupportedSchemes(const std::vector& schemes); + void SetCookieSupportedSchemes(const std::set& schemes); // Keep a reference to all handlers sharing this context so that they'll be // kept alive until the context is destroyed. void AddHandler(CefRefPtr handler); + net::CookieMonster* GetCookieMonster() const; + CefURLRequestManager* request_manager() const { return url_request_manager_.get(); } @@ -87,7 +90,7 @@ class CefURLRequestContextGetterImpl : public CefURLRequestContextGetter { content::URLRequestInterceptorScopedVector request_interceptors_; base::FilePath cookie_store_path_; - std::vector cookie_supported_schemes_; + std::set cookie_supported_schemes_; std::vector > handler_list_; diff --git a/tests/cefclient/common/client_app.cc b/tests/cefclient/common/client_app.cc index 262997483..3b16117fd 100644 --- a/tests/cefclient/common/client_app.cc +++ b/tests/cefclient/common/client_app.cc @@ -43,10 +43,6 @@ ClientApp::ProcessType ClientApp::GetProcessType( void ClientApp::OnRegisterCustomSchemes( CefRefPtr registrar) { - // Default schemes that support cookies. - cookieable_schemes_.push_back("http"); - cookieable_schemes_.push_back("https"); - RegisterCustomSchemes(registrar, cookieable_schemes_); } diff --git a/tests/unittests/cookie_unittest.cc b/tests/unittests/cookie_unittest.cc index 60649e141..4c5eb80f9 100644 --- a/tests/unittests/cookie_unittest.cc +++ b/tests/unittests/cookie_unittest.cc @@ -1083,8 +1083,6 @@ class CookieTestSchemeHandler : public TestHandler { if (scheme_ != "http") { std::vector schemes; - schemes.push_back("http"); - schemes.push_back("https"); schemes.push_back(scheme_); manager1_->SetSupportedSchemes(schemes, NULL); diff --git a/tests/unittests/urlrequest_unittest.cc b/tests/unittests/urlrequest_unittest.cc index 6df61b9ac..375f6e4b0 100644 --- a/tests/unittests/urlrequest_unittest.cc +++ b/tests/unittests/urlrequest_unittest.cc @@ -1003,8 +1003,6 @@ class RequestTestHandler : public TestHandler, // Set the schemes that are allowed to store cookies. std::vector supported_schemes; - supported_schemes.push_back("http"); - supported_schemes.push_back("https"); supported_schemes.push_back(kRequestScheme); // Continue the test once supported schemes has been set.