Bug 1640158 - Remove useless principal-passing in the CSS loader. r=ckerschb
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 25 May 2020 09:42:01 +0000
changeset 531879 9b3266bb0f915f1a033ef91cc50433ded0764efe
parent 531878 d2221f584b0f93afef0256306f12cc43b720627f
child 531880 1d1482c8d52cb8ad8491f3c699e0f92a5401561f
push id116933
push userealvarez@mozilla.com
push dateMon, 25 May 2020 10:08:39 +0000
treeherderautoland@9b3266bb0f91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1640158
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 1640158 - Remove useless principal-passing in the CSS loader. r=ckerschb The only caller that passes that principal is the only caller that calls into LoadSheet with a loader that has a document anyway. And the principal we're passing is Document::NodePrincipal(), which is what we'd end up using anyway, so the new code is exactly equivalent, as far as I can tell. Differential Revision: https://phabricator.services.mozilla.com/D76469
dom/base/Document.cpp
layout/style/Loader.cpp
layout/style/Loader.h
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -11511,17 +11511,17 @@ void Document::PreloadStyle(nsIURI* uri,
   nsCOMPtr<nsIReferrerInfo> referrerInfo =
       ReferrerInfo::CreateFromDocumentAndPolicyOverride(this, aReferrerPolicy);
 
   auto preloadType = aIsLinkPreload ? css::Loader::IsPreload::FromLink
                                     : css::Loader::IsPreload::FromParser;
 
   // Charset names are always ASCII.
   Unused << CSSLoader()->LoadSheet(
-      uri, preloadType, NodePrincipal(), aEncoding, referrerInfo, obs,
+      uri, preloadType, aEncoding, referrerInfo, obs,
       Element::StringToCORSMode(aCrossOriginAttr), aIntegrity);
 }
 
 RefPtr<StyleSheet> Document::LoadChromeSheetSync(nsIURI* uri) {
   return CSSLoader()
       ->LoadSheetSync(uri, css::eAuthorSheetFeatures)
       .unwrapOr(nullptr);
 }
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -2300,78 +2300,75 @@ nsresult Loader::LoadChildSheet(StyleShe
 }
 
 Result<RefPtr<StyleSheet>, nsresult> Loader::LoadSheetSync(
     nsIURI* aURL, SheetParsingMode aParsingMode,
     UseSystemPrincipal aUseSystemPrincipal) {
   LOG(("css::Loader::LoadSheetSync"));
   nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo(nullptr);
   return InternalLoadNonDocumentSheet(
-      aURL, IsPreload::No, aParsingMode, aUseSystemPrincipal, nullptr, nullptr,
+      aURL, IsPreload::No, aParsingMode, aUseSystemPrincipal, nullptr,
       referrerInfo, nullptr, CORS_NONE, EmptyString());
 }
 
 Result<RefPtr<StyleSheet>, nsresult> Loader::LoadSheet(
     nsIURI* aURI, SheetParsingMode aParsingMode,
     UseSystemPrincipal aUseSystemPrincipal, nsICSSLoaderObserver* aObserver) {
   nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo(nullptr);
   return InternalLoadNonDocumentSheet(
-      aURI, IsPreload::No, aParsingMode, aUseSystemPrincipal, nullptr, nullptr,
+      aURI, IsPreload::No, aParsingMode, aUseSystemPrincipal, nullptr,
       referrerInfo, aObserver, CORS_NONE, EmptyString());
 }
 
 Result<RefPtr<StyleSheet>, nsresult> Loader::LoadSheet(
-    nsIURI* aURL, IsPreload aIsPreload, nsIPrincipal* aOriginPrincipal,
-    const Encoding* aPreloadEncoding, nsIReferrerInfo* aReferrerInfo,
-    nsICSSLoaderObserver* aObserver, CORSMode aCORSMode,
-    const nsAString& aIntegrity) {
+    nsIURI* aURL, IsPreload aIsPreload, const Encoding* aPreloadEncoding,
+    nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
+    CORSMode aCORSMode, const nsAString& aIntegrity) {
   LOG(("css::Loader::LoadSheet(aURL, aObserver) api call"));
-  return InternalLoadNonDocumentSheet(aURL, aIsPreload, eAuthorSheetFeatures,
-                                      UseSystemPrincipal::No, aOriginPrincipal,
-                                      aPreloadEncoding, aReferrerInfo,
-                                      aObserver, aCORSMode, aIntegrity);
+  return InternalLoadNonDocumentSheet(
+      aURL, aIsPreload, eAuthorSheetFeatures, UseSystemPrincipal::No,
+      aPreloadEncoding, aReferrerInfo, aObserver, aCORSMode, aIntegrity);
 }
 
 Result<RefPtr<StyleSheet>, nsresult> Loader::InternalLoadNonDocumentSheet(
     nsIURI* aURL, IsPreload aIsPreload, SheetParsingMode aParsingMode,
-    UseSystemPrincipal aUseSystemPrincipal, nsIPrincipal* aOriginPrincipal,
-    const Encoding* aPreloadEncoding, nsIReferrerInfo* aReferrerInfo,
-    nsICSSLoaderObserver* aObserver, CORSMode aCORSMode,
-    const nsAString& aIntegrity) {
+    UseSystemPrincipal aUseSystemPrincipal, const Encoding* aPreloadEncoding,
+    nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
+    CORSMode aCORSMode, const nsAString& aIntegrity) {
   MOZ_ASSERT(aURL, "Must have a URI to load");
   MOZ_ASSERT(aUseSystemPrincipal == UseSystemPrincipal::No || !aObserver,
              "Shouldn't load system-principal sheets async");
   MOZ_ASSERT(aReferrerInfo, "Must have referrerInfo");
 
   LOG_URI("  Non-document sheet uri: '%s'", aURL);
 
   if (!mEnabled) {
     LOG_WARN(("  Not enabled"));
     return Err(NS_ERROR_NOT_AVAILABLE);
   }
 
   nsCOMPtr<nsIPrincipal> loadingPrincipal =
-      (aOriginPrincipal && mDocument ? mDocument->NodePrincipal() : nullptr);
-  nsresult rv = CheckContentPolicy(loadingPrincipal, aOriginPrincipal, aURL,
+      mDocument ? mDocument->NodePrincipal() : nullptr;
+  nsresult rv = CheckContentPolicy(loadingPrincipal, loadingPrincipal, aURL,
                                    mDocument, EmptyString(), aIsPreload);
   if (NS_FAILED(rv)) {
     return Err(rv);
   }
 
   bool syncLoad = !aObserver;
   auto [sheet, state] =
-      CreateSheet(aURL, nullptr, aOriginPrincipal, aParsingMode, aCORSMode,
+      CreateSheet(aURL, nullptr, loadingPrincipal, aParsingMode, aCORSMode,
                   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);
+      aPreloadEncoding, aObserver, loadingPrincipal, aReferrerInfo, mDocument);
   if (state == SheetState::Complete) {
     LOG(("  Sheet already complete"));
     if (aObserver || !mObservers.IsEmpty()) {
       rv = PostLoadEvent(std::move(data));
       if (NS_FAILED(rv)) {
         return Err(rv);
       }
     } else {
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -234,20 +234,19 @@ class Loader final {
    * @return the sheet to load. Note that the sheet may well not be loaded by
    * the time this method returns.
    *
    * NOTE: At the moment, this method assumes the sheet will be UTF-8, but
    * ideally it would allow arbitrary encodings.  Callers should NOT depend on
    * non-UTF8 sheets being treated as UTF-8 by this method.
    */
   Result<RefPtr<StyleSheet>, nsresult> LoadSheet(
-      nsIURI* aURI, IsPreload, nsIPrincipal* aOriginPrincipal,
-      const Encoding* aPreloadEncoding, nsIReferrerInfo* aReferrerInfo,
-      nsICSSLoaderObserver* aObserver, CORSMode aCORSMode = CORS_NONE,
-      const nsAString& aIntegrity = EmptyString());
+      nsIURI* aURI, IsPreload, const Encoding* aPreloadEncoding,
+      nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
+      CORSMode = CORS_NONE, const nsAString& aIntegrity = EmptyString());
 
   /**
    * As above, but without caring for a couple things.
    */
   Result<RefPtr<StyleSheet>, nsresult> LoadSheet(nsIURI*, SheetParsingMode,
                                                  UseSystemPrincipal,
                                                  nsICSSLoaderObserver*);
 
@@ -370,20 +369,19 @@ class Loader final {
 
   // 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);
 
   Result<RefPtr<StyleSheet>, nsresult> InternalLoadNonDocumentSheet(
       nsIURI* aURL, IsPreload, SheetParsingMode aParsingMode,
-      UseSystemPrincipal, nsIPrincipal* aOriginPrincipal,
-      const Encoding* aPreloadEncoding, nsIReferrerInfo* aReferrerInfo,
-      nsICSSLoaderObserver* aObserver, CORSMode aCORSMode,
-      const nsAString& aIntegrity);
+      UseSystemPrincipal, const Encoding* aPreloadEncoding,
+      nsIReferrerInfo* aReferrerInfo, nsICSSLoaderObserver* aObserver,
+      CORSMode aCORSMode, const nsAString& aIntegrity);
 
   // Post a load event for aObserver to be notified about aSheet.  The
   // notification will be sent with status NS_OK unless the load event is
   // canceled at some point (in which case it will be sent with
   // NS_BINDING_ABORTED).
   nsresult PostLoadEvent(RefPtr<SheetLoadData>);
 
   // Start the loads of all the sheets in mPendingDatas