Bug 1447828 part 4 - Remove StyleBackendType uses from Loader. r=emilio
authorXidorn Quan <me@upsuper.org>
Thu, 29 Mar 2018 02:33:01 +1100
changeset 410486 151e6133adcfac40596d909402a54e0aa82530e4
parent 410485 8f67af6a636ea4a3b7378360fca56f7708ce26f8
child 410487 ea7634ccd0247cbecf9a560acb21be8ed11827ae
push id101504
push userrgurzau@mozilla.com
push dateWed, 28 Mar 2018 22:01:17 +0000
treeherdermozilla-inbound@e51ae123ece9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1447828
milestone61.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 1447828 part 4 - Remove StyleBackendType uses from Loader. r=emilio MozReview-Commit-ID: 8DbjibZE3Dw
dom/base/nsDocument.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsStyleSheetService.cpp
layout/style/Loader.cpp
layout/style/Loader.h
layout/style/PreloadedStyleSheet.cpp
layout/style/ServoStyleSheet.cpp
layout/style/nsLayoutStylesheetCache.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4561,18 +4561,17 @@ nsIDocument::LoadAdditionalStyleSheet(ad
 {
   NS_PRECONDITION(aSheetURI, "null arg");
 
   // Checking if we have loaded this one already.
   if (FindSheet(mAdditionalSheets[aType], aSheetURI) >= 0)
     return NS_ERROR_INVALID_ARG;
 
   // Loading the sheet sync.
-  RefPtr<css::Loader> loader =
-    new css::Loader(GetStyleBackendType(), GetDocGroup());
+  RefPtr<css::Loader> loader = new css::Loader(GetDocGroup());
 
   css::SheetParsingMode parsingMode;
   switch (aType) {
     case nsIDocument::eAgentSheet:
       parsingMode = css::eAgentSheetFeatures;
       break;
 
     case nsIDocument::eUserSheet:
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2373,17 +2373,17 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
     nsCOMPtr<Element> elt(do_QueryInterface(chromeHandler));
     if (elt) {
       nsCOMPtr<nsIURI> baseURI = elt->GetBaseURI();
 
       nsAutoString sheets;
       elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
       if (!sheets.IsEmpty() && baseURI) {
         RefPtr<css::Loader> cssLoader =
-          new css::Loader(backendType, aDocument->GetDocGroup());
+          new css::Loader(aDocument->GetDocGroup());
 
         char *str = ToNewCString(sheets);
         char *newStr = str;
         char *token;
         while ( (token = nsCRT::strtok(newStr, ", ", &newStr)) ) {
           NS_NewURI(getter_AddRefs(uri), nsDependentCString(token), nullptr,
                     baseURI);
           if (!uri) continue;
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -194,20 +194,19 @@ nsStyleSheetService::LoadAndRegisterShee
     }
   }
   return rv;
 }
 
 static nsresult
 LoadSheet(nsIURI* aURI,
           css::SheetParsingMode aParsingMode,
-          StyleBackendType aType,
           RefPtr<StyleSheet>* aResult)
 {
-  RefPtr<css::Loader> loader = new css::Loader(aType, nullptr);
+  RefPtr<css::Loader> loader = new css::Loader;
   return loader->LoadSheetSync(aURI, aParsingMode, true, aResult);
 }
 
 nsresult
 nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
                                                   uint32_t aSheetType)
 {
   NS_ENSURE_ARG_POINTER(aSheetURI);
@@ -228,17 +227,17 @@ nsStyleSheetService::LoadAndRegisterShee
 
     default:
       NS_WARNING("invalid sheet type argument");
       return NS_ERROR_INVALID_ARG;
   }
 
 
   RefPtr<StyleSheet> servoSheet;
-  nsresult rv = LoadSheet(aSheetURI, parsingMode, StyleBackendType::Servo, &servoSheet);
+  nsresult rv = LoadSheet(aSheetURI, parsingMode, &servoSheet);
   NS_ENSURE_SUCCESS(rv, rv);
   MOZ_ASSERT(servoSheet);
   mServoSheets[aSheetType].AppendElement(servoSheet);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -362,40 +362,38 @@ LoaderReusableStyleSheets::FindReusableS
   }
   return false;
 }
 
 /*************************
  * Loader Implementation *
  *************************/
 
-Loader::Loader(StyleBackendType aType, DocGroup* aDocGroup)
+Loader::Loader()
   : mDocument(nullptr)
-  , mDocGroup(aDocGroup)
   , mDatasToNotifyOn(0)
   , mCompatMode(eCompatibility_FullStandards)
-  , mStyleBackendType(Some(aType))
   , mEnabled(true)
   , mReporter(new ConsoleReportCollector())
 #ifdef DEBUG
   , mSyncCallback(false)
 #endif
 {
 }
 
+Loader::Loader(DocGroup* aDocGroup)
+  : Loader()
+{
+  mDocGroup = aDocGroup;
+}
+
 Loader::Loader(nsIDocument* aDocument)
-  : mDocument(aDocument)
-  , mDatasToNotifyOn(0)
-  , mCompatMode(eCompatibility_FullStandards)
-  , mEnabled(true)
-  , mReporter(new ConsoleReportCollector())
-#ifdef DEBUG
-  , mSyncCallback(false)
-#endif
+  : Loader()
 {
+  mDocument = aDocument;
   MOZ_ASSERT(mDocument, "We should get a valid document from the caller!");
 
   // We can just use the preferred set, since there are no sheets in the
   // document yet (if there are, how did they get there? _we_ load the sheets!)
   // and hence the selected set makes no sense at this time.
   mDocument->GetPreferredStyleSheetSet(mPreferredSheet);
 }
 
@@ -1056,21 +1054,17 @@ Loader::CreateSheet(nsIURI* aURI,
       nsAutoCString sourceUri;
       if (mDocument && mDocument->GetDocumentURI()) {
         mDocument->GetDocumentURI()->GetAsciiSpec(sourceUri);
       }
       SRICheck::IntegrityMetadata(aIntegrity, sourceUri, mReporter,
                                   &sriMetadata);
     }
 
-    if (GetStyleBackendType() == StyleBackendType::Gecko) {
-      MOZ_CRASH("old style system disabled");
-    } else {
-      *aSheet = new ServoStyleSheet(aParsingMode, aCORSMode, aReferrerPolicy, sriMetadata);
-    }
+    *aSheet = new ServoStyleSheet(aParsingMode, aCORSMode, aReferrerPolicy, sriMetadata);
     (*aSheet)->SetURIs(sheetURI, originalURI, baseURI);
   }
 
   NS_ASSERTION(*aSheet, "We should have a sheet by now!");
   NS_ASSERTION(aSheetState != eSheetStateUnknown, "Have to set a state!");
   LOG(("  State: %s", gStateStrings[aSheetState]));
 
   return NS_OK;
@@ -2598,28 +2592,16 @@ Loader::SizeOfIncludingThis(mozilla::Mal
   //
   // The following members aren't measured:
   // - mDocument, because it's a weak backpointer
   // - mPreferredSheet, because it can be a shared string
 
   return n;
 }
 
-StyleBackendType
-Loader::GetStyleBackendType() const
-{
-  MOZ_ASSERT(mStyleBackendType || mDocument,
-             "you must construct a Loader with a document or set a "
-             "StyleBackendType on it before calling GetStyleBackendType");
-  if (mStyleBackendType) {
-    return *mStyleBackendType;
-  }
-  return mDocument->GetStyleBackendType();
-}
-
 void
 Loader::BlockOnload()
 {
   if (mDocument) {
     mDocument->BlockOnload();
   }
 }
 
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -19,17 +19,16 @@
 #include "nsTArray.h"
 #include "nsTObserverArray.h"
 #include "nsURIHashKey.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/CORSMode.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MemoryReporting.h"
-#include "mozilla/StyleBackendType.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class nsICSSLoaderObserver;
 class nsIConsoleReportCollector;
 class nsIContent;
 class nsIDocument;
 class nsIStyleSheetLinkingElement;
@@ -187,21 +186,21 @@ enum StyleSheetState {
   eSheetLoading,
   eSheetComplete
 };
 
 class Loader final {
   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
 
 public:
+  Loader();
   // aDocGroup is used for dispatching SheetLoadData in PostLoadEvent(). It
   // can be null if you want to use this constructor, and there's no
   // document when the Loader is constructed.
-  Loader(StyleBackendType aType, mozilla::dom::DocGroup* aDocGroup);
-
+  explicit Loader(mozilla::dom::DocGroup*);
   explicit Loader(nsIDocument*);
 
  private:
   // Private destructor, to discourage deletion outside of Release():
   ~Loader();
 
  public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Loader)
@@ -602,18 +601,16 @@ private:
   // datas whose observers need to be notified can be added to it.
   void DoSheetComplete(SheetLoadData* aLoadData, LoadDataArray& aDatasToNotify);
 
   // Mark the given SheetLoadData, as well as any of its siblings, parents, etc
   // transitively, as failed.  The idea is to mark as failed any load that was
   // directly or indirectly @importing the sheet this SheetLoadData represents.
   void MarkLoadTreeFailed(SheetLoadData* aLoadData);
 
-  StyleBackendType GetStyleBackendType() const;
-
   struct Sheets {
     nsBaseHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey,
                     RefPtr<StyleSheet>,
                     StyleSheet*> mCompleteSheets;
     nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
                       mLoadingDatas; // weak refs
     nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
                       mPendingDatas; // weak refs
@@ -638,20 +635,16 @@ private:
   // whole bunch at once (e.g. in one of the stop methods).  This is used to
   // make sure that HasPendingLoads() won't return false until we're notifying
   // on the last data we're working with.
   uint32_t          mDatasToNotifyOn;
 
   nsCompatibility   mCompatMode;
   nsString          mPreferredSheet;  // title of preferred sheet
 
-  // Set explicitly when the Loader(StyleBackendType) constructor is used, or
-  // taken from the document when the Loader(nsIDocument*) constructor is used.
-  mozilla::Maybe<StyleBackendType> mStyleBackendType;
-
   bool              mEnabled; // is enabled to load new styles
 
   nsCOMPtr<nsIConsoleReportCollector> mReporter;
 
 #ifdef DEBUG
   bool              mSyncCallback;
 #endif
 };
--- a/layout/style/PreloadedStyleSheet.cpp
+++ b/layout/style/PreloadedStyleSheet.cpp
@@ -53,17 +53,17 @@ PreloadedStyleSheet::GetSheet(StyleBacke
   *aResult = nullptr;
 
   MOZ_DIAGNOSTIC_ASSERT(mLoaded);
 
   RefPtr<StyleSheet>& sheet =
     aType == StyleBackendType::Gecko ? mGecko : mServo;
 
   if (!sheet) {
-    RefPtr<css::Loader> loader = new css::Loader(aType, nullptr);
+    RefPtr<css::Loader> loader = new css::Loader;
     nsresult rv = loader->LoadSheetSync(mURI, mParsingMode, true, &sheet);
     NS_ENSURE_SUCCESS(rv, rv);
     MOZ_ASSERT(sheet);
   }
 
   *aResult = sheet;
   return NS_OK;
 }
@@ -114,18 +114,17 @@ PreloadedStyleSheet::StylesheetPreloadOb
 // until the observer is notified that the sheet has finished loading.
 nsresult
 PreloadedStyleSheet::PreloadAsync(NotNull<dom::Promise*> aPromise)
 {
   MOZ_DIAGNOSTIC_ASSERT(!mLoaded);
 
   RefPtr<StyleSheet>& sheet = mServo;
 
-  RefPtr<css::Loader> loader =
-    new css::Loader(StyleBackendType::Servo, nullptr);
+  RefPtr<css::Loader> loader = new css::Loader;
 
   RefPtr<StylesheetPreloadObserver> obs =
     new StylesheetPreloadObserver(aPromise, this);
 
   return loader->LoadSheet(mURI, mParsingMode, false, obs, &sheet);
 }
 
 } // namespace mozilla
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -274,17 +274,17 @@ ServoStyleSheet::ReparseSheet(const nsAS
 
   // Hold strong ref to the CSSLoader in case the document update
   // kills the document
   RefPtr<css::Loader> loader;
   if (mDocument) {
     loader = mDocument->CSSLoader();
     NS_ASSERTION(loader, "Document with no CSS loader!");
   } else {
-    loader = new css::Loader(StyleBackendType::Servo, nullptr);
+    loader = new css::Loader;
   }
 
   mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
 
   WillDirty();
 
   // cache child sheets to reuse
   css::LoaderReusableStyleSheets reusableSheets;
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -798,17 +798,17 @@ nsLayoutStylesheetCache::LoadSheet(nsIUR
     return;
   }
 
   auto& loader = mBackendType == StyleBackendType::Gecko ?
     gCSSLoader_Gecko :
     gCSSLoader_Servo;
 
   if (!loader) {
-    loader = new Loader(mBackendType, nullptr);
+    loader = new Loader;
     if (!loader) {
       ErrorLoadingSheet(aURI, "no Loader", eCrash);
       return;
     }
   }
 
   nsZipArchive::sFileCorruptedReason = nullptr;