You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-11-23 21:34:53 +02:00
Added ConsoleBrowser2 and WebpageSnapshot demos
- Split the Lazarus demos directory into "Lazarus_Windows" and "Lazarus_Linux". - Added OSRExternalPumpBrowser and TinyBrowser2 demos to "Lazarus_Linux". - Set TBufferPanel.GetScreenScale as virtual. - Added DevTools to the SchemeRegistrationBrowser demo. - Modified the SchemeRegistrationBrowser demo to receive XMLHttpRequest requests from JavaScript.
This commit is contained in:
@@ -69,6 +69,9 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
uCEFConstants;
|
||||
|
||||
constructor THelloScheme.Create(const browser : ICefBrowser;
|
||||
const frame : ICefFrame;
|
||||
const schemeName : ustring;
|
||||
@@ -115,15 +118,17 @@ end;
|
||||
|
||||
function THelloScheme.ProcessRequest(const request : ICefRequest; const callback : ICefCallback): Boolean;
|
||||
var
|
||||
TempFilename, TempExt : string;
|
||||
TempFilename, TempExt, TempMessageTxt : string;
|
||||
TempParts : TUrlParts;
|
||||
TempFile : TFileStream;
|
||||
TempResp : TStringStream;
|
||||
begin
|
||||
Result := False;
|
||||
FStatus := 404;
|
||||
FStatusText := 'ERROR';
|
||||
FMimeType := '';
|
||||
TempFile := nil;
|
||||
TempResp := nil;
|
||||
|
||||
try
|
||||
try
|
||||
@@ -132,54 +137,51 @@ begin
|
||||
TempFilename := '';
|
||||
FStream.Clear;
|
||||
|
||||
if CefParseUrl(Request.URL, TempParts) then
|
||||
if CefParseUrl(Request.URL, TempParts) and
|
||||
(length(TempParts.path) > 0) and
|
||||
(TempParts.path <> '/') then
|
||||
begin
|
||||
if (length(TempParts.path) > 0) and
|
||||
(TempParts.path <> '/') then
|
||||
begin
|
||||
TempFilename := TempParts.path;
|
||||
TempFilename := TempParts.path;
|
||||
|
||||
if (length(TempFilename) > 0) and (TempFilename[1] = '/') then
|
||||
TempFilename := copy(TempFilename, 2, length(TempFilename));
|
||||
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;
|
||||
if (length(TempFilename) > 0) and (TempFilename[length(TempFilename)] = '/') then
|
||||
TempFilename := copy(TempFilename, 1, length(TempFilename) - 1);
|
||||
end;
|
||||
|
||||
if (length(TempFilename) > 0) then
|
||||
begin
|
||||
TempExt := ExtractFileExt(TempFilename);
|
||||
if (CompareText(TempFilename, 'customrequest') = 0) then
|
||||
begin
|
||||
Result := True;
|
||||
FStatus := 200;
|
||||
FStatusText := 'OK';
|
||||
|
||||
if (length(TempExt) > 0) and (TempExt[1] = '.') then
|
||||
TempExt := copy(TempExt, 2, length(TempExt));
|
||||
// This could be any information that your application needs to send to JS.
|
||||
TempMessageTxt := 'This is the response from Delphi!' + CRLF + CRLF +
|
||||
'Request query : ' + TempParts.query;
|
||||
|
||||
Result := True;
|
||||
FStatus := 200;
|
||||
FStatusText := 'OK';
|
||||
FMimeType := CefGetMimeType(TempExt);
|
||||
TempFile := TFileStream.Create(TempFilename, fmOpenRead);
|
||||
TempFile.Seek(0, soFromBeginning);
|
||||
FStream.LoadFromStream(TStream(TempFile));
|
||||
TempResp := TStringStream.Create(TempMessageTxt);
|
||||
TempResp.Seek(0, soFromBeginning);
|
||||
FStream.LoadFromStream(TStream(TempResp));
|
||||
end
|
||||
else
|
||||
if FileExists(TempFilename) then
|
||||
begin
|
||||
TempExt := ExtractFileExt(TempFilename);
|
||||
|
||||
if (length(TempExt) > 0) and (TempExt[1] = '.') then
|
||||
TempExt := copy(TempExt, 2, length(TempExt));
|
||||
|
||||
FMimeType := CefGetMimeType(TempExt);
|
||||
Result := True;
|
||||
FStatus := 200;
|
||||
FStatusText := 'OK';
|
||||
TempFile := TFileStream.Create(TempFilename, fmOpenRead);
|
||||
TempFile.Seek(0, soFromBeginning);
|
||||
FStream.LoadFromStream(TStream(TempFile));
|
||||
end;
|
||||
end;
|
||||
|
||||
FStream.Seek(0, soFromBeginning);
|
||||
@@ -191,6 +193,7 @@ begin
|
||||
finally
|
||||
if (callback <> nil) then callback.Cont;
|
||||
if (TempFile <> nil) then FreeAndNil(TempFile);
|
||||
if (TempResp <> nil) then FreeAndNil(TempResp);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@@ -51,10 +51,10 @@ object SchemeRegistrationBrowserFrm: TSchemeRegistrationBrowserFrm
|
||||
Align = alClient
|
||||
ItemIndex = 1
|
||||
TabOrder = 1
|
||||
Text = 'hello://test.html'
|
||||
Text = 'hello://localhost/test.html'
|
||||
Items.Strings = (
|
||||
'https://www.google.com'
|
||||
'hello://test.html'
|
||||
'hello://localhost/test.html'
|
||||
'file://test.html')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,6 +56,7 @@ uses
|
||||
const
|
||||
MINIBROWSER_CONTEXTMENU_REGSCHEME = MENU_ID_USER_FIRST + 1;
|
||||
MINIBROWSER_CONTEXTMENU_CLEARFACT = MENU_ID_USER_FIRST + 2;
|
||||
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 3;
|
||||
|
||||
CUSTOM_SCHEME_NAME = 'hello';
|
||||
|
||||
@@ -148,6 +149,7 @@ procedure CreateGlobalCEFApp;
|
||||
begin
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp.OnRegCustomSchemes := GlobalCEFApp_OnRegCustomSchemes;
|
||||
GlobalCEFApp.DisableWebSecurity := True;
|
||||
|
||||
// GlobalCEFApp.LogFile := 'debug.log';
|
||||
// GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
|
||||
@@ -171,6 +173,7 @@ procedure TSchemeRegistrationBrowserFrm.Chromium1BeforeContextMenu(
|
||||
begin
|
||||
model.AddItem(MINIBROWSER_CONTEXTMENU_REGSCHEME, 'Register scheme');
|
||||
model.AddItem(MINIBROWSER_CONTEXTMENU_CLEARFACT, 'Clear schemes');
|
||||
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, 'Show DevTools');
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.Chromium1BeforePopup(
|
||||
@@ -198,6 +201,7 @@ procedure TSchemeRegistrationBrowserFrm.Chromium1ContextMenuCommand(
|
||||
const params: ICefContextMenuParams; commandId: Integer;
|
||||
eventFlags: Cardinal; out Result: Boolean);
|
||||
var
|
||||
TempPoint : TPoint;
|
||||
TempFactory: ICefSchemeHandlerFactory;
|
||||
begin
|
||||
Result := False;
|
||||
@@ -222,6 +226,13 @@ begin
|
||||
if not(browser.host.RequestContext.ClearSchemeHandlerFactories) then
|
||||
MessageDlg('ClearSchemeHandlerFactories error !', mtError, [mbOk], 0);
|
||||
end;
|
||||
|
||||
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS :
|
||||
begin
|
||||
TempPoint.x := params.XCoord;
|
||||
TempPoint.y := params.YCoord;
|
||||
Chromium1.ShowDevTools(TempPoint, nil);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -245,6 +256,7 @@ end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.FormShow(Sender: TObject);
|
||||
begin
|
||||
Chromium1.DefaultURL := AddressCbx.Text;
|
||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||
// If it's not initialized yet, we use a simple timer to create the browser later.
|
||||
if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) then Timer1.Enabled := True;
|
||||
@@ -266,7 +278,6 @@ procedure TSchemeRegistrationBrowserFrm.BrowserCreatedMsg(var aMessage : TMessag
|
||||
begin
|
||||
CEFWindowParent1.UpdateSize;
|
||||
AddressBarPnl.Enabled := True;
|
||||
GoBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TSchemeRegistrationBrowserFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||
|
||||
Reference in New Issue
Block a user