Пример #1
0
static void encodeElement(Encoder& encoder, const FormDataElement& element)
{
    encoder.encodeUInt32(element.m_type);

    switch (element.m_type) {
    case FormDataElement::data:
        encoder.encodeBytes(reinterpret_cast<const uint8_t*>(element.m_data.data()), element.m_data.size());
        return;

    case FormDataElement::encodedFile:
        encoder.encodeString(element.m_filename);
        encoder.encodeString(element.m_generatedFilename);
        encoder.encodeBool(element.m_shouldGenerateFile);
#if ENABLE(BLOB)
        encoder.encodeInt64(element.m_fileStart);
        encoder.encodeInt64(element.m_fileLength);
        encoder.encodeDouble(element.m_expectedFileModificationTime);
#else
        encoder.encodeInt64(0);
        encoder.encodeInt64(0);
        encoder.encodeDouble(invalidFileTime());
#endif
        return;

#if ENABLE(BLOB)
    case FormDataElement::encodedBlob:
        encoder.encodeString(element.m_url.string());
        return;
#endif
    }

    ASSERT_NOT_REACHED();
}
Пример #2
0
static HTTPBody toHTTPBody(const FormData& formData)
{
    HTTPBody httpBody;

    for (const auto& formDataElement : formData.elements()) {
        HTTPBody::Element element;

        switch (formDataElement.m_type) {
        case FormDataElement::Type::Data:
            element.type = HTTPBody::Element::Type::Data;
            element.data = formDataElement.m_data;
            break;

        case FormDataElement::Type::EncodedFile:
            element.filePath = formDataElement.m_filename;
            element.fileStart = formDataElement.m_fileStart;
            if (formDataElement.m_fileLength != BlobDataItem::toEndOfFile)
                element.fileLength = formDataElement.m_fileLength;
            if (formDataElement.m_expectedFileModificationTime != invalidFileTime())
                element.expectedFileModificationTime = formDataElement.m_expectedFileModificationTime;
            break;

        case FormDataElement::Type::EncodedBlob:
            element.blobURLString = formDataElement.m_url.string();
            break;
        }

        httpBody.elements.append(WTF::move(element));
    }

    return httpBody;
}
Пример #3
0
void FormData::appendFile(const String& filename, bool shouldGenerateFile)
{
#if ENABLE(BLOB)
    m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, invalidFileTime(), shouldGenerateFile));
#else
    m_elements.append(FormDataElement(filename, shouldGenerateFile));
#endif
}
File::File(const String& path, ContentTypeLookupPolicy policy)
    : Blob(createBlobDataForFile(path, policy), -1)
    , m_path(path)
    , m_name(pathGetFileName(path))
#if ENABLE(FILE_SYSTEM)
    , m_snapshotSize(-1)
    , m_snapshotModificationTime(invalidFileTime())
#endif
{
}
Пример #5
0
File::File(const String& path,
           ContentTypeLookupPolicy policy,
           UserVisibility userVisibility)
    : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)),
      m_hasBackingFile(true),
      m_userVisibility(userVisibility),
      m_path(path),
      m_name(Platform::current()->fileUtilities()->baseName(path)),
      m_snapshotSize(-1),
      m_snapshotModificationTimeMS(invalidFileTime()) {}
File::File(const String& path, const KURL& url, const String& type)
    : Blob(url, type, -1)
    , m_path(path)
#if ENABLE(FILE_SYSTEM)
    , m_snapshotSize(-1)
    , m_snapshotModificationTime(invalidFileTime())
#endif
{
    m_name = pathGetFileName(path);
    // FIXME: File object serialization/deserialization does not include
    // newer file object data members: m_name and m_relativePath.
    // See SerializedScriptValue.cpp
}
Пример #7
0
File::File(const String& path,
           const String& name,
           ContentTypeLookupPolicy policy,
           UserVisibility userVisibility)
    : Blob(BlobDataHandle::create(
          createBlobDataForFileWithName(path, name, policy),
          -1)),
      m_hasBackingFile(true),
      m_userVisibility(userVisibility),
      m_path(path),
      m_name(name),
      m_snapshotSize(-1),
      m_snapshotModificationTimeMS(invalidFileTime()) {}
Пример #8
0
double File::lastModifiedDate() const
{
#if ENABLE(FILE_SYSTEM)
    if (hasValidSnapshotMetadata())
        return m_snapshotModificationTime * 1000.0;
#endif

    time_t modificationTime;
    if (!getFileModificationTime(m_path, modificationTime))
        return invalidFileTime();

    // Needs to return epoch time in milliseconds for Date.
    return modificationTime * 1000.0;
}
Пример #9
0
File::File(const String& path,
           const String& name,
           const String& relativePath,
           UserVisibility userVisibility,
           bool hasSnapshotData,
           uint64_t size,
           double lastModified,
           PassRefPtr<BlobDataHandle> blobDataHandle)
    : Blob(std::move(blobDataHandle)),
      m_hasBackingFile(!path.isEmpty() || !relativePath.isEmpty()),
      m_userVisibility(userVisibility),
      m_path(path),
      m_name(name),
      m_snapshotSize(hasSnapshotData ? static_cast<long long>(size) : -1),
      m_snapshotModificationTimeMS(hasSnapshotData ? lastModified
                                                   : invalidFileTime()),
      m_relativePath(relativePath) {}
Пример #10
0
bool WebHTTPBody::elementAt(size_t index, Element& result) const
{
    ASSERT(!isNull());

    if (index >= m_private->elements().size())
        return false;

    const FormDataElement& element = m_private->elements()[index];

    result.data.reset();
    result.filePath.reset();
    result.fileStart = 0;
    result.fileLength = 0;
    result.modificationTime = invalidFileTime();
    result.blobUUID.reset();

    switch (element.m_type) {
    case FormDataElement::data:
        result.type = Element::TypeData;
        result.data.assign(element.m_data.data(), element.m_data.size());
        break;
    case FormDataElement::encodedFile:
        result.type = Element::TypeFile;
        result.filePath = element.m_filename;
        result.fileStart = element.m_fileStart;
        result.fileLength = element.m_fileLength;
        result.modificationTime = element.m_expectedFileModificationTime;
        break;
    case FormDataElement::encodedBlob:
        result.type = Element::TypeBlob;
        result.blobUUID = element.m_blobUUID;
        break;
    case FormDataElement::encodedFileSystemURL:
        result.type = Element::TypeFileSystemURL;
        result.fileSystemURL = element.m_fileSystemURL;
        result.fileStart = element.m_fileStart;
        result.fileLength = element.m_fileLength;
        result.modificationTime = element.m_expectedFileModificationTime;
        break;
    default:
        ASSERT_NOT_REACHED();
        return false;
    }

    return true;
}
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;
}
Пример #12
0
void FormData::appendFile(const String& filename, bool shouldGenerateFile)
{
    m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, invalidFileTime(), shouldGenerateFile));
}
Пример #13
0
void FormData::appendURL(const KURL& url)
{
    m_elements.append(FormDataElement(url, 0, BlobDataItem::toEndOfFile, invalidFileTime()));
}
Пример #14
0
void FormData::appendFile(const String& filename)
{
    m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, invalidFileTime()));
}
Пример #15
0
static PassRefPtr<FormData> toFormData(const HTTPBody& httpBody)
{
    RefPtr<FormData> formData = FormData::create();

    for (const auto& element : httpBody.elements) {
        switch (element.type) {
        case HTTPBody::Element::Type::Data:
            formData->appendData(element.data.data(), element.data.size());
            break;

        case HTTPBody::Element::Type::File:
            formData->appendFileRange(element.filePath, element.fileStart, element.fileLength.valueOr(BlobDataItem::toEndOfFile), element.expectedFileModificationTime.valueOr(invalidFileTime()));
            break;

        case HTTPBody::Element::Type::Blob:
            formData->appendBlob(URL(URL(), element.blobURLString));
            break;
        }
    }

    return formData.release();
}