This source file includes following definitions.
- m_decoder
- setEncoding
- encoding
- mimeType
- script
- mimeTypeAllowedByNosniff
#include "config.h"
#include "core/fetch/ScriptResource.h"
#include "core/html/parser/TextResourceDecoder.h"
#include "platform/MIMETypeRegistry.h"
#include "platform/SharedBuffer.h"
#include "platform/network/HTTPParsers.h"
namespace WebCore {
ScriptResource::ScriptResource(const ResourceRequest& resourceRequest, const String& charset)
: Resource(resourceRequest, Script)
, m_decoder(TextResourceDecoder::create("application/javascript", charset))
{
DEFINE_STATIC_LOCAL(const AtomicString, acceptScript, ("*/*", AtomicString::ConstructFromLiteral));
setAccept(acceptScript);
}
ScriptResource::~ScriptResource()
{
}
void ScriptResource::setEncoding(const String& chs)
{
m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
}
String ScriptResource::encoding() const
{
return m_decoder->encoding().name();
}
AtomicString ScriptResource::mimeType() const
{
return extractMIMETypeFromMediaType(m_response.httpHeaderField("Content-Type")).lower();
}
const String& ScriptResource::script()
{
ASSERT(!isPurgeable());
ASSERT(isLoaded());
if (!m_script && m_data) {
String script = m_decoder->decode(m_data->data(), encodedSize());
script = script + m_decoder->flush();
m_data.clear();
setEncodedSize(script.sizeInBytes());
m_script = AtomicString(script);
}
return m_script.string();
}
bool ScriptResource::mimeTypeAllowedByNosniff() const
{
return parseContentTypeOptionsHeader(m_response.httpHeaderField("X-Content-Type-Options")) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
}
}