OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_file_ref.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "webkit/glue/plugins/pepper_common.h" | 10 #include "webkit/plugins/ppapi/common.h" |
11 #include "webkit/glue/plugins/pepper_directory_reader.h" | 11 #include "webkit/plugins/ppapi/file_callbacks.h" |
12 #include "webkit/glue/plugins/pepper_file_callbacks.h" | 12 #include "webkit/plugins/ppapi/plugin_delegate.h" |
13 #include "webkit/glue/plugins/pepper_file_system.h" | 13 #include "webkit/plugins/ppapi/plugin_instance.h" |
14 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 14 #include "webkit/plugins/ppapi/plugin_module.h" |
15 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
16 #include "webkit/glue/plugins/pepper_plugin_module.h" | 16 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
17 #include "webkit/glue/plugins/pepper_var.h" | 17 #include "webkit/plugins/ppapi/var.h" |
18 | 18 |
19 namespace pepper { | 19 namespace webkit { |
| 20 namespace plugins { |
| 21 namespace ppapi { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 bool IsValidLocalPath(const std::string& path) { | 25 bool IsValidLocalPath(const std::string& path) { |
24 // The path must start with '/' | 26 // The path must start with '/' |
25 if (path.empty() || path[0] != '/') | 27 if (path.empty() || path[0] != '/') |
26 return false; | 28 return false; |
27 | 29 |
28 // The path must contain valid UTF-8 characters. | 30 // The path must contain valid UTF-8 characters. |
29 if (!IsStringUTF8(path)) | 31 if (!IsStringUTF8(path)) |
30 return false; | 32 return false; |
31 | 33 |
32 return true; | 34 return true; |
33 } | 35 } |
34 | 36 |
35 void TrimTrailingSlash(std::string* path) { | 37 void TrimTrailingSlash(std::string* path) { |
36 // If this path ends with a slash, then normalize it away unless path is the | 38 // If this path ends with a slash, then normalize it away unless path is the |
37 // root path. | 39 // root path. |
38 if (path->size() > 1 && path->at(path->size() - 1) == '/') | 40 if (path->size() > 1 && path->at(path->size() - 1) == '/') |
39 path->erase(path->size() - 1, 1); | 41 path->erase(path->size() - 1, 1); |
40 } | 42 } |
41 | 43 |
42 PP_Resource Create(PP_Resource file_system_id, const char* path) { | 44 PP_Resource Create(PP_Resource file_system_id, const char* path) { |
43 scoped_refptr<FileSystem> file_system( | 45 scoped_refptr<PPB_FileSystem_Impl> file_system( |
44 Resource::GetAs<FileSystem>(file_system_id)); | 46 Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); |
45 if (!file_system) | 47 if (!file_system) |
46 return 0; | 48 return 0; |
47 | 49 |
48 if (!file_system->instance()) | 50 if (!file_system->instance()) |
49 return 0; | 51 return 0; |
50 | 52 |
51 std::string validated_path(path); | 53 std::string validated_path(path); |
52 if (!IsValidLocalPath(validated_path)) | 54 if (!IsValidLocalPath(validated_path)) |
53 return 0; | 55 return 0; |
54 TrimTrailingSlash(&validated_path); | 56 TrimTrailingSlash(&validated_path); |
55 | 57 |
56 FileRef* file_ref = new FileRef(file_system->instance()->module(), | 58 PPB_FileRef_Impl* file_ref = |
57 file_system, | 59 new PPB_FileRef_Impl(file_system->instance()->module(), |
58 validated_path); | 60 file_system, validated_path); |
59 return file_ref->GetReference(); | 61 return file_ref->GetReference(); |
60 } | 62 } |
61 | 63 |
62 PP_Bool IsFileRef(PP_Resource resource) { | 64 PP_Bool IsFileRef(PP_Resource resource) { |
63 return BoolToPPBool(!!Resource::GetAs<FileRef>(resource)); | 65 return BoolToPPBool(!!Resource::GetAs<PPB_FileRef_Impl>(resource)); |
64 } | 66 } |
65 | 67 |
66 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { | 68 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { |
67 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 69 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 70 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
68 if (!file_ref) | 71 if (!file_ref) |
69 return PP_FILESYSTEMTYPE_EXTERNAL; | 72 return PP_FILESYSTEMTYPE_EXTERNAL; |
70 return file_ref->GetFileSystemType(); | 73 return file_ref->GetFileSystemType(); |
71 } | 74 } |
72 | 75 |
73 PP_Var GetName(PP_Resource file_ref_id) { | 76 PP_Var GetName(PP_Resource file_ref_id) { |
74 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 77 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 78 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
75 if (!file_ref) | 79 if (!file_ref) |
76 return PP_MakeUndefined(); | 80 return PP_MakeUndefined(); |
77 return StringVar::StringToPPVar(file_ref->module(), file_ref->GetName()); | 81 return StringVar::StringToPPVar(file_ref->module(), file_ref->GetName()); |
78 } | 82 } |
79 | 83 |
80 PP_Var GetPath(PP_Resource file_ref_id) { | 84 PP_Var GetPath(PP_Resource file_ref_id) { |
81 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 85 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 86 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
82 if (!file_ref) | 87 if (!file_ref) |
83 return PP_MakeUndefined(); | 88 return PP_MakeUndefined(); |
84 | 89 |
85 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | 90 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
86 return PP_MakeUndefined(); | 91 return PP_MakeUndefined(); |
87 | 92 |
88 return StringVar::StringToPPVar(file_ref->module(), file_ref->GetPath()); | 93 return StringVar::StringToPPVar(file_ref->module(), file_ref->GetPath()); |
89 } | 94 } |
90 | 95 |
91 PP_Resource GetParent(PP_Resource file_ref_id) { | 96 PP_Resource GetParent(PP_Resource file_ref_id) { |
92 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 97 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 98 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
93 if (!file_ref) | 99 if (!file_ref) |
94 return 0; | 100 return 0; |
95 | 101 |
96 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | 102 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
97 return 0; | 103 return 0; |
98 | 104 |
99 scoped_refptr<FileRef> parent_ref(file_ref->GetParent()); | 105 scoped_refptr<PPB_FileRef_Impl> parent_ref(file_ref->GetParent()); |
100 if (!parent_ref) | 106 if (!parent_ref) |
101 return 0; | 107 return 0; |
102 | 108 |
103 return parent_ref->GetReference(); | 109 return parent_ref->GetReference(); |
104 } | 110 } |
105 | 111 |
106 int32_t MakeDirectory(PP_Resource directory_ref_id, | 112 int32_t MakeDirectory(PP_Resource directory_ref_id, |
107 PP_Bool make_ancestors, | 113 PP_Bool make_ancestors, |
108 PP_CompletionCallback callback) { | 114 PP_CompletionCallback callback) { |
109 scoped_refptr<FileRef> directory_ref( | 115 scoped_refptr<PPB_FileRef_Impl> directory_ref( |
110 Resource::GetAs<FileRef>(directory_ref_id)); | 116 Resource::GetAs<PPB_FileRef_Impl>(directory_ref_id)); |
111 if (!directory_ref) | 117 if (!directory_ref) |
112 return PP_ERROR_BADRESOURCE; | 118 return PP_ERROR_BADRESOURCE; |
113 | 119 |
114 scoped_refptr<FileSystem> file_system = directory_ref->GetFileSystem(); | 120 scoped_refptr<PPB_FileSystem_Impl> file_system = directory_ref->GetFileSystem(
); |
115 if (!file_system || !file_system->opened() || | 121 if (!file_system || !file_system->opened() || |
116 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 122 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
117 return PP_ERROR_NOACCESS; | 123 return PP_ERROR_NOACCESS; |
118 | 124 |
119 PluginInstance* instance = file_system->instance(); | 125 PluginInstance* instance = file_system->instance(); |
120 if (!instance->delegate()->MakeDirectory( | 126 if (!instance->delegate()->MakeDirectory( |
121 directory_ref->GetSystemPath(), PPBoolToBool(make_ancestors), | 127 directory_ref->GetSystemPath(), PPBoolToBool(make_ancestors), |
122 new FileCallbacks(instance->module()->AsWeakPtr(), | 128 new FileCallbacks(instance->module()->AsWeakPtr(), |
123 callback, NULL, NULL, NULL))) | 129 callback, NULL, NULL, NULL))) |
124 return PP_ERROR_FAILED; | 130 return PP_ERROR_FAILED; |
125 | 131 |
126 return PP_ERROR_WOULDBLOCK; | 132 return PP_ERROR_WOULDBLOCK; |
127 } | 133 } |
128 | 134 |
129 int32_t Query(PP_Resource file_ref_id, | 135 int32_t Query(PP_Resource file_ref_id, |
130 PP_FileInfo_Dev* info, | 136 PP_FileInfo_Dev* info, |
131 PP_CompletionCallback callback) { | 137 PP_CompletionCallback callback) { |
132 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 138 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 139 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
133 if (!file_ref) | 140 if (!file_ref) |
134 return PP_ERROR_BADRESOURCE; | 141 return PP_ERROR_BADRESOURCE; |
135 | 142 |
136 scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem(); | 143 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
137 if (!file_system || !file_system->opened() || | 144 if (!file_system || !file_system->opened() || |
138 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 145 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
139 return PP_ERROR_NOACCESS; | 146 return PP_ERROR_NOACCESS; |
140 | 147 |
141 PluginInstance* instance = file_system->instance(); | 148 PluginInstance* instance = file_system->instance(); |
142 if (!instance->delegate()->Query( | 149 if (!instance->delegate()->Query( |
143 file_ref->GetSystemPath(), | 150 file_ref->GetSystemPath(), |
144 new FileCallbacks(instance->module()->AsWeakPtr(), | 151 new FileCallbacks(instance->module()->AsWeakPtr(), |
145 callback, info, file_system, NULL))) | 152 callback, info, file_system, NULL))) |
146 return PP_ERROR_FAILED; | 153 return PP_ERROR_FAILED; |
147 | 154 |
148 return PP_ERROR_WOULDBLOCK; | 155 return PP_ERROR_WOULDBLOCK; |
149 } | 156 } |
150 | 157 |
151 int32_t Touch(PP_Resource file_ref_id, | 158 int32_t Touch(PP_Resource file_ref_id, |
152 PP_Time last_access_time, | 159 PP_Time last_access_time, |
153 PP_Time last_modified_time, | 160 PP_Time last_modified_time, |
154 PP_CompletionCallback callback) { | 161 PP_CompletionCallback callback) { |
155 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 162 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 163 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
156 if (!file_ref) | 164 if (!file_ref) |
157 return PP_ERROR_BADRESOURCE; | 165 return PP_ERROR_BADRESOURCE; |
158 | 166 |
159 scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem(); | 167 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
160 if (!file_system || !file_system->opened() || | 168 if (!file_system || !file_system->opened() || |
161 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 169 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
162 return PP_ERROR_NOACCESS; | 170 return PP_ERROR_NOACCESS; |
163 | 171 |
164 PluginInstance* instance = file_system->instance(); | 172 PluginInstance* instance = file_system->instance(); |
165 if (!instance->delegate()->Touch( | 173 if (!instance->delegate()->Touch( |
166 file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time), | 174 file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time), |
167 base::Time::FromDoubleT(last_modified_time), | 175 base::Time::FromDoubleT(last_modified_time), |
168 new FileCallbacks(instance->module()->AsWeakPtr(), | 176 new FileCallbacks(instance->module()->AsWeakPtr(), |
169 callback, NULL, NULL, NULL))) | 177 callback, NULL, NULL, NULL))) |
170 return PP_ERROR_FAILED; | 178 return PP_ERROR_FAILED; |
171 | 179 |
172 return PP_ERROR_WOULDBLOCK; | 180 return PP_ERROR_WOULDBLOCK; |
173 } | 181 } |
174 | 182 |
175 int32_t Delete(PP_Resource file_ref_id, | 183 int32_t Delete(PP_Resource file_ref_id, |
176 PP_CompletionCallback callback) { | 184 PP_CompletionCallback callback) { |
177 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 185 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 186 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
178 if (!file_ref) | 187 if (!file_ref) |
179 return PP_ERROR_BADRESOURCE; | 188 return PP_ERROR_BADRESOURCE; |
180 | 189 |
181 scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem(); | 190 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
182 if (!file_system || !file_system->opened() || | 191 if (!file_system || !file_system->opened() || |
183 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 192 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
184 return PP_ERROR_NOACCESS; | 193 return PP_ERROR_NOACCESS; |
185 | 194 |
186 PluginInstance* instance = file_system->instance(); | 195 PluginInstance* instance = file_system->instance(); |
187 if (!instance->delegate()->Delete( | 196 if (!instance->delegate()->Delete( |
188 file_ref->GetSystemPath(), | 197 file_ref->GetSystemPath(), |
189 new FileCallbacks(instance->module()->AsWeakPtr(), | 198 new FileCallbacks(instance->module()->AsWeakPtr(), |
190 callback, NULL, NULL, NULL))) | 199 callback, NULL, NULL, NULL))) |
191 return PP_ERROR_FAILED; | 200 return PP_ERROR_FAILED; |
192 | 201 |
193 return PP_ERROR_WOULDBLOCK; | 202 return PP_ERROR_WOULDBLOCK; |
194 } | 203 } |
195 | 204 |
196 int32_t Rename(PP_Resource file_ref_id, | 205 int32_t Rename(PP_Resource file_ref_id, |
197 PP_Resource new_file_ref_id, | 206 PP_Resource new_file_ref_id, |
198 PP_CompletionCallback callback) { | 207 PP_CompletionCallback callback) { |
199 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 208 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 209 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
200 if (!file_ref) | 210 if (!file_ref) |
201 return PP_ERROR_BADRESOURCE; | 211 return PP_ERROR_BADRESOURCE; |
202 | 212 |
203 scoped_refptr<FileRef> new_file_ref( | 213 scoped_refptr<PPB_FileRef_Impl> new_file_ref( |
204 Resource::GetAs<FileRef>(new_file_ref_id)); | 214 Resource::GetAs<PPB_FileRef_Impl>(new_file_ref_id)); |
205 if (!new_file_ref) | 215 if (!new_file_ref) |
206 return PP_ERROR_BADRESOURCE; | 216 return PP_ERROR_BADRESOURCE; |
207 | 217 |
208 scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem(); | 218 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
209 if (!file_system || !file_system->opened() || | 219 if (!file_system || !file_system->opened() || |
210 (file_system != new_file_ref->GetFileSystem()) || | 220 (file_system != new_file_ref->GetFileSystem()) || |
211 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 221 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
212 return PP_ERROR_NOACCESS; | 222 return PP_ERROR_NOACCESS; |
213 | 223 |
214 PluginInstance* instance = file_system->instance(); | 224 PluginInstance* instance = file_system->instance(); |
215 if (!instance->delegate()->Rename( | 225 if (!instance->delegate()->Rename( |
216 file_ref->GetSystemPath(), new_file_ref->GetSystemPath(), | 226 file_ref->GetSystemPath(), new_file_ref->GetSystemPath(), |
217 new FileCallbacks(instance->module()->AsWeakPtr(), | 227 new FileCallbacks(instance->module()->AsWeakPtr(), |
218 callback, NULL, NULL, NULL))) | 228 callback, NULL, NULL, NULL))) |
(...skipping 11 matching lines...) Expand all Loading... |
230 &GetParent, | 240 &GetParent, |
231 &MakeDirectory, | 241 &MakeDirectory, |
232 &Query, | 242 &Query, |
233 &Touch, | 243 &Touch, |
234 &Delete, | 244 &Delete, |
235 &Rename | 245 &Rename |
236 }; | 246 }; |
237 | 247 |
238 } // namespace | 248 } // namespace |
239 | 249 |
240 FileRef::FileRef() | 250 PPB_FileRef_Impl::PPB_FileRef_Impl() |
241 : Resource(NULL), | 251 : Resource(NULL), |
242 file_system_(NULL) { | 252 file_system_(NULL) { |
243 } | 253 } |
244 | 254 |
245 FileRef::FileRef(PluginModule* module, | 255 PPB_FileRef_Impl::PPB_FileRef_Impl(PluginModule* module, |
246 scoped_refptr<FileSystem> file_system, | 256 scoped_refptr<PPB_FileSystem_Impl> file_system, |
247 const std::string& validated_path) | 257 const std::string& validated_path) |
248 : Resource(module), | 258 : Resource(module), |
249 file_system_(file_system), | 259 file_system_(file_system), |
250 virtual_path_(validated_path) { | 260 virtual_path_(validated_path) { |
251 } | 261 } |
252 | 262 |
253 FileRef::FileRef(PluginModule* module, | 263 PPB_FileRef_Impl::PPB_FileRef_Impl(PluginModule* module, |
254 const FilePath& external_file_path) | 264 const FilePath& external_file_path) |
255 : Resource(module), | 265 : Resource(module), |
256 file_system_(NULL), | 266 file_system_(NULL), |
257 system_path_(external_file_path) { | 267 system_path_(external_file_path) { |
258 } | 268 } |
259 | 269 |
260 FileRef::~FileRef() { | 270 PPB_FileRef_Impl::~PPB_FileRef_Impl() { |
261 } | 271 } |
262 | 272 |
263 // static | 273 // static |
264 const PPB_FileRef_Dev* FileRef::GetInterface() { | 274 const PPB_FileRef_Dev* PPB_FileRef_Impl::GetInterface() { |
265 return &ppb_fileref; | 275 return &ppb_fileref; |
266 } | 276 } |
267 | 277 |
268 FileRef* FileRef::AsFileRef() { | 278 PPB_FileRef_Impl* PPB_FileRef_Impl::AsFileRef() { |
269 return this; | 279 return this; |
270 } | 280 } |
271 | 281 |
272 std::string FileRef::GetName() const { | 282 std::string PPB_FileRef_Impl::GetName() const { |
273 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) { | 283 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) { |
274 FilePath::StringType path = system_path_.value(); | 284 FilePath::StringType path = system_path_.value(); |
275 size_t pos = path.rfind(FilePath::kSeparators[0]); | 285 size_t pos = path.rfind(FilePath::kSeparators[0]); |
276 DCHECK(pos != FilePath::StringType::npos); | 286 DCHECK(pos != FilePath::StringType::npos); |
277 #if defined(OS_WIN) | 287 #if defined(OS_WIN) |
278 return WideToUTF8(path.substr(pos + 1)); | 288 return WideToUTF8(path.substr(pos + 1)); |
279 #elif defined(OS_POSIX) | 289 #elif defined(OS_POSIX) |
280 return path.substr(pos + 1); | 290 return path.substr(pos + 1); |
281 #else | 291 #else |
282 #error "Unsupported platform." | 292 #error "Unsupported platform." |
283 #endif | 293 #endif |
284 } | 294 } |
285 | 295 |
286 if (virtual_path_.size() == 1 && virtual_path_[0] == '/') | 296 if (virtual_path_.size() == 1 && virtual_path_[0] == '/') |
287 return virtual_path_; | 297 return virtual_path_; |
288 | 298 |
289 // There should always be a leading slash at least! | 299 // There should always be a leading slash at least! |
290 size_t pos = virtual_path_.rfind('/'); | 300 size_t pos = virtual_path_.rfind('/'); |
291 DCHECK(pos != std::string::npos); | 301 DCHECK(pos != std::string::npos); |
292 | 302 |
293 return virtual_path_.substr(pos + 1); | 303 return virtual_path_.substr(pos + 1); |
294 } | 304 } |
295 | 305 |
296 scoped_refptr<FileRef> FileRef::GetParent() { | 306 scoped_refptr<PPB_FileRef_Impl> PPB_FileRef_Impl::GetParent() { |
297 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | 307 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
298 return new FileRef(); | 308 return new PPB_FileRef_Impl(); |
299 | 309 |
300 // There should always be a leading slash at least! | 310 // There should always be a leading slash at least! |
301 size_t pos = virtual_path_.rfind('/'); | 311 size_t pos = virtual_path_.rfind('/'); |
302 DCHECK(pos != std::string::npos); | 312 DCHECK(pos != std::string::npos); |
303 | 313 |
304 // If the path is "/foo", then we want to include the slash. | 314 // If the path is "/foo", then we want to include the slash. |
305 if (pos == 0) | 315 if (pos == 0) |
306 pos++; | 316 pos++; |
307 std::string parent_path = virtual_path_.substr(0, pos); | 317 std::string parent_path = virtual_path_.substr(0, pos); |
308 | 318 |
309 FileRef* parent_ref = new FileRef(module(), file_system_, parent_path); | 319 PPB_FileRef_Impl* parent_ref = new PPB_FileRef_Impl(module(), file_system_, |
| 320 parent_path); |
310 return parent_ref; | 321 return parent_ref; |
311 } | 322 } |
312 | 323 |
313 scoped_refptr<FileSystem> FileRef::GetFileSystem() const { | 324 scoped_refptr<PPB_FileSystem_Impl> PPB_FileRef_Impl::GetFileSystem() const { |
314 return file_system_; | 325 return file_system_; |
315 } | 326 } |
316 | 327 |
317 PP_FileSystemType_Dev FileRef::GetFileSystemType() const { | 328 PP_FileSystemType_Dev PPB_FileRef_Impl::GetFileSystemType() const { |
318 if (!file_system_) | 329 if (!file_system_) |
319 return PP_FILESYSTEMTYPE_EXTERNAL; | 330 return PP_FILESYSTEMTYPE_EXTERNAL; |
320 | 331 |
321 return file_system_->type(); | 332 return file_system_->type(); |
322 } | 333 } |
323 | 334 |
324 std::string FileRef::GetPath() const { | 335 std::string PPB_FileRef_Impl::GetPath() const { |
325 return virtual_path_; | 336 return virtual_path_; |
326 } | 337 } |
327 | 338 |
328 FilePath FileRef::GetSystemPath() const { | 339 FilePath PPB_FileRef_Impl::GetSystemPath() const { |
329 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | 340 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
330 return system_path_; | 341 return system_path_; |
331 | 342 |
332 // Since |virtual_path_| starts with a '/', it is considered an absolute path | 343 // Since |virtual_path_| starts with a '/', it is considered an absolute path |
333 // on POSIX systems. We need to remove the '/' before calling Append() or we | 344 // on POSIX systems. We need to remove the '/' before calling Append() or we |
334 // will run into a DCHECK. | 345 // will run into a DCHECK. |
335 FilePath virtual_file_path( | 346 FilePath virtual_file_path( |
336 #if defined(OS_WIN) | 347 #if defined(OS_WIN) |
337 UTF8ToWide(virtual_path_.substr(1)) | 348 UTF8ToWide(virtual_path_.substr(1)) |
338 #elif defined(OS_POSIX) | 349 #elif defined(OS_POSIX) |
339 virtual_path_.substr(1) | 350 virtual_path_.substr(1) |
340 #else | 351 #else |
341 #error "Unsupported platform." | 352 #error "Unsupported platform." |
342 #endif | 353 #endif |
343 ); | 354 ); |
344 return file_system_->root_path().Append(virtual_file_path); | 355 return file_system_->root_path().Append(virtual_file_path); |
345 } | 356 } |
346 | 357 |
347 } // namespace pepper | 358 } // namespace ppapi |
| 359 } // namespace plugins |
| 360 } // namespace webkit |
| 361 |
OLD | NEW |