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 uCEFDownloadHandler;
|
|
|
|
|
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
|
|
|
TCefDownloadHandlerOwn = class(TCefBaseRefCountedOwn, ICefDownloadHandler)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
|
|
|
procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); virtual;
|
|
|
|
procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback); virtual;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure RemoveReferences; virtual;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomDownloadHandler = class(TCefDownloadHandlerOwn)
|
|
|
|
protected
|
2018-02-03 18:52:48 +02:00
|
|
|
FEvents : Pointer;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); override;
|
|
|
|
procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback); override;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
public
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor Create(const events : IChromiumEvents); reintroduce; virtual;
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor Destroy; override;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFDownLoadItem, uCEFBeforeDownloadCallback,
|
|
|
|
uCEFDownloadItemCallback;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_download_handler_on_before_download( self : PCefDownloadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
download_item : PCefDownloadItem;
|
|
|
|
const suggested_name : PCefString;
|
|
|
|
callback : PCefBeforeDownloadCallback); stdcall;
|
|
|
|
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 TCefDownloadHandlerOwn) then
|
|
|
|
TCefDownloadHandlerOwn(TempObject).OnBeforeDownload(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefDownLoadItemRef.UnWrap(download_item),
|
|
|
|
CefString(suggested_name),
|
|
|
|
TCefBeforeDownloadCallbackRef.UnWrap(callback));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_download_handler_on_download_updated(self : PCefDownloadHandler;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
download_item : PCefDownloadItem;
|
|
|
|
callback : PCefDownloadItemCallback); stdcall;
|
|
|
|
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 TCefDownloadHandlerOwn) then
|
|
|
|
TCefDownloadHandlerOwn(TempObject).OnDownloadUpdated(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefDownLoadItemRef.UnWrap(download_item),
|
|
|
|
TCefDownloadItemCallbackRef.UnWrap(callback));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefDownloadHandlerOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefDownloadHandler));
|
2018-02-03 18:52:48 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
with PCefDownloadHandler(FData)^ do
|
2018-02-03 18:52:48 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
on_before_download := {$IFDEF FPC}@{$ENDIF}cef_download_handler_on_before_download;
|
|
|
|
on_download_updated := {$IFDEF FPC}@{$ENDIF}cef_download_handler_on_download_updated;
|
2018-02-03 18:52:48 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefDownloadHandlerOwn.OnBeforeDownload(const browser : ICefBrowser;
|
|
|
|
const downloadItem : ICefDownloadItem;
|
|
|
|
const suggestedName : ustring;
|
|
|
|
const callback : ICefBeforeDownloadCallback);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefDownloadHandlerOwn.OnDownloadUpdated(const browser : ICefBrowser;
|
|
|
|
const downloadItem : ICefDownloadItem;
|
|
|
|
const callback : ICefDownloadItemCallback);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure TCefDownloadHandlerOwn.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
// TCustomDownloadHandler
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor TCustomDownloadHandler.Create(const events : IChromiumEvents);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
FEvents := Pointer(events);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2017-06-11 17:48:20 +02:00
|
|
|
destructor TCustomDownloadHandler.Destroy;
|
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
RemoveReferences;
|
2017-06-11 17:48:20 +02:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure TCustomDownloadHandler.RemoveReferences;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
FEvents := nil;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-03 18:52:48 +02:00
|
|
|
procedure TCustomDownloadHandler.OnBeforeDownload(const browser : ICefBrowser;
|
|
|
|
const downloadItem : ICefDownloadItem;
|
|
|
|
const suggestedName : ustring;
|
|
|
|
const callback : ICefBeforeDownloadCallback);
|
|
|
|
begin
|
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnBeforeDownload(browser, downloadItem, suggestedName, callback);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomDownloadHandler.OnDownloadUpdated(const browser : ICefBrowser;
|
|
|
|
const downloadItem : ICefDownloadItem;
|
|
|
|
const callback : ICefDownloadItemCallback);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-02-03 18:52:48 +02:00
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnDownloadUpdated(browser, downloadItem, callback);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|