Bug 1377158 - (Part 2) Add the info of StyloEnabled() to hash function to make reftests of styloVsGecko get the correct caches. draft
authorKuoE0 <kuoe0.tw@gmail.com>
Mon, 24 Jul 2017 11:51:20 +0800
changeset 641618 c2305a8e38116fa102ea8fe1d61807c4fb56a9b9
parent 641565 58f4368f105c4e7de5322a689e7d2bbcf106b54c
child 641619 959b9b31ae7266e82b836c981b66666a9e66c4dd
child 641627 93ed1e2a55e17fb4a986fd2be50227679c3e10a4
child 642446 9da6dee13b5cf5f38fa9c97560d0fd0a489ba215
child 642453 80a0e6af460a1909107fbbad0e5878040562ad40
child 643233 0cf7234a06c1e1d5035fcdb3c0a5cd335742f4b9
push id72592
push userbmo:kuoe0@mozilla.com
push dateMon, 07 Aug 2017 10:42:25 +0000
bugs1377158
milestone57.0a1
Bug 1377158 - (Part 2) Add the info of StyloEnabled() to hash function to make reftests of styloVsGecko get the correct caches. MozReview-Commit-ID: 7cyXheHQ7Ot
image/ImageCacheKey.cpp
image/ImageCacheKey.h
--- 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