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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 int32_t PepperFileIOHost::OnHostMsgOpen( | 188 int32_t PepperFileIOHost::OnHostMsgOpen( |
189 ppapi::host::HostMessageContext* context, | 189 ppapi::host::HostMessageContext* context, |
190 PP_Resource file_ref_resource, | 190 PP_Resource file_ref_resource, |
191 int32_t open_flags) { | 191 int32_t open_flags) { |
192 int32_t rv = state_manager_.CheckOperationState( | 192 int32_t rv = state_manager_.CheckOperationState( |
193 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 193 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
194 if (rv != PP_OK) | 194 if (rv != PP_OK) |
195 return rv; | 195 return rv; |
196 | 196 |
197 int flags = 0; | 197 // TODO(tommycli): Eventually just pass the Pepper flags straight to the |
| 198 // FileSystemDispatcher so it can handle doing the security check. |
| 199 int platform_file_flags = 0; |
198 open_flags_ = open_flags; | 200 open_flags_ = open_flags; |
199 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) | 201 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, |
| 202 &platform_file_flags)) { |
200 return PP_ERROR_BADARGUMENT; | 203 return PP_ERROR_BADARGUMENT; |
| 204 } |
201 | 205 |
202 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); | 206 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); |
203 if (enter.failed()) | 207 if (enter.failed()) |
204 return PP_ERROR_BADRESOURCE; | 208 return PP_ERROR_BADRESOURCE; |
205 | 209 |
206 PPB_FileRef_API* file_ref_api = enter.object(); | 210 PPB_FileRef_API* file_ref_api = enter.object(); |
207 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | 211 PP_FileSystemType type = file_ref_api->GetFileSystemType(); |
208 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 212 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
209 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | 213 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && |
210 type != PP_FILESYSTEMTYPE_EXTERNAL && | 214 type != PP_FILESYSTEMTYPE_EXTERNAL && |
211 type != PP_FILESYSTEMTYPE_ISOLATED) | 215 type != PP_FILESYSTEMTYPE_ISOLATED) |
212 return PP_ERROR_FAILED; | 216 return PP_ERROR_FAILED; |
213 file_system_type_ = type; | 217 file_system_type_ = type; |
214 | 218 |
215 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | 219 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); |
216 if (file_ref->HasValidFileSystem()) { | 220 if (file_ref->HasValidFileSystem()) { |
217 file_system_url_ = file_ref->GetFileSystemURL(); | 221 file_system_url_ = file_ref->GetFileSystemURL(); |
218 | 222 |
219 FileSystemDispatcher* file_system_dispatcher = | 223 FileSystemDispatcher* file_system_dispatcher = |
220 ChildThread::current()->file_system_dispatcher(); | 224 ChildThread::current()->file_system_dispatcher(); |
221 AsyncOpenFileSystemURLCallback callback = base::Bind( | 225 AsyncOpenFileSystemURLCallback callback = base::Bind( |
222 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 226 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
223 weak_factory_.GetWeakPtr(), | 227 weak_factory_.GetWeakPtr(), |
224 context->MakeReplyMessageContext()); | 228 context->MakeReplyMessageContext()); |
225 file_system_dispatcher->OpenFile( | 229 file_system_dispatcher->OpenFile( |
226 file_system_url_, flags, | 230 file_system_url_, platform_file_flags, |
227 base::Bind(&DidOpenFileSystemURL, callback), | 231 base::Bind(&DidOpenFileSystemURL, callback), |
228 base::Bind(&DidFailOpenFileSystemURL, callback)); | 232 base::Bind(&DidFailOpenFileSystemURL, callback)); |
229 } else { | 233 } else { |
230 PepperHelperImpl* helper = static_cast<PepperPluginInstanceImpl*>( | 234 PepperHelperImpl* helper = static_cast<PepperPluginInstanceImpl*>( |
231 PepperPluginInstance::Get(pp_instance()))->helper(); | 235 PepperPluginInstance::Get(pp_instance()))->helper(); |
232 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL || !helper) | 236 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL || !helper) |
233 return PP_ERROR_FAILED; | 237 return PP_ERROR_FAILED; |
234 if (!helper->AsyncOpenFile( | 238 if (!helper->AsyncOpenFile( |
235 file_ref->GetSystemPath(), flags, | 239 file_ref->GetSystemPath(), open_flags, |
236 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 240 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
237 weak_factory_.GetWeakPtr(), | 241 weak_factory_.GetWeakPtr(), |
238 context->MakeReplyMessageContext()))) | 242 context->MakeReplyMessageContext()))) |
239 return PP_ERROR_FAILED; | 243 return PP_ERROR_FAILED; |
240 } | 244 } |
241 | 245 |
242 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 246 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
243 return PP_OK_COMPLETIONPENDING; | 247 return PP_OK_COMPLETIONPENDING; |
244 } | 248 } |
245 | 249 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 // On the plugin side, the callback expects a parameter with different meaning | 540 // On the plugin side, the callback expects a parameter with different meaning |
537 // depends on whether is negative or not. It is the result here. We translate | 541 // depends on whether is negative or not. It is the result here. We translate |
538 // for the callback. | 542 // for the callback. |
539 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 543 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
540 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 544 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
541 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 545 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
542 state_manager_.SetOperationFinished(); | 546 state_manager_.SetOperationFinished(); |
543 } | 547 } |
544 | 548 |
545 } // namespace content | 549 } // namespace content |
OLD | NEW |