2012-04-03 03:34:16 +02:00
|
|
|
// 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_
|
|
|
|
|
2015-08-21 22:17:59 +02:00
|
|
|
#include <set>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_cookie.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
2016-03-16 03:55:59 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2016-04-29 23:09:35 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/cookies/cookie_monster.h"
|
|
|
|
|
|
|
|
// Implementation of the CefCookieManager interface.
|
|
|
|
class CefCookieManagerImpl : public CefCookieManager {
|
|
|
|
public:
|
2015-03-02 21:25:14 +01:00
|
|
|
CefCookieManagerImpl();
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefCookieManagerImpl() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Must be called immediately after this object is created.
|
|
|
|
void Initialize(CefRefPtr<CefRequestContextImpl> request_context,
|
|
|
|
const CefString& path,
|
|
|
|
bool persist_session_cookies,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback);
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
// 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<net::CookieStore*()> CookieStoreGetter;
|
|
|
|
typedef base::Callback<void(const CookieStoreGetter&)> CookieStoreCallback;
|
2017-05-17 11:29:28 +02:00
|
|
|
void GetCookieStore(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const CookieStoreCallback& callback);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
// 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();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefCookieManager methods.
|
2015-03-02 21:25:14 +01:00
|
|
|
void SetSupportedSchemes(const std::vector<CefString>& schemes,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
bool VisitUrlCookies(const CefString& url,
|
|
|
|
bool includeHttpOnly,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefCookieVisitor> visitor) override;
|
|
|
|
bool SetCookie(const CefString& url,
|
2015-03-02 21:25:14 +01:00
|
|
|
const CefCookie& cookie,
|
|
|
|
CefRefPtr<CefSetCookieCallback> callback) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
bool DeleteCookies(const CefString& url,
|
2015-03-02 21:25:14 +01:00
|
|
|
const CefString& cookie_name,
|
|
|
|
CefRefPtr<CefDeleteCookiesCallback> callback) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
bool SetStoragePath(const CefString& path,
|
2015-03-02 21:25:14 +01:00
|
|
|
bool persist_session_cookies,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-08-04 02:59:58 +02:00
|
|
|
static bool GetCefCookie(const net::CanonicalCookie& cc, CefCookie& cookie);
|
2017-05-17 11:29:28 +02:00
|
|
|
static bool GetCefCookie(const GURL& url,
|
|
|
|
const std::string& cookie_line,
|
2012-06-19 18:29:49 +02:00
|
|
|
CefCookie& cookie);
|
|
|
|
|
2015-08-21 22:17:59 +02:00
|
|
|
// Set the schemes supported by |cookie_monster|. Default schemes will always
|
|
|
|
// be supported.
|
|
|
|
static void SetCookieMonsterSchemes(net::CookieMonster* cookie_monster,
|
2016-02-05 01:49:19 +01:00
|
|
|
const std::vector<std::string>& schemes);
|
2015-08-21 22:17:59 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
private:
|
2015-03-02 21:25:14 +01:00
|
|
|
// Returns true if a context is or will be available.
|
|
|
|
bool HasContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Execute |method| on the IO thread once the request context is available.
|
|
|
|
void RunMethodWithContext(
|
|
|
|
const CefRequestContextImpl::RequestContextCallback& method);
|
|
|
|
|
|
|
|
void InitWithContext(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
|
|
|
|
void SetStoragePathWithContext(
|
|
|
|
const CefString& path,
|
|
|
|
bool persist_session_cookies,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
|
|
|
|
void SetSupportedSchemesWithContext(
|
2016-02-05 01:49:19 +01:00
|
|
|
const std::vector<std::string>& schemes,
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
|
2016-03-16 03:55:59 +01:00
|
|
|
void GetCookieStoreWithContext(
|
2015-03-02 21:25:14 +01:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
2016-03-16 03:55:59 +01:00
|
|
|
const CookieStoreCallback& callback,
|
2015-03-02 21:25:14 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void SetSupportedSchemesInternal(const std::vector<std::string>& schemes,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback);
|
|
|
|
void VisitAllCookiesInternal(CefRefPtr<CefCookieVisitor> visitor,
|
|
|
|
const CookieStoreGetter& cookie_store_getter);
|
|
|
|
void VisitUrlCookiesInternal(const CefString& url,
|
|
|
|
bool includeHttpOnly,
|
|
|
|
CefRefPtr<CefCookieVisitor> visitor,
|
|
|
|
const CookieStoreGetter& cookie_store_getter);
|
|
|
|
void SetCookieInternal(const GURL& url,
|
|
|
|
const CefCookie& cookie,
|
|
|
|
CefRefPtr<CefSetCookieCallback> callback,
|
|
|
|
const CookieStoreGetter& cookie_store_getter);
|
|
|
|
void DeleteCookiesInternal(const GURL& url,
|
|
|
|
const CefString& cookie_name,
|
|
|
|
CefRefPtr<CefDeleteCookiesCallback> callback,
|
|
|
|
const CookieStoreGetter& cookie_store_getter);
|
|
|
|
void FlushStoreInternal(CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
const CookieStoreGetter& cookie_store_getter);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
// Used for cookie monsters owned by the context.
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context_;
|
|
|
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context_impl_;
|
|
|
|
|
|
|
|
// Used for cookie monsters owned by this object.
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath storage_path_;
|
2016-02-05 01:49:19 +01:00
|
|
|
std::vector<std::string> supported_schemes_;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::CookieMonster> cookie_store_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-04-29 23:09:35 +02:00
|
|
|
// Must be the last member.
|
|
|
|
base::WeakPtrFactory<CefCookieManagerImpl> weak_ptr_factory_;
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(CefCookieManagerImpl);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_
|