| 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 "chrome/browser/nacl_host/nacl_file_host.h" | 5 #include "chrome/browser/nacl_host/nacl_file_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 void DoOpenPnaclFile( | 58 void DoOpenPnaclFile( |
| 59 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 59 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 60 const std::string& filename, | 60 const std::string& filename, |
| 61 IPC::Message* reply_msg) { | 61 IPC::Message* reply_msg) { |
| 62 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 62 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 63 base::FilePath full_filepath; | 63 base::FilePath full_filepath; |
| 64 | 64 |
| 65 // Do some validation. | 65 // Do some validation. |
| 66 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { | 66 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { |
| 67 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 67 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 | 70 |
| 71 base::PlatformFile file_to_open; | 71 base::PlatformFile file_to_open; |
| 72 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) { | 72 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) { |
| 73 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 73 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Send the reply! | 77 // Send the reply! |
| 78 // Do any DuplicateHandle magic that is necessary first. | 78 // Do any DuplicateHandle magic that is necessary first. |
| 79 IPC::PlatformFileForTransit target_desc = | 79 IPC::PlatformFileForTransit target_desc = |
| 80 IPC::GetFileHandleForProcess(file_to_open, | 80 IPC::GetFileHandleForProcess(file_to_open, |
| 81 chrome_render_message_filter->peer_handle(), | 81 chrome_render_message_filter->peer_handle(), |
| 82 true /* Close source */); | 82 true /* Close source */); |
| 83 if (target_desc == IPC::InvalidPlatformFileForTransit()) { | 83 if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
| 84 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 84 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 85 return; | 85 return; |
| 86 } | 86 } |
| 87 ChromeViewHostMsg_GetReadonlyPnaclFD::WriteReplyParams( | 87 ChromeViewHostMsg_GetReadonlyPnaclFD::WriteReplyParams( |
| 88 reply_msg, target_desc); | 88 reply_msg, target_desc); |
| 89 chrome_render_message_filter->Send(reply_msg); | 89 chrome_render_message_filter->Send(reply_msg); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DoCreateTemporaryFile( | 92 void DoCreateTemporaryFile( |
| 93 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 93 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 94 IPC::Message* reply_msg) { | 94 IPC::Message* reply_msg) { |
| 95 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 95 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 96 | 96 |
| 97 base::FilePath file_path; | 97 base::FilePath file_path; |
| 98 if (!file_util::CreateTemporaryFile(&file_path)) { | 98 if (!file_util::CreateTemporaryFile(&file_path)) { |
| 99 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 99 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 | 102 |
| 103 base::PlatformFileError error; | 103 base::PlatformFileError error; |
| 104 base::PlatformFile file_handle = base::CreatePlatformFile( | 104 base::PlatformFile file_handle = base::CreatePlatformFile( |
| 105 file_path, | 105 file_path, |
| 106 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | | 106 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | |
| 107 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY | | 107 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_TEMPORARY | |
| 108 base::PLATFORM_FILE_DELETE_ON_CLOSE, | 108 base::PLATFORM_FILE_DELETE_ON_CLOSE, |
| 109 NULL, &error); | 109 NULL, &error); |
| 110 | 110 |
| 111 if (error != base::PLATFORM_FILE_OK) { | 111 if (error != base::PLATFORM_FILE_OK) { |
| 112 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 112 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Send the reply! | 116 // Send the reply! |
| 117 // Do any DuplicateHandle magic that is necessary first. | 117 // Do any DuplicateHandle magic that is necessary first. |
| 118 IPC::PlatformFileForTransit target_desc = | 118 IPC::PlatformFileForTransit target_desc = |
| 119 IPC::GetFileHandleForProcess(file_handle, | 119 IPC::GetFileHandleForProcess(file_handle, |
| 120 chrome_render_message_filter->peer_handle(), | 120 chrome_render_message_filter->peer_handle(), |
| 121 true); | 121 true); |
| 122 if (target_desc == IPC::InvalidPlatformFileForTransit()) { | 122 if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
| 123 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 123 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( | 127 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( |
| 128 reply_msg, target_desc); | 128 reply_msg, target_desc); |
| 129 chrome_render_message_filter->Send(reply_msg); | 129 chrome_render_message_filter->Send(reply_msg); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void DoRegisterOpenedNaClExecutableFile( | 132 void DoRegisterOpenedNaClExecutableFile( |
| 133 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 133 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // person before you modify it. | 207 // person before you modify it. |
| 208 void DoOpenNaClExecutableOnThreadPool( | 208 void DoOpenNaClExecutableOnThreadPool( |
| 209 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 209 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 210 scoped_refptr<ExtensionInfoMap> extension_info_map, | 210 scoped_refptr<ExtensionInfoMap> extension_info_map, |
| 211 const GURL& file_url, | 211 const GURL& file_url, |
| 212 IPC::Message* reply_msg) { | 212 IPC::Message* reply_msg) { |
| 213 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 213 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 214 | 214 |
| 215 base::FilePath file_path; | 215 base::FilePath file_path; |
| 216 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) { | 216 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) { |
| 217 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 217 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 base::PlatformFile file; | 221 base::PlatformFile file; |
| 222 nacl::OpenNaClExecutableImpl(file_path, &file); | 222 nacl::OpenNaClExecutableImpl(file_path, &file); |
| 223 if (file != base::kInvalidPlatformFileValue) { | 223 if (file != base::kInvalidPlatformFileValue) { |
| 224 // This function is running on the blocking pool, but the path needs to be | 224 // This function is running on the blocking pool, but the path needs to be |
| 225 // registered in a structure owned by the IO thread. | 225 // registered in a structure owned by the IO thread. |
| 226 BrowserThread::PostTask( | 226 BrowserThread::PostTask( |
| 227 BrowserThread::IO, FROM_HERE, | 227 BrowserThread::IO, FROM_HERE, |
| 228 base::Bind( | 228 base::Bind( |
| 229 &DoRegisterOpenedNaClExecutableFile, | 229 &DoRegisterOpenedNaClExecutableFile, |
| 230 chrome_render_message_filter, | 230 chrome_render_message_filter, |
| 231 file, file_path, reply_msg)); | 231 file, file_path, reply_msg)); |
| 232 } else { | 232 } else { |
| 233 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 233 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace | 238 } // namespace |
| 239 | 239 |
| 240 namespace nacl_file_host { | 240 namespace nacl_file_host { |
| 241 | 241 |
| 242 void GetReadonlyPnaclFd( | 242 void GetReadonlyPnaclFd( |
| 243 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 243 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 244 const std::string& filename, | 244 const std::string& filename, |
| 245 IPC::Message* reply_msg) { | 245 IPC::Message* reply_msg) { |
| 246 if (!BrowserThread::PostBlockingPoolTask( | 246 if (!BrowserThread::PostBlockingPoolTask( |
| 247 FROM_HERE, | 247 FROM_HERE, |
| 248 base::Bind(&DoOpenPnaclFile, | 248 base::Bind(&DoOpenPnaclFile, |
| 249 chrome_render_message_filter, | 249 chrome_render_message_filter, |
| 250 filename, | 250 filename, |
| 251 reply_msg))) { | 251 reply_msg))) { |
| 252 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 252 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 // This function is security sensitive. Be sure to check with a security | 256 // This function is security sensitive. Be sure to check with a security |
| 257 // person before you modify it. | 257 // person before you modify it. |
| 258 bool PnaclCanOpenFile(const std::string& filename, | 258 bool PnaclCanOpenFile(const std::string& filename, |
| 259 base::FilePath* file_to_open) { | 259 base::FilePath* file_to_open) { |
| 260 if (filename.length() > kMaxFileLength) | 260 if (filename.length() > kMaxFileLength) |
| 261 return false; | 261 return false; |
| 262 | 262 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 287 } | 287 } |
| 288 | 288 |
| 289 void CreateTemporaryFile( | 289 void CreateTemporaryFile( |
| 290 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 290 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 291 IPC::Message* reply_msg) { | 291 IPC::Message* reply_msg) { |
| 292 if (!BrowserThread::PostBlockingPoolTask( | 292 if (!BrowserThread::PostBlockingPoolTask( |
| 293 FROM_HERE, | 293 FROM_HERE, |
| 294 base::Bind(&DoCreateTemporaryFile, | 294 base::Bind(&DoCreateTemporaryFile, |
| 295 chrome_render_message_filter, | 295 chrome_render_message_filter, |
| 296 reply_msg))) { | 296 reply_msg))) { |
| 297 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 297 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 void OpenNaClExecutable( | 301 void OpenNaClExecutable( |
| 302 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 302 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 303 scoped_refptr<ExtensionInfoMap> extension_info_map, | 303 scoped_refptr<ExtensionInfoMap> extension_info_map, |
| 304 int render_view_id, | 304 int render_view_id, |
| 305 const GURL& file_url, | 305 const GURL& file_url, |
| 306 IPC::Message* reply_msg) { | 306 IPC::Message* reply_msg) { |
| 307 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 307 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 321 content::RenderViewHost* rvh = content::RenderViewHost::FromID( | 321 content::RenderViewHost* rvh = content::RenderViewHost::FromID( |
| 322 chrome_render_message_filter->render_process_id(), render_view_id); | 322 chrome_render_message_filter->render_process_id(), render_view_id); |
| 323 if (!rvh) { | 323 if (!rvh) { |
| 324 chrome_render_message_filter->BadMessageReceived(); // Kill the renderer. | 324 chrome_render_message_filter->BadMessageReceived(); // Kill the renderer. |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 content::SiteInstance* site_instance = rvh->GetSiteInstance(); | 327 content::SiteInstance* site_instance = rvh->GetSiteInstance(); |
| 328 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), | 328 if (!content::SiteInstance::IsSameWebSite(site_instance->GetBrowserContext(), |
| 329 site_instance->GetSiteURL(), | 329 site_instance->GetSiteURL(), |
| 330 file_url)) { | 330 file_url)) { |
| 331 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 331 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 332 return; | 332 return; |
| 333 } | 333 } |
| 334 | 334 |
| 335 // The URL is part of the current app. Now query the extension system for the | 335 // The URL is part of the current app. Now query the extension system for the |
| 336 // file path and convert that to a file descriptor. This should be done on a | 336 // file path and convert that to a file descriptor. This should be done on a |
| 337 // blocking pool thread. | 337 // blocking pool thread. |
| 338 if (!BrowserThread::PostBlockingPoolTask( | 338 if (!BrowserThread::PostBlockingPoolTask( |
| 339 FROM_HERE, | 339 FROM_HERE, |
| 340 base::Bind( | 340 base::Bind( |
| 341 &DoOpenNaClExecutableOnThreadPool, | 341 &DoOpenNaClExecutableOnThreadPool, |
| 342 chrome_render_message_filter, | 342 chrome_render_message_filter, |
| 343 extension_info_map, | 343 extension_info_map, |
| 344 file_url, reply_msg))) { | 344 file_url, reply_msg))) { |
| 345 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 345 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace nacl_file_host | 349 } // namespace nacl_file_host |
| OLD | NEW |