| 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/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 17 #include "content/public/renderer/content_renderer_client.h" | 18 #include "content/public/renderer/content_renderer_client.h" |
| 18 #include "content/renderer/pepper/host_globals.h" | 19 #include "content/renderer/pepper/host_globals.h" |
| 19 #include "content/renderer/pepper/pepper_helper_impl.h" | 20 #include "content/renderer/pepper/pepper_helper_impl.h" |
| 20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 21 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 21 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 22 #include "content/renderer/pepper/ppb_file_ref_impl.h" |
| 22 #include "content/renderer/pepper/quota_file_io.h" | 23 #include "content/renderer/pepper/quota_file_io.h" |
| 23 #include "content/renderer/pepper/resource_helper.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/host/dispatch_host_message.h" | 26 #include "ppapi/host/dispatch_host_message.h" |
| 27 #include "ppapi/host/ppapi_host.h" | 27 #include "ppapi/host/ppapi_host.h" |
| 28 #include "ppapi/proxy/ppapi_messages.h" | 28 #include "ppapi/proxy/ppapi_messages.h" |
| 29 #include "ppapi/shared_impl/file_type_conversion.h" | 29 #include "ppapi/shared_impl/file_type_conversion.h" |
| 30 #include "ppapi/shared_impl/time_conversion.h" | 30 #include "ppapi/shared_impl/time_conversion.h" |
| 31 #include "ppapi/thunk/enter.h" | 31 #include "ppapi/thunk/enter.h" |
| 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 33 | 33 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | 142 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, |
| 143 PP_Instance instance, | 143 PP_Instance instance, |
| 144 PP_Resource resource) | 144 PP_Resource resource) |
| 145 : ResourceHost(host->GetPpapiHost(), instance, resource), | 145 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 146 file_(base::kInvalidPlatformFileValue), | 146 file_(base::kInvalidPlatformFileValue), |
| 147 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | 147 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| 148 quota_policy_(quota::kQuotaLimitTypeUnknown), | 148 quota_policy_(quota::kQuotaLimitTypeUnknown), |
| 149 is_running_in_process_(host->IsRunningInProcess()), | 149 is_running_in_process_(host->IsRunningInProcess()), |
| 150 open_flags_(0), | 150 open_flags_(0), |
| 151 weak_factory_(this) { | 151 weak_factory_(this), |
| 152 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { |
| 153 ChildThread::current()->AddRoute(routing_id_, this); |
| 152 } | 154 } |
| 153 | 155 |
| 154 PepperFileIOHost::~PepperFileIOHost() { | 156 PepperFileIOHost::~PepperFileIOHost() { |
| 155 OnHostMsgClose(NULL); | 157 OnHostMsgClose(NULL); |
| 158 ChildThread::current()->RemoveRoute(routing_id_); |
| 156 } | 159 } |
| 157 | 160 |
| 158 int32_t PepperFileIOHost::OnResourceMessageReceived( | 161 int32_t PepperFileIOHost::OnResourceMessageReceived( |
| 159 const IPC::Message& msg, | 162 const IPC::Message& msg, |
| 160 ppapi::host::HostMessageContext* context) { | 163 ppapi::host::HostMessageContext* context) { |
| 161 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) | 164 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) |
| 162 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, | 165 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, |
| 163 OnHostMsgOpen) | 166 OnHostMsgOpen) |
| 164 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Query, | 167 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Query, |
| 165 OnHostMsgQuery) | 168 OnHostMsgQuery) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 180 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillSetLength, | 183 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillSetLength, |
| 181 OnHostMsgWillSetLength) | 184 OnHostMsgWillSetLength) |
| 182 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_GetOSFileDescriptor, | 185 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_GetOSFileDescriptor, |
| 183 OnHostMsgGetOSFileDescriptor) | 186 OnHostMsgGetOSFileDescriptor) |
| 184 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_RequestOSFileHandle, | 187 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_RequestOSFileHandle, |
| 185 OnHostMsgRequestOSFileHandle) | 188 OnHostMsgRequestOSFileHandle) |
| 186 IPC_END_MESSAGE_MAP() | 189 IPC_END_MESSAGE_MAP() |
| 187 return PP_ERROR_FAILED; | 190 return PP_ERROR_FAILED; |
| 188 } | 191 } |
| 189 | 192 |
| 193 bool PepperFileIOHost::OnMessageReceived(const IPC::Message& msg) { |
| 194 bool handled = true; |
| 195 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) |
| 196 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenPepperFile_ACK, OnAsyncFileOpened) |
| 197 IPC_MESSAGE_UNHANDLED(handled = false) |
| 198 IPC_END_MESSAGE_MAP() |
| 199 return handled; |
| 200 } |
| 201 |
| 202 void PepperFileIOHost::OnAsyncFileOpened( |
| 203 base::PlatformFileError error_code, |
| 204 IPC::PlatformFileForTransit file_for_transit, |
| 205 int message_id) { |
| 206 AsyncOpenFileCallback* callback = |
| 207 pending_async_open_files_.Lookup(message_id); |
| 208 DCHECK(callback); |
| 209 pending_async_open_files_.Remove(message_id); |
| 210 |
| 211 base::PlatformFile file = |
| 212 IPC::PlatformFileForTransitToPlatformFile(file_for_transit); |
| 213 callback->Run(error_code, base::PassPlatformFile(&file)); |
| 214 // Make sure we won't leak file handle if the requester has died. |
| 215 if (file != base::kInvalidPlatformFileValue) { |
| 216 base::FileUtilProxy::Close( |
| 217 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 218 file, |
| 219 base::FileUtilProxy::StatusCallback()); |
| 220 } |
| 221 delete callback; |
| 222 } |
| 223 |
| 190 int32_t PepperFileIOHost::OnHostMsgOpen( | 224 int32_t PepperFileIOHost::OnHostMsgOpen( |
| 191 ppapi::host::HostMessageContext* context, | 225 ppapi::host::HostMessageContext* context, |
| 192 PP_Resource file_ref_resource, | 226 PP_Resource file_ref_resource, |
| 193 int32_t open_flags) { | 227 int32_t open_flags) { |
| 194 int32_t rv = state_manager_.CheckOperationState( | 228 int32_t rv = state_manager_.CheckOperationState( |
| 195 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 229 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
| 196 if (rv != PP_OK) | 230 if (rv != PP_OK) |
| 197 return rv; | 231 return rv; |
| 198 | 232 |
| 199 // TODO(tommycli): Eventually just pass the Pepper flags straight to the | 233 // TODO(tommycli): Eventually just pass the Pepper flags straight to the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 222 if (file_ref->HasValidFileSystem()) { | 256 if (file_ref->HasValidFileSystem()) { |
| 223 file_system_url_ = file_ref->GetFileSystemURL(); | 257 file_system_url_ = file_ref->GetFileSystemURL(); |
| 224 | 258 |
| 225 FileSystemDispatcher* file_system_dispatcher = | 259 FileSystemDispatcher* file_system_dispatcher = |
| 226 ChildThread::current()->file_system_dispatcher(); | 260 ChildThread::current()->file_system_dispatcher(); |
| 227 AsyncOpenFileSystemURLCallback callback = base::Bind( | 261 AsyncOpenFileSystemURLCallback callback = base::Bind( |
| 228 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 262 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
| 229 weak_factory_.GetWeakPtr(), | 263 weak_factory_.GetWeakPtr(), |
| 230 context->MakeReplyMessageContext()); | 264 context->MakeReplyMessageContext()); |
| 231 file_system_dispatcher->OpenFile( | 265 file_system_dispatcher->OpenFile( |
| 232 file_system_url_, platform_file_flags, | 266 file_system_url_, platform_file_flags, |
| 233 base::Bind(&DidOpenFileSystemURL, callback), | 267 base::Bind(&DidOpenFileSystemURL, callback), |
| 234 base::Bind(&DidFailOpenFileSystemURL, callback)); | 268 base::Bind(&DidFailOpenFileSystemURL, callback)); |
| 235 } else { | 269 } else { |
| 236 PepperHelperImpl* helper = static_cast<PepperPluginInstanceImpl*>( | 270 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) |
| 237 PepperPluginInstance::Get(pp_instance()))->helper(); | |
| 238 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL || !helper) | |
| 239 return PP_ERROR_FAILED; | 271 return PP_ERROR_FAILED; |
| 240 if (!helper->AsyncOpenFile( | 272 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( |
| 241 file_ref->GetSystemPath(), open_flags, | 273 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
| 242 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 274 weak_factory_.GetWeakPtr(), |
| 243 weak_factory_.GetWeakPtr(), | 275 context->MakeReplyMessageContext()))); |
| 244 context->MakeReplyMessageContext()))) | 276 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( |
| 245 return PP_ERROR_FAILED; | 277 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); |
| 246 } | 278 } |
| 247 | 279 |
| 248 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 280 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 249 return PP_OK_COMPLETIONPENDING; | 281 return PP_OK_COMPLETIONPENDING; |
| 250 } | 282 } |
| 251 | 283 |
| 252 int32_t PepperFileIOHost::OnHostMsgQuery( | 284 int32_t PepperFileIOHost::OnHostMsgQuery( |
| 253 ppapi::host::HostMessageContext* context) { | 285 ppapi::host::HostMessageContext* context) { |
| 254 int32_t rv = state_manager_.CheckOperationState( | 286 int32_t rv = state_manager_.CheckOperationState( |
| 255 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 287 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 // On the plugin side, the callback expects a parameter with different meaning | 644 // On the plugin side, the callback expects a parameter with different meaning |
| 613 // depends on whether is negative or not. It is the result here. We translate | 645 // depends on whether is negative or not. It is the result here. We translate |
| 614 // for the callback. | 646 // for the callback. |
| 615 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 647 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
| 616 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 648 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
| 617 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 649 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 618 state_manager_.SetOperationFinished(); | 650 state_manager_.SetOperationFinished(); |
| 619 } | 651 } |
| 620 | 652 |
| 621 } // namespace content | 653 } // namespace content |
| OLD | NEW |