OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/shared_impl/url_request_info_impl.h" | 5 #include "ppapi/shared_impl/ppb_url_request_info_shared.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "ppapi/shared_impl/var.h" | 8 #include "ppapi/shared_impl/var.h" |
9 #include "ppapi/thunk/enter.h" | 9 #include "ppapi/thunk/enter.h" |
10 #include "ppapi/thunk/ppb_file_ref_api.h" | 10 #include "ppapi/thunk/ppb_file_ref_api.h" |
11 | 11 |
12 using ppapi::thunk::EnterResourceNoLock; | 12 using ppapi::thunk::EnterResourceNoLock; |
13 | 13 |
14 namespace ppapi { | 14 namespace ppapi { |
15 | 15 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 has_custom_content_transfer_encoding(false), | 63 has_custom_content_transfer_encoding(false), |
64 custom_content_transfer_encoding(), | 64 custom_content_transfer_encoding(), |
65 prefetch_buffer_upper_threshold(kDefaultPrefetchBufferUpperThreshold), | 65 prefetch_buffer_upper_threshold(kDefaultPrefetchBufferUpperThreshold), |
66 prefetch_buffer_lower_threshold(kDefaultPrefetchBufferLowerThreshold), | 66 prefetch_buffer_lower_threshold(kDefaultPrefetchBufferLowerThreshold), |
67 body() { | 67 body() { |
68 } | 68 } |
69 | 69 |
70 PPB_URLRequestInfo_Data::~PPB_URLRequestInfo_Data() { | 70 PPB_URLRequestInfo_Data::~PPB_URLRequestInfo_Data() { |
71 } | 71 } |
72 | 72 |
73 URLRequestInfoImpl::URLRequestInfoImpl(PP_Instance instance, | 73 PPB_URLRequestInfo_Shared::PPB_URLRequestInfo_Shared( |
74 const PPB_URLRequestInfo_Data& data) | 74 PP_Instance instance, |
| 75 const PPB_URLRequestInfo_Data& data) |
75 : Resource(instance), | 76 : Resource(instance), |
76 data_(data) { | 77 data_(data) { |
77 } | 78 } |
78 | 79 |
79 URLRequestInfoImpl::URLRequestInfoImpl(const HostResource& host_resource, | 80 PPB_URLRequestInfo_Shared::PPB_URLRequestInfo_Shared( |
80 const PPB_URLRequestInfo_Data& data) | 81 const HostResource& host_resource, |
| 82 const PPB_URLRequestInfo_Data& data) |
81 : Resource(host_resource), | 83 : Resource(host_resource), |
82 data_(data) { | 84 data_(data) { |
83 } | 85 } |
84 | 86 |
85 URLRequestInfoImpl::~URLRequestInfoImpl() { | 87 PPB_URLRequestInfo_Shared::~PPB_URLRequestInfo_Shared() { |
86 } | 88 } |
87 | 89 |
88 thunk::PPB_URLRequestInfo_API* URLRequestInfoImpl::AsPPB_URLRequestInfo_API() { | 90 thunk::PPB_URLRequestInfo_API* |
| 91 PPB_URLRequestInfo_Shared::AsPPB_URLRequestInfo_API() { |
89 return this; | 92 return this; |
90 } | 93 } |
91 | 94 |
92 PP_Bool URLRequestInfoImpl::SetProperty(PP_URLRequestProperty property, | 95 PP_Bool PPB_URLRequestInfo_Shared::SetProperty(PP_URLRequestProperty property, |
93 PP_Var var) { | 96 PP_Var var) { |
94 // IMPORTANT: Do not do security validation of parameters at this level | 97 // IMPORTANT: Do not do security validation of parameters at this level |
95 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. This | 98 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. This |
96 // code is used both in the plugin (which we don't trust) and in the renderer | 99 // code is used both in the plugin (which we don't trust) and in the renderer |
97 // (which we trust more). When running out-of-process, the plugin calls this | 100 // (which we trust more). When running out-of-process, the plugin calls this |
98 // function to configure the PPB_URLRequestInfo_Data, which is then sent to | 101 // function to configure the PPB_URLRequestInfo_Data, which is then sent to |
99 // the renderer and *not* run through SetProperty again. | 102 // the renderer and *not* run through SetProperty again. |
100 // | 103 // |
101 // This means that anything in the PPB_URLRequestInfo_Data needs to be | 104 // This means that anything in the PPB_URLRequestInfo_Data needs to be |
102 // validated at the time the URL is requested (which is what ValidateData | 105 // validated at the time the URL is requested (which is what ValidateData |
103 // does). If your feature requires security checks, it should be in the | 106 // does). If your feature requires security checks, it should be in the |
(...skipping 21 matching lines...) Expand all Loading... |
125 if (string) | 128 if (string) |
126 result = PP_FromBool(SetStringProperty(property, string->value())); | 129 result = PP_FromBool(SetStringProperty(property, string->value())); |
127 break; | 130 break; |
128 } | 131 } |
129 default: | 132 default: |
130 break; | 133 break; |
131 } | 134 } |
132 return result; | 135 return result; |
133 } | 136 } |
134 | 137 |
135 PP_Bool URLRequestInfoImpl::AppendDataToBody(const void* data, uint32_t len) { | 138 PP_Bool PPB_URLRequestInfo_Shared::AppendDataToBody(const void* data, |
| 139 uint32_t len) { |
136 if (len > 0) { | 140 if (len > 0) { |
137 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem( | 141 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem( |
138 std::string(static_cast<const char*>(data), len))); | 142 std::string(static_cast<const char*>(data), len))); |
139 } | 143 } |
140 return PP_TRUE; | 144 return PP_TRUE; |
141 } | 145 } |
142 | 146 |
143 PP_Bool URLRequestInfoImpl::AppendFileToBody( | 147 PP_Bool PPB_URLRequestInfo_Shared::AppendFileToBody( |
144 PP_Resource file_ref, | 148 PP_Resource file_ref, |
145 int64_t start_offset, | 149 int64_t start_offset, |
146 int64_t number_of_bytes, | 150 int64_t number_of_bytes, |
147 PP_Time expected_last_modified_time) { | 151 PP_Time expected_last_modified_time) { |
148 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true); | 152 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true); |
149 if (enter.failed()) | 153 if (enter.failed()) |
150 return PP_FALSE; | 154 return PP_FALSE; |
151 | 155 |
152 // Ignore a call to append nothing. | 156 // Ignore a call to append nothing. |
153 if (number_of_bytes == 0) | 157 if (number_of_bytes == 0) |
154 return PP_TRUE; | 158 return PP_TRUE; |
155 | 159 |
156 // Check for bad values. (-1 means read until end of file.) | 160 // Check for bad values. (-1 means read until end of file.) |
157 if (start_offset < 0 || number_of_bytes < -1) | 161 if (start_offset < 0 || number_of_bytes < -1) |
158 return PP_FALSE; | 162 return PP_FALSE; |
159 | 163 |
160 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem( | 164 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem( |
161 enter.resource(), | 165 enter.resource(), |
162 start_offset, | 166 start_offset, |
163 number_of_bytes, | 167 number_of_bytes, |
164 expected_last_modified_time)); | 168 expected_last_modified_time)); |
165 return PP_TRUE; | 169 return PP_TRUE; |
166 } | 170 } |
167 | 171 |
168 const PPB_URLRequestInfo_Data& URLRequestInfoImpl::GetData() const { | 172 const PPB_URLRequestInfo_Data& PPB_URLRequestInfo_Shared::GetData() const { |
169 return data_; | 173 return data_; |
170 } | 174 } |
171 | 175 |
172 bool URLRequestInfoImpl::SetUndefinedProperty(PP_URLRequestProperty property) { | 176 bool PPB_URLRequestInfo_Shared::SetUndefinedProperty( |
| 177 PP_URLRequestProperty property) { |
173 // IMPORTANT: Do not do security validation of parameters at this level | 178 // IMPORTANT: Do not do security validation of parameters at this level |
174 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See | 179 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See |
175 // SetProperty() above for why. | 180 // SetProperty() above for why. |
176 switch (property) { | 181 switch (property) { |
177 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | 182 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
178 data_.has_custom_referrer_url = false; | 183 data_.has_custom_referrer_url = false; |
179 data_.custom_referrer_url = std::string(); | 184 data_.custom_referrer_url = std::string(); |
180 return true; | 185 return true; |
181 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: | 186 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: |
182 data_.has_custom_content_transfer_encoding = false; | 187 data_.has_custom_content_transfer_encoding = false; |
183 data_.custom_content_transfer_encoding = std::string(); | 188 data_.custom_content_transfer_encoding = std::string(); |
184 return true; | 189 return true; |
185 default: | 190 default: |
186 return false; | 191 return false; |
187 } | 192 } |
188 } | 193 } |
189 | 194 |
190 bool URLRequestInfoImpl::SetBooleanProperty(PP_URLRequestProperty property, | 195 bool PPB_URLRequestInfo_Shared::SetBooleanProperty( |
191 bool value) { | 196 PP_URLRequestProperty property, |
| 197 bool value) { |
192 // IMPORTANT: Do not do security validation of parameters at this level | 198 // IMPORTANT: Do not do security validation of parameters at this level |
193 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See | 199 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See |
194 // SetProperty() above for why. | 200 // SetProperty() above for why. |
195 switch (property) { | 201 switch (property) { |
196 case PP_URLREQUESTPROPERTY_STREAMTOFILE: | 202 case PP_URLREQUESTPROPERTY_STREAMTOFILE: |
197 data_.stream_to_file = value; | 203 data_.stream_to_file = value; |
198 return true; | 204 return true; |
199 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: | 205 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: |
200 data_.follow_redirects = value; | 206 data_.follow_redirects = value; |
201 return true; | 207 return true; |
202 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: | 208 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: |
203 data_.record_download_progress = value; | 209 data_.record_download_progress = value; |
204 return true; | 210 return true; |
205 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: | 211 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: |
206 data_.record_upload_progress = value; | 212 data_.record_upload_progress = value; |
207 return true; | 213 return true; |
208 case PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS: | 214 case PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS: |
209 data_.allow_cross_origin_requests = value; | 215 data_.allow_cross_origin_requests = value; |
210 return true; | 216 return true; |
211 case PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS: | 217 case PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS: |
212 data_.allow_credentials = value; | 218 data_.allow_credentials = value; |
213 return true; | 219 return true; |
214 default: | 220 default: |
215 return false; | 221 return false; |
216 } | 222 } |
217 } | 223 } |
218 | 224 |
219 bool URLRequestInfoImpl::SetIntegerProperty(PP_URLRequestProperty property, | 225 bool PPB_URLRequestInfo_Shared::SetIntegerProperty( |
220 int32_t value) { | 226 PP_URLRequestProperty property, |
| 227 int32_t value) { |
221 // IMPORTANT: Do not do security validation of parameters at this level | 228 // IMPORTANT: Do not do security validation of parameters at this level |
222 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See | 229 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See |
223 // SetProperty() above for why. | 230 // SetProperty() above for why. |
224 switch (property) { | 231 switch (property) { |
225 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD: | 232 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD: |
226 data_.prefetch_buffer_upper_threshold = value; | 233 data_.prefetch_buffer_upper_threshold = value; |
227 return true; | 234 return true; |
228 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD: | 235 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD: |
229 data_.prefetch_buffer_lower_threshold = value; | 236 data_.prefetch_buffer_lower_threshold = value; |
230 return true; | 237 return true; |
231 default: | 238 default: |
232 return false; | 239 return false; |
233 } | 240 } |
234 } | 241 } |
235 | 242 |
236 bool URLRequestInfoImpl::SetStringProperty(PP_URLRequestProperty property, | 243 bool PPB_URLRequestInfo_Shared::SetStringProperty( |
237 const std::string& value) { | 244 PP_URLRequestProperty property, |
| 245 const std::string& value) { |
238 // IMPORTANT: Do not do security validation of parameters at this level | 246 // IMPORTANT: Do not do security validation of parameters at this level |
239 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See | 247 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See |
240 // SetProperty() above for why. | 248 // SetProperty() above for why. |
241 switch (property) { | 249 switch (property) { |
242 case PP_URLREQUESTPROPERTY_URL: | 250 case PP_URLREQUESTPROPERTY_URL: |
243 data_.url = value; // NOTE: This may be a relative URL. | 251 data_.url = value; // NOTE: This may be a relative URL. |
244 return true; | 252 return true; |
245 case PP_URLREQUESTPROPERTY_METHOD: | 253 case PP_URLREQUESTPROPERTY_METHOD: |
246 data_.method = value; | 254 data_.method = value; |
247 return true; | 255 return true; |
248 case PP_URLREQUESTPROPERTY_HEADERS: | 256 case PP_URLREQUESTPROPERTY_HEADERS: |
249 data_.headers = value; | 257 data_.headers = value; |
250 return true; | 258 return true; |
251 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | 259 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
252 data_.has_custom_referrer_url = true; | 260 data_.has_custom_referrer_url = true; |
253 data_.custom_referrer_url = value; | 261 data_.custom_referrer_url = value; |
254 return true; | 262 return true; |
255 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: | 263 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: |
256 data_.has_custom_content_transfer_encoding = true; | 264 data_.has_custom_content_transfer_encoding = true; |
257 data_.custom_content_transfer_encoding = value; | 265 data_.custom_content_transfer_encoding = value; |
258 return true; | 266 return true; |
259 default: | 267 default: |
260 return false; | 268 return false; |
261 } | 269 } |
262 } | 270 } |
263 | 271 |
264 } // namespace ppapi | 272 } // namespace ppapi |
OLD | NEW |