This source file includes following definitions.
- m_decoder
- setEncoding
- encoding
- checkNotify
- createDocument
#include "config.h"
#include "core/fetch/DocumentResource.h"
#include "platform/SharedBuffer.h"
#include "core/svg/SVGDocument.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
DocumentResource::DocumentResource(const ResourceRequest& request, Type type)
: Resource(request, type)
, m_decoder(TextResourceDecoder::create("application/xml"))
{
ASSERT(type == SVGDocument);
}
DocumentResource::~DocumentResource()
{
}
void DocumentResource::setEncoding(const String& chs)
{
m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
}
String DocumentResource::encoding() const
{
return m_decoder->encoding().name();
}
void DocumentResource::checkNotify()
{
if (m_data) {
StringBuilder decodedText;
decodedText.append(m_decoder->decode(m_data->data(), m_data->size()));
decodedText.append(m_decoder->flush());
m_document = createDocument(response().url());
m_document->setContent(decodedText.toString());
}
Resource::checkNotify();
}
PassRefPtr<Document> DocumentResource::createDocument(const KURL& url)
{
switch (type()) {
case SVGDocument:
return SVGDocument::create(DocumentInit(url));
default:
ASSERT_NOT_REACHED();
return nullptr;
}
}
}