diff --git a/image/ImageCacheKey.cpp b/image/ImageCacheKey.cpp index 33ba6ca4cbf4..861c11d3e619 100644 --- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -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. diff --git a/image/ImageURL.h b/image/ImageURL.h index 4e5b34674bb3..dd72690fbd68 100644 --- a/image/ImageURL.h +++ b/image/ImageURL.h @@ -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 diff --git a/image/test/reftest/blob/blob-uri-with-ref-param-notref.html b/image/test/reftest/blob/blob-uri-with-ref-param-notref.html new file mode 100644 index 000000000000..b909fd89082d --- /dev/null +++ b/image/test/reftest/blob/blob-uri-with-ref-param-notref.html @@ -0,0 +1,37 @@ + + + + + + + + + + + diff --git a/image/test/reftest/blob/blob-uri-with-ref-param.html b/image/test/reftest/blob/blob-uri-with-ref-param.html new file mode 100644 index 000000000000..a0807e25ad15 --- /dev/null +++ b/image/test/reftest/blob/blob-uri-with-ref-param.html @@ -0,0 +1,36 @@ + + + + + + + + + + + diff --git a/image/test/reftest/blob/image.png b/image/test/reftest/blob/image.png new file mode 100644 index 000000000000..d7d87adce09a Binary files /dev/null and b/image/test/reftest/blob/image.png differ diff --git a/image/test/reftest/blob/reftest.list b/image/test/reftest/blob/reftest.list new file mode 100644 index 000000000000..e795ba9d386b --- /dev/null +++ b/image/test/reftest/blob/reftest.list @@ -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 diff --git a/image/test/reftest/reftest.list b/image/test/reftest/reftest.list index 4eb2fc34ef6f..45131b4ac26e 100644 --- a/image/test/reftest/reftest.list +++ b/image/test/reftest/reftest.list @@ -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