| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 int32_t PepperFileIOHost::OnHostMsgOpen( | 214 int32_t PepperFileIOHost::OnHostMsgOpen( |
| 215 ppapi::host::HostMessageContext* context, | 215 ppapi::host::HostMessageContext* context, |
| 216 PP_Resource file_ref_resource, | 216 PP_Resource file_ref_resource, |
| 217 int32_t open_flags) { | 217 int32_t open_flags) { |
| 218 int32_t rv = state_manager_.CheckOperationState( | 218 int32_t rv = state_manager_.CheckOperationState( |
| 219 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 219 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
| 220 if (rv != PP_OK) | 220 if (rv != PP_OK) |
| 221 return rv; | 221 return rv; |
| 222 | 222 |
| 223 // TODO(tommycli): Eventually just pass the Pepper flags straight to the | |
| 224 // FileSystemDispatcher so it can handle doing the security check. | |
| 225 int platform_file_flags = 0; | |
| 226 open_flags_ = open_flags; | 223 open_flags_ = open_flags; |
| 227 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, | 224 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, NULL)) |
| 228 &platform_file_flags)) { | |
| 229 return PP_ERROR_BADARGUMENT; | 225 return PP_ERROR_BADARGUMENT; |
| 230 } | |
| 231 | 226 |
| 232 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); | 227 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); |
| 233 if (enter.failed()) | 228 if (enter.failed()) |
| 234 return PP_ERROR_BADRESOURCE; | 229 return PP_ERROR_BADRESOURCE; |
| 235 | 230 |
| 236 PPB_FileRef_API* file_ref_api = enter.object(); | 231 PPB_FileRef_API* file_ref_api = enter.object(); |
| 237 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | 232 PP_FileSystemType type = file_ref_api->GetFileSystemType(); |
| 238 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 233 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
| 239 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | 234 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && |
| 240 type != PP_FILESYSTEMTYPE_EXTERNAL && | 235 type != PP_FILESYSTEMTYPE_EXTERNAL && |
| 241 type != PP_FILESYSTEMTYPE_ISOLATED) | 236 type != PP_FILESYSTEMTYPE_ISOLATED) |
| 242 return PP_ERROR_FAILED; | 237 return PP_ERROR_FAILED; |
| 243 file_system_type_ = type; | 238 file_system_type_ = type; |
| 244 | 239 |
| 245 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | 240 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); |
| 246 if (file_ref->HasValidFileSystem()) { | 241 if (file_ref->HasValidFileSystem()) { |
| 247 file_system_url_ = file_ref->GetFileSystemURL(); | 242 file_system_url_ = file_ref->GetFileSystemURL(); |
| 248 | 243 |
| 249 FileSystemDispatcher* file_system_dispatcher = | 244 FileSystemDispatcher* file_system_dispatcher = |
| 250 ChildThread::current()->file_system_dispatcher(); | 245 ChildThread::current()->file_system_dispatcher(); |
| 251 AsyncOpenFileSystemURLCallback callback = base::Bind( | 246 AsyncOpenFileSystemURLCallback callback = base::Bind( |
| 252 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 247 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
| 253 weak_factory_.GetWeakPtr(), | 248 weak_factory_.GetWeakPtr(), |
| 254 context->MakeReplyMessageContext()); | 249 context->MakeReplyMessageContext()); |
| 255 file_system_dispatcher->OpenFile( | 250 file_system_dispatcher->OpenPepperFile( |
| 256 file_system_url_, platform_file_flags, | 251 file_system_url_, open_flags, |
| 257 base::Bind(&DidOpenFileSystemURL, callback), | 252 base::Bind(&DidOpenFileSystemURL, callback), |
| 258 base::Bind(&DidFailOpenFileSystemURL, callback)); | 253 base::Bind(&DidFailOpenFileSystemURL, callback)); |
| 259 } else { | 254 } else { |
| 260 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | 255 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) |
| 261 return PP_ERROR_FAILED; | 256 return PP_ERROR_FAILED; |
| 262 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( | 257 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( |
| 263 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 258 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
| 264 weak_factory_.GetWeakPtr(), | 259 weak_factory_.GetWeakPtr(), |
| 265 context->MakeReplyMessageContext()))); | 260 context->MakeReplyMessageContext()))); |
| 266 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( | 261 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // On the plugin side, the callback expects a parameter with different meaning | 562 // On the plugin side, the callback expects a parameter with different meaning |
| 568 // depends on whether is negative or not. It is the result here. We translate | 563 // depends on whether is negative or not. It is the result here. We translate |
| 569 // for the callback. | 564 // for the callback. |
| 570 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); | 565 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); |
| 571 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 566 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
| 572 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 567 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 573 state_manager_.SetOperationFinished(); | 568 state_manager_.SetOperationFinished(); |
| 574 } | 569 } |
| 575 | 570 |
| 576 } // namespace content | 571 } // namespace content |
| OLD | NEW |