| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/common/android/resource_request_body_android.h" | 5 #include "content/common/android/resource_request_body_android.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 JNIEnv* env, | 59 JNIEnv* env, |
| 60 const scoped_refptr<ResourceRequestBodyImpl>& body) { | 60 const scoped_refptr<ResourceRequestBodyImpl>& body) { |
| 61 if (!body) | 61 if (!body) |
| 62 return base::android::ScopedJavaLocalRef<jobject>(); | 62 return base::android::ScopedJavaLocalRef<jobject>(); |
| 63 | 63 |
| 64 // TODO(lukasza): Avoid repeatedly copying the bytes. | 64 // TODO(lukasza): Avoid repeatedly copying the bytes. |
| 65 // See also https://goo.gl/ITiLGI. | 65 // See also https://goo.gl/ITiLGI. |
| 66 base::android::ScopedJavaLocalRef<jbyteArray> j_encoded = | 66 base::android::ScopedJavaLocalRef<jbyteArray> j_encoded = |
| 67 ConvertResourceRequestBodyToJavaArray(env, *body); | 67 ConvertResourceRequestBodyToJavaArray(env, *body); |
| 68 | 68 |
| 69 return Java_ResourceRequestBody_createFromEncodedNativeForm(env, | 69 return Java_ResourceRequestBody_createFromEncodedNativeForm(env, j_encoded); |
| 70 j_encoded.obj()); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 scoped_refptr<ResourceRequestBodyImpl> ExtractResourceRequestBodyFromJavaObject( | 72 scoped_refptr<ResourceRequestBodyImpl> ExtractResourceRequestBodyFromJavaObject( |
| 74 JNIEnv* env, | 73 JNIEnv* env, |
| 75 const base::android::JavaParamRef<jobject>& j_body) { | 74 const base::android::JavaParamRef<jobject>& j_body) { |
| 76 if (!j_body) | 75 if (!j_body) |
| 77 return nullptr; | 76 return nullptr; |
| 78 | 77 |
| 79 base::android::ScopedJavaLocalRef<jbyteArray> j_encoded = | 78 base::android::ScopedJavaLocalRef<jbyteArray> j_encoded = |
| 80 Java_ResourceRequestBody_getEncodedNativeForm(env, j_body.obj()); | 79 Java_ResourceRequestBody_getEncodedNativeForm(env, j_body); |
| 81 if (j_encoded.is_null()) | 80 if (j_encoded.is_null()) |
| 82 return nullptr; | 81 return nullptr; |
| 83 | 82 |
| 84 std::vector<uint8_t> encoded; | 83 std::vector<uint8_t> encoded; |
| 85 base::android::JavaByteArrayToByteVector(env, j_encoded.obj(), &encoded); | 84 base::android::JavaByteArrayToByteVector(env, j_encoded.obj(), &encoded); |
| 86 | 85 |
| 87 return DecodeResourceRequestBody( | 86 return DecodeResourceRequestBody( |
| 88 reinterpret_cast<const char*>(encoded.data()), encoded.size()); | 87 reinterpret_cast<const char*>(encoded.data()), encoded.size()); |
| 89 } | 88 } |
| 90 | 89 |
| 91 } // namespace content | 90 } // namespace content |
| OLD | NEW |