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 "content/renderer/pepper/pepper_file_io_host.h" | 5 #include "content/renderer/pepper/pepper_file_io_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_util_proxy.h" | 11 #include "base/files/file_util_proxy.h" |
12 #include "content/child/child_thread.h" | 12 #include "content/child/child_thread.h" |
13 #include "content/child/fileapi/file_system_dispatcher.h" | 13 #include "content/child/fileapi/file_system_dispatcher.h" |
14 #include "content/child/quota_dispatcher.h" | 14 #include "content/child/quota_dispatcher.h" |
15 #include "content/common/fileapi/file_system_messages.h" | 15 #include "content/common/fileapi/file_system_messages.h" |
16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "content/public/renderer/content_renderer_client.h" | 18 #include "content/public/renderer/content_renderer_client.h" |
19 #include "content/renderer/pepper/host_globals.h" | 19 #include "content/renderer/pepper/host_globals.h" |
20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
21 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 21 #include "content/renderer/pepper/ppb_file_ref_impl.h" |
22 #include "content/renderer/pepper/quota_file_io.h" | 22 #include "content/renderer/pepper/quota_file_io.h" |
23 #include "content/renderer/render_thread_impl.h" | 23 #include "content/renderer/render_thread_impl.h" |
24 #include "ppapi/c/pp_errors.h" | 24 #include "ppapi/c/pp_errors.h" |
| 25 #include "ppapi/c/ppb_file_io.h" |
25 #include "ppapi/host/dispatch_host_message.h" | 26 #include "ppapi/host/dispatch_host_message.h" |
26 #include "ppapi/host/ppapi_host.h" | 27 #include "ppapi/host/ppapi_host.h" |
27 #include "ppapi/proxy/ppapi_messages.h" | 28 #include "ppapi/proxy/ppapi_messages.h" |
28 #include "ppapi/shared_impl/file_type_conversion.h" | 29 #include "ppapi/shared_impl/file_type_conversion.h" |
29 #include "ppapi/shared_impl/time_conversion.h" | 30 #include "ppapi/shared_impl/time_conversion.h" |
30 #include "ppapi/thunk/enter.h" | 31 #include "ppapi/thunk/enter.h" |
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 quota::kQuotaLimitTypeUnknown, | 136 quota::kQuotaLimitTypeUnknown, |
136 PepperFileIOHost::NotifyCloseFileCallback()); | 137 PepperFileIOHost::NotifyCloseFileCallback()); |
137 } | 138 } |
138 | 139 |
139 } // namespace | 140 } // namespace |
140 | 141 |
141 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | 142 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, |
142 PP_Instance instance, | 143 PP_Instance instance, |
143 PP_Resource resource) | 144 PP_Resource resource) |
144 : ResourceHost(host->GetPpapiHost(), instance, resource), | 145 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 146 renderer_ppapi_host_(host), |
145 file_(base::kInvalidPlatformFileValue), | 147 file_(base::kInvalidPlatformFileValue), |
146 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | 148 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
147 quota_policy_(quota::kQuotaLimitTypeUnknown), | 149 quota_policy_(quota::kQuotaLimitTypeUnknown), |
148 is_running_in_process_(host->IsRunningInProcess()), | 150 is_running_in_process_(host->IsRunningInProcess()), |
149 open_flags_(0), | 151 open_flags_(0), |
150 weak_factory_(this), | 152 weak_factory_(this), |
151 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { | 153 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { |
152 ChildThread::current()->AddRoute(routing_id_, this); | 154 ChildThread::current()->AddRoute(routing_id_, this); |
153 } | 155 } |
154 | 156 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 515 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
514 return PP_OK_COMPLETIONPENDING; | 516 return PP_OK_COMPLETIONPENDING; |
515 } | 517 } |
516 | 518 |
517 int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle( | 519 int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle( |
518 ppapi::host::HostMessageContext* context) { | 520 ppapi::host::HostMessageContext* context) { |
519 if (!is_running_in_process_ && | 521 if (!is_running_in_process_ && |
520 quota_policy_ != quota::kQuotaLimitTypeUnlimited) | 522 quota_policy_ != quota::kQuotaLimitTypeUnlimited) |
521 return PP_ERROR_FAILED; | 523 return PP_ERROR_FAILED; |
522 | 524 |
523 RendererPpapiHost* renderer_ppapi_host = | |
524 RendererPpapiHost::GetForPPInstance(pp_instance()); | |
525 | |
526 // Whitelist to make it privately accessible. | 525 // Whitelist to make it privately accessible. |
527 if (!GetContentClient()->renderer()->IsPluginAllowedToCallRequestOSFileHandle( | 526 if (!GetContentClient()->renderer()->IsPluginAllowedToCallRequestOSFileHandle( |
528 renderer_ppapi_host->GetContainerForInstance(pp_instance()))) | 527 renderer_ppapi_host_->GetContainerForInstance(pp_instance()))) |
529 return PP_ERROR_NOACCESS; | 528 return PP_ERROR_NOACCESS; |
530 | 529 |
531 IPC::PlatformFileForTransit file = | 530 IPC::PlatformFileForTransit file = |
532 renderer_ppapi_host->ShareHandleWithRemote(file_, false); | 531 renderer_ppapi_host_->ShareHandleWithRemote(file_, false); |
533 if (file == IPC::InvalidPlatformFileForTransit()) | 532 if (file == IPC::InvalidPlatformFileForTransit()) |
534 return PP_ERROR_FAILED; | 533 return PP_ERROR_FAILED; |
535 ppapi::host::ReplyMessageContext reply_context = | 534 ppapi::host::ReplyMessageContext reply_context = |
536 context->MakeReplyMessageContext(); | 535 context->MakeReplyMessageContext(); |
537 ppapi::proxy::SerializedHandle file_handle; | 536 ppapi::proxy::SerializedHandle file_handle; |
538 file_handle.set_file_handle(file, open_flags_); | 537 file_handle.set_file_handle(file, open_flags_); |
539 reply_context.params.AppendHandle(file_handle); | 538 reply_context.params.AppendHandle(file_handle); |
540 host()->SendReply(reply_context, | 539 host()->SendReply(reply_context, |
541 PpapiPluginMsg_FileIO_RequestOSFileHandleReply()); | 540 PpapiPluginMsg_FileIO_RequestOSFileHandleReply()); |
542 return PP_OK_COMPLETIONPENDING; | 541 return PP_OK_COMPLETIONPENDING; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 base::PlatformFileError error_code, | 574 base::PlatformFileError error_code, |
576 base::PassPlatformFile file) { | 575 base::PassPlatformFile file) { |
577 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 576 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
578 if (pp_error == PP_OK) | 577 if (pp_error == PP_OK) |
579 state_manager_.SetOpenSucceed(); | 578 state_manager_.SetOpenSucceed(); |
580 | 579 |
581 DCHECK(file_ == base::kInvalidPlatformFileValue); | 580 DCHECK(file_ == base::kInvalidPlatformFileValue); |
582 file_ = file.ReleaseValue(); | 581 file_ = file.ReleaseValue(); |
583 | 582 |
584 DCHECK(!quota_file_io_.get()); | 583 DCHECK(!quota_file_io_.get()); |
585 if (file_ != base::kInvalidPlatformFileValue && | 584 if (file_ != base::kInvalidPlatformFileValue) { |
586 (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY || | 585 if (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY || |
587 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) { | 586 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT) { |
588 quota_file_io_.reset(new QuotaFileIO( | 587 quota_file_io_.reset(new QuotaFileIO( |
589 new QuotaFileIODelegate, file_, file_system_url_, file_system_type_)); | 588 new QuotaFileIODelegate, file_, file_system_url_, file_system_type_)); |
| 589 } |
| 590 |
| 591 IPC::PlatformFileForTransit file_for_transit = |
| 592 renderer_ppapi_host_->ShareHandleWithRemote(file_, false); |
| 593 if (!(file_for_transit == IPC::InvalidPlatformFileForTransit())) { |
| 594 // Send the file descriptor to the plugin process. This is used in the |
| 595 // plugin for any file operations that can be done there. |
| 596 // IMPORTANT: Clear PP_FILEOPENFLAG_WRITE and PP_FILEOPENFLAG_APPEND so |
| 597 // the plugin can't write and so bypass our quota checks. |
| 598 int32_t no_write_flags = |
| 599 open_flags_ & ~(PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND); |
| 600 ppapi::proxy::SerializedHandle file_handle; |
| 601 file_handle.set_file_handle(file_for_transit, no_write_flags); |
| 602 reply_context.params.AppendHandle(file_handle); |
| 603 } |
590 } | 604 } |
591 | 605 |
592 reply_context.params.set_result(pp_error); | 606 reply_context.params.set_result(pp_error); |
593 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply()); | 607 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenReply()); |
594 state_manager_.SetOperationFinished(); | 608 state_manager_.SetOperationFinished(); |
595 } | 609 } |
596 | 610 |
597 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( | 611 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( |
598 ppapi::host::ReplyMessageContext reply_context, | 612 ppapi::host::ReplyMessageContext reply_context, |
599 base::PlatformFileError error_code, | 613 base::PlatformFileError error_code, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 // On the plugin side, the callback expects a parameter with different meaning | 657 // On the plugin side, the callback expects a parameter with different meaning |
644 // depends on whether is negative or not. It is the result here. We translate | 658 // depends on whether is negative or not. It is the result here. We translate |
645 // for the callback. | 659 // for the callback. |
646 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 660 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
647 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 661 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
648 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 662 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
649 state_manager_.SetOperationFinished(); | 663 state_manager_.SetOperationFinished(); |
650 } | 664 } |
651 | 665 |
652 } // namespace content | 666 } // namespace content |
OLD | NEW |