| OLD | NEW |
| 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" |
| 11 #include "android_webview/browser/aw_request_interceptor.h" | 11 #include "android_webview/browser/aw_request_interceptor.h" |
| 12 #include "android_webview/browser/net/aw_network_delegate.h" | 12 #include "android_webview/browser/net/aw_network_delegate.h" |
| 13 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 13 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| 14 #include "android_webview/browser/net/init_native_callback.h" | 14 #include "android_webview/browser/net/init_native_callback.h" |
| 15 #include "android_webview/common/aw_content_client.h" | 15 #include "android_webview/common/aw_content_client.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
| 20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" |
| 20 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se
rvice.h" | 21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se
rvice.h" |
| 21 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 22 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 24 #include "content/public/browser/cookie_store_factory.h" | 25 #include "content/public/browser/cookie_store_factory.h" |
| 25 #include "content/public/common/content_client.h" | 26 #include "content/public/common/content_client.h" |
| 26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 28 #include "net/base/cache_type.h" | 29 #include "net/base/cache_type.h" |
| 29 #include "net/cookies/cookie_store.h" | 30 #include "net/cookies/cookie_store.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 job_factory.Pass(), make_scoped_ptr(*i))); | 161 job_factory.Pass(), make_scoped_ptr(*i))); |
| 161 } | 162 } |
| 162 request_interceptors.weak_clear(); | 163 request_interceptors.weak_clear(); |
| 163 | 164 |
| 164 return job_factory.Pass(); | 165 return job_factory.Pass(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 } // namespace | 168 } // namespace |
| 168 | 169 |
| 169 AwURLRequestContextGetter::AwURLRequestContextGetter( | 170 AwURLRequestContextGetter::AwURLRequestContextGetter( |
| 170 const base::FilePath& partition_path, net::CookieStore* cookie_store) | 171 const base::FilePath& partition_path, net::CookieStore* cookie_store, |
| 172 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService> |
| 173 config_service) |
| 171 : partition_path_(partition_path), | 174 : partition_path_(partition_path), |
| 172 cookie_store_(cookie_store), | 175 cookie_store_(cookie_store) { |
| 173 proxy_config_service_(new DataReductionProxyConfigService( | 176 data_reduction_proxy_config_service_ = config_service.Pass(); |
| 174 scoped_ptr<net::ProxyConfigService>( | |
| 175 net::ProxyService::CreateSystemProxyConfigService( | |
| 176 GetNetworkTaskRunner(), | |
| 177 NULL /* Ignored on Android */)).Pass())) { | |
| 178 // CreateSystemProxyConfigService for Android must be called on main thread. | 177 // CreateSystemProxyConfigService for Android must be called on main thread. |
| 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 180 } | 179 } |
| 181 | 180 |
| 182 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 181 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
| 183 } | 182 } |
| 184 | 183 |
| 185 void AwURLRequestContextGetter::InitializeURLRequestContext() { | 184 void AwURLRequestContextGetter::InitializeURLRequestContext() { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 187 DCHECK(!url_request_context_); | 186 DCHECK(!url_request_context_); |
| 188 | 187 |
| 189 net::URLRequestContextBuilder builder; | 188 net::URLRequestContextBuilder builder; |
| 190 builder.set_user_agent(GetUserAgent()); | 189 builder.set_user_agent(GetUserAgent()); |
| 191 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); | 190 AwNetworkDelegate* aw_network_delegate = new AwNetworkDelegate(); |
| 192 builder.set_network_delegate(aw_network_delegate); | 191 builder.set_network_delegate(aw_network_delegate); |
| 193 #if !defined(DISABLE_FTP_SUPPORT) | 192 #if !defined(DISABLE_FTP_SUPPORT) |
| 194 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 193 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
| 195 #endif | 194 #endif |
| 196 builder.set_proxy_config_service(proxy_config_service_.release()); | 195 if (data_reduction_proxy_config_service_.get()) { |
| 196 builder.set_proxy_config_service( |
| 197 data_reduction_proxy_config_service_.release()); |
| 198 } else { |
| 199 builder.set_proxy_config_service( |
| 200 net::ProxyService::CreateSystemProxyConfigService( |
| 201 GetNetworkTaskRunner(), NULL /* Ignored on Android */ )); |
| 202 } |
| 197 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( | 203 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( |
| 198 AwContentBrowserClient::GetAcceptLangsImpl())); | 204 AwContentBrowserClient::GetAcceptLangsImpl())); |
| 199 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); | 205 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); |
| 200 | 206 |
| 201 url_request_context_.reset(builder.Build()); | 207 url_request_context_.reset(builder.Build()); |
| 202 channel_id_service_.reset( | 208 channel_id_service_.reset( |
| 203 new net::ChannelIDService( | 209 new net::ChannelIDService( |
| 204 new net::DefaultChannelIDStore(NULL), | 210 new net::DefaultChannelIDStore(NULL), |
| 205 base::WorkerPool::GetTaskRunner(true))); | 211 base::WorkerPool::GetTaskRunner(true))); |
| 206 url_request_context_->set_channel_id_service(channel_id_service_.get()); | 212 url_request_context_->set_channel_id_service(channel_id_service_.get()); |
| 207 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. | 213 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. |
| 208 net::HttpNetworkSession::Params network_session_params; | 214 net::HttpNetworkSession::Params network_session_params; |
| 209 | 215 |
| 210 PopulateNetworkSessionParams(url_request_context_.get(), | 216 PopulateNetworkSessionParams(url_request_context_.get(), |
| 211 &network_session_params); | 217 &network_session_params); |
| 212 | 218 |
| 213 net::HttpCache* main_cache = new net::HttpCache( | 219 net::HttpCache* main_cache = new net::HttpCache( |
| 214 network_session_params, | 220 network_session_params, |
| 215 new net::HttpCache::DefaultBackend( | 221 new net::HttpCache::DefaultBackend( |
| 216 net::DISK_CACHE, | 222 net::DISK_CACHE, |
| 217 net::CACHE_BACKEND_SIMPLE, | 223 net::CACHE_BACKEND_SIMPLE, |
| 218 partition_path_.Append(FILE_PATH_LITERAL("Cache")), | 224 partition_path_.Append(FILE_PATH_LITERAL("Cache")), |
| 219 20 * 1024 * 1024, // 20M | 225 20 * 1024 * 1024, // 20M |
| 220 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 226 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
| 221 | 227 |
| 222 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 228 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 223 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); | 229 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); |
| 224 DCHECK(browser_context); | 230 DCHECK(browser_context); |
| 225 DataReductionProxySettings* drp_settings = | 231 DataReductionProxySettings* data_reduction_proxy_settings = |
| 226 browser_context->GetDataReductionProxySettings(); | 232 browser_context->GetDataReductionProxySettings(); |
| 227 if (drp_settings) { | 233 DCHECK(data_reduction_proxy_settings); |
| 228 aw_network_delegate->set_data_reduction_proxy_params( | 234 data_reduction_proxy_auth_request_handler_.reset( |
| 229 drp_settings->params()); | 235 new data_reduction_proxy::DataReductionProxyAuthRequestHandler( |
| 230 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( | 236 data_reduction_proxy::kClientAndroidWebview, |
| 231 browser_context->GetDataReductionProxyAuthRequestHandler()); | 237 data_reduction_proxy::kAndroidWebViewProtocolVersion, |
| 232 } | 238 data_reduction_proxy_settings->params(), |
| 239 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 240 |
| 241 aw_network_delegate->set_data_reduction_proxy_params( |
| 242 data_reduction_proxy_settings->params()); |
| 243 aw_network_delegate->set_data_reduction_proxy_auth_request_handler( |
| 244 data_reduction_proxy_auth_request_handler_.get()); |
| 233 #endif | 245 #endif |
| 234 | 246 |
| 235 main_http_factory_.reset(main_cache); | 247 main_http_factory_.reset(main_cache); |
| 236 url_request_context_->set_http_transaction_factory(main_cache); | 248 url_request_context_->set_http_transaction_factory(main_cache); |
| 237 url_request_context_->set_cookie_store(cookie_store_); | 249 url_request_context_->set_cookie_store(cookie_store_); |
| 238 | 250 |
| 239 job_factory_ = CreateJobFactory(&protocol_handlers_, | 251 job_factory_ = CreateJobFactory(&protocol_handlers_, |
| 240 request_interceptors_.Pass()); | 252 request_interceptors_.Pass()); |
| 241 url_request_context_->set_job_factory(job_factory_.get()); | 253 url_request_context_->set_job_factory(job_factory_.get()); |
| 242 } | 254 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 266 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 255 } | 267 } |
| 256 | 268 |
| 257 void AwURLRequestContextGetter::SetHandlersAndInterceptors( | 269 void AwURLRequestContextGetter::SetHandlersAndInterceptors( |
| 258 content::ProtocolHandlerMap* protocol_handlers, | 270 content::ProtocolHandlerMap* protocol_handlers, |
| 259 content::URLRequestInterceptorScopedVector request_interceptors) { | 271 content::URLRequestInterceptorScopedVector request_interceptors) { |
| 260 std::swap(protocol_handlers_, *protocol_handlers); | 272 std::swap(protocol_handlers_, *protocol_handlers); |
| 261 request_interceptors_.swap(request_interceptors); | 273 request_interceptors_.swap(request_interceptors); |
| 262 } | 274 } |
| 263 | 275 |
| 264 DataReductionProxyConfigService* | 276 data_reduction_proxy::DataReductionProxyAuthRequestHandler* |
| 265 AwURLRequestContextGetter::proxy_config_service() { | 277 AwURLRequestContextGetter::GetDataReductionProxyAuthRequestHandler() const { |
| 266 // TODO(bengr): return system config if data reduction proxy is disabled. | 278 return data_reduction_proxy_auth_request_handler_.get(); |
| 267 return proxy_config_service_.get(); | |
| 268 } | 279 } |
| 269 | 280 |
| 270 } // namespace android_webview | 281 } // namespace android_webview |
| OLD | NEW |