Index: content/renderer/render_view_impl.cc |
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
index fd18ad12f38bd5c74efabbc9da61f111f82687f0..04b69b648e0c79f4c3e27488ee01b18b34951c1a 100644 |
--- a/content/renderer/render_view_impl.cc |
+++ b/content/renderer/render_view_impl.cc |
@@ -3669,25 +3669,37 @@ void RenderViewImpl::willSendRequest(WebFrame* frame, |
// The request's extra data may indicate that we should set a custom user |
// agent. This needs to be done here, after WebKit is through with setting the |
- // user agent on its own. |
+ // user agent on its own. Similarly, it may indicate that we should set an |
+ // X-Requested-With header. This must be done here to avoid breaking CORS |
+ // checks. |
WebString custom_user_agent; |
+ WebString requested_with; |
if (request.extraData()) { |
webkit_glue::WebURLRequestExtraDataImpl* old_extra_data = |
static_cast<webkit_glue::WebURLRequestExtraDataImpl*>( |
request.extraData()); |
- custom_user_agent = old_extra_data->custom_user_agent(); |
+ custom_user_agent = old_extra_data->custom_user_agent(); |
if (!custom_user_agent.isNull()) { |
if (custom_user_agent.isEmpty()) |
request.clearHTTPHeaderField("User-Agent"); |
else |
request.setHTTPHeaderField("User-Agent", custom_user_agent); |
} |
+ |
+ requested_with = old_extra_data->requested_with(); |
+ if (!requested_with.isNull()) { |
+ if (requested_with.isEmpty()) |
+ request.clearHTTPHeaderField("X-Requested-With"); |
+ else |
+ request.setHTTPHeaderField("X-Requested-With", requested_with); |
+ } |
} |
request.setExtraData( |
new RequestExtraData(referrer_policy, |
custom_user_agent, |
+ requested_with, |
(frame == top_frame), |
frame->identifier(), |
frame->parent() == top_frame, |