2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2015 The CefSharp Authors. All rights reserved.
|
2015-07-29 22:56:46 +02:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
2015-07-29 22:47:10 +02:00
|
|
|
#include "Stdafx.h"
|
|
|
|
|
#include "CookieManager.h"
|
|
|
|
|
|
2020-04-06 06:50:32 +10:00
|
|
|
#include "Internals\CefCookieVisitorAdapter.h"
|
2015-09-29 15:14:18 +10:00
|
|
|
#include "Internals\CefCompletionCallbackAdapter.h"
|
2017-02-14 11:40:12 +10:00
|
|
|
#include "Internals\CefSetCookieCallbackAdapter.h"
|
|
|
|
|
#include "Internals\CefDeleteCookiesCallbackAdapter.h"
|
2015-09-29 15:14:18 +10:00
|
|
|
|
2017-10-19 16:17:58 +10:00
|
|
|
using namespace CefSharp::Internals;
|
|
|
|
|
|
2015-07-29 22:47:10 +02:00
|
|
|
namespace CefSharp
|
|
|
|
|
{
|
2018-09-10 02:41:13 +02:00
|
|
|
void CookieManager::ThrowIfDisposed()
|
|
|
|
|
{
|
|
|
|
|
if (_cookieManager.get() == nullptr)
|
|
|
|
|
{
|
|
|
|
|
throw gcnew ObjectDisposedException("CookieManager");
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
bool CookieManager::DeleteCookies(String^ url, String^ name, IDeleteCookiesCallback^ callback)
|
|
|
|
|
{
|
|
|
|
|
ThrowIfDisposed();
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2021-07-31 15:35:38 +10:00
|
|
|
CefRefPtr<CefDeleteCookiesCallback> wrapper = callback == nullptr ? nullptr : new CefDeleteCookiesCallbackAdapter(callback);
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
return _cookieManager->DeleteCookies(StringUtils::ToNative(url), StringUtils::ToNative(name), wrapper);
|
|
|
|
|
}
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
bool CookieManager::SetCookie(String^ url, Cookie^ cookie, ISetCookieCallback^ callback)
|
|
|
|
|
{
|
|
|
|
|
ThrowIfDisposed();
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2021-07-31 15:35:38 +10:00
|
|
|
CefRefPtr<CefSetCookieCallback> wrapper = callback == nullptr ? nullptr : new CefSetCookieCallbackAdapter(callback);
|
2017-02-14 11:40:12 +10:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
CefCookie c;
|
|
|
|
|
StringUtils::AssignNativeFromClr(c.name, cookie->Name);
|
|
|
|
|
StringUtils::AssignNativeFromClr(c.value, cookie->Value);
|
|
|
|
|
StringUtils::AssignNativeFromClr(c.domain, cookie->Domain);
|
|
|
|
|
StringUtils::AssignNativeFromClr(c.path, cookie->Path);
|
|
|
|
|
c.secure = cookie->Secure;
|
|
|
|
|
c.httponly = cookie->HttpOnly;
|
|
|
|
|
c.has_expires = cookie->Expires.HasValue;
|
2022-09-06 11:09:42 +10:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
if (cookie->Expires.HasValue)
|
|
|
|
|
{
|
2022-09-06 15:07:09 +10:00
|
|
|
c.expires.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->Expires.Value);
|
2018-09-10 02:41:13 +02:00
|
|
|
}
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2022-09-07 10:56:29 +10:00
|
|
|
// creation/last_access are basically readonly (assigned by Chromium when the cookie is created)
|
|
|
|
|
// So I don't think we actually need to set them. The other option is to assign them to DateTime.Now
|
|
|
|
|
// Issue #4234
|
|
|
|
|
//c.creation.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->Creation);
|
|
|
|
|
//c.last_access.val = CefTimeUtils::FromDateTimeToBaseTime(cookie->LastAccess);
|
2020-10-14 14:56:35 +10:00
|
|
|
c.same_site = (cef_cookie_same_site_t)cookie->SameSite;
|
|
|
|
|
c.priority = (cef_cookie_priority_t)cookie->Priority;
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
return _cookieManager->SetCookie(StringUtils::ToNative(url), c, wrapper);
|
|
|
|
|
}
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
bool CookieManager::VisitAllCookies(ICookieVisitor^ visitor)
|
|
|
|
|
{
|
|
|
|
|
ThrowIfDisposed();
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2020-04-06 06:50:32 +10:00
|
|
|
CefRefPtr<CefCookieVisitorAdapter> cookieVisitor = new CefCookieVisitorAdapter(visitor);
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
return _cookieManager->VisitAllCookies(cookieVisitor);
|
|
|
|
|
}
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
bool CookieManager::VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor)
|
|
|
|
|
{
|
|
|
|
|
ThrowIfDisposed();
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2020-04-06 06:50:32 +10:00
|
|
|
CefRefPtr<CefCookieVisitorAdapter> cookieVisitor = new CefCookieVisitorAdapter(visitor);
|
2015-07-29 22:47:10 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
return _cookieManager->VisitUrlCookies(StringUtils::ToNative(url), includeHttpOnly, cookieVisitor);
|
|
|
|
|
}
|
2015-07-29 22:55:35 +02:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
bool CookieManager::FlushStore(ICompletionCallback^ callback)
|
|
|
|
|
{
|
|
|
|
|
ThrowIfDisposed();
|
2015-07-29 22:55:35 +02:00
|
|
|
|
2021-07-31 15:35:38 +10:00
|
|
|
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? nullptr : new CefCompletionCallbackAdapter(callback);
|
2015-10-12 08:47:38 +10:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
return _cookieManager->FlushStore(wrapper);
|
|
|
|
|
}
|
2019-01-09 21:58:52 +10:00
|
|
|
}
|