Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2720)

Unified Diff: android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc

Issue 99683006: [Android WebView] Only send extra headers for the main page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bulach's comments addressed Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5042dcdbe0eff49ab20327a3bb5863f6ce985f16 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,32 @@ 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 content::PageTransition transition = request_info->GetPageTransition();
+ const bool is_load_url =
+ transition & content::PAGE_TRANSITION_FROM_API;
+ const bool is_go_back_forward =
+ transition & content::PAGE_TRANSITION_FORWARD_BACK;
+ const bool is_reload = content::PageTransitionCoreTypeIs(
+ transition, content::PAGE_TRANSITION_RELOAD);
+ 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

Powered by Google App Engine
This is Rietveld 408576698