CEF4Delphi/source/uCEFDownloadHandler.pas

156 lines
5.2 KiB
ObjectPascal
Raw Normal View History

2017-01-27 16:37:51 +01: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 <20> 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 uCEFDownloadHandler;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
2017-02-05 20:56:46 +01:00
{$I cef.inc}
2017-01-27 16:37:51 +01:00
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
2017-01-27 16:37:51 +01:00
type
TCefDownloadHandlerOwn = class(TCefBaseRefCountedOwn, ICefDownloadHandler)
2017-01-27 16:37:51 +01: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;
public
constructor Create; virtual;
end;
TCustomDownloadHandler = class(TCefDownloadHandlerOwn)
protected
FEvent: IChromiumEvents;
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;
public
constructor Create(const events: IChromiumEvents); reintroduce; virtual;
destructor Destroy; override;
2017-01-27 16:37:51 +01:00
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFDownLoadItem, uCEFBeforeDownloadCallback,
uCEFDownloadItemCallback;
procedure cef_download_handler_on_before_download(self: PCefDownloadHandler;
browser: PCefBrowser; download_item: PCefDownloadItem;
const suggested_name: PCefString; callback: PCefBeforeDownloadCallback); stdcall;
begin
TCefDownloadHandlerOwn(CefGetObject(self)).
OnBeforeDownload(TCefBrowserRef.UnWrap(browser),
TCefDownLoadItemRef.UnWrap(download_item), CefString(suggested_name),
TCefBeforeDownloadCallbackRef.UnWrap(callback));
end;
procedure cef_download_handler_on_download_updated(self: PCefDownloadHandler;
browser: PCefBrowser; download_item: PCefDownloadItem; callback: PCefDownloadItemCallback); stdcall;
begin
TCefDownloadHandlerOwn(CefGetObject(self)).
OnDownloadUpdated(TCefBrowserRef.UnWrap(browser),
TCefDownLoadItemRef.UnWrap(download_item),
TCefDownloadItemCallbackRef.UnWrap(callback));
end;
constructor TCefDownloadHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefDownloadHandler));
with PCefDownloadHandler(FData)^ do
begin
on_before_download := cef_download_handler_on_before_download;
on_download_updated := cef_download_handler_on_download_updated;
end;
end;
procedure TCefDownloadHandlerOwn.OnBeforeDownload(const browser: ICefBrowser;
const downloadItem: ICefDownloadItem; const suggestedName: ustring;
const callback: ICefBeforeDownloadCallback);
begin
end;
procedure TCefDownloadHandlerOwn.OnDownloadUpdated(const browser: ICefBrowser;
const downloadItem: ICefDownloadItem;
const callback: ICefDownloadItemCallback);
begin
end;
// TCustomDownloadHandler
constructor TCustomDownloadHandler.Create(const events: IChromiumEvents);
begin
inherited Create;
2017-01-27 16:37:51 +01:00
FEvent := events;
end;
destructor TCustomDownloadHandler.Destroy;
begin
FEvent := nil;
inherited Destroy;
end;
2017-01-27 16:37:51 +01:00
procedure TCustomDownloadHandler.OnBeforeDownload(const browser: ICefBrowser;
const downloadItem: ICefDownloadItem; const suggestedName: ustring;
const callback: ICefBeforeDownloadCallback);
begin
if (FEvent <> nil) then
FEvent.doOnBeforeDownload(browser, downloadItem, suggestedName, callback);
2017-01-27 16:37:51 +01:00
end;
procedure TCustomDownloadHandler.OnDownloadUpdated(const browser: ICefBrowser;
const downloadItem: ICefDownloadItem;
const callback: ICefDownloadItemCallback);
begin
if (FEvent <> nil) then
FEvent.doOnDownloadUpdated(browser, downloadItem, callback);
2017-01-27 16:37:51 +01:00
end;
end.