Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/pepper/pepper_directory_reader_host.h" | |
| 6 | |
| 7 #include "content/public/renderer/renderer_ppapi_host.h" | |
| 8 #include "ppapi/c/pp_completion_callback.h" | |
| 9 #include "ppapi/c/pp_errors.h" | |
| 10 #include "ppapi/host/dispatch_host_message.h" | |
| 11 #include "ppapi/host/ppapi_host.h" | |
| 12 #include "ppapi/proxy/ppapi_messages.h" | |
| 13 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
| 14 | |
| 15 using ppapi::thunk::EnterResource; | |
| 16 using ppapi::thunk::EnterResourceCreation; | |
| 17 using ppapi::thunk::PPB_DirectoryReader_API; | |
| 18 using ppapi::thunk::PPB_FileRef_API; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 PepperDirectoryReaderHost::PepperDirectoryReaderHost( | |
| 23 RendererPpapiHost* host, | |
| 24 PP_Instance instance, | |
| 25 PP_Resource resource) | |
| 26 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 27 instance_(instance), | |
| 28 directory_reader_(0) { | |
| 29 entry_.file_ref = 0; | |
| 30 } | |
| 31 | |
| 32 PepperDirectoryReaderHost::~PepperDirectoryReaderHost() { | |
| 33 } | |
| 34 | |
| 35 int32_t PepperDirectoryReaderHost::OnResourceMessageReceived( | |
| 36 const IPC::Message& msg, | |
| 37 ppapi::host::HostMessageContext* context) { | |
| 38 IPC_BEGIN_MESSAGE_MAP(PepperDirectoryReaderHost, msg) | |
| 39 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 40 PpapiHostMsg_DirectoryReader_GetNextEntry, OnGetNextEntry) | |
| 41 IPC_END_MESSAGE_MAP() | |
| 42 return PP_ERROR_FAILED; | |
| 43 } | |
| 44 | |
| 45 // static | |
| 46 void PepperDirectoryReaderHost::OnGetNextEntryCallback( | |
| 47 void* data, | |
| 48 int32_t result) { | |
| 49 PepperDirectoryReaderHost* self = | |
| 50 static_cast<PepperDirectoryReaderHost*>(data); | |
| 51 if (result == PP_OK && self->entry_.file_ref) { | |
| 52 self->PushEntry(self->entry_); | |
| 53 self->GetNextEntryInternal(); | |
| 54 return; | |
| 55 } | |
| 56 self->SendGetNextEntryReply(result); | |
| 57 } | |
| 58 | |
| 59 int32_t PepperDirectoryReaderHost::OnGetNextEntry( | |
| 60 ppapi::host::HostMessageContext* host_context, | |
| 61 ppapi::HostResource resource) { | |
| 62 reply_context_ = host_context->MakeReplyMessageContext(); | |
| 63 host_resource_ = resource; | |
| 64 | |
| 65 ppapi::thunk::EnterResourceCreation enter(pp_instance()); | |
| 66 if (enter.failed()) | |
| 67 return PP_ERROR_FAILED; | |
| 68 | |
| 69 if (!directory_reader_) | |
| 70 directory_reader_ = | |
| 71 enter.functions()->CreateDirectoryReader(resource.host_resource()); | |
| 72 DCHECK(directory_reader_); | |
| 73 | |
| 74 return GetNextEntryInternal(); | |
| 75 } | |
| 76 | |
| 77 int32_t PepperDirectoryReaderHost::GetNextEntryInternal() { | |
| 78 EnterResource<PPB_DirectoryReader_API> enter(directory_reader_, false); | |
| 79 if (enter.failed()) | |
| 80 return PP_ERROR_FAILED; | |
| 81 | |
| 82 ppapi::ResourceTracker* tracker = | |
| 83 ppapi::PpapiGlobals::Get()->GetResourceTracker(); | |
| 84 ppapi::TrackedCallback* callback = new ppapi::TrackedCallback( | |
| 85 tracker->GetResource(directory_reader_), | |
| 86 PP_MakeCompletionCallback( | |
| 87 &PepperDirectoryReaderHost::OnGetNextEntryCallback, | |
| 88 AsWeakPtr())); | |
| 89 | |
| 90 int32_t result = enter.object()->GetNextEntry(&entry_, callback); | |
| 91 if (result == PP_OK_COMPLETIONPENDING) | |
| 92 return result; | |
| 93 | |
| 94 while (result == PP_OK && entry_.file_ref) { | |
| 95 PushEntry(entry_); | |
| 96 result = enter.object()->GetNextEntry(&entry_, callback); | |
| 97 } | |
| 98 SendGetNextEntryReply(result); | |
| 99 return result; | |
| 100 } | |
| 101 | |
| 102 void PepperDirectoryReaderHost::SendGetNextEntryReply(int32_t result) { | |
| 103 reply_context_.params.set_result(result); | |
| 104 host()->SendReply( | |
| 105 reply_context_, | |
| 106 PpapiPluginMsg_DirectoryReader_GetNextEntryReply(host_resources_, | |
|
yzshen1
2013/01/28 17:52:34
Do you need to clear this and file_types_?
nhiroki
2013/01/29 05:10:34
Done.
| |
| 107 file_types_)); | |
| 108 } | |
| 109 | |
| 110 void PepperDirectoryReaderHost::PushEntry(const PP_DirectoryEntry_Dev& entry) { | |
| 111 ppapi::PPB_FileRef_CreateInfo info; | |
| 112 ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(entry.file_ref, &info); | |
| 113 host_resources_.push_back(info); | |
| 114 file_types_.push_back(entry.file_type); | |
| 115 } | |
| 116 | |
| 117 } // namespace content | |
| OLD | NEW |