Page 1 of 1

DoOnLoadStart/doOnLoadEnd doesn't work.

Posted: Fri Jun 08, 2018 11:28 am
by Rockiman
Hi, I programmatically create a browser and try to use doOnLoadStart/doOnLoadEnd procedure, but it is never called. In the same time, for example, function doOnGetResourceHandler works normally. What is the problem?

Code: Select all

unit cef4exp1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uCEFWindowParent, uCEFChromiumWindow,
  uCEFChromium, uCEFInterfaces, uCEFConstants, uCEFTypes, Vcl.StdCtrls;

type
  chrome = class(TChromium)
  private
  public
    procedure doOnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: TCefTransitionType);override;
  end;

type
  TForm1 = class(TForm)
    CEFWindowParent1: TCEFWindowParent;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  Form1: TForm1; ch:chrome;

implementation


{$R *.dfm}

procedure chrome.doOnLoadStart(const browser: ICefBrowser; const frame: ICefFrame; transitionType: Cardinal);
begin
 form1.Caption:='Procedure works';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 ch:=chrome.Create(Form1);
 ch.CreateBrowser(CEFWindowParent1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if ch.Initialized then ch.LoadURL('google.com');
end;

end.

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Posted: Fri Jun 08, 2018 12:26 pm
by salvadordf
Hi,

The short answer for that is this :
Override TChromium.MustCreateLoadHandler and set the result to TRUE. After that, doOnLoadStart and doOnLoadEnd will work.

The long answer is this :
TChromium only creates what's needed. When your application calls TChromium.CreateBrowser it checks what events are really used and then it creates the "handlers" that are needed to make those events work.

There are a bunch of virtual functions called "TChromium.MustCreate********Handler" that check what TChromium events are used. In this case, you want to create ICefLoadHandler even if there are no events used so you need to override TChromium.MustCreateLoadHandler and set the result to TRUE.

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Posted: Fri Jun 08, 2018 1:46 pm
by Rockiman
Ok, got that, thank you for answer. :)

Re: DoOnLoadStart/doOnLoadEnd doesn't work.

Posted: Thu Jun 21, 2018 3:19 pm
by salvadordf
Assign the event you need before calling TChromium.CreateBrowser at runtime and everything will be ok.