OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "core/fileapi/File.h" | 34 #include "core/fileapi/File.h" |
35 #include "core/fileapi/FileError.h" | 35 #include "core/fileapi/FileError.h" |
36 #include "core/html/VoidCallback.h" | 36 #include "core/html/VoidCallback.h" |
37 #include "modules/filesystem/DOMFilePath.h" | 37 #include "modules/filesystem/DOMFilePath.h" |
38 #include "modules/filesystem/DirectoryEntry.h" | 38 #include "modules/filesystem/DirectoryEntry.h" |
39 #include "modules/filesystem/DirectoryReaderBase.h" | 39 #include "modules/filesystem/DirectoryReaderBase.h" |
40 #include "modules/filesystem/EntriesCallback.h" | 40 #include "modules/filesystem/EntriesCallback.h" |
41 #include "modules/filesystem/Entry.h" | 41 #include "modules/filesystem/Entry.h" |
42 #include "modules/filesystem/EntryBase.h" | 42 #include "modules/filesystem/EntryBase.h" |
43 #include "modules/filesystem/EntryCallback.h" | 43 #include "modules/filesystem/EntryCallback.h" |
44 #include "modules/filesystem/ErrorCallback.h" | |
45 #include "modules/filesystem/FileSystemCallbacks.h" | 44 #include "modules/filesystem/FileSystemCallbacks.h" |
46 #include "modules/filesystem/MetadataCallback.h" | 45 #include "modules/filesystem/MetadataCallback.h" |
47 #include "platform/weborigin/SecurityOrigin.h" | 46 #include "platform/weborigin/SecurityOrigin.h" |
48 #include "public/platform/Platform.h" | 47 #include "public/platform/Platform.h" |
49 #include "public/platform/WebFileSystem.h" | 48 #include "public/platform/WebFileSystem.h" |
50 #include "public/platform/WebFileSystemCallbacks.h" | 49 #include "public/platform/WebFileSystemCallbacks.h" |
51 #include "wtf/text/StringBuilder.h" | 50 #include "wtf/text/StringBuilder.h" |
52 #include "wtf/text/TextEncoding.h" | 51 #include "wtf/text/TextEncoding.h" |
53 #include <memory> | 52 #include <memory> |
54 | 53 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 207 |
209 if (!metadata.platformPath.isEmpty()) { | 208 if (!metadata.platformPath.isEmpty()) { |
210 // If the platformPath in the returned metadata is given, we create a Fi
le object for the snapshot path. | 209 // If the platformPath in the returned metadata is given, we create a Fi
le object for the snapshot path. |
211 return File::createForFileSystemFile(name, metadata, userVisibility); | 210 return File::createForFileSystemFile(name, metadata, userVisibility); |
212 } else { | 211 } else { |
213 // Otherwise we create a File object for the fileSystemURL. | 212 // Otherwise we create a File object for the fileSystemURL. |
214 return File::createForFileSystemFile(fileSystemURL, metadata, userVisibi
lity); | 213 return File::createForFileSystemFile(fileSystemURL, metadata, userVisibi
lity); |
215 } | 214 } |
216 } | 215 } |
217 | 216 |
218 void DOMFileSystemBase::getMetadata(const EntryBase* entry, MetadataCallback* su
ccessCallback, ErrorCallback* errorCallback, SynchronousType synchronousType) | 217 void DOMFileSystemBase::getMetadata(const EntryBase* entry, MetadataCallback* su
ccessCallback, ErrorCallbackBase* errorCallback, SynchronousType synchronousType
) |
219 { | 218 { |
220 if (!fileSystem()) { | 219 if (!fileSystem()) { |
221 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 220 reportError(errorCallback, FileError::ABORT_ERR); |
222 return; | 221 return; |
223 } | 222 } |
224 | 223 |
225 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::creat
e(successCallback, errorCallback, m_context, this)); | 224 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::creat
e(successCallback, errorCallback, m_context, this)); |
226 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 225 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
227 fileSystem()->readMetadata(createFileSystemURL(entry), std::move(callbacks))
; | 226 fileSystem()->readMetadata(createFileSystemURL(entry), std::move(callbacks))
; |
228 } | 227 } |
229 | 228 |
230 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En
tryBase* parent, const String& newName, String& destinationPath) | 229 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En
tryBase* parent, const String& newName, String& destinationPath) |
231 { | 230 { |
(...skipping 17 matching lines...) Expand all Loading... |
249 | 248 |
250 destinationPath = parent->fullPath(); | 249 destinationPath = parent->fullPath(); |
251 if (!newName.isEmpty()) | 250 if (!newName.isEmpty()) |
252 destinationPath = DOMFilePath::append(destinationPath, newName); | 251 destinationPath = DOMFilePath::append(destinationPath, newName); |
253 else | 252 else |
254 destinationPath = DOMFilePath::append(destinationPath, source->name()); | 253 destinationPath = DOMFilePath::append(destinationPath, source->name()); |
255 | 254 |
256 return true; | 255 return true; |
257 } | 256 } |
258 | 257 |
259 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S
tring& newName, EntryCallback* successCallback, ErrorCallback* errorCallback, Sy
nchronousType synchronousType) | 258 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S
tring& newName, EntryCallback* successCallback, ErrorCallbackBase* errorCallback
, SynchronousType synchronousType) |
260 { | 259 { |
261 if (!fileSystem()) { | 260 if (!fileSystem()) { |
262 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 261 reportError(errorCallback, FileError::ABORT_ERR); |
263 return; | 262 return; |
264 } | 263 } |
265 | 264 |
266 String destinationPath; | 265 String destinationPath; |
267 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { | 266 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { |
268 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 267 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
269 return; | 268 return; |
270 } | 269 } |
271 | 270 |
272 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, parent->filesystem(), destinationPath,
source->isDirectory())); | 271 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, parent->filesystem(), destinationPath,
source->isDirectory())); |
273 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 272 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
274 | 273 |
275 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), std::move(callbacks)); | 274 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), std::move(callbacks)); |
276 } | 275 } |
277 | 276 |
278 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S
tring& newName, EntryCallback* successCallback, ErrorCallback* errorCallback, Sy
nchronousType synchronousType) | 277 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S
tring& newName, EntryCallback* successCallback, ErrorCallbackBase* errorCallback
, SynchronousType synchronousType) |
279 { | 278 { |
280 if (!fileSystem()) { | 279 if (!fileSystem()) { |
281 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 280 reportError(errorCallback, FileError::ABORT_ERR); |
282 return; | 281 return; |
283 } | 282 } |
284 | 283 |
285 String destinationPath; | 284 String destinationPath; |
286 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { | 285 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { |
287 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 286 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
288 return; | 287 return; |
289 } | 288 } |
290 | 289 |
291 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, parent->filesystem(), destinationPath,
source->isDirectory())); | 290 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, parent->filesystem(), destinationPath,
source->isDirectory())); |
292 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 291 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
293 | 292 |
294 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), std::move(callbacks)); | 293 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), std::move(callbacks)); |
295 } | 294 } |
296 | 295 |
297 void DOMFileSystemBase::remove(const EntryBase* entry, VoidCallback* successCall
back, ErrorCallback* errorCallback, SynchronousType synchronousType) | 296 void DOMFileSystemBase::remove(const EntryBase* entry, VoidCallback* successCall
back, ErrorCallbackBase* errorCallback, SynchronousType synchronousType) |
298 { | 297 { |
299 if (!fileSystem()) { | 298 if (!fileSystem()) { |
300 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 299 reportError(errorCallback, FileError::ABORT_ERR); |
301 return; | 300 return; |
302 } | 301 } |
303 | 302 |
304 ASSERT(entry); | 303 ASSERT(entry); |
305 // We don't allow calling remove() on the root directory. | 304 // We don't allow calling remove() on the root directory. |
306 if (entry->fullPath() == String(DOMFilePath::root)) { | 305 if (entry->fullPath() == String(DOMFilePath::root)) { |
307 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 306 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
308 return; | 307 return; |
309 } | 308 } |
310 | 309 |
311 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(su
ccessCallback, errorCallback, m_context, this)); | 310 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(su
ccessCallback, errorCallback, m_context, this)); |
312 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 311 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
313 | 312 |
314 fileSystem()->remove(createFileSystemURL(entry), std::move(callbacks)); | 313 fileSystem()->remove(createFileSystemURL(entry), std::move(callbacks)); |
315 } | 314 } |
316 | 315 |
317 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, VoidCallback*
successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType) | 316 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, VoidCallback*
successCallback, ErrorCallbackBase* errorCallback, SynchronousType synchronousTy
pe) |
318 { | 317 { |
319 if (!fileSystem()) { | 318 if (!fileSystem()) { |
320 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 319 reportError(errorCallback, FileError::ABORT_ERR); |
321 return; | 320 return; |
322 } | 321 } |
323 | 322 |
324 ASSERT(entry && entry->isDirectory()); | 323 ASSERT(entry && entry->isDirectory()); |
325 // We don't allow calling remove() on the root directory. | 324 // We don't allow calling remove() on the root directory. |
326 if (entry->fullPath() == String(DOMFilePath::root)) { | 325 if (entry->fullPath() == String(DOMFilePath::root)) { |
327 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 326 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
328 return; | 327 return; |
329 } | 328 } |
330 | 329 |
331 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(su
ccessCallback, errorCallback, m_context, this)); | 330 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(su
ccessCallback, errorCallback, m_context, this)); |
332 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 331 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
333 | 332 |
334 fileSystem()->removeRecursively(createFileSystemURL(entry), std::move(callba
cks)); | 333 fileSystem()->removeRecursively(createFileSystemURL(entry), std::move(callba
cks)); |
335 } | 334 } |
336 | 335 |
337 void DOMFileSystemBase::getParent(const EntryBase* entry, EntryCallback* success
Callback, ErrorCallback* errorCallback) | 336 void DOMFileSystemBase::getParent(const EntryBase* entry, EntryCallback* success
Callback, ErrorCallbackBase* errorCallback) |
338 { | 337 { |
339 if (!fileSystem()) { | 338 if (!fileSystem()) { |
340 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 339 reportError(errorCallback, FileError::ABORT_ERR); |
341 return; | 340 return; |
342 } | 341 } |
343 | 342 |
344 ASSERT(entry); | 343 ASSERT(entry); |
345 String path = DOMFilePath::getDirectory(entry->fullPath()); | 344 String path = DOMFilePath::getDirectory(entry->fullPath()); |
346 | 345 |
347 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre
ate(successCallback, errorCallback, m_context, this, path, true)); | 346 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre
ate(successCallback, errorCallback, m_context, this, path, true)); |
348 } | 347 } |
349 | 348 |
350 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons
t FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallback* errorCa
llback, SynchronousType synchronousType) | 349 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons
t FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallbackBase* err
orCallback, SynchronousType synchronousType) |
351 { | 350 { |
352 if (!fileSystem()) { | 351 if (!fileSystem()) { |
353 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 352 reportError(errorCallback, FileError::ABORT_ERR); |
354 return; | 353 return; |
355 } | 354 } |
356 | 355 |
357 String absolutePath; | 356 String absolutePath; |
358 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 357 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
359 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 358 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
360 return; | 359 return; |
361 } | 360 } |
362 | 361 |
363 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, this, absolutePath, false)); | 362 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, this, absolutePath, false)); |
364 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 363 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
365 | 364 |
366 if (flags.createFlag()) | 365 if (flags.createFlag()) |
367 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus
ive(), std::move(callbacks)); | 366 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus
ive(), std::move(callbacks)); |
368 else | 367 else |
369 fileSystem()->fileExists(createFileSystemURL(absolutePath), std::move(ca
llbacks)); | 368 fileSystem()->fileExists(createFileSystemURL(absolutePath), std::move(ca
llbacks)); |
370 } | 369 } |
371 | 370 |
372 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path,
const FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallback* er
rorCallback, SynchronousType synchronousType) | 371 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path,
const FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallbackBase
* errorCallback, SynchronousType synchronousType) |
373 { | 372 { |
374 if (!fileSystem()) { | 373 if (!fileSystem()) { |
375 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 374 reportError(errorCallback, FileError::ABORT_ERR); |
376 return; | 375 return; |
377 } | 376 } |
378 | 377 |
379 String absolutePath; | 378 String absolutePath; |
380 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 379 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
381 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 380 reportError(errorCallback, FileError::INVALID_MODIFICATION_ERR); |
382 return; | 381 return; |
383 } | 382 } |
384 | 383 |
385 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, this, absolutePath, true)); | 384 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(s
uccessCallback, errorCallback, m_context, this, absolutePath, true)); |
386 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 385 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
387 | 386 |
388 if (flags.createFlag()) | 387 if (flags.createFlag()) |
389 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e
xclusive(), std::move(callbacks)); | 388 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e
xclusive(), std::move(callbacks)); |
390 else | 389 else |
391 fileSystem()->directoryExists(createFileSystemURL(absolutePath), std::mo
ve(callbacks)); | 390 fileSystem()->directoryExists(createFileSystemURL(absolutePath), std::mo
ve(callbacks)); |
392 } | 391 } |
393 | 392 |
394 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String&
path, EntriesCallback* successCallback, ErrorCallback* errorCallback, Synchronou
sType synchronousType) | 393 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String&
path, EntriesCallback* successCallback, ErrorCallbackBase* errorCallback, Synchr
onousType synchronousType) |
395 { | 394 { |
396 if (!fileSystem()) { | 395 if (!fileSystem()) { |
397 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); | 396 reportError(errorCallback, FileError::ABORT_ERR); |
398 return 0; | 397 return 0; |
399 } | 398 } |
400 | 399 |
401 ASSERT(DOMFilePath::isAbsolute(path)); | 400 ASSERT(DOMFilePath::isAbsolute(path)); |
402 | 401 |
403 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create
(successCallback, errorCallback, m_context, reader, path)); | 402 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create
(successCallback, errorCallback, m_context, reader, path)); |
404 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 403 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
405 | 404 |
406 return fileSystem()->readDirectory(createFileSystemURL(path), std::move(call
backs)); | 405 return fileSystem()->readDirectory(createFileSystemURL(path), std::move(call
backs)); |
407 } | 406 } |
408 | 407 |
409 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) | 408 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) |
410 { | 409 { |
411 if (!fileSystem()) | 410 if (!fileSystem()) |
412 return false; | 411 return false; |
413 return fileSystem()->waitForAdditionalResult(callbacksId); | 412 return fileSystem()->waitForAdditionalResult(callbacksId); |
414 } | 413 } |
415 | 414 |
416 } // namespace blink | 415 } // namespace blink |
OLD | NEW |