CEFInterfaceCookieManager.cpp
5.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Engine/Source/Runtime/WebBrowser/Private/CEF/CEFCookieManager.cpp
#include "CoreTypes.h"
#include "Containers/ContainersFwd.h"
#if WITH_CEF3
#include "IWebInterfaceBrowserCookieManager.h"
#include "WebInterfaceBrowserSingleton.h"
#if PLATFORM_WINDOWS
# include "Windows/WindowsHWrapper.h"
# include "Windows/AllowWindowsPlatformTypes.h"
# include "Windows/AllowWindowsPlatformAtomics.h"
#endif
#pragma push_macro("OVERRIDE")
# undef OVERRIDE // cef headers provide their own OVERRIDE macro
THIRD_PARTY_INCLUDES_START
#if PLATFORM_APPLE
PRAGMA_DISABLE_DEPRECATION_WARNINGS
#endif
# include "include/cef_app.h"
#if PLATFORM_APPLE
PRAGMA_ENABLE_DEPRECATION_WARNINGS
#endif
THIRD_PARTY_INCLUDES_END
#pragma pop_macro("OVERRIDE")
#if PLATFORM_WINDOWS
# include "Windows/HideWindowsPlatformAtomics.h"
# include "Windows/HideWindowsPlatformTypes.h"
#endif
class FCefInterfaceCookieManager
: public IWebInterfaceBrowserCookieManager
{
public:
virtual ~FCefInterfaceCookieManager()
{ }
virtual void SetCookie(const FString& URL, const FCookie& Cookie, TFunction<void(bool)> Completed) override
{
CefRefPtr<FSetCookieFunctionCallback> Callback = Completed ? new FSetCookieFunctionCallback(Completed) : nullptr;
CefCookie CefCookie;
CefString(&CefCookie.name) = TCHAR_TO_WCHAR(*Cookie.Name);
CefString(&CefCookie.value) = TCHAR_TO_WCHAR(*Cookie.Value);
CefString(&CefCookie.domain) = TCHAR_TO_WCHAR(*Cookie.Domain);
CefString(&CefCookie.path) = TCHAR_TO_WCHAR(*Cookie.Path);
CefCookie.secure = Cookie.bSecure;
CefCookie.httponly = Cookie.bHttpOnly;
CefCookie.has_expires = Cookie.bHasExpires;
cef_time_t CefTime;
CefTime.year = Cookie.Expires.GetYear();
CefTime.month = Cookie.Expires.GetMonth();
CefTime.day_of_month = Cookie.Expires.GetDay();
CefTime.hour = Cookie.Expires.GetHour();
CefTime.minute = Cookie.Expires.GetMinute();
CefTime.second = Cookie.Expires.GetSecond();
CefTime.millisecond = Cookie.Expires.GetMillisecond();
const EDayOfWeek DayOfWeek = Cookie.Expires.GetDayOfWeek();
if (DayOfWeek == EDayOfWeek::Sunday) // some crazy reason our date/time class think Monday is the beginning of the week
{
CefTime.day_of_week = 0;
}
else
{
CefTime.day_of_week = ((int32)DayOfWeek) + 1;
}
CefCookie.expires = CefTime;
if (!CookieManager->SetCookie(TCHAR_TO_WCHAR(*URL), CefCookie, Callback))
{
Callback->OnComplete(false);
}
}
virtual void DeleteCookies(const FString& URL, const FString& CookieName, TFunction<void(int)> Completed) override
{
CefRefPtr<FDeleteCookiesFunctionCallback> Callback = Completed ? new FDeleteCookiesFunctionCallback(Completed) : nullptr;
if (!CookieManager->DeleteCookies(TCHAR_TO_WCHAR(*URL), TCHAR_TO_WCHAR(*CookieName), Callback))
{
Callback->OnComplete(-1);
}
}
private:
FCefInterfaceCookieManager(
const CefRefPtr<CefCookieManager>& InCookieManager)
: CookieManager(InCookieManager)
{ }
// Callback that will invoke the callback with the result on the UI thread.
class FDeleteCookiesFunctionCallback
: public CefDeleteCookiesCallback
{
TFunction<void(int)> Callback;
public:
FDeleteCookiesFunctionCallback(const TFunction<void(int)>& InCallback)
: Callback(InCallback)
{}
virtual void OnComplete(int NumDeleted) override
{
// We're on the IO thread, so we'll have to schedule the callback on the main thread
CefPostTask(TID_UI, new FDeleteCookiesNotificationTask(Callback, NumDeleted));
}
IMPLEMENT_REFCOUNTING(FDeleteCookiesFunctionCallback);
};
// Callback that will invoke the callback with the result on the UI thread.
class FSetCookieFunctionCallback
: public CefSetCookieCallback
{
TFunction<void(bool)> Callback;
public:
FSetCookieFunctionCallback(const TFunction<void(bool)>& InCallback)
: Callback(InCallback)
{}
virtual void OnComplete(bool bSuccess) override
{
// We're on the IO thread, so we'll have to schedule the callback on the main thread
CefPostTask(TID_UI, new FSetCookieNotificationTask(Callback, bSuccess));
}
IMPLEMENT_REFCOUNTING(FSetCookieFunctionCallback);
};
// Task for executing a callback on a given thread.
class FDeleteCookiesNotificationTask
: public CefTask
{
TFunction<void(int)> Callback;
int Value;
public:
FDeleteCookiesNotificationTask(const TFunction<void(int)>& InCallback, int InValue)
: Callback(InCallback)
, Value(InValue)
{}
virtual void Execute() override
{
Callback(Value);
}
IMPLEMENT_REFCOUNTING(FDeleteCookiesNotificationTask);
};
// Task for executing a callback on a given thread.
class FSetCookieNotificationTask
: public CefTask
{
TFunction<void(bool)> Callback;
bool bSuccess;
public:
FSetCookieNotificationTask(const TFunction<void(bool)>& InCallback, bool InSuccess)
: Callback(InCallback)
, bSuccess(InSuccess)
{}
virtual void Execute() override
{
Callback(bSuccess);
}
IMPLEMENT_REFCOUNTING(FSetCookieNotificationTask);
};
private:
const CefRefPtr<CefCookieManager> CookieManager;
friend FCefWebInterfaceCookieManagerFactory;
};
TSharedRef<IWebInterfaceBrowserCookieManager> FCefWebInterfaceCookieManagerFactory::Create(
const CefRefPtr<CefCookieManager>& CookieManager)
{
return MakeShareable(new FCefInterfaceCookieManager(
CookieManager));
}
#endif