1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

SchemeRegistrationBrowser demo now can load local files

This commit is contained in:
Salvador Díaz Fau 2018-01-21 09:48:43 +01:00
parent 374b48e45b
commit 330fd18397
5 changed files with 93 additions and 19 deletions

BIN
bin/emoji.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
bin/helloworld.swf Normal file

Binary file not shown.

17
bin/test.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<body>
<p> <img src='emoji.png'><br>Local image</p>
<p> <img src='dontexist.png'><br>Non existing local image</p>
<p><img src='http://www.briskbard.com/images/logo2.png'><br>Remote image</p>
<p><object width="150" height="150" data="helloworld.swf"></object><br>
Local SWF file.<br>
You need to install the Adobe Flash PPAPI plugin to view the SWF file.</p>
</body>
</html>

View File

@ -46,7 +46,7 @@ uses
{$ELSE}
Classes, Windows, SysUtils,
{$ENDIF}
uCEFInterfaces, uCEFTypes, uCEFResourceHandler;
uCEFInterfaces, uCEFTypes, uCEFResourceHandler, uCEFMiscFunctions;
type
THelloScheme = class(TCefResourceHandlerOwn)
@ -115,28 +115,85 @@ end;
function THelloScheme.ProcessRequest(const request : ICefRequest; const callback : ICefCallback): Boolean;
var
TempString : string;
TempContents, TempFilename, TempExt : string;
TempUTF8String : AnsiString;
TempPointer : pointer;
TempParts : TUrlParts;
TempFile : TFileStream;
begin
Result := True;
FStatus := 200;
FStatusText := 'OK';
FMimeType := 'text/html';
Result := False;
FStatus := 404;
FStatusText := 'ERROR';
FMimeType := '';
TempFile := nil;
if (FStream <> nil) and (request <> nil) then
begin
TempString := '<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"/></head>' +
'<body>Hello world!<br>' + request.URL + '</body></html>';
TempUTF8String := UTF8Encode(TempString);
TempPointer := @TempUTF8String[1];
try
try
if (FStream <> nil) and (request <> nil) then
begin
TempFilename := '';
FStream.Clear;
FStream.Clear;
FStream.Write(TempPointer, length(TempUTF8String));
FStream.Seek(0, soFromBeginning);
if CefParseUrl(Request.URL, TempParts) then
begin
if (length(TempParts.path) > 0) and
(TempParts.path <> '/') then
begin
TempFilename := TempParts.path;
if (length(TempFilename) > 0) and (TempFilename[1] = '/') then
TempFilename := copy(TempFilename, 2, length(TempFilename));
if (length(TempFilename) > 0) and (TempFilename[length(TempFilename)] = '/') then
TempFilename := copy(TempFilename, 1, length(TempFilename) - 1);
if (length(TempFilename) > 0) and not(FileExists(TempFilename)) then
TempFilename := '';
end;
if (length(TempFilename) = 0) and
(length(TempParts.host) > 0) and
(TempParts.host <> '/') then
begin
TempFilename := TempParts.host;
if (length(TempFilename) > 0) and (TempFilename[1] = '/') then
TempFilename := copy(TempFilename, 2, length(TempFilename));
if (length(TempFilename) > 0) and (TempFilename[length(TempFilename)] = '/') then
TempFilename := copy(TempFilename, 1, length(TempFilename) - 1);
if (length(TempFilename) > 0) and not(FileExists(TempFilename)) then
TempFilename := '';
end;
end;
if (length(TempFilename) > 0) then
begin
TempExt := ExtractFileExt(TempFilename);
if (length(TempExt) > 0) and (TempExt[1] = '.') then
TempExt := copy(TempExt, 2, length(TempExt));
Result := True;
FStatus := 200;
FStatusText := 'OK';
FMimeType := CefGetMimeType(TempExt);
TempFile := TFileStream.Create(TempFilename, fmOpenRead);
TempFile.Seek(0, soFromBeginning);
FStream.LoadFromStream(TStream(TempFile));
end;
FStream.Seek(0, soFromBeginning);
end;
except
on e : exception do
if CustomExceptionHandler('THelloScheme.ProcessRequest', e) then raise;
end;
if (callback <> nil) then callback.Cont;
finally
if (callback <> nil) then callback.Cont;
if (TempFile <> nil) then FreeAndNil(TempFile);
end;
end;
function THelloScheme.ReadResponse(const dataOut : Pointer;

View File

@ -51,10 +51,10 @@ object SchemeRegistrationBrowserFrm: TSchemeRegistrationBrowserFrm
Align = alClient
ItemIndex = 1
TabOrder = 1
Text = 'hello://world'
Text = 'hello://test.html'
Items.Strings = (
'https://www.google.com'
'hello://world')
'hello://test.html')
end
end
object CEFWindowParent1: TCEFWindowParent