// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights // reserved. Use of this source code is governed by a BSD-style license that can // be found in the LICENSE file. #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" #include "libcef/browser/thread_util.h" #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "net/cookies/cookie_monster.h" // Implementation of the CefCookieManager interface. class CefCookieManagerImpl : public CefCookieManager { public: CefCookieManagerImpl(); ~CefCookieManagerImpl() override; // Must be called immediately after this object is created. void Initialize(CefRefPtr request_context, const CefString& path, bool persist_session_cookies, CefRefPtr callback); // Executes |callback| either synchronously or asynchronously with the // CookieStoreGetter when the cookie store object is available. If // |task_runner| is NULL the callback will be executed on the originating // thread. CookieStoreGetter can only be executed on, and the resulting cookie // store object can only be accessed on, the IO thread. typedef base::Callback CookieStoreGetter; typedef base::Callback CookieStoreCallback; void GetCookieStore( scoped_refptr task_runner, const CookieStoreCallback& callback); // Returns the existing cookie store object. Logs an error if the cookie // store does not yet exist. Must be called on the IO thread. net::CookieStore* GetExistingCookieStore(); // CefCookieManager methods. void SetSupportedSchemes(const std::vector& schemes, CefRefPtr callback) override; bool VisitAllCookies(CefRefPtr visitor) override; bool VisitUrlCookies(const CefString& url, bool includeHttpOnly, CefRefPtr visitor) override; bool SetCookie(const CefString& url, const CefCookie& cookie, CefRefPtr callback) override; bool DeleteCookies(const CefString& url, const CefString& cookie_name, CefRefPtr callback) override; bool SetStoragePath(const CefString& path, bool persist_session_cookies, CefRefPtr callback) override; bool FlushStore(CefRefPtr callback) override; static bool GetCefCookie(const net::CanonicalCookie& cc, CefCookie& cookie); 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::vector& schemes); private: // Returns true if a context is or will be available. bool HasContext(); // Execute |method| on the IO thread once the request context is available. void RunMethodWithContext( const CefRequestContextImpl::RequestContextCallback& method); void InitWithContext( CefRefPtr callback, scoped_refptr request_context); void SetStoragePathWithContext( const CefString& path, bool persist_session_cookies, CefRefPtr callback, scoped_refptr request_context); void SetSupportedSchemesWithContext( const std::vector& schemes, CefRefPtr callback, scoped_refptr request_context); void GetCookieStoreWithContext( scoped_refptr task_runner, const CookieStoreCallback& callback, scoped_refptr request_context); void SetSupportedSchemesInternal( const std::vector& schemes, CefRefPtr callback); void VisitAllCookiesInternal( CefRefPtr visitor, const CookieStoreGetter& cookie_store_getter); void VisitUrlCookiesInternal( const CefString& url, bool includeHttpOnly, CefRefPtr visitor, const CookieStoreGetter& cookie_store_getter); void SetCookieInternal( const GURL& url, const CefCookie& cookie, CefRefPtr callback, const CookieStoreGetter& cookie_store_getter); void DeleteCookiesInternal( const GURL& url, const CefString& cookie_name, CefRefPtr callback, const CookieStoreGetter& cookie_store_getter); void FlushStoreInternal( CefRefPtr callback, const CookieStoreGetter& cookie_store_getter); // Used for cookie monsters owned by the context. CefRefPtr request_context_; scoped_refptr request_context_impl_; // Used for cookie monsters owned by this object. base::FilePath storage_path_; std::vector supported_schemes_; std::unique_ptr cookie_store_; // Must be the last member. base::WeakPtrFactory weak_ptr_factory_; IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(CefCookieManagerImpl); }; #endif // CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_