OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_url_loader.h" | 5 #include "webkit/glue/plugins/pepper_url_loader.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/ppapi/c/pp_completion_callback.h" | 8 #include "third_party/ppapi/c/pp_completion_callback.h" |
9 #include "third_party/ppapi/c/pp_errors.h" | 9 #include "third_party/ppapi/c/pp_errors.h" |
10 #include "third_party/ppapi/c/ppb_url_loader.h" | 10 #include "third_party/ppapi/c/ppb_url_loader.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return FillUserBuffer(); | 214 return FillUserBuffer(); |
215 | 215 |
216 pending_callback_ = callback; | 216 pending_callback_ = callback; |
217 return PP_Error_WouldBlock; | 217 return PP_Error_WouldBlock; |
218 } | 218 } |
219 | 219 |
220 void URLLoader::Close() { | 220 void URLLoader::Close() { |
221 NOTIMPLEMENTED(); // TODO(darin): Implement me. | 221 NOTIMPLEMENTED(); // TODO(darin): Implement me. |
222 } | 222 } |
223 | 223 |
224 void URLLoader::RunCallback(int32_t result) { | |
225 if (!pending_callback_.func) | |
226 return; | |
227 | |
228 PP_CompletionCallback callback = {0}; | |
229 std::swap(callback, pending_callback_); | |
230 PP_RunCompletionCallback(&callback, result); | |
231 } | |
232 | |
233 size_t URLLoader::FillUserBuffer() { | |
234 DCHECK(user_buffer_); | |
235 DCHECK(user_buffer_size_); | |
236 | |
237 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); | |
238 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); | |
239 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); | |
240 | |
241 // Reset for next time. | |
242 user_buffer_ = NULL; | |
243 user_buffer_size_ = 0; | |
244 return bytes_to_copy; | |
245 } | |
246 | |
247 void URLLoader::willSendRequest(WebURLLoader* loader, | 224 void URLLoader::willSendRequest(WebURLLoader* loader, |
248 WebURLRequest& new_request, | 225 WebURLRequest& new_request, |
249 const WebURLResponse& redirect_response) { | 226 const WebURLResponse& redirect_response) { |
250 NOTIMPLEMENTED(); // TODO(darin): Allow the plugin to inspect redirects. | 227 NOTIMPLEMENTED(); // TODO(darin): Allow the plugin to inspect redirects. |
251 } | 228 } |
252 | 229 |
253 void URLLoader::didSendData(WebURLLoader* loader, | 230 void URLLoader::didSendData(WebURLLoader* loader, |
254 unsigned long long bytes_sent, | 231 unsigned long long bytes_sent, |
255 unsigned long long total_bytes_to_be_sent) { | 232 unsigned long long total_bytes_to_be_sent) { |
256 // TODO(darin): Bounds check input? | 233 // TODO(darin): Bounds check input? |
(...skipping 20 matching lines...) Expand all Loading... |
277 | 254 |
278 void URLLoader::didFinishLoading(WebURLLoader* loader) { | 255 void URLLoader::didFinishLoading(WebURLLoader* loader) { |
279 RunCallback(PP_OK); | 256 RunCallback(PP_OK); |
280 } | 257 } |
281 | 258 |
282 void URLLoader::didFail(WebURLLoader* loader, const WebURLError& error) { | 259 void URLLoader::didFail(WebURLLoader* loader, const WebURLError& error) { |
283 // TODO(darin): Provide more detailed error information. | 260 // TODO(darin): Provide more detailed error information. |
284 RunCallback(PP_Error_Failed); | 261 RunCallback(PP_Error_Failed); |
285 } | 262 } |
286 | 263 |
| 264 void URLLoader::RunCallback(int32_t result) { |
| 265 if (!pending_callback_.func) |
| 266 return; |
| 267 |
| 268 PP_CompletionCallback callback = {0}; |
| 269 std::swap(callback, pending_callback_); |
| 270 PP_RunCompletionCallback(&callback, result); |
| 271 } |
| 272 |
| 273 size_t URLLoader::FillUserBuffer() { |
| 274 DCHECK(user_buffer_); |
| 275 DCHECK(user_buffer_size_); |
| 276 |
| 277 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); |
| 278 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); |
| 279 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); |
| 280 |
| 281 // Reset for next time. |
| 282 user_buffer_ = NULL; |
| 283 user_buffer_size_ = 0; |
| 284 return bytes_to_copy; |
| 285 } |
| 286 |
287 } // namespace pepper | 287 } // namespace pepper |
OLD | NEW |