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

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

Issue 11419093: [Android WebView] Implement WebSettings.{get|set}CacheMode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased just in case Created 8 years, 1 month 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 328cecf30f5e2d69e86b84336118844603d64e20..dab1be280bd167ca5c3cbb566963593fb0fc0365 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
@@ -27,6 +27,19 @@ using android_webview::AwContentsIoThreadClient;
base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate>
g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER;
+void SetCacheControlFlag(
+ net::URLRequest* request, int flag) {
+ const int all_flags = net::LOAD_BYPASS_CACHE |
mkosiba (inactive) 2012/11/21 12:35:15 nit: s/all_flags/valid_flags/
mnaganov (inactive) 2012/11/21 13:17:09 "valid_flags" doesn't make much sense to me. Renam
+ net::LOAD_VALIDATE_CACHE |
+ net::LOAD_PREFERRING_CACHE |
+ net::LOAD_ONLY_FROM_CACHE;
+ DCHECK((flag & all_flags) == flag);
+ int load_flags = request->load_flags();
+ load_flags &= ~all_flags;
+ load_flags |= flag;
+ request->set_load_flags(load_flags);
+}
+
void SetOnlyAllowLoadFromCache(
net::URLRequest* request) {
int load_flags = request->load_flags();
@@ -37,12 +50,13 @@ void SetOnlyAllowLoadFromCache(
request->set_load_flags(load_flags);
}
-// May cancel this resource request based on result of Java callbacks.
-class MaybeCancelResourceThrottle : public content::ResourceThrottle {
+// Enqueries certain WebSettings values, sets up the resource request
+// accordingly. May cancel the request.
+class ApplyWebSettingsResourceThrottle : public content::ResourceThrottle {
mkosiba (inactive) 2012/11/21 12:35:15 might as well call this IoThreadClientThrottle to
mnaganov (inactive) 2012/11/21 13:17:09 OK, renamed and updated the comment. But this will
public:
- MaybeCancelResourceThrottle(int child_id,
- int route_id,
- net::URLRequest* request)
+ ApplyWebSettingsResourceThrottle(int child_id,
+ int route_id,
+ net::URLRequest* request)
: child_id_(child_id),
route_id_(route_id),
request_(request) { }
@@ -58,7 +72,7 @@ class MaybeCancelResourceThrottle : public content::ResourceThrottle {
net::URLRequest* request_;
};
-void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) {
+void ApplyWebSettingsResourceThrottle::WillStartRequest(bool* defer) {
// If there is no IO thread client set at this point, use a
// restrictive policy. This can happen for blocked popup
// windows for example.
@@ -96,7 +110,23 @@ void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) {
controller()->CancelWithError(net::ERR_ACCESS_DENIED);
return;
}
- SetOnlyAllowLoadFromCache(request_);
+ SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE);
+ } else {
+ AwContentsIoThreadClient::CacheMode cache_mode =
+ GetIoThreadClient()->GetCacheMode();
+ switch(cache_mode) {
+ case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK:
+ SetCacheControlFlag(request_, net::LOAD_PREFERRING_CACHE);
+ break;
+ case AwContentsIoThreadClient::LOAD_NO_CACHE:
+ SetCacheControlFlag(request_, net::LOAD_BYPASS_CACHE);
+ break;
+ case AwContentsIoThreadClient::LOAD_CACHE_ONLY:
+ SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE);
+ break;
+ default:
+ break;
+ }
}
}
@@ -127,7 +157,7 @@ void AwResourceDispatcherHostDelegate::RequestBeginning(
bool is_continuation_of_transferred_request,
ScopedVector<content::ResourceThrottle>* throttles) {
- throttles->push_back(new MaybeCancelResourceThrottle(
+ throttles->push_back(new ApplyWebSettingsResourceThrottle(
child_id, route_id, request));
bool allow_intercepting =

Powered by Google App Engine
This is Rietveld 408576698