简体   繁体   中英

TChromium individual resource download completion event?

Currently I've got TWebBrowser embedded in an application which "logs" activity in an online game, so that statistics about that game can be shown to the user. This works fine currently, but TWebBrowser appears to be a mighty bit slower than TChromium. Hence, I've started converting my project to make use of the Delphi TChromium embedded framework (CEF)-3 from : https://bitbucket.org/chromiumembedded/

From this I took the guiclient which can be found in the demos directory of the download.

So far so good - however, it appears the user is able to press a button to navigate away from their current page before the call to "crmBrowserLoadEnd" can be received. This results in my program missing out on data.

As an alternative I figure it might be possible to check what resources complete their individual download. I can hook the event "crmBrowserBeforeResourceLoad" to see which resources "start" loading,. But there doesn't seem to be any event that can tell me the resource has finished loading.

procedure TFrmDBrowser.crmBrowserBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; out Result: Boolean);
var
  u: TUrlParts;
  Item: TListItem;
begin
  item := LvDataView.Items.Add();
  item.Caption := request.Url;
end;

So, it comes down to:

    1. Q: How can I ask/tell the CEF to give me an event for the individual resources that have been downloaded, so I can read the index.htm when it's been downloaded. (instead of waiting for the entire page and all resources to finish loading)
    1. A: Use "crmBrowserLoadStart" instead of "crmBrowserLoadEnd". To ensure it can grab the url before the browser starts handline the downloaded file.
    1. Q: How might I block all user input until the entire document has finished loading and crmBrowserLoadEnd is done. (Though this is less preferred as it will decrease the user's enjoyment of the browser) :
    1. A: Update: Catching "crmBrowserPreKeyEvent" and adding " if FLoading then Result := True;" will ensure the user can not use the keyboard to navigate. Setting crmBrowser.Enabled := False,. will ensure the user can not navigate using the mouse.

Got an answer from the Facebook Delphi group, by: Shariful Alam Khan. "use OnLoadStart event"

Which, turns out is exactly the best way for the above example.

Source example:

procedure DataExtractionCallback(const Html: uString);
begin
  try
    FrmDBrowser.RunDataExtraction(Html);
  except
    //
  end;
end;

procedure TFrmDBrowser.crmBrowserLoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
var
  CefStringVisitor: ICefStringVisitor;
  URL: String;
begin
  if not IsMain(browser, frame) then
    Exit;

  FLoading := True;

  CefStringVisitor := TCefFastStringVisitor.Create(DataExtractionCallback);
  crmBrowser.Browser.MainFrame.GetSource(CefStringVisitor);
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM