Bug 1169680 - Don't merge image cache entries for blob URIs with different refs. r=tn

This commit is contained in:
Seth Fowler 2015-06-05 01:52:06 -07:00
parent 8321ec5336
commit 788e795e6e
7 changed files with 99 additions and 4 deletions

View File

@ -86,8 +86,10 @@ bool
ImageCacheKey::operator==(const ImageCacheKey& aOther) const
{
if (mBlobSerial || aOther.mBlobSerial) {
// If at least one of us has a blob serial, just compare those.
return mBlobSerial == aOther.mBlobSerial;
// If at least one of us has a blob serial, just compare the blob serial and
// the ref portion of the URIs.
return mBlobSerial == aOther.mBlobSerial &&
mURI->HasSameRef(*aOther.mURI);
}
// For non-blob URIs, compare the URIs.
@ -109,8 +111,13 @@ ImageCacheKey::ComputeHash(ImageURL* aURI,
if (aBlobSerial) {
// For blob URIs, we hash the serial number of the underlying blob, so that
// different blob URIs which point to the same blob share a cache entry.
return HashGeneric(*aBlobSerial);
// different blob URIs which point to the same blob share a cache entry. We
// also include the ref portion of the URI to support -moz-samplesize and
// -moz-resolution, which require us to create different Image objects even
// if the source data is the same.
nsAutoCString ref;
aURI->GetRef(ref);
return HashGeneric(*aBlobSerial, HashString(ref));
}
// For non-blob URIs, we hash the URI spec.

View File

@ -101,6 +101,11 @@ public:
return mSpec == aOther.mSpec;
}
bool HasSameRef(const ImageURL& aOther) const
{
return mRef == aOther.mRef;
}
private:
// Since this is a basic storage class, no duplication of spec parsing is
// included in the functionality. Instead, the class depends upon the

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html class="reftest-wait">
<body>
<img id="test">
</body>
<script>
var image = new Image;
image.onload = function() {
// Create a canvas.
var canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
// Draw the image into the canvas.
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
// Convert the image into a blob URI and use it as #test's src.
canvas.toBlob(function(blob) {
var uri = window.URL.createObjectURL(blob);
uri += '#-moz-samplesize=8';
document.getElementById('test').src = uri;
// Take the snapshot.
document.documentElement.removeAttribute('class');
}, 'image/jpeg', 0.99);
}
// Start loading the image.
image.src = 'image.png';
</script>
</html>

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html class="reftest-wait">
<body>
<img id="test">
</body>
<script>
var image = new Image;
image.onload = function() {
// Create a canvas.
var canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
// Draw the image into the canvas.
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
// Convert the image into a blob URI and use it as #test's src.
canvas.toBlob(function(blob) {
var uri = window.URL.createObjectURL(blob);
document.getElementById('test').src = uri;
// Take the snapshot.
document.documentElement.removeAttribute('class');
}, 'image/jpeg', 0.99);
}
// Start loading the image.
image.src = 'image.png';
</script>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

View File

@ -0,0 +1,7 @@
# Blob URI tests
# Test that blob URIs don't get merged if they have different ref params.
# (We run the test twice to check both cached and non-cached cases.)
default-preferences pref(image.mozsamplesize.enabled,true)
!= blob-uri-with-ref-param.html blob-uri-with-ref-param-notref.html
!= blob-uri-with-ref-param.html blob-uri-with-ref-param-notref.html

View File

@ -46,5 +46,8 @@ include color-management/reftest.list
# Downscaling tests
include downscaling/reftest.list
# Blob URI tests
include blob/reftest.list
# Lossless encoders
skip-if(Android||B2G) include encoders-lossless/reftest.list # bug 783621