Bug 1454460 - Hoist SRI helper into Loader.cpp. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Tue, 17 Apr 2018 15:33:17 -0700
changeset 467675 a368c8d6676b13e970459e30df46efd2d4c20b6f
parent 467674 985679bb19281871a38e16b330fa63c63881513e
child 467676 b06fe2f80ddfc8baa9af24ac5ad5a9e4b98940a8
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1454460
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 1454460 - Hoist SRI helper into Loader.cpp. r=bz MozReview-Commit-ID: 2wgVAJDgHDl
dom/security/SRICheck.cpp
dom/security/SRICheck.h
layout/style/Loader.cpp
--- a/dom/security/SRICheck.cpp
+++ b/dom/security/SRICheck.cpp
@@ -174,48 +174,16 @@ SRICheck::IntegrityMetadata(const nsAStr
       SRILOG(("SRICheck::IntegrityMetadata, no metadata"));
     } else {
       SRILOG(("SRICheck::IntegrityMetadata, no valid metadata found"));
     }
   }
   return NS_OK;
 }
 
-/* static */ nsresult
-SRICheck::VerifyIntegrity(const SRIMetadata& aMetadata,
-                          nsIChannel* aChannel,
-                          const nsACString& aFirst,
-                          const nsACString& aSecond,
-                          const nsACString& aSourceFileURI,
-                          nsIConsoleReportCollector* aReporter)
-{
-  NS_ENSURE_ARG_POINTER(aReporter);
-
-  if (MOZ_LOG_TEST(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug)) {
-    nsAutoCString requestURL;
-    nsCOMPtr<nsIURI> originalURI;
-    if (aChannel &&
-        NS_SUCCEEDED(aChannel->GetOriginalURI(getter_AddRefs(originalURI))) &&
-        originalURI) {
-      originalURI->GetAsciiSpec(requestURL);
-    }
-    SRILOG(("SRICheck::VerifyIntegrity (unichar stream)"));
-  }
-
-  SRICheckDataVerifier verifier(aMetadata, aSourceFileURI, aReporter);
-  nsresult rv =
-    verifier.Update(aFirst.Length(), (const uint8_t*)aFirst.BeginReading());
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv =
-    verifier.Update(aSecond.Length(), (const uint8_t*)aSecond.BeginReading());
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return verifier.Verify(aMetadata, aChannel, aSourceFileURI, aReporter);
-}
-
 //////////////////////////////////////////////////////////////
 //
 //////////////////////////////////////////////////////////////
 SRICheckDataVerifier::SRICheckDataVerifier(const SRIMetadata& aMetadata,
                                            const nsACString& aSourceFileURI,
                                            nsIConsoleReportCollector* aReporter)
   : mCryptoHash(nullptr),
     mBytesHashed(0),
--- a/dom/security/SRICheck.h
+++ b/dom/security/SRICheck.h
@@ -27,30 +27,16 @@ public:
   /**
    * Parse the multiple hashes specified in the integrity attribute and
    * return the strongest supported hash.
    */
   static nsresult IntegrityMetadata(const nsAString& aMetadataList,
                                     const nsACString& aSourceFileURI,
                                     nsIConsoleReportCollector* aReporter,
                                     SRIMetadata* outMetadata);
-
-  /**
-   * Process the integrity attribute of the element.  A result of false
-   * must prevent the resource from loading.
-   *
-   * For uninteresting reasons, the caller may have the data split into two
-   * strings, so we support that here.
-   */
-  static nsresult VerifyIntegrity(const SRIMetadata& aMetadata,
-                                  nsIChannel* aChannel,
-                                  const nsACString& aFirst,
-                                  const nsACString& aSecond,
-                                  const nsACString& aSourceFileURI,
-                                  nsIConsoleReportCollector* aReporter);
 };
 
 // The SRICheckDataVerifier can be used in 2 different mode:
 //
 // 1. The streaming mode involves reading bytes from an input, and to use
 //    the |Update| function to stream new bytes, and to use the |Verify|
 //    function to check the hash of the content with the hash provided by
 //    the metadata.
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -5,18 +5,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* loading of CSS style sheets using the network APIs */
 
 #include "mozilla/css/Loader.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/DocGroup.h"
+#include "mozilla/dom/SRILogHelper.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/LoadInfo.h"
+#include "mozilla/Logging.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/SystemGroup.h"
 #include "mozilla/ResultExtensions.h"
 #include "mozilla/URLPreloader.h"
 #include "nsIRunnable.h"
 #include "nsSyncLoadService.h"
 #include "nsCOMPtr.h"
@@ -565,16 +567,49 @@ SheetLoadData::GetReferrerURI()
   nsCOMPtr<nsIURI> uri;
   if (mParentData)
     uri = mParentData->mSheet->GetSheetURI();
   if (!uri && mLoader->mDocument)
     uri = mLoader->mDocument->GetDocumentURI();
   return uri.forget();
 }
 
+static nsresult
+VerifySheetIntegrity(const SRIMetadata& aMetadata,
+                     nsIChannel* aChannel,
+                     const nsACString& aFirst,
+                     const nsACString& aSecond,
+                     const nsACString& aSourceFileURI,
+                     nsIConsoleReportCollector* aReporter)
+{
+  NS_ENSURE_ARG_POINTER(aReporter);
+
+  if (MOZ_LOG_TEST(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug)) {
+    nsAutoCString requestURL;
+    nsCOMPtr<nsIURI> originalURI;
+    if (aChannel &&
+        NS_SUCCEEDED(aChannel->GetOriginalURI(getter_AddRefs(originalURI))) &&
+        originalURI) {
+      originalURI->GetAsciiSpec(requestURL);
+    }
+    MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
+            ("VerifySheetIntegrity (unichar stream)"));
+  }
+
+  SRICheckDataVerifier verifier(aMetadata, aSourceFileURI, aReporter);
+  nsresult rv =
+    verifier.Update(aFirst.Length(), (const uint8_t*)aFirst.BeginReading());
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv =
+    verifier.Update(aSecond.Length(), (const uint8_t*)aSecond.BeginReading());
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return verifier.Verify(aMetadata, aChannel, aSourceFileURI, aReporter);
+}
+
 /*
  * Stream completion code shared by Stylo and the old style system.
  *
  * Here we need to check that the load did not give us an http error
  * page and check the mimetype on the channel to make sure we're not
  * loading non-text/css data in standards mode.
  */
 nsresult
@@ -767,17 +802,17 @@ SheetLoadData::VerifySheetReadyToParse(n
         0, EmptyString(), EmptyString());
       return NS_OK;
     }
   } else {
     nsAutoCString sourceUri;
     if (mLoader->mDocument && mLoader->mDocument->GetDocumentURI()) {
       mLoader->mDocument->GetDocumentURI()->GetAsciiSpec(sourceUri);
     }
-    nsresult rv = SRICheck::VerifyIntegrity(
+    nsresult rv = VerifySheetIntegrity(
       sriMetadata, aChannel, aBytes1, aBytes2, sourceUri, mLoader->mReporter);
 
     nsCOMPtr<nsILoadGroup> loadGroup;
     aChannel->GetLoadGroup(getter_AddRefs(loadGroup));
     if (loadGroup) {
       mLoader->mReporter->FlushConsoleReports(loadGroup);
     } else {
       mLoader->mReporter->FlushConsoleReports(mLoader->mDocument);