Ejemplo n.º 1
0
bool IDBKeyData::decode(KeyedDecoder& decoder, IDBKeyData& result)
{
    if (!decoder.decodeBool("null", result.m_isNull))
        return false;

    if (result.m_isNull)
        return true;

    auto enumFunction = [](int64_t value) {
        return value == KeyType::Max
            || value == KeyType::Invalid
            || value == KeyType::Array
            || value == KeyType::String
            || value == KeyType::Date
            || value == KeyType::Number
            || value == KeyType::Min;
    };
    if (!decoder.decodeEnum("m_type", result.m_type, enumFunction))
        return false;

    if (result.m_type == KeyType::Invalid)
        return true;

    if (result.m_type == KeyType::Max)
        return true;

    if (result.m_type == KeyType::Min)
        return true;

    if (result.m_type == KeyType::String)
        return decoder.decodeString("string", result.m_stringValue);

    if (result.m_type == KeyType::Number || result.m_type == KeyType::Date)
        return decoder.decodeDouble("number", result.m_numberValue);

    ASSERT(result.m_type == KeyType::Array);

    auto arrayFunction = [](KeyedDecoder& decoder, IDBKeyData& result) {
        return decode(decoder, result);
    };
    
    result.m_arrayValue.clear();
    return decoder.decodeObjects("array", result.m_arrayValue, arrayFunction);
}
Ejemplo n.º 2
0
PassRefPtr<FormData> FormData::decode(KeyedDecoder& decoder)
{
    RefPtr<FormData> data = FormData::create();

    if (!decoder.decodeBool("alwaysStream", data->m_alwaysStream))
        return nullptr;

    if (!decoder.decodeBytes("boundary", data->m_boundary))
        return nullptr;

    if (!decoder.decodeObjects("elements", data->m_elements, [](KeyedDecoder& decoder, FormDataElement& element) {
        return decodeElement(decoder, element);
    }))
        return nullptr;

    if (!decoder.decodeInt64("identifier", data->m_identifier))
        return nullptr;

    return data.release();
}
Ejemplo n.º 3
0
PassRefPtr<HistoryItem> HistoryItem::decodeBackForwardTree(const String&, const String&, const String&, KeyedDecoder& decoder)
{
    uint32_t version;
    if (!decoder.decodeUInt32("version", version))
        return nullptr;
    
    if (version != backForwardTreeEncodingVersion)
        return nullptr;

    // FIXME: Implement.
    return nullptr;
}
Ejemplo n.º 4
0
bool IDBKeyPath::decode(KeyedDecoder& decoder, IDBKeyPath& result)
{
    auto enumFunction = [](int64_t value) {
        return value == NullType || value == StringType || value == ArrayType;
    };

    if (!decoder.decodeVerifiedEnum("type", result.m_type, enumFunction))
        return false;

    if (result.m_type == NullType)
        return true;

    if (result.m_type == StringType)
        return decoder.decodeString("string", result.m_string);

    ASSERT(result.m_type == ArrayType);

    auto arrayFunction = [](KeyedDecoder& decoder, String& result) {
        return decoder.decodeString("string", result);
    };

    return decoder.decodeObjects("array", result.m_array, arrayFunction);
}
Ejemplo n.º 5
0
static bool decodeElement(KeyedDecoder& decoder, FormDataElement& element)
{
    if (!decoder.decodeEnum("type", element.m_type, [](FormDataElement::Type type) {
        switch (type) {
        case FormDataElement::Type::Data:
        case FormDataElement::Type::EncodedFile:
        case FormDataElement::Type::EncodedBlob:
            return true;
        }

        return false;
    }))
        return false;

    switch (element.m_type) {
    case FormDataElement::Type::Data:
        if (!decoder.decodeBytes("data", element.m_data))
            return false;
        break;

    case FormDataElement::Type::EncodedFile: {
        if (!decoder.decodeString("filename", element.m_filename))
            return false;
        if (!decoder.decodeString("generatedFilename", element.m_generatedFilename))
            return false;
        if (!decoder.decodeBool("shouldGenerateFile", element.m_shouldGenerateFile))
            return false;

        int64_t fileStart;
        if (!decoder.decodeInt64("fileStart", fileStart))
            return false;
        if (fileStart < 0)
            return false;

        int64_t fileLength;
        if (!decoder.decodeInt64("fileLength", fileLength))
            return false;
        if (fileLength != BlobDataItem::toEndOfFile && fileLength < fileStart)
            return false;

        double expectedFileModificationTime;
        if (!decoder.decodeDouble("expectedFileModificationTime", expectedFileModificationTime))
            return false;

        element.m_fileStart = fileStart;
        element.m_fileLength = fileLength;
        element.m_expectedFileModificationTime = expectedFileModificationTime;
        break;
    }

    case FormDataElement::Type::EncodedBlob: {
        String blobURLString;
        if (!decoder.decodeString("url", blobURLString))
            return false;

        element.m_url = URL(URL(), blobURLString);
        break;
    }
    }

    return true;
}