Filtering response content

Made a cool mod to CEF that you'd like to share with others? Discuss CEF modifications here, and view modifications that others have made.

Filtering response content

Postby yyankov » Fri May 20, 2011 8:48 am

As outlined in my post in the support forum Pluggable MIME filter equivalent, I needed to be able to look at and modify the content of the resources being downloaded by the browser. While this functionality can be emulated with the existing CEF API, it required me to employ some pretty invasive techniques. To avoid that, I made a few minor additions to CEF, which give me the ability to tap the incoming data stream before it is consumed by the browser - one simple interface and one additional callback method in CefHandler:

Code: Select all
class CefHandler : public CefBase
{
public:
  ...
  ...
  // Called on the UI thread after a response to the resource request is
  // received. Set |filter| if response content needs to be monitored
  // and/or modified as it arrives. The return value is currently ignored.
  /*--cef()--*/
  virtual RetVal HandleResourceReponse(CefRefPtr<CefBrowser> browser,
                                     const CefString& url,
                                     CefRefPtr<CefResponse> response,
                                     CefRefPtr<CefContentFilter>& filter) =0;
  ...
  ...
};

// Class used to represent a content filter interface. The methods of
// this class will always be called on the UI thread.
/*--cef(source=client)--*/
class CefContentFilter : public CefBase
{
public:
  // Set |substitute_data| to the replacement for the data in |data|
  // if data should be modified. The return value is currently ignored.
  /*--cef()--*/
  virtual bool ProcessData(void* data, int data_size, CefRefPtr<CefStreamReader>& substitute_data) =0;
 
  // Called when there is no more data to be processed. It is expected
  // that whatever data was retained in the last ProcessData() call,
  // it should be returned now by setting |remainder| if appropriate.
  // The return value is currently ignored.
  /*--cef()--*/
  virtual bool Drain(CefRefPtr<CefStreamReader>& remainder) =0;
};



I think CefHandler::HandleResourceResponse() has merit on its own even without the filter, as it gives the user the opportunity to peek into the actual response headers.
Not really sure if CefStreamReader is the best and most semantically correct class to use to pass the modified content back to CEF. Suggestions welcome.
Attachments
content_filter_r234.patch.7z
(6.22 KiB) Downloaded 941 times
yyankov
Techie
 
Posts: 10
Joined: Fri May 21, 2010 12:10 pm

Re: Filtering response content

Postby magreenblatt » Fri May 20, 2011 8:57 am

I like this idea conceptually. Please create an issue in the issue tracker and attach an uncompressed patch file.

Thanks,
Marshall
magreenblatt
Site Admin
 
Posts: 9974
Joined: Fri May 29, 2009 6:57 pm

Re: Filtering response content

Postby yyankov » Fri May 20, 2011 9:33 am

magreenblatt wrote:I like this idea conceptually. Please create an issue in the issue tracker and attach an uncompressed patch file.


Done.
yyankov
Techie
 
Posts: 10
Joined: Fri May 21, 2010 12:10 pm


Return to Modifications Forum

Who is online

Users browsing this forum: No registered users and 3 guests