Skip to content

Commit 2c623ab

Browse files
committed
IUrlRequest - Minor formatting and xml doc improvements
- Formatting - Xml doc improvements - Rewrite test case to run continuation async Issue #2881
1 parent d66798b commit 2c623ab

File tree

8 files changed

+54
-52
lines changed

8 files changed

+54
-52
lines changed

CefSharp.Core/Internals/CefFrameWrapper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ IUrlRequest^ CefFrameWrapper::CreateUrlRequest(IRequest^ request, IUrlRequestCli
413413
{
414414
ThrowIfDisposed();
415415

416+
if (request == nullptr)
417+
{
418+
throw gcnew ArgumentNullException("request");
419+
}
420+
421+
if (client == nullptr)
422+
{
423+
throw gcnew ArgumentNullException("client");
424+
}
425+
416426
auto urlRequest = _frame->CreateURLRequest(
417427
(CefRequestWrapper^)request,
418428
new CefUrlRequestClientAdapter(client));

CefSharp.Core/Internals/CefUrlRequestClientAdapter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void CefUrlRequestClientAdapter::OnDownloadProgress(CefRefPtr<CefURLRequest> req
2727
void CefUrlRequestClientAdapter::OnDownloadData(CefRefPtr<CefURLRequest> request, const void* data, size_t data_length)
2828
{
2929
UnmanagedMemoryStream readStream((Byte*)data, (Int64)data_length, (Int64)data_length, FileAccess::Read);
30+
3031
_client->OnDownloadData(
3132
gcnew CefUrlRequestWrapper(request),
3233
%readStream

CefSharp.Core/Internals/CefUrlRequestClientAdapter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace CefSharp
1111
{
1212
namespace Internals
1313
{
14-
1514
/// Interface that should be implemented by the CefUrlRequest client.
1615
/// The methods of this class will be called on the same thread that created
1716
/// the request unless otherwise documented.

CefSharp.Core/Internals/CefUrlRequestWrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace CefSharp
2121
// be accessed on the same thread that created it.
2222
///
2323
/*--cef(source=library)--*/
24-
ref class CefUrlRequestWrapper : public IUrlRequest, public CefWrapper
24+
public ref class CefUrlRequestWrapper : public IUrlRequest, public CefWrapper
2525
{
2626
private:
2727
MCefRefPtr<CefURLRequest> _urlRequest;
@@ -51,7 +51,7 @@ namespace CefSharp
5151
{
5252
bool get();
5353
}
54-
54+
5555
///
5656
// Returns the response, or NULL if no response information is available.
5757
// Response information will only be available after the upload has completed.

CefSharp.Example/UrlRequestClient.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,39 @@
77

88
namespace CefSharp.Example
99
{
10-
1110
public class UrlRequestClient : IUrlRequestClient
1211
{
13-
private Action<IUrlRequest, byte[]> CompleteAction;
14-
private MemoryStream ResponseBody = new MemoryStream();
12+
private readonly Action<IUrlRequest, byte[]> completeAction;
13+
private readonly MemoryStream responseBody = new MemoryStream();
1514

1615
public UrlRequestClient(Action<IUrlRequest, byte[]> completeAction)
1716
{
18-
CompleteAction = completeAction;
17+
this.completeAction = completeAction;
1918
}
20-
public bool GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
19+
20+
bool IUrlRequestClient.GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
2121
{
2222
return true;
2323
}
2424

25-
public void OnDownloadData(IUrlRequest request, Stream data)
25+
void IUrlRequestClient.OnDownloadData(IUrlRequest request, Stream data)
2626
{
27-
data.CopyTo(ResponseBody);
27+
data.CopyTo(responseBody);
2828
}
2929

30-
public void OnDownloadProgress(IUrlRequest request, long current, long total)
30+
void IUrlRequestClient.OnDownloadProgress(IUrlRequest request, long current, long total)
3131
{
32-
return;
32+
3333
}
3434

35-
public void OnRequestComplete(IUrlRequest request)
35+
void IUrlRequestClient.OnRequestComplete(IUrlRequest request)
3636
{
37-
38-
CompleteAction(request, ResponseBody.ToArray());
37+
this?.completeAction(request, responseBody.ToArray());
3938
}
4039

41-
public void OnUploadProgress(IUrlRequest request, long current, long total)
40+
void IUrlRequestClient.OnUploadProgress(IUrlRequest request, long current, long total)
4241
{
43-
return;
42+
4443
}
4544
}
4645
}

CefSharp.Test/OffScreen/OffScreenBrowserBasicFacts.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
//
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

5-
using System;
6-
using System.IO;
7-
using System.Threading;
8-
using CefSharp.OffScreen;
5+
using System.Text;
96
using System.Threading.Tasks;
7+
using CefSharp.Example;
8+
using CefSharp.OffScreen;
109
using Xunit;
1110
using Xunit.Abstractions;
12-
using CefSharp.Example;
1311

1412
namespace CefSharp.Test.OffScreen
1513
{
@@ -142,18 +140,13 @@ public async Task CanMakeUrlRequest()
142140
var mainFrame = browser.GetMainFrame();
143141
Assert.True(mainFrame.IsValid);
144142

145-
146-
IUrlRequest urlRequest = null;
147-
148-
var t = new TaskCompletionSource<string>();
143+
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
149144
var wasCached = false;
150-
var requestClient = new UrlRequestClient(
151-
(IUrlRequest request, byte[] responseBody) =>
152-
{
153-
wasCached = request.ResponseWasCached;
154-
t.TrySetResult(System.Text.Encoding.UTF8.GetString(responseBody));
155-
}
156-
);
145+
var requestClient = new UrlRequestClient((IUrlRequest req, byte[] responseBody) =>
146+
{
147+
wasCached = req.ResponseWasCached;
148+
taskCompletionSource.TrySetResult(Encoding.UTF8.GetString(responseBody));
149+
});
157150

158151
//Make the request on the CEF UI Thread
159152
await Cef.UIThreadTaskFactory.StartNew(delegate
@@ -162,10 +155,10 @@ await Cef.UIThreadTaskFactory.StartNew(delegate
162155

163156
request.Method = "GET";
164157
request.Url = "https://code.jquery.com/jquery-3.4.1.min.js";
165-
urlRequest = mainFrame.CreateUrlRequest(request, requestClient);
158+
var urlRequest = mainFrame.CreateUrlRequest(request, requestClient);
166159
});
167160

168-
var stringResult = await t.Task;
161+
var stringResult = await taskCompletionSource.Task;
169162

170163
Assert.True(!string.IsNullOrEmpty(stringResult));
171164
Assert.True(wasCached);

CefSharp/IUrlRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IUrlRequest : IDisposable
1919
/// True if the response was served from the cache.
2020
/// </summary>
2121
bool ResponseWasCached { get; }
22-
22+
2323
/// <summary>
2424
/// The response, or null if no response information is available
2525
/// </summary>

CefSharp/IUrlRequestClient.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,51 @@ namespace CefSharp
1313
public interface IUrlRequestClient
1414
{
1515
/// <summary>
16-
/// Called on the IO thread when the browser needs credentials from the user.
16+
/// Called on the CEF IO thread when the browser needs credentials from the user.
1717
/// This method will only be called for requests initiated from the browser process.
1818
/// </summary>
1919
/// <param name="isProxy">indicates whether the host is a proxy server.</param>
2020
/// <param name="host">the hostname.</param>
2121
/// <param name="port">the port number.</param>
22-
/// <param name="realm"></param>
23-
/// <param name="scheme"></param>
22+
/// <param name="realm">realm</param>
23+
/// <param name="scheme">scheme</param>
2424
/// <param name="callback">is a callback for authentication information</param>
2525
/// <returns>
26-
/// Return true to continue the request and call IAuthCallback.Continue() when the authentication information is available.
27-
/// If the request has an associated browser/frame then returning false will result in a call to GetAuthCredentials
28-
/// on the IRequestHandler associated with that browser, if any.
26+
/// Return true to continue the request and call <see cref="IAuthCallback.Continue(string, string)"/> when the authentication information is available.
27+
/// If the request has an associated browser/frame then returning false will result in a call to <see cref="IRequestHandler.GetAuthCredentials"/>
28+
/// on the <see cref="IRequestHandler"/> associated with that browser, if any.
2929
/// Otherwise, returning false will cancel the request immediately.
3030
/// </returns>
31-
3231
bool GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback);
32+
3333
/// <summary>
34-
/// Called when some part of the response is read. This method will not be called if the UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request.
34+
/// Called when some part of the response is read. This method will not be called if the <see cref="UrlRequestFlags.NoDownloadData"/> flag is set on the request.
3535
/// </summary>
36-
/// <param name="request"></param>
37-
/// <param name="data">Contains the current bytes received since the last call.</param>
36+
/// <param name="request">request</param>
37+
/// <param name="data">A stream containing the bytes received since the last call. Cannot be used outside the scope of this method. </param>
3838
void OnDownloadData(IUrlRequest request, Stream data);
3939

4040
/// <summary>
4141
/// Notifies the client of download progress.
4242
/// </summary>
43-
/// <param name="request"></param>
43+
/// <param name="request">request</param>
4444
/// <param name="current">denotes the number of bytes received up to the call </param>
4545
/// <param name="total">is the expected total size of the response (or -1 if not determined).</param>
4646
void OnDownloadProgress(IUrlRequest request, long current, long total);
4747

4848
/// <summary>
49-
/// Notifies the client that the request has completed. Use the
50-
/// IURLRequest.GetRequestStatus method to determine if the request was
51-
/// successful or not.
49+
/// Notifies the client that the request has completed.
50+
/// Use the <see cref="IUrlRequest.RequestStatus"/> property to determine if the
51+
/// request was successful or not.
5252
/// </summary>
53-
/// <param name="request"></param>
53+
/// <param name="request">request</param>
5454
void OnRequestComplete(IUrlRequest request);
5555

5656
/// <summary>
5757
/// Notifies the client of upload progress.
5858
/// This method will only be called if the UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request.
5959
/// </summary>
60-
/// <param name="request"></param>
60+
/// <param name="request">request</param>
6161
/// <param name="current">denotes the number of bytes sent so far.</param>
6262
/// <param name="total">is the total size of uploading data (or -1 if chunked upload is enabled).</param>
6363
void OnUploadProgress(IUrlRequest request, long current, long total);

0 commit comments

Comments
 (0)