| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/renderer_host/media_resource_handler.h" | |
| 6 | |
| 7 #include "base/process.h" | |
| 8 #include "chrome/common/render_messages.h" | |
| 9 #include "net/base/load_flags.h" | |
| 10 | |
| 11 MediaResourceHandler::MediaResourceHandler( | |
| 12 ResourceHandler* resource_handler, | |
| 13 ResourceDispatcherHost::Receiver* receiver, | |
| 14 int render_process_host_id, | |
| 15 int routing_id, | |
| 16 base::ProcessHandle render_process, | |
| 17 ResourceDispatcherHost* resource_dispatcher_host) | |
| 18 : receiver_(receiver), | |
| 19 render_process_host_id_(render_process_host_id), | |
| 20 routing_id_(routing_id), | |
| 21 render_process_(render_process), | |
| 22 handler_(resource_handler), | |
| 23 rdh_(resource_dispatcher_host), | |
| 24 has_file_handle_(false), | |
| 25 position_(0), | |
| 26 size_(-1) { | |
| 27 } | |
| 28 | |
| 29 bool MediaResourceHandler::OnUploadProgress(int request_id, | |
| 30 uint64 position, | |
| 31 uint64 size) { | |
| 32 return handler_->OnUploadProgress(request_id, position, size); | |
| 33 } | |
| 34 | |
| 35 bool MediaResourceHandler::OnRequestRedirected(int request_id, | |
| 36 const GURL& new_url) { | |
| 37 return handler_->OnRequestRedirected(request_id, new_url); | |
| 38 } | |
| 39 | |
| 40 bool MediaResourceHandler::OnResponseStarted(int request_id, | |
| 41 ResourceResponse* response) { | |
| 42 #if defined(OS_POSIX) | |
| 43 if (response->response_head.response_data_file.fd != | |
| 44 base::kInvalidPlatformFileValue) { | |
| 45 // On POSIX, we will just set auto_close to true, and the IPC infrastructure | |
| 46 // will send this file handle through and close it automatically. | |
| 47 response->response_head.response_data_file.auto_close = true; | |
| 48 has_file_handle_ = true; | |
| 49 } | |
| 50 #elif defined(OS_WIN) | |
| 51 if (response->response_head.response_data_file != | |
| 52 base::kInvalidPlatformFileValue) { | |
| 53 // On Windows, we duplicate the file handle for the renderer process and | |
| 54 // close the original manually. | |
| 55 base::PlatformFile foreign_handle; | |
| 56 if (DuplicateHandle(GetCurrentProcess(), | |
| 57 response->response_head.response_data_file, | |
| 58 render_process_, | |
| 59 &foreign_handle, | |
| 60 FILE_READ_DATA, // Only allow read access to data. | |
| 61 false, // Foreign handle is not inheritable. | |
| 62 // Close the file handle after duplication. | |
| 63 DUPLICATE_CLOSE_SOURCE)){ | |
| 64 response->response_head.response_data_file = foreign_handle; | |
| 65 has_file_handle_ = true; | |
| 66 } else { | |
| 67 has_file_handle_ = false; | |
| 68 } | |
| 69 } | |
| 70 #endif | |
| 71 size_ = response->response_head.content_length; | |
| 72 return handler_->OnResponseStarted(request_id, response); | |
| 73 } | |
| 74 | |
| 75 bool MediaResourceHandler::OnWillRead(int request_id, | |
| 76 net::IOBuffer** buf, int* buf_size, | |
| 77 int min_size) { | |
| 78 return handler_->OnWillRead(request_id, buf, buf_size, min_size); | |
| 79 } | |
| 80 | |
| 81 bool MediaResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { | |
| 82 if (has_file_handle_) { | |
| 83 // If we have received a file handle before we will be sending a progress | |
| 84 // update for download. | |
| 85 // TODO(hclam): rate limit this message so we won't be sending too much to | |
| 86 // the renderer process. | |
| 87 receiver_->Send( | |
| 88 new ViewMsg_Resource_DownloadProgress(routing_id_, request_id, | |
| 89 position_, size_)); | |
| 90 position_ += *bytes_read; | |
| 91 } | |
| 92 return handler_->OnReadCompleted(request_id, bytes_read); | |
| 93 } | |
| 94 | |
| 95 bool MediaResourceHandler::OnResponseCompleted(int request_id, | |
| 96 const URLRequestStatus& status, const std::string& security_info) { | |
| 97 return handler_->OnResponseCompleted(request_id, status, security_info); | |
| 98 } | |
| OLD | NEW |