2017-01-27 18:29:37 +02:00
|
|
|
unit uCEFCommandLine;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 21:56:46 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 19:56:41 +02:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 18:29:37 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-02-05 21:56:46 +02:00
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-02-26 19:40:51 +02:00
|
|
|
System.Classes, System.SysUtils,
|
2017-02-05 21:56:46 +02:00
|
|
|
{$ELSE}
|
2018-02-26 19:40:51 +02:00
|
|
|
Classes, SysUtils,
|
2017-02-05 21:56:46 +02:00
|
|
|
{$ENDIF}
|
2017-03-16 20:09:42 +02:00
|
|
|
uCEFBaseRefCounted, uCEFTypes, uCEFInterfaces;
|
2017-01-27 18:29:37 +02:00
|
|
|
|
|
|
|
type
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefCommandLineRef = class(TCefBaseRefCountedRef, ICefCommandLine)
|
2017-01-27 18:29:37 +02:00
|
|
|
protected
|
|
|
|
function IsValid: Boolean;
|
|
|
|
function IsReadOnly: Boolean;
|
|
|
|
function Copy: ICefCommandLine;
|
|
|
|
procedure InitFromArgv(argc: Integer; const argv: PPAnsiChar);
|
|
|
|
procedure InitFromString(const commandLine: ustring);
|
|
|
|
procedure Reset;
|
|
|
|
function GetCommandLineString: ustring;
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure GetArgv(var args: TStrings);
|
2017-01-27 18:29:37 +02:00
|
|
|
function GetProgram: ustring;
|
|
|
|
procedure SetProgram(const prog: ustring);
|
|
|
|
function HasSwitches: Boolean;
|
|
|
|
function HasSwitch(const name: ustring): Boolean;
|
|
|
|
function GetSwitchValue(const name: ustring): ustring;
|
2020-07-30 10:45:12 +02:00
|
|
|
function GetSwitches(var switches: TStrings): boolean; overload;
|
|
|
|
function GetSwitches(var SwitchKeys, SwitchValues: TStringList): boolean; overload;
|
2017-01-27 18:29:37 +02:00
|
|
|
procedure AppendSwitch(const name: ustring);
|
|
|
|
procedure AppendSwitchWithValue(const name, value: ustring);
|
|
|
|
function HasArguments: Boolean;
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure GetArguments(var arguments: TStrings);
|
2017-01-27 18:29:37 +02:00
|
|
|
procedure AppendArgument(const argument: ustring);
|
|
|
|
procedure PrependWrapper(const wrapper: ustring);
|
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefCommandLine;
|
|
|
|
class function New: ICefCommandLine;
|
|
|
|
class function Global: ICefCommandLine;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-03-29 20:02:04 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFStringMap, uCefStringList;
|
2017-01-27 18:29:37 +02:00
|
|
|
|
|
|
|
procedure TCefCommandLineRef.AppendArgument(const argument: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempArgument : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempArgument := CefString(argument);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.append_argument(PCefCommandLine(FData), @TempArgument);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.AppendSwitch(const name: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName := CefString(name);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.append_switch(PCefCommandLine(FData), @TempName);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.AppendSwitchWithValue(const name, value: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName, TempValue : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName := CefString(name);
|
|
|
|
TempValue := CefString(value);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.append_switch_with_value(PCefCommandLine(FData), @TempName, @TempValue);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.Copy: ICefCommandLine;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := UnWrap(PCefCommandLine(FData)^.copy(PCefCommandLine(FData)));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure TCefCommandLineRef.GetArguments(var arguments : TStrings);
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL : ICefStringList;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
if (arguments <> nil) then
|
|
|
|
begin
|
|
|
|
TempSL := TCefStringListOwn.Create;
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.get_arguments(PCefCommandLine(FData), TempSL.Handle);
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL.CopyToStrings(arguments);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure TCefCommandLineRef.GetArgv(var args: TStrings);
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL : ICefStringList;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
if (args <> nil) then
|
|
|
|
begin
|
|
|
|
TempSL := TCefStringListOwn.Create;
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.get_argv(PCefCommandLine(FData), TempSL.Handle);
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL.CopyToStrings(args);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.GetCommandLineString: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefCommandLine(FData)^.get_command_line_string(PCefCommandLine(FData)));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.GetProgram: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefCommandLine(FData)^.get_program(PCefCommandLine(FData)));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2020-07-30 10:45:12 +02:00
|
|
|
function TCefCommandLineRef.GetSwitches(var switches: TStrings): boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempStrMap : ICefStringMap;
|
2018-02-26 19:40:51 +02:00
|
|
|
i, j : NativeUInt;
|
2018-05-12 14:50:54 +02:00
|
|
|
TempKey, TempValue : ustring;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2020-07-30 10:45:12 +02:00
|
|
|
Result := False;
|
2018-03-29 20:02:04 +02:00
|
|
|
TempStrMap := nil;
|
2018-02-26 19:40:51 +02:00
|
|
|
|
2017-01-27 18:29:37 +02:00
|
|
|
try
|
2018-02-26 19:40:51 +02:00
|
|
|
try
|
|
|
|
if (switches <> nil) then
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempStrMap := TCefStringMapOwn.Create;
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.get_switches(PCefCommandLine(FData), TempStrMap.Handle);
|
2018-02-26 19:40:51 +02:00
|
|
|
|
|
|
|
i := 0;
|
2018-03-29 20:02:04 +02:00
|
|
|
j := TempStrMap.Size;
|
2018-02-26 19:40:51 +02:00
|
|
|
|
|
|
|
while (i < j) do
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempKey := TempStrMap.Key[i];
|
|
|
|
TempValue := TempStrMap.Value[i];
|
|
|
|
|
|
|
|
if (length(TempKey) > 0) and (length(TempValue) > 0) then
|
|
|
|
switches.Add(TempKey + switches.NameValueSeparator + TempValue)
|
|
|
|
else
|
|
|
|
if (length(TempKey) > 0) then
|
|
|
|
switches.Add(TempKey)
|
|
|
|
else
|
|
|
|
if (length(TempValue) > 0) then
|
|
|
|
switches.Add(TempValue);
|
|
|
|
|
2018-02-26 19:40:51 +02:00
|
|
|
inc(i);
|
|
|
|
end;
|
2020-07-30 10:45:12 +02:00
|
|
|
|
|
|
|
Result := (j > 0);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCefCommandLineRef.GetSwitches', e) then raise;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
TempStrMap := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.GetSwitches(var SwitchKeys, SwitchValues: TStringList): boolean;
|
|
|
|
var
|
|
|
|
TempStrMap : ICefStringMap;
|
|
|
|
i, j : NativeUInt;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
TempStrMap := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
if (SwitchKeys <> nil) and (SwitchValues <> nil) then
|
|
|
|
begin
|
|
|
|
TempStrMap := TCefStringMapOwn.Create;
|
|
|
|
PCefCommandLine(FData)^.get_switches(PCefCommandLine(FData), TempStrMap.Handle);
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
j := TempStrMap.Size;
|
|
|
|
|
|
|
|
while (i < j) do
|
|
|
|
begin
|
|
|
|
SwitchKeys.Add(TempStrMap.Key[i]);
|
|
|
|
SwitchValues.Add(TempStrMap.Value[i]);
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := (j > 0);
|
2018-02-26 19:40:51 +02:00
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCefCommandLineRef.GetSwitches', e) then raise;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
finally
|
2018-03-29 20:02:04 +02:00
|
|
|
TempStrMap := nil;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.GetSwitchValue(const name: ustring): ustring;
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName := CefString(name);
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefCommandLine(FData)^.get_switch_value(PCefCommandLine(FData), @TempName));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefCommandLineRef.Global: ICefCommandLine;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := UnWrap(cef_command_line_get_global());
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.HasArguments: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefCommandLine(FData)^.has_arguments(PCefCommandLine(FData)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.HasSwitch(const name: ustring): Boolean;
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempName := CefString(name);
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefCommandLine(FData)^.has_switch(PCefCommandLine(FData), @TempName) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.HasSwitches: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefCommandLine(FData)^.has_switches(PCefCommandLine(FData)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefCommandLineRef.InitFromArgv(argc: Integer; const argv: PPAnsiChar);
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.init_from_argv(PCefCommandLine(FData), argc, argv);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.InitFromString(const commandLine: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempCommandLine : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempCommandLine := CefString(commandLine);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.init_from_string(PCefCommandLine(FData), @TempCommandLine);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.IsReadOnly: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefCommandLine(FData)^.is_read_only(PCefCommandLine(FData)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCommandLineRef.IsValid: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefCommandLine(FData)^.is_valid(PCefCommandLine(FData)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefCommandLineRef.New: ICefCommandLine;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := UnWrap(cef_command_line_create());
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.PrependWrapper(const wrapper: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempWrapper : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempWrapper := CefString(wrapper);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.prepend_wrapper(PCefCommandLine(FData), @TempWrapper);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.Reset;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.reset(PCefCommandLine(FData));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCommandLineRef.SetProgram(const prog: ustring);
|
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempProgram : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempProgram := CefString(prog);
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefCommandLine(FData)^.set_program(PCefCommandLine(FData), @TempProgram);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefCommandLineRef.UnWrap(data: Pointer): ICefCommandLine;
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefCommandLine
|
|
|
|
else
|
2017-01-27 18:29:37 +02:00
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|