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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 nacl_host_message_filter->Send(reply_msg); | 115 nacl_host_message_filter->Send(reply_msg); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 // Convert the file URL into a file descriptor. | 119 // Convert the file URL into a file descriptor. |
120 // This function is security sensitive. Be sure to check with a security | 120 // This function is security sensitive. Be sure to check with a security |
121 // person before you modify it. | 121 // person before you modify it. |
122 void DoOpenNaClExecutableOnThreadPool( | 122 void DoOpenNaClExecutableOnThreadPool( |
123 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 123 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
124 const GURL& file_url, | 124 const GURL& file_url, |
125 bool register_executable, | |
Mark Seaborn
2015/01/12 21:59:35
How about calling this something like "enable_vali
teravest
2015/01/13 16:47:34
Done.
| |
125 IPC::Message* reply_msg) { | 126 IPC::Message* reply_msg) { |
126 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 127 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
127 | 128 |
128 base::FilePath file_path; | 129 base::FilePath file_path; |
129 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( | 130 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
130 file_url, | 131 file_url, |
131 true /* use_blocking_api */, | 132 true /* use_blocking_api */, |
132 nacl_host_message_filter->profile_directory(), | 133 nacl_host_message_filter->profile_directory(), |
133 &file_path)) { | 134 &file_path)) { |
134 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 135 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
135 return; | 136 return; |
136 } | 137 } |
137 | 138 |
138 base::File file = nacl::OpenNaClReadExecImpl(file_path, | 139 base::File file = nacl::OpenNaClReadExecImpl(file_path, |
139 true /* is_executable */); | 140 true /* is_executable */); |
140 if (file.IsValid()) { | 141 if (file.IsValid()) { |
141 // This function is running on the blocking pool, but the path needs to be | 142 if (register_executable) { |
Mark Seaborn
2015/01/12 21:59:34
Can you add a comment to explain that: Both branch
teravest
2015/01/13 16:47:34
Good point. I've added a comment here.
| |
142 // registered in a structure owned by the IO thread. | 143 // This function is running on the blocking pool, but the path needs to be |
143 BrowserThread::PostTask( | 144 // registered in a structure owned by the IO thread. |
144 BrowserThread::IO, FROM_HERE, | 145 BrowserThread::PostTask( |
145 base::Bind( | 146 BrowserThread::IO, FROM_HERE, |
146 &DoRegisterOpenedNaClExecutableFile, | 147 base::Bind( |
147 nacl_host_message_filter, | 148 &DoRegisterOpenedNaClExecutableFile, |
148 Passed(file.Pass()), file_path, reply_msg, | 149 nacl_host_message_filter, |
149 static_cast<WriteFileInfoReply>( | 150 Passed(file.Pass()), file_path, reply_msg, |
150 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); | 151 static_cast<WriteFileInfoReply>( |
152 NaClHostMsg_OpenNaClExecutable::WriteReplyParams))); | |
153 } else { | |
154 IPC::PlatformFileForTransit file_desc = | |
155 IPC::TakeFileHandleForProcess(file.Pass(), | |
156 nacl_host_message_filter->PeerHandle()); | |
157 uint64_t dummy_file_token = 0; | |
158 NaClHostMsg_OpenNaClExecutable::WriteReplyParams( | |
159 reply_msg, file_desc, dummy_file_token, dummy_file_token); | |
160 nacl_host_message_filter->Send(reply_msg); | |
161 } | |
151 } else { | 162 } else { |
152 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 163 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
153 return; | 164 return; |
154 } | 165 } |
155 } | 166 } |
156 | 167 |
157 } // namespace | 168 } // namespace |
158 | 169 |
159 namespace nacl_file_host { | 170 namespace nacl_file_host { |
160 | 171 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 base::FilePath full_path = pnacl_dir.AppendASCII( | 215 base::FilePath full_path = pnacl_dir.AppendASCII( |
205 std::string(kExpectedFilePrefix) + filename); | 216 std::string(kExpectedFilePrefix) + filename); |
206 *file_to_open = full_path; | 217 *file_to_open = full_path; |
207 return true; | 218 return true; |
208 } | 219 } |
209 | 220 |
210 void OpenNaClExecutable( | 221 void OpenNaClExecutable( |
211 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, | 222 scoped_refptr<nacl::NaClHostMessageFilter> nacl_host_message_filter, |
212 int render_view_id, | 223 int render_view_id, |
213 const GURL& file_url, | 224 const GURL& file_url, |
225 bool register_executable, | |
214 IPC::Message* reply_msg) { | 226 IPC::Message* reply_msg) { |
215 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 227 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
216 BrowserThread::PostTask( | 228 BrowserThread::PostTask( |
217 BrowserThread::UI, FROM_HERE, | 229 BrowserThread::UI, FROM_HERE, |
218 base::Bind( | 230 base::Bind( |
219 &OpenNaClExecutable, | 231 &OpenNaClExecutable, |
220 nacl_host_message_filter, | 232 nacl_host_message_filter, |
221 render_view_id, file_url, reply_msg)); | 233 render_view_id, |
234 file_url, | |
235 register_executable, | |
236 reply_msg)); | |
222 return; | 237 return; |
223 } | 238 } |
224 | 239 |
225 // Make sure render_view_id is valid and that the URL is a part of the | 240 // Make sure render_view_id is valid and that the URL is a part of the |
226 // render view's site. Without these checks, apps could probe the extension | 241 // render view's site. Without these checks, apps could probe the extension |
227 // directory or run NaCl code from other extensions. | 242 // directory or run NaCl code from other extensions. |
228 content::RenderViewHost* rvh = content::RenderViewHost::FromID( | 243 content::RenderViewHost* rvh = content::RenderViewHost::FromID( |
229 nacl_host_message_filter->render_process_id(), render_view_id); | 244 nacl_host_message_filter->render_process_id(), render_view_id); |
230 if (!rvh) { | 245 if (!rvh) { |
231 nacl_host_message_filter->BadMessageReceived(); // Kill the renderer. | 246 nacl_host_message_filter->BadMessageReceived(); // Kill the renderer. |
232 return; | 247 return; |
233 } | 248 } |
234 content::SiteInstance* site_instance = rvh->GetSiteInstance(); | 249 content::SiteInstance* site_instance = rvh->GetSiteInstance(); |
235 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), | 250 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), |
236 site_instance->GetSiteURL(), | 251 site_instance->GetSiteURL(), |
237 file_url)) { | 252 file_url)) { |
238 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 253 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
239 return; | 254 return; |
240 } | 255 } |
241 | 256 |
242 // The URL is part of the current app. Now query the extension system for the | 257 // The URL is part of the current app. Now query the extension system for the |
243 // file path and convert that to a file descriptor. This should be done on a | 258 // file path and convert that to a file descriptor. This should be done on a |
244 // blocking pool thread. | 259 // blocking pool thread. |
245 if (!BrowserThread::PostBlockingPoolTask( | 260 if (!BrowserThread::PostBlockingPoolTask( |
246 FROM_HERE, | 261 FROM_HERE, |
247 base::Bind( | 262 base::Bind( |
248 &DoOpenNaClExecutableOnThreadPool, | 263 &DoOpenNaClExecutableOnThreadPool, |
249 nacl_host_message_filter, | 264 nacl_host_message_filter, |
250 file_url, reply_msg))) { | 265 file_url, |
266 register_executable, | |
267 reply_msg))) { | |
251 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 268 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
252 } | 269 } |
253 } | 270 } |
254 | 271 |
255 } // namespace nacl_file_host | 272 } // namespace nacl_file_host |
OLD | NEW |