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

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: Moved reloadSync into AwTestBase 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 c88722bc9950603db4545b66a6a51e6ff8ba0518..11c85d0b6e1b266884fd085f0a61506c99217ec9 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"
@@ -225,6 +226,8 @@ void AwResourceDispatcherHostDelegate::RequestBeginning(
if (!io_client)
return;
+ AddExtraHeadersIfNeeded(request, resource_context);
+
throttles->push_back(new IoThreadClientThrottle(
child_id, route_id, request));
@@ -247,6 +250,15 @@ void AwResourceDispatcherHostDelegate::RequestBeginning(
}
}
+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,
@@ -412,4 +424,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);
+ 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(), true);
benm (inactive) 2013/12/09 17:49:11 What's the behaviour in Classic vs. Chromium WebVi
mnaganov (inactive) 2013/12/10 11:03:31 That's a good catch! In fact, the old WebView seem
+ }
+ }
+ }
+}
+
} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698