2017-12-18 19:38:56 +01:00
|
|
|
unit uCEFServer;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-12-18 19:38:56 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-12-18 19:38:56 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TCEFServerRef = class(TCefBaseRefCountedRef, ICefServer)
|
|
|
|
protected
|
|
|
|
function GetTaskRunner : ICefTaskRunner; virtual;
|
|
|
|
procedure Shutdown; virtual;
|
|
|
|
function IsRunning : boolean; virtual;
|
|
|
|
function GetAddress : ustring; virtual;
|
|
|
|
function HasConnection : boolean; virtual;
|
|
|
|
function IsValidConnection(connection_id: Integer) : boolean; virtual;
|
|
|
|
procedure SendHttp200response(connection_id: Integer; const content_type: ustring; const data: Pointer; data_size: NativeUInt); virtual;
|
|
|
|
procedure SendHttp404response(connection_id: Integer); virtual;
|
|
|
|
procedure SendHttp500response(connection_id: Integer; const error_message: ustring); virtual;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure SendHttpResponse(connection_id, response_code: Integer; const content_type: ustring; content_length: int64; const extra_headers: ICefStringMultimap); virtual;
|
2017-12-18 19:38:56 +01:00
|
|
|
procedure SendRawData(connection_id: Integer; const data: Pointer; data_size: NativeUInt); virtual;
|
|
|
|
procedure CloseConnection(connection_id: Integer); virtual;
|
|
|
|
procedure SendWebSocketMessage(connection_id: Integer; const data: Pointer; data_size: NativeUInt); virtual;
|
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefServer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFTaskRunner;
|
|
|
|
|
|
|
|
// ******************************************************
|
|
|
|
// ****************** TCEFServerRef *********************
|
|
|
|
// ******************************************************
|
|
|
|
|
|
|
|
class function TCEFServerRef.UnWrap(data: Pointer): ICefServer;
|
|
|
|
begin
|
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefServer
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFServerRef.GetTaskRunner : ICefTaskRunner;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TCefTaskRunnerRef.UnWrap(PCefServer(FData)^.get_task_runner(PCefServer(FData)));
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.Shutdown;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.shutdown(PCefServer(FData));
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFServerRef.IsRunning : boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefServer(FData)^.is_running(PCefServer(FData)) <> 0;
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFServerRef.GetAddress : ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefServer(FData)^.get_address(PCefServer(FData)));
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFServerRef.HasConnection : boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefServer(FData)^.has_connection(PCefServer(FData)) <> 0;
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFServerRef.IsValidConnection(connection_id: Integer) : boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefServer(FData)^.is_valid_connection(PCefServer(FData), connection_id) <> 0;
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.SendHttp200response(connection_id: Integer; const content_type: ustring; const data: Pointer; data_size: NativeUInt);
|
|
|
|
var
|
|
|
|
TempContentType : TCefString;
|
|
|
|
begin
|
|
|
|
TempContentType := CefString(content_type);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_http200response(PCefServer(FData), connection_id, @TempContentType, data, data_size);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.SendHttp404response(connection_id: Integer);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_http404response(PCefServer(FData), connection_id);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.SendHttp500response(connection_id: Integer; const error_message: ustring);
|
|
|
|
var
|
|
|
|
TempError : TCefString;
|
|
|
|
begin
|
|
|
|
TempError := CefString(error_message);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_http500response(PCefServer(FData), connection_id, @TempError);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCEFServerRef.SendHttpResponse(connection_id, response_code: Integer; const content_type: ustring; content_length: int64; const extra_headers: ICefStringMultimap);
|
2017-12-18 19:38:56 +01:00
|
|
|
var
|
|
|
|
TempContentType : TCefString;
|
|
|
|
begin
|
|
|
|
TempContentType := CefString(content_type);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_http_response(PCefServer(FData), connection_id, response_code, @TempContentType, content_length, extra_headers.Handle);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.SendRawData(connection_id: Integer; const data: Pointer; data_size: NativeUInt);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_raw_data(PCefServer(FData), connection_id, data, data_size);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.CloseConnection(connection_id: Integer);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.close_connection(PCefServer(FData), connection_id);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFServerRef.SendWebSocketMessage(connection_id: Integer; const data: Pointer; data_size: NativeUInt);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefServer(FData)^.send_web_socket_message(PCefServer(FData), connection_id, data, data_size);
|
2017-12-18 19:38:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|