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 #ifndef CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ |
6 #define CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ | 6 #define CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "build/build_config.h" |
14 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
15 | 17 |
| 18 #if defined(OS_ANDROID) |
| 19 #include <jni.h> |
| 20 #include "base/android/scoped_java_ref.h" |
| 21 #endif |
| 22 |
16 namespace content { | 23 namespace content { |
17 | 24 |
18 // ResourceRequestBody represents body (i.e. upload data) of a HTTP request. | 25 // ResourceRequestBody represents body (i.e. upload data) of a HTTP request. |
19 // | 26 // |
20 // This class is intentionally opaque: | 27 // This class is intentionally opaque: |
21 // - Embedders cannot inspect the payload of ResourceRequestBody. Only the | 28 // *) Embedders cannot inspect the payload of ResourceRequestBody. Only the |
22 // //content layer can decompose ResourceRequestBody into references to file | 29 // //content layer can decompose ResourceRequestBody into references to file |
23 // ranges, byte vectors, blob uris, etc. | 30 // ranges, byte vectors, blob uris, etc. |
24 // - Embedders can get instances of ResourceRequestBody only by receiving an | 31 // *) Embedders can get instances of ResourceRequestBody only by |
25 // instance created inside //content layer (e.g. receiving it via | 32 // - receiving an instance created inside //content layer (e.g. receiving it |
26 // content::OpenURLParams). | 33 // via content::OpenURLParams), |
27 // - Embedders typically end up passing ResourceRequestBody back into the | 34 // - calling CreateFromBytes with a vector of bytes (e.g. to support |
28 // //content layer via content::NavigationController::LoadUrlParams. | 35 // Android's WebView::postUrl API, to support DoSearchByImageInNewTab and |
| 36 // to support test code). |
| 37 // *) Embedders typically end up passing ResourceRequestBody back into the |
| 38 // //content layer via content::NavigationController::LoadUrlParams. |
29 class CONTENT_EXPORT ResourceRequestBody | 39 class CONTENT_EXPORT ResourceRequestBody |
30 : public base::RefCountedThreadSafe<ResourceRequestBody> { | 40 : public base::RefCountedThreadSafe<ResourceRequestBody> { |
| 41 public: |
| 42 // Creates ResourceRequestBody that holds a copy of |bytes|. |
| 43 static scoped_refptr<ResourceRequestBody> CreateFromBytes(const char* bytes, |
| 44 size_t length); |
| 45 |
| 46 #if defined(OS_ANDROID) |
| 47 // Returns a org.chromium.content_public.common.ResourceRequestBody Java |
| 48 // object that wraps a ref-counted pointer to the |resource_request_body|. |
| 49 base::android::ScopedJavaLocalRef<jobject> ToJavaObject(JNIEnv* env); |
| 50 |
| 51 // Extracts and returns a C++ object out of Java's |
| 52 // org.chromium.content_public.common.ResourceRequestBody. |
| 53 static scoped_refptr<ResourceRequestBody> FromJavaObject( |
| 54 JNIEnv* env, |
| 55 const base::android::JavaParamRef<jobject>& java_object); |
| 56 #endif |
| 57 |
31 protected: | 58 protected: |
32 ResourceRequestBody(); | 59 ResourceRequestBody(); |
33 virtual ~ResourceRequestBody(); | 60 virtual ~ResourceRequestBody(); |
34 | 61 |
35 private: | 62 private: |
36 friend class base::RefCountedThreadSafe<ResourceRequestBody>; | 63 friend class base::RefCountedThreadSafe<ResourceRequestBody>; |
37 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); | 64 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); |
38 }; | 65 }; |
39 | 66 |
40 } // namespace content | 67 } // namespace content |
41 | 68 |
42 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ | 69 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ |
OLD | NEW |