| 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 "components/cronet/android/cronet_url_request_context_adapter.h" | 5 #include "components/cronet/android/cronet_url_request_context_adapter.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/metrics/statistics_recorder.h" | 19 #include "base/metrics/statistics_recorder.h" |
| 19 #include "base/prefs/pref_filter.h" | 20 #include "base/prefs/pref_filter.h" |
| 20 #include "base/prefs/pref_registry_simple.h" | 21 #include "base/prefs/pref_registry_simple.h" |
| 21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
| 22 #include "base/prefs/pref_service_factory.h" | 23 #include "base/prefs/pref_service_factory.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( | 310 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( |
| 310 new net::HttpServerPropertiesManager(pref_service_.get(), | 311 new net::HttpServerPropertiesManager(pref_service_.get(), |
| 311 kHttpServerProperties, | 312 kHttpServerProperties, |
| 312 GetNetworkTaskRunner())); | 313 GetNetworkTaskRunner())); |
| 313 http_server_properties_manager->InitializeOnNetworkThread(); | 314 http_server_properties_manager->InitializeOnNetworkThread(); |
| 314 http_server_properties_manager_ = http_server_properties_manager.get(); | 315 http_server_properties_manager_ = http_server_properties_manager.get(); |
| 315 context_builder.SetHttpServerProperties( | 316 context_builder.SetHttpServerProperties( |
| 316 http_server_properties_manager.Pass()); | 317 http_server_properties_manager.Pass()); |
| 317 } | 318 } |
| 318 | 319 |
| 320 // Explicitly disable the persister for Cronet to avoid persistence of dynamic |
| 321 // HPKP. This is a safety measure ensuring that nobody enables the persistence |
| 322 // of HPKP by specifying transport_security_persister_path in the future. |
| 323 context_builder.set_transport_security_persister_path(base::FilePath()); |
| 324 |
| 319 context_ = context_builder.Build().Pass(); | 325 context_ = context_builder.Build().Pass(); |
| 320 | 326 |
| 321 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 327 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 322 net::LOAD_DO_NOT_SEND_COOKIES; | 328 net::LOAD_DO_NOT_SEND_COOKIES; |
| 323 if (config->load_disable_cache) | 329 if (config->load_disable_cache) |
| 324 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 330 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 325 | 331 |
| 326 if (config->enable_sdch) { | 332 if (config->enable_sdch) { |
| 327 DCHECK(context_->sdch_manager()); | 333 DCHECK(context_->sdch_manager()); |
| 328 sdch_owner_.reset( | 334 sdch_owner_.reset( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 quic_hint.port); | 375 quic_hint.port); |
| 370 net::AlternativeService alternative_service( | 376 net::AlternativeService alternative_service( |
| 371 net::AlternateProtocol::QUIC, "", | 377 net::AlternateProtocol::QUIC, "", |
| 372 static_cast<uint16>(quic_hint.alternate_port)); | 378 static_cast<uint16>(quic_hint.alternate_port)); |
| 373 context_->http_server_properties()->SetAlternativeService( | 379 context_->http_server_properties()->SetAlternativeService( |
| 374 quic_hint_host_port_pair, alternative_service, 1.0f, | 380 quic_hint_host_port_pair, alternative_service, 1.0f, |
| 375 base::Time::Max()); | 381 base::Time::Max()); |
| 376 } | 382 } |
| 377 } | 383 } |
| 378 | 384 |
| 385 // Iterate through PKP configuration for every host. |
| 386 for (const auto& pkp : config->pkp_list) { |
| 387 // Convert the vector of hash strings from the config to |
| 388 // a vector of HashValue objects. |
| 389 net::HashValueVector hash_value_vector; |
| 390 for (const auto& hash : pkp->pin_hashes) { |
| 391 net::HashValue hash_value; |
| 392 bool good_hash = hash_value.FromString(*hash); |
| 393 if (good_hash) { |
| 394 hash_value_vector.push_back(hash_value); |
| 395 } else { |
| 396 LOG(WARNING) << "Unable to add hash value " << *hash; |
| 397 } |
| 398 } |
| 399 |
| 400 // Add the host pinning. |
| 401 context_->transport_security_state()->AddHPKP( |
| 402 pkp->host, pkp->expiration_date, pkp->include_subdomains, |
| 403 hash_value_vector, GURL::EmptyGURL()); |
| 404 } |
| 405 |
| 379 JNIEnv* env = base::android::AttachCurrentThread(); | 406 JNIEnv* env = base::android::AttachCurrentThread(); |
| 380 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); | 407 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); |
| 381 Java_CronetUrlRequestContext_initNetworkThread( | 408 Java_CronetUrlRequestContext_initNetworkThread( |
| 382 env, jcronet_url_request_context.obj()); | 409 env, jcronet_url_request_context.obj()); |
| 383 | 410 |
| 384 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 411 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 385 if (data_reduction_proxy_) | 412 if (data_reduction_proxy_) |
| 386 data_reduction_proxy_->Init(true, GetURLRequestContext()); | 413 data_reduction_proxy_->Init(true, GetURLRequestContext()); |
| 387 #endif | 414 #endif |
| 388 is_context_initialized_ = true; | 415 is_context_initialized_ = true; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 JNIEnv* env, | 578 JNIEnv* env, |
| 552 const JavaParamRef<jclass>& jcaller) { | 579 const JavaParamRef<jclass>& jcaller) { |
| 553 base::StatisticsRecorder::Initialize(); | 580 base::StatisticsRecorder::Initialize(); |
| 554 std::vector<uint8> data; | 581 std::vector<uint8> data; |
| 555 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 582 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 556 return ScopedJavaLocalRef<jbyteArray>(); | 583 return ScopedJavaLocalRef<jbyteArray>(); |
| 557 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 584 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 558 } | 585 } |
| 559 | 586 |
| 560 } // namespace cronet | 587 } // namespace cronet |
| OLD | NEW |