| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_directory_reader_host.h" | 5 #include "content/renderer/pepper/pepper_directory_reader_host.h" |
| 6 | 6 |
| 7 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "content/public/renderer/renderer_ppapi_host.h" | 11 #include "content/public/renderer/renderer_ppapi_host.h" |
| 12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" |
| 11 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/host/dispatch_host_message.h" | 14 #include "ppapi/host/dispatch_host_message.h" |
| 13 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
| 16 #include "ppapi/shared_impl/ppb_file_ref_shared.h" | 18 #include "ppapi/shared_impl/ppb_file_ref_shared.h" |
| 17 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
| 18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 20 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | |
| 21 #include "webkit/plugins/ppapi/resource_helper.h" | 21 #include "webkit/plugins/ppapi/resource_helper.h" |
| 22 | 22 |
| 23 using ppapi::thunk::EnterResource; | 23 using ppapi::thunk::EnterResource; |
| 24 using ppapi::thunk::PPB_FileRef_API; | 24 using ppapi::thunk::PPB_FileRef_API; |
| 25 using webkit::ppapi::PPB_FileRef_Impl; | 25 using webkit::ppapi::PPB_FileRef_Impl; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 base::FilePath::StringType UTF8StringToFilePathString(const std::string& str) { | 41 base::FilePath::StringType UTF8StringToFilePathString(const std::string& str) { |
| 42 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 43 return UTF8ToWide(str); | 43 return UTF8ToWide(str); |
| 44 #elif defined(OS_POSIX) | 44 #elif defined(OS_POSIX) |
| 45 return str; | 45 return str; |
| 46 #else | 46 #else |
| 47 #error "Unsupported platform." | 47 #error "Unsupported platform." |
| 48 #endif | 48 #endif |
| 49 } | 49 } |
| 50 | 50 |
| 51 class ReadDirectoryCallback : public fileapi::FileSystemCallbackDispatcher { | 51 class ReadDirectoryCallback : public NullFileSystemCallbackDispatcher { |
| 52 public: | 52 public: |
| 53 typedef base::Callback<void (const PepperDirectoryReaderHost::Entries&, | 53 typedef base::Callback<void (const PepperDirectoryReaderHost::Entries&, |
| 54 bool, int32_t)> | 54 bool, int32_t)> |
| 55 OnReadDirectoryCallback; | 55 OnReadDirectoryCallback; |
| 56 | 56 |
| 57 explicit ReadDirectoryCallback(const OnReadDirectoryCallback& callback) | 57 explicit ReadDirectoryCallback(const OnReadDirectoryCallback& callback) |
| 58 : callback_(callback) {} | 58 : callback_(callback) {} |
| 59 virtual ~ReadDirectoryCallback() {} | 59 virtual ~ReadDirectoryCallback() {} |
| 60 | 60 |
| 61 virtual void DidSucceed() OVERRIDE { | |
| 62 NOTREACHED(); | |
| 63 } | |
| 64 | |
| 65 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, | |
| 66 const base::FilePath& platform_path) OVERRIDE { | |
| 67 NOTREACHED(); | |
| 68 } | |
| 69 | |
| 70 virtual void DidCreateSnapshotFile( | |
| 71 const base::PlatformFileInfo& file_info, | |
| 72 const base::FilePath& platform_path) OVERRIDE { | |
| 73 NOTREACHED(); | |
| 74 } | |
| 75 | |
| 76 virtual void DidReadDirectory( | 61 virtual void DidReadDirectory( |
| 77 const std::vector<base::FileUtilProxy::Entry>& entries, | 62 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 78 bool has_more) OVERRIDE { | 63 bool has_more) OVERRIDE { |
| 79 callback_.Run(entries, has_more, PP_OK); | 64 callback_.Run(entries, has_more, PP_OK); |
| 80 } | 65 } |
| 81 | 66 |
| 82 virtual void DidOpenFileSystem(const std::string& name, | 67 virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE { |
| 83 const GURL& root) OVERRIDE { | 68 callback_.Run(PepperDirectoryReaderHost::Entries(), false, |
| 84 NOTREACHED(); | 69 ppapi::PlatformFileErrorToPepperError(platform_error)); |
| 85 } | |
| 86 | |
| 87 virtual void DidFail(base::PlatformFileError error) OVERRIDE { | |
| 88 callback_.Run(PepperDirectoryReaderHost::Entries(), | |
| 89 false, | |
| 90 ppapi::PlatformFileErrorToPepperError(error)); | |
| 91 } | |
| 92 | |
| 93 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | |
| 94 NOTREACHED(); | |
| 95 } | |
| 96 | |
| 97 virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { | |
| 98 NOTREACHED(); | |
| 99 } | 70 } |
| 100 | 71 |
| 101 private: | 72 private: |
| 102 OnReadDirectoryCallback callback_; | 73 OnReadDirectoryCallback callback_; |
| 103 }; | 74 }; |
| 104 | 75 |
| 105 } // namespace | 76 } // namespace |
| 106 | 77 |
| 107 PepperDirectoryReaderHost::PepperDirectoryReaderHost( | 78 PepperDirectoryReaderHost::PepperDirectoryReaderHost( |
| 108 RendererPpapiHost* host, | 79 RendererPpapiHost* host, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 std::string dir_path = directory_ref_->GetCreateInfo().path; | 138 std::string dir_path = directory_ref_->GetCreateInfo().path; |
| 168 if (dir_path[dir_path.size() - 1] != '/') | 139 if (dir_path[dir_path.size() - 1] != '/') |
| 169 dir_path += '/'; | 140 dir_path += '/'; |
| 170 base::FilePath::StringType dir_file_path = | 141 base::FilePath::StringType dir_file_path = |
| 171 UTF8StringToFilePathString(dir_path); | 142 UTF8StringToFilePathString(dir_path); |
| 172 | 143 |
| 173 for (Entries::const_iterator it = entries.begin(); | 144 for (Entries::const_iterator it = entries.begin(); |
| 174 it != entries.end(); ++it) { | 145 it != entries.end(); ++it) { |
| 175 EntryData data; | 146 EntryData data; |
| 176 data.file_ref = PPB_FileRef_Impl::CreateInternal( | 147 data.file_ref = PPB_FileRef_Impl::CreateInternal( |
| 177 directory_ref_->file_system()->pp_resource(), | 148 pp_instance(), |
| 149 directory_ref_->file_system_resource(), |
| 178 FilePathStringToUTF8String(dir_file_path + it->name)); | 150 FilePathStringToUTF8String(dir_file_path + it->name)); |
| 179 if (!data.file_ref) { | 151 if (!data.file_ref) { |
| 180 entry_data_.clear(); | 152 entry_data_.clear(); |
| 181 return false; | 153 return false; |
| 182 } | 154 } |
| 183 data.file_type = it->is_directory ? | 155 data.file_type = it->is_directory ? |
| 184 PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR; | 156 PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR; |
| 185 entry_data_.push_back(data); | 157 entry_data_.push_back(data); |
| 186 } | 158 } |
| 187 | 159 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 208 file_types)); | 180 file_types)); |
| 209 } | 181 } |
| 210 | 182 |
| 211 PepperDirectoryReaderHost::EntryData::EntryData() { | 183 PepperDirectoryReaderHost::EntryData::EntryData() { |
| 212 } | 184 } |
| 213 | 185 |
| 214 PepperDirectoryReaderHost::EntryData::~EntryData() { | 186 PepperDirectoryReaderHost::EntryData::~EntryData() { |
| 215 } | 187 } |
| 216 | 188 |
| 217 } // namespace content | 189 } // namespace content |
| OLD | NEW |