Ejemplo n.º 1
0
void FileReaderLoader::didReceiveResponse(const ResourceResponse& response)
{
    if (response.httpStatusCode() != 200) {
        failed(httpStatusCodeToErrorCode(response.httpStatusCode()));
        return;
    }

    unsigned long long length = response.expectedContentLength();

    // Check that we can cast to unsigned since we have to do
    // so to call ArrayBuffer's create function.
    // FIXME: Support reading more than the current size limit of ArrayBuffer.
    if (length > numeric_limits<unsigned>::max()) {
        failed(FileError::NOT_READABLE_ERR);
        return;
    }

    ASSERT(!m_rawData);
    m_rawData = ArrayBuffer::create(static_cast<unsigned>(length), 1);

    if (!m_rawData) {
        failed(FileError::NOT_READABLE_ERR);
        return;
    }

    m_totalBytes = static_cast<unsigned>(length);

    if (m_client)
        m_client->didStartLoading();
}
Ejemplo n.º 2
0
void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
{
    ASSERT_UNUSED(handle, !handle);
    if (response.httpStatusCode() != 200) {
        failed(httpStatusCodeToErrorCode(response.httpStatusCode()));
        return;
    }

    // A negative value means that the content length wasn't specified.
    m_totalBytes = response.expectedContentLength();

    long long initialBufferLength = -1;

    if (m_totalBytes >= 0) {
        initialBufferLength = m_totalBytes;
    } else if (m_hasRange) {
        // Set m_totalBytes and allocate a buffer based on the specified range.
        m_totalBytes = 1LL + m_rangeEnd - m_rangeStart;
        initialBufferLength = m_totalBytes;
    } else {
        // Nothing is known about the size of the resource. Normalize
        // m_totalBytes to -1 and initialize the buffer for receiving with the
        // default size.
        m_totalBytes = -1;
    }

    ASSERT(!m_rawData);

    if (m_readType != ReadByClient) {
        // Check that we can cast to unsigned since we have to do
        // so to call ArrayBuffer's create function.
        // FIXME: Support reading more than the current size limit of ArrayBuffer.
        if (initialBufferLength > std::numeric_limits<unsigned>::max()) {
            failed(FileError::NOT_READABLE_ERR);
            return;
        }

        if (initialBufferLength < 0)
            m_rawData = adoptPtr(new ArrayBufferBuilder());
        else
            m_rawData = adoptPtr(new ArrayBufferBuilder(static_cast<unsigned>(initialBufferLength)));

        if (!m_rawData || !m_rawData->isValid()) {
            failed(FileError::NOT_READABLE_ERR);
            return;
        }

        if (initialBufferLength >= 0) {
            // Total size is known. Set m_rawData to ignore overflowed data.
            m_rawData->setVariableCapacity(false);
        }
    }

    if (m_client)
        m_client->didStartLoading();
}
Ejemplo n.º 3
0
void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse& response)
{
    if (response.httpStatusCode() != 200) {
        failed(httpStatusCodeToErrorCode(response.httpStatusCode()));
        return;
    }

    unsigned long long length = response.expectedContentLength();

    // A value larger than INT_MAX means that the content length wasn't
    // specified, so the buffer will need to be dynamically grown.
    if (length > INT_MAX) {
        m_variableLength = true;
        if (m_hasRange)
            length = 1 + m_rangeEnd - m_rangeStart;
        else
            length = defaultBufferLength;
    }

    // Check that we can cast to unsigned since we have to do
    // so to call ArrayBuffer's create function.
    // FIXME: Support reading more than the current size limit of ArrayBuffer.
    if (length > std::numeric_limits<unsigned>::max()) {
        failed(FileError::NOT_READABLE_ERR);
        return;
    }

    ASSERT(!m_rawData);
    m_rawData = ArrayBuffer::create(static_cast<unsigned>(length), 1);

    if (!m_rawData) {
        failed(FileError::NOT_READABLE_ERR);
        return;
    }

    m_totalBytes = static_cast<unsigned>(length);

    if (m_client)
        m_client->didStartLoading();
}