xxfxxf / chromiumembedded

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

Observe and modify request redirects #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There is no way to observe and modify server redirects, such as HTTP 302 Found, 
for individual resource requests (as opposed to navigation requests). To this 
end, I propose a new method be added to CefRequestHandler with the following or 
similar signature:

  ///
  // Called on the UI thread when the server responds with 
  // HTTP 302 Found or similar. |redirectUrl| holds the location
  // the initial request is being redirected to. Changes
  // made to |redirectUrl| are observed.
  ///
  /*--cef()--*/
  virtual void OnLocationRedirect(CefRefPtr<CefBrowser> browser,
                                  CefString& redirectUrl) {}

Attached is the patch against r291 to make this work.

Original issue reported on code.google.com by yyankov on 21 Sep 2011 at 4:11

GoogleCodeExporter commented 9 years ago
Further testing shows the patch fulfills only half of its intended purpose. If 
a redirect URL is modified in OnLocationRedirect() it is taken note of only 
internally. For example, the subsequent call to OnBeforeBrowse() contains the 
modified URL, but the actual request being sent out over the net uses the 
initial unmodified URL.

Working on fixing this.

Original comment by yyankov on 24 Sep 2011 at 2:21

GoogleCodeExporter commented 9 years ago
With this new patch changes to redirectUrl are now observed properly. Please 
note that this requires a small modification to Chromium itself in 
src/net/url_request/url_request.*

The attached patch includes the patch to Chromium, but it is required that you 
run gclient runhooks after patching for it to be applied.

Also, note that OnLocationRedirect() will be invoked on the IO thread, not UI.

Original comment by yyankov on 26 Sep 2011 at 2:20

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for developing a patch with unit tests!

It looks like the "recommended" way to change redirects is by using 
URLRequest::Interceptor::MaybeInterceptRedirect(). Did you explore this option?

Original comment by magreenb...@gmail.com on 27 Sep 2011 at 8:03

GoogleCodeExporter commented 9 years ago
Not really, how do you know this is the recommended way? I'm only asking 
because, whatever the source you're citing is, it might be useful for further 
reference in general.

I was looking for the least invasive way to solve the issue, but if 
MaybeInterceptRedirect() is exposed to libcef/browser_resource_loader_bridge in 
some way, and it makes possible to avoid patching Chromium, that would indeed 
be preferable.

I'll look into it, thanks. 

Original comment by yyankov on 27 Sep 2011 at 8:14

GoogleCodeExporter commented 9 years ago
> Not really, how do you know this is the recommended way?

Via inspection of the header file and my general knowledge of Chromium thinking 
:-).

Original comment by magreenb...@gmail.com on 27 Sep 2011 at 8:53

GoogleCodeExporter commented 9 years ago
Fixed in revision 419.

Original comment by magreenb...@gmail.com on 15 Dec 2011 at 4:06