You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-07-12 22:30:17 +02:00
Fixed backwards compatibility issue in uCEFWorkScheduler
Added more checks and comments in ResponseFilterBrowser in case the server doesn't send a Content-Length header
This commit is contained in:
@ -75,12 +75,12 @@ type
|
|||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormDestroy(Sender: TObject);
|
procedure FormDestroy(Sender: TObject);
|
||||||
protected
|
protected
|
||||||
FFilter : ICefResponseFilter;
|
FFilter : ICefResponseFilter; // CEF Filter interface that receives the resource contents
|
||||||
FStream : TMemoryStream;
|
FStream : TMemoryStream; // TMemoryStream to hold the resource contents
|
||||||
FStreamCS : TCriticalSection;
|
FStreamCS : TCriticalSection; // Critical section used to protect the memory stream
|
||||||
FRscName : string;
|
FRscName : string; // name of the resource that will be filtered
|
||||||
FRscSize : int64;
|
FRscSize : int64; // size of the resource if the server sends the Content-Length header
|
||||||
FRscCompleted : boolean;
|
FRscCompleted : boolean; // This variable will be used to handle the results only once.
|
||||||
|
|
||||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||||
@ -153,7 +153,9 @@ begin
|
|||||||
if (data_in_size > 0) then
|
if (data_in_size > 0) then
|
||||||
data_in_read := FStream.Write(data_in^, data_in_size);
|
data_in_read := FStream.Write(data_in^, data_in_size);
|
||||||
|
|
||||||
if not(FRscCompleted) and (FRscSize = FStream.Size) then
|
// Send the STREAM_COPY_COMPLETE message only if the server sent the data size in
|
||||||
|
// a Content-Length header and we can compare it with the stream size
|
||||||
|
if not(FRscCompleted) and (FRscSize <> -1) and (FRscSize = FStream.Size) then
|
||||||
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
|
|
||||||
aResult := RESPONSE_FILTER_NEED_MORE_DATA;
|
aResult := RESPONSE_FILTER_NEED_MORE_DATA;
|
||||||
@ -174,6 +176,7 @@ procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
FRscName := 'index-47f5f07682.js'; // JS script used at wikipedia.org
|
FRscName := 'index-47f5f07682.js'; // JS script used at wikipedia.org
|
||||||
FRscCompleted := False;
|
FRscCompleted := False;
|
||||||
|
FRscSize := -1;
|
||||||
FStream := TMemoryStream.Create;
|
FStream := TMemoryStream.Create;
|
||||||
FStreamCS := TCriticalSection.Create;
|
FStreamCS := TCriticalSection.Create;
|
||||||
FFilter := TCustomResponseFilter.Create;
|
FFilter := TCustomResponseFilter.Create;
|
||||||
@ -208,11 +211,19 @@ procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter(Sender :
|
|||||||
const request : ICefRequest;
|
const request : ICefRequest;
|
||||||
const response : ICefResponse;
|
const response : ICefResponse;
|
||||||
out Result : ICefResponseFilter);
|
out Result : ICefResponseFilter);
|
||||||
|
var
|
||||||
|
TempHeader : string;
|
||||||
|
TempLen : integer;
|
||||||
begin
|
begin
|
||||||
if (request <> nil) and (response <> nil) and (pos(FRscName, request.URL) > 0) then
|
if (request <> nil) and (response <> nil) and (pos(FRscName, request.URL) > 0) then
|
||||||
begin
|
begin
|
||||||
Result := FFilter;
|
Result := FFilter;
|
||||||
FRscSize := StrToIntDef(response.GetHeader('Content-Length'), 0);
|
TempHeader := trim(response.GetHeader('Content-Length'));
|
||||||
|
|
||||||
|
if TryStrToInt(TempHeader, TempLen) and (TempLen > 0) then
|
||||||
|
FRscSize := TempLen
|
||||||
|
else
|
||||||
|
FRscSize := -1;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
@ -225,20 +236,26 @@ begin
|
|||||||
GoBtn.Click;
|
GoBtn.Click;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// This procedure handles the stream contents after it's fully downloaded
|
||||||
procedure TResponseFilterBrowserFrm.StreamCopyCompleteMsg(var aMessage : TMessage);
|
procedure TResponseFilterBrowserFrm.StreamCopyCompleteMsg(var aMessage : TMessage);
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
FStreamCS.Acquire;
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
FStream.Seek(0, soBeginning);
|
if (FStream.Size > 0) then
|
||||||
|
begin
|
||||||
|
FStream.Seek(0, soBeginning);
|
||||||
|
|
||||||
Memo1.Lines.Clear;
|
Memo1.Lines.Clear;
|
||||||
Memo1.Lines.LoadFromStream(FStream);
|
Memo1.Lines.LoadFromStream(FStream);
|
||||||
|
|
||||||
FStream.Clear;
|
FStream.Clear;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
|
||||||
FRscSize := 0;
|
FRscSize := -1;
|
||||||
FRscCompleted := False;
|
FRscCompleted := False;
|
||||||
finally
|
finally
|
||||||
FStreamCS.Release;
|
FStreamCS.Release;
|
||||||
end;
|
end;
|
||||||
|
@ -161,7 +161,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
FThread.DefaultInterval := FDefaultInterval;
|
FThread.DefaultInterval := FDefaultInterval;
|
||||||
FThread.OnPulse := Thread_OnPulse;
|
FThread.OnPulse := Thread_OnPulse;
|
||||||
{$IFDEF DELPHI8_UP}
|
{$IFDEF DELPHI14_UP}
|
||||||
FThread.Start;
|
FThread.Start;
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
FThread.Resume;
|
FThread.Resume;
|
||||||
|
Reference in New Issue
Block a user