2017-01-27 16:37:51 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-01-27 16:37:51 +01:00
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2023-01-07 15:53:04 +01:00
|
|
|
|
// Copyright <20> 2023 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 16:37:51 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFResponse;
|
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-03-16 19:09:42 +01:00
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
|
TCefResponseRef = class(TCefBaseRefCountedRef, ICefResponse)
|
2018-04-20 12:45:06 +02:00
|
|
|
|
protected
|
|
|
|
|
function IsReadOnly: Boolean;
|
|
|
|
|
function GetError: TCefErrorCode;
|
|
|
|
|
procedure SetError(error: TCefErrorCode);
|
|
|
|
|
function GetStatus: Integer;
|
|
|
|
|
procedure SetStatus(status: Integer);
|
|
|
|
|
function GetStatusText: ustring;
|
|
|
|
|
procedure SetStatusText(const StatusText: ustring);
|
|
|
|
|
function GetMimeType: ustring;
|
|
|
|
|
procedure SetMimeType(const mimetype: ustring);
|
2019-06-16 10:31:13 +02:00
|
|
|
|
function GetCharset: ustring;
|
|
|
|
|
procedure SetCharset(const charset: ustring);
|
2019-10-30 10:26:48 +01:00
|
|
|
|
function GetHeaderByName(const name: ustring): ustring;
|
|
|
|
|
procedure SetHeaderByName(const name, value: ustring; overwrite: boolean);
|
2018-04-20 12:45:06 +02:00
|
|
|
|
procedure GetHeaderMap(const headerMap: ICefStringMultimap);
|
|
|
|
|
procedure SetHeaderMap(const headerMap: ICefStringMultimap);
|
|
|
|
|
function GetURL: ustring;
|
|
|
|
|
procedure SetURL(const url: ustring);
|
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
class function UnWrap(data: Pointer): ICefResponse;
|
|
|
|
|
class function New: ICefResponse;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class function TCefResponseRef.New: ICefResponse;
|
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
|
Result := UnWrap(cef_response_create());
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.GetError: TCefErrorCode;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefResponse(FData)^.get_error(FData);
|
|
|
|
|
end;
|
|
|
|
|
|
2019-10-30 10:26:48 +01:00
|
|
|
|
function TCefResponseRef.GetHeaderByName(const name: ustring): ustring;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
var
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempName : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempName := CefString(name);
|
2019-10-30 10:26:48 +01:00
|
|
|
|
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_header_by_name(PCefResponse(FData), @TempName));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetHeaderByName(const name, value: ustring; overwrite: boolean);
|
|
|
|
|
var
|
|
|
|
|
TempName, TempValue : TCefString;
|
|
|
|
|
begin
|
|
|
|
|
TempName := CefString(name);
|
|
|
|
|
TempValue := CefString(value);
|
|
|
|
|
PCefResponse(FData)^.set_header_by_name(PCefResponse(FData), @TempName, @TempValue, ord(overwrite));
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.GetHeaderMap(const headerMap: ICefStringMultimap);
|
|
|
|
|
begin
|
|
|
|
|
PCefResponse(FData)^.get_header_map(PCefResponse(FData), headermap.Handle);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.GetMimeType: ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_mime_type(PCefResponse(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.GetStatus: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefResponse(FData)^.get_status(PCefResponse(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.GetStatusText: ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_status_text(PCefResponse(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.IsReadOnly: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefResponse(FData)^.is_read_only(PCefResponse(FData)) <> 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetError(error: TCefErrorCode);
|
|
|
|
|
begin
|
|
|
|
|
PCefResponse(FData)^.set_error(FData, error);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetHeaderMap(const headerMap: ICefStringMultimap);
|
|
|
|
|
begin
|
|
|
|
|
PCefResponse(FData)^.set_header_map(PCefResponse(FData), headerMap.Handle);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetMimeType(const mimetype: ustring);
|
|
|
|
|
var
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempType : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempType := CefString(mimetype);
|
|
|
|
|
PCefResponse(FData)^.set_mime_type(PCefResponse(FData), @TempType);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
|
function TCefResponseRef.GetCharset: ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_charset(PCefResponse(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetCharset(const charset: ustring);
|
|
|
|
|
var
|
|
|
|
|
TempCharset : TCefString;
|
|
|
|
|
begin
|
|
|
|
|
TempCharset := CefString(charset);
|
|
|
|
|
PCefResponse(FData)^.set_charset(PCefResponse(FData), @TempCharset);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
procedure TCefResponseRef.SetStatus(status: Integer);
|
|
|
|
|
begin
|
|
|
|
|
PCefResponse(FData)^.set_status(PCefResponse(FData), status);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetStatusText(const StatusText: ustring);
|
|
|
|
|
var
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempStatus : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
begin
|
2018-04-20 12:45:06 +02:00
|
|
|
|
TempStatus := CefString(StatusText);
|
|
|
|
|
PCefResponse(FData)^.set_status_text(PCefResponse(FData), @TempStatus);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefResponseRef.GetURL : ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_url(PCefResponse(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefResponseRef.SetURL(const url : ustring);
|
|
|
|
|
var
|
|
|
|
|
TempURL : TCefString;
|
|
|
|
|
begin
|
|
|
|
|
TempURL := CefString(url);
|
|
|
|
|
PCefResponse(FData)^.set_url(PCefResponse(FData), @TempURL);
|
2017-01-27 16:37:51 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
class function TCefResponseRef.UnWrap(data: Pointer): ICefResponse;
|
|
|
|
|
begin
|
2018-04-20 12:45:06 +02:00
|
|
|
|
if (data <> nil) then
|
|
|
|
|
Result := Create(data) as ICefResponse
|
|
|
|
|
else
|
2017-01-27 16:37:51 +01:00
|
|
|
|
Result := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|