Chromium Code Reviews| 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 and to support test code). |
| 36 // *) Embedders typically end up passing ResourceRequestBody back into the | |
| 37 // //content layer via content::NavigationController::LoadUrlParams. | |
| 29 class CONTENT_EXPORT ResourceRequestBody | 38 class CONTENT_EXPORT ResourceRequestBody |
| 30 : public base::RefCountedThreadSafe<ResourceRequestBody> { | 39 : public base::RefCountedThreadSafe<ResourceRequestBody> { |
| 40 public: | |
| 41 // Creates ResourceRequestBody that holds a copy of |bytes|. | |
| 42 static scoped_refptr<ResourceRequestBody> CreateFromBytes(const char* bytes, | |
|
Charlie Reis
2016/06/09 22:38:16
You mentioned that this should only be used for An
Łukasz Anforowicz
2016/06/10 19:20:50
I found out that I was wrong about that - there is
Charlie Reis
2016/06/10 20:59:28
As Daniel points out, this is the "Search Google f
Łukasz Anforowicz
2016/06/13 18:01:11
Oh, ok. It seems to continue to work in the priva
| |
| 43 size_t length); | |
| 44 static scoped_refptr<ResourceRequestBody> CreateFromBytes( | |
| 45 const std::string& bytes); | |
|
Charlie Reis
2016/06/09 22:38:16
Maybe we can get by with just the first version of
Łukasz Anforowicz
2016/06/10 19:20:50
Done.
| |
| 46 | |
| 47 #if defined(OS_ANDROID) | |
| 48 // Returns a org.chromium.content_public.common.ResourceRequestBody Java | |
| 49 // object that wraps a ref-counted pointer to the |resource_request_body|. | |
| 50 base::android::ScopedJavaLocalRef<jobject> ToJavaObject(JNIEnv* env); | |
| 51 | |
| 52 // Extracts and returns a C++ object out of Java's | |
| 53 // org.chromium.content_public.common.ResourceRequestBody. | |
| 54 static scoped_refptr<ResourceRequestBody> FromJavaObject( | |
| 55 JNIEnv* env, | |
| 56 const base::android::JavaParamRef<jobject>& java_object); | |
| 57 #endif | |
| 58 | |
| 31 protected: | 59 protected: |
| 32 ResourceRequestBody(); | 60 ResourceRequestBody(); |
| 33 virtual ~ResourceRequestBody(); | 61 virtual ~ResourceRequestBody(); |
| 34 | 62 |
| 35 private: | 63 private: |
| 36 friend class base::RefCountedThreadSafe<ResourceRequestBody>; | 64 friend class base::RefCountedThreadSafe<ResourceRequestBody>; |
| 37 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); | 65 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); |
| 38 }; | 66 }; |
| 39 | 67 |
| 40 } // namespace content | 68 } // namespace content |
| 41 | 69 |
| 42 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ | 70 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ |
| OLD | NEW |