Commit 1fb4dd0e authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Update <use>'s target reference when adopting to a new document

When the <use> element moves to a new document, it's both possible that
the base URL changes and that the transition is from an inactive to an
active document. In the latter case we need to re-resolve the URL and
potentially attempt to fetch any external resource again.

Do this by calling UpdateTargetReference() in a DidMoveToNewDocument()
override. Also add a check for being in an inactive document to avoid
the unnecessary work in that case, as well as clearing out the resource
reference if the move is from an active to an inactive document.

Fixed: 1070076
Change-Id: Ibfcbe5a590d2115eece0d68ed1c03db49ef5f708
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149415Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#759169}
parent 2f209b9f
......@@ -133,6 +133,11 @@ void SVGUseElement::RemovedFrom(ContainerNode& root_parent) {
}
}
void SVGUseElement::DidMoveToNewDocument(Document& old_document) {
SVGGraphicsElement::DidMoveToNewDocument(old_document);
UpdateTargetReference();
}
static void TransferUseWidthAndHeightIfNeeded(
const SVGUseElement& use,
SVGElement& shadow_element,
......@@ -190,7 +195,7 @@ void SVGUseElement::UpdateTargetReference() {
const String& url_string = HrefString();
element_url_ = GetDocument().CompleteURL(url_string);
element_url_is_local_ = url_string.StartsWith('#');
if (!IsStructurallyExternal()) {
if (!IsStructurallyExternal() || !GetDocument().IsActive()) {
ClearResource();
return;
}
......
......@@ -78,6 +78,7 @@ class SVGUseElement final : public SVGGraphicsElement,
InsertionNotificationRequest InsertedInto(ContainerNode&) override;
void RemovedFrom(ContainerNode&) override;
void DidMoveToNewDocument(Document&) override;
void SvgAttributeChanged(const QualifiedName&) override;
......
<svg xmlns="http://www.w3.org/2000/svg">
<rect id="green-rect" width="100" height="100" fill="green"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml">
<title>Adopting a &#x3c;use&#x3e; (from an inactive document) requests an external resource</title>
<h:link rel="match" href="reference/green-100x100.svg"/>
<script type="text/plain" template=""><![CDATA[
<svg xmlns="http://www.w3.org/2000/svg">
<use href="support/sprites.svg#green-rect"/>
</svg>]]>
</script>
<script>
let text = document.querySelector('script[template]').textContent;
let doc = new DOMParser().parseFromString(text, 'image/svg+xml');
document.documentElement.appendChild(doc.documentElement);
</script>
</svg>
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