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 uCEFRequestContextHandler;
|
2018-05-12 14:50:54 +02:00
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
2017-01-27 17:37:51 +02:00
|
|
|
|
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
|
|
|
TCefRequestContextHandlerRef = class(TCefBaseRefCountedRef, ICefRequestContextHandler)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
2017-10-26 13:23:13 +02:00
|
|
|
procedure OnRequestContextInitialized(const request_context: ICefRequestContext);
|
|
|
|
function GetCookieManager: ICefCookieManager;
|
|
|
|
function OnBeforePluginLoad(const mimeType, pluginUrl: ustring; isMainFrame : boolean; const topOriginUrl: ustring; const pluginInfo: ICefWebPluginInfo; pluginPolicy: PCefPluginPolicy): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefRequestContextHandler;
|
|
|
|
end;
|
|
|
|
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefRequestContextHandlerOwn = class(TCefBaseRefCountedOwn, ICefRequestContextHandler)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
2017-10-26 13:23:13 +02:00
|
|
|
procedure OnRequestContextInitialized(const request_context: ICefRequestContext);
|
|
|
|
function GetCookieManager: ICefCookieManager; virtual;
|
|
|
|
function OnBeforePluginLoad(const mimeType, pluginUrl: ustring; isMainFrame : boolean; const topOriginUrl: ustring; const pluginInfo: ICefWebPluginInfo; pluginPolicy: PCefPluginPolicy): Boolean; virtual;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCefFastRequestContextHandler = class(TCefRequestContextHandlerOwn)
|
|
|
|
protected
|
|
|
|
FProc: TCefRequestContextHandlerProc;
|
|
|
|
|
|
|
|
function GetCookieManager: ICefCookieManager; override;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(const proc: TCefRequestContextHandlerProc); reintroduce;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2017-10-26 13:23:13 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFCookieManager, uCEFWebPluginInfo, uCEFRequestContext;
|
|
|
|
|
|
|
|
// TCefRequestContextHandlerOwn
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_request_context_handler_on_request_context_initialized(self : PCefRequestContextHandler;
|
|
|
|
request_context : PCefRequestContext); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-10-26 13:23:13 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestContextHandlerOwn) then
|
|
|
|
TCefRequestContextHandlerOwn(TempObject).OnRequestContextInitialized(TCefRequestContextRef.UnWrap(request_context));
|
2017-10-26 13:23:13 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
function cef_request_context_handler_get_cookie_manager(self: PCefRequestContextHandler): PCefCookieManager; 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
|
|
|
Result := nil;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefRequestContextHandlerOwn) then
|
|
|
|
Result := CefGetData(TCefRequestContextHandlerOwn(TempObject).GetCookieManager());
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_request_context_handler_on_before_plugin_load( self : PCefRequestContextHandler;
|
|
|
|
const mime_type : PCefString;
|
|
|
|
const plugin_url : PCefString;
|
|
|
|
is_main_frame : integer;
|
|
|
|
const top_origin_url : PCefString;
|
|
|
|
plugin_info : PCefWebPluginInfo;
|
|
|
|
plugin_policy : PCefPluginPolicy): 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 TCefRequestContextHandlerOwn) then
|
|
|
|
Result := Ord(TCefRequestContextHandlerOwn(TempObject).OnBeforePluginLoad(CefString(mime_type),
|
|
|
|
CefString(plugin_url),
|
|
|
|
(is_main_frame <> 0),
|
|
|
|
CefString(top_origin_url),
|
|
|
|
TCefWebPluginInfoRef.UnWrap(plugin_info),
|
|
|
|
plugin_policy));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-10-26 13:23:13 +02:00
|
|
|
constructor TCefRequestContextHandlerOwn.Create;
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
inherited CreateData(SizeOf(TCefRequestContextHandler));
|
2017-10-26 13:23:13 +02:00
|
|
|
|
|
|
|
with PCefRequestContextHandler(FData)^ do
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
on_request_context_initialized := {$IFDEF FPC}@{$ENDIF}cef_request_context_handler_on_request_context_initialized;
|
|
|
|
get_cookie_manager := {$IFDEF FPC}@{$ENDIF}cef_request_context_handler_get_cookie_manager;
|
|
|
|
on_before_plugin_load := {$IFDEF FPC}@{$ENDIF}cef_request_context_handler_on_before_plugin_load;
|
2017-10-26 13:23:13 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestContextHandlerOwn.OnRequestContextInitialized(const request_context: ICefRequestContext);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
//
|
2017-10-26 13:23:13 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestContextHandlerOwn.GetCookieManager: ICefCookieManager;
|
|
|
|
begin
|
|
|
|
Result:= nil;
|
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefRequestContextHandlerOwn.OnBeforePluginLoad(const mimeType : ustring;
|
|
|
|
const pluginUrl : ustring;
|
|
|
|
isMainFrame : boolean;
|
|
|
|
const topOriginUrl : ustring;
|
|
|
|
const pluginInfo : ICefWebPluginInfo;
|
|
|
|
pluginPolicy : PCefPluginPolicy): Boolean;
|
2017-10-26 13:23:13 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// TCefRequestContextHandlerRef
|
|
|
|
|
|
|
|
procedure TCefRequestContextHandlerRef.OnRequestContextInitialized(const request_context: ICefRequestContext);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefRequestContextHandler(FData)^.on_request_context_initialized(PCefRequestContextHandler(FData), CefGetData(request_context));
|
2017-10-26 13:23:13 +02:00
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
function TCefRequestContextHandlerRef.GetCookieManager: ICefCookieManager;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TCefCookieManagerRef.UnWrap(PCefRequestContextHandler(FData)^.get_cookie_manager(PCefRequestContextHandler(FData)));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
function TCefRequestContextHandlerRef.OnBeforePluginLoad(const mimeType : ustring;
|
|
|
|
const pluginUrl : ustring;
|
|
|
|
isMainFrame : boolean;
|
|
|
|
const topOriginUrl : ustring;
|
|
|
|
const pluginInfo : ICefWebPluginInfo;
|
|
|
|
pluginPolicy : PCefPluginPolicy): Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempType, TempPluginURL, TempOriginURL : TCefString;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempType := CefString(mimeType);
|
|
|
|
TempPluginURL := CefString(pluginUrl);
|
|
|
|
TempOriginURL := CefString(topOriginUrl);
|
|
|
|
|
|
|
|
Result := PCefRequestContextHandler(FData)^.on_before_plugin_load(PCefRequestContextHandler(FData),
|
|
|
|
@TempType,
|
|
|
|
@TempPluginURL,
|
|
|
|
ord(isMainFrame),
|
|
|
|
@TempOriginURL,
|
|
|
|
CefGetData(pluginInfo),
|
|
|
|
pluginPolicy) <> 0;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefRequestContextHandlerRef.UnWrap(data: Pointer): ICefRequestContextHandler;
|
|
|
|
begin
|
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefRequestContextHandler
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// TCefFastRequestContextHandler
|
|
|
|
|
|
|
|
constructor TCefFastRequestContextHandler.Create(const proc: TCefRequestContextHandlerProc);
|
|
|
|
begin
|
|
|
|
FProc := proc;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
inherited Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefFastRequestContextHandler.GetCookieManager: ICefCookieManager;
|
|
|
|
begin
|
|
|
|
Result := FProc();
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|