diff options
Diffstat (limited to 'Source/WebCore/svg/SVGFEImageElement.cpp')
-rw-r--r-- | Source/WebCore/svg/SVGFEImageElement.cpp | 105 |
1 files changed, 41 insertions, 64 deletions
diff --git a/Source/WebCore/svg/SVGFEImageElement.cpp b/Source/WebCore/svg/SVGFEImageElement.cpp index 2078fe5a7..19ef63b29 100644 --- a/Source/WebCore/svg/SVGFEImageElement.cpp +++ b/Source/WebCore/svg/SVGFEImageElement.cpp @@ -20,22 +20,17 @@ */ #include "config.h" - -#if ENABLE(SVG) && ENABLE(FILTERS) #include "SVGFEImageElement.h" -#include "Attr.h" #include "CachedImage.h" #include "CachedResourceLoader.h" #include "CachedResourceRequest.h" -#include "ColorSpace.h" #include "Document.h" #include "Image.h" #include "RenderObject.h" #include "RenderSVGResource.h" -#include "SVGElementInstance.h" #include "SVGNames.h" -#include "SVGPreserveAspectRatio.h" +#include "SVGPreserveAspectRatioValue.h" #include "XLinkNames.h" namespace WebCore { @@ -59,9 +54,9 @@ inline SVGFEImageElement::SVGFEImageElement(const QualifiedName& tagName, Docume registerAnimatedPropertiesForSVGFEImageElement(); } -PassRefPtr<SVGFEImageElement> SVGFEImageElement::create(const QualifiedName& tagName, Document& document) +Ref<SVGFEImageElement> SVGFEImageElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new SVGFEImageElement(tagName, document)); + return adoptRef(*new SVGFEImageElement(tagName, document)); } SVGFEImageElement::~SVGFEImageElement() @@ -69,30 +64,41 @@ SVGFEImageElement::~SVGFEImageElement() clearResourceReferences(); } +bool SVGFEImageElement::hasSingleSecurityOrigin() const +{ + if (!m_cachedImage) + return true; + auto* image = m_cachedImage->image(); + return !image || image->hasSingleSecurityOrigin(); +} + void SVGFEImageElement::clearResourceReferences() { if (m_cachedImage) { - m_cachedImage->removeClient(this); - m_cachedImage = 0; + m_cachedImage->removeClient(*this); + m_cachedImage = nullptr; } - document().accessSVGExtensions()->removeAllTargetReferencesForElement(this); + document().accessSVGExtensions().removeAllTargetReferencesForElement(this); } void SVGFEImageElement::requestImageResource() { - CachedResourceRequest request(ResourceRequest(document().completeURL(href()))); - request.setInitiator(this); - m_cachedImage = document().cachedResourceLoader()->requestImage(request); + ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); + options.contentSecurityPolicyImposition = isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck; + + CachedResourceRequest request(ResourceRequest(document().completeURL(href())), options); + request.setInitiator(*this); + m_cachedImage = document().cachedResourceLoader().requestImage(WTFMove(request)); if (m_cachedImage) - m_cachedImage->addClient(this); + m_cachedImage->addClient(*this); } void SVGFEImageElement::buildPendingResource() { clearResourceReferences(); - if (!inDocument()) + if (!isConnected()) return; String id; @@ -101,102 +107,75 @@ void SVGFEImageElement::buildPendingResource() if (id.isEmpty()) requestImageResource(); else { - document().accessSVGExtensions()->addPendingResource(id, this); + document().accessSVGExtensions().addPendingResource(id, this); ASSERT(hasPendingResources()); } } else if (target->isSVGElement()) { // Register us with the target in the dependencies map. Any change of hrefElement // that leads to relayout/repainting now informs us, so we can react to it. - document().accessSVGExtensions()->addElementReferencingTarget(this, toSVGElement(target)); + document().accessSVGExtensions().addElementReferencingTarget(this, downcast<SVGElement>(target)); } invalidate(); } -bool SVGFEImageElement::isSupportedAttribute(const QualifiedName& attrName) -{ - DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); - if (supportedAttributes.isEmpty()) { - SVGURIReference::addSupportedAttributes(supportedAttributes); - SVGLangSpace::addSupportedAttributes(supportedAttributes); - SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); - supportedAttributes.add(SVGNames::preserveAspectRatioAttr); - } - return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); -} - void SVGFEImageElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { - if (!isSupportedAttribute(name)) { - SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); - return; - } - if (name == SVGNames::preserveAspectRatioAttr) { - SVGPreserveAspectRatio preserveAspectRatio; + SVGPreserveAspectRatioValue preserveAspectRatio; preserveAspectRatio.parse(value); setPreserveAspectRatioBaseValue(preserveAspectRatio); return; } - if (SVGURIReference::parseAttribute(name, value)) - return; - if (SVGLangSpace::parseAttribute(name, value)) - return; - if (SVGExternalResourcesRequired::parseAttribute(name, value)) - return; - - ASSERT_NOT_REACHED(); + SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); + SVGURIReference::parseAttribute(name, value); + SVGExternalResourcesRequired::parseAttribute(name, value); } void SVGFEImageElement::svgAttributeChanged(const QualifiedName& attrName) { - if (!isSupportedAttribute(attrName)) { - SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); - return; - } - - SVGElementInstance::InvalidationGuard invalidationGuard(this); - if (attrName == SVGNames::preserveAspectRatioAttr) { + InstanceInvalidationGuard guard(*this); invalidate(); return; } if (SVGURIReference::isKnownAttribute(attrName)) { + InstanceInvalidationGuard guard(*this); buildPendingResource(); return; } - if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) - return; - - ASSERT_NOT_REACHED(); + SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); } Node::InsertionNotificationRequest SVGFEImageElement::insertedInto(ContainerNode& rootParent) { SVGFilterPrimitiveStandardAttributes::insertedInto(rootParent); + return InsertionShouldCallFinishedInsertingSubtree; +} + +void SVGFEImageElement::finishedInsertingSubtree() +{ buildPendingResource(); - return InsertionDone; } void SVGFEImageElement::removedFrom(ContainerNode& rootParent) { SVGFilterPrimitiveStandardAttributes::removedFrom(rootParent); - if (rootParent.inDocument()) + if (rootParent.isConnected()) clearResourceReferences(); } -void SVGFEImageElement::notifyFinished(CachedResource*) +void SVGFEImageElement::notifyFinished(CachedResource&) { - if (!inDocument()) + if (!isConnected()) return; Element* parent = parentElement(); - ASSERT(parent); - if (!parent->hasTagName(SVGNames::filterTag)) + if (!parent || !parent->hasTagName(SVGNames::filterTag)) return; RenderElement* parentRenderer = parent->renderer(); @@ -206,7 +185,7 @@ void SVGFEImageElement::notifyFinished(CachedResource*) RenderSVGResource::markForLayoutAndParentResourceInvalidation(*parentRenderer); } -PassRefPtr<FilterEffect> SVGFEImageElement::build(SVGFilterBuilder*, Filter* filter) +RefPtr<FilterEffect> SVGFEImageElement::build(SVGFilterBuilder*, Filter& filter) { if (m_cachedImage) return FEImage::createWithImage(filter, m_cachedImage->imageForRenderer(renderer()), preserveAspectRatio()); @@ -221,5 +200,3 @@ void SVGFEImageElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) cons } } - -#endif // ENABLE(SVG) |