Bug 1571530 - Make PrepareSheet take a reference. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 16 Aug 2019 10:56:18 +0000
changeset 488488 3d9de500e9c51f8f8439d2c35d643e7847bcf260
parent 488487 a28efee19e9ceda71182874e51e19ee5e3ea72cb
child 488489 e10941ec60dfbe48d3c88e25b4166e0108c88b4c
push id36444
push userccoroiu@mozilla.com
push dateFri, 16 Aug 2019 16:24:18 +0000
treeherdermozilla-central@8a9e9189cd98 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1571530
milestone70.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 1571530 - Make PrepareSheet take a reference. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D41561
layout/style/Loader.cpp
layout/style/Loader.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1095,33 +1095,31 @@ static Loader::MediaMatched MediaListMat
 }
 
 /**
  * PrepareSheet() handles setting the media and title on the sheet, as
  * well as setting the enabled state based on the title and whether
  * the sheet had "alternate" in its rel.
  */
 Loader::MediaMatched Loader::PrepareSheet(
-    StyleSheet* aSheet, const nsAString& aTitle, const nsAString& aMediaString,
+    StyleSheet& aSheet, const nsAString& aTitle, const nsAString& aMediaString,
     MediaList* aMediaList, IsAlternate aIsAlternate,
     IsExplicitlyEnabled aIsExplicitlyEnabled) {
-  MOZ_ASSERT(aSheet, "Must have a sheet!");
-
   RefPtr<MediaList> mediaList(aMediaList);
 
   if (!aMediaString.IsEmpty()) {
     NS_ASSERTION(!aMediaList,
                  "must not provide both aMediaString and aMediaList");
     mediaList = MediaList::Create(aMediaString);
   }
 
-  aSheet->SetMedia(mediaList);
+  aSheet.SetMedia(mediaList);
 
-  aSheet->SetTitle(aTitle);
-  aSheet->SetEnabled(aIsAlternate == IsAlternate::No ||
+  aSheet.SetTitle(aTitle);
+  aSheet.SetEnabled(aIsAlternate == IsAlternate::No ||
                      aIsExplicitlyEnabled == IsExplicitlyEnabled::Yes);
   return MediaListMatches(mediaList, mDocument);
 }
 
 /**
  * InsertSheetInTree handles ordering of sheets in the document or shadow root.
  *
  * Here we have two types of sheets -- those with linking elements and
@@ -1836,17 +1834,17 @@ Result<Loader::LoadSheetResult, nsresult
                                       SRIMetadata{});
   sheet->SetURIs(sheetURI, originalURI, baseURI);
   nsCOMPtr<nsIReferrerInfo> referrerInfo =
       ReferrerInfo::CreateForInternalCSSResources(aInfo.mContent->OwnerDoc());
   sheet->SetReferrerInfo(referrerInfo);
 
   LOG(("  Sheet is alternate: %d", static_cast<int>(isAlternate)));
 
-  auto matched = PrepareSheet(sheet, aInfo.mTitle, aInfo.mMedia, nullptr,
+  auto matched = PrepareSheet(*sheet, aInfo.mTitle, aInfo.mMedia, nullptr,
                               isAlternate, aInfo.mIsExplicitlyEnabled);
 
   InsertSheetInTree(*sheet, aInfo.mContent);
 
   nsIPrincipal* principal = aInfo.mContent->NodePrincipal();
   if (aInfo.mTriggeringPrincipal) {
     // The triggering principal may be an expanded principal, which is safe to
     // use for URL security checks, but not as the loader principal for a
@@ -1938,17 +1936,17 @@ Result<Loader::LoadSheetResult, nsresult
 
   SheetState state;
   RefPtr<StyleSheet> sheet;
   Tie(sheet, state) =
       CreateSheet(aInfo, principal, eAuthorSheetFeatures, syncLoad);
 
   LOG(("  Sheet is alternate: %d", static_cast<int>(isAlternate)));
 
-  auto matched = PrepareSheet(sheet, aInfo.mTitle, aInfo.mMedia, nullptr,
+  auto matched = PrepareSheet(*sheet, aInfo.mTitle, aInfo.mMedia, nullptr,
                               isAlternate, aInfo.mIsExplicitlyEnabled);
 
   InsertSheetInTree(*sheet, aInfo.mContent);
 
   nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(
       do_QueryInterface(aInfo.mContent));
 
   if (state == SheetState::Complete) {
@@ -2100,17 +2098,17 @@ nsresult Loader::LoadChildSheet(StyleShe
     state = SheetState::Complete;
   } else {
     // For now, use CORS_NONE for child sheets
     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);
-    PrepareSheet(sheet, EmptyString(), EmptyString(), aMedia, IsAlternate::No,
+    PrepareSheet(*sheet, EmptyString(), EmptyString(), aMedia, IsAlternate::No,
                  IsExplicitlyEnabled::No);
   }
 
   MOZ_ASSERT(sheet);
   InsertChildSheet(*sheet, aParentSheet);
 
   if (state == SheetState::Complete) {
     LOG(("  Sheet already complete"));
@@ -2196,17 +2194,17 @@ Result<RefPtr<StyleSheet>, nsresult> Loa
   bool syncLoad = !aObserver;
 
   SheetState state;
   RefPtr<StyleSheet> sheet;
   Tie(sheet, state) =
       CreateSheet(aURL, nullptr, aOriginPrincipal, aParsingMode, aCORSMode,
                   aReferrerInfo, aIntegrity, syncLoad);
 
-  PrepareSheet(sheet, EmptyString(), EmptyString(), nullptr, IsAlternate::No,
+  PrepareSheet(*sheet, EmptyString(), EmptyString(), nullptr, IsAlternate::No,
                IsExplicitlyEnabled::No);
 
   if (state == SheetState::Complete) {
     LOG(("  Sheet already complete"));
     if (aObserver || !mObservers.IsEmpty()) {
       rv = PostLoadEvent(aURL, sheet, aObserver, IsAlternate::No,
                          MediaMatched::Yes, aReferrerInfo, nullptr);
       if (NS_FAILED(rv)) {
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -348,18 +348,18 @@ class Loader final {
   Tuple<RefPtr<StyleSheet>, SheetState> CreateSheet(
       nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal,
       css::SheetParsingMode, CORSMode, nsIReferrerInfo* aLoadingReferrerInfo,
       const nsAString& aIntegrity, bool aSyncLoad);
 
   // 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 aIsAlternate
-  MediaMatched PrepareSheet(StyleSheet* aSheet, const nsAString& aTitle,
+  // 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);
 
   // Inserts a style sheet in a document or a ShadowRoot.
   void InsertSheetInTree(StyleSheet& aSheet, nsIContent* aLinkingContent);
   // Inserts a style sheet into a parent style sheet.
   void InsertChildSheet(StyleSheet& aSheet, StyleSheet& aParentSheet);