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

Unified Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 1429863008: [Cronet] Remove JSON serialization of CronetEngine.Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add PKP Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_context_adapter.cc
diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
index 686119748bee65a4ae6c4817f287947cca25f2a9..8ec95d15484bab363e876a89daf5e820c160c16f 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -32,6 +32,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/base/network_delegate_impl.h"
+#include "net/cert/cert_verifier.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_server_properties_manager.h"
#include "net/log/write_to_file_net_log_observer.h"
@@ -384,23 +385,10 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
// Iterate through PKP configuration for every host.
for (const auto& pkp : config->pkp_list) {
- // Convert the vector of hash strings from the config to
- // a vector of HashValue objects.
- net::HashValueVector hash_value_vector;
- for (const auto& hash : pkp->pin_hashes) {
- net::HashValue hash_value;
- bool good_hash = hash_value.FromString(*hash);
- if (good_hash) {
- hash_value_vector.push_back(hash_value);
- } else {
- LOG(WARNING) << "Unable to add hash value " << *hash;
- }
- }
-
// Add the host pinning.
context_->transport_security_state()->AddHPKP(
pkp->host, pkp->expiration_date, pkp->include_subdomains,
- hash_value_vector, GURL::EmptyGURL());
+ pkp->pin_hashes, GURL::EmptyGURL());
}
JNIEnv* env = base::android::AttachCurrentThread();
@@ -548,17 +536,93 @@ void CronetURLRequestContextAdapter::OnThroughputObservation(
(timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), source);
}
+// Create a URLRequestContextConfig from the given parameters.
+static jlong CreateRequestContextConfig(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& jcaller,
+ const JavaParamRef<jstring>& juser_agent,
+ const JavaParamRef<jstring>& jstorage_path,
+ jboolean jquic_enabled,
+ jboolean jhttp2_enabled,
+ jboolean jsdch_enabled,
+ const JavaParamRef<jstring>& jdata_reduction_proxy_key,
+ const JavaParamRef<jstring>& jdata_reduction_proxy_primary_proxy,
+ const JavaParamRef<jstring>& jdata_reduction_proxy_fallback_proxy,
+ const JavaParamRef<jstring>& jdata_reduction_proxy_secure_proxy_check_url,
+ jboolean jdisable_cache,
+ jint jhttp_cache_mode,
+ jlong jhttp_cache_max_size,
+ const JavaParamRef<jstring>& jexperimental_quic_connection_options,
+ jlong jmock_cert_verifier) {
+ return reinterpret_cast<jlong>(new URLRequestContextConfig(
+ jquic_enabled, jhttp2_enabled, jsdch_enabled,
+ static_cast<URLRequestContextConfig::HttpCacheType>(jhttp_cache_mode),
+ jhttp_cache_max_size, jdisable_cache,
+ base::android::ConvertJavaStringToUTF8(env, jstorage_path),
+ base::android::ConvertJavaStringToUTF8(env, juser_agent),
+ base::android::ConvertJavaStringToUTF8(
+ env, jexperimental_quic_connection_options),
+ base::android::ConvertJavaStringToUTF8(env, jdata_reduction_proxy_key),
+ base::android::ConvertJavaStringToUTF8(
+ env, jdata_reduction_proxy_primary_proxy),
+ base::android::ConvertJavaStringToUTF8(
+ env, jdata_reduction_proxy_fallback_proxy),
+ base::android::ConvertJavaStringToUTF8(
+ env, jdata_reduction_proxy_secure_proxy_check_url),
+ make_scoped_ptr(
+ reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier))));
+}
+
+// Add a QUIC hint to a URLRequestContextConfig.
+static void AddQuicHint(JNIEnv* env,
+ const JavaParamRef<jclass>& jcaller,
+ jlong jurl_request_context_config,
+ const JavaParamRef<jstring>& jhost,
+ jint jport,
+ jint jalternate_port) {
+ URLRequestContextConfig* config =
+ reinterpret_cast<URLRequestContextConfig*>(jurl_request_context_config);
+ config->quic_hints.push_back(
+ make_scoped_ptr(new URLRequestContextConfig::QuicHint(
+ base::android::ConvertJavaStringToUTF8(env, jhost), jport,
+ jalternate_port)));
+}
+
+// Add a public key ping to URLRequestContextConfig.
+static void AddPkp(JNIEnv* env,
+ const JavaParamRef<jclass>& jcaller,
+ jlong jurl_request_context_config,
+ const JavaParamRef<jstring>& jhost,
+ const JavaParamRef<jobjectArray>& jhashes,
+ jboolean jinclude_subdomains,
+ jlong jexpiration_time) {
xunjieli 2015/12/04 19:19:13 Maybe add a comment here documenting what |jexpira
pauljensen 2015/12/07 13:53:34 Done.
+ URLRequestContextConfig* config =
+ reinterpret_cast<URLRequestContextConfig*>(jurl_request_context_config);
+ scoped_ptr<URLRequestContextConfig::Pkp> pkp(new URLRequestContextConfig::Pkp(
+ base::android::ConvertJavaStringToUTF8(env, jhost), jinclude_subdomains,
+ base::Time::UnixEpoch() +
+ base::TimeDelta::FromMilliseconds(jexpiration_time)));
+ size_t hash_count = env->GetArrayLength(jhashes);
+ for (size_t i = 0; i < hash_count; ++i) {
+ ScopedJavaLocalRef<jbyteArray> bytes_array(
+ env, static_cast<jbyteArray>(env->GetObjectArrayElement(jhashes, i)));
+ if (env->GetArrayLength(bytes_array.obj()) != sizeof(net::SHA256HashValue))
xunjieli 2015/12/04 19:19:13 Does this actually work? The size of the struct in
pauljensen 2015/12/07 13:53:34 Yes, this works. In fact SHA256HashValue exists t
+ continue;
+ jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), nullptr);
+ net::HashValue hash(*reinterpret_cast<net::SHA256HashValue*>(bytes));
xunjieli 2015/12/04 19:19:13 SHA256HashValue is a struct. Does the reinterpret_
pauljensen 2015/12/07 13:53:34 Yes, this works. I really want to avoid memcpy as
+ pkp->pin_hashes.push_back(hash);
+ env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT);
+ }
+ config->pkp_list.push_back(std::move(pkp));
+}
+
// Creates RequestContextAdater if config is valid URLRequestContextConfig,
// returns 0 otherwise.
static jlong CreateRequestContextAdapter(JNIEnv* env,
const JavaParamRef<jclass>& jcaller,
- const JavaParamRef<jstring>& jconfig) {
- std::string config_string =
- base::android::ConvertJavaStringToUTF8(env, jconfig);
+ jlong jconfig) {
scoped_ptr<URLRequestContextConfig> context_config(
- new URLRequestContextConfig());
- if (!context_config->LoadFromJSON(config_string))
- return 0;
+ reinterpret_cast<URLRequestContextConfig*>(jconfig));
CronetURLRequestContextAdapter* context_adapter =
new CronetURLRequestContextAdapter(context_config.Pass());

Powered by Google App Engine
This is Rietveld 408576698