Added the ability to setup the Profile Directory and Cache Directory via OnDirectoryService.
Small changes in initialization sequence. Added a designtime logo to the Gecko window. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1389 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
0d9579aebb
commit
8f75063a47
@ -34,10 +34,22 @@
|
|||||||
* ***** END LICENSE BLOCK ***** *)
|
* ***** END LICENSE BLOCK ***** *)
|
||||||
unit CallbackInterfaces;
|
unit CallbackInterfaces;
|
||||||
|
|
||||||
|
{$MACRO on}
|
||||||
|
|
||||||
|
{$IFDEF Windows}
|
||||||
|
{$DEFINE extdecl:=stdcall}
|
||||||
|
{$ELSE Windows}
|
||||||
|
{$DEFINE extdecl:=cdecl}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFNDEF FPC_HAS_CONSTREF}
|
||||||
|
{$DEFINE constref:=const}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
nsXPCOM, nsTypes;
|
nsXPCOM, nsTypes,nsInit, nsGeckoStrings;
|
||||||
|
|
||||||
type
|
type
|
||||||
IGeckoCreateWindowTarget = interface
|
IGeckoCreateWindowTarget = interface
|
||||||
@ -51,6 +63,26 @@ type
|
|||||||
function GetCreateWindowTarget: IGeckoCreateWindowTarget;
|
function GetCreateWindowTarget: IGeckoCreateWindowTarget;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ nsMyDirectoryServiceProvider }
|
||||||
|
|
||||||
|
{ IDirectoryServiceProvider }
|
||||||
|
|
||||||
|
IDirectoryServiceProvider = class(TInterfacedObject,
|
||||||
|
nsIDirectoryServiceProvider)
|
||||||
|
private
|
||||||
|
FCacheParentDir: UTF8String;
|
||||||
|
FProfileDir: UTF8String;
|
||||||
|
procedure SetCacheDir(const AValue: UTF8String);
|
||||||
|
procedure SetProfileDir(const AValue: UTF8String);
|
||||||
|
public
|
||||||
|
function GetFile(const prop: PAnsiChar; out persistent: PRBool): nsIFile; safecall;
|
||||||
|
property CacheParentDir: UTF8String read FCacheParentDir write SetCacheDir;
|
||||||
|
property ProfileDir: UTF8String read FProfileDir write SetProfileDir;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
GeckoEngineDirectoryService: IDirectoryServiceProvider;
|
||||||
|
|
||||||
function InitWindowCreator: Boolean;
|
function InitWindowCreator: Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -149,4 +181,43 @@ begin
|
|||||||
Result := HRESULT(NS_ERROR_FAILURE);
|
Result := HRESULT(NS_ERROR_FAILURE);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ IDirectoryServiceProvider }
|
||||||
|
|
||||||
|
procedure IDirectoryServiceProvider.SetCacheDir(const AValue: UTF8String);
|
||||||
|
begin
|
||||||
|
if FCacheParentDir=AValue then exit;
|
||||||
|
FCacheParentDir:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure IDirectoryServiceProvider.SetProfileDir(const AValue: UTF8String);
|
||||||
|
begin
|
||||||
|
if FProfileDir=AValue then exit;
|
||||||
|
FProfileDir:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function IDirectoryServiceProvider.GetFile(const prop: PAnsiChar; out
|
||||||
|
persistent: PRBool): nsIFile; safecall;
|
||||||
|
var
|
||||||
|
Local: nsILocalFile;
|
||||||
|
begin
|
||||||
|
persistent:=true; //Only ask one time for each directory, it will be remembered
|
||||||
|
//by the Gecko engine while running.
|
||||||
|
if prop = 'ProfD' then //Profile directory
|
||||||
|
begin
|
||||||
|
if FProfileDir<>'' then
|
||||||
|
begin
|
||||||
|
NS_NewLocalFile(NewString(FProfileDir).AString,false,Local);
|
||||||
|
Local.QueryInterface(nsILocalFile,Result);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
if prop = 'cachePDir' then //Cache directory
|
||||||
|
begin
|
||||||
|
if FCacheParentDir<>'' then
|
||||||
|
begin
|
||||||
|
NS_NewLocalFile(NewString(FCacheParentDir).AString,false,Local);
|
||||||
|
Local.QueryInterface(nsILocalFile,Result);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -53,7 +53,7 @@ unit GeckoBrowser;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFNDEF LCL} Windows, Messages, {$ELSE} LclIntf, LMessages, LclType, LResources, {$ENDIF}
|
LclIntf, LMessages, LclType, LResources, Graphics,
|
||||||
SysUtils, Classes, Controls, nsXPCOM,
|
SysUtils, Classes, Controls, nsXPCOM,
|
||||||
nsGeckoStrings, CallbackInterfaces, nsTypes, nsXPCOMGlue, BrowserSupports,
|
nsGeckoStrings, CallbackInterfaces, nsTypes, nsXPCOMGlue, BrowserSupports,
|
||||||
nsXPCOM_std19
|
nsXPCOM_std19
|
||||||
@ -140,6 +140,7 @@ type
|
|||||||
TGeckoBrowserDOMEventHandler = procedure (Sender: TObject; aEvent:TGeckoDOMEvent) of object;
|
TGeckoBrowserDOMEventHandler = procedure (Sender: TObject; aEvent:TGeckoDOMEvent) of object;
|
||||||
TGeckoBrowserHistoryMove = procedure (Sender: TObject; aURI: nsIURI; out aContinue: LongBool; var Handled: Boolean) of object;
|
TGeckoBrowserHistoryMove = procedure (Sender: TObject; aURI: nsIURI; out aContinue: LongBool; var Handled: Boolean) of object;
|
||||||
TGeckoBrowserHistoryGoTo = procedure (Sender: TObject; aIndex: Longint; aURI: nsIURI; out aContinue: LongBool; var Handled: Boolean) of object;
|
TGeckoBrowserHistoryGoTo = procedure (Sender: TObject; aIndex: Longint; aURI: nsIURI; out aContinue: LongBool; var Handled: Boolean) of object;
|
||||||
|
TGeckoBrowserDirectoryService = procedure (Sender: TObject; const aDirectoryService: IDirectoryServiceProvider) of object;
|
||||||
|
|
||||||
TGeckoBrowserHisoty = record
|
TGeckoBrowserHisoty = record
|
||||||
URI: AnsiString;
|
URI: AnsiString;
|
||||||
@ -147,7 +148,6 @@ type
|
|||||||
IsSubFrame: Boolean;
|
IsSubFrame: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
//TODO 2 -cTCustomGeckoBrowser: DocShell ƒvƒƒpƒeƒB‚ð’ljÁ
|
//TODO 2 -cTCustomGeckoBrowser: DocShell ƒvƒƒpƒeƒB‚ð’ljÁ
|
||||||
|
|
||||||
{ TCustomGeckoBrowser }
|
{ TCustomGeckoBrowser }
|
||||||
@ -178,6 +178,7 @@ type
|
|||||||
FOnNewWindow: TGeckoBrowserNewWindow;
|
FOnNewWindow: TGeckoBrowserNewWindow;
|
||||||
|
|
||||||
FOnSetupProperties: TNotifyEvent;
|
FOnSetupProperties: TNotifyEvent;
|
||||||
|
FOnDirectoryService: TGeckoBrowserDirectoryService;
|
||||||
|
|
||||||
FGeckoComponentsStartupSucceeded: boolean;
|
FGeckoComponentsStartupSucceeded: boolean;
|
||||||
|
|
||||||
@ -186,6 +187,9 @@ type
|
|||||||
FInitializationStarted: Boolean;
|
FInitializationStarted: Boolean;
|
||||||
FInitialized: Boolean;
|
FInitialized: Boolean;
|
||||||
|
|
||||||
|
//Designtime graphic
|
||||||
|
FDesignTimeLogo: TPortableNetworkGraphic;
|
||||||
|
|
||||||
function GetDisableJavaScript: Boolean;
|
function GetDisableJavaScript: Boolean;
|
||||||
procedure SetDisableJavascript(const AValue: Boolean);
|
procedure SetDisableJavascript(const AValue: Boolean);
|
||||||
procedure ShutdownWebBrowser;
|
procedure ShutdownWebBrowser;
|
||||||
@ -301,9 +305,13 @@ type
|
|||||||
property OnNewWindow: TGeckoBrowserNewWindow
|
property OnNewWindow: TGeckoBrowserNewWindow
|
||||||
read FOnNewWindow write FOnNewWindow;
|
read FOnNewWindow write FOnNewWindow;
|
||||||
|
|
||||||
property OnSetupProperties: TNotifyEvent read FOnSetupProperties write FOnSetupProperties;
|
property OnSetupProperties: TNotifyEvent
|
||||||
|
read FOnSetupProperties write FOnSetupProperties;
|
||||||
|
property OnDirectoryService: TGeckoBrowserDirectoryService
|
||||||
|
read FOnDirectoryService write FOnDirectoryService;
|
||||||
// misc base settings
|
// misc base settings
|
||||||
property DisableJavaScript: Boolean read GetDisableJavaScript write SetDisableJavascript;
|
property DisableJavaScript: Boolean
|
||||||
|
read GetDisableJavaScript write SetDisableJavascript;
|
||||||
property Initialized: Boolean read FInitialized;
|
property Initialized: Boolean read FInitialized;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -373,6 +381,8 @@ type
|
|||||||
function SafeCallException(Obj: TObject; Addr: Pointer): HRESULT; override;
|
function SafeCallException(Obj: TObject; Addr: Pointer): HRESULT; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TGeckoBrowser }
|
||||||
|
|
||||||
TGeckoBrowser = class(TCustomGeckoBrowser)
|
TGeckoBrowser = class(TCustomGeckoBrowser)
|
||||||
protected
|
protected
|
||||||
FBrowser: nsIWebBrowser;
|
FBrowser: nsIWebBrowser;
|
||||||
@ -406,7 +416,7 @@ type
|
|||||||
function DoCreateChromeWindow(
|
function DoCreateChromeWindow(
|
||||||
chromeFlags: Longword): nsIWebBrowserChrome; override;
|
chromeFlags: Longword): nsIWebBrowserChrome; override;
|
||||||
|
|
||||||
function GetURIString(): UTF8String;
|
function GetURIString: UTF8String;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
|
||||||
@ -480,6 +490,7 @@ type
|
|||||||
property OnGoToIndex;
|
property OnGoToIndex;
|
||||||
|
|
||||||
property OnSetupProperties;
|
property OnSetupProperties;
|
||||||
|
property OnDirectoryService;
|
||||||
|
|
||||||
property DisableJavaScript;
|
property DisableJavaScript;
|
||||||
|
|
||||||
@ -680,6 +691,8 @@ procedure Register;
|
|||||||
|
|
||||||
{$IFNDEF LCL}
|
{$IFNDEF LCL}
|
||||||
{$R *.dcr}
|
{$R *.dcr}
|
||||||
|
{$ELSE}
|
||||||
|
{$R geckoresources.rc}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -1011,6 +1024,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCustomGeckoBrowser.Create(AOwner: TComponent);
|
constructor TCustomGeckoBrowser.Create(AOwner: TComponent);
|
||||||
|
var
|
||||||
|
Logo: TResourceStream;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
@ -1019,8 +1034,11 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if not (csDesigning in ComponentState) then
|
if not (csDesigning in ComponentState) then
|
||||||
begin
|
begin
|
||||||
GeckoComponentsStartup;
|
end else begin
|
||||||
FGeckoComponentsStartupSucceeded := true;
|
Logo:=TResourceStream.Create(HINSTANCE,'ID_GECKO_LOGO',pchar(RT_RCDATA));
|
||||||
|
FDesignTimeLogo:=TPortableNetworkGraphic.Create;
|
||||||
|
FDesignTimeLogo.LoadFromStream(Logo);
|
||||||
|
Logo.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1031,6 +1049,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if not (csDesigning in ComponentState) then
|
if not (csDesigning in ComponentState) then
|
||||||
begin
|
begin
|
||||||
|
FreeAndNil(FDesignTimeLogo);
|
||||||
ShutdownWebBrowser;
|
ShutdownWebBrowser;
|
||||||
|
|
||||||
Chrome := nil;
|
Chrome := nil;
|
||||||
@ -1059,6 +1078,22 @@ end;
|
|||||||
|
|
||||||
procedure TCustomGeckoBrowser.Loaded;
|
procedure TCustomGeckoBrowser.Loaded;
|
||||||
begin
|
begin
|
||||||
|
if not (csDesigning in ComponentState) then
|
||||||
|
begin
|
||||||
|
if not Assigned(GeckoEngineDirectoryService) then begin
|
||||||
|
//This interface must be created as soon as possible because it
|
||||||
|
//will be callbacked when starting the XRE which happend just
|
||||||
|
//after the GeckoBrowser is created but before it is ready to be
|
||||||
|
//used. The setup of this component is a one time operation, called
|
||||||
|
//by the FIRST instance of GeckoBrowser and not called by the next
|
||||||
|
//ones; and its data persists while the program is running.
|
||||||
|
GeckoEngineDirectoryService:=IDirectoryServiceProvider.Create;
|
||||||
|
end;
|
||||||
|
if Assigned(FOnDirectoryService) then
|
||||||
|
FOnDirectoryService(Self,GeckoEngineDirectoryService);
|
||||||
|
GeckoComponentsStartup;
|
||||||
|
FGeckoComponentsStartupSucceeded := true;
|
||||||
|
end;
|
||||||
inherited Loaded;
|
inherited Loaded;
|
||||||
DoInitializationIfNeeded;
|
DoInitializationIfNeeded;
|
||||||
end;
|
end;
|
||||||
@ -1823,7 +1858,10 @@ begin
|
|||||||
if csDesigning in ComponentState then
|
if csDesigning in ComponentState then
|
||||||
begin
|
begin
|
||||||
rc := ClientRect;
|
rc := ClientRect;
|
||||||
Canvas.FillRect(rc);
|
if Assigned(FDesignTimeLogo) then
|
||||||
|
Canvas.StretchDraw(rc,FDesignTimeLogo)
|
||||||
|
else
|
||||||
|
Canvas.FillRect(rc);
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
baseWin := FWebBrowser as nsIBaseWindow;
|
baseWin := FWebBrowser as nsIBaseWindow;
|
||||||
|
BIN
components/geckoport/Components/gecko-logo.png
Normal file
BIN
components/geckoport/Components/gecko-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
1
components/geckoport/Components/geckoresources.rc
Normal file
1
components/geckoport/Components/geckoresources.rc
Normal file
@ -0,0 +1 @@
|
|||||||
|
ID_GECKO_LOGO RCDATA gecko-logo.png
|
@ -3,7 +3,7 @@ unit nsXRE;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
nsTypes, nsXPCOM, nsInit;
|
nsTypes, nsXPCOM, nsInit, CallbackInterfaces;
|
||||||
|
|
||||||
type
|
type
|
||||||
PXREAppData = ^nsXREAppData;
|
PXREAppData = ^nsXREAppData;
|
||||||
@ -406,8 +406,10 @@ begin
|
|||||||
XRE_UnloadGRE();
|
XRE_UnloadGRE();
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
if not Assigned(GeckoEngineDirectoryService) then
|
||||||
|
GeckoEngineDirectoryService:=IDirectoryServiceProvider.Create;
|
||||||
// NS_LogInit();
|
// NS_LogInit();
|
||||||
Result := XRE_InitEmbedding(xulDir, appDir, nil, nil, 0);
|
Result := XRE_InitEmbedding(xulDir, appDir, GeckoEngineDirectoryService, nil, 0);
|
||||||
// NS_LogTerm();
|
// NS_LogTerm();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user