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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task_scheduler/post_task.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
17 #include "components/nacl/browser/bad_message.h" | 18 #include "components/nacl/browser/bad_message.h" |
18 #include "components/nacl/browser/nacl_browser.h" | 19 #include "components/nacl/browser/nacl_browser.h" |
19 #include "components/nacl/browser/nacl_browser_delegate.h" | 20 #include "components/nacl/browser/nacl_browser_delegate.h" |
20 #include "components/nacl/browser/nacl_host_message_filter.h" | 21 #include "components/nacl/browser/nacl_host_message_filter.h" |
21 #include "components/nacl/common/nacl_host_messages.h" | 22 #include "components/nacl/common/nacl_host_messages.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
25 #include "ipc/ipc_platform_file.h" | 26 #include "ipc/ipc_platform_file.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); | 68 write_reply_message(reply_msg, file_desc, file_token_lo, file_token_hi); |
68 nacl_host_message_filter->Send(reply_msg); | 69 nacl_host_message_filter->Send(reply_msg); |
69 } | 70 } |
70 | 71 |
71 void DoOpenPnaclFile( | 72 void DoOpenPnaclFile( |
72 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 73 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
73 const std::string& filename, | 74 const std::string& filename, |
74 bool is_executable, | 75 bool is_executable, |
75 IPC::Message* reply_msg) { | 76 IPC::Message* reply_msg) { |
76 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
77 base::FilePath full_filepath; | 77 base::FilePath full_filepath; |
78 | 78 |
79 // PNaCl must be installed. | 79 // PNaCl must be installed. |
80 base::FilePath pnacl_dir; | 80 base::FilePath pnacl_dir; |
81 if (!nacl::NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || | 81 if (!nacl::NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || |
82 !base::PathExists(pnacl_dir)) { | 82 !base::PathExists(pnacl_dir)) { |
83 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 83 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 // Convert the file URL into a file descriptor. | 122 // Convert the file URL into a file descriptor. |
123 // This function is security sensitive. Be sure to check with a security | 123 // This function is security sensitive. Be sure to check with a security |
124 // person before you modify it. | 124 // person before you modify it. |
125 void DoOpenNaClExecutableOnThreadPool( | 125 void DoOpenNaClExecutableOnThreadPool( |
126 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 126 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
127 const GURL& file_url, | 127 const GURL& file_url, |
128 bool enable_validation_caching, | 128 bool enable_validation_caching, |
129 IPC::Message* reply_msg) { | 129 IPC::Message* reply_msg) { |
130 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
131 | |
132 base::FilePath file_path; | 130 base::FilePath file_path; |
133 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( | 131 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
134 file_url, | 132 file_url, |
135 true /* use_blocking_api */, | 133 true /* use_blocking_api */, |
136 nacl_host_message_filter->profile_directory(), | 134 nacl_host_message_filter->profile_directory(), |
137 &file_path)) { | 135 &file_path)) { |
138 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 136 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
139 return; | 137 return; |
140 } | 138 } |
141 | 139 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 171 |
174 } // namespace | 172 } // namespace |
175 | 173 |
176 namespace nacl_file_host { | 174 namespace nacl_file_host { |
177 | 175 |
178 void GetReadonlyPnaclFd( | 176 void GetReadonlyPnaclFd( |
179 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 177 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
180 const std::string& filename, | 178 const std::string& filename, |
181 bool is_executable, | 179 bool is_executable, |
182 IPC::Message* reply_msg) { | 180 IPC::Message* reply_msg) { |
183 if (!BrowserThread::PostBlockingPoolTask( | 181 base::PostTaskWithTraits( |
184 FROM_HERE, | 182 FROM_HERE, base::TaskTraits().MayBlock(), |
185 base::Bind(&DoOpenPnaclFile, | 183 base::Bind(&DoOpenPnaclFile, nacl_host_message_filter, filename, |
186 nacl_host_message_filter, | 184 is_executable, reply_msg)); |
187 filename, | |
188 is_executable, | |
189 reply_msg))) { | |
190 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | |
191 } | |
192 } | 185 } |
193 | 186 |
194 // This function is security sensitive. Be sure to check with a security | 187 // This function is security sensitive. Be sure to check with a security |
195 // person before you modify it. | 188 // person before you modify it. |
196 bool PnaclCanOpenFile(const std::string& filename, | 189 bool PnaclCanOpenFile(const std::string& filename, |
197 base::FilePath* file_to_open) { | 190 base::FilePath* file_to_open) { |
198 if (filename.length() > kMaxFileLength) | 191 if (filename.length() > kMaxFileLength) |
199 return false; | 192 return false; |
200 | 193 |
201 if (filename.empty()) | 194 if (filename.empty()) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), | 252 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), |
260 site_instance->GetSiteURL(), | 253 site_instance->GetSiteURL(), |
261 file_url)) { | 254 file_url)) { |
262 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 255 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
263 return; | 256 return; |
264 } | 257 } |
265 | 258 |
266 // The URL is part of the current app. Now query the extension system for the | 259 // The URL is part of the current app. Now query the extension system for the |
267 // file path and convert that to a file descriptor. This should be done on a | 260 // file path and convert that to a file descriptor. This should be done on a |
268 // blocking pool thread. | 261 // blocking pool thread. |
269 if (!BrowserThread::PostBlockingPoolTask( | 262 base::PostTaskWithTraits( |
270 FROM_HERE, | 263 FROM_HERE, base::TaskTraits().MayBlock(), |
271 base::Bind( | 264 base::Bind(&DoOpenNaClExecutableOnThreadPool, nacl_host_message_filter, |
272 &DoOpenNaClExecutableOnThreadPool, | 265 file_url, enable_validation_caching, reply_msg)); |
273 nacl_host_message_filter, | |
274 file_url, | |
275 enable_validation_caching, | |
276 reply_msg))) { | |
277 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | |
278 } | |
279 } | 266 } |
280 | 267 |
281 } // namespace nacl_file_host | 268 } // namespace nacl_file_host |
OLD | NEW |