#include "base/stl_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/thread_pool.h"
+#include "browser_context_efl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_options.h"
+#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "net/cookies/static_cookie_policy.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "url/gurl.h"
-#include "net/cookies/cookie_store_test_callbacks.h"
-
-#include <Eina.h>
-
using content::BrowserThread;
using net::CookieList;
using net::CookieMonster;
void* user_data_;
};
-CookieManager::CookieManager()
- : cookie_policy_(EWK_COOKIE_ACCEPT_POLICY_ALWAYS),
- weak_ptr_factory_(this) {
-}
+CookieManager::CookieManager(EWebContext* eweb_context)
+ : eweb_context_(eweb_context),
+ cookie_policy_(EWK_COOKIE_ACCEPT_POLICY_ALWAYS),
+ weak_ptr_factory_(this) {}
CookieManager::~CookieManager() {
DeleteSessionCookiesOnIOThread();
void CookieManager::DeleteSessionCookiesOnIOThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- std::unique_ptr<net::CookieStore> cookie_store = GetCookieStore();
+ net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->DeleteSessionCookiesAsync(
base::OnceCallback<void(uint32_t)>());
}
}
-static void DeleteCookiesOnIOThread(std::unique_ptr<net::CookieStore> cookie_store,
- const std::string& url,
- const std::string& cookie_name) {
+void CookieManager::DeleteCookiesOnIOThread(const std::string& url,
+ const std::string& cookie_name) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ net::CookieStore* cookie_store = GetCookieStore();
+ if (!cookie_store)
+ return;
+
if (url.empty()) { // Delete all cookies.
cookie_store->DeleteAllAsync(net::CookieMonster::DeleteCallback());
+ return;
}
+
GURL gurl(url);
if (!gurl.is_valid())
return;
+
if (cookie_name.empty()) {
// Delete all matching host cookies.
-#if !defined(EWK_BRINGUP) // FIXME: m69 bringup
- cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(base::Time(), base::Time::Max(),
- content::StoragePartitionImpl::CreatePredicateForHostCookies(gurl),
- net::CookieMonster::DeleteCallback());
-#endif
+ net::CookieDeletionInfo delete_info;
+ delete_info.host = gurl.host();
+ cookie_store->DeleteAllMatchingInfoAsync(
+ std::move(delete_info), net::CookieStore::DeleteCallback());
} else {
// Delete all matching host and domain cookies.
#if !defined(EWK_BRINGUP) // FIXME: m76 bringup
}
void CookieManager::DeleteCookiesAsync(const std::string& url,
- const std::string& cookie_name)
-{
+ const std::string& cookie_name) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::unique_ptr<net::CookieStore> cookie_store = GetCookieStore();
- if (cookie_store.get()) {
- base::ThreadPool::PostTask(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(DeleteCookiesOnIOThread, std::move(cookie_store), url,
- cookie_name));
- }
+ base::ThreadPool::PostTask(
+ FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&CookieManager::DeleteCookiesOnIOThread,
+ base::Unretained(this), url, cookie_name));
}
static void SetStoragePathOnIOThread(
void CookieManager::GetHostNamesWithCookiesAsync(AsyncHostnamesGetCb callback, void *data) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
host_callback_queue_.push(new EwkGetHostCallback(callback, data));
- std::unique_ptr<net::CookieStore> cookie_store = GetCookieStore();
- if (cookie_store.get()) {
- base::ThreadPool::PostTask(
- FROM_HERE, {BrowserThread::IO},
- base::BindOnce(&CookieManager::FetchCookiesOnIOThread, GetSharedThis(),
- std::move(cookie_store)));
- }
+ base::ThreadPool::PostTask(
+ FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&CookieManager::FetchCookiesOnIOThread, GetSharedThis()));
}
-void CookieManager::FetchCookiesOnIOThread(
- std::unique_ptr<net::CookieStore> cookie_store) {
+void CookieManager::FetchCookiesOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- if (cookie_store.get()) {
+ net::CookieStore* cookie_store = GetCookieStore();
+ if (cookie_store) {
cookie_store->GetAllCookiesAsync(base::BindOnce(
&CookieManager::OnFetchComplete, base::Unretained(this)));
} else {
}
bool CookieManager::IsFileSchemeCookiesAllowed() {
- auto cookie_monster =
- static_cast<net::CookieMonster*>(GetCookieStore().get());
- if (!cookie_monster)
- return false;
-#if !defined(EWK_BRINGUP) // FIXME: m94 bringup
AutoLock lock(file_scheme_lock_);
- return cookie_monster->IsCookieableScheme(url::kFileScheme);
-#else
- return false;
-#endif
+ return is_file_scheme_cookies_allowed_;
}
-void CookieManager::SetAcceptFileSchemeCookies(bool accept) {
- auto cookie_monster =
- static_cast<net::CookieMonster*>(GetCookieStore().get());
- if (!cookie_monster)
+void CookieManager::AllowFileSchemeCookies(bool allow) {
+ if (allow == is_file_scheme_cookies_allowed_)
return;
- std::vector<std::string> schemes(
- CookieMonster::kDefaultCookieableSchemes,
- CookieMonster::kDefaultCookieableSchemes +
- CookieMonster::kDefaultCookieableSchemesCount);
- if (accept)
- schemes.push_back(url::kFileScheme);
+ auto* cookie_manager = eweb_context_->browser_context()
+ ->GetDefaultStoragePartition()
+ ->GetCookieManagerForBrowserProcess();
- AutoLock lock(file_scheme_lock_);
- cookie_monster->SetCookieableSchemes(schemes, base::DoNothing());
+ base::ThreadPool::PostTask(
+ FROM_HERE, {BrowserThread::IO},
+ base::BindOnce(&CookieManager::AllowFileSchemeCookiesOnIOThread,
+ weak_ptr_factory_.GetWeakPtr(), cookie_manager, allow));
}
-static void SignalGetCookieValueCompleted(base::WaitableEvent* completion,
- std::string* result,
- const std::string& value) {
+void CookieManager::AllowFileSchemeCookiesOnIOThread(
+ network::mojom::CookieManager* cookie_manager,
+ bool allow) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ cookie_manager->AllowFileSchemeCookies(
+ allow, base::BindOnce(&CookieManager::OnAllowFileSchemeCookies,
+ weak_ptr_factory_.GetWeakPtr(), allow));
+}
+
+void CookieManager::OnAllowFileSchemeCookies(bool allow, bool success) {
+ if (success)
+ is_file_scheme_cookies_allowed_ = allow;
+}
+
+static void SignalGetCookieValueCompleted(
+ base::WaitableEvent* completion,
+ std::string* result,
+ const net::CookieAccessResultList& cookie_list,
+ const net::CookieAccessResultList& excluded_cookies) {
DCHECK(completion);
- *result = value;
+ std::string cookie_line = net::CanonicalCookie::BuildCookieLine(cookie_list);
+ *result = cookie_line;
completion->Signal();
}
-static void GetCookieValueOnIOThread(std::unique_ptr<net::CookieStore> cookie_store,
+static void GetCookieValueOnIOThread(net::CookieStore* cookie_store,
const GURL& host,
std::string* result,
base::WaitableEvent* completion) {
net::CookieOptions options;
options.set_include_httponly();
- if (cookie_store.get()) {
-#if !defined(EWK_BRINGUP) // FIXME: m67 bringup
- cookie_store->GetCookiesWithOptionsAsync(
- host, options,
- base::BindOnce(SignalGetCookieValueCompleted, completion, i result));
-#endif
+ if (cookie_store) {
+ cookie_store->GetCookieListWithOptionsAsync(
+ host, options, net::CookiePartitionKeyCollection::Todo(),
+ base::BindOnce(SignalGetCookieValueCompleted, completion, result));
} else {
DCHECK(completion);
completion->Signal();
std::string CookieManager::GetCookiesForURL(const std::string& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::unique_ptr<net::CookieStore> cookie_store = GetCookieStore();
- if (!cookie_store.get())
+ net::CookieStore* cookie_store = GetCookieStore();
+ if (!cookie_store)
return std::string();
std::string cookie_value;
base::WaitableEvent::InitialState::NOT_SIGNALED);
base::ThreadPool::PostTask(
FROM_HERE, {BrowserThread::IO},
- base::BindOnce(GetCookieValueOnIOThread, std::move(cookie_store),
- GURL(url), &cookie_value, &completion));
+ base::BindOnce(GetCookieValueOnIOThread, cookie_store, GURL(url),
+ &cookie_value, &completion));
// allow wait temporarily.
completion.Wait();
return cookie_value;
return scoped_refptr<content::URLRequestContextGetterEfl>(request_context_getter_.get());
}
-std::unique_ptr<net::CookieStore> CookieManager::GetCookieStore() const {
- scoped_refptr<content::URLRequestContextGetterEfl> request_context_getter = GetContextGetter();
- if (request_context_getter.get()) {
- return std::unique_ptr<net::CookieStore>(
- request_context_getter->GetURLRequestContext()->cookie_store());
- } else {
- return std::unique_ptr<net::CookieStore>();
- }
+net::CookieStore* CookieManager::GetCookieStore() const {
+ return request_context_getter_
+ ? request_context_getter_->GetURLRequestContext()->cookie_store()
+ : nullptr;
}
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/cookie_util.h"
-#include "public/ewk_cookie_manager.h"
#include "url/gurl.h"
#include "url_request_context_getter_efl.h"
class ResourceContext;
}
+namespace network {
+namespace mojom {
+class CookieManager;
+}
+} // namespace network
+
+class EWebContext;
+
struct _Ewk_Error;
class CookieManager : public base::RefCountedThreadSafe<CookieManager> {
public:
typedef void (*AsyncHostnamesGetCb)(Eina_List*, _Ewk_Error*, void *);
- CookieManager();
+ explicit CookieManager(EWebContext* eweb_context);
virtual ~CookieManager();
CookieManager(const CookieManager&) = delete;
// file scheme
bool IsFileSchemeCookiesAllowed();
- void SetAcceptFileSchemeCookies(bool accept);
+ void AllowFileSchemeCookies(bool allow);
private:
struct EwkGetHostCallback;
void DeleteSessionCookiesOnIOThread();
+ void DeleteCookiesOnIOThread(const std::string& url,
+ const std::string& cookie_name);
bool AllowCookies(const GURL& url,
const net::SiteForCookies& site_for_cookies,
bool setting_cookie);
// Fetch the cookies. This must be called in the IO thread.
- void FetchCookiesOnIOThread(std::unique_ptr<net::CookieStore> cookie_store);
+ void FetchCookiesOnIOThread();
void OnFetchComplete(const net::CookieList& cookies);
+ void AllowFileSchemeCookiesOnIOThread(
+ network::mojom::CookieManager* cookie_manager,
+ bool allow);
+ void OnAllowFileSchemeCookies(bool allow, bool success);
+
scoped_refptr<CookieManager> GetSharedThis();
scoped_refptr<content::URLRequestContextGetterEfl> GetContextGetter() const;
- std::unique_ptr<net::CookieStore> GetCookieStore() const;
+ net::CookieStore* GetCookieStore() const;
+
+ EWebContext* eweb_context_;
scoped_refptr<content::URLRequestContextGetterEfl> request_context_getter_;
//cookie policy information
base::Lock lock_;
Ewk_Cookie_Accept_Policy cookie_policy_;
// This only mutates on the UI thread.
std::queue< EwkGetHostCallback* > host_callback_queue_;
- base::WeakPtrFactory<CookieManager> weak_ptr_factory_;
// file scheme
base::Lock file_scheme_lock_;
+ bool is_file_scheme_cookies_allowed_ = false;
+ base::WeakPtrFactory<CookieManager> weak_ptr_factory_;
};
#endif //cookie_manager_h