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

Side by Side Diff: android_webview/browser/net/aw_url_request_context_getter.cc

Issue 294023015: Hook up request interceptors in AndroidWebView code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 6 years, 6 months 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
« no previous file with comments | « android_webview/browser/net/aw_url_request_context_getter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/net/aw_url_request_context_getter.h" 5 #include "android_webview/browser/net/aw_url_request_context_getter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "android_webview/browser/aw_browser_context.h" 9 #include "android_webview/browser/aw_browser_context.h"
10 #include "android_webview/browser/aw_content_browser_client.h" 10 #include "android_webview/browser/aw_content_browser_client.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 params->net_log = context->net_log(); 94 params->net_log = context->net_log();
95 95
96 // TODO(sgurun) remove once crbug.com/329681 is fixed. 96 // TODO(sgurun) remove once crbug.com/329681 is fixed.
97 params->next_protos = net::NextProtosSpdy31(); 97 params->next_protos = net::NextProtosSpdy31();
98 params->use_alternate_protocols = true; 98 params->use_alternate_protocols = true;
99 99
100 ApplyCmdlineOverridesToNetworkSessionParams(params); 100 ApplyCmdlineOverridesToNetworkSessionParams(params);
101 } 101 }
102 102
103 scoped_ptr<net::URLRequestJobFactory> CreateJobFactory( 103 scoped_ptr<net::URLRequestJobFactory> CreateJobFactory(
104 content::ProtocolHandlerMap* protocol_handlers) { 104 content::ProtocolHandlerMap* protocol_handlers,
105 content::URLRequestInterceptorScopedVector request_interceptors) {
105 scoped_ptr<AwURLRequestJobFactory> aw_job_factory(new AwURLRequestJobFactory); 106 scoped_ptr<AwURLRequestJobFactory> aw_job_factory(new AwURLRequestJobFactory);
106 bool set_protocol = aw_job_factory->SetProtocolHandler( 107 bool set_protocol = aw_job_factory->SetProtocolHandler(
107 url::kFileScheme, 108 url::kFileScheme,
108 new net::FileProtocolHandler( 109 new net::FileProtocolHandler(
109 content::BrowserThread::GetBlockingPool()-> 110 content::BrowserThread::GetBlockingPool()->
110 GetTaskRunnerWithShutdownBehavior( 111 GetTaskRunnerWithShutdownBehavior(
111 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); 112 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
112 DCHECK(set_protocol); 113 DCHECK(set_protocol);
113 set_protocol = aw_job_factory->SetProtocolHandler( 114 set_protocol = aw_job_factory->SetProtocolHandler(
114 url::kDataScheme, new net::DataProtocolHandler()); 115 url::kDataScheme, new net::DataProtocolHandler());
115 DCHECK(set_protocol); 116 DCHECK(set_protocol);
116 set_protocol = aw_job_factory->SetProtocolHandler( 117 set_protocol = aw_job_factory->SetProtocolHandler(
117 url::kBlobScheme, 118 url::kBlobScheme,
118 (*protocol_handlers)[url::kBlobScheme].release()); 119 (*protocol_handlers)[url::kBlobScheme].release());
119 DCHECK(set_protocol); 120 DCHECK(set_protocol);
120 set_protocol = aw_job_factory->SetProtocolHandler( 121 set_protocol = aw_job_factory->SetProtocolHandler(
121 url::kFileSystemScheme, 122 url::kFileSystemScheme,
122 (*protocol_handlers)[url::kFileSystemScheme].release()); 123 (*protocol_handlers)[url::kFileSystemScheme].release());
123 DCHECK(set_protocol); 124 DCHECK(set_protocol);
124 set_protocol = aw_job_factory->SetProtocolHandler( 125 set_protocol = aw_job_factory->SetProtocolHandler(
125 content::kChromeUIScheme, 126 content::kChromeUIScheme,
126 (*protocol_handlers)[content::kChromeUIScheme].release()); 127 (*protocol_handlers)[content::kChromeUIScheme].release());
127 DCHECK(set_protocol); 128 DCHECK(set_protocol);
128 set_protocol = aw_job_factory->SetProtocolHandler( 129 set_protocol = aw_job_factory->SetProtocolHandler(
129 content::kChromeDevToolsScheme, 130 content::kChromeDevToolsScheme,
130 (*protocol_handlers)[content::kChromeDevToolsScheme].release()); 131 (*protocol_handlers)[content::kChromeDevToolsScheme].release());
131 DCHECK(set_protocol); 132 DCHECK(set_protocol);
132 protocol_handlers->clear(); 133 protocol_handlers->clear();
133 134
134 // Create a chain of URLRequestJobFactories. The handlers will be invoked
135 // in the order in which they appear in the |request_interceptors| vector.
136 typedef std::vector<net::URLRequestInterceptor*>
137 URLRequestInterceptorVector;
138 URLRequestInterceptorVector request_interceptors;
139
140 // Note that even though the content:// scheme handler is created here, 135 // Note that even though the content:// scheme handler is created here,
141 // it cannot be used by child processes until access to it is granted via 136 // it cannot be used by child processes until access to it is granted via
142 // ChildProcessSecurityPolicy::GrantScheme(). This is done in 137 // ChildProcessSecurityPolicy::GrantScheme(). This is done in
143 // AwContentBrowserClient. 138 // AwContentBrowserClient.
144 request_interceptors.push_back( 139 request_interceptors.push_back(
145 CreateAndroidContentRequestInterceptor().release()); 140 CreateAndroidContentRequestInterceptor().release());
146 request_interceptors.push_back( 141 request_interceptors.push_back(
147 CreateAndroidAssetFileRequestInterceptor().release()); 142 CreateAndroidAssetFileRequestInterceptor().release());
148 // The AwRequestInterceptor must come after the content and asset file job 143 // The AwRequestInterceptor must come after the content and asset file job
149 // factories. This for WebViewClassic compatibility where it was not 144 // factories. This for WebViewClassic compatibility where it was not
150 // possible to intercept resource loads to resolvable content:// and 145 // possible to intercept resource loads to resolvable content:// and
151 // file:// URIs. 146 // file:// URIs.
152 // This logical dependency is also the reason why the Content 147 // This logical dependency is also the reason why the Content
153 // URLRequestInterceptor has to be added as an interceptor rather than as a 148 // URLRequestInterceptor has to be added as an interceptor rather than as a
154 // ProtocolHandler. 149 // ProtocolHandler.
155 request_interceptors.push_back(new AwRequestInterceptor()); 150 request_interceptors.push_back(new AwRequestInterceptor());
156 151
157 // The chain of responsibility will execute the handlers in reverse to the 152 // The chain of responsibility will execute the handlers in reverse to the
158 // order in which the elements of the chain are created. 153 // order in which the elements of the chain are created.
159 scoped_ptr<net::URLRequestJobFactory> job_factory(aw_job_factory.Pass()); 154 scoped_ptr<net::URLRequestJobFactory> job_factory(aw_job_factory.Pass());
160 for (URLRequestInterceptorVector::reverse_iterator 155 for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
161 i = request_interceptors.rbegin(); 156 request_interceptors.rbegin();
162 i != request_interceptors.rend(); 157 i != request_interceptors.rend();
163 ++i) { 158 ++i) {
164 job_factory.reset(new net::URLRequestInterceptingJobFactory( 159 job_factory.reset(new net::URLRequestInterceptingJobFactory(
165 job_factory.Pass(), make_scoped_ptr(*i))); 160 job_factory.Pass(), make_scoped_ptr(*i)));
166 } 161 }
162 request_interceptors.weak_clear();
167 163
168 return job_factory.Pass(); 164 return job_factory.Pass();
169 } 165 }
170 166
171 } // namespace 167 } // namespace
172 168
173 AwURLRequestContextGetter::AwURLRequestContextGetter( 169 AwURLRequestContextGetter::AwURLRequestContextGetter(
174 const base::FilePath& partition_path, net::CookieStore* cookie_store) 170 const base::FilePath& partition_path, net::CookieStore* cookie_store)
175 : partition_path_(partition_path), 171 : partition_path_(partition_path),
176 cookie_store_(cookie_store), 172 cookie_store_(cookie_store),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 DataReductionProxySettings::InitDataReductionProxySession( 235 DataReductionProxySettings::InitDataReductionProxySession(
240 main_cache->GetSession(), &drp_params); 236 main_cache->GetSession(), &drp_params);
241 } 237 }
242 } 238 }
243 #endif 239 #endif
244 240
245 main_http_factory_.reset(main_cache); 241 main_http_factory_.reset(main_cache);
246 url_request_context_->set_http_transaction_factory(main_cache); 242 url_request_context_->set_http_transaction_factory(main_cache);
247 url_request_context_->set_cookie_store(cookie_store_); 243 url_request_context_->set_cookie_store(cookie_store_);
248 244
249 job_factory_ = CreateJobFactory(&protocol_handlers_); 245 job_factory_ = CreateJobFactory(&protocol_handlers_,
246 request_interceptors_.Pass());
250 url_request_context_->set_job_factory(job_factory_.get()); 247 url_request_context_->set_job_factory(job_factory_.get());
251 } 248 }
252 249
253 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { 250 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
255 if (!url_request_context_) 252 if (!url_request_context_)
256 InitializeURLRequestContext(); 253 InitializeURLRequestContext();
257 254
258 return url_request_context_.get(); 255 return url_request_context_.get();
259 } 256 }
260 257
261 scoped_refptr<base::SingleThreadTaskRunner> 258 scoped_refptr<base::SingleThreadTaskRunner>
262 AwURLRequestContextGetter::GetNetworkTaskRunner() const { 259 AwURLRequestContextGetter::GetNetworkTaskRunner() const {
263 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 260 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
264 } 261 }
265 262
266 void AwURLRequestContextGetter::SetProtocolHandlers( 263 void AwURLRequestContextGetter::SetHandlersAndInterceptors(
267 content::ProtocolHandlerMap* protocol_handlers) { 264 content::ProtocolHandlerMap* protocol_handlers,
265 content::URLRequestInterceptorScopedVector request_interceptors) {
268 std::swap(protocol_handlers_, *protocol_handlers); 266 std::swap(protocol_handlers_, *protocol_handlers);
267 request_interceptors_.swap(request_interceptors);
269 } 268 }
270 269
271 DataReductionProxyConfigService* 270 DataReductionProxyConfigService*
272 AwURLRequestContextGetter::proxy_config_service() { 271 AwURLRequestContextGetter::proxy_config_service() {
273 // TODO(bengr): return system config if data reduction proxy is disabled. 272 // TODO(bengr): return system config if data reduction proxy is disabled.
274 return proxy_config_service_.get(); 273 return proxy_config_service_.get();
275 } 274 }
276 275
277 } // namespace android_webview 276 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/net/aw_url_request_context_getter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698