mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2024-12-14 09:42:54 +02:00
26c6f6696d
- New TCEFServerComponent. The new CEF3 includes a http and websockets server for communication between applications in localhost. - New JSDialogBrowser demo to showhow to use custom forms in javascript dialogs. - New SimpleServer demo which uses TCEFServerComponent. - Removed all the code that could be removed from the DPR files and moved to another units. - Now the GlogalCEFApp checks all the CEF3 binaries and stores the missing files in GlogalCEFApp.MissingLibFiles. The default error message gives a list of missing files. - New GlobalCEFApp.Status property. Use it with GlobalCEFApp.ShowMessageDlg set to False if you want to show customized error messages. - Now TCEFClient only creates the necessary handlers if you use any their events in TChromium. - Fixed a destruction bug in OSRExternalPumpBrowser - Added the procedures to handle WM_ENTERMENULOOP and WM_EXITMENULOOP to all the demos.
169 lines
5.8 KiB
ObjectPascal
169 lines
5.8 KiB
ObjectPascal
// ************************************************************************
|
|
// ***************************** CEF4Delphi *******************************
|
|
// ************************************************************************
|
|
//
|
|
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
|
|
// browser in Delphi applications.
|
|
//
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
//
|
|
// For more information about CEF4Delphi visit :
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
//
|
|
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
|
|
//
|
|
// ************************************************************************
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
// ************************************************************************
|
|
(*
|
|
* Delphi Chromium Embedded 3
|
|
*
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
* the specific language governing rights and limitations under the License.
|
|
*
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
* Web site : http://www.progdigy.com
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
*
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
* this source code without explicit permission.
|
|
*
|
|
*)
|
|
|
|
unit uJSWindowBindingWithFunction;
|
|
|
|
{$I cef.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
{$IFDEF DELPHI16_UP}
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls,
|
|
{$ELSE}
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics,
|
|
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
|
|
{$ENDIF}
|
|
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants;
|
|
|
|
type
|
|
TJSWindowBindingWithFunctionFrm = class(TForm)
|
|
NavControlPnl: TPanel;
|
|
Edit1: TEdit;
|
|
GoBtn: TButton;
|
|
CEFWindowParent1: TCEFWindowParent;
|
|
Chromium1: TChromium;
|
|
Timer1: TTimer;
|
|
procedure FormShow(Sender: TObject);
|
|
procedure GoBtnClick(Sender: TObject);
|
|
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
procedure Timer1Timer(Sender: TObject);
|
|
protected
|
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
|
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
|
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
|
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
|
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm;
|
|
|
|
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses
|
|
uCEFv8Value, uMyV8Handler;
|
|
|
|
// The CEF3 document describing JavaScript integration is here :
|
|
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
|
|
|
|
// The HTML file in this demo has a button that shows the result of 'window.myfunc()'
|
|
// which was set in the GlobalCEFApp.OnContextCreated event.
|
|
|
|
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
|
|
var
|
|
TempHandler : ICefv8Handler;
|
|
TempFunction : ICefv8Value;
|
|
begin
|
|
// This is the JS Window Binding example with a function in the "JavaScript Integration" wiki page at
|
|
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
|
|
|
|
TempHandler := TMyV8Handler.Create;
|
|
TempFunction := TCefv8ValueRef.NewFunction('myfunc', TempHandler);
|
|
|
|
context.Global.SetValueByKey('myfunc', TempFunction, V8_PROPERTY_ATTRIBUTE_NONE);
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.GoBtnClick(Sender: TObject);
|
|
begin
|
|
Chromium1.LoadURL(Edit1.Text);
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
begin
|
|
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.FormShow(Sender: TObject);
|
|
begin
|
|
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
|
// If it's not initialized yet, we use a simple timer to create the browser later.
|
|
if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) then Timer1.Enabled := True;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.WMMove(var aMessage : TWMMove);
|
|
begin
|
|
inherited;
|
|
|
|
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.WMMoving(var aMessage : TMessage);
|
|
begin
|
|
inherited;
|
|
|
|
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.Timer1Timer(Sender: TObject);
|
|
begin
|
|
Timer1.Enabled := False;
|
|
if not(Chromium1.CreateBrowser(CEFWindowParent1, '')) and not(Chromium1.Initialized) then
|
|
Timer1.Enabled := True;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.BrowserCreatedMsg(var aMessage : TMessage);
|
|
begin
|
|
Caption := 'JSWindowBindingWithFunction';
|
|
CEFWindowParent1.UpdateSize;
|
|
NavControlPnl.Enabled := True;
|
|
GoBtn.Click;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.WMEnterMenuLoop(var aMessage: TMessage);
|
|
begin
|
|
inherited;
|
|
|
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
|
|
end;
|
|
|
|
procedure TJSWindowBindingWithFunctionFrm.WMExitMenuLoop(var aMessage: TMessage);
|
|
begin
|
|
inherited;
|
|
|
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
|
end;
|
|
|
|
end.
|