Chromium Code Reviews| Index: android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc |
| diff --git a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc |
| index f145d40e706011258f3761ab3b48cd5a903a62a8..f04efa68bc4465ab8f31feb75549dbf305b9e8c6 100644 |
| --- a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc |
| +++ b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc |
| @@ -8,6 +8,7 @@ |
| #include "android_webview/browser/aw_contents_io_thread_client.h" |
| #include "android_webview/browser/aw_login_delegate.h" |
| +#include "android_webview/browser/aw_resource_context.h" |
| #include "android_webview/common/url_constants.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/scoped_vector.h" |
| @@ -212,6 +213,8 @@ void AwResourceDispatcherHostDelegate::RequestBeginning( |
| int route_id, |
| ScopedVector<content::ResourceThrottle>* throttles) { |
| + AddExtraHeadersIfNeeded(request, resource_context); |
| + |
| // We always push the throttles here. Checking the existence of io_client |
| // is racy when a popup window is created. That is because RequestBeginning |
| // is called whether or not requests are blocked via BlockRequestForRoute() |
| @@ -228,6 +231,15 @@ void AwResourceDispatcherHostDelegate::RequestBeginning( |
| request)); |
| } |
| +void AwResourceDispatcherHostDelegate::OnRequestRedirected( |
| + const GURL& redirect_url, |
| + net::URLRequest* request, |
| + content::ResourceContext* resource_context, |
| + content::ResourceResponse* response) { |
| + AddExtraHeadersIfNeeded(request, resource_context); |
| +} |
| + |
| + |
| void AwResourceDispatcherHostDelegate::DownloadStarting( |
| net::URLRequest* request, |
| content::ResourceContext* resource_context, |
| @@ -393,4 +405,31 @@ void AwResourceDispatcherHostDelegate::OnIoThreadClientReadyInternal( |
| } |
| } |
| +void AwResourceDispatcherHostDelegate::AddExtraHeadersIfNeeded( |
| + net::URLRequest* request, |
| + content::ResourceContext* resource_context) { |
| + const content::ResourceRequestInfo* request_info = |
| + content::ResourceRequestInfo::ForRequest(request); |
| + if (!request_info) return; |
| + if (request_info->GetResourceType() != ResourceType::MAIN_FRAME) return; |
| + |
| + const bool is_load_url = request_info->GetPageTransition() & |
| + content::PAGE_TRANSITION_FROM_API; |
| + const bool is_go_back_forward = request_info->GetPageTransition() & |
| + content::PAGE_TRANSITION_FORWARD_BACK; |
| + const bool is_reload = content::PageTransitionCoreTypeIs( |
| + request_info->GetPageTransition(), content::PAGE_TRANSITION_RELOAD); |
|
bulach
2013/12/10 15:16:57
nit: perhaps unroll request_info->GetPageTransitio
mnaganov (inactive)
2013/12/10 16:00:37
Done.
|
| + if (is_load_url || is_go_back_forward || is_reload) { |
| + AwResourceContext* awrc = static_cast<AwResourceContext*>(resource_context); |
| + std::string extra_headers = awrc->GetExtraHeaders(request->url()); |
| + if (!extra_headers.empty()) { |
| + net::HttpRequestHeaders headers; |
| + headers.AddHeadersFromString(extra_headers); |
| + for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { |
| + request->SetExtraRequestHeaderByName(it.name(), it.value(), false); |
| + } |
| + } |
| + } |
| +} |
| + |
| } // namespace android_webview |