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
|
|
|
|
//
|
2019-01-08 20:15:25 +02:00
|
|
|
// Copyright � 2019 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 17:37:51 +02: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 uCEFResourceHandler;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-11-22 16:02:21 +02:00
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2017-02-05 21:56:46 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-03-16 20:09:42 +02:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
type
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefResourceHandlerOwn = class(TCefBaseRefCountedOwn, ICefResourceHandler)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
|
|
|
function ProcessRequest(const request: ICefRequest; const callback: ICefCallback): Boolean; virtual;
|
|
|
|
procedure GetResponseHeaders(const response: ICefResponse; out responseLength: Int64; out redirectUrl: ustring); virtual;
|
|
|
|
function ReadResponse(const dataOut: Pointer; bytesToRead: Integer; var bytesRead: Integer; const callback: ICefCallback): Boolean; virtual;
|
|
|
|
function CanGetCookie(const cookie: PCefCookie): Boolean; virtual;
|
|
|
|
function CanSetCookie(const cookie: PCefCookie): Boolean; virtual;
|
|
|
|
procedure Cancel; virtual;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(const browser: ICefBrowser; const frame: ICefFrame; const schemeName: ustring; const request: ICefRequest); virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCefResourceHandlerClass = class of TCefResourceHandlerOwn;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFCallback, uCEFRequest, uCEFResponse;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_handler_process_request(self : PCefResourceHandler;
|
|
|
|
request : PCefRequest;
|
|
|
|
callback : PCefCallback): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
Result := Ord(TCefResourceHandlerOwn(TempObject).ProcessRequest(TCefRequestRef.UnWrap(request),
|
|
|
|
TCefCallbackRef.UnWrap(callback)));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_resource_handler_get_response_headers(self : PCefResourceHandler;
|
|
|
|
response : PCefResponse;
|
|
|
|
response_length : PInt64;
|
|
|
|
redirectUrl : PCefString); stdcall;
|
2017-01-27 17:37:51 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempRedirect : ustring;
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempRedirect := '';
|
|
|
|
TempObject := CefGetObject(self);
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
TCefResourceHandlerOwn(TempObject).GetResponseHeaders(TCefResponseRef.UnWrap(response),
|
|
|
|
response_length^,
|
|
|
|
TempRedirect);
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
if (TempRedirect <> '') then CefStringSet(redirectUrl, TempRedirect);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_handler_read_response(self : PCefResourceHandler;
|
|
|
|
data_out : Pointer;
|
|
|
|
bytes_to_read : Integer;
|
|
|
|
bytes_read : PInteger;
|
|
|
|
callback : PCefCallback): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
Result := Ord(TCefResourceHandlerOwn(TempObject).ReadResponse(data_out,
|
|
|
|
bytes_to_read,
|
|
|
|
bytes_read^,
|
|
|
|
TCefCallbackRef.UnWrap(callback)));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_handler_can_get_cookie( self : PCefResourceHandler;
|
|
|
|
const cookie : PCefCookie): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(True);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
Result := Ord(TCefResourceHandlerOwn(TempObject).CanGetCookie(cookie));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_handler_can_set_cookie( self : PCefResourceHandler;
|
|
|
|
const cookie : PCefCookie): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(True);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
Result := Ord(TCefResourceHandlerOwn(TempObject).CanSetCookie(cookie));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure cef_resource_handler_cancel(self: PCefResourceHandler); stdcall;
|
2018-03-29 20:02:04 +02:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefResourceHandlerOwn) then
|
|
|
|
TCefResourceHandlerOwn(TempObject).Cancel;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefResourceHandlerOwn.Cancel;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
//
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefResourceHandlerOwn.CanGetCookie(const cookie: PCefCookie): Boolean;
|
|
|
|
begin
|
2018-02-08 13:45:25 +02:00
|
|
|
Result := True;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefResourceHandlerOwn.CanSetCookie(const cookie: PCefCookie): Boolean;
|
|
|
|
begin
|
2018-02-08 13:45:25 +02:00
|
|
|
Result := True;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-03-16 20:09:42 +02:00
|
|
|
constructor TCefResourceHandlerOwn.Create(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const schemeName : ustring;
|
|
|
|
const request : ICefRequest);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefResourceHandler));
|
2017-03-16 20:09:42 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
with PCefResourceHandler(FData)^ do
|
2017-03-16 20:09:42 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
process_request := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_process_request;
|
|
|
|
get_response_headers := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_get_response_headers;
|
|
|
|
read_response := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_read_response;
|
|
|
|
can_get_cookie := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_can_get_cookie;
|
|
|
|
can_set_cookie := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_can_set_cookie;
|
|
|
|
cancel := {$IFDEF FPC}@{$ENDIF}cef_resource_handler_cancel;
|
2017-03-16 20:09:42 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-03-16 20:09:42 +02:00
|
|
|
procedure TCefResourceHandlerOwn.GetResponseHeaders(const response : ICefResponse;
|
|
|
|
out responseLength : Int64;
|
|
|
|
out redirectUrl : ustring);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
//
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefResourceHandlerOwn.ProcessRequest(const request : ICefRequest;
|
|
|
|
const callback : ICefCallback): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
2017-03-16 20:09:42 +02:00
|
|
|
function TCefResourceHandlerOwn.ReadResponse(const dataOut : Pointer;
|
|
|
|
bytesToRead : Integer;
|
|
|
|
var bytesRead : Integer;
|
|
|
|
const callback : ICefCallback): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|