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

Unified Diff: content/common/android/resource_request_body_android.cc

Issue 2038233002: Using ResourceRequestBody as the type of HTTP body outside of //content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@make-resource-request-body-public
Patch Set: Rebasing... Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/common/android/resource_request_body_android.cc
diff --git a/content/common/android/resource_request_body_android.cc b/content/common/android/resource_request_body_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b9d8ad5cbc1297edb6ce59ad6461427ef0d1837
--- /dev/null
+++ b/content/common/android/resource_request_body_android.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/android/resource_request_body_android.h"
+
+#include <jni.h>
+
+#include "base/android/jni_array.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/ref_counted.h"
+#include "content/public/common/resource_request_body.h"
+#include "jni/ResourceRequestBody_jni.h"
+
+namespace content {
+
+bool RegisterResourceRequestBody(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+jlong CreateResourceRequestBodyFromBytes(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jbyteArray>& j_post_data) {
+ if (!j_post_data)
+ return 0;
+
+ std::vector<uint8_t> post_data;
+ base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data);
+ scoped_refptr<ResourceRequestBody> result =
+ ResourceRequestBody::CreateFromBytes(
+ reinterpret_cast<const char*>(post_data.data()), post_data.size());
+
+ result->AddRef(); // This ref-count is passed to the Java world.
+ return reinterpret_cast<ptrdiff_t>(result.get());
+}
+
+void ReleaseResourceRequestBodyRefCount(JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ jlong j_ptr) {
+ ResourceRequestBody* resource_request_body =
+ reinterpret_cast<ResourceRequestBody*>(j_ptr);
+ resource_request_body->Release();
+}
+
+base::android::ScopedJavaLocalRef<jobject>
+ConvertResourceRequestBodyToJavaObject(
+ JNIEnv* env,
+ const scoped_refptr<ResourceRequestBody>& native_object) {
+ jlong j_native_ptr = 0;
+ if (native_object) {
+ native_object->AddRef(); // This ref-count will be passed to Java world.
+ j_native_ptr = reinterpret_cast<jlong>(native_object.get());
+ }
+ return Java_ResourceRequestBody_create(env, j_native_ptr);
+}
+
+scoped_refptr<ResourceRequestBody> ExtractResourceRequestBodyFromJavaObject(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& java_object) {
+ if (!java_object)
+ return nullptr;
+
+ jlong j_native_ptr = Java_ResourceRequestBody_getNativePtr(env, java_object);
+ scoped_refptr<ResourceRequestBody> result =
+ reinterpret_cast<ResourceRequestBody*>(j_native_ptr);
+ return result;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698