From 9541790d6a1d0de31fc5d8bd67ee024780beed39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jun 2020 10:48:44 +0000 Subject: [PATCH] Bug 1646776 - Add some logging for sheet cache misses for the same URI. r=heycam This makes it easy to see why your test is not failing without your patch, for example ;) Note that we log only when the URIs are the same, which I think is a reasonable compromise in verbosity. Differential Revision: https://phabricator.services.mozilla.com/D80288 --- layout/style/Loader.cpp | 63 +++++++++++++++++++++++++++++++++++++++++ layout/style/Loader.h | 55 +---------------------------------- 2 files changed, 64 insertions(+), 54 deletions(-) diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 8c83d3dc52f3..cd4c98dfbe0f 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -148,6 +148,69 @@ SheetLoadDataHashKey::SheetLoadDataHashKey(const css::SheetLoadData& aLoadData) aLoadData.mSheet->GetIntegrity(mSRIMetadata); } +bool SheetLoadDataHashKey::KeyEquals(const SheetLoadDataHashKey& aKey) const { + { + bool eq; + if (NS_FAILED(mURI->Equals(aKey.mURI, &eq)) || !eq) { + return false; + } + } + + LOG_URI("KeyEquals(%s)\n", mURI); + + // The loader principal doesn't really need to match to be a cache hit, it's + // just useful for cache-eviction purposes. + + if (!mPrincipal->Equals(aKey.mPrincipal)) { + LOG((" > Principal mismatch\n")); + return false; + } + + if (mCORSMode != aKey.mCORSMode) { + LOG((" > CORS mismatch\n")); + return false; + } + + if (mParsingMode != aKey.mParsingMode) { + LOG((" > Parsing mode mismatch\n")); + return false; + } + + if (mCompatMode != aKey.mCompatMode) { + LOG((" > Quirks mismatch\n")); + return false; + } + + // If encoding differs, then don't reuse the cache. + // + // TODO(emilio): When the encoding is determined from the request (either + // BOM or Content-Length or @charset), we could do a bit better, + // theoretically. + if (mEncodingGuess != aKey.mEncodingGuess) { + LOG((" > Encoding guess mismatch\n")); + return false; + } + + // Consuming stylesheet tags must never coalesce to initiated + // speculative loads with a weaker SRI hash or its different value. This + // check makes sure that regular loads will never find such a weaker preload + // and rather start a new, independent load with new, stronger SRI checker + // set up, so that integrity is ensured. + if (mIsLinkPreload != aKey.mIsLinkPreload) { + const auto& linkPreloadMetadata = + mIsLinkPreload ? mSRIMetadata : aKey.mSRIMetadata; + const auto& consumerPreloadMetadata = + mIsLinkPreload ? aKey.mSRIMetadata : mSRIMetadata; + + if (!consumerPreloadMetadata.CanTrustBeDelegatedTo(linkPreloadMetadata)) { + LOG((" > Preload SRI metadata mismatch\n")); + return false; + } + } + + return true; +} + namespace css { static NotNull GetFallbackEncoding( diff --git a/layout/style/Loader.h b/layout/style/Loader.h index 046f93ff3b4e..675fb6885e96 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -118,60 +118,7 @@ class SheetLoadDataHashKey : public PLDHashEntryHdr { return KeyEquals(*aKey); } - bool KeyEquals(const SheetLoadDataHashKey& aKey) const { - { - bool eq; - if (NS_FAILED(mURI->Equals(aKey.mURI, &eq)) || !eq) { - return false; - } - } - - // The loader principal doesn't really need to match to be a cache hit, it's - // just useful for cache-eviction purposes. - - if (!mPrincipal->Equals(aKey.mPrincipal)) { - return false; - } - - if (mCORSMode != aKey.mCORSMode) { - return false; - } - - if (mParsingMode != aKey.mParsingMode) { - return false; - } - - if (mCompatMode != aKey.mCompatMode) { - return false; - } - - // If encoding differs, then don't reuse the cache. - // - // TODO(emilio): When the encoding is determined from the request (either - // BOM or Content-Length or @charset), we could do a bit better, - // theoretically. - if (mEncodingGuess != aKey.mEncodingGuess) { - return false; - } - - // Consuming stylesheet tags must never coalesce to initiated - // speculative loads with a weaker SRI hash or its different value. This - // check makes sure that regular loads will never find such a weaker preload - // and rather start a new, independent load with new, stronger SRI checker - // set up, so that integrity is ensured. - if (mIsLinkPreload != aKey.mIsLinkPreload) { - const auto& linkPreloadMetadata = - mIsLinkPreload ? mSRIMetadata : aKey.mSRIMetadata; - const auto& consumerPreloadMetadata = - mIsLinkPreload ? aKey.mSRIMetadata : mSRIMetadata; - - if (!consumerPreloadMetadata.CanTrustBeDelegatedTo(linkPreloadMetadata)) { - return false; - } - } - - return true; - } + bool KeyEquals(const SheetLoadDataHashKey&) const; static const SheetLoadDataHashKey* KeyToPointer( const SheetLoadDataHashKey& aKey) {