summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/nacl_host/pnacl_file_host.cc52
-rw-r--r--chrome/browser/nacl_host/pnacl_file_host.h6
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.cc7
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.h1
4 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/nacl_host/pnacl_file_host.cc b/chrome/browser/nacl_host/pnacl_file_host.cc
index a518668..fa0e5f0 100644
--- a/chrome/browser/nacl_host/pnacl_file_host.cc
+++ b/chrome/browser/nacl_host/pnacl_file_host.cc
@@ -76,6 +76,46 @@ void DoOpenPnaclFile(
chrome_render_message_filter->Send(reply_msg);
}
+void DoCreateTemporaryFile(
+ ChromeRenderMessageFilter* chrome_render_message_filter,
+ IPC::Message* reply_msg) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ FilePath file_path;
+ if (!file_util::CreateTemporaryFile(&file_path)) {
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg);
+ return;
+ }
+
+ base::PlatformFileError error;
+ base::PlatformFile file_handle = base::CreatePlatformFile(
+ file_path,
+ base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY |
+ base::PLATFORM_FILE_DELETE_ON_CLOSE,
+ NULL, &error);
+
+ if (error != base::PLATFORM_FILE_OK) {
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg);
+ return;
+ }
+
+ // Send the reply!
+ // Do any DuplicateHandle magic that is necessary first.
+ IPC::PlatformFileForTransit target_desc =
+ IPC::GetFileHandleForProcess(file_handle,
+ chrome_render_message_filter->peer_handle(),
+ true);
+ if (target_desc == IPC::InvalidPlatformFileForTransit()) {
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg);
+ return;
+ }
+
+ ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams(
+ reply_msg, target_desc);
+ chrome_render_message_filter->Send(reply_msg);
+}
+
} // namespace
namespace pnacl_file_host {
@@ -135,4 +175,16 @@ bool PnaclCanOpenFile(const std::string& filename,
return true;
}
+void CreateTemporaryFile(
+ ChromeRenderMessageFilter* chrome_render_message_filter,
+ IPC::Message* reply_msg) {
+ if (!BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DoCreateTemporaryFile,
+ make_scoped_refptr(chrome_render_message_filter),
+ reply_msg))) {
+ NotifyRendererOfError(chrome_render_message_filter, reply_msg);
+ }
+}
+
} // namespace pnacl_file_host
diff --git a/chrome/browser/nacl_host/pnacl_file_host.h b/chrome/browser/nacl_host/pnacl_file_host.h
index 7a60a3c..7187561 100644
--- a/chrome/browser/nacl_host/pnacl_file_host.h
+++ b/chrome/browser/nacl_host/pnacl_file_host.h
@@ -28,6 +28,12 @@ void GetReadonlyPnaclFd(ChromeRenderMessageFilter* chrome_render_message_filter,
bool PnaclCanOpenFile(const std::string& filename,
FilePath* file_to_open);
+// Creates a temporary file that will be deleted when the last handle
+// is closed, or earlier.
+void CreateTemporaryFile(
+ ChromeRenderMessageFilter* chrome_render_message_filter,
+ IPC::Message* reply_msg);
+
} // namespace pnacl_file_host
#endif // CHROME_BROWSER_NACL_HOST_PNACL_FILE_HOST_H_
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc
index e646f2b..671241a 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc
@@ -76,6 +76,8 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_LaunchNaCl, OnLaunchNaCl)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_GetReadonlyPnaclFD,
OnGetReadonlyPnaclFd)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_NaClCreateTemporaryFile,
+ OnNaClCreateTemporaryFile)
#endif
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DnsPrefetch, OnDnsPrefetch)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ResourceTypeStats,
@@ -179,6 +181,11 @@ void ChromeRenderMessageFilter::OnGetReadonlyPnaclFd(
// block until the reply is sent.
pnacl_file_host::GetReadonlyPnaclFd(this, filename, reply_msg);
}
+
+void ChromeRenderMessageFilter::OnNaClCreateTemporaryFile(
+ IPC::Message* reply_msg) {
+ pnacl_file_host::CreateTemporaryFile(this, reply_msg);
+}
#endif
void ChromeRenderMessageFilter::OnDnsPrefetch(
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h
index 3dcda7d..327ff70 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.h
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.h
@@ -78,6 +78,7 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
IPC::Message* reply_msg);
void OnGetReadonlyPnaclFd(const std::string& filename,
IPC::Message* reply_msg);
+ void OnNaClCreateTemporaryFile(IPC::Message* reply_msg);
#endif
void OnDnsPrefetch(const std::vector<std::string>& hostnames);
void OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats);