This source file includes following definitions.
- canReferToParentFrameEncoding
- m_encodingWasChosenByUser
- createDecoderInstance
- setupEncoding
- buildFor
- clear
#include "config.h"
#include "core/loader/TextResourceDecoderBuilder.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "platform/weborigin/SecurityOrigin.h"
namespace WebCore {
static inline bool canReferToParentFrameEncoding(const LocalFrame* frame, const LocalFrame* parentFrame)
{
return parentFrame && parentFrame->document()->securityOrigin()->canAccess(frame->document()->securityOrigin());
}
TextResourceDecoderBuilder::TextResourceDecoderBuilder(const AtomicString& mimeType, const AtomicString& encoding, bool encodingUserChoosen)
: m_mimeType(mimeType)
, m_encoding(encoding)
, m_encodingWasChosenByUser(encodingUserChoosen)
{
}
TextResourceDecoderBuilder::~TextResourceDecoderBuilder()
{
}
inline PassOwnPtr<TextResourceDecoder> TextResourceDecoderBuilder::createDecoderInstance(Document* document)
{
if (LocalFrame* frame = document->frame()) {
if (Settings* settings = frame->settings())
return TextResourceDecoder::create(m_mimeType, settings->defaultTextEncodingName(), settings->usesEncodingDetector());
}
return TextResourceDecoder::create(m_mimeType, String());
}
inline void TextResourceDecoderBuilder::setupEncoding(TextResourceDecoder* decoder, Document* document)
{
LocalFrame* frame = document->frame();
LocalFrame* parentFrame = frame ? frame->tree().parent() : 0;
if (!m_encoding.isEmpty())
decoder->setEncoding(m_encoding.string(), m_encodingWasChosenByUser ? TextResourceDecoder::UserChosenEncoding : TextResourceDecoder::EncodingFromHTTPHeader);
if (frame && canReferToParentFrameEncoding(frame, parentFrame)) {
if (parentFrame->document()->encodingWasDetectedHeuristically())
decoder->setHintEncoding(parentFrame->document()->encoding());
if (m_encoding.isEmpty())
decoder->setEncoding(parentFrame->document()->inputEncoding().string(), TextResourceDecoder::EncodingFromParentFrame);
}
}
PassOwnPtr<TextResourceDecoder> TextResourceDecoderBuilder::buildFor(Document* document)
{
OwnPtr<TextResourceDecoder> decoder = createDecoderInstance(document);
setupEncoding(decoder.get(), document);
return decoder.release();
}
void TextResourceDecoderBuilder::clear()
{
if (!m_encodingWasChosenByUser)
m_encoding = nullAtom;
}
}