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 497683a75ae581762bff81d6af8726baa59220d8..58f43b7e45d38cadab21ee6199b13833c332eb8f 100644 |
| --- a/components/nacl/browser/nacl_file_host.cc |
| +++ b/components/nacl/browser/nacl_file_host.cc |
| @@ -15,6 +15,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" |
| @@ -38,15 +39,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); |
| + 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. |
| @@ -61,7 +88,26 @@ void DoRegisterOpenedNaClExecutableFile( |
| file.Pass(), |
| nacl_host_message_filter->PeerHandle()); |
| - write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); |
| + std::vector<IPC::PlatformFileForTransit> resource_file_handles; |
| + std::vector<std::pair<uint64, uint64> > resource_file_tokens; |
|
teravest
2014/10/24 16:18:06
Why are you using a pair of uint64 here instead of
Yusuke Sato
2014/11/04 22:50:21
Stopped using a pair and switched to a struct foll
|
| + 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); |
| + resource_file_handles.push_back(IPC::TakeFileHandleForProcess( |
| + resource_files[i].Pass(), nacl_host_message_filter->PeerHandle())); |
| + resource_file_tokens.push_back(std::make_pair(resource_file_token_lo, |
| + resource_file_token_hi)); |
| + } |
| + |
| + write_reply_message(reply_msg, |
| + nacl::NaClOpenExecutableResult(file_desc, |
| + file_token_lo, |
| + file_token_hi, |
| + resource_file_handles, |
| + resource_file_tokens)); |
| nacl_host_message_filter->Send(reply_msg); |
| } |
| @@ -101,10 +147,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 = |
| @@ -123,6 +169,7 @@ void DoOpenPnaclFile( |
| void DoOpenNaClExecutableOnThreadPool( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| const GURL& file_url, |
| + const std::vector<GURL>& resource_urls, |
| IPC::Message* reply_msg) { |
| DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| @@ -138,21 +185,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; |
|
teravest
2014/10/24 16:18:05
nit: Why not just do the following?
scoped_ptr<b
Yusuke Sato
2014/11/04 22:50:21
This is because resource_urls can be empty (eg. wh
|
| + 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_OpenNaClExecutable::WriteReplyParams))); |
| } |
| } // namespace |
| @@ -212,6 +285,7 @@ void OpenNaClExecutable( |
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
| int render_view_id, |
| const GURL& file_url, |
| + const std::vector<GURL>& resource_urls, |
| IPC::Message* reply_msg) { |
| if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| BrowserThread::PostTask( |
| @@ -219,7 +293,7 @@ void OpenNaClExecutable( |
| base::Bind( |
| &OpenNaClExecutable, |
| nacl_host_message_filter, |
| - render_view_id, file_url, reply_msg)); |
| + render_view_id, file_url, resource_urls, reply_msg)); |
| return; |
| } |
| @@ -240,6 +314,16 @@ void OpenNaClExecutable( |
| 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. |
| @@ -248,7 +332,7 @@ void OpenNaClExecutable( |
| base::Bind( |
| &DoOpenNaClExecutableOnThreadPool, |
| nacl_host_message_filter, |
| - file_url, reply_msg))) { |
| + file_url, resource_urls, reply_msg))) { |
| NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| } |
| } |