| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 nacl_host_message_filter->Send(reply_msg); | 115 nacl_host_message_filter->Send(reply_msg); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Convert the file URL into a file descriptor. | 119 // Convert the file URL into a file descriptor. |
| 120 // This function is security sensitive. Be sure to check with a security | 120 // This function is security sensitive. Be sure to check with a security |
| 121 // person before you modify it. | 121 // person before you modify it. |
| 122 void DoOpenNaClExecutableOnThreadPool( | 122 void DoOpenNaClExecutableOnThreadPool( |
| 123 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 123 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| 124 const GURL& file_url, | 124 const GURL& file_url, |
| 125 bool enable_validation_caching, |
| 125 IPC::Message* reply_msg) { | 126 IPC::Message* reply_msg) { |
| 126 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 127 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 127 | 128 |
| 128 base::FilePath file_path; | 129 base::FilePath file_path; |
| 129 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( | 130 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
| 130 file_url, | 131 file_url, |
| 131 true /* use_blocking_api */, | 132 true /* use_blocking_api */, |
| 132 nacl_host_message_filter->profile_directory(), | 133 nacl_host_message_filter->profile_directory(), |
| 133 &file_path)) { | 134 &file_path)) { |
| 134 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 135 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 135 return; | 136 return; |
| 136 } | 137 } |
| 137 | 138 |
| 138 base::File file = nacl::OpenNaClReadExecImpl(file_path, | 139 base::File file = nacl::OpenNaClReadExecImpl(file_path, |
| 139 true /* is_executable */); | 140 true /* is_executable */); |
| 140 if (file.IsValid()) { | 141 if (file.IsValid()) { |
| 141 // This function is running on the blocking pool, but the path needs to be | 142 // Opening a NaCl executable works with or without validation caching. |
| 142 // registered in a structure owned by the IO thread. | 143 // Validation caching requires that the file descriptor is registered now |
| 143 BrowserThread::PostTask( | 144 // for later use, which will save time. |
| 144 BrowserThread::IO, FROM_HERE, | 145 // When validation caching isn't used (e.g. Non-SFI mode), there is no |
| 145 base::Bind( | 146 // reason to do that unnecessary registration. |
| 146 &DoRegisterOpenedNaClExecutableFile, | 147 if (enable_validation_caching) { |
| 147 nacl_host_message_filter, | 148 // This function is running on the blocking pool, but the path needs to be |
| 148 Passed(file.Pass()), file_path, reply_msg, | 149 // registered in a structure owned by the IO thread. |
| 149 static_cast<WriteFileInfoReply>( | 150 BrowserThread::PostTask( |
| 150 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); | 151 BrowserThread::IO, FROM_HERE, |
| 152 base::Bind( |
| 153 &DoRegisterOpenedNaClExecutableFile, |
| 154 nacl_host_message_filter, |
| 155 Passed(file.Pass()), file_path, reply_msg, |
| 156 static_cast<WriteFileInfoReply>( |
| 157 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); |
| 158 } else { |
| 159 IPC::PlatformFileForTransit file_desc = |
| 160 IPC::TakeFileHandleForProcess(file.Pass(), |
| 161 nacl_host_message_filter->PeerHandle()); |
| 162 uint64_t dummy_file_token = 0; |
| 163 NaClHostMsg_OpenNaClExecutable::WriteReplyParams( |
| 164 reply_msg, file_desc, dummy_file_token, dummy_file_token); |
| 165 nacl_host_message_filter->Send(reply_msg); |
| 166 } |
| 151 } else { | 167 } else { |
| 152 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 168 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 153 return; | 169 return; |
| 154 } | 170 } |
| 155 } | 171 } |
| 156 | 172 |
| 157 } // namespace | 173 } // namespace |
| 158 | 174 |
| 159 namespace nacl_file_host { | 175 namespace nacl_file_host { |
| 160 | 176 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 base::FilePath full_path = pnacl_dir.AppendASCII( | 220 base::FilePath full_path = pnacl_dir.AppendASCII( |
| 205 std::string(kExpectedFilePrefix) + filename); | 221 std::string(kExpectedFilePrefix) + filename); |
| 206 *file_to_open = full_path; | 222 *file_to_open = full_path; |
| 207 return true; | 223 return true; |
| 208 } | 224 } |
| 209 | 225 |
| 210 void OpenNaClExecutable( | 226 void OpenNaClExecutable( |
| 211 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 227 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| 212 int render_view_id, | 228 int render_view_id, |
| 213 const GURL& file_url, | 229 const GURL& file_url, |
| 230 bool enable_validation_caching, |
| 214 IPC::Message* reply_msg) { | 231 IPC::Message* reply_msg) { |
| 215 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 232 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 216 BrowserThread::PostTask( | 233 BrowserThread::PostTask( |
| 217 BrowserThread::UI, FROM_HERE, | 234 BrowserThread::UI, FROM_HERE, |
| 218 base::Bind( | 235 base::Bind( |
| 219 &OpenNaClExecutable, | 236 &OpenNaClExecutable, |
| 220 nacl_host_message_filter, | 237 nacl_host_message_filter, |
| 221 render_view_id, file_url, reply_msg)); | 238 render_view_id, |
| 239 file_url, |
| 240 enable_validation_caching, |
| 241 reply_msg)); |
| 222 return; | 242 return; |
| 223 } | 243 } |
| 224 | 244 |
| 225 // Make sure render_view_id is valid and that the URL is a part of the | 245 // Make sure render_view_id is valid and that the URL is a part of the |
| 226 // render view's site. Without these checks, apps could probe the extension | 246 // render view's site. Without these checks, apps could probe the extension |
| 227 // directory or run NaCl code from other extensions. | 247 // directory or run NaCl code from other extensions. |
| 228 content::RenderViewHost* rvh = content::RenderViewHost::FromID( | 248 content::RenderViewHost* rvh = content::RenderViewHost::FromID( |
| 229 nacl_host_message_filter->render_process_id(), render_view_id); | 249 nacl_host_message_filter->render_process_id(), render_view_id); |
| 230 if (!rvh) { | 250 if (!rvh) { |
| 231 nacl_host_message_filter->BadMessageReceived(); // Kill the renderer. | 251 nacl_host_message_filter->BadMessageReceived(); // Kill the renderer. |
| 232 return; | 252 return; |
| 233 } | 253 } |
| 234 content::SiteInstance* site_instance = rvh->GetSiteInstance(); | 254 content::SiteInstance* site_instance = rvh->GetSiteInstance(); |
| 235 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), | 255 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), |
| 236 site_instance->GetSiteURL(), | 256 site_instance->GetSiteURL(), |
| 237 file_url)) { | 257 file_url)) { |
| 238 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 258 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 239 return; | 259 return; |
| 240 } | 260 } |
| 241 | 261 |
| 242 // The URL is part of the current app. Now query the extension system for the | 262 // The URL is part of the current app. Now query the extension system for the |
| 243 // file path and convert that to a file descriptor. This should be done on a | 263 // file path and convert that to a file descriptor. This should be done on a |
| 244 // blocking pool thread. | 264 // blocking pool thread. |
| 245 if (!BrowserThread::PostBlockingPoolTask( | 265 if (!BrowserThread::PostBlockingPoolTask( |
| 246 FROM_HERE, | 266 FROM_HERE, |
| 247 base::Bind( | 267 base::Bind( |
| 248 &DoOpenNaClExecutableOnThreadPool, | 268 &DoOpenNaClExecutableOnThreadPool, |
| 249 nacl_host_message_filter, | 269 nacl_host_message_filter, |
| 250 file_url, reply_msg))) { | 270 file_url, |
| 271 enable_validation_caching, |
| 272 reply_msg))) { |
| 251 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 273 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 252 } | 274 } |
| 253 } | 275 } |
| 254 | 276 |
| 255 } // namespace nacl_file_host | 277 } // namespace nacl_file_host |
| OLD | NEW |