how to use BeforeResourceLoad in Chromium Embedded 3 (DCEF3) ?

1,397 views
Skip to first unread message

Bruno

unread,
Aug 6, 2014, 3:54:19 AM8/6/14
to delphichrom...@googlegroups.com

we would like update our code from DECF1 to DCEF3.
the prototype of the method OnBeforeResourceLoad change

in DECF1

procedure ChromeBrowserBeforeResourceLoad(
     Sender: TObject; const browser: ICefBrowser;
     const request: ICefRequest; var redirectUrl: ustring;
     var resourceStream: ICefStreamReader; const response: ICefResponse;
     loadFlags: Integer; out Result: Boolean);

in DCEF3

procedure ChromeBrowserBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const request: ICefRequest; out Result: Boolean);

resourceStream and response parameters doesn't exist now in DCEF3

we have this code in DCEF1, so how to make it with DCEF3 ?

procedure TXFChromeViewer.ChromeBrowserBeforeResourceLoad(
      Sender: TObject; const browser: ICefBrowser;
    const request: ICefRequest; var redirectUrl: ustring;
    var resourceStream: ICefStreamReader; const response: ICefResponse;
    loadFlags: Integer; out Result: Boolean);
var
   content : TContentData;
   handled : Boolean;
begin
   FixupThreadLangageID;
   if StrEndsWith(request.Url, '/test.htm') then begin
      content:=FHomePage; //HTML code
      handled:=True;
   end else content:=FChromeServer.ExecuteRequest(request, handled);
   if handled then begin
      response.Status:=200;
      response.StatusText:='Ok';
      response.MimeType:=StrBefore(content.MimeType, ';');
      if content.Size=0 then
         content.AsPlainText:='.';
      resourceStream:=TCefStreamReaderRef.CreateForData(@content.Data[1], content.Size);
   end;
end;

Bruno

unread,
Sep 30, 2014, 9:39:59 AM9/30/14
to delphichrom...@googlegroups.com
anybody can help me ?

Czarek Tomczak

unread,
Oct 1, 2014, 3:51:18 AM10/1/14
to delphichrom...@googlegroups.com
See https://code.google.com/p/chromiumembedded/issues/detail?id=515

There's no great way to filter response contents with CEF3 currently. 
You can use CefResourceHandler via CefRequestHandler::GetResourceHandler 
and execute the request/return the response contents yourself using 
CefURLRequest.

Johny Tim

unread,
Jan 19, 2015, 5:17:50 PM1/19/15
to delphichrom...@googlegroups.com
Hi Bruno,

Have you managed to find a solution to your problem ?
I'm having the same issue.

Thanks!

Jason

unread,
Feb 3, 2015, 4:06:39 PM2/3/15
to delphichrom...@googlegroups.com
I've been doing a bit of work on this, which you can find here:
http://stackoverflow.com/questions/28304049/blob-urls-and-cross-origin-errors-with-dcef-getresourcehandler

Eventually when I shake out all the problems, I'm (hopefully) going to post something more cleaned up with a callback that lets you modify the response.

Johny Tim

unread,
Feb 3, 2015, 4:44:46 PM2/3/15
to delphichrom...@googlegroups.com
Hi Jason,

Your sample looks really good. I've compiled it, but as Czarek Tomczak says on stackoverflow, something is wrong with the headers.
For example if i go to google.com its redirected automatically to local google but the codepage is not set correctly when using your resourcehandler.

I found this code, maybe it helps:

Johny Tim

unread,
Feb 12, 2015, 3:36:11 AM2/12/15
to delphichrom...@googlegroups.com
Hi Jason,

Eventually when I shake out all the problems, I'm (hopefully) going to post something more cleaned up with a callback that lets you modify the response.

Have you managed to fix the header problems?

Thanks!

Jason

unread,
Feb 12, 2015, 10:24:23 AM2/12/15
to delphichrom...@googlegroups.com
Not yet, but only because I haven't revisited it, yet. I'll post here if/when I do.

Czarek Tomczak

unread,
Feb 13, 2015, 9:21:15 AM2/13/15
to delphichrom...@googlegroups.com
In the past I've had issues with the "encoding" header, problem reported to CEF here: http://www.magpcss.org/ceforum/viewtopic.php?p=18401#p18401In the stackoverflow question link posted here there is a different problem with CORS headers. Looks to me this might be some issue in CEF with headers when using resource handler. Some further debugging would be needed to find out what is going on.

Michael Denis

unread,
Jun 5, 2015, 10:04:28 AM6/5/15
to delphichrom...@googlegroups.com
Hi Jason,

I'm trying to get the mime type of the browser responses. In CEF1 was easy, now in CEF3 is little harder. I've tried your code:
And I can get the mime type, but the header seems to be having some problems, as some texts are not correctly displayed, probably encoding issues.

I've tried also the code from TLama's answer on:
http://stackoverflow.com/questions/30406803/how-to-retrieve-an-xhr-response

Same issue with encoding. Have you managed to fix the encoding issue?
Is there another simplier way I could get the mime type of the response ?

Thanks in advance.

Jason

unread,
Jun 8, 2015, 2:34:19 PM6/8/15
to delphichrom...@googlegroups.com
Sorry, Michael, I haven't had time to make any further progress on that.  I just wound up sticking with bypassing the resource handler for those places where it failed with the blobs. Please do post any of your findings. This stuff can be pretty uncharted territory and every little bit helps.

Michael

unread,
Jun 9, 2015, 12:02:53 PM6/9/15
to delphichrom...@googlegroups.com
I also found a workaround, using IDHTTP for some urls to retrieve the response header with the mime type :) It's not perfect but it works.
Reply all
Reply to author
Forward
0 new messages