Block all popup windows and new tabs in all demos except the MiniBrowser

- Added TChromium.IsSameBrowser function
This commit is contained in:
Salvador Díaz Fau 2018-02-16 18:41:13 +01:00
parent 1cbe18947e
commit 6905f9a292
64 changed files with 880 additions and 205 deletions

View File

@ -68,6 +68,7 @@ object CookieVisitorFrm: TCookieVisitorFrm
OnCookiesDeleted = Chromium1CookiesDeleted
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -81,6 +81,13 @@ type
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -196,6 +203,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_GETCOOKIES, 'Visit cookies');
end;
procedure TCookieVisitorFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TCookieVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -49,7 +49,8 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFInterfaces, uCustomResourceHandler, uCEFConstants;
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFInterfaces, uCustomResourceHandler,
uCEFConstants, uCEFTypes;
type
TMainForm = class(TForm)
@ -72,6 +73,7 @@ type
protected
procedure Chromium_OnAfterCreated(Sender: TObject);
procedure Chromium_OnGetResourceHandler(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
public
{ Public declarations }
@ -96,6 +98,7 @@ procedure TMainForm.FormShow(Sender: TObject);
begin
ChromiumWindow1.OnAfterCreated := Chromium_OnAfterCreated;
ChromiumWindow1.ChromiumBrowser.OnGetResourceHandler := Chromium_OnGetResourceHandler;
ChromiumWindow1.ChromiumBrowser.OnBeforePopup := Chromium_OnBeforePopup;
// 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.
@ -140,6 +143,18 @@ begin
end;
end;
procedure TMainForm.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TMainForm.WMMove(var aMessage : TWMMove);
begin
inherited;

View File

@ -94,6 +94,7 @@ object DOMVisitorFrm: TDOMVisitorFrm
OnProcessMessageReceived = Chromium1ProcessMessageReceived
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 16
Top = 40

View File

@ -87,6 +87,13 @@ type
const message: ICefProcessMessage; out Result: Boolean);
procedure Timer1Timer(Sender: TObject);
procedure VisitDOMBtnClick(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
{ Private declarations }
protected
@ -253,6 +260,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM, 'Visit DOM in CEF');
end;
procedure TDOMVisitorFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TDOMVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -93,6 +93,7 @@ object ExternalPumpBrowserFrm: TExternalPumpBrowserFrm
Top = 88
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close

View File

@ -70,6 +70,13 @@ type
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
procedure Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
FCanClose : boolean;
@ -144,6 +151,18 @@ begin
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TExternalPumpBrowserFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TExternalPumpBrowserFrm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
PostMessage(Handle, CEF_DESTROY, 0, 0);

View File

@ -106,6 +106,7 @@ object FMXExternalPumpBrowserFrm: TFMXExternalPumpBrowserFrm
end
object chrmosr: TFMXChromium
OnTooltip = chrmosrTooltip
OnBeforePopup = chrmosrBeforePopup
OnAfterCreated = chrmosrAfterCreated
OnBeforeClose = chrmosrBeforeClose
OnClose = chrmosrClose

View File

@ -104,6 +104,13 @@ type
procedure SnapshotBtnEnter(Sender: TObject);
procedure chrmosrTooltip(Sender: TObject; const browser: ICefBrowser;
var text: ustring; out Result: Boolean);
procedure chrmosrBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FPopUpBitmap : TBitmap;
@ -449,6 +456,24 @@ begin
SendCompMessage(WM_CLOSE);
end;
procedure TFMXExternalPumpBrowserFrm.chrmosrBeforePopup(Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
const targetFrameName : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
var popupFeatures : TCefPopupFeatures;
var windowInfo : TCefWindowInfo;
var client : ICefClient;
var settings : TCefBrowserSettings;
var noJavascriptAccess : Boolean;
out Result : Boolean);
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;
procedure TFMXExternalPumpBrowserFrm.chrmosrClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
Result := False;

View File

@ -29,6 +29,7 @@ object MainForm: TMainForm
object Chromium1: TChromium
OnPreKeyEvent = Chromium1PreKeyEvent
OnKeyEvent = Chromium1KeyEvent
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 208
Top = 120

View File

@ -66,6 +66,13 @@ type
procedure Chromium1AfterCreated(Sender: TObject;
const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
{ Private declarations }
protected
@ -134,6 +141,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TMainForm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TMainForm.BrowserCreatedMsg(var aMessage : TMessage);
begin
CEFWindowParent1.UpdateSize;

View File

@ -78,6 +78,7 @@ object GeolocationFrm: TGeolocationFrm
end>
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -69,6 +69,13 @@ type
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure NewLocationMsg(var aMessage : TMessage); message MINIBROWSER_NEWLOCATION;
@ -110,6 +117,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TGeolocationFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TGeolocationFrm.FormCreate(Sender: TObject);
begin
CefGetGeolocation(GeoLocationUpdate);

View File

@ -77,7 +77,8 @@ type
FDialogType : TCefJsDialogType;
FCallback : ICefJsDialogCallback;
procedure ChromiumBrowser_OnJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean; out Result: Boolean);
procedure Chromium_OnJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean; out Result: Boolean);
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
@ -118,7 +119,8 @@ end;
procedure TJSDialogBrowserFrm.FormShow(Sender: TObject);
begin
ChromiumWindow1.ChromiumBrowser.OnJsdialog := ChromiumBrowser_OnJsdialog;
ChromiumWindow1.ChromiumBrowser.OnJsdialog := Chromium_OnJsdialog;
ChromiumWindow1.ChromiumBrowser.OnBeforePopup := Chromium_OnBeforePopup;
// 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.
@ -172,15 +174,15 @@ begin
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
end;
procedure TJSDialogBrowserFrm.ChromiumBrowser_OnJsdialog(Sender : TObject;
const browser : ICefBrowser;
const originUrl : ustring;
dialogType : TCefJsDialogType;
const messageText : ustring;
const defaultPromptText : ustring;
const callback : ICefJsDialogCallback;
out suppressMessage : Boolean;
out Result : Boolean);
procedure TJSDialogBrowserFrm.Chromium_OnJsdialog(Sender : TObject;
const browser : ICefBrowser;
const originUrl : ustring;
dialogType : TCefJsDialogType;
const messageText : ustring;
const defaultPromptText : ustring;
const callback : ICefJsDialogCallback;
out suppressMessage : Boolean;
out Result : Boolean);
begin
// In this event we must store the dialog information and post a message to the main form to show the dialog
FJSDialogInfoCS.Acquire;
@ -207,6 +209,18 @@ begin
FJSDialogInfoCS.Release;
end;
procedure TJSDialogBrowserFrm.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSDialogBrowserFrm.ShowJSDialogMsg(var aMessage: TMessage);
var
TempCaption : string;

View File

@ -65,6 +65,7 @@ object JSEvalFrm: TJSEvalFrm
OnProcessMessageReceived = Chromium1ProcessMessageReceived
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 16
Top = 40

View File

@ -86,6 +86,13 @@ type
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
{ Private declarations }
@ -175,6 +182,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_JSBINPARAM, 'Send JPEG image...');
end;
procedure TJSEvalFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSEvalFrm.Chromium1ContextMenuCommand(Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;

View File

@ -63,6 +63,7 @@ object JSExecutingFunctionsFrm: TJSExecutingFunctionsFrm
object Chromium1: TChromium
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -76,6 +76,13 @@ type
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -164,6 +171,18 @@ begin
model.AddItem(JSDEMO_CONTEXTMENU_EXECFUNCTION, 'Execute registered JS function');
end;
procedure TJSExecutingFunctionsFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSExecutingFunctionsFrm.Chromium1ContextMenuCommand(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -74,6 +74,7 @@ object JSExtensionFrm: TJSExtensionFrm
OnProcessMessageReceived = Chromium1ProcessMessageReceived
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -83,6 +83,13 @@ type
const message: ICefProcessMessage; out Result: Boolean);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FText : string;
@ -174,6 +181,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_JSVISITDOM, 'Visit DOM in JavaScript');
end;
procedure TJSExtensionFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSExtensionFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -61,6 +61,7 @@ object JSExtensionWithFunctionFrm: TJSExtensionWithFunctionFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -63,6 +63,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -124,6 +131,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSExtensionWithFunctionFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSExtensionWithFunctionFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -61,6 +61,7 @@ object JSExtensionWithObjectParameterFrm: TJSExtensionWithObjectParameterFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -63,6 +63,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -131,6 +138,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSExtensionWithObjectParameterFrm.Chromium1BeforePopup(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
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;
procedure TJSExtensionWithObjectParameterFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -74,6 +74,7 @@ object JSRTTIExtensionFrm: TJSRTTIExtensionFrm
OnProcessMessageReceived = Chromium1ProcessMessageReceived
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -83,6 +83,13 @@ type
const message: ICefProcessMessage; out Result: Boolean);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FText : string;
@ -153,6 +160,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_JSVISITDOM, 'Visit DOM in JavaScript');
end;
procedure TJSRTTIExtensionFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSRTTIExtensionFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -61,6 +61,7 @@ object JSSimpleExtensionFrm: TJSSimpleExtensionFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -63,6 +63,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -118,6 +125,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSSimpleExtensionFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSSimpleExtensionFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -61,6 +61,7 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -64,6 +64,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -111,6 +118,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSSimpleWindowBindingFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSSimpleWindowBindingFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -61,6 +61,7 @@ object JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -64,6 +64,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -97,6 +104,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSSimpleWindowBindingFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TJSSimpleWindowBindingFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -61,6 +61,7 @@ object JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -63,6 +63,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -115,6 +122,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSWindowBindingWithFunctionFrm.Chromium1BeforePopup(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
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;
procedure TJSWindowBindingWithFunctionFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -61,6 +61,7 @@ object JSWindowBindingWithObjectFrm: TJSWindowBindingWithObjectFrm
TabOrder = 1
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -63,6 +63,13 @@ type
procedure GoBtnClick(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -116,6 +123,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TJSWindowBindingWithObjectFrm.Chromium1BeforePopup(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
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;
procedure TJSWindowBindingWithObjectFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -78,6 +78,7 @@ object ChildForm: TChildForm
object Chromium1: TChromium
OnLoadingStateChange = Chromium1LoadingStateChange
OnStatusMessage = Chromium1StatusMessage
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close

View File

@ -76,6 +76,13 @@ type
canGoForward: Boolean);
procedure Chromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
// Variables to control when can we destroy the form safely
@ -123,6 +130,18 @@ begin
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TChildForm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TChildForm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
PostMessage(Handle, CEFBROWSER_DESTROY, 0, 0);

View File

@ -78,6 +78,7 @@ object ChildForm: TChildForm
object Chromium1: TChromium
OnLoadingStateChange = Chromium1LoadingStateChange
OnStatusMessage = Chromium1StatusMessage
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close

View File

@ -76,6 +76,13 @@ type
canGoForward: Boolean);
procedure Chromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
// Variables to control when can we destroy the form safely
@ -123,6 +130,18 @@ begin
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TChildForm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TChildForm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
PostMessage(Handle, CEFBROWSER_DESTROY, 0, 0);

View File

@ -268,18 +268,21 @@ end;
procedure TMiniBrowserFrm.Chromium1AddressChange(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
begin
AddURL(url);
if Chromium1.IsSameBrowser(browser) then AddURL(url);
end;
procedure TMiniBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
if Chromium1.IsSameBrowser(browser) then
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TMiniBrowserFrm.Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
if not(Chromium1.IsSameBrowser(browser)) then exit;
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_TAKESNAPSHOT, 'Take snapshot...');
model.AddSeparator;
@ -331,7 +334,10 @@ procedure TMiniBrowserFrm.Chromium1BeforeDownload(Sender: TObject;
var
TempMyDocuments, TempFullPath, TempName : string;
begin
if (downloadItem = nil) or not(downloadItem.IsValid) then exit;
if not(Chromium1.IsSameBrowser(browser)) or
(downloadItem = nil) or
not(downloadItem.IsValid) then
exit;
TempMyDocuments := PathToMyDocuments;
@ -355,7 +361,9 @@ procedure TMiniBrowserFrm.Chromium1BeforeResourceLoad(Sender: TObject;
begin
Result := RV_CONTINUE;
if (frame <> nil) and frame.IsMain then
if Chromium1.IsSameBrowser(browser) and
(frame <> nil) and
frame.IsMain then
InspectRequest(request);
end;
@ -368,6 +376,8 @@ var
begin
Result := False;
if not(Chromium1.IsSameBrowser(browser)) then exit;
case commandId of
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS :
PostMessage(Handle, MINIBROWSER_HIDEDEVTOOLS, 0, 0);
@ -421,6 +431,8 @@ procedure TMiniBrowserFrm.Chromium1DownloadUpdated(Sender: TObject;
var
TempString : string;
begin
if not(Chromium1.IsSameBrowser(browser)) then exit;
if downloadItem.IsComplete then
ShowStatusText(downloadItem.FullPath + ' completed')
else
@ -441,6 +453,8 @@ end;
procedure TMiniBrowserFrm.Chromium1FullScreenModeChange(Sender: TObject;
const browser: ICefBrowser; fullscreen: Boolean);
begin
if not(Chromium1.IsSameBrowser(browser)) then exit;
if fullscreen then
begin
NavControlPnl.Visible := False;
@ -471,6 +485,8 @@ var
begin
Result := False;
if not(Chromium1.IsSameBrowser(browser)) then exit;
if (event <> nil) and (osEvent <> nil) then
case osEvent.Message of
WM_KEYUP :
@ -535,6 +551,8 @@ end;
procedure TMiniBrowserFrm.Chromium1LoadingStateChange(Sender: TObject;
const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
begin
if not(Chromium1.IsSameBrowser(browser)) then exit;
BackBtn.Enabled := canGoBack;
ForwardBtn.Enabled := canGoForward;
@ -574,7 +592,8 @@ procedure TMiniBrowserFrm.Chromium1PreKeyEvent(Sender: TObject;
begin
Result := False;
if (event <> nil) and
if Chromium1.IsSameBrowser(browser) and
(event <> nil) and
(event.kind in [KEYEVENT_KEYDOWN, KEYEVENT_KEYUP]) and
(event.windows_key_code = VK_F12) then
isKeyboardShortcut := True;
@ -643,7 +662,9 @@ procedure TMiniBrowserFrm.Chromium1ResourceResponse(Sender: TObject;
begin
Result := False;
if (frame <> nil) and frame.IsMain then
if Chromium1.IsSameBrowser(browser) and
(frame <> nil) and
frame.IsMain then
InspectResponse(response);
end;
@ -660,7 +681,7 @@ end;
procedure TMiniBrowserFrm.Chromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
begin
ShowStatusText(value);
if Chromium1.IsSameBrowser(browser) then ShowStatusText(value);
end;
procedure TMiniBrowserFrm.Chromium1TextResultAvailable(Sender: TObject; const aText: string);
@ -671,6 +692,8 @@ end;
procedure TMiniBrowserFrm.Chromium1TitleChange(Sender: TObject;
const browser: ICefBrowser; const title: ustring);
begin
if not(Chromium1.IsSameBrowser(browser)) then exit;
if (title <> '') then
caption := 'MiniBrowser - ' + title
else

View File

@ -122,6 +122,7 @@ object OSRExternalPumpBrowserFrm: TOSRExternalPumpBrowserFrm
OnMouseLeave = Panel1MouseLeave
end
object chrmosr: TChromium
OnBeforePopup = chrmosrBeforePopup
OnAfterCreated = chrmosrAfterCreated
OnBeforeClose = chrmosrBeforeClose
OnClose = chrmosrClose

View File

@ -102,6 +102,13 @@ type
procedure Timer1Timer(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
procedure chrmosrBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FPopUpBitmap : TBitmap;
@ -302,6 +309,18 @@ begin
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TOSRExternalPumpBrowserFrm.chrmosrBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TOSRExternalPumpBrowserFrm.chrmosrClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
Result := False;

View File

@ -74,6 +74,7 @@ object PostDataInspectorFrm: TPostDataInspectorFrm
end
object Chromium1: TChromium
OnProcessMessageReceived = Chromium1ProcessMessageReceived
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 32
Top = 224

View File

@ -71,6 +71,13 @@ type
procedure Chromium1AfterCreated(Sender: TObject;
const browser: ICefBrowser);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
@ -138,6 +145,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TPostDataInspectorFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TPostDataInspectorFrm.Chromium1ProcessMessageReceived(
Sender: TObject; const browser: ICefBrowser;
sourceProcess: TCefProcessId; const message: ICefProcessMessage;

View File

@ -118,6 +118,7 @@ object ResponseFilterBrowserFrm: TResponseFilterBrowserFrm
Top = 88
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnGetResourceResponseFilter = Chromium1GetResourceResponseFilter
OnResourceLoadComplete = Chromium1ResourceLoadComplete

View File

@ -75,6 +75,13 @@ type
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FFilter : ICefResponseFilter; // CEF Filter interface that receives the resource contents
FStream : TMemoryStream; // TMemoryStream to hold the resource contents
@ -218,6 +225,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TResponseFilterBrowserFrm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter(Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;

View File

@ -68,6 +68,7 @@ object SchemeRegistrationBrowserFrm: TSchemeRegistrationBrowserFrm
object Chromium1: TChromium
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 16
Top = 40

View File

@ -78,6 +78,13 @@ type
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
{ Private declarations }
protected
@ -120,6 +127,18 @@ begin
model.AddItem(MINIBROWSER_CONTEXTMENU_CLEARFACT, 'Clear schemes');
end;
procedure TSchemeRegistrationBrowserFrm.Chromium1BeforePopup(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
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;
procedure TSchemeRegistrationBrowserFrm.Chromium1ContextMenuCommand(
Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;

View File

@ -49,7 +49,7 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow;
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces;
type
TForm1 = class(TForm)
@ -69,6 +69,10 @@ type
// You also have to handle these two messages to set GlobalCEFApp.OsmodalLoop
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
protected
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
public
{ Public declarations }
end;
@ -97,6 +101,9 @@ uses
procedure TForm1.FormShow(Sender: TObject);
begin
// For simplicity, this demo blocks all popup windows and new tabs
ChromiumWindow1.ChromiumBrowser.OnBeforePopup := Chromium_OnBeforePopup;
// You *MUST* call CreateBrowser to create and initialize the browser.
// This will trigger the AfterCreated event when the browser is fully
// initialized and ready to receive commands.
@ -106,6 +113,18 @@ begin
if not(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True;
end;
procedure TForm1.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TForm1.ChromiumWindow1AfterCreated(Sender: TObject);
begin
// Now the browser is fully initialized we can load the initial web page.

View File

@ -59,10 +59,6 @@ object Form1: TForm1
Height = 594
Align = alClient
TabOrder = 1
ExplicitLeft = 320
ExplicitTop = 168
ExplicitWidth = 100
ExplicitHeight = 41
end
object Timer1: TTimer
Enabled = False
@ -72,8 +68,9 @@ object Form1: TForm1
Top = 88
end
object Chromium1: TChromium
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
Left = 464
Top = 360
Left = 56
Top = 152
end
end

View File

@ -49,7 +49,7 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants;
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants, uCEFTypes;
type
TForm1 = class(TForm)
@ -63,6 +63,13 @@ type
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
// You have to handle this two messages to call NotifyMoveOrResizeStarted or some page elements will be misaligned.
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -117,6 +124,18 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TForm1.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
begin
Caption := 'Simple Browser 2';

View File

@ -71,6 +71,7 @@ type
procedure ChromiumWindow1AfterCreated(Sender: TObject);
procedure ChromiumWindow1BeforeClose(Sender: TObject);
procedure ChromiumWindow1Close(Sender: TObject);
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FCanClose : boolean;
@ -129,11 +130,26 @@ end;
procedure TSimpleExternalPumpBrowserFrm.FormShow(Sender: TObject);
begin
// For simplicity, this demo blocks all popup windows and new tabs
ChromiumWindow1.ChromiumBrowser.OnBeforePopup := Chromium_OnBeforePopup;
// 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(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True;
end;
procedure TSimpleExternalPumpBrowserFrm.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TSimpleExternalPumpBrowserFrm.ChromiumWindow1AfterCreated(Sender: TObject);
begin
Caption := 'Simple External Pump Browser';

View File

@ -121,6 +121,7 @@ object Form1: TForm1
end
object chrmosr: TChromium
OnTooltip = chrmosrTooltip
OnBeforePopup = chrmosrBeforePopup
OnAfterCreated = chrmosrAfterCreated
OnGetViewRect = chrmosrGetViewRect
OnGetScreenPoint = chrmosrGetScreenPoint

View File

@ -99,6 +99,13 @@ type
procedure Timer1Timer(Sender: TObject);
procedure SnapshotBtnEnter(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
procedure chrmosrBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
protected
FPopUpBitmap : TBitmap;
@ -283,6 +290,24 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TForm1.chrmosrBeforePopup(Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
const targetFrameName : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
var popupFeatures : TCefPopupFeatures;
var windowInfo : TCefWindowInfo;
var client : ICefClient;
var settings : TCefBrowserSettings;
var noJavascriptAccess : Boolean;
out Result : Boolean);
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;
procedure TForm1.chrmosrCursorChange(Sender : TObject;
const browser : ICefBrowser;
cursor : HICON;

View File

@ -49,7 +49,7 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow;
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces;
type
TForm1 = class(TForm)
@ -66,9 +66,12 @@ type
// You have to handle this two messages to call NotifyMoveOrResizeStarted or some page elements will be misaligned.
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
// You also have to handle these two messages to set GlobalCEFApp.OsmodalLoop
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
// You also have to handle these two messages to set GlobalCEFApp.OsmodalLoop
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
protected
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
public
{ Public declarations }
end;
@ -79,8 +82,8 @@ var
implementation
{$R *.dfm}
uses
uses
uCEFApplication;
// This is a demo with the simplest web browser you can build using CEF4Delphi and
@ -89,31 +92,44 @@ uses
// Remember that it may take a few seconds to load if Windows update, your antivirus or
// any other windows service is using your hard drive.
// Depending on your internet connection it may take longer than expected.
// Please check that your firewall or antivirus are not blocking this application
// or the domain "google.com". If you don't live in the US, you'll be redirected to
// another domain which will take a little time too.
// Depending on your internet connection it may take longer than expected.
// Please check that your firewall or antivirus are not blocking this application
// or the domain "google.com". If you don't live in the US, you'll be redirected to
// another domain which will take a little time too.
procedure TForm1.FormShow(Sender: TObject);
begin
Caption := 'Simple Browser - Initializing browser. Please wait...';
// You *MUST* call CreateBrowser to create and initialize the browser.
// This will trigger the AfterCreated event when the browser is fully
// initialized and ready to receive commands.
// 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.
ChromiumWindow1.ChromiumBrowser.OnBeforePopup := Chromium_OnBeforePopup;
// You *MUST* call CreateBrowser to create and initialize the browser.
// This will trigger the AfterCreated event when the browser is fully
// initialized and ready to receive commands.
// 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(ChromiumWindow1.CreateBrowser) then Timer1.Enabled := True;
end;
procedure TForm1.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TForm1.ChromiumWindow1AfterCreated(Sender: TObject);
begin
// Now the browser is fully initialized we can load the initial web page.
Caption := 'Simple Browser';
AddressPnl.Enabled := True;
GoBtn.Click;
begin
// Now the browser is fully initialized we can load the initial web page.
Caption := 'Simple Browser';
AddressPnl.Enabled := True;
GoBtn.Click;
end;
procedure TForm1.GoBtnClick(Sender: TObject);
@ -123,10 +139,10 @@ begin
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
if not(ChromiumWindow1.CreateBrowser) and not(ChromiumWindow1.Initialized) then
Timer1.Enabled := True;
begin
Timer1.Enabled := False;
if not(ChromiumWindow1.CreateBrowser) and not(ChromiumWindow1.Initialized) then
Timer1.Enabled := True;
end;
procedure TForm1.WMMove(var aMessage : TWMMove);
@ -142,19 +158,19 @@ begin
if (ChromiumWindow1 <> nil) then ChromiumWindow1.NotifyMoveOrResizeStarted;
end;
procedure TForm1.WMEnterMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
end;
procedure TForm1.WMExitMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
procedure TForm1.WMEnterMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
end;
procedure TForm1.WMExitMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
end;
end.

View File

@ -90,6 +90,8 @@ type
procedure Chromium_OnTitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);
procedure Chromium_OnClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
procedure Chromium_OnBeforeClose(Sender: TObject; const browser: ICefBrowser);
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure BrowserDestroyWindowParentMsg(var aMessage : TMessage); message CEFBROWSER_DESTROYWNDPARENT;
@ -163,6 +165,7 @@ begin
TempChromium.OnTitleChange := Chromium_OnTitleChange;
TempChromium.OnClose := Chromium_OnClose;
TempChromium.OnBeforeClose := Chromium_OnBeforeClose;
TempChromium.OnBeforePopup := Chromium_OnBeforePopup;
TempChromium.CreateBrowser(TempWindowParent, '');
end;
@ -325,6 +328,18 @@ begin
PostMessage(Handle, CEFBROWSER_DESTROYTAB, 0, TempPageIndex);
end;
procedure TMainForm.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
function TMainForm.SearchChromium(aPageIndex : integer; var aChromium : TChromium) : boolean;
var
i, j : integer;

View File

@ -3,8 +3,8 @@ object ChildForm: TChildForm
Top = 0
BorderStyle = bsToolWindow
Caption = 'Browser'
ClientHeight = 300
ClientWidth = 400
ClientHeight = 394
ClientWidth = 602
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
@ -23,14 +23,17 @@ object ChildForm: TChildForm
object CEFWindowParent1: TCEFWindowParent
Left = 0
Top = 0
Width = 400
Height = 300
Width = 602
Height = 394
Align = alClient
TabOrder = 0
ExplicitWidth = 400
ExplicitHeight = 300
end
object Chromium1: TChromium
OnPreKeyEvent = Chromium1PreKeyEvent
OnKeyEvent = Chromium1KeyEvent
OnBeforePopup = Chromium1BeforePopup
OnAfterCreated = Chromium1AfterCreated
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close

View File

@ -73,6 +73,13 @@ type
out Result: Boolean);
procedure Chromium1BeforeClose(Sender: TObject;
const browser: ICefBrowser);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var noJavascriptAccess: Boolean; out Result: Boolean);
private
// Variables to control when can we destroy the form safely
@ -120,6 +127,18 @@ begin
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TChildForm.Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
out Result: Boolean);
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;
procedure TChildForm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
PostMessage(Handle, CEFBROWSER_DESTROY, 0, 0);

Binary file not shown.

View File

@ -256,8 +256,8 @@ type
procedure SetWindowlessFrameRate(aValue : integer);
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): Boolean;
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): ICefBrowser;
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): boolean;
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): Boolean;
procedure DestroyClientHandler;
@ -268,11 +268,11 @@ type
procedure GetPrintPDFSettings(var aSettings : TCefPdfPrintSettings; const aTitle, aURL : string);
function UpdateProxyPrefs : boolean;
function UpdatePreference(const aName : string; aValue : boolean) : boolean; overload;
function UpdatePreference(const aName : string; aValue : integer) : boolean; overload;
function UpdatePreference(const aName : string; const aValue : double) : boolean; overload;
function UpdatePreference(const aName, aValue : string) : boolean; overload;
function UpdateProxyPrefs(const aBrowser: ICefBrowser) : boolean;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : boolean) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : integer) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; const aValue : double) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName, aValue : string) : boolean; overload;
procedure HandleDictionary(const aDict : ICefDictionaryValue; var aResultSL : TStringList; const aRoot : string);
procedure HandleNull(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
@ -415,7 +415,8 @@ type
procedure doCookiesDeleted(numDeleted : integer); virtual;
procedure doPdfPrintFinished(aResultOK : boolean); virtual;
procedure doTextResultAvailable(const aText : string); virtual;
procedure doUpdatePreferences; virtual;
procedure doUpdatePreferences(const aBrowser: ICefBrowser); virtual;
procedure doUpdateOwnPreferences; virtual;
function doSavePreferences : boolean; virtual;
procedure doResolvedHostAvailable(result: TCefErrorCode; const resolvedIps: TStrings); virtual;
@ -433,8 +434,6 @@ type
procedure InitializeDragAndDrop(const aDropTargetCtrl : TWinControl);
procedure ShutdownDragAndDrop;
procedure LoadURL(const aURL : ustring);
procedure LoadString(const aString : ustring; const aURL : ustring = '');
procedure LoadRequest(const aRequest: ICefRequest);
@ -464,6 +463,7 @@ type
function SetNewBrowserParent(aNewParentHwnd : HWND) : boolean;
procedure ResolveHost(const aURL : ustring);
function TakeSnapshot(var aBitmap : TBitmap) : boolean;
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
procedure ShowDevTools(inspectElementAt: TPoint; const aDevTools : TWinControl);
procedure CloseDevTools(const aDevTools : TWinControl = nil);
@ -1037,19 +1037,10 @@ begin
end;
if MultithreadApp then
if GlobalCEFApp.MultiThreadedMessageLoop then
Result := CreateBrowserHost(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext)
else
begin
FBrowser := CreateBrowserHostSync(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext);
if (FBrowser <> nil) then
begin
FBrowserId := FBrowser.Identifier;
FInitialized := (FBrowserId <> 0);
Result := True;
end;
end;
Result := CreateBrowserHostSync(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext);
end;
except
on e : exception do
@ -1181,7 +1172,7 @@ end;
function TChromium.CreateBrowserHost(aWindowInfo : PCefWindowInfo;
const aURL : ustring;
const aSettings : PCefBrowserSettings;
const aContext : ICefRequestContext): Boolean;
const aContext : ICefRequestContext): boolean;
var
TempURL : TCefString;
begin
@ -1192,14 +1183,21 @@ end;
function TChromium.CreateBrowserHostSync(aWindowInfo : PCefWindowInfo;
const aURL : ustring;
const aSettings : PCefBrowserSettings;
const aContext : ICefRequestContext): ICefBrowser;
const aContext : ICefRequestContext): boolean;
var
TempURL : TCefString;
TempBrowser : PCefBrowser;
TempURL : TCefString;
begin
TempURL := CefString(aURL);
TempBrowser := cef_browser_host_create_browser_sync(aWindowInfo, FHandler.Wrap, @TempURL, aSettings, CefGetData(aContext));
Result := TCefBrowserRef.UnWrap(TempBrowser);
TempURL := CefString(aURL);
FBrowser := TCefBrowserRef.UnWrap(cef_browser_host_create_browser_sync(aWindowInfo, FHandler.Wrap, @TempURL, aSettings, CefGetData(aContext)));
if (FBrowser <> nil) then
begin
FBrowserId := FBrowser.Identifier;
FInitialized := (FBrowserId <> 0);
Result := FInitialized;
end
else
Result := False;
end;
procedure TChromium.Find(aIdentifier : integer; const aSearchText : ustring; aForward, aMatchCase, aFindNext : Boolean);
@ -1487,14 +1485,7 @@ end;
function TChromium.GetMultithreadApp : boolean;
begin
Result := True;
try
if (GlobalCEFApp <> nil) then Result := GlobalCEFApp.MultiThreadedMessageLoop;
except
on e : exception do
if CustomExceptionHandler('TChromium.GetMultithreadApp', e) then raise;
end;
Result := (GlobalCEFApp <> nil) and GlobalCEFApp.MultiThreadedMessageLoop;
end;
function TChromium.GetHasDocument : boolean;
@ -2073,6 +2064,11 @@ begin
end;
end;
function TChromium.IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
begin
Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser);
end;
procedure TChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer);
var
TempEvent : TCefMouseEvent;
@ -2086,34 +2082,39 @@ begin
end;
end;
procedure TChromium.doUpdatePreferences;
procedure TChromium.doUpdatePreferences(const aBrowser: ICefBrowser);
begin
FUpdatePreferences := False;
UpdateProxyPrefs;
UpdatePreference('enable_do_not_track', FDoNotTrack);
UpdatePreference('enable_referrers', FSendReferrer);
UpdatePreference('enable_a_ping', FHyperlinkAuditing);
UpdateProxyPrefs(aBrowser);
UpdatePreference(aBrowser, 'enable_do_not_track', FDoNotTrack);
UpdatePreference(aBrowser, 'enable_referrers', FSendReferrer);
UpdatePreference(aBrowser, 'enable_a_ping', FHyperlinkAuditing);
case FWebRTCIPHandlingPolicy of
hpDefaultPublicAndPrivateInterfaces :
UpdatePreference('webrtc.ip_handling_policy', 'default_public_and_private_interfaces');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'default_public_and_private_interfaces');
hpDefaultPublicInterfaceOnly :
UpdatePreference('webrtc.ip_handling_policy', 'default_public_interface_only');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'default_public_interface_only');
hpDisableNonProxiedUDP :
UpdatePreference('webrtc.ip_handling_policy', 'disable_non_proxied_udp');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'disable_non_proxied_udp');
end;
if (FWebRTCMultipleRoutes <> STATE_DEFAULT) then
UpdatePreference('webrtc.multiple_routes_enabled', (FWebRTCMultipleRoutes = STATE_ENABLED));
UpdatePreference(aBrowser, 'webrtc.multiple_routes_enabled', (FWebRTCMultipleRoutes = STATE_ENABLED));
if (FWebRTCNonProxiedUDP <> STATE_DEFAULT) then
UpdatePreference('webrtc.nonproxied_udp_enabled', (FWebRTCNonProxiedUDP = STATE_ENABLED));
UpdatePreference(aBrowser, 'webrtc.nonproxied_udp_enabled', (FWebRTCNonProxiedUDP = STATE_ENABLED));
end;
function TChromium.UpdateProxyPrefs : boolean;
procedure TChromium.doUpdateOwnPreferences;
begin
if Initialized then doUpdatePreferences(FBrowser);
end;
function TChromium.UpdateProxyPrefs(const aBrowser: ICefBrowser) : boolean;
var
TempError : ustring;
TempProxy : ICefValue;
@ -2123,7 +2124,9 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference('proxy') then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference('proxy') then
begin
TempProxy := TCefValueRef.New;
TempValue := TCefValueRef.New;
@ -2171,7 +2174,7 @@ begin
end;
Result := TempProxy.SetDictionary(TempDict) and
FBrowser.Host.RequestContext.SetPreference('proxy', TempProxy, TempError);
aBrowser.Host.RequestContext.SetPreference('proxy', TempProxy, TempError);
if not(Result) then
OutputDebugMessage('TChromium.UpdateProxyPrefs error : ' + quotedstr(TempError));
@ -2182,7 +2185,7 @@ begin
end;
end;
function TChromium.UpdatePreference(const aName : string; aValue : boolean) : boolean;
function TChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : boolean) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2190,7 +2193,9 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
@ -2199,7 +2204,7 @@ begin
else
TempValue.SetBool(0);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2210,7 +2215,7 @@ begin
end;
end;
function TChromium.UpdatePreference(const aName : string; aValue : integer) : boolean;
function TChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : integer) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2218,11 +2223,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetInt(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2233,7 +2240,7 @@ begin
end;
end;
function TChromium.UpdatePreference(const aName : string; const aValue : double) : boolean;
function TChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; const aValue : double) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2241,11 +2248,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetDouble(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2256,7 +2265,7 @@ begin
end;
end;
function TChromium.UpdatePreference(const aName, aValue : string) : boolean;
function TChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName, aValue : string) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2264,11 +2273,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetString(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2775,15 +2786,16 @@ end;
procedure TChromium.doOnAfterCreated(const browser: ICefBrowser);
begin
if MultithreadApp and (FBrowser = nil) then
if (FBrowser = nil) and (browser <> nil) then
begin
FBrowser := browser;
if (FBrowser <> nil) then FBrowserId := FBrowser.Identifier;
FBrowser := browser;
FBrowserId := browser.Identifier;
end;
doUpdatePreferences;
doUpdatePreferences(browser);
FInitialized := (FBrowser <> nil) and (FBrowserId <> 0);
if not(FInitialized) then
FInitialized := (FBrowser <> nil) and (FBrowserId <> 0);
if Assigned(FOnAfterCreated) then FOnAfterCreated(Self, browser);
end;
@ -2795,7 +2807,7 @@ function TChromium.doOnBeforeBrowse(const browser : ICefBrowser;
begin
Result := False;
if FUpdatePreferences then doUpdatePreferences;
if FUpdatePreferences then doUpdatePreferences(browser);
if Assigned(FOnBeforeBrowse) then FOnBeforeBrowse(Self, browser, frame, request, isRedirect, Result);
end;

View File

@ -1842,7 +1842,8 @@ type
procedure doCookiesDeleted(numDeleted : integer);
procedure doPdfPrintFinished(aResultOK : boolean);
procedure doTextResultAvailable(const aText : string);
procedure doUpdatePreferences;
procedure doUpdatePreferences(const aBrowser: ICefBrowser);
procedure doUpdateOwnPreferences;
function doSavePreferences : boolean;
procedure doResolvedHostAvailable(result: TCefErrorCode; const resolvedIps: TStrings);
end;

View File

@ -194,7 +194,7 @@ procedure TCefUpdatePrefsTask.Execute;
begin
try
try
if (FEvents <> nil) then IChromiumEvents(FEvents).doUpdatePreferences;
if (FEvents <> nil) then IChromiumEvents(FEvents).doUpdateOwnPreferences;
except
on e : exception do
if CustomExceptionHandler('TCefUpdatePrefsTask.Execute', e) then raise;

View File

@ -246,8 +246,8 @@ type
procedure SetWindowlessFrameRate(aValue : integer);
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): Boolean;
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): ICefBrowser;
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): boolean;
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aContext : ICefRequestContext): boolean;
procedure DestroyClientHandler;
@ -258,11 +258,11 @@ type
procedure GetPrintPDFSettings(var aSettings : TCefPdfPrintSettings; const aTitle, aURL : string);
function UpdateProxyPrefs : boolean;
function UpdatePreference(const aName : string; aValue : boolean) : boolean; overload;
function UpdatePreference(const aName : string; aValue : integer) : boolean; overload;
function UpdatePreference(const aName : string; const aValue : double) : boolean; overload;
function UpdatePreference(const aName, aValue : string) : boolean; overload;
function UpdateProxyPrefs(const aBrowser: ICefBrowser) : boolean;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : boolean) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : integer) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName : string; const aValue : double) : boolean; overload;
function UpdatePreference(const aBrowser: ICefBrowser; const aName, aValue : string) : boolean; overload;
procedure HandleDictionary(const aDict : ICefDictionaryValue; var aResultSL : TStringList; const aRoot : string);
procedure HandleNull(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
@ -395,7 +395,8 @@ type
procedure doCookiesDeleted(numDeleted : integer); virtual;
procedure doPdfPrintFinished(aResultOK : boolean); virtual;
procedure doTextResultAvailable(const aText : string); virtual;
procedure doUpdatePreferences; virtual;
procedure doUpdatePreferences(const aBrowser: ICefBrowser); virtual;
procedure doUpdateOwnPreferences; virtual;
function doSavePreferences : boolean; virtual;
procedure doResolvedHostAvailable(result: TCefErrorCode; const resolvedIps: TStrings); virtual;
@ -437,6 +438,7 @@ type
procedure UpdatePreferences;
procedure SavePreferences(const aFileName : string);
procedure ResolveHost(const aURL : ustring);
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
procedure Find(aIdentifier : integer; const aSearchText : ustring; aForward, aMatchCase, aFindNext : Boolean);
procedure StopFinding(aClearSelection : Boolean);
@ -953,19 +955,10 @@ begin
end;
if MultithreadApp then
if GlobalCEFApp.MultiThreadedMessageLoop then
Result := CreateBrowserHost(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext)
else
begin
FBrowser := CreateBrowserHostSync(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext);
if (FBrowser <> nil) then
begin
FBrowserId := FBrowser.Identifier;
FInitialized := (FBrowserId <> 0);
Result := True;
end;
end;
Result := CreateBrowserHostSync(@FWindowInfo, FDefaultUrl, @FBrowserSettings, aContext);
end;
except
on e : exception do
@ -1005,14 +998,21 @@ end;
function TFMXChromium.CreateBrowserHostSync(aWindowInfo : PCefWindowInfo;
const aURL : ustring;
const aSettings : PCefBrowserSettings;
const aContext : ICefRequestContext): ICefBrowser;
const aContext : ICefRequestContext): boolean;
var
TempURL : TCefString;
TempBrowser : PCefBrowser;
TempURL : TCefString;
begin
TempURL := CefString(aURL);
TempBrowser := cef_browser_host_create_browser_sync(aWindowInfo, FHandler.Wrap, @TempURL, aSettings, CefGetData(aContext));
Result := TCefBrowserRef.UnWrap(TempBrowser);
TempURL := CefString(aURL);
FBrowser := TCefBrowserRef.UnWrap(cef_browser_host_create_browser_sync(aWindowInfo, FHandler.Wrap, @TempURL, aSettings, CefGetData(aContext)));
if (FBrowser <> nil) then
begin
FBrowserId := FBrowser.Identifier;
FInitialized := (FBrowserId <> 0);
Result := FInitialized;
end
else
Result := False;
end;
procedure TFMXChromium.Find(aIdentifier : integer; const aSearchText : ustring; aForward, aMatchCase, aFindNext : Boolean);
@ -1300,14 +1300,7 @@ end;
function TFMXChromium.GetMultithreadApp : boolean;
begin
Result := True;
try
if (GlobalCEFApp <> nil) then Result := GlobalCEFApp.MultiThreadedMessageLoop;
except
on e : exception do
if CustomExceptionHandler('TFMXChromium.GetMultithreadApp', e) then raise;
end;
Result := (GlobalCEFApp <> nil) and GlobalCEFApp.MultiThreadedMessageLoop;
end;
function TFMXChromium.GetHasDocument : boolean;
@ -1837,6 +1830,11 @@ begin
end;
end;
function TFMXChromium.IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
begin
Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser);
end;
procedure TFMXChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer);
var
TempEvent : TCefMouseEvent;
@ -1850,34 +1848,39 @@ begin
end;
end;
procedure TFMXChromium.doUpdatePreferences;
procedure TFMXChromium.doUpdatePreferences(const aBrowser: ICefBrowser);
begin
FUpdatePreferences := False;
UpdateProxyPrefs;
UpdatePreference('enable_do_not_track', FDoNotTrack);
UpdatePreference('enable_referrers', FSendReferrer);
UpdatePreference('enable_a_ping', FHyperlinkAuditing);
UpdateProxyPrefs(aBrowser);
UpdatePreference(aBrowser, 'enable_do_not_track', FDoNotTrack);
UpdatePreference(aBrowser, 'enable_referrers', FSendReferrer);
UpdatePreference(aBrowser, 'enable_a_ping', FHyperlinkAuditing);
case FWebRTCIPHandlingPolicy of
hpDefaultPublicAndPrivateInterfaces :
UpdatePreference('webrtc.ip_handling_policy', 'default_public_and_private_interfaces');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'default_public_and_private_interfaces');
hpDefaultPublicInterfaceOnly :
UpdatePreference('webrtc.ip_handling_policy', 'default_public_interface_only');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'default_public_interface_only');
hpDisableNonProxiedUDP :
UpdatePreference('webrtc.ip_handling_policy', 'disable_non_proxied_udp');
UpdatePreference(aBrowser, 'webrtc.ip_handling_policy', 'disable_non_proxied_udp');
end;
if (FWebRTCMultipleRoutes <> STATE_DEFAULT) then
UpdatePreference('webrtc.multiple_routes_enabled', (FWebRTCMultipleRoutes = STATE_ENABLED));
UpdatePreference(aBrowser, 'webrtc.multiple_routes_enabled', (FWebRTCMultipleRoutes = STATE_ENABLED));
if (FWebRTCNonProxiedUDP <> STATE_DEFAULT) then
UpdatePreference('webrtc.nonproxied_udp_enabled', (FWebRTCNonProxiedUDP = STATE_ENABLED));
UpdatePreference(aBrowser, 'webrtc.nonproxied_udp_enabled', (FWebRTCNonProxiedUDP = STATE_ENABLED));
end;
function TFMXChromium.UpdateProxyPrefs : boolean;
procedure TFMXChromium.doUpdateOwnPreferences;
begin
if Initialized then doUpdatePreferences(FBrowser);
end;
function TFMXChromium.UpdateProxyPrefs(const aBrowser: ICefBrowser) : boolean;
var
TempError : ustring;
TempProxy : ICefValue;
@ -1887,7 +1890,9 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference('proxy') then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference('proxy') then
begin
TempProxy := TCefValueRef.New;
TempValue := TCefValueRef.New;
@ -1935,7 +1940,7 @@ begin
end;
Result := TempProxy.SetDictionary(TempDict) and
FBrowser.Host.RequestContext.SetPreference('proxy', TempProxy, TempError);
aBrowser.Host.RequestContext.SetPreference('proxy', TempProxy, TempError);
if not(Result) then
OutputDebugMessage('TFMXChromium.UpdateProxyPrefs error : ' + quotedstr(TempError));
@ -1946,7 +1951,7 @@ begin
end;
end;
function TFMXChromium.UpdatePreference(const aName : string; aValue : boolean) : boolean;
function TFMXChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : boolean) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -1954,7 +1959,9 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
@ -1963,7 +1970,7 @@ begin
else
TempValue.SetBool(0);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TFMXChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -1974,7 +1981,7 @@ begin
end;
end;
function TFMXChromium.UpdatePreference(const aName : string; aValue : integer) : boolean;
function TFMXChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; aValue : integer) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -1982,11 +1989,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetInt(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TFMXChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -1997,7 +2006,7 @@ begin
end;
end;
function TFMXChromium.UpdatePreference(const aName : string; const aValue : double) : boolean;
function TFMXChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName : string; const aValue : double) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2005,11 +2014,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetDouble(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TFMXChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2020,7 +2031,7 @@ begin
end;
end;
function TFMXChromium.UpdatePreference(const aName, aValue : string) : boolean;
function TFMXChromium.UpdatePreference(const aBrowser: ICefBrowser; const aName, aValue : string) : boolean;
var
TempError : ustring;
TempValue : ICefValue;
@ -2028,11 +2039,13 @@ begin
Result := False;
try
if (FBrowser <> nil) and FBrowser.Host.RequestContext.CanSetPreference(aName) then
if (aBrowser <> nil) and
(aBrowser.Host <> nil) and
aBrowser.Host.RequestContext.CanSetPreference(aName) then
begin
TempValue := TCefValueRef.New;
TempValue.SetString(aValue);
Result := FBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
Result := aBrowser.Host.RequestContext.SetPreference(aName, TempValue, TempError);
if not(Result) then
OutputDebugMessage('TFMXChromium.UpdatePreference error : ' + quotedstr(TempError));
@ -2475,15 +2488,16 @@ end;
procedure TFMXChromium.doOnAfterCreated(const browser: ICefBrowser);
begin
if MultithreadApp and (FBrowser = nil) then
if (FBrowser = nil) and (browser <> nil) then
begin
FBrowser := browser;
if (FBrowser <> nil) then FBrowserId := FBrowser.Identifier;
FBrowser := browser;
FBrowserId := browser.Identifier;
end;
doUpdatePreferences;
doUpdatePreferences(browser);
FInitialized := (FBrowser <> nil) and (FBrowserId <> 0);
if not(FInitialized) then
FInitialized := (FBrowser <> nil) and (FBrowserId <> 0);
if Assigned(FOnAfterCreated) then FOnAfterCreated(Self, browser);
end;
@ -2495,7 +2509,7 @@ function TFMXChromium.doOnBeforeBrowse(const browser : ICefBrowser;
begin
Result := False;
if FUpdatePreferences then doUpdatePreferences;
if FUpdatePreferences then doUpdatePreferences(browser);
if Assigned(FOnBeforeBrowse) then FOnBeforeBrowse(Self, browser, frame, request, isRedirect, Result);
end;
@ -2610,7 +2624,7 @@ begin
end;
function TFMXChromium.doOnAutoResize(const browser : ICefBrowser;
const new_size : PCefSize): Boolean;
const new_size : PCefSize): Boolean;
begin
Result := False;