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 #include "content/public/common/resource_request_body.h" | 5 #include "content/public/common/resource_request_body.h" |
6 | 6 |
7 #include "content/common/resource_request_body_impl.h" | |
8 | |
9 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
10 #include "content/common/android/resource_request_body_android.h" | 8 #include "content/common/android/resource_request_body_android.h" |
11 #endif | 9 #endif |
12 | 10 |
13 namespace content { | 11 namespace content { |
14 | 12 |
15 ResourceRequestBody::ResourceRequestBody() {} | 13 ResourceRequestBody::ResourceRequestBody() |
16 | 14 : identifier_(0), contains_sensitive_info_(false) {} |
17 ResourceRequestBody::~ResourceRequestBody() {} | |
18 | 15 |
19 // static | 16 // static |
20 scoped_refptr<ResourceRequestBody> ResourceRequestBody::CreateFromBytes( | 17 scoped_refptr<ResourceRequestBody> ResourceRequestBody::CreateFromBytes( |
21 const char* bytes, | 18 const char* bytes, |
22 size_t length) { | 19 size_t length) { |
23 scoped_refptr<ResourceRequestBodyImpl> result = new ResourceRequestBodyImpl(); | 20 scoped_refptr<ResourceRequestBody> result = new ResourceRequestBody(); |
24 result->AppendBytes(bytes, length); | 21 result->AppendBytes(bytes, length); |
25 return result; | 22 return result; |
26 } | 23 } |
27 | 24 |
28 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
29 base::android::ScopedJavaLocalRef<jobject> ResourceRequestBody::ToJavaObject( | 26 base::android::ScopedJavaLocalRef<jobject> ResourceRequestBody::ToJavaObject( |
30 JNIEnv* env) { | 27 JNIEnv* env) { |
31 return ConvertResourceRequestBodyToJavaObject( | 28 return ConvertResourceRequestBodyToJavaObject( |
32 env, static_cast<ResourceRequestBodyImpl*>(this)); | 29 env, static_cast<ResourceRequestBody*>(this)); |
33 } | 30 } |
34 | 31 |
35 // static | 32 // static |
36 scoped_refptr<ResourceRequestBody> ResourceRequestBody::FromJavaObject( | 33 scoped_refptr<ResourceRequestBody> ResourceRequestBody::FromJavaObject( |
37 JNIEnv* env, | 34 JNIEnv* env, |
38 const base::android::JavaParamRef<jobject>& java_object) { | 35 const base::android::JavaParamRef<jobject>& java_object) { |
39 return ExtractResourceRequestBodyFromJavaObject(env, java_object); | 36 return ExtractResourceRequestBodyFromJavaObject(env, java_object); |
40 } | 37 } |
41 #endif | 38 #endif |
42 | 39 |
| 40 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
| 41 if (bytes_len > 0) { |
| 42 elements_.push_back(Element()); |
| 43 elements_.back().SetToBytes(bytes, bytes_len); |
| 44 } |
| 45 } |
| 46 |
| 47 void ResourceRequestBody::AppendFileRange( |
| 48 const base::FilePath& file_path, |
| 49 uint64_t offset, |
| 50 uint64_t length, |
| 51 const base::Time& expected_modification_time) { |
| 52 elements_.push_back(Element()); |
| 53 elements_.back().SetToFilePathRange(file_path, offset, length, |
| 54 expected_modification_time); |
| 55 } |
| 56 |
| 57 void ResourceRequestBody::AppendBlob(const std::string& uuid) { |
| 58 elements_.push_back(Element()); |
| 59 elements_.back().SetToBlob(uuid); |
| 60 } |
| 61 |
| 62 void ResourceRequestBody::AppendFileSystemFileRange( |
| 63 const GURL& url, |
| 64 uint64_t offset, |
| 65 uint64_t length, |
| 66 const base::Time& expected_modification_time) { |
| 67 elements_.push_back(Element()); |
| 68 elements_.back().SetToFileSystemUrlRange(url, offset, length, |
| 69 expected_modification_time); |
| 70 } |
| 71 |
| 72 std::vector<base::FilePath> ResourceRequestBody::GetReferencedFiles() const { |
| 73 std::vector<base::FilePath> result; |
| 74 for (const auto& element : *elements()) { |
| 75 if (element.type() == Element::TYPE_FILE) |
| 76 result.push_back(element.path()); |
| 77 } |
| 78 return result; |
| 79 } |
| 80 |
| 81 ResourceRequestBody::~ResourceRequestBody() {} |
| 82 |
43 } // namespace content | 83 } // namespace content |
OLD | NEW |