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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h"
6 6
7 #include "android_webview/browser/aw_login_delegate.h" 7 #include "android_webview/browser/aw_login_delegate.h"
8 #include "android_webview/browser/aw_contents_io_thread_client.h" 8 #include "android_webview/browser/aw_contents_io_thread_client.h"
9 #include "android_webview/common/url_constants.h" 9 #include "android_webview/common/url_constants.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "content/components/navigation_interception/intercept_navigation_delega te.h" 12 #include "content/components/navigation_interception/intercept_navigation_delega te.h"
13 #include "content/public/browser/resource_controller.h" 13 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_dispatcher_host.h" 14 #include "content/public/browser/resource_dispatcher_host.h"
15 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 15 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
16 #include "content/public/browser/resource_throttle.h" 16 #include "content/public/browser/resource_throttle.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
19 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
20 20
21 using content::InterceptNavigationDelegate; 21 using content::InterceptNavigationDelegate;
22 22
23 namespace { 23 namespace {
24 24
25 using android_webview::AwContentsIoThreadClient; 25 using android_webview::AwContentsIoThreadClient;
26 26
27 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> 27 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate>
28 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; 28 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER;
29 29
30 void SetCacheControlFlag(
31 net::URLRequest* request, int flag) {
32 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
33 net::LOAD_VALIDATE_CACHE |
34 net::LOAD_PREFERRING_CACHE |
35 net::LOAD_ONLY_FROM_CACHE;
36 DCHECK((flag & all_flags) == flag);
37 int load_flags = request->load_flags();
38 load_flags &= ~all_flags;
39 load_flags |= flag;
40 request->set_load_flags(load_flags);
41 }
42
30 void SetOnlyAllowLoadFromCache( 43 void SetOnlyAllowLoadFromCache(
31 net::URLRequest* request) { 44 net::URLRequest* request) {
32 int load_flags = request->load_flags(); 45 int load_flags = request->load_flags();
33 load_flags &= ~(net::LOAD_BYPASS_CACHE & 46 load_flags &= ~(net::LOAD_BYPASS_CACHE &
34 net::LOAD_VALIDATE_CACHE & 47 net::LOAD_VALIDATE_CACHE &
35 net::LOAD_PREFERRING_CACHE); 48 net::LOAD_PREFERRING_CACHE);
36 load_flags |= net::LOAD_ONLY_FROM_CACHE; 49 load_flags |= net::LOAD_ONLY_FROM_CACHE;
37 request->set_load_flags(load_flags); 50 request->set_load_flags(load_flags);
38 } 51 }
39 52
40 // May cancel this resource request based on result of Java callbacks. 53 // Enqueries certain WebSettings values, sets up the resource request
41 class MaybeCancelResourceThrottle : public content::ResourceThrottle { 54 // accordingly. May cancel the request.
55 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
42 public: 56 public:
43 MaybeCancelResourceThrottle(int child_id, 57 ApplyWebSettingsResourceThrottle(int child_id,
44 int route_id, 58 int route_id,
45 net::URLRequest* request) 59 net::URLRequest* request)
46 : child_id_(child_id), 60 : child_id_(child_id),
47 route_id_(route_id), 61 route_id_(route_id),
48 request_(request) { } 62 request_(request) { }
49 virtual void WillStartRequest(bool* defer) OVERRIDE; 63 virtual void WillStartRequest(bool* defer) OVERRIDE;
50 64
51 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() { 65 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() {
52 return AwContentsIoThreadClient::FromID(child_id_, route_id_); 66 return AwContentsIoThreadClient::FromID(child_id_, route_id_);
53 } 67 }
54 68
55 private: 69 private:
56 int child_id_; 70 int child_id_;
57 int route_id_; 71 int route_id_;
58 net::URLRequest* request_; 72 net::URLRequest* request_;
59 }; 73 };
60 74
61 void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) { 75 void ApplyWebSettingsResourceThrottle::WillStartRequest(bool* defer) {
62 // If there is no IO thread client set at this point, use a 76 // If there is no IO thread client set at this point, use a
63 // restrictive policy. This can happen for blocked popup 77 // restrictive policy. This can happen for blocked popup
64 // windows for example. 78 // windows for example.
65 // TODO(benm): Revert this to a DCHECK when the we support 79 // TODO(benm): Revert this to a DCHECK when the we support
66 // pop up windows being created in the WebView, as at that 80 // pop up windows being created in the WebView, as at that
67 // time we should always have an IoThreadClient at this 81 // time we should always have an IoThreadClient at this
68 // point (i.e., the one associated with the new popup). 82 // point (i.e., the one associated with the new popup).
69 if (!GetIoThreadClient()) { 83 if (!GetIoThreadClient()) {
70 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 84 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
71 return; 85 return;
(...skipping 17 matching lines...) Expand all
89 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 103 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
90 return; 104 return;
91 } 105 }
92 } 106 }
93 107
94 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) { 108 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) {
95 if (request_->url().SchemeIs(chrome::kFtpScheme)) { 109 if (request_->url().SchemeIs(chrome::kFtpScheme)) {
96 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 110 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
97 return; 111 return;
98 } 112 }
99 SetOnlyAllowLoadFromCache(request_); 113 SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE);
114 } else {
115 AwContentsIoThreadClient::CacheMode cache_mode =
116 GetIoThreadClient()->GetCacheMode();
117 switch(cache_mode) {
118 case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK:
119 SetCacheControlFlag(request_, net::LOAD_PREFERRING_CACHE);
120 break;
121 case AwContentsIoThreadClient::LOAD_NO_CACHE:
122 SetCacheControlFlag(request_, net::LOAD_BYPASS_CACHE);
123 break;
124 case AwContentsIoThreadClient::LOAD_CACHE_ONLY:
125 SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE);
126 break;
127 default:
128 break;
129 }
100 } 130 }
101 } 131 }
102 132
103 } // namespace 133 } // namespace
104 134
105 namespace android_webview { 135 namespace android_webview {
106 136
107 // static 137 // static
108 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() { 138 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() {
109 content::ResourceDispatcherHost::Get()->SetDelegate( 139 content::ResourceDispatcherHost::Get()->SetDelegate(
(...skipping 10 matching lines...) Expand all
120 void AwResourceDispatcherHostDelegate::RequestBeginning( 150 void AwResourceDispatcherHostDelegate::RequestBeginning(
121 net::URLRequest* request, 151 net::URLRequest* request,
122 content::ResourceContext* resource_context, 152 content::ResourceContext* resource_context,
123 appcache::AppCacheService* appcache_service, 153 appcache::AppCacheService* appcache_service,
124 ResourceType::Type resource_type, 154 ResourceType::Type resource_type,
125 int child_id, 155 int child_id,
126 int route_id, 156 int route_id,
127 bool is_continuation_of_transferred_request, 157 bool is_continuation_of_transferred_request,
128 ScopedVector<content::ResourceThrottle>* throttles) { 158 ScopedVector<content::ResourceThrottle>* throttles) {
129 159
130 throttles->push_back(new MaybeCancelResourceThrottle( 160 throttles->push_back(new ApplyWebSettingsResourceThrottle(
131 child_id, route_id, request)); 161 child_id, route_id, request));
132 162
133 bool allow_intercepting = 163 bool allow_intercepting =
134 // We ignore POST requests because of BUG=155250. 164 // We ignore POST requests because of BUG=155250.
135 request->method() != "POST" && 165 request->method() != "POST" &&
136 // We allow intercepting navigations within subframes, but only if the 166 // We allow intercepting navigations within subframes, but only if the
137 // scheme other than http or https. This is because the embedder 167 // scheme other than http or https. This is because the embedder
138 // can't distinguish main frame and subframe callbacks (which could lead 168 // can't distinguish main frame and subframe callbacks (which could lead
139 // to broken content if the embedder decides to not ignore the main frame 169 // to broken content if the embedder decides to not ignore the main frame
140 // navigation, but ignores the subframe navigation). 170 // navigation, but ignores the subframe navigation).
(...skipping 26 matching lines...) Expand all
167 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url, 197 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url,
168 int child_id, 198 int child_id,
169 int route_id) { 199 int route_id) {
170 // The AwURLRequestJobFactory implementation should ensure this method never 200 // The AwURLRequestJobFactory implementation should ensure this method never
171 // gets called. 201 // gets called.
172 NOTREACHED(); 202 NOTREACHED();
173 return false; 203 return false;
174 } 204 }
175 205
176 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698