// static
PassRefPtr<EntryArray> HTMLInputElementFileSystem::webkitEntries(ScriptExecutionContext* scriptExecutionContext, HTMLInputElement* input)
{
    RefPtr<EntryArray> array = EntryArray::create();
    FileList* files = input->files();

    if (!files)
        return array;

    RefPtr<DOMFileSystem> filesystem = DOMFileSystem::createIsolatedFileSystem(scriptExecutionContext, input->droppedFileSystemId());
    if (!filesystem) {
        // Drag-drop isolated filesystem is not available.
        return array;
    }

    for (unsigned i = 0; i < files->length(); ++i) {
        File* file = files->item(i);

        // FIXME: This involves synchronous file operation.
        FileMetadata metadata;
        if (!getFileMetadata(file->path(), metadata))
            continue;

        // The dropped entries are mapped as top-level entries in the isolated filesystem.
        String virtualPath = DOMFilePath::append("/", file->name());
        if (metadata.type == FileMetadata::TypeDirectory)
            array->append(DirectoryEntry::create(filesystem, virtualPath));
        else
            array->append(FileEntry::create(filesystem, virtualPath));
    }
    return array;
}
// static
EntryHeapVector HTMLInputElementFileSystem::webkitEntries(ExecutionContext* executionContext, HTMLInputElement& input)
{
    EntryHeapVector entries;
    FileList* files = input.files();

    if (!files)
        return entries;

    RefPtrWillBeRawPtr<DOMFileSystem> filesystem = DOMFileSystem::createIsolatedFileSystem(executionContext, input.droppedFileSystemId());
    if (!filesystem) {
        // Drag-drop isolated filesystem is not available.
        return entries;
    }

    for (unsigned i = 0; i < files->length(); ++i) {
        File* file = files->item(i);

        // FIXME: This involves synchronous file operation.
        FileMetadata metadata;
        if (!getFileMetadata(file->path(), metadata))
            continue;

        // The dropped entries are mapped as top-level entries in the isolated filesystem.
        String virtualPath = DOMFilePath::append("/", file->name());
        if (metadata.type == FileMetadata::TypeDirectory)
            entries.append(DirectoryEntry::create(filesystem, virtualPath));
        else
            entries.append(FileEntry::create(filesystem, virtualPath));
    }
    return entries;
}
// static
PassRefPtrWillBeRawPtr<Entry> DataTransferItemFileSystem::webkitGetAsEntry(ExecutionContext* executionContext, DataTransferItem& item)
{
    if (!item.dataObjectItem()->isFilename())
        return nullptr;

    // For dragged files getAsFile must be pretty lightweight.
    Blob* file = item.getAsFile().get();
    // The clipboard may not be in a readable state.
    if (!file)
        return nullptr;
    ASSERT(file->isFile());

    DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(item.clipboard()->dataObject().get());
    DOMFileSystem* domFileSystem = filesystem ? filesystem->getDOMFileSystem(executionContext) : 0;
    if (!filesystem) {
        // IsolatedFileSystem may not be enabled.
        return nullptr;
    }

    ASSERT(domFileSystem);

    // The dropped entries are mapped as top-level entries in the isolated filesystem.
    String virtualPath = DOMFilePath::append("/", toFile(file)->name());

    // FIXME: This involves synchronous file operation. Consider passing file type data when we dispatch drag event.
    FileMetadata metadata;
    if (!getFileMetadata(toFile(file)->path(), metadata))
        return nullptr;

    if (metadata.type == FileMetadata::TypeDirectory)
        return DirectoryEntry::create(domFileSystem, virtualPath);
    return FileEntry::create(domFileSystem, virtualPath);
}
Beispiel #4
0
bool getFileModificationTime(const String& path, double& result) {
  FileMetadata metadata;
  if (!getFileMetadata(path, metadata))
    return false;
  result = metadata.modificationTime;
  return true;
}
Beispiel #5
0
bool getFileSize(const String& path, long long& result) {
  FileMetadata metadata;
  if (!getFileMetadata(path, metadata))
    return false;
  result = metadata.length;
  return true;
}
 DOMFileSystemBaseTest()
 {
     m_filePath = testing::blinkRootDir();
     m_filePath.append("/Source/modules/filesystem/DOMFileSystemBaseTest.cpp");
     getFileMetadata(m_filePath, m_fileMetadata);
     m_fileMetadata.platformPath = m_filePath;
 }
void File::captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const
{
#if ENABLE(FILE_SYSTEM)
    if (hasValidSnapshotMetadata()) {
        snapshotSize = m_snapshotSize;
        snapshotModificationTime = m_snapshotModificationTime;
        return;
    }
#endif

    // Obtains a snapshot of the file by capturing its current size and modification time. This is used when we slice a file for the first time.
    // If we fail to retrieve the size or modification time, probably due to that the file has been deleted, 0 size is returned.
    FileMetadata metadata;
    if (!getFileMetadata(m_path, metadata)) {
        snapshotSize = 0;
        snapshotModificationTime = invalidFileTime();
        return;
    }

    snapshotSize = metadata.length;
    snapshotModificationTime = metadata.modificationTime;
}