forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookieManager.cpp
More file actions
95 lines (71 loc) · 3.34 KB
/
CookieManager.cpp
File metadata and controls
95 lines (71 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright © 2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "Stdafx.h"
#include "CookieManager.h"
#include "Internals\CefCookieVisitorAdapter.h"
#include "Internals\CefCompletionCallbackAdapter.h"
#include "Internals\CefSetCookieCallbackAdapter.h"
#include "Internals\CefDeleteCookiesCallbackAdapter.h"
using namespace CefSharp::Internals;
namespace CefSharp
{
void CookieManager::ThrowIfDisposed()
{
if (_cookieManager.get() == nullptr)
{
throw gcnew ObjectDisposedException("CookieManager");
}
}
bool CookieManager::DeleteCookies(String^ url, String^ name, IDeleteCookiesCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefDeleteCookiesCallback> wrapper = callback == nullptr ? NULL : new CefDeleteCookiesCallbackAdapter(callback);
return _cookieManager->DeleteCookies(StringUtils::ToNative(url), StringUtils::ToNative(name), wrapper);
}
bool CookieManager::SetCookie(String^ url, Cookie^ cookie, ISetCookieCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefSetCookieCallback> wrapper = callback == nullptr ? NULL : new CefSetCookieCallbackAdapter(callback);
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;
if (cookie->Expires.HasValue)
{
auto expires = cookie->Expires.Value;
c.expires = CefTime(DateTimeUtils::ToCefTime(expires));
}
c.creation = CefTime(DateTimeUtils::ToCefTime(cookie->Creation));
c.last_access = CefTime(DateTimeUtils::ToCefTime(cookie->LastAccess));
return _cookieManager->SetCookie(StringUtils::ToNative(url), c, wrapper);
}
void CookieManager::SetSupportedSchemes(cli::array<String^>^ schemes, bool includeDefaults, ICompletionCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback);
_cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), includeDefaults, wrapper);
}
bool CookieManager::VisitAllCookies(ICookieVisitor^ visitor)
{
ThrowIfDisposed();
CefRefPtr<CefCookieVisitorAdapter> cookieVisitor = new CefCookieVisitorAdapter(visitor);
return _cookieManager->VisitAllCookies(cookieVisitor);
}
bool CookieManager::VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor)
{
ThrowIfDisposed();
CefRefPtr<CefCookieVisitorAdapter> cookieVisitor = new CefCookieVisitorAdapter(visitor);
return _cookieManager->VisitUrlCookies(StringUtils::ToNative(url), includeHttpOnly, cookieVisitor);
}
bool CookieManager::FlushStore(ICompletionCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback);
return _cookieManager->FlushStore(wrapper);
}
}