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