示例#1
0
static LayoutRect getShapeImageReplacedRect(const RenderBox& renderBox, const StyleImage& styleImage)
{
    if (renderBox.isRenderImage()) {
        const RenderImage& renderImage = *toRenderImage(&renderBox);
        return renderImage.replacedContentRect(renderBox.intrinsicSize());
    }

    ASSERT(styleImage.cachedImage());
    ASSERT(styleImage.cachedImage()->hasImage());
    return LayoutRect(LayoutPoint(), styleImage.cachedImage()->image()->size());
}
示例#2
0
static ImageResourceContent* cachedImageForCSSValue(CSSValue* value,
                                                    const Document& document) {
  if (!value)
    return nullptr;

  if (value->isImageValue()) {
    StyleImage* styleImageResource =
        toCSSImageValue(value)->cacheImage(document);
    if (!styleImageResource)
      return nullptr;

    return styleImageResource->cachedImage();
  }

  if (value->isImageGeneratorValue()) {
    toCSSImageGeneratorValue(value)->loadSubimages(document);
    // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradients
    // and canvas).
    return nullptr;
  }

  ASSERT_NOT_REACHED();

  return nullptr;
}
static bool checkShapeImageOrigin(Document& document, const StyleImage& styleImage)
{
    if (styleImage.isGeneratedImage())
        return true;

    ASSERT(styleImage.cachedImage());
    ImageResource& imageResource = *(styleImage.cachedImage());
    if (imageResource.isAccessAllowed(document.securityOrigin()))
        return true;

    const KURL& url = imageResource.url();
    String urlString = url.isNull() ? "''" : url.elidedString();
    document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Unsafe attempt to load URL " + urlString + ".");

    return false;
}
示例#4
0
static inline bool checkShapeImageOrigin(Document& document, const StyleImage& styleImage)
{
    if (styleImage.isGeneratedImage())
        return true;

    ASSERT(styleImage.cachedImage());
    CachedImage& cachedImage = *(styleImage.cachedImage());
    if (cachedImage.isOriginClean(document.securityOrigin()))
        return true;

    const URL& url = cachedImage.url();
    String urlString = url.isNull() ? "''" : url.stringCenterEllipsizedToLength();
    document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Unsafe attempt to load URL " + urlString + ".");

    return false;
}
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);
    }
}
示例#6
0
static void getShapeImageAndRect(const ShapeValue& shapeValue, const RenderBox& renderBox, const LayoutSize& referenceBoxSize, Image*& image, LayoutRect& rect)
{
    ASSERT(shapeValue.isImageValid());
    StyleImage* styleImage = shapeValue.image();

    const LayoutSize& imageSize = renderBox.calculateImageIntrinsicDimensions(styleImage, roundedIntSize(referenceBoxSize), RenderImage::ScaleByEffectiveZoom);
    styleImage->setContainerSizeForRenderer(&renderBox, imageSize, renderBox.style().effectiveZoom());

    image = nullptr;
    if (styleImage->isCachedImage() || styleImage->isCachedImageSet())
        image = styleImage->cachedImage()->imageForRenderer(&renderBox);
    else if (styleImage->isGeneratedImage())
        image = styleImage->image(const_cast<RenderBox*>(&renderBox), imageSize).get();

    if (renderBox.isRenderImage())
        rect = toRenderImage(&renderBox)->replacedContentRect(renderBox.intrinsicSize());
    else
        rect = LayoutRect(LayoutPoint(), imageSize);
}