| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/nacl/browser/nacl_file_host.h" | 5 #include "components/nacl/browser/nacl_file_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "components/nacl/browser/bad_message.h" | 17 #include "components/nacl/browser/bad_message.h" |
| 17 #include "components/nacl/browser/nacl_browser.h" | 18 #include "components/nacl/browser/nacl_browser.h" |
| 18 #include "components/nacl/browser/nacl_browser_delegate.h" | 19 #include "components/nacl/browser/nacl_browser_delegate.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 WriteFileInfoReply write_reply_message) { | 55 WriteFileInfoReply write_reply_message) { |
| 55 // IO thread owns the NaClBrowser singleton. | 56 // IO thread owns the NaClBrowser singleton. |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 57 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 | 58 |
| 58 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 59 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| 59 uint64_t file_token_lo = 0; | 60 uint64_t file_token_lo = 0; |
| 60 uint64_t file_token_hi = 0; | 61 uint64_t file_token_hi = 0; |
| 61 nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); | 62 nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); |
| 62 | 63 |
| 63 IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( | 64 IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| 64 file.Pass(), | 65 std::move(file), nacl_host_message_filter->PeerHandle()); |
| 65 nacl_host_message_filter->PeerHandle()); | |
| 66 | 66 |
| 67 write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); | 67 write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); |
| 68 nacl_host_message_filter->Send(reply_msg); | 68 nacl_host_message_filter->Send(reply_msg); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DoOpenPnaclFile( | 71 void DoOpenPnaclFile( |
| 72 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 72 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| 73 const std::string& filename, | 73 const std::string& filename, |
| 74 bool is_executable, | 74 bool is_executable, |
| 75 IPC::Message* reply_msg) { | 75 IPC::Message* reply_msg) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 // This function is running on the blocking pool, but the path needs to be | 100 // This function is running on the blocking pool, but the path needs to be |
| 101 // registered in a structure owned by the IO thread. | 101 // registered in a structure owned by the IO thread. |
| 102 // Not all PNaCl files are executable. Only register those that are | 102 // Not all PNaCl files are executable. Only register those that are |
| 103 // executable in the NaCl file_path cache. | 103 // executable in the NaCl file_path cache. |
| 104 if (is_executable) { | 104 if (is_executable) { |
| 105 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
| 106 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
| 107 base::Bind(&DoRegisterOpenedNaClExecutableFile, | 107 base::Bind(&DoRegisterOpenedNaClExecutableFile, |
| 108 nacl_host_message_filter, | 108 nacl_host_message_filter, Passed(std::move(file_to_open)), |
| 109 Passed(file_to_open.Pass()), full_filepath, reply_msg, | 109 full_filepath, reply_msg, |
| 110 static_cast<WriteFileInfoReply>( | 110 static_cast<WriteFileInfoReply>( |
| 111 NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams))); | 111 NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams))); |
| 112 } else { | 112 } else { |
| 113 IPC::PlatformFileForTransit target_desc = | 113 IPC::PlatformFileForTransit target_desc = IPC::TakeFileHandleForProcess( |
| 114 IPC::TakeFileHandleForProcess(file_to_open.Pass(), | 114 std::move(file_to_open), nacl_host_message_filter->PeerHandle()); |
| 115 nacl_host_message_filter->PeerHandle()); | |
| 116 uint64_t dummy_file_token = 0; | 115 uint64_t dummy_file_token = 0; |
| 117 NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams( | 116 NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams( |
| 118 reply_msg, target_desc, dummy_file_token, dummy_file_token); | 117 reply_msg, target_desc, dummy_file_token, dummy_file_token); |
| 119 nacl_host_message_filter->Send(reply_msg); | 118 nacl_host_message_filter->Send(reply_msg); |
| 120 } | 119 } |
| 121 } | 120 } |
| 122 | 121 |
| 123 // Convert the file URL into a file descriptor. | 122 // Convert the file URL into a file descriptor. |
| 124 // This function is security sensitive. Be sure to check with a security | 123 // This function is security sensitive. Be sure to check with a security |
| 125 // person before you modify it. | 124 // person before you modify it. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 // Opening a NaCl executable works with or without validation caching. | 145 // Opening a NaCl executable works with or without validation caching. |
| 147 // Validation caching requires that the file descriptor is registered now | 146 // Validation caching requires that the file descriptor is registered now |
| 148 // for later use, which will save time. | 147 // for later use, which will save time. |
| 149 // When validation caching isn't used (e.g. Non-SFI mode), there is no | 148 // When validation caching isn't used (e.g. Non-SFI mode), there is no |
| 150 // reason to do that unnecessary registration. | 149 // reason to do that unnecessary registration. |
| 151 if (enable_validation_caching) { | 150 if (enable_validation_caching) { |
| 152 // This function is running on the blocking pool, but the path needs to be | 151 // This function is running on the blocking pool, but the path needs to be |
| 153 // registered in a structure owned by the IO thread. | 152 // registered in a structure owned by the IO thread. |
| 154 BrowserThread::PostTask( | 153 BrowserThread::PostTask( |
| 155 BrowserThread::IO, FROM_HERE, | 154 BrowserThread::IO, FROM_HERE, |
| 156 base::Bind( | 155 base::Bind(&DoRegisterOpenedNaClExecutableFile, |
| 157 &DoRegisterOpenedNaClExecutableFile, | 156 nacl_host_message_filter, Passed(std::move(file)), |
| 158 nacl_host_message_filter, | 157 file_path, reply_msg, |
| 159 Passed(file.Pass()), file_path, reply_msg, | 158 static_cast<WriteFileInfoReply>( |
| 160 static_cast<WriteFileInfoReply>( | 159 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); |
| 161 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); | |
| 162 } else { | 160 } else { |
| 163 IPC::PlatformFileForTransit file_desc = | 161 IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| 164 IPC::TakeFileHandleForProcess(file.Pass(), | 162 std::move(file), nacl_host_message_filter->PeerHandle()); |
| 165 nacl_host_message_filter->PeerHandle()); | |
| 166 uint64_t dummy_file_token = 0; | 163 uint64_t dummy_file_token = 0; |
| 167 NaClHostMsg_OpenNaClExecutable::WriteReplyParams( | 164 NaClHostMsg_OpenNaClExecutable::WriteReplyParams( |
| 168 reply_msg, file_desc, dummy_file_token, dummy_file_token); | 165 reply_msg, file_desc, dummy_file_token, dummy_file_token); |
| 169 nacl_host_message_filter->Send(reply_msg); | 166 nacl_host_message_filter->Send(reply_msg); |
| 170 } | 167 } |
| 171 } else { | 168 } else { |
| 172 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 169 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 173 return; | 170 return; |
| 174 } | 171 } |
| 175 } | 172 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 &DoOpenNaClExecutableOnThreadPool, | 272 &DoOpenNaClExecutableOnThreadPool, |
| 276 nacl_host_message_filter, | 273 nacl_host_message_filter, |
| 277 file_url, | 274 file_url, |
| 278 enable_validation_caching, | 275 enable_validation_caching, |
| 279 reply_msg))) { | 276 reply_msg))) { |
| 280 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 277 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 281 } | 278 } |
| 282 } | 279 } |
| 283 | 280 |
| 284 } // namespace nacl_file_host | 281 } // namespace nacl_file_host |
| OLD | NEW |