Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_file_impl.cc

Issue 8764003: Implement a proxy for Pepper FileIO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_flash_file_impl.h" 5 #include "webkit/plugins/ppapi/ppb_flash_file_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "ppapi/c/pp_file_info.h" 11 #include "ppapi/c/pp_file_info.h"
12 #include "ppapi/c/ppb_file_io.h" 12 #include "ppapi/c/ppb_file_io.h"
13 #include "ppapi/c/private/ppb_flash_file.h" 13 #include "ppapi/c/private/ppb_flash_file.h"
14 #include "ppapi/shared_impl/file_type_conversion.h"
14 #include "ppapi/shared_impl/time_conversion.h" 15 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
16 #include "webkit/plugins/ppapi/common.h" 17 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/plugins/ppapi/file_path.h" 18 #include "webkit/plugins/ppapi/file_path.h"
18 #include "webkit/plugins/ppapi/file_type_conversions.h"
19 #include "webkit/plugins/ppapi/host_globals.h" 19 #include "webkit/plugins/ppapi/host_globals.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 20 #include "webkit/plugins/ppapi/plugin_delegate.h"
21 #include "webkit/plugins/ppapi/plugin_module.h" 21 #include "webkit/plugins/ppapi/plugin_module.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
23 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 23 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
24 #include "webkit/plugins/ppapi/resource_helper.h" 24 #include "webkit/plugins/ppapi/resource_helper.h"
25 25
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 #include "base/utf_string_conversions.h" 27 #include "base/utf_string_conversions.h"
28 #endif 28 #endif
(...skipping 27 matching lines...) Expand all
56 } 56 }
57 57
58 void ClearThreadAdapterForInstance(PP_Instance instance) { 58 void ClearThreadAdapterForInstance(PP_Instance instance) {
59 } 59 }
60 60
61 int32_t OpenModuleLocalFile(PP_Instance pp_instance, 61 int32_t OpenModuleLocalFile(PP_Instance pp_instance,
62 const char* path, 62 const char* path,
63 int32_t mode, 63 int32_t mode,
64 PP_FileHandle* file) { 64 PP_FileHandle* file) {
65 int flags = 0; 65 int flags = 0;
66 if (!path || !PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) 66 if (!path ||
67 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) ||
68 !file)
67 return PP_ERROR_BADARGUMENT; 69 return PP_ERROR_BADARGUMENT;
68 70
69 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 71 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
70 if (!instance) 72 if (!instance)
71 return PP_ERROR_FAILED; 73 return PP_ERROR_FAILED;
72 74
73 base::PlatformFile base_file; 75 base::PlatformFile base_file;
74 base::PlatformFileError result = instance->delegate()->OpenFile( 76 base::PlatformFileError result = instance->delegate()->OpenFile(
75 PepperFilePath::MakeModuleLocal(instance->module(), path), 77 PepperFilePath::MakeModuleLocal(instance->module(), path),
76 flags, 78 flags,
77 &base_file); 79 &base_file);
78 *file = base_file; 80 *file = base_file;
79 return PlatformFileErrorToPepperError(result); 81 return ::ppapi::PlatformFileErrorToPepperError(result);
80 } 82 }
81 83
82 int32_t RenameModuleLocalFile(PP_Instance pp_instance, 84 int32_t RenameModuleLocalFile(PP_Instance pp_instance,
83 const char* from_path, 85 const char* from_path,
84 const char* to_path) { 86 const char* to_path) {
85 if (!from_path || !to_path) 87 if (!from_path || !to_path)
86 return PP_ERROR_BADARGUMENT; 88 return PP_ERROR_BADARGUMENT;
87 89
88 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 90 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
89 if (!instance) 91 if (!instance)
90 return PP_ERROR_FAILED; 92 return PP_ERROR_FAILED;
91 93
92 base::PlatformFileError result = instance->delegate()->RenameFile( 94 base::PlatformFileError result = instance->delegate()->RenameFile(
93 PepperFilePath::MakeModuleLocal(instance->module(), from_path), 95 PepperFilePath::MakeModuleLocal(instance->module(), from_path),
94 PepperFilePath::MakeModuleLocal(instance->module(), to_path)); 96 PepperFilePath::MakeModuleLocal(instance->module(), to_path));
95 return PlatformFileErrorToPepperError(result); 97 return ::ppapi::PlatformFileErrorToPepperError(result);
96 } 98 }
97 99
98 int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, 100 int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance,
99 const char* path, 101 const char* path,
100 PP_Bool recursive) { 102 PP_Bool recursive) {
101 if (!path) 103 if (!path)
102 return PP_ERROR_BADARGUMENT; 104 return PP_ERROR_BADARGUMENT;
103 105
104 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 106 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
105 if (!instance) 107 if (!instance)
106 return PP_ERROR_FAILED; 108 return PP_ERROR_FAILED;
107 109
108 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( 110 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir(
109 PepperFilePath::MakeModuleLocal(instance->module(), path), 111 PepperFilePath::MakeModuleLocal(instance->module(), path),
110 PPBoolToBool(recursive)); 112 PPBoolToBool(recursive));
111 return PlatformFileErrorToPepperError(result); 113 return ::ppapi::PlatformFileErrorToPepperError(result);
112 } 114 }
113 115
114 int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { 116 int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) {
115 if (!path) 117 if (!path)
116 return PP_ERROR_BADARGUMENT; 118 return PP_ERROR_BADARGUMENT;
117 119
118 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 120 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
119 if (!instance) 121 if (!instance)
120 return PP_ERROR_FAILED; 122 return PP_ERROR_FAILED;
121 123
122 base::PlatformFileError result = instance->delegate()->CreateDir( 124 base::PlatformFileError result = instance->delegate()->CreateDir(
123 PepperFilePath::MakeModuleLocal(instance->module(), path)); 125 PepperFilePath::MakeModuleLocal(instance->module(), path));
124 return PlatformFileErrorToPepperError(result); 126 return ::ppapi::PlatformFileErrorToPepperError(result);
125 } 127 }
126 128
127 int32_t QueryModuleLocalFile(PP_Instance pp_instance, 129 int32_t QueryModuleLocalFile(PP_Instance pp_instance,
128 const char* path, 130 const char* path,
129 PP_FileInfo* info) { 131 PP_FileInfo* info) {
130 if (!path || !info) 132 if (!path || !info)
131 return PP_ERROR_BADARGUMENT; 133 return PP_ERROR_BADARGUMENT;
132 134
133 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 135 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
134 if (!instance) 136 if (!instance)
135 return PP_ERROR_FAILED; 137 return PP_ERROR_FAILED;
136 138
137 base::PlatformFileInfo file_info; 139 base::PlatformFileInfo file_info;
138 base::PlatformFileError result = instance->delegate()->QueryFile( 140 base::PlatformFileError result = instance->delegate()->QueryFile(
139 PepperFilePath::MakeModuleLocal(instance->module(), path), 141 PepperFilePath::MakeModuleLocal(instance->module(), path),
140 &file_info); 142 &file_info);
141 if (result == base::PLATFORM_FILE_OK) { 143 if (result == base::PLATFORM_FILE_OK) {
142 info->size = file_info.size; 144 info->size = file_info.size;
143 info->creation_time = TimeToPPTime(file_info.creation_time); 145 info->creation_time = TimeToPPTime(file_info.creation_time);
144 info->last_access_time = TimeToPPTime(file_info.last_accessed); 146 info->last_access_time = TimeToPPTime(file_info.last_accessed);
145 info->last_modified_time = TimeToPPTime(file_info.last_modified); 147 info->last_modified_time = TimeToPPTime(file_info.last_modified);
146 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; 148 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
147 if (file_info.is_directory) 149 if (file_info.is_directory)
148 info->type = PP_FILETYPE_DIRECTORY; 150 info->type = PP_FILETYPE_DIRECTORY;
149 else 151 else
150 info->type = PP_FILETYPE_REGULAR; 152 info->type = PP_FILETYPE_REGULAR;
151 } 153 }
152 return PlatformFileErrorToPepperError(result); 154 return ::ppapi::PlatformFileErrorToPepperError(result);
153 } 155 }
154 156
155 int32_t GetModuleLocalDirContents(PP_Instance pp_instance, 157 int32_t GetModuleLocalDirContents(PP_Instance pp_instance,
156 const char* path, 158 const char* path,
157 PP_DirContents_Dev** contents) { 159 PP_DirContents_Dev** contents) {
158 if (!path || !contents) 160 if (!path || !contents)
159 return PP_ERROR_BADARGUMENT; 161 return PP_ERROR_BADARGUMENT;
160 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 162 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
161 if (!instance) 163 if (!instance)
162 return PP_ERROR_FAILED; 164 return PP_ERROR_FAILED;
163 165
164 *contents = NULL; 166 *contents = NULL;
165 DirContents pepper_contents; 167 DirContents pepper_contents;
166 base::PlatformFileError result = instance->delegate()->GetDirContents( 168 base::PlatformFileError result = instance->delegate()->GetDirContents(
167 PepperFilePath::MakeModuleLocal(instance->module(), path), 169 PepperFilePath::MakeModuleLocal(instance->module(), path),
168 &pepper_contents); 170 &pepper_contents);
169 171
170 if (result != base::PLATFORM_FILE_OK) 172 if (result != base::PLATFORM_FILE_OK)
171 return PlatformFileErrorToPepperError(result); 173 return ::ppapi::PlatformFileErrorToPepperError(result);
172 174
173 *contents = new PP_DirContents_Dev; 175 *contents = new PP_DirContents_Dev;
174 size_t count = pepper_contents.size(); 176 size_t count = pepper_contents.size();
175 (*contents)->count = count; 177 (*contents)->count = count;
176 (*contents)->entries = new PP_DirEntry_Dev[count]; 178 (*contents)->entries = new PP_DirEntry_Dev[count];
177 for (size_t i = 0; i < count; ++i) { 179 for (size_t i = 0; i < count; ++i) {
178 PP_DirEntry_Dev& entry = (*contents)->entries[i]; 180 PP_DirEntry_Dev& entry = (*contents)->entries[i];
179 #if defined(OS_WIN) 181 #if defined(OS_WIN)
180 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); 182 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value());
181 #else 183 #else
(...skipping 29 matching lines...) Expand all
211 } 213 }
212 214
213 // PPB_Flash_File_FileRef_Impl ------------------------------------------------- 215 // PPB_Flash_File_FileRef_Impl -------------------------------------------------
214 216
215 namespace { 217 namespace {
216 218
217 int32_t OpenFileRefFile(PP_Resource file_ref_id, 219 int32_t OpenFileRefFile(PP_Resource file_ref_id,
218 int32_t mode, 220 int32_t mode,
219 PP_FileHandle* file) { 221 PP_FileHandle* file) {
220 int flags = 0; 222 int flags = 0;
221 if (!PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) 223 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file)
222 return PP_ERROR_BADARGUMENT; 224 return PP_ERROR_BADARGUMENT;
223 225
224 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); 226 EnterResource<PPB_FileRef_API> enter(file_ref_id, true);
225 if (enter.failed()) 227 if (enter.failed())
226 return PP_ERROR_BADRESOURCE; 228 return PP_ERROR_BADRESOURCE;
227 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); 229 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object());
228 230
229 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); 231 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref);
230 if (!instance) 232 if (!instance)
231 return PP_ERROR_FAILED; 233 return PP_ERROR_FAILED;
232 234
233 base::PlatformFile base_file; 235 base::PlatformFile base_file;
234 base::PlatformFileError result = instance->delegate()->OpenFile( 236 base::PlatformFileError result = instance->delegate()->OpenFile(
235 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), 237 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()),
236 flags, 238 flags,
237 &base_file); 239 &base_file);
238 *file = base_file; 240 *file = base_file;
239 return PlatformFileErrorToPepperError(result); 241 return ::ppapi::PlatformFileErrorToPepperError(result);
240 } 242 }
241 243
242 int32_t QueryFileRefFile(PP_Resource file_ref_id, 244 int32_t QueryFileRefFile(PP_Resource file_ref_id,
243 PP_FileInfo* info) { 245 PP_FileInfo* info) {
244 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); 246 EnterResource<PPB_FileRef_API> enter(file_ref_id, true);
245 if (enter.failed()) 247 if (enter.failed())
246 return PP_ERROR_BADRESOURCE; 248 return PP_ERROR_BADRESOURCE;
247 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); 249 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object());
248 250
249 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); 251 PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref);
250 if (!instance) 252 if (!instance)
251 return PP_ERROR_FAILED; 253 return PP_ERROR_FAILED;
252 254
253 base::PlatformFileInfo file_info; 255 base::PlatformFileInfo file_info;
254 base::PlatformFileError result = instance->delegate()->QueryFile( 256 base::PlatformFileError result = instance->delegate()->QueryFile(
255 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), 257 PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()),
256 &file_info); 258 &file_info);
257 if (result == base::PLATFORM_FILE_OK) { 259 if (result == base::PLATFORM_FILE_OK) {
258 info->size = file_info.size; 260 info->size = file_info.size;
259 info->creation_time = TimeToPPTime(file_info.creation_time); 261 info->creation_time = TimeToPPTime(file_info.creation_time);
260 info->last_access_time = TimeToPPTime(file_info.last_accessed); 262 info->last_access_time = TimeToPPTime(file_info.last_accessed);
261 info->last_modified_time = TimeToPPTime(file_info.last_modified); 263 info->last_modified_time = TimeToPPTime(file_info.last_modified);
262 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; 264 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
263 if (file_info.is_directory) 265 if (file_info.is_directory)
264 info->type = PP_FILETYPE_DIRECTORY; 266 info->type = PP_FILETYPE_DIRECTORY;
265 else 267 else
266 info->type = PP_FILETYPE_REGULAR; 268 info->type = PP_FILETYPE_REGULAR;
267 } 269 }
268 return PlatformFileErrorToPepperError(result); 270 return ::ppapi::PlatformFileErrorToPepperError(result);
269 } 271 }
270 272
271 const PPB_Flash_File_FileRef ppb_flash_file_fileref = { 273 const PPB_Flash_File_FileRef ppb_flash_file_fileref = {
272 &OpenFileRefFile, 274 &OpenFileRefFile,
273 &QueryFileRefFile, 275 &QueryFileRefFile,
274 }; 276 };
275 277
276 } // namespace 278 } // namespace
277 279
278 // static 280 // static
279 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() { 281 const PPB_Flash_File_FileRef* PPB_Flash_File_FileRef_Impl::GetInterface() {
280 return &ppb_flash_file_fileref; 282 return &ppb_flash_file_fileref;
281 } 283 }
282 284
283 } // namespace ppapi 285 } // namespace ppapi
284 } // namespace webkit 286 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/ppb_file_io_impl.h ('K') | « webkit/plugins/ppapi/ppb_file_io_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698