| 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/download/quarantine.h" |
| 14 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" | 15 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" |
| 15 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" | 16 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" |
| 16 #include "content/browser/renderer_host/pepper/pepper_security_helper.h" | 17 #include "content/browser/renderer_host/pepper/pepper_security_helper.h" |
| 17 #include "content/common/fileapi/file_system_messages.h" | 18 #include "content/common/fileapi/file_system_messages.h" |
| 18 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 reply_context, | 282 reply_context, |
| 282 base::Passed(&file))); | 283 base::Passed(&file))); |
| 283 return; | 284 return; |
| 284 } | 285 } |
| 285 } | 286 } |
| 286 | 287 |
| 287 DCHECK(!file_.IsValid()); | 288 DCHECK(!file_.IsValid()); |
| 288 base::File::Error error = | 289 base::File::Error error = |
| 289 file.IsValid() ? base::File::FILE_OK : file.error_details(); | 290 file.IsValid() ? base::File::FILE_OK : file.error_details(); |
| 290 file_.SetFile(std::move(file)); | 291 file_.SetFile(std::move(file)); |
| 291 OnOpenProxyCallback(reply_context, error); | 292 SendFileOpenReply(reply_context, error); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void PepperFileIOHost::GotResolvedRenderProcessId( | 295 void PepperFileIOHost::GotResolvedRenderProcessId( |
| 295 ppapi::host::ReplyMessageContext reply_context, | 296 ppapi::host::ReplyMessageContext reply_context, |
| 296 base::FilePath path, | 297 base::FilePath path, |
| 297 int file_flags, | 298 int file_flags, |
| 298 base::ProcessId resolved_render_process_id) { | 299 base::ProcessId resolved_render_process_id) { |
| 299 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 300 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 300 resolved_render_process_id_ = resolved_render_process_id; | 301 resolved_render_process_id_ = resolved_render_process_id; |
| 301 file_.CreateOrOpen( | 302 file_.CreateOrOpen(path, file_flags, |
| 302 path, | 303 base::Bind(&PepperFileIOHost::OnLocalFileOpened, |
| 303 file_flags, | 304 AsWeakPtr(), reply_context, path)); |
| 304 base::Bind(&PepperFileIOHost::OnOpenProxyCallback, | |
| 305 AsWeakPtr(), | |
| 306 reply_context)); | |
| 307 } | 305 } |
| 308 | 306 |
| 309 int32_t PepperFileIOHost::OnHostMsgTouch( | 307 int32_t PepperFileIOHost::OnHostMsgTouch( |
| 310 ppapi::host::HostMessageContext* context, | 308 ppapi::host::HostMessageContext* context, |
| 311 PP_Time last_access_time, | 309 PP_Time last_access_time, |
| 312 PP_Time last_modified_time) { | 310 PP_Time last_modified_time) { |
| 313 int32_t rv = state_manager_.CheckOperationState( | 311 int32_t rv = state_manager_.CheckOperationState( |
| 314 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 312 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 315 if (rv != PP_OK) | 313 if (rv != PP_OK) |
| 316 return rv; | 314 return rv; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 386 |
| 389 void PepperFileIOHost::DidOpenQuotaFile( | 387 void PepperFileIOHost::DidOpenQuotaFile( |
| 390 ppapi::host::ReplyMessageContext reply_context, | 388 ppapi::host::ReplyMessageContext reply_context, |
| 391 base::File file, | 389 base::File file, |
| 392 int64_t max_written_offset) { | 390 int64_t max_written_offset) { |
| 393 DCHECK(!file_.IsValid()); | 391 DCHECK(!file_.IsValid()); |
| 394 DCHECK(file.IsValid()); | 392 DCHECK(file.IsValid()); |
| 395 max_written_offset_ = max_written_offset; | 393 max_written_offset_ = max_written_offset; |
| 396 file_.SetFile(std::move(file)); | 394 file_.SetFile(std::move(file)); |
| 397 | 395 |
| 398 OnOpenProxyCallback(reply_context, base::File::FILE_OK); | 396 SendFileOpenReply(reply_context, base::File::FILE_OK); |
| 399 } | 397 } |
| 400 | 398 |
| 401 void PepperFileIOHost::DidCloseFile(base::File::Error /*error*/) { | 399 void PepperFileIOHost::DidCloseFile(base::File::Error /*error*/) { |
| 402 // Silently ignore if we fail to close the file. | 400 // Silently ignore if we fail to close the file. |
| 403 if (!on_close_callback_.is_null()) { | 401 if (!on_close_callback_.is_null()) { |
| 404 on_close_callback_.Run(); | 402 on_close_callback_.Run(); |
| 405 on_close_callback_.Reset(); | 403 on_close_callback_.Reset(); |
| 406 } | 404 } |
| 407 } | 405 } |
| 408 | 406 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 440 } |
| 443 | 441 |
| 444 void PepperFileIOHost::ExecutePlatformGeneralCallback( | 442 void PepperFileIOHost::ExecutePlatformGeneralCallback( |
| 445 ppapi::host::ReplyMessageContext reply_context, | 443 ppapi::host::ReplyMessageContext reply_context, |
| 446 base::File::Error error_code) { | 444 base::File::Error error_code) { |
| 447 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code)); | 445 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code)); |
| 448 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 446 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 449 state_manager_.SetOperationFinished(); | 447 state_manager_.SetOperationFinished(); |
| 450 } | 448 } |
| 451 | 449 |
| 452 void PepperFileIOHost::OnOpenProxyCallback( | 450 void PepperFileIOHost::OnLocalFileOpened( |
| 451 ppapi::host::ReplyMessageContext reply_context, |
| 452 const base::FilePath& path, |
| 453 base::File::Error error_code) { |
| 454 if (!FileOpenForWrite(open_flags_) || error_code != base::File::FILE_OK) { |
| 455 SendFileOpenReply(reply_context, error_code); |
| 456 return; |
| 457 } |
| 458 |
| 459 base::PostTaskAndReplyWithResult( |
| 460 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), |
| 461 FROM_HERE, |
| 462 base::Bind(&QuarantineFile, path, |
| 463 browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()), |
| 464 GURL(), std::string()), |
| 465 base::Bind(&PepperFileIOHost::OnLocalFileQuarantined, AsWeakPtr(), |
| 466 reply_context, path)); |
| 467 } |
| 468 |
| 469 void PepperFileIOHost::OnLocalFileQuarantined( |
| 470 ppapi::host::ReplyMessageContext reply_context, |
| 471 const base::FilePath& path, |
| 472 QuarantineFileResult quarantine_result) { |
| 473 base::File::Error file_error = |
| 474 (quarantine_result == QuarantineFileResult::OK |
| 475 ? base::File::FILE_OK |
| 476 : base::File::FILE_ERROR_SECURITY); |
| 477 if (file_error != base::File::FILE_OK && file_.IsValid()) |
| 478 file_.Close(base::FileProxy::StatusCallback()); |
| 479 SendFileOpenReply(reply_context, file_error); |
| 480 } |
| 481 |
| 482 void PepperFileIOHost::SendFileOpenReply( |
| 453 ppapi::host::ReplyMessageContext reply_context, | 483 ppapi::host::ReplyMessageContext reply_context, |
| 454 base::File::Error error_code) { | 484 base::File::Error error_code) { |
| 455 int32_t pp_error = ppapi::FileErrorToPepperError(error_code); | 485 int32_t pp_error = ppapi::FileErrorToPepperError(error_code); |
| 456 if (file_.IsValid() && !AddFileToReplyContext(open_flags_, &reply_context)) | 486 if (file_.IsValid() && !AddFileToReplyContext(open_flags_, &reply_context)) |
| 457 pp_error = PP_ERROR_FAILED; | 487 pp_error = PP_ERROR_FAILED; |
| 458 | 488 |
| 459 PP_Resource quota_file_system = 0; | 489 PP_Resource quota_file_system = 0; |
| 460 if (pp_error == PP_OK) { | 490 if (pp_error == PP_OK) { |
| 461 state_manager_.SetOpenSucceed(); | 491 state_manager_.SetOpenSucceed(); |
| 462 // A non-zero resource id signals the plugin side to check quota. | 492 // A non-zero resource id signals the plugin side to check quota. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 486 | 516 |
| 487 ppapi::proxy::SerializedHandle file_handle; | 517 ppapi::proxy::SerializedHandle file_handle; |
| 488 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. | 518 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. |
| 489 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; | 519 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; |
| 490 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); | 520 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); |
| 491 reply_context->params.AppendHandle(file_handle); | 521 reply_context->params.AppendHandle(file_handle); |
| 492 return true; | 522 return true; |
| 493 } | 523 } |
| 494 | 524 |
| 495 } // namespace content | 525 } // namespace content |
| OLD | NEW |