2018-02-03 17:52:48 +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
//
2018-05-24 17:40:49 +02:00
// Copyright ?2018 Salvador Diaz Fau. All rights reserved.
2018-02-03 17:52:48 +01: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.
*
* )
2018-02-04 11:50:14 +01:00
unit uResponseFilterBrowser;
2018-02-03 17:52:48 +01:00
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
Winapi . Windows, Winapi . Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls, Vcl. ExtCtrls, System. SyncObjs,
{$ELSE}
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, SyncObjs,
{$ENDIF}
2018-05-27 11:13:01 +02:00
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants, uCEFTypes, uCEFResponseFilter,
Vcl. ComCtrls;
2018-02-03 17:52:48 +01:00
const
STREAM_COPY_COMPLETE = WM_APP + $B00 ;
type
TResponseFilterBrowserFrm = class( TForm)
AddressPnl: TPanel;
AddressEdt: TEdit;
Timer1: TTimer;
Chromium1: TChromium;
CEFWindowParent1: TCEFWindowParent;
Splitter1: TSplitter;
2018-02-08 10:49:06 +01:00
Panel1: TPanel;
GoBtn: TButton;
Label1: TLabel;
RscNameEdt: TEdit;
2018-05-27 11:13:01 +02:00
Panel2: TPanel;
Memo1: TMemo;
StatusBar1: TStatusBar;
2018-02-03 17:52:48 +01:00
procedure GoBtnClick( Sender: TObject) ;
procedure Timer1Timer( Sender: TObject) ;
procedure Chromium1AfterCreated( Sender: TObject; const browser: ICefBrowser) ;
2018-02-08 10:49:06 +01:00
procedure Chromium1GetResourceResponseFilter( Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result : ICefResponseFilter) ;
2018-02-13 20:16:24 +01:00
procedure Chromium1ResourceLoadComplete( Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; status: TCefUrlRequestStatus; receivedContentLength: Int64 ) ;
2018-02-08 10:49:06 +01:00
procedure FormShow( Sender: TObject) ;
2018-02-03 17:52:48 +01:00
procedure FormCreate( Sender: TObject) ;
procedure FormDestroy( Sender: TObject) ;
2018-02-16 18:41:13 +01:00
procedure Chromium1BeforePopup( Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean ;
2018-03-29 20:02:04 +02:00
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
2018-02-16 18:41:13 +01:00
var client: ICefClient; var settings: TCefBrowserSettings;
2018-03-29 20:02:04 +02:00
var noJavascriptAccess: Boolean ; var Result : Boolean ) ;
2018-03-31 18:08:18 +02:00
procedure FormCloseQuery( Sender: TObject; var CanClose: Boolean ) ;
procedure Chromium1Close( Sender: TObject; const browser: ICefBrowser;
out Result : Boolean ) ;
procedure Chromium1BeforeClose( Sender: TObject;
const browser: ICefBrowser) ;
2018-02-03 17:52:48 +01:00
protected
2018-02-07 14:30:44 +01:00
FFilter : ICefResponseFilter; // CEF Filter interface that receives the resource contents
FStream : TMemoryStream; // TMemoryStream to hold the resource contents
FStreamCS : TCriticalSection; // Critical section used to protect the memory stream
FRscSize : int64 ; // size of the resource if the server sends the Content-Length header
FRscCompleted : boolean ; // This variable will be used to handle the results only once.
2018-05-24 17:40:49 +02:00
FRscEncoding : TEncoding; // The resource response Encoding. When encoding is unicode. The response data may be sent by multi chains, will cause encoding parsing problem.
FRscMimeType : String ;
2018-05-27 11:13:01 +02:00
FFilterInit : boolean ;
2018-03-31 18:08:18 +02:00
// Variables to control when can we destroy the form safely
FCanClose : boolean ; // Set to True in TChromium.OnBeforeClose
FClosing : boolean ; // Set to True in the CloseQuery event.
2018-02-03 17:52:48 +01:00
2018-05-24 17:40:49 +02:00
procedure WMMove( var aMessage: TWMMove) ; message WM_MOVE;
procedure WMMoving( var aMessage: TMessage) ; message WM_MOVING;
2018-02-03 17:52:48 +01:00
procedure WMEnterMenuLoop( var aMessage: TMessage) ; message WM_ENTERMENULOOP;
procedure WMExitMenuLoop( var aMessage: TMessage) ; message WM_EXITMENULOOP;
procedure BrowserCreatedMsg( var aMessage : TMessage) ; message CEF_AFTERCREATED;
2018-05-24 17:40:49 +02:00
procedure BrowserDestroyMsg( var aMessage: TMessage) ; message CEF_DESTROY;
2018-02-03 17:52:48 +01:00
procedure StreamCopyCompleteMsg( var aMessage : TMessage) ; message STREAM_COPY_COMPLETE;
procedure Filter_OnFilter( Sender: TObject; data_in: Pointer ; data_in_size: NativeUInt ; var data_in_read: NativeUInt ; data_out: Pointer ; data_out_size : NativeUInt ; var data_out_written: NativeUInt ; var aResult : TCefResponseFilterStatus) ;
2018-02-08 10:49:06 +01:00
2018-05-24 19:15:41 +02:00
procedure UpdateRscEncoding( const aMimeType, aContentType : string ) ;
2018-02-08 10:49:06 +01:00
function IsMyResource( const aRequest : ICefRequest) : boolean ;
2018-05-24 17:40:49 +02:00
procedure GetResponseEncoding( const aContentType: string ) ;
2018-02-03 17:52:48 +01:00
public
{ Public declarations }
end ;
var
ResponseFilterBrowserFrm: TResponseFilterBrowserFrm;
implementation
{$R *.dfm}
uses
{$IFDEF DELPHI16_UP}
System. Math,
{$ELSE}
Math,
{$ENDIF}
2018-02-04 11:50:14 +01:00
uCEFApplication, uCEFMiscFunctions;
2018-02-03 17:52:48 +01:00
// This demo uses a TCustomResponseFilter to read the contents from a JavaScript file in wikipedia.org into a TMemoryStream.
// The stream is shown in the TMemo when it's finished.
// For more information read the CEF3 code comments here :
// https://github.com/chromiumembedded/cef/blob/master/include/capi/cef_response_filter_capi.h
2018-03-31 18:08:18 +02:00
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
2018-02-03 17:52:48 +01:00
procedure TResponseFilterBrowserFrm. Filter_OnFilter( Sender: TObject;
data_in : Pointer ;
data_in_size : NativeUInt ;
var data_in_read : NativeUInt ;
data_out : Pointer ;
data_out_size : NativeUInt ;
var data_out_written : NativeUInt ;
var aResult : TCefResponseFilterStatus) ;
begin
try
2018-02-04 11:50:14 +01:00
try
2018-05-24 19:15:41 +02:00
FStreamCS. Acquire;
2018-05-27 11:13:01 +02:00
if FFilterInit then
2018-02-04 11:50:14 +01:00
begin
2018-05-27 11:13:01 +02:00
// This event will be called repeatedly until the input buffer has been fully read.
// When there's no more data then data_in is nil and you can show the stream contents.
if ( data_in = nil ) then
begin
data_in_read : = 0 ;
data_out_written : = 0 ;
aResult : = RESPONSE_FILTER_DONE;
if not( FRscCompleted) and
( FStream. Size > 0 ) and
( ( FRscSize = - 1 ) or ( FRscSize = FStream. Size) ) then
FRscCompleted : = PostMessage( Handle, STREAM_COPY_COMPLETE, 0 , 0 ) ;
end
else
2018-05-24 19:15:41 +02:00
begin
2018-05-27 11:13:01 +02:00
if ( data_out < > nil ) then
begin
data_out_written : = min( data_in_size, data_out_size) ;
2018-02-07 10:02:24 +01:00
2018-05-27 11:13:01 +02:00
if ( data_out_written > 0 ) then
Move( data_in^ , data_out^ , data_out_written) ;
end ;
2018-02-04 11:50:14 +01:00
2018-05-27 11:13:01 +02:00
if ( data_in_size > 0 ) then
data_in_read : = FStream. Write( data_in^ , data_in_size) ;
2018-02-07 10:02:24 +01:00
2018-05-27 11:13:01 +02:00
// Send the STREAM_COPY_COMPLETE message only if the server sent the data size in
// a Content-Length header and we can compare it with the stream size
if not( FRscCompleted) and ( FRscSize < > - 1 ) and ( FRscSize = FStream. Size) then
FRscCompleted : = PostMessage( Handle, STREAM_COPY_COMPLETE, 0 , 0 ) ;
2018-02-07 10:36:11 +01:00
2018-05-27 11:13:01 +02:00
aResult : = RESPONSE_FILTER_NEED_MORE_DATA;
end ;
end ;
2018-02-04 11:50:14 +01:00
except
on e : exception do
begin
aResult : = RESPONSE_FILTER_ERROR;
if CustomExceptionHandler( 'TResponseFilterBrowserFrm.Filter_OnFilter' , e) then raise ;
end ;
end ;
2018-02-03 17:52:48 +01:00
finally
FStreamCS. Release;
end ;
end ;
2018-02-08 10:49:06 +01:00
function TResponseFilterBrowserFrm. IsMyResource( const aRequest : ICefRequest) : boolean ;
var
TempName : string ;
begin
TempName : = trim( RscNameEdt. Text ) ;
if ( aRequest < > nil ) and ( length( TempName) > 0 ) then
Result : = ( pos( TempName, aRequest. URL) > 0 )
else
Result : = False ;
end ;
2018-03-31 18:08:18 +02:00
procedure TResponseFilterBrowserFrm. FormCloseQuery( Sender: TObject; var CanClose: Boolean ) ;
begin
CanClose : = FCanClose;
if not( FClosing) then
begin
FClosing : = True ;
Visible : = False ;
Chromium1. CloseBrowser( True ) ;
end ;
end ;
2018-02-03 17:52:48 +01:00
procedure TResponseFilterBrowserFrm. FormCreate( Sender: TObject) ;
begin
2018-05-27 11:13:01 +02:00
FFilterInit : = False ;
2018-02-07 10:36:11 +01:00
FRscCompleted : = False ;
2018-02-07 14:30:44 +01:00
FRscSize : = - 1 ;
2018-02-07 10:36:11 +01:00
FStream : = TMemoryStream. Create;
FStreamCS : = TCriticalSection. Create;
FFilter : = TCustomResponseFilter. Create;
2018-05-24 19:15:41 +02:00
FRscEncoding : = TEncoding. Default ;
2018-02-03 17:52:48 +01:00
2018-03-31 18:08:18 +02:00
FCanClose : = False ;
FClosing : = False ;
2018-02-03 17:52:48 +01:00
// This event will receive the data
TCustomResponseFilter( FFilter) . OnFilter : = Filter_OnFilter;
end ;
procedure TResponseFilterBrowserFrm. FormDestroy( Sender: TObject) ;
begin
FFilter : = nil ;
FStream. Free;
FStreamCS. Free;
end ;
procedure TResponseFilterBrowserFrm. FormShow( Sender: TObject) ;
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
// If it's not initialized yet, we use a simple timer to create the browser later.
if not( Chromium1. CreateBrowser( CEFWindowParent1) ) then Timer1. Enabled : = True ;
end ;
procedure TResponseFilterBrowserFrm. Chromium1AfterCreated( Sender: TObject; const browser: ICefBrowser) ;
begin
// Now the browser is fully initialized we can send a message to the main form to load the initial web page.
PostMessage( Handle, CEF_AFTERCREATED, 0 , 0 ) ;
end ;
2018-05-24 19:15:41 +02:00
procedure TResponseFilterBrowserFrm. Chromium1BeforeClose( Sender: TObject; const browser: ICefBrowser) ;
2018-03-31 18:08:18 +02:00
begin
FCanClose : = True ;
PostMessage( Handle, WM_CLOSE, 0 , 0 ) ;
end ;
2018-02-16 18:41:13 +01:00
procedure TResponseFilterBrowserFrm. Chromium1BeforePopup( Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
2018-03-29 20:02:04 +02:00
userGesture: Boolean ; const popupFeatures: TCefPopupFeatures;
2018-02-16 18:41:13 +01:00
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean ;
2018-03-29 20:02:04 +02:00
var Result : Boolean ) ;
2018-02-16 18:41:13 +01:00
begin
// For simplicity, this demo blocks all popup windows and new tabs
Result : = ( targetDisposition in [ WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW] ) ;
end ;
2018-05-27 11:13:01 +02:00
procedure TResponseFilterBrowserFrm. Chromium1Close( Sender: TObject; const browser: ICefBrowser; out Result : Boolean ) ;
2018-03-31 18:08:18 +02:00
begin
PostMessage( Handle, CEF_DESTROY, 0 , 0 ) ;
Result : = True ;
end ;
2018-02-03 17:52:48 +01:00
procedure TResponseFilterBrowserFrm. Chromium1GetResourceResponseFilter( Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const request : ICefRequest;
const response : ICefResponse;
out Result : ICefResponseFilter) ;
2018-02-07 14:30:44 +01:00
var
TempHeader : string ;
2018-05-24 19:15:41 +02:00
TempLen : integer ;
2018-02-03 17:52:48 +01:00
begin
2018-05-25 14:40:49 +02:00
if not( FRscCompleted) and ( response < > nil ) and IsMyResource( request) then
begin
2018-05-27 11:13:01 +02:00
try
FStreamCS. Acquire;
2018-05-25 14:40:49 +02:00
2018-05-27 11:13:01 +02:00
Result : = FFilter;
FFilterInit : = True ;
TempHeader : = trim( response. GetHeader( 'Content-Length' ) ) ;
2018-05-25 14:40:49 +02:00
2018-05-27 11:13:01 +02:00
if TryStrToInt( TempHeader, TempLen) and ( TempLen > 0 ) then
begin
FRscSize : = TempLen;
StatusBar1. Panels[ 0 ] . Text : = 'Content-Length : ' + inttostr( FRscSize) ;
end
else
begin
FRscSize : = - 1 ;
StatusBar1. Panels[ 0 ] . Text : = 'Content-Length : not available' ;
end ;
UpdateRscEncoding( response. MimeType, response. GetHeader( 'Content-Type' ) ) ;
finally
FStreamCS. Release;
end ;
2018-05-25 14:40:49 +02:00
end
else
2018-02-03 17:52:48 +01:00
Result : = nil ;
end ;
2018-05-24 19:15:41 +02:00
procedure TResponseFilterBrowserFrm. UpdateRscEncoding( const aMimeType, aContentType : string ) ;
begin
FRscMimeType : = aMimeType;
if ( aMimeType = 'application/json' ) or
( aMimeType = 'text/json' ) or
( aMimeType = 'text/javascript' ) or
( aMimeType = 'application/javascript' ) then
GetResponseEncoding( aContentType) ;
end ;
2018-02-08 10:49:06 +01:00
procedure TResponseFilterBrowserFrm. Chromium1ResourceLoadComplete( Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const request : ICefRequest;
const response : ICefResponse;
status : TCefUrlRequestStatus;
receivedContentLength : Int64 ) ;
begin
2018-05-24 19:15:41 +02:00
try
FStreamCS. Acquire;
// In case the server didn't send a Content-Length header
// and CEF didn't send a data_in = nil in Filter_OnFilter
// we still can use this event to know when the resource is complete
if IsMyResource( request) then
begin
UpdateRscEncoding( response. MimeType, response. GetHeader( 'Content-Type' ) ) ;
if not( FRscCompleted) then
FRscCompleted : = PostMessage( Handle, STREAM_COPY_COMPLETE, 0 , 0 ) ;
end ;
finally
FStreamCS. Release;
2018-05-24 17:40:49 +02:00
end ;
2018-02-08 10:49:06 +01:00
end ;
2018-02-03 17:52:48 +01:00
procedure TResponseFilterBrowserFrm. BrowserCreatedMsg( var aMessage : TMessage) ;
begin
Caption : = 'Response Filter Browser' ;
AddressPnl. Enabled : = True ;
GoBtn. Click;
end ;
2018-03-31 18:08:18 +02:00
procedure TResponseFilterBrowserFrm. BrowserDestroyMsg( var aMessage : TMessage) ;
begin
CEFWindowParent1. Free;
end ;
2018-02-07 14:30:44 +01:00
// This procedure handles the stream contents after it's fully downloaded
2018-02-03 17:52:48 +01:00
procedure TResponseFilterBrowserFrm. StreamCopyCompleteMsg( var aMessage : TMessage) ;
2018-05-24 17:40:49 +02:00
var
LAS: AnsiString ;
LS: String ;
2018-02-03 17:52:48 +01:00
begin
try
FStreamCS. Acquire;
2018-02-07 11:20:38 +01:00
2018-02-07 14:30:44 +01:00
if ( FStream. Size > 0 ) then
2018-05-24 17:40:49 +02:00
begin
2018-05-24 19:15:41 +02:00
FStream. Seek( 0 , soBeginning) ;
Memo1. Lines. Clear;
if ( FRscMimeType = 'application/json' ) or
( FRscMimeType = 'text/json' ) or
( FRscMimeType = 'text/javascript' ) or
( FRscMimeType = 'application/javascript' ) then
begin
2018-05-27 11:13:01 +02:00
StatusBar1. Panels[ 1 ] . Text : = 'Stream size : ' + inttostr( FStream. Size) ;
2018-05-24 19:15:41 +02:00
SetLength( LAS, FStream. Size) ;
FStream. Read( LAS[ Low( LAS) ] , FStream. Size) ;
if ( FRscEncoding = TEncoding. UTF8) then
LS : = UTF8Decode( LAS) // UTF8 Here
else
LS : = string( LAS) ; // Others encoding text
Memo1. Lines. Add( LS) ;
2018-05-27 11:13:01 +02:00
StatusBar1. Panels[ 2 ] . Text : = 'Decoded size : ' + inttostr( length( LS) ) ;
2018-05-24 19:15:41 +02:00
end
else
Memo1. Lines. LoadFromStream( FStream) ; // Image or others
FStream. Clear;
2018-05-24 17:40:49 +02:00
end
2018-05-24 19:15:41 +02:00
else
2018-02-07 14:30:44 +01:00
Memo1. Lines. Clear;
2018-02-03 17:52:48 +01:00
finally
FStreamCS. Release;
end ;
end ;
procedure TResponseFilterBrowserFrm. GoBtnClick( Sender: TObject) ;
begin
2018-05-27 11:13:01 +02:00
try
FStreamCS. Acquire;
FRscCompleted : = False ;
FRscSize : = - 1 ;
StatusBar1. Panels[ 0 ] . Text : = '' ;
StatusBar1. Panels[ 1 ] . Text : = '' ;
StatusBar1. Panels[ 2 ] . Text : = '' ;
Memo1. Lines. Clear;
FStream. Clear;
finally
FStreamCS. Release;
end ;
2018-02-03 17:52:48 +01:00
Chromium1. LoadURL( AddressEdt. Text ) ;
end ;
procedure TResponseFilterBrowserFrm. Timer1Timer( Sender: TObject) ;
begin
Timer1. Enabled : = False ;
if not( Chromium1. CreateBrowser( CEFWindowParent1) ) and not( Chromium1. Initialized) then
Timer1. Enabled : = True ;
end ;
procedure TResponseFilterBrowserFrm. WMMove( var aMessage : TWMMove) ;
begin
inherited ;
if ( Chromium1 < > nil ) then Chromium1. NotifyMoveOrResizeStarted;
end ;
procedure TResponseFilterBrowserFrm. WMMoving( var aMessage : TMessage) ;
begin
inherited ;
if ( Chromium1 < > nil ) then Chromium1. NotifyMoveOrResizeStarted;
end ;
procedure TResponseFilterBrowserFrm. WMEnterMenuLoop( var aMessage: TMessage) ;
begin
inherited ;
if ( aMessage. wParam = 0 ) and ( GlobalCEFApp < > nil ) then GlobalCEFApp. OsmodalLoop : = True ;
end ;
procedure TResponseFilterBrowserFrm. WMExitMenuLoop( var aMessage: TMessage) ;
begin
inherited ;
if ( aMessage. wParam = 0 ) and ( GlobalCEFApp < > nil ) then GlobalCEFApp. OsmodalLoop : = False ;
end ;
2018-05-24 19:15:41 +02:00
procedure TResponseFilterBrowserFrm. GetResponseEncoding( const aContentType: string ) ;
2018-05-24 17:40:49 +02:00
var
LEncoding: String ;
begin
{
( Name : 'Latin-US (DOS)' ; CodePage: 4 3 7 ) ,
( Name : 'Western (DOS Latin 1)' ; CodePage: 8 5 0 ) ,
( Name : 'Thai (Windows, DOS)' ; CodePage: 8 7 4 ) ,
( Name : 'Japanese (Windows, DOS)' ; CodePage: 9 3 2 ) ,
( Name : 'Simplified Chinese (Windows, DOS)' ; CodePage: 9 3 6 ) ,
( Name : 'Korean (Windows, DOS)' ; CodePage: 9 4 9 ) ,
( Name : 'Traditional Chinese (Windows, DOS)' ; CodePage: 9 5 0 ) ,
( Name : 'Unicode (UTF-16)' ; CodePage: 1 2 0 0 ) ,
( Name : 'Unicode (UTF-16LE)' ; CodePage: 1 2 0 0 ) ,
( Name : 'Unicode (UTF-16BE)' ; CodePage: 1 2 0 1 ) ,
( Name : 'Central European (Windows Latin 2)' ; CodePage: 1 2 5 0 ) ,
( Name : 'Cyrillic (Windows)' ; CodePage: 1 2 5 1 ) ,
( Name : 'Western (Windows Latin 1)' ; CodePage: 1 2 5 2 ) ,
( Name : 'Greek (Windows)' ; CodePage: 1 2 5 3 ) ,
( Name : 'Turkish (Windows Latin 5)' ; CodePage: 1 2 5 4 ) ,
( Name : 'Hebrew (Windows)' ; CodePage: 1 2 5 5 ) ,
( Name : 'Arabic (Windows)' ; CodePage: 1 2 5 6 ) ,
( Name : 'Baltic (Windows)' ; CodePage: 1 2 5 7 ) ,
( Name : 'Vietnamese (Windows)' ; CodePage: 1 2 5 8 ) ,
( Name : 'Western (ASCII)' ; CodePage: 2 0 1 2 7 ) ,
( Name : 'Unicode (UTF-7)' ; CodePage: CP_UTF7) ,
( Name : 'Unicode (UTF-8)' ; CodePage: CP_UTF8) ,
// Windows code pages...
( Name : 'Windows-1252' ; CodePage: 1 2 5 2 ) ,
( Name : 'US-ASCII' ; CodePage: 2 0 1 2 7 ) ,
( Name : 'UTF-7' ; CodePage: CP_UTF7) ,
( Name : 'UTF-8' ; CodePage: CP_UTF8) ,
( Name : 'UTF-16' ; CodePage: 1 2 0 0 ) ,
( Name : 'UTF-16BE' ; CodePage: 1 2 0 1 ) ,
( Name : 'UTF-16LE' ; CodePage: 1 2 0 0 ) ,
( Name : 'SHIFT-JIS' ; CodePage: 9 3 2 ) ,
( Name : 'ISO-8859-1' ; CodePage: 2 8 5 9 1 ) ,
( Name : 'iso-8859-1' ; CodePage: 2 8 5 9 1 ) ,
( Name : 'MACCROATIAN' ; CodePage: 1 0 0 8 2 ) ,
( Name : 'ASCII' ; CodePage: 2 0 1 2 7 ) ,
( Name : '' ; CodePage: 0 )
}
LEncoding : = Trim( Copy( UpperCase( aContentType) , Pos( 'CHARSET=' ,
UpperCase( aContentType) ) + Length( 'CHARSET=' ) , MaxInt) ) ;
if LEncoding = 'ANSI' then
begin
FRscEncoding : = TEncoding. ANSI;
end
else if LEncoding = 'ASCII' then
begin
FRscEncoding : = TEncoding. ASCII;
end
else if LEncoding = 'UTF-8' then
begin
FRscEncoding : = TEncoding. UTF8;
end
else if LEncoding = 'UTF-7' then
begin
FRscEncoding : = TEncoding. UTF7;
end
else if LEncoding = 'UTF-16' then
begin
FRscEncoding : = TEncoding. Unicode;
end
else if LEncoding = 'UNICODEFFFE' then
begin
FRscEncoding : = TEncoding. GetEncoding( 1 2 0 1 ) ;
end
else if LEncoding = 'UNICODE' then
begin
FRscEncoding : = TEncoding. Unicode;
end
else if LEncoding = 'GB2312' then
begin
FRscEncoding : = TEncoding. GetEncoding( 9 3 6 ) ;
end
else if LEncoding = 'GBK' then
begin
FRscEncoding : = TEncoding. GetEncoding( 9 3 6 ) ;
end
else if LEncoding = 'GB18030' then
begin
FRscEncoding : = TEncoding. GetEncoding( 5 4 9 3 6 ) ;
end
else if LEncoding = 'ISO-8859-1' then
begin
FRscEncoding : = TEncoding. GetEncoding( 2 8 5 9 1 ) ;
end
else if LEncoding = 'BIG5' then
begin
FRscEncoding : = TEncoding. GetEncoding( 9 5 0 ) ;
end
else
begin
FRscEncoding : = TEncoding. Default ;
end ;
end ;
2018-02-03 17:52:48 +01:00
end .