Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 637f9ed

Browse files
committed
Bug 1474311 - check whether we should load images r=jwatt
Differential Revision: https://phabricator.services.mozilla.com/D93096
1 parent 0ea5139 commit 637f9ed

6 files changed

Lines changed: 72 additions & 8 deletions

File tree

dom/svg/SVGFEImageElement.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ nsresult SVGFEImageElement::LoadSVGImage(bool aForce, bool aNotify) {
8787
return LoadImage(href, aForce, aNotify, eImageLoadType_Normal);
8888
}
8989

90+
bool SVGFEImageElement::ShouldLoadImage() const {
91+
return LoadingEnabled() && OwnerDoc()->ShouldLoadImages();
92+
}
93+
9094
//----------------------------------------------------------------------
9195
// EventTarget methods:
9296

@@ -113,7 +117,9 @@ nsresult SVGFEImageElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
113117
if (aName == nsGkAtoms::href && (aNamespaceID == kNameSpaceID_XLink ||
114118
aNamespaceID == kNameSpaceID_None)) {
115119
if (aValue) {
116-
LoadSVGImage(true, aNotify);
120+
if (ShouldLoadImage()) {
121+
LoadSVGImage(true, aNotify);
122+
}
117123
} else {
118124
CancelImageRequests(aNotify);
119125
}
@@ -138,8 +144,9 @@ nsresult SVGFEImageElement::BindToTree(BindContext& aContext,
138144

139145
nsImageLoadingContent::BindToTree(aContext, aParent);
140146

141-
if (mStringAttributes[HREF].IsExplicitlySet() ||
142-
mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
147+
if ((mStringAttributes[HREF].IsExplicitlySet() ||
148+
mStringAttributes[XLINK_HREF].IsExplicitlySet()) &&
149+
ShouldLoadImage()) {
143150
nsContentUtils::AddScriptRunner(
144151
NewRunnableMethod("dom::SVGFEImageElement::MaybeLoadSVGImage", this,
145152
&SVGFEImageElement::MaybeLoadSVGImage));

dom/svg/SVGFEImageElement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ class SVGFEImageElement final : public SVGFEImageElementBase,
7070
virtual EventStates IntrinsicState() const override;
7171
virtual void DestroyContent() override;
7272

73-
void Notify(imgIRequest* aRequest, int32_t aType,
74-
const nsIntRect* aData) override;
73+
NS_DECL_IMGINOTIFICATIONOBSERVER
7574

7675
// Override for nsIImageLoadingContent.
7776
NS_IMETHOD_(void) FrameCreated(nsIFrame* aFrame) override;
@@ -84,6 +83,7 @@ class SVGFEImageElement final : public SVGFEImageElementBase,
8483

8584
private:
8685
nsresult LoadSVGImage(bool aForce, bool aNotify);
86+
bool ShouldLoadImage() const;
8787

8888
protected:
8989
virtual bool ProducesSRGB() override { return true; }

dom/svg/SVGImageElement.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ nsresult SVGImageElement::LoadSVGImage(bool aForce, bool aNotify) {
147147
return LoadImage(href, aForce, aNotify, eImageLoadType_Normal);
148148
}
149149

150+
bool SVGImageElement::ShouldLoadImage() const {
151+
return LoadingEnabled() && OwnerDoc()->ShouldLoadImages();
152+
}
153+
150154
//----------------------------------------------------------------------
151155
// EventTarget methods:
152156

@@ -180,7 +184,9 @@ nsresult SVGImageElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
180184
if (aName == nsGkAtoms::href && (aNamespaceID == kNameSpaceID_None ||
181185
aNamespaceID == kNameSpaceID_XLink)) {
182186
if (aValue) {
183-
LoadSVGImage(true, aNotify);
187+
if (ShouldLoadImage()) {
188+
LoadSVGImage(true, aNotify);
189+
}
184190
} else {
185191
CancelImageRequests(aNotify);
186192
}
@@ -209,8 +215,9 @@ nsresult SVGImageElement::BindToTree(BindContext& aContext, nsINode& aParent) {
209215

210216
nsImageLoadingContent::BindToTree(aContext, aParent);
211217

212-
if (mStringAttributes[HREF].IsExplicitlySet() ||
213-
mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
218+
if ((mStringAttributes[HREF].IsExplicitlySet() ||
219+
mStringAttributes[XLINK_HREF].IsExplicitlySet()) &&
220+
ShouldLoadImage()) {
214221
nsContentUtils::AddScriptRunner(
215222
NewRunnableMethod("dom::SVGImageElement::MaybeLoadSVGImage", this,
216223
&SVGImageElement::MaybeLoadSVGImage));

dom/svg/SVGImageElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class SVGImageElement : public SVGImageElementBase,
104104

105105
protected:
106106
nsresult LoadSVGImage(bool aForce, bool aNotify);
107+
bool ShouldLoadImage() const;
107108

108109
virtual LengthAttributesInfo GetLengthInfo() override;
109110
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()

dom/svg/test/mochitest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ skip-if = true # disabled-for-intermittent-failures--bug-701060
5858
[test_object-delayed-intrinsic-size.html]
5959
[test_onerror.xhtml]
6060
[test_onload.xhtml]
61+
[test_onload2.xhtml]
6162
[test_pairParsing.html]
6263
[test_pathAnimInterpolation.xhtml]
6364
skip-if = true # We need to polyfill the SVG DOM for path data

dom/svg/test/test_onload2.xhtml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<html xmlns="http://www.w3.org/1999/xhtml">
2+
<!--
3+
https://bugzilla.mozilla.org/show_bug.cgi?id=1474311
4+
-->
5+
<head>
6+
<title>Test onload behaviour</title>
7+
<script src="/tests/SimpleTest/SimpleTest.js"></script>
8+
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
9+
</head>
10+
<body>
11+
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1474311">Mozilla Bug 1474311</a>
12+
<p id="display"></p>
13+
<script class="testbody" type="text/javascript">
14+
<![CDATA[
15+
16+
SimpleTest.waitForExplicitFinish();
17+
18+
function run() {
19+
20+
let doc = document.implementation.createHTMLDocument('');
21+
22+
doc.body.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image id="image" xlink:href="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" height="200" width="200"/></svg>';
23+
24+
let img = doc.body.firstChild.firstChild;
25+
26+
document.getElementById('svg').appendChild(img);
27+
28+
img.addEventListener('load', function () {
29+
ok(true, "onload method called");
30+
SimpleTest.finish();
31+
});
32+
33+
img.addEventListener('error', function () {
34+
ok(false, "onerror method called");
35+
});
36+
}
37+
38+
]]>
39+
</script>
40+
<div id="content">
41+
42+
<svg id="svg" onload="run()" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="1">
43+
</svg>
44+
</div>
45+
<pre id="test">
46+
</pre>
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)