-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
RequestContext.cpp
206 lines (144 loc) · 7.02 KB
/
RequestContext.cpp
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// 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 "RequestContext.h"
#include "include\cef_parser.h"
#include "CookieManager.h"
#include "Internals\CefSchemeHandlerFactoryAdapter.h"
#include "Internals\CefCompletionCallbackAdapter.h"
#include "Internals\CefResolveCallbackAdapter.h"
#include "Internals\TypeConversion.h"
using namespace System::Runtime::InteropServices;
namespace CefSharp
{
namespace Core
{
bool RequestContext::IsSame(IRequestContext^ context)
{
ThrowIfDisposed();
auto requestContext = (RequestContext^)context->UnWrap();
return _requestContext->IsSame(requestContext);
}
bool RequestContext::IsSharingWith(IRequestContext^ context)
{
ThrowIfDisposed();
auto requestContext = (RequestContext^)context->UnWrap();
return _requestContext->IsSharingWith(requestContext);
}
ICookieManager^ RequestContext::GetCookieManager(ICompletionCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? nullptr : new CefCompletionCallbackAdapter(callback);
auto cookieManager = _requestContext->GetCookieManager(wrapper);
if (cookieManager.get())
{
return gcnew CookieManager(cookieManager);
}
return nullptr;
}
bool RequestContext::RegisterSchemeHandlerFactory(String^ schemeName, String^ domainName, ISchemeHandlerFactory^ factory)
{
ThrowIfDisposed();
auto wrapper = new CefSchemeHandlerFactoryAdapter(factory);
return _requestContext->RegisterSchemeHandlerFactory(StringUtils::ToNative(schemeName), StringUtils::ToNative(domainName), wrapper);
}
bool RequestContext::ClearSchemeHandlerFactories()
{
ThrowIfDisposed();
return _requestContext->ClearSchemeHandlerFactories();
}
bool RequestContext::HasPreference(String^ name)
{
ThrowIfDisposed();
ThrowIfExecutedOnNonCefUiThread();
return _requestContext->HasPreference(StringUtils::ToNative(name));
}
Object^ RequestContext::GetPreference(String^ name)
{
ThrowIfDisposed();
ThrowIfExecutedOnNonCefUiThread();
return TypeConversion::FromNative(_requestContext->GetPreference(StringUtils::ToNative(name)));
}
IDictionary<String^, Object^>^ RequestContext::GetAllPreferences(bool includeDefaults)
{
ThrowIfDisposed();
auto preferences = _requestContext->GetAllPreferences(includeDefaults);
return TypeConversion::FromNative(preferences);
}
bool RequestContext::CanSetPreference(String^ name)
{
ThrowIfDisposed();
ThrowIfExecutedOnNonCefUiThread();
return _requestContext->CanSetPreference(StringUtils::ToNative(name));
}
bool RequestContext::SetPreference(String^ name, Object^ value, [Out] String^ %error)
{
ThrowIfDisposed();
ThrowIfExecutedOnNonCefUiThread();
CefString cefError;
auto success = _requestContext->SetPreference(StringUtils::ToNative(name), TypeConversion::ToNative(value), cefError);
error = StringUtils::ToClr(cefError);
return success;
}
void RequestContext::ClearCertificateExceptions(ICompletionCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? nullptr : new CefCompletionCallbackAdapter(callback);
_requestContext->ClearCertificateExceptions(wrapper);
}
void RequestContext::ClearHttpAuthCredentials(ICompletionCallback^ callback)
{
ThrowIfDisposed();
//TODO: Remove this once CEF Issue has been resolved
//ClearHttpAuthCredentials crashes when no callback specified
if (callback == nullptr)
{
callback = gcnew CefSharp::Callback::NoOpCompletionCallback();
}
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? nullptr : new CefCompletionCallbackAdapter(callback);
_requestContext->ClearHttpAuthCredentials(wrapper);
}
void RequestContext::CloseAllConnections(ICompletionCallback^ callback)
{
ThrowIfDisposed();
CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? nullptr : new CefCompletionCallbackAdapter(callback);
_requestContext->CloseAllConnections(wrapper);
}
Task<ResolveCallbackResult>^ RequestContext::ResolveHostAsync(Uri^ origin)
{
ThrowIfDisposed();
auto callback = gcnew TaskResolveCallback();
CefRefPtr<CefResolveCallback> callbackWrapper = new CefResolveCallbackAdapter(callback);
_requestContext->ResolveHost(StringUtils::ToNative(origin->AbsoluteUri), callbackWrapper);
return callback->Task;
}
Object^ RequestContext::GetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType)
{
ThrowIfDisposed();
auto result = _requestContext->GetWebsiteSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType);
return TypeConversion::FromNative(result);
}
void RequestContext::SetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Object^ value)
{
ThrowIfDisposed();
auto nativeValue = TypeConversion::ToNative(value);
_requestContext->SetWebsiteSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType, nativeValue);
}
Enums::ContentSettingValues RequestContext::GetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType)
{
ThrowIfDisposed();
auto result = _requestContext->GetContentSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType);
return (Enums::ContentSettingValues)result;
}
void RequestContext::SetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Enums::ContentSettingValues value)
{
ThrowIfDisposed();
_requestContext->SetContentSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType, (cef_content_setting_values_t)value);
}
IRequestContext^ RequestContext::UnWrap()
{
return this;
}
}
}