Example #1
0
 private void ThrowIfMoreThan5MB(CefUrlRequest request, long total)
 {
     if (total > 5 * 1024 * 1024 && !IgnoreSize)
     {
         throw new OperationCanceledException("The file size more than 5 MB.");
     }
 }
Example #2
0
 protected override void OnRequestComplete(CefUrlRequest request)
 {
     logic.OnRequestComplete(request.RequestStatus switch {
         CefUrlRequestStatus.Success => Success,
         CefUrlRequestStatus.Failed => Failed,
         _ => Unknown
     });
Example #3
0
        /// <summary>
        /// Notifies that the request has completed.
        /// </summary>
        /// <param name="request">The associated <see cref="CefUrlRequest"/>.</param>
        /// <remarks>
        /// Use the <see cref="CefUrlRequest.RequestStatus"/> to determine
        /// if the request was successful or not.
        /// </remarks>
        protected internal override void OnRequestComplete(CefUrlRequest request)
        {
            if (_stream != null)
            {
                try
                {
                    _stream.Flush();
                    if (_stream.CanSeek)
                    {
                        _stream.Seek(0, SeekOrigin.Begin);
                    }
                }
                catch (IOException ioe)
                {
                    SetException(ioe);
                }
            }

            _request               = request.Request;
            _response              = request.Response;
            _requestStatus         = request.RequestStatus;
            this.RequestError      = request.RequestError;
            this.ResponseWasCached = request.ResponseWasCached();

            IsCompleted = true;
            RequestOperation op = Volatile.Read(ref _activeOperation);

            if (op is null || op.continuation is null)
            {
                return;
            }

            ThreadPool.QueueUserWorkItem(cont => ((Action)cont)(), op.continuation);
        }
Example #4
0
 protected override void OnDownloadProgress(CefUrlRequest request, long current, long total)
 {
     try
     {
         ThrowIfMoreThan5MB(request, total);
         base.OnDownloadProgress(request, current, total);
     }
     catch (Exception e)
     {
         SetException(e);
         request.Cancel();
     }
 }
Example #5
0
 protected override void OnDownloadData(CefUrlRequest request, IntPtr data, long dataLength)
 {
     _total += dataLength;
     try
     {
         ThrowIfMoreThan5MB(request, _total);
         base.OnDownloadData(request, data, dataLength);
     }
     catch (Exception e)
     {
         SetException(e);
         request.Cancel();
     }
 }
Example #6
0
 /// <summary>
 /// Notifies about a download progress.
 /// </summary>
 /// <param name="request">The associated <see cref="CefUrlRequest"/>.</param>
 /// <param name="current">The number of bytes received up to the call.</param>
 /// <param name="total">The expected total size of the response (or -1 if not determined).</param>
 protected internal override void OnDownloadProgress(CefUrlRequest request, long current, long total)
 {
     try
     {
         if (_stream is MemoryStream mem && mem.Capacity < total)
         {
             mem.Capacity = (int)total;
         }
     }
     catch (Exception e)
     {
         SetException(e);
         request.Cancel();
     }
 }
Example #7
0
        /// <summary>
        /// Called when some part of the response is read. This function will not be called if the
        /// <see cref="CefUrlRequestFlags.NoDownloadData"/> flag is set on the request.
        /// </summary>
        /// <param name="request">The associated <see cref="CefUrlRequest"/>.</param>
        /// <param name="data">The pointer to the buffer that contains the current bytes received since the last call.</param>
        /// <param name="dataLength">The size of the data buffer in bytes.</param>
        protected internal override void OnDownloadData(CefUrlRequest request, IntPtr data, long dataLength)
        {
            try
            {
                if (_stream is null)
                {
                    _stream = CreateResourceStream((int)dataLength);
                    if (_stream is null)
                    {
                        request.Cancel();
                        return;
                    }
                }

                if (_stream is MemoryStream mem)
                {
                    long startPos = _stream.Position;
                    long endPos   = startPos + dataLength;
                    if (endPos < mem.Capacity)
                    {
                        Marshal.Copy(data, mem.GetBuffer(), (int)startPos, (int)dataLength);
                        mem.SetLength(endPos);
                        mem.Position = endPos;
                        return;
                    }
                }

                var buffer = new byte[dataLength];
                Marshal.Copy(data, buffer, 0, buffer.Length);
                _stream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception e)
            {
                SetException(e);
                request.Cancel();
            }
        }
Example #8
0
 public override void OnDownloadData(CefUrlRequest request, IntPtr data, long dataLength)
 {
     _implementation.OnDownloadData(request, data, dataLength);
 }
Example #9
0
 public override void OnDownloadProgress(CefUrlRequest request, long current, long total)
 {
     _implementation.OnDownloadProgress(request, current, total);
 }
Example #10
0
 public override void OnRequestComplete(CefUrlRequest request)
 {
     _implementation.OnRequestComplete(request);
 }
Example #11
0
 protected internal unsafe override void OnDownloadData(CefUrlRequest request, IntPtr data, long dataLength)
 {
     _implementation.OnDownloadData(request, data, dataLength);
 }
Example #12
0
 protected internal unsafe override void OnDownloadProgress(CefUrlRequest request, long current, long total)
 {
     _implementation.OnDownloadProgress(request, current, total);
 }
Example #13
0
 protected internal unsafe override void OnRequestComplete(CefUrlRequest request)
 {
     _implementation.OnRequestComplete(request);
 }
Example #14
0
 protected override void OnDownloadData(CefUrlRequest request, Stream data)
 {
     logic.OnDownloadData(data);
 }