-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathResourceHandlerWrapper.cpp
More file actions
138 lines (116 loc) · 3.96 KB
/
Copy pathResourceHandlerWrapper.cpp
File metadata and controls
138 lines (116 loc) · 3.96 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
// Copyright © 2010-2017 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 "Internals/CefRequestWrapper.h"
#include "Internals/CefResponseWrapper.h"
#include "Internals/CefCallbackWrapper.h"
#include "ResourceHandlerWrapper.h"
#include "Internals/TypeConversion.h"
using namespace System::Runtime::InteropServices;
using namespace System::IO;
namespace CefSharp
{
bool ResourceHandlerWrapper::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
auto callbackWrapper = gcnew CefCallbackWrapper(callback);
_request = gcnew CefRequestWrapper(request);
return _handler->ProcessRequest(_request, callbackWrapper);
}
void ResourceHandlerWrapper::GetResponseHeaders(CefRefPtr<CefResponse> response, int64& response_length, CefString& redirectUrl)
{
String^ newRedirectUrl;
CefResponseWrapper responseWrapper(response);
_handler->GetResponseHeaders(%responseWrapper, response_length, newRedirectUrl);
redirectUrl = StringUtils::ToNative(newRedirectUrl);
}
bool ResourceHandlerWrapper::ReadResponse(void* dataOut, int bytesToRead, int& bytesRead, CefRefPtr<CefCallback> callback)
{
UnmanagedMemoryStream writeStream((Byte*)dataOut, (Int64)bytesToRead, (Int64)bytesToRead, FileAccess::Write);
auto callbackWrapper = gcnew CefCallbackWrapper(callback);
return _handler->ReadResponse(%writeStream, bytesRead, callbackWrapper);
}
bool ResourceHandlerWrapper::CanGetCookie(const CefCookie& cefCookie)
{
auto cookie = GetCookie(cefCookie);
//Default value is true
return _handler->CanGetCookie(cookie);
}
bool ResourceHandlerWrapper::CanSetCookie(const CefCookie& cefCookie)
{
auto cookie = GetCookie(cefCookie);
//Default value is true
return _handler->CanSetCookie(cookie);
}
void ResourceHandlerWrapper::Cancel()
{
_handler->Cancel();
}
Cookie^ ResourceHandlerWrapper::GetCookie(const CefCookie& cefCookie)
{
auto cookie = gcnew Cookie();
String^ cookieName = StringUtils::ToClr(cefCookie.name);
if (!String::IsNullOrEmpty(cookieName))
{
cookie->Name = StringUtils::ToClr(cefCookie.name);
cookie->Value = StringUtils::ToClr(cefCookie.value);
cookie->Domain = StringUtils::ToClr(cefCookie.domain);
cookie->Path = StringUtils::ToClr(cefCookie.path);
cookie->Secure = cefCookie.secure == 1;
cookie->HttpOnly = cefCookie.httponly == 1;
try
{
if (cefCookie.has_expires)
{
cookie->Expires = DateTime(
cefCookie.expires.year,
cefCookie.expires.month,
cefCookie.expires.day_of_month,
cefCookie.expires.hour,
cefCookie.expires.minute,
cefCookie.expires.second,
cefCookie.expires.millisecond
);
}
}
catch (Exception^ ex)
{
cookie->Expires = DateTime::MinValue;
}
//TODO: There is a method in TypeUtils that's in BrowserSubProcess that convers CefTime, need to make it accessible.
try
{
cookie->Creation = DateTime(
cefCookie.creation.year,
cefCookie.creation.month,
cefCookie.creation.day_of_month,
cefCookie.creation.hour,
cefCookie.creation.minute,
cefCookie.creation.second,
cefCookie.creation.millisecond
);
}
catch (Exception^ ex)
{
cookie->Creation = DateTime::MinValue;
}
try
{
cookie->LastAccess = DateTime(
cefCookie.last_access.year,
cefCookie.last_access.month,
cefCookie.last_access.day_of_month,
cefCookie.last_access.hour,
cefCookie.last_access.minute,
cefCookie.last_access.second,
cefCookie.last_access.millisecond
);
}
catch (Exception^ ex)
{
cookie->LastAccess = DateTime::MinValue;
}
}
return cookie;
}
}