| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/pepper/pepper_file_io_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/callback_helpers.h" | |
| 12 #include "base/files/file_util_proxy.h" | 11 #include "base/files/file_util_proxy.h" |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/task_runner_util.h" |
| 14 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" | 14 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" |
| 15 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" | 15 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" |
| 16 #include "content/browser/renderer_host/pepper/pepper_security_helper.h" | 16 #include "content/browser/renderer_host/pepper/pepper_security_helper.h" |
| 17 #include "content/common/fileapi/file_system_messages.h" | 17 #include "content/common/fileapi/file_system_messages.h" |
| 18 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 24 #include "content/public/common/quarantine.h" |
| 24 #include "ipc/ipc_platform_file.h" | 25 #include "ipc/ipc_platform_file.h" |
| 25 #include "ppapi/c/pp_errors.h" | 26 #include "ppapi/c/pp_errors.h" |
| 26 #include "ppapi/c/ppb_file_io.h" | 27 #include "ppapi/c/ppb_file_io.h" |
| 27 #include "ppapi/host/dispatch_host_message.h" | 28 #include "ppapi/host/dispatch_host_message.h" |
| 28 #include "ppapi/host/ppapi_host.h" | 29 #include "ppapi/host/ppapi_host.h" |
| 29 #include "ppapi/proxy/ppapi_messages.h" | 30 #include "ppapi/proxy/ppapi_messages.h" |
| 30 #include "ppapi/shared_impl/file_system_util.h" | 31 #include "ppapi/shared_impl/file_system_util.h" |
| 31 #include "ppapi/shared_impl/file_type_conversion.h" | 32 #include "ppapi/shared_impl/file_type_conversion.h" |
| 32 #include "ppapi/shared_impl/time_conversion.h" | 33 #include "ppapi/shared_impl/time_conversion.h" |
| 33 #include "storage/browser/fileapi/file_observers.h" | 34 #include "storage/browser/fileapi/file_observers.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 reply_context, | 281 reply_context, |
| 281 base::Passed(&file))); | 282 base::Passed(&file))); |
| 282 return; | 283 return; |
| 283 } | 284 } |
| 284 } | 285 } |
| 285 | 286 |
| 286 DCHECK(!file_.IsValid()); | 287 DCHECK(!file_.IsValid()); |
| 287 base::File::Error error = | 288 base::File::Error error = |
| 288 file.IsValid() ? base::File::FILE_OK : file.error_details(); | 289 file.IsValid() ? base::File::FILE_OK : file.error_details(); |
| 289 file_.SetFile(std::move(file)); | 290 file_.SetFile(std::move(file)); |
| 290 OnOpenProxyCallback(reply_context, error); | 291 SendFileOpenReply(reply_context, error); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void PepperFileIOHost::GotResolvedRenderProcessId( | 294 void PepperFileIOHost::GotResolvedRenderProcessId( |
| 294 ppapi::host::ReplyMessageContext reply_context, | 295 ppapi::host::ReplyMessageContext reply_context, |
| 295 base::FilePath path, | 296 base::FilePath path, |
| 296 int file_flags, | 297 int file_flags, |
| 297 base::ProcessId resolved_render_process_id) { | 298 base::ProcessId resolved_render_process_id) { |
| 298 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 299 resolved_render_process_id_ = resolved_render_process_id; | 300 resolved_render_process_id_ = resolved_render_process_id; |
| 300 file_.CreateOrOpen( | 301 file_.CreateOrOpen(path, file_flags, |
| 301 path, | 302 base::Bind(&PepperFileIOHost::OnLocalFileOpened, |
| 302 file_flags, | 303 AsWeakPtr(), reply_context, path)); |
| 303 base::Bind(&PepperFileIOHost::OnOpenProxyCallback, | |
| 304 AsWeakPtr(), | |
| 305 reply_context)); | |
| 306 } | 304 } |
| 307 | 305 |
| 308 int32_t PepperFileIOHost::OnHostMsgTouch( | 306 int32_t PepperFileIOHost::OnHostMsgTouch( |
| 309 ppapi::host::HostMessageContext* context, | 307 ppapi::host::HostMessageContext* context, |
| 310 PP_Time last_access_time, | 308 PP_Time last_access_time, |
| 311 PP_Time last_modified_time) { | 309 PP_Time last_modified_time) { |
| 312 int32_t rv = state_manager_.CheckOperationState( | 310 int32_t rv = state_manager_.CheckOperationState( |
| 313 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 311 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 314 if (rv != PP_OK) | 312 if (rv != PP_OK) |
| 315 return rv; | 313 return rv; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 385 |
| 388 void PepperFileIOHost::DidOpenQuotaFile( | 386 void PepperFileIOHost::DidOpenQuotaFile( |
| 389 ppapi::host::ReplyMessageContext reply_context, | 387 ppapi::host::ReplyMessageContext reply_context, |
| 390 base::File file, | 388 base::File file, |
| 391 int64_t max_written_offset) { | 389 int64_t max_written_offset) { |
| 392 DCHECK(!file_.IsValid()); | 390 DCHECK(!file_.IsValid()); |
| 393 DCHECK(file.IsValid()); | 391 DCHECK(file.IsValid()); |
| 394 max_written_offset_ = max_written_offset; | 392 max_written_offset_ = max_written_offset; |
| 395 file_.SetFile(std::move(file)); | 393 file_.SetFile(std::move(file)); |
| 396 | 394 |
| 397 OnOpenProxyCallback(reply_context, base::File::FILE_OK); | 395 SendFileOpenReply(reply_context, base::File::FILE_OK); |
| 398 } | 396 } |
| 399 | 397 |
| 400 void PepperFileIOHost::DidCloseFile(base::File::Error /*error*/) { | 398 void PepperFileIOHost::DidCloseFile(base::File::Error /*error*/) { |
| 401 // Silently ignore if we fail to close the file. | 399 // Silently ignore if we fail to close the file. |
| 402 if (!on_close_callback_.is_null()) { | 400 if (!on_close_callback_.is_null()) { |
| 403 on_close_callback_.Run(); | 401 on_close_callback_.Run(); |
| 404 on_close_callback_.Reset(); | 402 on_close_callback_.Reset(); |
| 405 } | 403 } |
| 406 } | 404 } |
| 407 | 405 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 439 } |
| 442 | 440 |
| 443 void PepperFileIOHost::ExecutePlatformGeneralCallback( | 441 void PepperFileIOHost::ExecutePlatformGeneralCallback( |
| 444 ppapi::host::ReplyMessageContext reply_context, | 442 ppapi::host::ReplyMessageContext reply_context, |
| 445 base::File::Error error_code) { | 443 base::File::Error error_code) { |
| 446 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code)); | 444 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code)); |
| 447 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 445 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 448 state_manager_.SetOperationFinished(); | 446 state_manager_.SetOperationFinished(); |
| 449 } | 447 } |
| 450 | 448 |
| 451 void PepperFileIOHost::OnOpenProxyCallback( | 449 void PepperFileIOHost::OnLocalFileOpened( |
| 450 ppapi::host::ReplyMessageContext reply_context, |
| 451 const base::FilePath& path, |
| 452 base::File::Error error_code) { |
| 453 #if defined(OS_WIN) || defined(OS_LINUX) |
| 454 // Quarantining a file before its contents are available is only supported on |
| 455 // Windows and Linux. |
| 456 if (!FileOpenForWrite(open_flags_) || error_code != base::File::FILE_OK) { |
| 457 SendFileOpenReply(reply_context, error_code); |
| 458 return; |
| 459 } |
| 460 |
| 461 base::PostTaskAndReplyWithResult( |
| 462 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get(), |
| 463 FROM_HERE, |
| 464 base::Bind(&QuarantineFile, path, |
| 465 browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()), |
| 466 GURL(), std::string()), |
| 467 base::Bind(&PepperFileIOHost::OnLocalFileQuarantined, AsWeakPtr(), |
| 468 reply_context, path)); |
| 469 #else |
| 470 SendFileOpenReply(reply_context, error_code); |
| 471 #endif |
| 472 } |
| 473 |
| 474 #if defined(OS_WIN) || defined(OS_LINUX) |
| 475 void PepperFileIOHost::OnLocalFileQuarantined( |
| 476 ppapi::host::ReplyMessageContext reply_context, |
| 477 const base::FilePath& path, |
| 478 QuarantineFileResult quarantine_result) { |
| 479 base::File::Error file_error = (quarantine_result == QuarantineFileResult::OK |
| 480 ? base::File::FILE_OK |
| 481 : base::File::FILE_ERROR_SECURITY); |
| 482 if (file_error != base::File::FILE_OK && file_.IsValid()) |
| 483 file_.Close(base::FileProxy::StatusCallback()); |
| 484 SendFileOpenReply(reply_context, file_error); |
| 485 } |
| 486 #endif |
| 487 |
| 488 void PepperFileIOHost::SendFileOpenReply( |
| 452 ppapi::host::ReplyMessageContext reply_context, | 489 ppapi::host::ReplyMessageContext reply_context, |
| 453 base::File::Error error_code) { | 490 base::File::Error error_code) { |
| 454 int32_t pp_error = ppapi::FileErrorToPepperError(error_code); | 491 int32_t pp_error = ppapi::FileErrorToPepperError(error_code); |
| 455 if (file_.IsValid() && !AddFileToReplyContext(open_flags_, &reply_context)) | 492 if (file_.IsValid() && !AddFileToReplyContext(open_flags_, &reply_context)) |
| 456 pp_error = PP_ERROR_FAILED; | 493 pp_error = PP_ERROR_FAILED; |
| 457 | 494 |
| 458 PP_Resource quota_file_system = 0; | 495 PP_Resource quota_file_system = 0; |
| 459 if (pp_error == PP_OK) { | 496 if (pp_error == PP_OK) { |
| 460 state_manager_.SetOpenSucceed(); | 497 state_manager_.SetOpenSucceed(); |
| 461 // A non-zero resource id signals the plugin side to check quota. | 498 // A non-zero resource id signals the plugin side to check quota. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 485 | 522 |
| 486 ppapi::proxy::SerializedHandle file_handle; | 523 ppapi::proxy::SerializedHandle file_handle; |
| 487 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. | 524 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. |
| 488 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; | 525 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; |
| 489 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); | 526 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); |
| 490 reply_context->params.AppendHandle(file_handle); | 527 reply_context->params.AppendHandle(file_handle); |
| 491 return true; | 528 return true; |
| 492 } | 529 } |
| 493 | 530 |
| 494 } // namespace content | 531 } // namespace content |
| OLD | NEW |