-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CefResourceHandlerAdapter.cpp
83 lines (63 loc) · 3.08 KB
/
CefResourceHandlerAdapter.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
// Copyright © 2010 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 "Request.h"
#include "CefResourceHandlerAdapter.h"
#include "Internals/CefResponseWrapper.h"
#include "Internals/CefCallbackWrapper.h"
#include "Internals/CefResourceReadCallbackWrapper.h"
#include "Internals/CefResourceSkipCallbackWrapper.h"
#include "Internals/TypeConversion.h"
using namespace System::Runtime::InteropServices;
using namespace System::IO;
using namespace CefSharp::Core;
namespace CefSharp
{
namespace Internals
{
bool CefResourceHandlerAdapter::Open(CefRefPtr<CefRequest> request, bool& handleRequest, CefRefPtr<CefCallback> callback)
{
auto callbackWrapper = gcnew CefCallbackWrapper(callback);
_request = gcnew Request(request);
return _handler->Open(_request, handleRequest, callbackWrapper);
}
void CefResourceHandlerAdapter::GetResponseHeaders(CefRefPtr<CefResponse> response, int64_t& response_length, CefString& redirectUrl)
{
String^ newRedirectUrl;
CefResponseWrapper responseWrapper(response);
_handler->GetResponseHeaders(% responseWrapper, response_length, newRedirectUrl);
redirectUrl = StringUtils::ToNative(newRedirectUrl);
}
bool CefResourceHandlerAdapter::Skip(int64_t bytesToSkip, int64_t& bytesSkipped, CefRefPtr<CefResourceSkipCallback> callback)
{
auto callbackWrapper = gcnew CefResourceSkipCallbackWrapper(callback);
return _handler->Skip(bytesToSkip, bytesSkipped, callbackWrapper);
}
bool CefResourceHandlerAdapter::Read(void* dataOut, int bytesToRead, int& bytesRead, CefRefPtr<CefResourceReadCallback> callback)
{
auto writeStream = gcnew UnmanagedMemoryStream((Byte*)dataOut, (Int64)bytesToRead, (Int64)bytesToRead, FileAccess::Write);
auto callbackWrapper = gcnew CefResourceReadCallbackWrapper(callback);
return _handler->Read(writeStream, bytesRead, callbackWrapper);
}
void CefResourceHandlerAdapter::Cancel()
{
_handler->Cancel();
delete _request;
_request = nullptr;
}
//Deprecated
bool CefResourceHandlerAdapter::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
auto callbackWrapper = gcnew CefCallbackWrapper(callback);
_request = gcnew Request(request);
return _handler->ProcessRequest(_request, callbackWrapper);
}
bool CefResourceHandlerAdapter::ReadResponse(void* dataOut, int bytesToRead, int& bytesRead, CefRefPtr<CefCallback> callback)
{
auto writeStream = gcnew UnmanagedMemoryStream((Byte*)dataOut, (Int64)bytesToRead, (Int64)bytesToRead, FileAccess::Write);
auto callbackWrapper = gcnew CefCallbackWrapper(callback);
return _handler->ReadResponse(writeStream, bytesRead, callbackWrapper);
}
}
}