oulan / dcef3

Automatically exported from code.google.com/p/dcef3
0 stars 0 forks source link

Unable to traverse DOM #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am using the latest SVN with XE2 under Win7 x64.

It seems there's something wrong with DOM traversing.

This code should reach ProcessNode() but it doesn't even get to ProcessDOM().

procedure ProcessNode(ANode: ICefDomNode);
var
  Node1: ICefDomNode;
begin
  if Assigned(ANode) then begin
    Node1 := ANode.FirstChild;
    while Assigned(Node1) do begin
      {Do stuff with node}
      ProcessNode(Node1);
      Node1 := Node1.NextSibling;
    end;
  end;
end;

procedure ProcessDOM(const ADocument: ICefDomDocument);
begin
  ProcessNode(ADocument.Body);
end;

procedure TMainForm.Chrome1LoadEnd(Sender: TObject; const ABrowser: 
ICefBrowser; const AFrame: ICefFrame; AStatus: Integer);
begin
  if Assigned(AFrame) then AFrame.VisitDomProc(ProcessDOM);
end;

Original issue reported on code.google.com by adem.meda@gmail.com on 24 Jan 2013 at 12:42

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
In dcef3 access to DOM only in the rendering process. 
Use:

TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn)
private
  procedure ProcessDOM(const ADocument: ICefDomDocument);
  procedure ProcessNode(ANode: ICefDomNode);
protected
  function OnProcessMessageReceived(const browser: ICefBrowser;
    sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; override;
public
end;

function TCustomRenderProcessHandler.OnProcessMessageReceived(
  const browser: ICefBrowser; sourceProcess: TCefProcessId;
  const message: ICefProcessMessage): Boolean;
begin
  if (message.Name = 'visitdom') then
  begin
    browser.MainFrame.VisitDomProc(ProcessDOM);
    Result := True;
  end
  else
    Result := False;
end;

CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
TCustomRenderProcessHandler(CefRenderProcessHandler).bFinish := False;

procedure TMainForm.Chrome1LoadEnd(Sender: TObject; const ABrowser: 
ICefBrowser; const AFrame: ICefFrame; AStatus: Integer);
begin
  if (AStatus = 200) and (ABrowser<>nil) and AFrame.IsMain then
    ABrowser.SendProcessMessage(PID_RENDERER, TCefProcessMessageRef.New('visitdom'));
end;

Original comment by AlexZha...@gmail.com on 1 Feb 2013 at 6:26