Bug 1639262 - Get the right "is preload" value to CreateSheet. r=nordzilla
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 21 May 2020 00:06:25 +0000
changeset 531378 191820bda8f5b3fa245f458c031557f78fa95bda
parent 531377 cf1939b293d954d1539818daeb2a2553dcf1d15d
child 531379 3978210495447999e98a443aa838a934270cda2b
push id116614
push userealvarez@mozilla.com
push dateThu, 21 May 2020 00:07:38 +0000
treeherderautoland@191820bda8f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnordzilla
bugs1639262
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639262 - Get the right "is preload" value to CreateSheet. r=nordzilla This could also cause mismatches in the cache for no good reason. Differential Revision: https://phabricator.services.mozilla.com/D76003
layout/style/Loader.cpp
layout/style/Loader.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -126,16 +126,18 @@ static mozilla::LazyLogModule gSriPRLog(
 
 // And some convenience strings...
 static const char* const gStateStrings[] = {"Unknown", "NeedsParser", "Pending",
                                             "Loading", "Complete"};
 
 namespace mozilla {
 
 class SheetLoadDataHashKey : public nsURIHashKey {
+  using IsPreload = css::Loader::IsPreload;
+
  public:
   typedef SheetLoadDataHashKey* KeyType;
   typedef const SheetLoadDataHashKey* KeyTypePointer;
 
   explicit SheetLoadDataHashKey(const SheetLoadDataHashKey* aKey)
       : nsURIHashKey(aKey->mKey),
         mPrincipal(aKey->mPrincipal),
         mReferrerInfo(aKey->mReferrerInfo),
@@ -144,24 +146,24 @@ class SheetLoadDataHashKey : public nsUR
         mSRIMetadata(aKey->mSRIMetadata),
         mIsLinkPreload(aKey->mIsLinkPreload) {
     MOZ_COUNT_CTOR(SheetLoadDataHashKey);
   }
 
   SheetLoadDataHashKey(nsIURI* aURI, nsIPrincipal* aPrincipal,
                        nsIReferrerInfo* aReferrerInfo, CORSMode aCORSMode,
                        css::SheetParsingMode aParsingMode,
-                       const SRIMetadata& aSRIMetadata, bool aIsLinkPreload)
+                       const SRIMetadata& aSRIMetadata, IsPreload aIsPreload)
       : nsURIHashKey(aURI),
         mPrincipal(aPrincipal),
         mReferrerInfo(aReferrerInfo),
         mCORSMode(aCORSMode),
         mParsingMode(aParsingMode),
         mSRIMetadata(aSRIMetadata),
-        mIsLinkPreload(aIsLinkPreload) {
+        mIsLinkPreload(aIsPreload == IsPreload::FromLink) {
     MOZ_COUNT_CTOR(SheetLoadDataHashKey);
   }
 
   SheetLoadDataHashKey(SheetLoadDataHashKey&& toMove)
       : nsURIHashKey(std::move(toMove)),
         mPrincipal(std::move(toMove.mPrincipal)),
         mReferrerInfo(std::move(toMove.mReferrerInfo)),
         mCORSMode(std::move(toMove.mCORSMode)),
@@ -1141,17 +1143,17 @@ nsresult Loader::CheckContentPolicy(nsIP
  * and clone it if we find it.  Cloned sheets will have the title/media/enabled
  * state of the sheet they are clones off; make sure to call PrepareSheet() on
  * the result of CreateSheet().
  */
 std::tuple<RefPtr<StyleSheet>, Loader::SheetState> Loader::CreateSheet(
     nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal,
     css::SheetParsingMode aParsingMode, CORSMode aCORSMode,
     nsIReferrerInfo* aLoadingReferrerInfo, const nsAString& aIntegrity,
-    bool aSyncLoad) {
+    bool aSyncLoad, IsPreload aIsPreload) {
   MOZ_ASSERT(aURI, "This path is not taken for inline stylesheets");
   LOG(("css::Loader::CreateSheet(%s)", aURI->GetSpecOrDefault().get()));
 
   if (!mSheets) {
     mSheets = MakeUnique<Sheets>();
   }
 
   SRIMetadata sriMetadata;
@@ -1162,18 +1164,17 @@ std::tuple<RefPtr<StyleSheet>, Loader::S
     nsAutoCString sourceUri;
     if (mDocument && mDocument->GetDocumentURI()) {
       mDocument->GetDocumentURI()->GetAsciiSpec(sourceUri);
     }
     SRICheck::IntegrityMetadata(aIntegrity, sourceUri, mReporter, &sriMetadata);
   }
 
   SheetLoadDataHashKey key(aURI, aLoaderPrincipal, aLoadingReferrerInfo,
-                           aCORSMode, aParsingMode, sriMetadata,
-                           false /** TODO - is-link-preload **/);
+                           aCORSMode, aParsingMode, sriMetadata, aIsPreload);
   auto cacheResult = mSheets->Lookup(key, aSyncLoad);
   if (const auto& [styleSheet, sheetState] = cacheResult; styleSheet) {
     LOG(("  Hit cache with state: %s", gStateStrings[size_t(sheetState)]));
     return cacheResult;
   }
 
   nsIURI* sheetURI = aURI;
   nsIURI* baseURI = aURI;
@@ -2089,18 +2090,18 @@ Result<Loader::LoadSheetResult, nsresult
       loadBlockingAsyncDispatcher->PostDOMEvent();
     }
     return Err(rv);
   }
 
   // Check IsAlternateSheet now, since it can mutate our document and make
   // pending sheets go to the non-pending state.
   auto isAlternate = IsAlternateSheet(aInfo.mTitle, aInfo.mHasAlternateRel);
-  auto [sheet, state] =
-      CreateSheet(aInfo, principal, eAuthorSheetFeatures, syncLoad);
+  auto [sheet, state] = CreateSheet(aInfo, principal, eAuthorSheetFeatures,
+                                    syncLoad, IsPreload::No);
 
   LOG(("  Sheet is alternate: %d", static_cast<int>(isAlternate)));
 
   auto matched = PrepareSheet(*sheet, aInfo.mTitle, aInfo.mMedia, nullptr,
                               isAlternate, aInfo.mIsExplicitlyEnabled);
 
   InsertSheetInTree(*sheet, aInfo.mContent);
 
@@ -2265,17 +2266,17 @@ nsresult Loader::LoadChildSheet(StyleShe
   if (aReusableSheets && aReusableSheets->FindReusableStyleSheet(aURL, sheet)) {
     state = SheetState::Complete;
   } else {
     // For now, use CORS_NONE for child sheets
     std::tie(sheet, state) =
         CreateSheet(aURL, nullptr, principal, aParentSheet.ParsingMode(),
                     CORS_NONE, aParentSheet.GetReferrerInfo(),
                     EmptyString(),  // integrity is only checked on main sheet
-                    aParentData ? aParentData->mSyncLoad : false);
+                    aParentData && aParentData->mSyncLoad, IsPreload::No);
     PrepareSheet(*sheet, EmptyString(), EmptyString(), aMedia, IsAlternate::No,
                  IsExplicitlyEnabled::No);
   }
 
   MOZ_ASSERT(sheet);
   InsertChildSheet(*sheet, aParentSheet);
 
   if (state == SheetState::Complete) {
@@ -2357,17 +2358,17 @@ Result<RefPtr<StyleSheet>, nsresult> Loa
                                    mDocument, EmptyString(), aIsPreload);
   if (NS_FAILED(rv)) {
     return Err(rv);
   }
 
   bool syncLoad = !aObserver;
   auto [sheet, state] =
       CreateSheet(aURL, nullptr, aOriginPrincipal, aParsingMode, aCORSMode,
-                  aReferrerInfo, aIntegrity, syncLoad);
+                  aReferrerInfo, aIntegrity, syncLoad, aIsPreload);
 
   PrepareSheet(*sheet, EmptyString(), EmptyString(), nullptr, IsAlternate::No,
                IsExplicitlyEnabled::No);
 
   auto data = MakeRefPtr<SheetLoadData>(
       this, aURL, sheet, syncLoad, aUseSystemPrincipal, aIsPreload,
       aPreloadEncoding, aObserver, aOriginPrincipal, aReferrerInfo, mDocument);
   if (state == SheetState::Complete) {
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -340,29 +340,30 @@ class Loader final {
     NeedsParser,
     Pending,
     Loading,
     Complete
   };
 
   std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
       const SheetInfo& aInfo, nsIPrincipal* aLoaderPrincipal,
-      css::SheetParsingMode aParsingMode, bool aSyncLoad) {
+      css::SheetParsingMode aParsingMode, bool aSyncLoad,
+      IsPreload aIsPreload) {
     return CreateSheet(aInfo.mURI, aInfo.mContent, aLoaderPrincipal,
                        aParsingMode, aInfo.mCORSMode, aInfo.mReferrerInfo,
-                       aInfo.mIntegrity, aSyncLoad);
+                       aInfo.mIntegrity, aSyncLoad, aIsPreload);
   }
 
   // For inline style, the aURI param is null, but the aLinkingContent
   // must be non-null then.  The loader principal must never be null
   // if aURI is not null.
   std::tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
       nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal,
       css::SheetParsingMode, CORSMode, nsIReferrerInfo* aLoadingReferrerInfo,
-      const nsAString& aIntegrity, bool aSyncLoad);
+      const nsAString& aIntegrity, bool aSyncLoad, IsPreload aIsPreload);
 
   // Pass in either a media string or the MediaList from the CSSParser.  Don't
   // pass both.
   //
   // This method will set the sheet's enabled state based on IsAlternate and co.
   MediaMatched PrepareSheet(StyleSheet&, const nsAString& aTitle,
                             const nsAString& aMediaString, dom::MediaList*,
                             IsAlternate, IsExplicitlyEnabled);