Commit 32a58c7e authored by fs's avatar fs Committed by Commit bot

Use IdTargetObserver in SVGFEImageElement

Change SVGFEImageElement to use the observeTarget() helper from
SVGURIReference.
A slight change in behavior for when a load is initiated for a potential
image resource is made. Instead of using a "failed element lookup and a
non-existing id" as the condition, use "failed element lookup and non-
local resource reference".
Also add a new method clearImageResource() and put the tear-down for
the image resource, and change a use of ownerDocument() to just
document().

BUG=661598

Review-Url: https://codereview.chromium.org/2740003003
Cr-Commit-Position: refs/heads/master@{#455765}
parent ce79930d
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
#include "core/svg/SVGFEImageElement.h" #include "core/svg/SVGFEImageElement.h"
#include "core/SVGNames.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/dom/IdTargetObserver.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/svg/SVGPreserveAspectRatio.h" #include "core/svg/SVGPreserveAspectRatio.h"
#include "core/svg/SVGTreeScopeResources.h"
#include "core/svg/graphics/filters/SVGFEImage.h" #include "core/svg/graphics/filters/SVGFEImage.h"
#include "platform/graphics/Image.h" #include "platform/graphics/Image.h"
#include "platform/loader/fetch/FetchRequest.h" #include "platform/loader/fetch/FetchRequest.h"
...@@ -43,15 +45,13 @@ inline SVGFEImageElement::SVGFEImageElement(Document& document) ...@@ -43,15 +45,13 @@ inline SVGFEImageElement::SVGFEImageElement(Document& document)
DEFINE_NODE_FACTORY(SVGFEImageElement) DEFINE_NODE_FACTORY(SVGFEImageElement)
SVGFEImageElement::~SVGFEImageElement() { SVGFEImageElement::~SVGFEImageElement() {
if (m_cachedImage) { clearImageResource();
m_cachedImage->removeObserver(this);
m_cachedImage = nullptr;
}
} }
DEFINE_TRACE(SVGFEImageElement) { DEFINE_TRACE(SVGFEImageElement) {
visitor->trace(m_preserveAspectRatio); visitor->trace(m_preserveAspectRatio);
visitor->trace(m_cachedImage); visitor->trace(m_cachedImage);
visitor->trace(m_targetIdObserver);
SVGFilterPrimitiveStandardAttributes::trace(visitor); SVGFilterPrimitiveStandardAttributes::trace(visitor);
SVGURIReference::trace(visitor); SVGURIReference::trace(visitor);
} }
...@@ -64,38 +64,36 @@ bool SVGFEImageElement::currentFrameHasSingleSecurityOrigin() const { ...@@ -64,38 +64,36 @@ bool SVGFEImageElement::currentFrameHasSingleSecurityOrigin() const {
} }
void SVGFEImageElement::clearResourceReferences() { void SVGFEImageElement::clearResourceReferences() {
if (m_cachedImage) { clearImageResource();
m_cachedImage->removeObserver(this); unobserveTarget(m_targetIdObserver);
m_cachedImage = nullptr;
}
removeAllOutgoingReferences(); removeAllOutgoingReferences();
} }
void SVGFEImageElement::fetchImageResource() { void SVGFEImageElement::fetchImageResource() {
FetchRequest request( FetchRequest request(ResourceRequest(document().completeURL(hrefString())),
ResourceRequest(ownerDocument()->completeURL(hrefString())), localName()); localName());
m_cachedImage = ImageResourceContent::fetch(request, document().fetcher()); m_cachedImage = ImageResourceContent::fetch(request, document().fetcher());
if (m_cachedImage) if (m_cachedImage)
m_cachedImage->addObserver(this); m_cachedImage->addObserver(this);
} }
void SVGFEImageElement::clearImageResource() {
if (!m_cachedImage)
return;
m_cachedImage->removeObserver(this);
m_cachedImage = nullptr;
}
void SVGFEImageElement::buildPendingResource() { void SVGFEImageElement::buildPendingResource() {
clearResourceReferences(); clearResourceReferences();
if (!isConnected()) if (!isConnected())
return; return;
AtomicString id; Element* target = observeTarget(m_targetIdObserver, *this);
Element* target = SVGURIReference::targetElementFromIRIString(
hrefString(), treeScope(), &id);
if (!target) { if (!target) {
if (id.isEmpty()) { if (!SVGURLReferenceResolver(hrefString(), document()).isLocal())
fetchImageResource(); fetchImageResource();
} else {
treeScope().ensureSVGTreeScopedResources().addPendingResource(id, *this);
DCHECK(hasPendingResources());
}
} else if (target->isSVGElement()) { } else if (target->isSVGElement()) {
// Register us with the target in the dependencies map. Any change of // Register us with the target in the dependencies map. Any change of
// hrefElement that leads to relayout/repainting now informs us, so we can // hrefElement that leads to relayout/repainting now informs us, so we can
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#ifndef SVGFEImageElement_h #ifndef SVGFEImageElement_h
#define SVGFEImageElement_h #define SVGFEImageElement_h
#include "core/SVGNames.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "core/loader/resource/ImageResourceObserver.h" #include "core/loader/resource/ImageResourceObserver.h"
#include "core/svg/SVGAnimatedPreserveAspectRatio.h" #include "core/svg/SVGAnimatedPreserveAspectRatio.h"
#include "core/svg/SVGFilterPrimitiveStandardAttributes.h" #include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
...@@ -31,6 +29,8 @@ ...@@ -31,6 +29,8 @@
namespace blink { namespace blink {
class ImageResourceContent;
class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes, class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
public SVGURIReference, public SVGURIReference,
public ImageResourceObserver { public ImageResourceObserver {
...@@ -62,6 +62,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes, ...@@ -62,6 +62,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
void clearResourceReferences(); void clearResourceReferences();
void fetchImageResource(); void fetchImageResource();
void clearImageResource();
void buildPendingResource() override; void buildPendingResource() override;
InsertionNotificationRequest insertedInto(ContainerNode*) override; InsertionNotificationRequest insertedInto(ContainerNode*) override;
...@@ -70,6 +71,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes, ...@@ -70,6 +71,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes,
Member<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio; Member<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
Member<ImageResourceContent> m_cachedImage; Member<ImageResourceContent> m_cachedImage;
Member<IdTargetObserver> m_targetIdObserver;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment