| 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" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 int32_t PepperFileIOHost::OnHostMsgOpen( | 216 int32_t PepperFileIOHost::OnHostMsgOpen( |
| 217 ppapi::host::HostMessageContext* context, | 217 ppapi::host::HostMessageContext* context, |
| 218 PP_Resource file_ref_resource, | 218 PP_Resource file_ref_resource, |
| 219 int32_t open_flags) { | 219 int32_t open_flags) { |
| 220 int32_t rv = state_manager_.CheckOperationState( | 220 int32_t rv = state_manager_.CheckOperationState( |
| 221 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 221 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
| 222 if (rv != PP_OK) | 222 if (rv != PP_OK) |
| 223 return rv; | 223 return rv; |
| 224 | 224 |
| 225 // TODO(tommycli): Eventually just pass the Pepper flags straight to the | |
| 226 // FileSystemDispatcher so it can handle doing the security check. | |
| 227 int platform_file_flags = 0; | |
| 228 open_flags_ = open_flags; | 225 open_flags_ = open_flags; |
| 229 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, | 226 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, NULL)) |
| 230 &platform_file_flags)) { | |
| 231 return PP_ERROR_BADARGUMENT; | 227 return PP_ERROR_BADARGUMENT; |
| 232 } | |
| 233 | 228 |
| 234 ppapi::host::ResourceHost* resource_host = | 229 ppapi::host::ResourceHost* resource_host = |
| 235 renderer_ppapi_host_->GetPpapiHost()->GetResourceHost(file_ref_resource); | 230 renderer_ppapi_host_->GetPpapiHost()->GetResourceHost(file_ref_resource); |
| 236 if (!resource_host || !resource_host->IsFileRefHost()) | 231 if (!resource_host || !resource_host->IsFileRefHost()) |
| 237 return PP_ERROR_BADRESOURCE; | 232 return PP_ERROR_BADRESOURCE; |
| 238 PepperFileRefRendererHost* file_ref_host = | 233 PepperFileRefRendererHost* file_ref_host = |
| 239 static_cast<PepperFileRefRendererHost*>(resource_host); | 234 static_cast<PepperFileRefRendererHost*>(resource_host); |
| 240 | 235 |
| 241 file_system_type_ = file_ref_host->GetFileSystemType(); | 236 file_system_type_ = file_ref_host->GetFileSystemType(); |
| 242 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { | 237 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { |
| 243 file_system_url_ = file_ref_host->GetFileSystemURL(); | 238 file_system_url_ = file_ref_host->GetFileSystemURL(); |
| 244 FileSystemDispatcher* file_system_dispatcher = | 239 FileSystemDispatcher* file_system_dispatcher = |
| 245 ChildThread::current()->file_system_dispatcher(); | 240 ChildThread::current()->file_system_dispatcher(); |
| 246 | 241 |
| 247 AsyncOpenFileSystemURLCallback callback = base::Bind( | 242 AsyncOpenFileSystemURLCallback callback = base::Bind( |
| 248 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 243 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
| 249 weak_factory_.GetWeakPtr(), | 244 weak_factory_.GetWeakPtr(), |
| 250 context->MakeReplyMessageContext()); | 245 context->MakeReplyMessageContext()); |
| 251 file_system_dispatcher->OpenFile( | 246 file_system_dispatcher->OpenPepperFile( |
| 252 file_system_url_, platform_file_flags, | 247 file_system_url_, open_flags, |
| 253 base::Bind(&DidOpenFileSystemURL, callback), | 248 base::Bind(&DidOpenFileSystemURL, callback), |
| 254 base::Bind(&DidFailOpenFileSystemURL, callback)); | 249 base::Bind(&DidFailOpenFileSystemURL, callback)); |
| 255 } else { | 250 } else { |
| 256 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( | 251 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( |
| 257 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 252 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
| 258 weak_factory_.GetWeakPtr(), | 253 weak_factory_.GetWeakPtr(), |
| 259 context->MakeReplyMessageContext()))); | 254 context->MakeReplyMessageContext()))); |
| 260 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( | 255 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( |
| 261 routing_id_, | 256 routing_id_, |
| 262 file_ref_host->GetExternalFilePath(), | 257 file_ref_host->GetExternalFilePath(), |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // On the plugin side, the callback expects a parameter with different meaning | 555 // On the plugin side, the callback expects a parameter with different meaning |
| 561 // depends on whether is negative or not. It is the result here. We translate | 556 // depends on whether is negative or not. It is the result here. We translate |
| 562 // for the callback. | 557 // for the callback. |
| 563 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); | 558 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); |
| 564 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 559 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
| 565 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 560 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 566 state_manager_.SetOperationFinished(); | 561 state_manager_.SetOperationFinished(); |
| 567 } | 562 } |
| 568 | 563 |
| 569 } // namespace content | 564 } // namespace content |
| OLD | NEW |