CSSFontFaceSrcValue.cpp [plain text]
#include "config.h"
#include "CSSFontFaceSrcValue.h"
#include "CachedFont.h"
#include "CachedResourceLoader.h"
#include "CachedResourceRequest.h"
#include "CachedResourceRequestInitiators.h"
#include "Document.h"
#include "FontCustomPlatformData.h"
#include "Node.h"
#include "SVGFontFaceElement.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
bool CSSFontFaceSrcValue::isSVGFontFaceSrc() const
{
return equalLettersIgnoringASCIICase(m_format, "svg");
}
bool CSSFontFaceSrcValue::isSVGFontTarget() const
{
return isSVGFontFaceSrc() || svgFontFaceElement();
}
bool CSSFontFaceSrcValue::isSupportedFormat() const
{
if (m_format.isEmpty()) {
if (!protocolIs(m_resource, "data") && m_resource.endsWithIgnoringASCIICase(".eot"))
return false;
return true;
}
return FontCustomPlatformData::supportsFormat(m_format) || isSVGFontFaceSrc();
}
String CSSFontFaceSrcValue::customCSSText() const
{
const char* prefix = isLocal() ? "local(" : "url(";
if (m_format.isEmpty())
return makeString(prefix, m_resource, ')');
return makeString(prefix, m_resource, ')', " format(", m_format, ')');
}
bool CSSFontFaceSrcValue::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const
{
if (!m_cachedFont)
return false;
return handler(*m_cachedFont);
}
CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG, bool isInitiatingElementInUserAgentShadowTree)
{
if (m_cachedFont)
return m_cachedFont.get();
ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
options.contentSecurityPolicyImposition = isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
options.loadedFromOpaqueSource = m_loadedFromOpaqueSource;
CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)), options);
request.setInitiator(cachedResourceRequestInitiators().css);
m_cachedFont = document->cachedResourceLoader().requestFont(WTFMove(request), isSVG).value_or(nullptr);
return m_cachedFont.get();
}
bool CSSFontFaceSrcValue::equals(const CSSFontFaceSrcValue& other) const
{
return m_isLocal == other.m_isLocal && m_format == other.m_format && m_resource == other.m_resource;
}
}