2

I'm currently trying to view an image being loaded through a Res://imagename at the point its loaded. In Chromium with a res handler I've been able to do this through the ResourceResponse event however, TWebBrowser does not have a similar function as far as I can tell.

I have been able to latch on to the OnDocumentComplete function and have been able to implement a very inefficient way that looks through the whole of the HTML document once its been created...

procedure TNotesBrowser.TBrowserDocumentComplete(ASender: TObject; const pDisp:   IDispatch; var URL: OleVariant);
var
    HTMLDocument2: IHTMLDocument2;
    i            : Integer;
    Item         : IHTMLElement;
    ImageUrl     : string;
begin
    HTMLDocument2 := ((FBrowser as TWebBrowser).Document AS IHTMLDocument2);
    if HTMLDocument2 <> nil then
    begin
        for i := 0 to HTMLDocument2.images.length -1 do
        begin
        Item := HTMLDocument2.images.item(i, 'null') As IHTMLElement;
        ImageUrl:=item.getAttribute('src',0);

        if ContainsText(ImageURL,'ImageName') then
            if Assigned(FCCICONLoaded) then
                { Trigger Event }
                FCCICONLoaded(self);
        end;
    end;
end;

However, this is quite a long process. So has anyone else found an event that acts similar to Chromium's OnResourceResponse() to avoid looking through the document?

Scott Alexander
  • 455
  • 2
  • 17

1 Answers1

1

Through some hefty research I've found a solution to this problem using an asynchronous pluggable protocol, but so far it only works for a single form application with the TWebBrowser embedded directly into the form. Source code for this solution can be found here http://www.jasontpenny.com/blog/2010/03/23/custom-protocol-handler-in-delphi/.

If your like me and still have an issue using the asynchronous pluggable protocol because your TWebbrowser is not directly embedded into a form, I've opened up a new Question: How can I find the ComServer for a TWebBrowser Asynchronous Pluggable Protocol

Community
  • 1
  • 1
Scott Alexander
  • 455
  • 2
  • 17