This source file includes following definitions.
- create
- m_parser
- appendReplacingData
- addData
- end
- setUserChosenEncoding
- setDocumentWasLoadedAsPartOfNavigation
#include "config.h"
#include "core/loader/DocumentWriter.h"
#include "core/dom/Document.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/html/parser/TextResourceDecoder.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderStateMachine.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
PassRefPtr<DocumentWriter> DocumentWriter::create(Document* document, const AtomicString& mimeType, const AtomicString& encoding, bool encodingUserChoosen)
{
return adoptRef(new DocumentWriter(document, mimeType, encoding, encodingUserChoosen));
}
DocumentWriter::DocumentWriter(Document* document, const AtomicString& mimeType, const AtomicString& encoding, bool encodingUserChoosen)
: m_document(document)
, m_decoderBuilder(mimeType, encoding, encodingUserChoosen)
, m_parser(m_document->implicitOpen())
{
if (m_document->frame()) {
if (FrameView* view = m_document->frame()->view())
view->setContentsSize(IntSize());
}
}
DocumentWriter::~DocumentWriter()
{
}
void DocumentWriter::appendReplacingData(const String& source)
{
m_document->setCompatibilityMode(Document::NoQuirksMode);
if (DocumentParser* parser = m_document->parser()) {
parser->pinToMainThread();
parser->append(source.impl());
}
}
void DocumentWriter::addData(const char* bytes, size_t length)
{
ASSERT(m_parser);
if (m_parser->needsDecoder() && 0 < length) {
OwnPtr<TextResourceDecoder> decoder = m_decoderBuilder.buildFor(m_document);
m_parser->setDecoder(decoder.release());
}
RefPtr<DocumentWriter> protectingThis(this);
m_parser->appendBytes(bytes, length);
}
void DocumentWriter::end()
{
ASSERT(m_document);
RefPtr<LocalFrame> protector(m_document->frame());
if (!m_parser)
return;
if (m_parser->needsDecoder()) {
OwnPtr<TextResourceDecoder> decoder = m_decoderBuilder.buildFor(m_document);
m_parser->setDecoder(decoder.release());
}
RefPtr<DocumentWriter> protectingThis(this);
m_parser->flush();
if (!m_parser)
return;
m_parser->finish();
m_parser = nullptr;
m_document = 0;
}
void DocumentWriter::setUserChosenEncoding(const String& charset)
{
TextResourceDecoder* decoder = m_parser->decoder();
if (decoder)
decoder->setEncoding(charset, TextResourceDecoder::UserChosenEncoding);
}
void DocumentWriter::setDocumentWasLoadedAsPartOfNavigation()
{
ASSERT(m_parser && !m_parser->isStopped());
m_parser->setDocumentWasLoadedAsPartOfNavigation();
}
}