| 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..d6439d7b165d13823ee3f3f269c913d0f66982a7 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,17 +38,34 @@ void NotifyRendererOfError(
|
| 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);
|
| +void DoRegisterOpenedNaClExecutableFilePnacl(
|
| + scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter,
|
| + base::File file,
|
| + base::FilePath file_path,
|
| + IPC::Message* reply_msg) {
|
| + // 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());
|
| +
|
| + NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams(
|
| + reply_msg, file_desc, file_token_lo, file_token_hi);
|
| + nacl_host_message_filter->Send(reply_msg);
|
| +}
|
|
|
| void DoRegisterOpenedNaClExecutableFile(
|
| scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter,
|
| base::File file,
|
| base::FilePath file_path,
|
| - IPC::Message* reply_msg,
|
| - WriteFileInfoReply write_reply_message) {
|
| + scoped_ptr<base::File[]> resource_files,
|
| + const std::vector<base::FilePath>& resource_file_paths,
|
| + IPC::Message* reply_msg) {
|
| // IO thread owns the NaClBrowser singleton.
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
| @@ -59,8 +77,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);
|
| + NaClHostMsg_OpenNaClResources::WriteReplyParams(
|
| + reply_msg,
|
| + nacl::NaClOpenExecutableResult(nexe_file_info, resource_files_info));
|
| nacl_host_message_filter->Send(reply_msg);
|
| }
|
|
|
| @@ -100,11 +136,9 @@ 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>(
|
| - NaClHostMsg_GetReadonlyPnaclFD::WriteReplyParams)));
|
| + Passed(file_to_open.Pass()), full_filepath, reply_msg));
|
| } else {
|
| IPC::PlatformFileForTransit target_desc =
|
| IPC::TakeFileHandleForProcess(file_to_open.Pass(),
|
| @@ -119,15 +153,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 +172,45 @@ 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));
|
| }
|
|
|
| } // namespace
|
| @@ -207,18 +266,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 +294,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);
|
| }
|
| }
|
|
|