--- a/image/ImageCacheKey.cpp
+++ b/image/ImageCacheKey.cpp
@@ -3,16 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ImageCacheKey.h"
#include "mozilla/Move.h"
#include "ImageURL.h"
#include "nsHostObjectProtocolHandler.h"
+#include "nsLayoutUtils.h"
#include "nsString.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/workers/ServiceWorkerManager.h"
#include "nsIDocument.h"
#include "nsPrintfCString.h"
namespace mozilla {
@@ -48,66 +49,75 @@ BlobSerial(ImageURL* aURI)
ImageCacheKey::ImageCacheKey(nsIURI* aURI,
const OriginAttributes& aAttrs,
nsIDocument* aDocument,
nsresult& aRv)
: mURI(new ImageURL(aURI, aRv))
, mOriginAttributes(aAttrs)
, mControlledDocument(GetControlledDocumentToken(aDocument))
, mIsChrome(URISchemeIs(mURI, "chrome"))
+ , mIsStyloEnabled(nsLayoutUtils::StyloEnabled())
{
NS_ENSURE_SUCCESS_VOID(aRv);
MOZ_ASSERT(NS_IsMainThread());
if (URISchemeIs(mURI, "blob")) {
mBlobSerial = BlobSerial(mURI);
}
- mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument);
+ mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument,
+ mIsStyloEnabled);
}
ImageCacheKey::ImageCacheKey(ImageURL* aURI,
const OriginAttributes& aAttrs,
nsIDocument* aDocument)
: mURI(aURI)
, mOriginAttributes(aAttrs)
, mControlledDocument(GetControlledDocumentToken(aDocument))
, mIsChrome(URISchemeIs(mURI, "chrome"))
+ , mIsStyloEnabled(nsLayoutUtils::StyloEnabled())
{
MOZ_ASSERT(aURI);
if (URISchemeIs(mURI, "blob")) {
mBlobSerial = BlobSerial(mURI);
}
- mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument);
+ mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument,
+ mIsStyloEnabled);
}
ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
: mURI(aOther.mURI)
, mBlobSerial(aOther.mBlobSerial)
, mOriginAttributes(aOther.mOriginAttributes)
, mControlledDocument(aOther.mControlledDocument)
, mHash(aOther.mHash)
, mIsChrome(aOther.mIsChrome)
+ , mIsStyloEnabled(aOther.mIsStyloEnabled)
{ }
ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
: mURI(Move(aOther.mURI))
, mBlobSerial(Move(aOther.mBlobSerial))
, mOriginAttributes(aOther.mOriginAttributes)
, mControlledDocument(aOther.mControlledDocument)
, mHash(aOther.mHash)
, mIsChrome(aOther.mIsChrome)
+ , mIsStyloEnabled(aOther.mIsStyloEnabled)
{ }
bool
ImageCacheKey::operator==(const ImageCacheKey& aOther) const
{
+ if (mIsStyloEnabled != aOther.mIsStyloEnabled) {
+ return false;
+ }
// Don't share the image cache between a controlled document and anything else.
if (mControlledDocument != aOther.mControlledDocument) {
return false;
}
// The origin attributes always have to match.
if (mOriginAttributes != aOther.mOriginAttributes) {
return false;
}
@@ -127,27 +137,29 @@ ImageCacheKey::Spec() const
{
return mURI->Spec();
}
/* static */ PLDHashNumber
ImageCacheKey::ComputeHash(ImageURL* aURI,
const Maybe<uint64_t>& aBlobSerial,
const OriginAttributes& aAttrs,
- void* aControlledDocument)
+ void* aControlledDocument,
+ bool aIsStyloEnabled)
{
// Since we frequently call Hash() several times in a row on the same
// ImageCacheKey, as an optimization we compute our hash once and store it.
nsPrintfCString ptr("%p", aControlledDocument);
nsAutoCString suffix;
aAttrs.CreateSuffix(suffix);
return AddToHash(0, aURI->ComputeHash(aBlobSerial),
- HashString(suffix), HashString(ptr));
+ HashString(suffix), HashString(ptr),
+ aIsStyloEnabled);
}
/* static */ void*
ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument)
{
// For non-controlled documents, we just return null. For controlled
// documents, we cast the pointer into a void* to avoid dereferencing
// it (since we only use it for comparisons), and return it.
--- a/image/ImageCacheKey.h
+++ b/image/ImageCacheKey.h
@@ -53,23 +53,28 @@ public:
/// A token indicating which service worker controlled document this entry
/// belongs to, if any.
void* ControlledDocument() const { return mControlledDocument; }
private:
static PLDHashNumber ComputeHash(ImageURL* aURI,
const Maybe<uint64_t>& aBlobSerial,
const OriginAttributes& aAttrs,
- void* aControlledDocument);
+ void* aControlledDocument,
+ bool aIsStyloEnabled);
static void* GetControlledDocumentToken(nsIDocument* aDocument);
RefPtr<ImageURL> mURI;
Maybe<uint64_t> mBlobSerial;
OriginAttributes mOriginAttributes;
void* mControlledDocument;
PLDHashNumber mHash;
bool mIsChrome;
+ // To prevent the reftests of styloVsGecko taking the same image cache after
+ // refreshing, we need to store different caches of stylo and gecko. So, we
+ // also consider the info of StyloEnabled() in ImageCacheKey.
+ bool mIsStyloEnabled;
};
} // namespace image
} // namespace mozilla
#endif // mozilla_image_src_ImageCacheKey_h