OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ |
| 6 #define PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "ppapi/thunk/ppb_url_request_info_api.h" |
| 13 #include "ppapi/shared_impl/resource.h" |
| 14 |
| 15 namespace ppapi { |
| 16 |
| 17 namespace thunk { |
| 18 class PPB_FileRef_API; |
| 19 } |
| 20 |
| 21 struct PPB_URLRequestInfo_Data { |
| 22 struct BodyItem { |
| 23 BodyItem(); |
| 24 explicit BodyItem(const std::string& data); |
| 25 BodyItem(Resource* file_ref, |
| 26 int64_t start_offset, |
| 27 int64_t number_of_bytes, |
| 28 PP_Time expected_last_modified_time); |
| 29 |
| 30 // Set if the input is a file, false means the |data| is valid. |
| 31 bool is_file; |
| 32 |
| 33 std::string data; |
| 34 |
| 35 // Is is_file is set, these variables are set. Note that the resoruce |
| 36 // may still be NULL in some cases, such as deserialization errors. |
| 37 // |
| 38 // This is a bit tricky. In the plugin side of the proxy, both the file |
| 39 // ref and the file_ref_host_resource will be set and valid: the scoped_ptr |
| 40 // ensures that the resource is alive for as long as the BodyItem is, and |
| 41 // the host resource is for the serialization system to send it over the |
| 42 // wire. |
| 43 // |
| 44 // When we deserialize this in the renderer, the file_refs won't be valid |
| 45 // until the host resources are converted to Resource pointers in the |
| 46 // PPB_URLRequestInfo_Impl. |
| 47 scoped_refptr<Resource> file_ref; |
| 48 HostResource file_ref_host_resource; |
| 49 |
| 50 int64_t start_offset; |
| 51 int64_t number_of_bytes; |
| 52 PP_Time expected_last_modified_time; |
| 53 }; |
| 54 |
| 55 PPB_URLRequestInfo_Data(); |
| 56 ~PPB_URLRequestInfo_Data(); |
| 57 |
| 58 std::string url; |
| 59 std::string method; |
| 60 std::string headers; |
| 61 |
| 62 bool stream_to_file; |
| 63 bool follow_redirects; |
| 64 bool record_download_progress; |
| 65 bool record_upload_progress; |
| 66 |
| 67 // |has_custom_referrer_url| is set to false if a custom referrer hasn't been |
| 68 // set (or has been set to an Undefined Var) and the default referrer should |
| 69 // be used. (Setting the custom referrer to an empty string indicates that no |
| 70 // referrer header should be generated.) |
| 71 bool has_custom_referrer_url; |
| 72 std::string custom_referrer_url; |
| 73 |
| 74 bool allow_cross_origin_requests; |
| 75 bool allow_credentials; |
| 76 |
| 77 // Similar to the custom referrer (above), but for custom content transfer |
| 78 // encoding. |
| 79 bool has_custom_content_transfer_encoding; |
| 80 std::string custom_content_transfer_encoding; |
| 81 |
| 82 int32_t prefetch_buffer_upper_threshold; |
| 83 int32_t prefetch_buffer_lower_threshold; |
| 84 |
| 85 std::vector<BodyItem> body; |
| 86 }; |
| 87 |
| 88 class URLRequestInfoImpl : public ::ppapi::Resource, |
| 89 public ::ppapi::thunk::PPB_URLRequestInfo_API { |
| 90 public: |
| 91 // This constructor initializes the object as a proxy object with the given |
| 92 // host resource. |
| 93 URLRequestInfoImpl(const HostResource& host_resource, |
| 94 const PPB_URLRequestInfo_Data& data); |
| 95 |
| 96 ~URLRequestInfoImpl(); |
| 97 |
| 98 // Resource overrides. |
| 99 virtual thunk::PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; |
| 100 |
| 101 // PPB_URLRequestInfo_API implementation. |
| 102 virtual PP_Bool SetProperty(PP_URLRequestProperty property, |
| 103 PP_Var var) OVERRIDE; |
| 104 virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE; |
| 105 virtual PP_Bool AppendFileToBody( |
| 106 PP_Resource file_ref, |
| 107 int64_t start_offset, |
| 108 int64_t number_of_bytes, |
| 109 PP_Time expected_last_modified_time) OVERRIDE; |
| 110 virtual const PPB_URLRequestInfo_Data& GetData() const OVERRIDE; |
| 111 |
| 112 protected: |
| 113 // Constructor used by the webkit implementation. |
| 114 URLRequestInfoImpl(PP_Instance instance, |
| 115 const PPB_URLRequestInfo_Data& data); |
| 116 |
| 117 // Checks that the HTTP method is valid, returning the canonicalized version |
| 118 // if so. Returns empty string if it's invalid. |
| 119 static std::string ValidateMethod(const std::string& method); |
| 120 |
| 121 bool SetUndefinedProperty(PP_URLRequestProperty property); |
| 122 bool SetBooleanProperty(PP_URLRequestProperty property, bool value); |
| 123 bool SetIntegerProperty(PP_URLRequestProperty property, int32_t value); |
| 124 bool SetStringProperty(PP_URLRequestProperty property, |
| 125 const std::string& value); |
| 126 |
| 127 const PPB_URLRequestInfo_Data& data() const { return data_; } |
| 128 PPB_URLRequestInfo_Data& data() { return data_; } |
| 129 |
| 130 private: |
| 131 PPB_URLRequestInfo_Data data_; |
| 132 |
| 133 DISALLOW_IMPLICIT_CONSTRUCTORS(URLRequestInfoImpl); |
| 134 }; |
| 135 |
| 136 } // namespace ppapi |
| 137 |
| 138 #endif // PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ |
OLD | NEW |