Chromium Code Reviews| Index: components/nacl/browser/nacl_file_host.cc |
| diff --git a/components/nacl/browser/nacl_file_host.cc b/components/nacl/browser/nacl_file_host.cc |
| index 17e5bc5ea4208b7df545403d7b6110361051c842..8ef58dce91624bb52614ce8b6c8ba4f1596ef101 100644 |
| --- a/components/nacl/browser/nacl_file_host.cc |
| +++ b/components/nacl/browser/nacl_file_host.cc |
| @@ -14,6 +14,7 @@ |
| #include "components/nacl/browser/nacl_browser_delegate.h" |
| #include "components/nacl/browser/nacl_host_message_filter.h" |
| #include "components/nacl/common/nacl_host_messages.h" |
| +#include "components/nacl/common/nacl_types.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/site_instance.h" |
| @@ -37,15 +38,41 @@ void NotifyRendererOfError( |
| nacl_host_message_filter->Send(reply_msg); |
| } |
| +typedef void (*WriteFileInfoReplyPnacl)(IPC::Message* reply_msg, |
| + IPC::PlatformFileForTransit file_desc, |
| + uint64 file_token_lo, |
| + uint64 file_token_hi); |
| + |
| +void DoRegisterOpenedNaClExecutableFilePnacl( |
| + scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| + base::File file, |
| + base::FilePath file_path, |
| + IPC::Message* reply_msg, |
| + WriteFileInfoReplyPnacl write_reply_message) { |
| + // IO thread owns the NaClBrowser singleton. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| + uint64 file_token_lo = 0; |
| + uint64 file_token_hi = 0; |
| + nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); |
| + |
| + IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| + file.Pass(), nacl_host_message_filter->PeerHandle()); |
| + |
| + write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); |
|
teravest
2014/11/10 20:36:11
Why is write_reply_message passed as a parameter i
Yusuke Sato
2014/11/11 00:58:35
Good catch, fixed. Thanks.
|
| + nacl_host_message_filter->Send(reply_msg); |
| +} |
| + |
| typedef void (*WriteFileInfoReply)(IPC::Message* reply_msg, |
| - IPC::PlatformFileForTransit file_desc, |
| - uint64 file_token_lo, |
| - uint64 file_token_hi); |
| + nacl::NaClOpenExecutableResult open_result); |
| void DoRegisterOpenedNaClExecutableFile( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| base::File file, |
| base::FilePath file_path, |
| + scoped_ptr<base::File[]> resource_files, |
| + const std::vector<base::FilePath>& resource_file_paths, |
| IPC::Message* reply_msg, |
| WriteFileInfoReply write_reply_message) { |
| // IO thread owns the NaClBrowser singleton. |
| @@ -59,8 +86,26 @@ void DoRegisterOpenedNaClExecutableFile( |
| IPC::PlatformFileForTransit file_desc = IPC::TakeFileHandleForProcess( |
| file.Pass(), |
| nacl_host_message_filter->PeerHandle()); |
| + nacl::NaClOpenExecutableResult::FileInfo nexe_file_info( |
| + file_desc, file_token_lo, file_token_hi); |
| + |
| + std::vector<nacl::NaClOpenExecutableResult::FileInfo> resource_files_info; |
| + for (size_t i = 0; i < resource_file_paths.size(); ++i) { |
| + uint64 resource_file_token_lo = 0; |
| + uint64 resource_file_token_hi = 0; |
| + nacl_browser->PutFilePath(resource_file_paths[i], |
| + &resource_file_token_lo, |
| + &resource_file_token_hi); |
| + IPC::PlatformFileForTransit resource_file = IPC::TakeFileHandleForProcess( |
| + resource_files[i].Pass(), nacl_host_message_filter->PeerHandle()); |
| + nacl::NaClOpenExecutableResult::FileInfo resource_file_info( |
| + resource_file, resource_file_token_lo, resource_file_token_hi); |
| + resource_files_info.push_back(resource_file_info); |
| + } |
| - write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); |
| + write_reply_message( |
| + reply_msg, |
| + nacl::NaClOpenExecutableResult(nexe_file_info, resource_files_info)); |
| nacl_host_message_filter->Send(reply_msg); |
| } |
| @@ -100,10 +145,10 @@ void DoOpenPnaclFile( |
| if (is_executable) { |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| - base::Bind(&DoRegisterOpenedNaClExecutableFile, |
| + base::Bind(&DoRegisterOpenedNaClExecutableFilePnacl, |
| nacl_host_message_filter, |
| Passed(file_to_open.Pass()), full_filepath, reply_msg, |
| - static_cast<WriteFileInfoReply>( |
| + static_cast<WriteFileInfoReplyPnacl>( |
| NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams))); |
| } else { |
| IPC::PlatformFileForTransit target_desc = |
| @@ -119,15 +164,16 @@ void DoOpenPnaclFile( |
| // Convert the file URL into a file descriptor. |
| // This function is security sensitive. Be sure to check with a security |
| // person before you modify it. |
| -void DoOpenNaClExecutableOnThreadPool( |
| +void DoOpenNaClResourcesOnThreadPool( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| - const GURL& file_url, |
| + const GURL& executable_file_url, |
| + const std::vector<GURL>& resource_urls, |
| IPC::Message* reply_msg) { |
| DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| base::FilePath file_path; |
| if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
| - file_url, |
| + executable_file_url, |
| true /* use_blocking_api */, |
| nacl_host_message_filter->profile_directory(), |
| &file_path)) { |
| @@ -137,21 +183,47 @@ void DoOpenNaClExecutableOnThreadPool( |
| base::File file = nacl::OpenNaClReadExecImpl(file_path, |
| true /* is_executable */); |
| - if (file.IsValid()) { |
| - // This function is running on the blocking pool, but the path needs to be |
| - // registered in a structure owned by the IO thread. |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind( |
| - &DoRegisterOpenedNaClExecutableFile, |
| - nacl_host_message_filter, |
| - Passed(file.Pass()), file_path, reply_msg, |
| - static_cast<WriteFileInfoReply>( |
| - NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); |
| - } else { |
| + if (!file.IsValid()) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| return; |
| } |
| + |
| + scoped_ptr<base::File[]> resource_files; |
| + if (!resource_urls.empty()) |
| + resource_files.reset(new base::File[resource_urls.size()]); |
| + std::vector<base::FilePath> resource_file_paths(resource_urls.size()); |
| + |
| + for (size_t i = 0; i < resource_urls.size(); ++i) { |
| + if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
| + resource_urls[i], |
| + true /* use_blocking_api */, |
| + nacl_host_message_filter->profile_directory(), |
| + &resource_file_paths[i])) { |
| + NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| + return; |
| + } |
| + resource_files[i] = nacl::OpenNaClReadExecImpl(resource_file_paths[i], |
| + true /* is_executable */); |
| + if (!resource_files[i].IsValid()) { |
| + NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| + return; |
| + } |
| + } |
| + |
| + // This function is running on the blocking pool, but the path needs to be |
| + // registered in a structure owned by the IO thread. |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&DoRegisterOpenedNaClExecutableFile, |
| + nacl_host_message_filter, |
| + Passed(file.Pass()), |
| + file_path, |
| + Passed(resource_files.Pass()), |
| + resource_file_paths, |
| + reply_msg, |
| + static_cast<WriteFileInfoReply>( |
| + NaClHostMsg_OpenNaClResources::WriteReplyParams))); |
| } |
| } // namespace |
| @@ -207,18 +279,19 @@ bool PnaclCanOpenFile(const std::string& filename, |
| return true; |
| } |
| -void OpenNaClExecutable( |
| +void OpenNaClResources( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| int render_view_id, |
| - const GURL& file_url, |
| + const GURL& executable_file_url, |
| + const std::vector<GURL>& resource_urls, |
| IPC::Message* reply_msg) { |
| if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| base::Bind( |
| - &OpenNaClExecutable, |
| + &OpenNaClResources, |
| nacl_host_message_filter, |
| - render_view_id, file_url, reply_msg)); |
| + render_view_id, executable_file_url, resource_urls, reply_msg)); |
| return; |
| } |
| @@ -234,20 +307,30 @@ void OpenNaClExecutable( |
| content::SiteInstance* site_instance = rvh->GetSiteInstance(); |
| if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), |
| site_instance->GetSiteURL(), |
| - file_url)) { |
| + executable_file_url)) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| return; |
| } |
| + for (size_t i = 0; i < resource_urls.size(); ++i) { |
| + if (!content::SiteInstance::IsSameWebSite( |
| + site_instance->GetBrowserContext(), |
| + site_instance->GetSiteURL(), |
| + resource_urls[i])) { |
| + NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| + return; |
| + } |
| + } |
| + |
| // The URL is part of the current app. Now query the extension system for the |
| // file path and convert that to a file descriptor. This should be done on a |
| // blocking pool thread. |
| if (!BrowserThread::PostBlockingPoolTask( |
| FROM_HERE, |
| base::Bind( |
| - &DoOpenNaClExecutableOnThreadPool, |
| + &DoOpenNaClResourcesOnThreadPool, |
| nacl_host_message_filter, |
| - file_url, reply_msg))) { |
| + executable_file_url, resource_urls, reply_msg))) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| } |
| } |