OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/crnet/crnet_environment.h" | 5 #include "ios/crnet/crnet_environment.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 GetHttpNetworkSession(GetMainContextGetter()->GetURLRequestContext()); | 257 GetHttpNetworkSession(GetMainContextGetter()->GetURLRequestContext()); |
258 | 258 |
259 if (http_network_session) { | 259 if (http_network_session) { |
260 net::SpdySessionPool *spdy_session_pool = | 260 net::SpdySessionPool *spdy_session_pool = |
261 http_network_session->spdy_session_pool(); | 261 http_network_session->spdy_session_pool(); |
262 if (spdy_session_pool) | 262 if (spdy_session_pool) |
263 spdy_session_pool->CloseCurrentSessions(net::ERR_ABORTED); | 263 spdy_session_pool->CloseCurrentSessions(net::ERR_ABORTED); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 CrNetEnvironment::CrNetEnvironment(const std::string& user_agent_product_name) | 267 CrNetEnvironment::CrNetEnvironment(const std::string& user_agent, |
| 268 bool user_agent_partial) |
268 : spdy_enabled_(false), | 269 : spdy_enabled_(false), |
269 quic_enabled_(false), | 270 quic_enabled_(false), |
270 sdch_enabled_(false), | 271 sdch_enabled_(false), |
271 main_context_(new net::URLRequestContext), | 272 main_context_(new net::URLRequestContext), |
272 user_agent_product_name_(user_agent_product_name), | 273 user_agent_(user_agent), |
| 274 user_agent_partial_(user_agent_partial), |
273 net_log_(new net::NetLog) {} | 275 net_log_(new net::NetLog) {} |
274 | 276 |
275 void CrNetEnvironment::Install() { | 277 void CrNetEnvironment::Install() { |
276 // Threads setup. | 278 // Threads setup. |
277 network_cache_thread_.reset(new base::Thread("Chrome Network Cache Thread")); | 279 network_cache_thread_.reset(new base::Thread("Chrome Network Cache Thread")); |
278 network_cache_thread_->StartWithOptions( | 280 network_cache_thread_->StartWithOptions( |
279 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 281 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
280 network_io_thread_.reset(new base::Thread("Chrome Network IO Thread")); | 282 network_io_thread_.reset(new base::Thread("Chrome Network IO Thread")); |
281 network_io_thread_->StartWithOptions( | 283 network_io_thread_->StartWithOptions( |
282 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 284 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 @"Localizable", | 377 @"Localizable", |
376 bundle, | 378 bundle, |
377 @"en-US,en", | 379 @"en-US,en", |
378 @"These values are copied from Chrome's .xtb files, so the same " | 380 @"These values are copied from Chrome's .xtb files, so the same " |
379 "values are used in the |Accept-Language| header. Key name matches " | 381 "values are used in the |Accept-Language| header. Key name matches " |
380 "Chrome's."); | 382 "Chrome's."); |
381 if (acceptableLanguages == Nil) | 383 if (acceptableLanguages == Nil) |
382 acceptableLanguages = @"en-US,en"; | 384 acceptableLanguages = @"en-US,en"; |
383 std::string acceptable_languages = | 385 std::string acceptable_languages = |
384 [acceptableLanguages cStringUsingEncoding:NSUTF8StringEncoding]; | 386 [acceptableLanguages cStringUsingEncoding:NSUTF8StringEncoding]; |
385 std::string user_agent = | 387 if (user_agent_partial_) { |
386 web::BuildUserAgentFromProduct(user_agent_product_name_); | 388 user_agent_ = web::BuildUserAgentFromProduct(user_agent_); |
| 389 user_agent_partial_ = false; |
| 390 } |
387 // Set the user agent through NSUserDefaults. This sets it for both | 391 // Set the user agent through NSUserDefaults. This sets it for both |
388 // UIWebViews and WKWebViews, and javascript calls to navigator.userAgent | 392 // UIWebViews and WKWebViews, and javascript calls to navigator.userAgent |
389 // return this value. | 393 // return this value. |
390 [[NSUserDefaults standardUserDefaults] registerDefaults:@{ | 394 [[NSUserDefaults standardUserDefaults] registerDefaults:@{ |
391 @"UserAgent" : [NSString stringWithUTF8String:user_agent.c_str()] | 395 @"UserAgent" : [NSString stringWithUTF8String:user_agent_.c_str()] |
392 }]; | 396 }]; |
393 main_context_->set_http_user_agent_settings( | 397 main_context_->set_http_user_agent_settings( |
394 new net::StaticHttpUserAgentSettings(acceptable_languages, user_agent)); | 398 new net::StaticHttpUserAgentSettings(acceptable_languages, user_agent_)); |
395 | 399 |
396 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | 400 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
397 main_context_->set_transport_security_state( | 401 main_context_->set_transport_security_state( |
398 new net::TransportSecurityState()); | 402 new net::TransportSecurityState()); |
399 main_context_->set_cert_transparency_verifier(new net::MultiLogCTVerifier()); | 403 main_context_->set_cert_transparency_verifier(new net::MultiLogCTVerifier()); |
400 main_context_->set_ct_policy_enforcer(new net::CTPolicyEnforcer()); | 404 main_context_->set_ct_policy_enforcer(new net::CTPolicyEnforcer()); |
401 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); | 405 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); |
402 main_context_->set_http_server_properties(http_server_properties_.get()); | 406 main_context_->set_http_server_properties(http_server_properties_.get()); |
403 // TODO(rdsmith): Note that the ".release()" calls below are leaking | 407 // TODO(rdsmith): Note that the ".release()" calls below are leaking |
404 // the objects in question; this should be fixed by having an object | 408 // the objects in question; this should be fixed by having an object |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 497 |
494 return user_agent_settings->GetUserAgent(); | 498 return user_agent_settings->GetUserAgent(); |
495 } | 499 } |
496 | 500 |
497 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 501 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
498 PostToNetworkThread( | 502 PostToNetworkThread( |
499 FROM_HERE, | 503 FROM_HERE, |
500 base::Bind(&net::ClearHttpCache, main_context_getter_, | 504 base::Bind(&net::ClearHttpCache, main_context_getter_, |
501 network_io_thread_->task_runner(), base::BindBlock(callback))); | 505 network_io_thread_->task_runner(), base::BindBlock(callback))); |
502 } | 506 } |
OLD | NEW |