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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/android/resource_request_body_android.h"
6
7 #include <jni.h>
8
9 #include "base/android/jni_array.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/public/common/resource_request_body.h"
13 #include "jni/ResourceRequestBody_jni.h"
14
15 namespace content {
16
17 bool RegisterResourceRequestBody(JNIEnv* env) {
18 return RegisterNativesImpl(env);
19 }
20
21 jlong CreateResourceRequestBodyFromBytes(
22 JNIEnv* env,
23 const JavaParamRef<jclass>& clazz,
24 const JavaParamRef<jbyteArray>& j_post_data) {
25 if (!j_post_data)
26 return 0;
27
28 std::vector<uint8_t> post_data;
29 base::android::JavaByteArrayToByteVector(env, j_post_data, &post_data);
30 scoped_refptr<ResourceRequestBody> result =
31 ResourceRequestBody::CreateFromBytes(
32 reinterpret_cast<const char*>(post_data.data()), post_data.size());
33
34 result->AddRef(); // This ref-count is passed to the Java world.
35 return reinterpret_cast<ptrdiff_t>(result.get());
36 }
37
38 void ReleaseResourceRequestBodyRefCount(JNIEnv* env,
39 const JavaParamRef<jclass>& clazz,
40 jlong j_ptr) {
41 ResourceRequestBody* resource_request_body =
42 reinterpret_cast<ResourceRequestBody*>(j_ptr);
43 resource_request_body->Release();
44 }
45
46 base::android::ScopedJavaLocalRef<jobject>
47 ConvertResourceRequestBodyToJavaObject(
48 JNIEnv* env,
49 const scoped_refptr<ResourceRequestBody>& native_object) {
50 jlong j_native_ptr = 0;
51 if (native_object) {
52 native_object->AddRef(); // This ref-count will be passed to Java world.
53 j_native_ptr = reinterpret_cast<jlong>(native_object.get());
54 }
55 return Java_ResourceRequestBody_create(env, j_native_ptr);
56 }
57
58 scoped_refptr<ResourceRequestBody> ExtractResourceRequestBodyFromJavaObject(
59 JNIEnv* env,
60 const base::android::JavaParamRef<jobject>& java_object) {
61 if (!java_object)
62 return nullptr;
63
64 jlong j_native_ptr = Java_ResourceRequestBody_getNativePtr(env, java_object);
65 scoped_refptr<ResourceRequestBody> result =
66 reinterpret_cast<ResourceRequestBody*>(j_native_ptr);
67 return result;
68 }
69
70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698