Example #1
0
void Body::didFinishLoading()
{
    if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
        return;

    switch (m_responseType) {
    case ResponseAsArrayBuffer:
        m_resolver->resolve(DOMArrayBuffer::create(m_loader->arrayBufferResult()));
        break;
    case ResponseAsBlob: {
        ASSERT(blobDataHandle()->size() == kuint64max);
        OwnPtr<BlobData> blobData = BlobData::create();
        RefPtr<ArrayBuffer> buffer = m_loader->arrayBufferResult();
        blobData->appendArrayBuffer(buffer.get());
        const size_t length = blobData->length();
        m_resolver->resolve(Blob::create(BlobDataHandle::create(blobData.release(), length)));
        break;
    }
    case ResponseAsFormData:
        ASSERT_NOT_REACHED();
        break;
    case ResponseAsJSON:
        resolveJSON();
        break;
    case ResponseAsText:
        m_resolver->resolve(m_loader->stringResult());
        break;
    default:
        ASSERT_NOT_REACHED();
    }
    m_resolver.clear();
}
Example #2
0
void Body::didFinishLoadingViaStream(DOMArrayBuffer* buffer)
{
    if (!m_bodyUsed) {
        // |m_stream| is pulling.
        ASSERT(m_streamAccessed);
        m_stream->enqueue(buffer);
        return;
    }

    switch (m_responseType) {
    case ResponseAsArrayBuffer:
        m_resolver->resolve(buffer);
        break;
    case ResponseAsBlob: {
        OwnPtr<BlobData> blobData = BlobData::create();
        blobData->appendBytes(buffer->data(), buffer->byteLength());
        m_resolver->resolve(Blob::create(BlobDataHandle::create(blobData.release(), blobData->length())));
        break;
    }
    case ResponseAsFormData:
        ASSERT_NOT_REACHED();
        break;
    case ResponseAsJSON: {
        String s = String::fromUTF8(static_cast<const char*>(buffer->data()), buffer->byteLength());
        if (s.isNull())
            m_resolver->reject(DOMException::create(NetworkError, "Invalid utf-8 string"));
        else
            resolveJSON(s);
        break;
    }
    case ResponseAsText: {
        String s = String::fromUTF8(static_cast<const char*>(buffer->data()), buffer->byteLength());
        if (s.isNull())
            m_resolver->reject(DOMException::create(NetworkError, "Invalid utf-8 string"));
        else
            m_resolver->resolve(s);
        break;
    }
    default:
        ASSERT_NOT_REACHED();
    }
}