| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/child/npapi/plugin_url_fetcher.h" | 5 #include "content/child/npapi/plugin_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "content/child/child_thread_impl.h" | 8 #include "content/child/child_thread_impl.h" |
| 9 #include "content/child/multipart_response_delegate.h" | 9 #include "content/child/multipart_response_delegate.h" |
| 10 #include "content/child/npapi/plugin_host.h" | 10 #include "content/child/npapi/plugin_host.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 headers, | 321 headers, |
| 322 expected_length, | 322 expected_length, |
| 323 last_modified, | 323 last_modified, |
| 324 request_is_seekable); | 324 request_is_seekable); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void PluginURLFetcher::OnDownloadedData(int len, | 327 void PluginURLFetcher::OnDownloadedData(int len, |
| 328 int encoded_data_length) { | 328 int encoded_data_length) { |
| 329 } | 329 } |
| 330 | 330 |
| 331 void PluginURLFetcher::OnReceivedData(const char* data, | 331 void PluginURLFetcher::OnReceivedData(scoped_ptr<ReceivedData> data) { |
| 332 int data_length, | 332 const char* payload = data->payload(); |
| 333 int encoded_data_length) { | 333 int data_length = data->length(); |
| 334 int encoded_data_length = data->encoded_length(); |
| 334 if (!plugin_stream_) | 335 if (!plugin_stream_) |
| 335 return; | 336 return; |
| 336 | 337 |
| 337 if (multipart_delegate_) { | 338 if (multipart_delegate_) { |
| 338 multipart_delegate_->OnReceivedData(data, data_length, encoded_data_length); | 339 multipart_delegate_->OnReceivedData(payload, data_length, |
| 340 encoded_data_length); |
| 339 } else { | 341 } else { |
| 340 int64 offset = data_offset_; | 342 int64 offset = data_offset_; |
| 341 data_offset_ += data_length; | 343 data_offset_ += data_length; |
| 342 | 344 |
| 343 if (copy_stream_data_) { | 345 if (copy_stream_data_) { |
| 344 // QuickTime writes to this memory, and since we got it from | 346 // QuickTime writes to this memory, and since we got it from |
| 345 // ResourceDispatcher it's not mapped for write access in this process. | 347 // ResourceDispatcher it's not mapped for write access in this process. |
| 346 // http://crbug.com/308466. | 348 // http://crbug.com/308466. |
| 347 scoped_ptr<char[]> data_copy(new char[data_length]); | 349 scoped_ptr<char[]> data_copy(new char[data_length]); |
| 348 memcpy(data_copy.get(), data, data_length); | 350 memcpy(data_copy.get(), payload, data_length); |
| 349 plugin_stream_->DidReceiveData(data_copy.get(), data_length, offset); | 351 plugin_stream_->DidReceiveData(data_copy.get(), data_length, offset); |
| 350 } else { | 352 } else { |
| 351 plugin_stream_->DidReceiveData(data, data_length, offset); | 353 plugin_stream_->DidReceiveData(payload, data_length, offset); |
| 352 } | 354 } |
| 353 // DANGER: this instance may be deleted at this point. | 355 // DANGER: this instance may be deleted at this point. |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | 358 |
| 357 void PluginURLFetcher::OnCompletedRequest( | 359 void PluginURLFetcher::OnCompletedRequest( |
| 358 int error_code, | 360 int error_code, |
| 359 bool was_ignored_by_handler, | 361 bool was_ignored_by_handler, |
| 360 bool stale_copy_in_cache, | 362 bool stale_copy_in_cache, |
| 361 const std::string& security_info, | 363 const std::string& security_info, |
| 362 const base::TimeTicks& completion_time, | 364 const base::TimeTicks& completion_time, |
| 363 int64 total_transfer_size) { | 365 int64 total_transfer_size) { |
| 364 if (!plugin_stream_) | 366 if (!plugin_stream_) |
| 365 return; | 367 return; |
| 366 | 368 |
| 367 if (multipart_delegate_) { | 369 if (multipart_delegate_) { |
| 368 multipart_delegate_->OnCompletedRequest(); | 370 multipart_delegate_->OnCompletedRequest(); |
| 369 multipart_delegate_.reset(); | 371 multipart_delegate_.reset(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 if (error_code == net::OK) { | 374 if (error_code == net::OK) { |
| 373 plugin_stream_->DidFinishLoading(resource_id_); | 375 plugin_stream_->DidFinishLoading(resource_id_); |
| 374 } else { | 376 } else { |
| 375 plugin_stream_->DidFail(resource_id_); | 377 plugin_stream_->DidFail(resource_id_); |
| 376 } | 378 } |
| 377 } | 379 } |
| 378 | 380 |
| 379 } // namespace content | 381 } // namespace content |
| OLD | NEW |