mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 696451 - Reload <img> when crossOrigin attribute is set. r=bz
This commit is contained in:
parent
9e68ff11c1
commit
a354e85de9
@ -318,6 +318,49 @@ HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
nsDependentAtomString(aValue->GetAtomValue()));
|
||||
}
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None &&
|
||||
aName == nsGkAtoms::src &&
|
||||
!aValue) {
|
||||
CancelImageRequests(aNotify);
|
||||
}
|
||||
|
||||
// If we plan to call LoadImage, we want to do it first so that the image load
|
||||
// kicks off. But if aNotify is false, we are coming from the parser or some
|
||||
// such place; we'll get bound after all the attributes have been set, so
|
||||
// we'll do the image load from BindToTree. Skip the LoadImage call in that case.
|
||||
if (aNotify &&
|
||||
aNameSpaceID == kNameSpaceID_None &&
|
||||
aName == nsGkAtoms::crossorigin) {
|
||||
// We want aForce == true in this LoadImage call, because we want to force
|
||||
// a new load of the image with the new cross origin policy.
|
||||
nsAutoString uri;
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri);
|
||||
LoadImage(uri, true, aNotify);
|
||||
}
|
||||
|
||||
if (aNotify &&
|
||||
aNameSpaceID == kNameSpaceID_None &&
|
||||
aName == nsGkAtoms::src &&
|
||||
aValue) {
|
||||
|
||||
// Prevent setting image.src by exiting early
|
||||
if (nsContentUtils::IsImageSrcSetDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// A hack to get animations to reset. See bug 594771.
|
||||
mNewRequestsWillNeedAnimationReset = true;
|
||||
|
||||
// Force image loading here, so that we'll try to load the image from
|
||||
// network if it's set to be not cacheable... If we change things so that
|
||||
// the state gets in Element's attr-setting happen around this
|
||||
// LoadImage call, we could start passing false instead of aNotify
|
||||
// here.
|
||||
LoadImage(aValue->GetStringValue(), true, aNotify);
|
||||
|
||||
mNewRequestsWillNeedAnimationReset = false;
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
||||
aValue, aNotify);
|
||||
}
|
||||
@ -387,32 +430,6 @@ HTMLImageElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
bool aNotify)
|
||||
{
|
||||
// If we plan to call LoadImage, we want to do it first so that the
|
||||
// image load kicks off _before_ the reflow triggered by the SetAttr. But if
|
||||
// aNotify is false, we are coming from the parser or some such place; we'll
|
||||
// get bound after all the attributes have been set, so we'll do the
|
||||
// image load from BindToTree. Skip the LoadImage call in that case.
|
||||
if (aNotify &&
|
||||
aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
||||
|
||||
// Prevent setting image.src by exiting early
|
||||
if (nsContentUtils::IsImageSrcSetDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// A hack to get animations to reset. See bug 594771.
|
||||
mNewRequestsWillNeedAnimationReset = true;
|
||||
|
||||
// Force image loading here, so that we'll try to load the image from
|
||||
// network if it's set to be not cacheable... If we change things so that
|
||||
// the state gets in Element's attr-setting happen around this
|
||||
// LoadImage call, we could start passing false instead of aNotify
|
||||
// here.
|
||||
LoadImage(aValue, true, aNotify);
|
||||
|
||||
mNewRequestsWillNeedAnimationReset = false;
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue,
|
||||
aNotify);
|
||||
}
|
||||
@ -421,10 +438,6 @@ nsresult
|
||||
HTMLImageElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
||||
bool aNotify)
|
||||
{
|
||||
if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::src) {
|
||||
CancelImageRequests(aNotify);
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
|
||||
}
|
||||
|
||||
|
BIN
content/html/content/test/image-allow-credentials.png
Normal file
BIN
content/html/content/test/image-allow-credentials.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 844 B |
@ -0,0 +1,2 @@
|
||||
Access-Control-Allow-Origin: http://mochi.test:8888
|
||||
Access-Control-Allow-Credentials: true
|
@ -127,6 +127,8 @@ support-files =
|
||||
file_srcdoc.html
|
||||
form_submit_server.sjs
|
||||
image.png
|
||||
image-allow-credentials.png
|
||||
image-allow-credentials.png^headers^
|
||||
nnc_lockup.gif
|
||||
reflect.js
|
||||
wakelock.ogg
|
||||
@ -343,6 +345,7 @@ support-files =
|
||||
[test_bug879319.html]
|
||||
[test_bug885024.html]
|
||||
[test_bug893537.html]
|
||||
[test_change_crossorigin.html]
|
||||
[test_checked.html]
|
||||
[test_dir_attributes_reflection.html]
|
||||
[test_dl_attributes_reflection.html]
|
||||
|
89
content/html/content/test/test_change_crossorigin.html
Normal file
89
content/html/content/test/test_change_crossorigin.html
Normal file
@ -0,0 +1,89 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=696451
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 696451</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 696451 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var img = new Image,
|
||||
canvas = document.createElement("canvas"),
|
||||
ctx = canvas.getContext("2d"),
|
||||
src = "http://example.com/tests/content/html/content/test/image-allow-credentials.png",
|
||||
imgDone = false,
|
||||
imgNotAllowedToLoadDone = false;
|
||||
|
||||
img.src = src;
|
||||
img.crossOrigin = "Anonymous";
|
||||
|
||||
img.addEventListener("load", function() {
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
ctx.drawImage( img, 0, 0 );
|
||||
try {
|
||||
canvas.toDataURL("image/png");
|
||||
ok(true, "Image was refetched with setting crossOrigin.");
|
||||
} catch (e) {
|
||||
ok(false, "Image was not refetched after setting crossOrigin.");
|
||||
}
|
||||
|
||||
imgDone = true;
|
||||
if (imgDone && imgNotAllowedToLoadDone) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
||||
img.addEventListener("error", function (event) {
|
||||
ok(false, "Should be able to load cross origin image with proper headers.");
|
||||
|
||||
imgDone = true;
|
||||
if (imgDone && imgNotAllowedToLoadDone) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
||||
var imgNotAllowedToLoad = new Image;
|
||||
|
||||
imgNotAllowedToLoad.src = "http://example.com/tests/content/html/content/test/image.png";
|
||||
|
||||
imgNotAllowedToLoad.crossOrigin = "Anonymous";
|
||||
|
||||
imgNotAllowedToLoad.addEventListener("load", function() {
|
||||
ok(false, "Image should not be allowed to load without " +
|
||||
"allow-cross-origin-access headers.");
|
||||
|
||||
imgNotAllowedToLoadDone = true;
|
||||
if (imgDone && imgNotAllowedToLoadDone) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
||||
imgNotAllowedToLoad.addEventListener("error", function() {
|
||||
ok(true, "Image should not be allowed to load without " +
|
||||
"allow-cross-origin-access headers.");
|
||||
imgNotAllowedToLoadDone = true;
|
||||
if (imgDone && imgNotAllowedToLoadDone) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=696451">Mozilla Bug 696451</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user