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