mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-01-03 10:15:38 +02:00
The ResponseFilterBrowser demo now supports multiple data chunks
This commit is contained in:
parent
b365cce4cb
commit
51ffa49b7c
@ -48,7 +48,7 @@ uses
|
|||||||
Windows,
|
Windows,
|
||||||
{$ENDIF }
|
{$ENDIF }
|
||||||
uCEFApplication,
|
uCEFApplication,
|
||||||
uResopnseFilterBrowser in 'uResopnseFilterBrowser.pas' {ResponseFilterBrowserFrm};
|
uResponseFilterBrowser in 'uResponseFilterBrowser.pas' {ResponseFilterBrowserFrm};
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@
|
|||||||
<DelphiCompile Include="$(MainSource)">
|
<DelphiCompile Include="$(MainSource)">
|
||||||
<MainSource>MainSource</MainSource>
|
<MainSource>MainSource</MainSource>
|
||||||
</DelphiCompile>
|
</DelphiCompile>
|
||||||
<DCCReference Include="uResopnseFilterBrowser.pas">
|
<DCCReference Include="uResponseFilterBrowser.pas">
|
||||||
<Form>ResponseFilterBrowserFrm</Form>
|
<Form>ResponseFilterBrowserFrm</Form>
|
||||||
</DCCReference>
|
</DCCReference>
|
||||||
<BuildConfiguration Include="Release">
|
<BuildConfiguration Include="Release">
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
*
|
*
|
||||||
*)
|
*)
|
||||||
|
|
||||||
unit uResopnseFilterBrowser;
|
unit uResponseFilterBrowser;
|
||||||
|
|
||||||
{$I cef.inc}
|
{$I cef.inc}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ type
|
|||||||
FFilter : ICefResponseFilter;
|
FFilter : ICefResponseFilter;
|
||||||
FStream : TMemoryStream;
|
FStream : TMemoryStream;
|
||||||
FStreamCS : TCriticalSection;
|
FStreamCS : TCriticalSection;
|
||||||
FLoading : boolean;
|
FRscName : string;
|
||||||
|
|
||||||
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;
|
||||||
@ -105,7 +105,7 @@ uses
|
|||||||
{$ELSE}
|
{$ELSE}
|
||||||
Math,
|
Math,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFApplication;
|
uCEFApplication, uCEFMiscFunctions;
|
||||||
|
|
||||||
// This demo uses a TCustomResponseFilter to read the contents from a JavaScript file in wikipedia.org into a TMemoryStream.
|
// This demo uses a TCustomResponseFilter to read the contents from a JavaScript file in wikipedia.org into a TMemoryStream.
|
||||||
// The stream is shown in the TMemo when it's finished.
|
// The stream is shown in the TMemo when it's finished.
|
||||||
@ -123,29 +123,38 @@ procedure TResponseFilterBrowserFrm.Filter_OnFilter(Sender: TObject;
|
|||||||
var aResult : TCefResponseFilterStatus);
|
var aResult : TCefResponseFilterStatus);
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
// This event will be called repeatedly until the input buffer has been fully read.
|
try
|
||||||
FStreamCS.Acquire;
|
// This event will be called repeatedly until the input buffer has been fully read.
|
||||||
|
// When there's no more data then data_in is nil and you can show the stream contents.
|
||||||
|
|
||||||
aResult := RESPONSE_FILTER_DONE;
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
if (data_in = nil) then
|
if (data_in = nil) then
|
||||||
begin
|
begin
|
||||||
data_in_read := 0;
|
data_in_read := 0;
|
||||||
data_out_written := 0;
|
data_out_written := 0;
|
||||||
end
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
else
|
|
||||||
begin
|
|
||||||
data_in_read := data_in_size;
|
|
||||||
|
|
||||||
if (data_out <> nil) then
|
PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
begin
|
end
|
||||||
data_out_written := min(data_in_read, data_out_size);
|
else
|
||||||
Move(data_in^, data_out^, data_out_written);
|
begin
|
||||||
end;
|
if (data_out <> nil) then
|
||||||
|
begin
|
||||||
|
data_out_written := min(data_in_read, data_out_size);
|
||||||
|
Move(data_in^, data_out^, data_out_written);
|
||||||
|
end;
|
||||||
|
|
||||||
FStream.WriteBuffer(data_in^, data_in_size);
|
data_in_read := FStream.Write(data_in^, data_in_size);
|
||||||
PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
aResult := RESPONSE_FILTER_NEED_MORE_DATA;
|
||||||
end;
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
begin
|
||||||
|
aResult := RESPONSE_FILTER_ERROR;
|
||||||
|
if CustomExceptionHandler('TResponseFilterBrowserFrm.Filter_OnFilter', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
FStreamCS.Release;
|
FStreamCS.Release;
|
||||||
end;
|
end;
|
||||||
@ -153,7 +162,7 @@ end;
|
|||||||
|
|
||||||
procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject);
|
procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FLoading := False;
|
FRscName := 'index-47f5f07682.js'; // JS script used at wikipedia.org
|
||||||
FStream := TMemoryStream.Create;
|
FStream := TMemoryStream.Create;
|
||||||
FStreamCS := TCriticalSection.Create;
|
FStreamCS := TCriticalSection.Create;
|
||||||
FFilter := TCustomResponseFilter.Create;
|
FFilter := TCustomResponseFilter.Create;
|
||||||
@ -189,10 +198,7 @@ procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter(Sender :
|
|||||||
const response : ICefResponse;
|
const response : ICefResponse;
|
||||||
out Result : ICefResponseFilter);
|
out Result : ICefResponseFilter);
|
||||||
begin
|
begin
|
||||||
// All resources can be filtered but for this demo we will select a JS file in wikipedia.org called 'index-47f5f07682.js'
|
if (request <> nil) and (pos(FRscName, request.URL) > 0) then
|
||||||
if (request <> nil) and
|
|
||||||
(pos('index', request.URL) > 0) and // the file contains the word 'index'
|
|
||||||
(pos('.js', request.URL) > 0) then // the file contains the extension '.js'
|
|
||||||
Result := FFilter
|
Result := FFilter
|
||||||
else
|
else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
@ -220,7 +226,6 @@ end;
|
|||||||
|
|
||||||
procedure TResponseFilterBrowserFrm.GoBtnClick(Sender: TObject);
|
procedure TResponseFilterBrowserFrm.GoBtnClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FLoading := True;
|
|
||||||
Chromium1.LoadURL(AddressEdt.Text);
|
Chromium1.LoadURL(AddressEdt.Text);
|
||||||
end;
|
end;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user