|
| 1 | +// Copyright © 2019 The CefSharp Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +#pragma once |
| 6 | + |
| 7 | +#include "Stdafx.h" |
| 8 | +#include "Include\cef_urlrequest.h" |
| 9 | + |
| 10 | +namespace CefSharp |
| 11 | +{ |
| 12 | + namespace Internals |
| 13 | + { |
| 14 | + |
| 15 | + /// Interface that should be implemented by the CefUrlRequest client. |
| 16 | + /// The methods of this class will be called on the same thread that created |
| 17 | + /// the request unless otherwise documented. |
| 18 | + public class CefUrlRequestClientAdapter : public CefURLRequestClient |
| 19 | + { |
| 20 | + private: |
| 21 | + gcroot<IUrlRequestClient^> _client; |
| 22 | + |
| 23 | + public: |
| 24 | + CefUrlRequestClientAdapter(IUrlRequestClient^ client) |
| 25 | + { |
| 26 | + _client = client; |
| 27 | + } |
| 28 | + |
| 29 | + ~CefUrlRequestClientAdapter() |
| 30 | + { |
| 31 | + delete _client; |
| 32 | + _client = nullptr; |
| 33 | + } |
| 34 | + |
| 35 | + // Notifies the client that the request has completed. Use the |
| 36 | + // CefURLRequest::GetRequestStatus method to determine if the request was |
| 37 | + // successful or not. |
| 38 | + /// |
| 39 | + /*--cef()--*/ |
| 40 | + virtual void OnRequestComplete(CefRefPtr<CefURLRequest> request) OVERRIDE; |
| 41 | + |
| 42 | + /// |
| 43 | + // Notifies the client of upload progress. |current| denotes the number of |
| 44 | + // bytes sent so far and |total| is the total size of uploading data (or -1 if |
| 45 | + // chunked upload is enabled). This method will only be called if the |
| 46 | + // UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request. |
| 47 | + /// |
| 48 | + /*--cef()--*/ |
| 49 | + virtual void OnUploadProgress(CefRefPtr<CefURLRequest> request, |
| 50 | + int64 current, |
| 51 | + int64 total) OVERRIDE; |
| 52 | + |
| 53 | + ///ref |
| 54 | + // Notifies the client of download progress. |current| denotes the number of |
| 55 | + // bytes received up to the call and |total| is the expected total size of the |
| 56 | + // response (or -1 if not determined). |
| 57 | + /// |
| 58 | + /*--cef()--*/ |
| 59 | + virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request, |
| 60 | + int64 current, |
| 61 | + int64 total) OVERRIDE; |
| 62 | + |
| 63 | + /// |
| 64 | + // Called when some part of the response is read. |data| contains the current |
| 65 | + // bytes received since the last call. This method will not be called if the |
| 66 | + // UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request. |
| 67 | + /// |
| 68 | + /*--cef()--*/ |
| 69 | + virtual void OnDownloadData(CefRefPtr<CefURLRequest> request, |
| 70 | + const void* data, |
| 71 | + size_t data_length) OVERRIDE; |
| 72 | + |
| 73 | + /// |
| 74 | + // Called on the IO thread when the browser needs credentials from the user. |
| 75 | + // |isProxy| indicates whether the host is a proxy server. |host| contains the |
| 76 | + // hostname and |port| contains the port number. Return true to continue the |
| 77 | + // request and call CefAuthCallback::Continue() when the authentication |
| 78 | + // information is available. If the request has an associated browser/frame |
| 79 | + // then returning false will result in a call to GetAuthCredentials on the |
| 80 | + // CefRequestHandler associated with that browser, if any. Otherwise, |
| 81 | + // returning false will cancel the request immediately. This method will only |
| 82 | + // be called for requests initiated from the browser process. |
| 83 | + /// |
| 84 | + /*--cef(optional_param=realm)--*/ |
| 85 | + virtual bool GetAuthCredentials(bool isProxy, |
| 86 | + const CefString& host, |
| 87 | + int port, |
| 88 | + const CefString& realm, |
| 89 | + const CefString& scheme, |
| 90 | + CefRefPtr<CefAuthCallback> callback) OVERRIDE; |
| 91 | + |
| 92 | + IMPLEMENT_REFCOUNTING(CefUrlRequestClientAdapter); |
| 93 | + }; |
| 94 | + } |
| 95 | +} |
0 commit comments