void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; if (!item->isLocal()) { const Settings* settings = document ? document->settings() : nullptr; bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled(); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { FontLoader* fontLoader = document->styleEngine().fontSelector()->fontLoader(); source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader)); } } } else { source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource())); } if (source) m_cssFontFace->addSource(source.release()); } }
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { FontLoader* fontLoader = document->styleEngine()->fontSelector()->fontLoader(); #if ENABLE(SVG_FONTS) if (foundSVGFont) { source = adoptPtrWillBeNoop(new SVGRemoteFontFaceSource(item->resource(), fetched, fontLoader)); } else #endif { source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader)); } } } } else { #if ENABLE(SVG_FONTS) if (item->svgFontFaceElement()) { RefPtrWillBeRawPtr<SVGFontFaceElement> fontfaceElement = item->svgFontFaceElement(); // SVGFontFaceSource assumes that it is the case where <font-face> element resides in the same document. // We put a RELEASE_ASSERT here as it will cause UAF if the assumption is false. RELEASE_ASSERT(fontfaceElement->inDocument()); RELEASE_ASSERT(fontfaceElement->document() == document); source = adoptPtrWillBeNoop(new SVGFontFaceSource(fontfaceElement.get())); } else #endif { source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource())); } } if (source) m_cssFontFace->addSource(source.release()); } }
PassRefPtr<CSSFontFace> FontFace::createCSSFontFace(Document* document) { RefPtr<CSSFontFace> cssFontFace = CSSFontFace::create(this); // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. CSSValueList* srcList = toCSSValueList(m_src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)); OwnPtr<CSSFontFaceSource> source; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { source = adoptPtr(new CSSFontFaceSource(item->resource(), fetched)); #if ENABLE(SVG_FONTS) if (foundSVGFont) source->setHasExternalSVGFont(true); #endif } } } else { source = adoptPtr(new CSSFontFaceSource(item->resource())); } if (source) { #if ENABLE(SVG_FONTS) source->setSVGFontFaceElement(item->svgFontFaceElement()); #endif cssFontFace->addSource(source.release()); } } if (CSSValueList* rangeList = toCSSValueList(m_unicodeRange.get())) { unsigned numRanges = rangeList->length(); for (unsigned i = 0; i < numRanges; i++) { CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->itemWithoutBoundsCheck(i)); cssFontFace->ranges().add(range->from(), range->to()); } } return cssFontFace; }
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)); OwnPtr<CSSFontFaceSource> source; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { #if ENABLE(SVG_FONTS) if (foundSVGFont) { source = adoptPtr(new SVGRemoteFontFaceSource(item->resource(), fetched)); } else #endif { source = adoptPtr(new RemoteFontFaceSource(fetched)); } } } } else { #if ENABLE(SVG_FONTS) if (item->svgFontFaceElement()) { source = adoptPtr(new SVGFontFaceSource(item->svgFontFaceElement())); } else #endif { source = adoptPtr(new LocalFontFaceSource(item->resource())); } } if (source) m_cssFontFace->addSource(source.release()); } }
void FontFace::initCSSFontFace(Document* document, CSSValue* src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src); int srcLength = srcList->length(); for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); CSSFontFaceSource* source = nullptr; if (!item->isLocal()) { const Settings* settings = document ? document->settings() : nullptr; bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled(); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { CSSFontSelector* fontSelector = document->styleEngine().fontSelector(); source = new RemoteFontFaceSource(fetched, fontSelector, CSSValueToFontDisplay(m_display.get())); } } } else { source = new LocalFontFaceSource(item->resource()); } if (source) m_cssFontFace->addSource(source); } if (m_display) { DEFINE_STATIC_LOCAL(EnumerationHistogram, fontDisplayHistogram, ("WebFont.FontDisplayValue", FontDisplayEnumMax)); fontDisplayHistogram.count(CSSValueToFontDisplay(m_display.get())); } }
void PageSerializer::retrieveResourcesForCSSValue(CSSValue* cssValue, Document* document) { if (cssValue->isImageValue()) { CSSImageValue* imageValue = toCSSImageValue(cssValue); StyleImage* styleImage = imageValue->cachedOrPendingImage(); // Non cached-images are just place-holders and do not contain data. if (!styleImage || !styleImage->isImageResource()) return; addImageToResources(styleImage->cachedImage(), 0, styleImage->cachedImage()->url()); } else if (cssValue->isFontFaceSrcValue()) { CSSFontFaceSrcValue* fontFaceSrcValue = toCSSFontFaceSrcValue(cssValue); if (fontFaceSrcValue->isLocal()) { return; } addFontToResources(fontFaceSrcValue->fetch(document)); } else if (cssValue->isValueList()) { CSSValueList* cssValueList = toCSSValueList(cssValue); for (unsigned i = 0; i < cssValueList->length(); i++) retrieveResourcesForCSSValue(cssValueList->item(i), document); } }