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

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

Issue 1172093002: Implement HttpUserAgentSettings delegate for Android WebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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
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"
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_http_user_agent_settings.h"
12 #include "android_webview/browser/net/aw_network_delegate.h" 13 #include "android_webview/browser/net/aw_network_delegate.h"
13 #include "android_webview/browser/net/aw_url_request_job_factory.h" 14 #include "android_webview/browser/net/aw_url_request_job_factory.h"
14 #include "android_webview/browser/net/init_native_callback.h" 15 #include "android_webview/browser/net/init_native_callback.h"
15 #include "android_webview/common/aw_content_client.h" 16 #include "android_webview/common/aw_content_client.h"
16 #include "base/bind.h" 17 #include "base/bind.h"
17 #include "base/command_line.h" 18 #include "base/command_line.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
20 #include "base/threading/worker_pool.h" 21 #include "base/threading/worker_pool.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 174
174 } // namespace 175 } // namespace
175 176
176 AwURLRequestContextGetter::AwURLRequestContextGetter( 177 AwURLRequestContextGetter::AwURLRequestContextGetter(
177 const base::FilePath& cache_path, net::CookieStore* cookie_store, 178 const base::FilePath& cache_path, net::CookieStore* cookie_store,
178 scoped_ptr<net::ProxyConfigService> config_service) 179 scoped_ptr<net::ProxyConfigService> config_service)
179 : cache_path_(cache_path), 180 : cache_path_(cache_path),
180 cookie_store_(cookie_store), 181 cookie_store_(cookie_store),
181 net_log_(new net::NetLog()) { 182 net_log_(new net::NetLog()) {
182 proxy_config_service_ = config_service.Pass(); 183 proxy_config_service_ = config_service.Pass();
184 http_user_agent_settings_.reset(
185 new AwHttpUserAgentSettings());
183 // CreateSystemProxyConfigService for Android must be called on main thread. 186 // CreateSystemProxyConfigService for Android must be called on main thread.
184 DCHECK_CURRENTLY_ON(BrowserThread::UI); 187 DCHECK_CURRENTLY_ON(BrowserThread::UI);
185 } 188 }
186 189
187 AwURLRequestContextGetter::~AwURLRequestContextGetter() { 190 AwURLRequestContextGetter::~AwURLRequestContextGetter() {
188 } 191 }
189 192
190 void AwURLRequestContextGetter::InitializeURLRequestContext() { 193 void AwURLRequestContextGetter::InitializeURLRequestContext() {
191 DCHECK_CURRENTLY_ON(BrowserThread::IO); 194 DCHECK_CURRENTLY_ON(BrowserThread::IO);
192 DCHECK(!url_request_context_); 195 DCHECK(!url_request_context_);
193 196
194 net::URLRequestContextBuilder builder; 197 net::URLRequestContextBuilder builder;
195 builder.set_user_agent(GetUserAgent());
196 scoped_ptr<AwNetworkDelegate> aw_network_delegate(new AwNetworkDelegate()); 198 scoped_ptr<AwNetworkDelegate> aw_network_delegate(new AwNetworkDelegate());
197 199
198 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); 200 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
199 DCHECK(browser_context); 201 DCHECK(browser_context);
200 202
201 builder.set_network_delegate( 203 builder.set_network_delegate(
202 browser_context->GetDataReductionProxyIOData()->CreateNetworkDelegate( 204 browser_context->GetDataReductionProxyIOData()->CreateNetworkDelegate(
203 aw_network_delegate.Pass(), 205 aw_network_delegate.Pass(),
204 false /* No UMA is produced to track bypasses. */ ).release()); 206 false /* No UMA is produced to track bypasses. */ ).release());
205 #if !defined(DISABLE_FTP_SUPPORT) 207 #if !defined(DISABLE_FTP_SUPPORT)
206 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. 208 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet.
207 #endif 209 #endif
208 DCHECK(proxy_config_service_.get()); 210 DCHECK(proxy_config_service_.get());
209 // Android provides a local HTTP proxy that handles all the proxying. 211 // Android provides a local HTTP proxy that handles all the proxying.
210 // Create the proxy without a resolver since we rely on this local HTTP proxy. 212 // Create the proxy without a resolver since we rely on this local HTTP proxy.
211 // TODO(sgurun) is this behavior guaranteed through SDK? 213 // TODO(sgurun) is this behavior guaranteed through SDK?
212 builder.set_proxy_service( 214 builder.set_proxy_service(
213 net::ProxyService::CreateWithoutProxyResolver( 215 net::ProxyService::CreateWithoutProxyResolver(
214 proxy_config_service_.release(), 216 proxy_config_service_.release(),
215 net_log_.get())); 217 net_log_.get()));
216 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader(
217 AwContentBrowserClient::GetAcceptLangsImpl()));
218 builder.set_net_log(net_log_.get()); 218 builder.set_net_log(net_log_.get());
219 builder.SetCookieAndChannelIdStores(cookie_store_, NULL); 219 builder.SetCookieAndChannelIdStores(cookie_store_, NULL);
220 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); 220 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder);
221 221
222 url_request_context_.reset(builder.Build()); 222 url_request_context_.reset(builder.Build());
223 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. 223 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads.
224 net::HttpNetworkSession::Params network_session_params; 224 net::HttpNetworkSession::Params network_session_params;
225 225
226 PopulateNetworkSessionParams(url_request_context_.get(), 226 PopulateNetworkSessionParams(url_request_context_.get(),
227 &network_session_params); 227 &network_session_params);
(...skipping 10 matching lines...) Expand all
238 main_http_factory_.reset(main_cache); 238 main_http_factory_.reset(main_cache);
239 url_request_context_->set_http_transaction_factory(main_cache); 239 url_request_context_->set_http_transaction_factory(main_cache);
240 240
241 job_factory_ = CreateJobFactory(&protocol_handlers_, 241 job_factory_ = CreateJobFactory(&protocol_handlers_,
242 request_interceptors_.Pass()); 242 request_interceptors_.Pass());
243 243
244 job_factory_.reset(new net::URLRequestInterceptingJobFactory( 244 job_factory_.reset(new net::URLRequestInterceptingJobFactory(
245 job_factory_.Pass(), 245 job_factory_.Pass(),
246 browser_context->GetDataReductionProxyIOData()->CreateInterceptor())); 246 browser_context->GetDataReductionProxyIOData()->CreateInterceptor()));
247 url_request_context_->set_job_factory(job_factory_.get()); 247 url_request_context_->set_job_factory(job_factory_.get());
248 url_request_context_->set_http_user_agent_settings(
249 http_user_agent_settings_.get());
248 } 250 }
249 251
250 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { 252 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() {
251 DCHECK_CURRENTLY_ON(BrowserThread::IO); 253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
252 if (!url_request_context_) 254 if (!url_request_context_)
253 InitializeURLRequestContext(); 255 InitializeURLRequestContext();
254 256
255 return url_request_context_.get(); 257 return url_request_context_.get();
256 } 258 }
257 259
(...skipping 13 matching lines...) Expand all
271 return net_log_.get(); 273 return net_log_.get();
272 } 274 }
273 275
274 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { 276 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) {
275 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()); 277 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData());
276 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()-> 278 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()->
277 request_options()->SetKeyOnIO(key); 279 request_options()->SetKeyOnIO(key);
278 } 280 }
279 281
280 } // namespace android_webview 282 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698