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

Unified Diff: content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java

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/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
diff --git a/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java b/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
new file mode 100644
index 0000000000000000000000000000000000000000..f732cdf39e4e66935684584c710fa4d0976c2084
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
@@ -0,0 +1,69 @@
+// 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.
+
+package org.chromium.content_public.common;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * Wrapper around the native content::ResourceRequestBody.
+ */
+@JNINamespace("content")
+public final class ResourceRequestBody {
+ /**
+ * Result of EncodeResourceRequestBody call from page_state_serialization.h.
+ *
+ * Note that this is *not* the content of HTTP body (i.e. format of the
+ * value of mSerializedFormOfNativeResourceRequestBody is opaque and
+ * different from the value passed as an argument of
+ * ResourceRequestBody.createFromBytes method below).
+ */
+ private byte[] mEncodedNativeForm;
+
+ // ResourceRequestBody Java objects can only be constructed by
+ // - ResourceRequestBody::createFromBytes(byte[])
+ // (public - callable from other Java code)
+ // - ResourceRequestBody::createFromEncodedNativeForm(byte[])
+ // (private - called only from native code)
+ private ResourceRequestBody(byte[] encodedNativeForm) {
+ mEncodedNativeForm = encodedNativeForm;
+ }
+
+ /**
+ * Used by native code to construct ResourceRequestBody.
+ *
+ * @param encodedNativeForm Result of calling EncodeResourceRequestBody.
+ */
+ @CalledByNative
+ private static ResourceRequestBody createFromEncodedNativeForm(byte[] encodedNativeForm) {
+ return new ResourceRequestBody(encodedNativeForm);
+ }
+
+ @CalledByNative
+ private byte[] getEncodedNativeForm() {
+ return mEncodedNativeForm;
+ }
+
+ /**
+ * Creates an instance representing HTTP body where the payload
+ * is a copy of the specified byte array.
+ *
+ * @param body the HTTP body
+ */
+ public static ResourceRequestBody createFromBytes(byte[] httpBody) {
+ byte[] encodedNativeForm = nativeCreateResourceRequestBodyFromBytes(httpBody);
+ return createFromEncodedNativeForm(encodedNativeForm);
+ }
+
+ /**
+ * Equivalent of the native content::ResourceRequestBody::CreateFromBytes.
+ *
+ * @param body the HTTP body
+ *
+ * @return result of a call to EncodeResourceRequestBody on
+ * ResourceRequestBody created from |httpBody|.
+ */
+ private static native byte[] nativeCreateResourceRequestBodyFromBytes(byte[] httpBody);
+}

Powered by Google App Engine
This is Rietveld 408576698