Repository navigation
Expand file tree
/
Copy pathCookieManager.cpp
More file actions
106 lines (80 loc) · 3.48 KB
/
Copy pathCookieManager.cpp
File metadata and controls
106 lines (80 loc) · 3.48 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
96
97
98
99
100
101
102
103
104
105
106
// Copyright © 2010-2015 The CefSharp Project. 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 "CookieAsyncWrapper.h"
#include "CookieVisitor.h"
#include "Internals\CefCompletionCallbackAdapter.h"
#include "Cef.h"
namespace CefSharp
{
namespace Internals
{
void CookieManager::ThrowIfDisposed()
{
if (_cookieManager.get() == nullptr)
{
throw gcnew ObjectDisposedException("CookieManager");
}
}
Task<bool>^ CookieManager::DeleteCookiesAsync(String^ url, String^ name)
{
ThrowIfDisposed();
auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, name);
if (CefCurrentlyOn(TID_IO))
{
auto source = gcnew TaskCompletionSource<bool>();
source->TrySetResult(cookieInvoker->DeleteCookies());
return source->Task;
}
return Cef::IOThreadTaskFactory->StartNew(gcnew Func<bool>(cookieInvoker, &CookieAsyncWrapper::DeleteCookies));
}
Task<bool>^ CookieManager::SetCookieAsync(String^ url, Cookie^ cookie)
{
ThrowIfDisposed();
auto cookieInvoker = gcnew CookieAsyncWrapper(_cookieManager.get(), url, cookie->Name, cookie->Value, cookie->Domain, cookie->Path, cookie->Secure, cookie->HttpOnly, cookie->Expires.HasValue, cookie->Expires.HasValue ? cookie->Expires.Value : DateTime());
if (CefCurrentlyOn(TID_IO))
{
auto source = gcnew TaskCompletionSource<bool>();
source->TrySetResult(cookieInvoker->SetCookie());
return source->Task;
}
return Cef::IOThreadTaskFactory->StartNew(gcnew Func<bool>(cookieInvoker, &CookieAsyncWrapper::SetCookie));
}
bool CookieManager::SetStoragePath(String^ path, bool persistSessionCookies)
{
ThrowIfDisposed();
return _cookieManager->SetStoragePath(StringUtils::ToNative(path), persistSessionCookies, NULL);
}
void CookieManager::SetSupportedSchemes(... cli::array<String^>^ schemes)
{
ThrowIfDisposed();
_cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), NULL);
}
bool CookieManager::VisitAllCookies(ICookieVisitor^ visitor)
{
ThrowIfDisposed();
CefRefPtr<CookieVisitor> cookieVisitor = new CookieVisitor(visitor);
return _cookieManager->VisitAllCookies(cookieVisitor);
}
bool CookieManager::VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor)
{
ThrowIfDisposed();
CefRefPtr<CookieVisitor> cookieVisitor = new CookieVisitor(visitor);
return _cookieManager->VisitUrlCookies(StringUtils::ToNative(url), includeHttpOnly, cookieVisitor);
}
Task<bool>^ CookieManager::FlushStoreAsync()
{
ThrowIfDisposed();
auto handler = gcnew TaskCompletionHandler();
CefRefPtr<CefCompletionCallback> wrapper = new CefCompletionCallbackAdapter(handler);
if (_cookieManager->FlushStore(wrapper))
{
return handler->Task;
}
//returns false if cookies cannot be accessed.
return TaskExtensions::FromResult(false);
}
}
}