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 <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "storage/common/data_element.h" |
| 18 #include "url/gurl.h" |
17 | 19 |
18 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
19 #include <jni.h> | 21 #include <jni.h> |
20 #include "base/android/scoped_java_ref.h" | 22 #include "base/android/scoped_java_ref.h" |
21 #endif | 23 #endif |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 // ResourceRequestBody represents body (i.e. upload data) of a HTTP request. | 27 // ResourceRequestBody represents body (i.e. upload data) of a HTTP request. |
26 // | |
27 // This class is intentionally opaque: | |
28 // *) Embedders cannot inspect the payload of ResourceRequestBody. Only the | |
29 // //content layer can decompose ResourceRequestBody into references to file | |
30 // ranges, byte vectors, blob uris, etc. | |
31 // *) Embedders can get instances of ResourceRequestBody only by | |
32 // - receiving an instance created inside //content layer (e.g. receiving it | |
33 // via content::OpenURLParams), | |
34 // - calling CreateFromBytes with a vector of bytes (e.g. to support | |
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. | |
39 class CONTENT_EXPORT ResourceRequestBody | 28 class CONTENT_EXPORT ResourceRequestBody |
40 : public base::RefCountedThreadSafe<ResourceRequestBody> { | 29 : public base::RefCountedThreadSafe<ResourceRequestBody> { |
41 public: | 30 public: |
| 31 typedef storage::DataElement Element; |
| 32 |
| 33 ResourceRequestBody(); |
| 34 |
42 // Creates ResourceRequestBody that holds a copy of |bytes|. | 35 // Creates ResourceRequestBody that holds a copy of |bytes|. |
43 static scoped_refptr<ResourceRequestBody> CreateFromBytes(const char* bytes, | 36 static scoped_refptr<ResourceRequestBody> CreateFromBytes(const char* bytes, |
44 size_t length); | 37 size_t length); |
45 | 38 |
46 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
47 // Returns a org.chromium.content_public.common.ResourceRequestBody Java | 40 // Returns a org.chromium.content_public.common.ResourceRequestBody Java |
48 // object that wraps a ref-counted pointer to the |resource_request_body|. | 41 // object that wraps a ref-counted pointer to the |resource_request_body|. |
49 base::android::ScopedJavaLocalRef<jobject> ToJavaObject(JNIEnv* env); | 42 base::android::ScopedJavaLocalRef<jobject> ToJavaObject(JNIEnv* env); |
50 | 43 |
51 // Extracts and returns a C++ object out of Java's | 44 // Extracts and returns a C++ object out of Java's |
52 // org.chromium.content_public.common.ResourceRequestBody. | 45 // org.chromium.content_public.common.ResourceRequestBody. |
53 static scoped_refptr<ResourceRequestBody> FromJavaObject( | 46 static scoped_refptr<ResourceRequestBody> FromJavaObject( |
54 JNIEnv* env, | 47 JNIEnv* env, |
55 const base::android::JavaParamRef<jobject>& java_object); | 48 const base::android::JavaParamRef<jobject>& java_object); |
56 #endif | 49 #endif |
57 | 50 |
58 protected: | 51 void AppendBytes(const char* bytes, int bytes_len); |
59 ResourceRequestBody(); | 52 void AppendFileRange(const base::FilePath& file_path, |
60 virtual ~ResourceRequestBody(); | 53 uint64_t offset, |
| 54 uint64_t length, |
| 55 const base::Time& expected_modification_time); |
| 56 |
| 57 void AppendBlob(const std::string& uuid); |
| 58 void AppendFileSystemFileRange(const GURL& url, |
| 59 uint64_t offset, |
| 60 uint64_t length, |
| 61 const base::Time& expected_modification_time); |
| 62 |
| 63 const std::vector<Element>* elements() const { return &elements_; } |
| 64 std::vector<Element>* elements_mutable() { return &elements_; } |
| 65 void swap_elements(std::vector<Element>* elements) { |
| 66 elements_.swap(*elements); |
| 67 } |
| 68 |
| 69 // Identifies a particular upload instance, which is used by the cache to |
| 70 // formulate a cache key. This value should be unique across browser |
| 71 // sessions. A value of 0 is used to indicate an unspecified identifier. |
| 72 void set_identifier(int64_t id) { identifier_ = id; } |
| 73 int64_t identifier() const { return identifier_; } |
| 74 |
| 75 // Returns paths referred to by |elements| of type Element::TYPE_FILE. |
| 76 std::vector<base::FilePath> GetReferencedFiles() const; |
| 77 |
| 78 // Sets the flag which indicates whether the post data contains sensitive |
| 79 // information like passwords. |
| 80 void set_contains_sensitive_info(bool contains_sensitive_info) { |
| 81 contains_sensitive_info_ = contains_sensitive_info; |
| 82 } |
| 83 bool contains_sensitive_info() const { return contains_sensitive_info_; } |
61 | 84 |
62 private: | 85 private: |
63 friend class base::RefCountedThreadSafe<ResourceRequestBody>; | 86 friend class base::RefCountedThreadSafe<ResourceRequestBody>; |
| 87 |
| 88 ~ResourceRequestBody(); |
| 89 |
| 90 std::vector<Element> elements_; |
| 91 int64_t identifier_; |
| 92 |
| 93 bool contains_sensitive_info_; |
| 94 |
64 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); | 95 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); |
65 }; | 96 }; |
66 | 97 |
67 } // namespace content | 98 } // namespace content |
68 | 99 |
69 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ | 100 #endif // CONTENT_PUBLIC_COMMON_RESOURCE_REQUEST_BODY_H_ |
OLD | NEW |