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

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: 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"
(...skipping 19 matching lines...) Expand all
30 void SetOnlyAllowLoadFromCache( 30 void SetOnlyAllowLoadFromCache(
31 net::URLRequest* request) { 31 net::URLRequest* request) {
32 int load_flags = request->load_flags(); 32 int load_flags = request->load_flags();
33 load_flags &= ~(net::LOAD_BYPASS_CACHE & 33 load_flags &= ~(net::LOAD_BYPASS_CACHE &
34 net::LOAD_VALIDATE_CACHE & 34 net::LOAD_VALIDATE_CACHE &
35 net::LOAD_PREFERRING_CACHE); 35 net::LOAD_PREFERRING_CACHE);
36 load_flags |= net::LOAD_ONLY_FROM_CACHE; 36 load_flags |= net::LOAD_ONLY_FROM_CACHE;
37 request->set_load_flags(load_flags); 37 request->set_load_flags(load_flags);
38 } 38 }
39 39
40 // May cancel this resource request based on result of Java callbacks. 40 // Enqueries certain WebSettings values, sets up the resource request
41 class MaybeCancelResourceThrottle : public content::ResourceThrottle { 41 // accordingly. May cancel the request.
42 class ApplyWebSettingsResourceThrottle : public content::ResourceThrottle {
42 public: 43 public:
43 MaybeCancelResourceThrottle(int child_id, 44 ApplyWebSettingsResourceThrottle(int child_id,
44 int route_id, 45 int route_id,
45 net::URLRequest* request) 46 net::URLRequest* request)
46 : child_id_(child_id), 47 : child_id_(child_id),
47 route_id_(route_id), 48 route_id_(route_id),
48 request_(request) { } 49 request_(request) { }
49 virtual void WillStartRequest(bool* defer) OVERRIDE; 50 virtual void WillStartRequest(bool* defer) OVERRIDE;
50 51
51 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() { 52 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() {
52 return AwContentsIoThreadClient::FromID(child_id_, route_id_); 53 return AwContentsIoThreadClient::FromID(child_id_, route_id_);
53 } 54 }
54 55
55 private: 56 private:
56 int child_id_; 57 int child_id_;
57 int route_id_; 58 int route_id_;
58 net::URLRequest* request_; 59 net::URLRequest* request_;
59 }; 60 };
60 61
61 void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) { 62 void ApplyWebSettingsResourceThrottle::WillStartRequest(bool* defer) {
62 // If there is no IO thread client set at this point, use a 63 // If there is no IO thread client set at this point, use a
63 // restrictive policy. This can happen for blocked popup 64 // restrictive policy. This can happen for blocked popup
64 // windows for example. 65 // windows for example.
65 // TODO(benm): Revert this to a DCHECK when the we support 66 // TODO(benm): Revert this to a DCHECK when the we support
66 // pop up windows being created in the WebView, as at that 67 // pop up windows being created in the WebView, as at that
67 // time we should always have an IoThreadClient at this 68 // time we should always have an IoThreadClient at this
68 // point (i.e., the one associated with the new popup). 69 // point (i.e., the one associated with the new popup).
69 if (!GetIoThreadClient()) { 70 if (!GetIoThreadClient()) {
70 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 71 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
71 return; 72 return;
72 } 73 }
73 74
75 AwContentsIoThreadClient::CacheMode cache_mode =
76 GetIoThreadClient()->GetCacheMode();
77 int load_flags = request_->load_flags();
78 switch(cache_mode) {
79 case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK:
80 load_flags |= net::LOAD_PREFERRING_CACHE;
81 load_flags &= ~net::LOAD_VALIDATE_CACHE;
82 break;
83 case AwContentsIoThreadClient::LOAD_NO_CACHE:
84 load_flags |= net::LOAD_BYPASS_CACHE;
85 break;
86 case AwContentsIoThreadClient::LOAD_CACHE_ONLY:
87 load_flags |= net::LOAD_ONLY_FROM_CACHE;
88 break;
89 default:
90 break;
91 }
92 request_->set_load_flags(load_flags);
boliu 2012/11/20 20:00:09 nit: Let's do better than existing code. I think t
mnaganov (inactive) 2012/11/21 10:37:08 Done. BTW, there was an error in SetOnlyAllowLoadF
93
74 // Part of implementation of WebSettings.allowContentAccess. 94 // Part of implementation of WebSettings.allowContentAccess.
75 if (request_->url().SchemeIs(android_webview::kContentScheme) && 95 if (request_->url().SchemeIs(android_webview::kContentScheme) &&
76 GetIoThreadClient()->ShouldBlockContentUrls()) { 96 GetIoThreadClient()->ShouldBlockContentUrls()) {
77 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 97 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
78 return; 98 return;
79 } 99 }
80 100
81 // Part of implementation of WebSettings.allowFileAccess. 101 // Part of implementation of WebSettings.allowFileAccess.
82 if (request_->url().SchemeIsFile() && 102 if (request_->url().SchemeIsFile() &&
83 GetIoThreadClient()->ShouldBlockFileUrls()) { 103 GetIoThreadClient()->ShouldBlockFileUrls()) {
84 const GURL& url = request_->url(); 104 const GURL& url = request_->url();
85 if (!url.has_path() || 105 if (!url.has_path() ||
86 // Application's assets and resources are always available. 106 // Application's assets and resources are always available.
87 (url.path().find(android_webview::kAndroidResourcePath) != 0 && 107 (url.path().find(android_webview::kAndroidResourcePath) != 0 &&
88 url.path().find(android_webview::kAndroidAssetPath) != 0)) { 108 url.path().find(android_webview::kAndroidAssetPath) != 0)) {
89 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 109 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
90 return; 110 return;
91 } 111 }
92 } 112 }
93 113
94 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) { 114 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) {
95 if (request_->url().SchemeIs(chrome::kFtpScheme)) { 115 if (request_->url().SchemeIs(chrome::kFtpScheme)) {
96 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 116 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
97 return; 117 return;
98 } 118 }
99 SetOnlyAllowLoadFromCache(request_); 119 SetOnlyAllowLoadFromCache(request_);
boliu 2012/11/20 20:00:09 Can you make sure the flags above are interacting
mnaganov (inactive) 2012/11/21 10:37:08 Added a test. In fact, setting cache mode doesn't
100 } 120 }
101 } 121 }
102 122
103 } // namespace 123 } // namespace
104 124
105 namespace android_webview { 125 namespace android_webview {
106 126
107 // static 127 // static
108 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() { 128 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() {
109 content::ResourceDispatcherHost::Get()->SetDelegate( 129 content::ResourceDispatcherHost::Get()->SetDelegate(
(...skipping 10 matching lines...) Expand all
120 void AwResourceDispatcherHostDelegate::RequestBeginning( 140 void AwResourceDispatcherHostDelegate::RequestBeginning(
121 net::URLRequest* request, 141 net::URLRequest* request,
122 content::ResourceContext* resource_context, 142 content::ResourceContext* resource_context,
123 appcache::AppCacheService* appcache_service, 143 appcache::AppCacheService* appcache_service,
124 ResourceType::Type resource_type, 144 ResourceType::Type resource_type,
125 int child_id, 145 int child_id,
126 int route_id, 146 int route_id,
127 bool is_continuation_of_transferred_request, 147 bool is_continuation_of_transferred_request,
128 ScopedVector<content::ResourceThrottle>* throttles) { 148 ScopedVector<content::ResourceThrottle>* throttles) {
129 149
130 throttles->push_back(new MaybeCancelResourceThrottle( 150 throttles->push_back(new ApplyWebSettingsResourceThrottle(
131 child_id, route_id, request)); 151 child_id, route_id, request));
132 152
133 if (resource_type == ResourceType::MAIN_FRAME) { 153 if (resource_type == ResourceType::MAIN_FRAME) {
134 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( 154 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor(
135 request)); 155 request));
136 } 156 }
137 } 157 }
138 158
139 bool AwResourceDispatcherHostDelegate::AcceptAuthRequest( 159 bool AwResourceDispatcherHostDelegate::AcceptAuthRequest(
140 net::URLRequest* request, 160 net::URLRequest* request,
(...skipping 11 matching lines...) Expand all
152 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url, 172 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url,
153 int child_id, 173 int child_id,
154 int route_id) { 174 int route_id) {
155 // The AwURLRequestJobFactory implementation should ensure this method never 175 // The AwURLRequestJobFactory implementation should ensure this method never
156 // gets called. 176 // gets called.
157 NOTREACHED(); 177 NOTREACHED();
158 return false; 178 return false;
159 } 179 }
160 180
161 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698