From e418f1ccf520638dd1890da9d1f25235660ac0d2 Mon Sep 17 00:00:00 2001 From: KuoE0 Date: Mon, 24 Jul 2017 11:51:20 +0800 Subject: [PATCH] Bug 1377158 - (Part 2) Add the info of StyloEnabled() to hash function to make reftests of styloVsGecko get the correct caches. r=heycam MozReview-Commit-ID: 7cyXheHQ7Ot --HG-- extra : rebase_source : 4a92de63228cb2a138d95d8f366b39122dbdc05e --- image/ImageCacheKey.cpp | 20 ++++++++++++++++---- image/ImageCacheKey.h | 7 ++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/image/ImageCacheKey.cpp b/image/ImageCacheKey.cpp index c3327155c1cd..2dfdc7c763cc 100644 --- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -8,6 +8,7 @@ #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" @@ -53,6 +54,7 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI, , mOriginAttributes(aAttrs) , mControlledDocument(GetControlledDocumentToken(aDocument)) , mIsChrome(URISchemeIs(mURI, "chrome")) + , mIsStyloEnabled(nsLayoutUtils::StyloEnabled()) { NS_ENSURE_SUCCESS_VOID(aRv); @@ -62,7 +64,8 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI, mBlobSerial = BlobSerial(mURI); } - mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument); + mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument, + mIsStyloEnabled); } ImageCacheKey::ImageCacheKey(ImageURL* aURI, @@ -72,6 +75,7 @@ ImageCacheKey::ImageCacheKey(ImageURL* aURI, , mOriginAttributes(aAttrs) , mControlledDocument(GetControlledDocumentToken(aDocument)) , mIsChrome(URISchemeIs(mURI, "chrome")) + , mIsStyloEnabled(nsLayoutUtils::StyloEnabled()) { MOZ_ASSERT(aURI); @@ -79,7 +83,8 @@ ImageCacheKey::ImageCacheKey(ImageURL* aURI, mBlobSerial = BlobSerial(mURI); } - mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument); + mHash = ComputeHash(mURI, mBlobSerial, mOriginAttributes, mControlledDocument, + mIsStyloEnabled); } ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) @@ -89,6 +94,7 @@ ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther) , mControlledDocument(aOther.mControlledDocument) , mHash(aOther.mHash) , mIsChrome(aOther.mIsChrome) + , mIsStyloEnabled(aOther.mIsStyloEnabled) { } ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther) @@ -98,11 +104,15 @@ ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther) , 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; @@ -132,7 +142,8 @@ ImageCacheKey::Spec() const ImageCacheKey::ComputeHash(ImageURL* aURI, const Maybe& 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. @@ -142,7 +153,8 @@ ImageCacheKey::ComputeHash(ImageURL* aURI, aAttrs.CreateSuffix(suffix); return AddToHash(0, aURI->ComputeHash(aBlobSerial), - HashString(suffix), HashString(ptr)); + HashString(suffix), HashString(ptr), + aIsStyloEnabled); } /* static */ void* diff --git a/image/ImageCacheKey.h b/image/ImageCacheKey.h index c5acd0ea495e..6d676ccb6338 100644 --- a/image/ImageCacheKey.h +++ b/image/ImageCacheKey.h @@ -58,7 +58,8 @@ private: static PLDHashNumber ComputeHash(ImageURL* aURI, const Maybe& aBlobSerial, const OriginAttributes& aAttrs, - void* aControlledDocument); + void* aControlledDocument, + bool aIsStyloEnabled); static void* GetControlledDocumentToken(nsIDocument* aDocument); RefPtr mURI; @@ -67,6 +68,10 @@ private: 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