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

160 lines
4.6 KiB
ObjectPascal
Raw Normal View History

2017-01-27 17:37:51 +02:00
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// 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
//
// Copyright � 2017 Salvador D�az Fau. All rights reserved.
//
// ************************************************************************
// ************ 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;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
2017-02-05 21:56:46 +02:00
{$I cef.inc}
2017-01-27 17:37:51 +02:00
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
2017-01-27 17:37:51 +02:00
type
TCefResponseRef = class(TCefBaseRefCountedRef, ICefResponse)
2017-01-27 17:37:51 +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);
function GetHeader(const name: ustring): ustring;
procedure GetHeaderMap(const headerMap: ICefStringMultimap);
procedure SetHeaderMap(const headerMap: ICefStringMultimap);
public
class function UnWrap(data: Pointer): ICefResponse;
class function New: ICefResponse;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
class function TCefResponseRef.New: ICefResponse;
begin
Result := UnWrap(cef_response_create);
end;
function TCefResponseRef.GetError: TCefErrorCode;
begin
Result := PCefResponse(FData)^.get_error(FData);
end;
function TCefResponseRef.GetHeader(const name: ustring): ustring;
var
n: TCefString;
begin
n := CefString(name);
Result := CefStringFreeAndGet(PCefResponse(FData)^.get_header(PCefResponse(FData), @n));
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
txt: TCefString;
begin
txt := CefString(mimetype);
PCefResponse(FData)^.set_mime_type(PCefResponse(FData), @txt);
end;
procedure TCefResponseRef.SetStatus(status: Integer);
begin
PCefResponse(FData)^.set_status(PCefResponse(FData), status);
end;
procedure TCefResponseRef.SetStatusText(const StatusText: ustring);
var
txt: TCefString;
begin
txt := CefString(StatusText);
PCefResponse(FData)^.set_status_text(PCefResponse(FData), @txt);
end;
class function TCefResponseRef.UnWrap(data: Pointer): ICefResponse;
begin
if data <> nil then
Result := Create(data) as ICefResponse else
Result := nil;
end;
end.