Bug 1603458 - Distinguish between Error and Warning messages from OTS in the web console. r=heycam
authorJonathan Kew <jkew@mozilla.com>
Fri, 13 Dec 2019 00:01:54 +0000
changeset 506804 0568763216b3ffb72cc8e6b64bc81f8bf5b3f501
parent 506803 d7361ebcaefa13465f7cdb1b30351942a90f9312
child 506805 fe871f29510dec7ecf7377fabe271e0d21e2f9fe
push id103091
push userjkew@mozilla.com
push dateFri, 13 Dec 2019 00:31:01 +0000
treeherderautoland@0568763216b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1603458
milestone73.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 1603458 - Distinguish between Error and Warning messages from OTS in the web console. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D56963
gfx/thebes/gfxUserFontSet.cpp
gfx/thebes/gfxUserFontSet.h
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -237,41 +237,43 @@ class MOZ_STACK_CLASS gfxOTSContext : pu
       // For warnings (rather than errors that cause the font to fail),
       // we only report the first instance of any given message.
       if (mWarningsIssued.Contains(msg)) {
         return;
       }
       mWarningsIssued.PutEntry(msg);
     }
 
-    mMessages.AppendElement(msg);
+    mMessages.AppendElement(gfxUserFontEntry::OTSMessage{msg, level});
   }
 
   bool Process(ots::OTSStream* aOutput, const uint8_t* aInput, size_t aLength,
-               nsTArray<nsCString>& aMessages) {
+               nsTArray<gfxUserFontEntry::OTSMessage>& aMessages) {
     bool ok = ots::OTSContext::Process(aOutput, aInput, aLength);
     aMessages = TakeMessages();
     return ok;
   }
 
-  nsTArray<nsCString>&& TakeMessages() { return std::move(mMessages); }
+  nsTArray<gfxUserFontEntry::OTSMessage>&& TakeMessages() {
+    return std::move(mMessages);
+  }
 
  private:
   nsTHashtable<nsCStringHashKey> mWarningsIssued;
-  nsTArray<nsCString> mMessages;
+  nsTArray<gfxUserFontEntry::OTSMessage> mMessages;
   bool mCheckOTLTables;
   bool mCheckVariationTables;
   bool mKeepColorBitmaps;
 };
 
 // Call the OTS library to sanitize an sfnt before attempting to use it.
 // Returns a newly-allocated block, or nullptr in case of fatal errors.
 const uint8_t* gfxUserFontEntry::SanitizeOpenTypeData(
     const uint8_t* aData, uint32_t aLength, uint32_t& aSaneLength,
-    gfxUserFontType& aFontType, nsTArray<nsCString>& aMessages) {
+    gfxUserFontType& aFontType, nsTArray<OTSMessage>& aMessages) {
   aFontType = gfxFontUtils::DetermineFontDataType(aData, aLength);
   Telemetry::Accumulate(Telemetry::WEBFONT_FONTTYPE, uint32_t(aFontType));
 
   if (aFontType == GFX_USERFONT_UNKNOWN) {
     aSaneLength = 0;
     return nullptr;
   }
 
@@ -690,56 +692,58 @@ bool gfxUserFontEntry::LoadPlatformFontS
 
   // Unwrap/decompress/sanitize or otherwise munge the downloaded data
   // to make a usable sfnt structure.
 
   // Call the OTS sanitizer; this will also decode WOFF to sfnt
   // if necessary. The original data in aFontData is left unchanged.
   uint32_t saneLen;
   gfxUserFontType fontType;
-  nsTArray<nsCString> messages;
+  nsTArray<OTSMessage> messages;
   const uint8_t* saneData =
       SanitizeOpenTypeData(aFontData, aLength, saneLen, fontType, messages);
 
   return LoadPlatformFont(aFontData, aLength, fontType, saneData, saneLen,
                           std::move(messages));
 }
 
 void gfxUserFontEntry::StartPlatformFontLoadOnWorkerThread(
     const uint8_t* aFontData, uint32_t aLength,
     nsMainThreadPtrHandle<nsIFontLoadCompleteCallback> aCallback) {
   MOZ_ASSERT(sFontLoadingThread);
   MOZ_ASSERT(sFontLoadingThread->IsOnCurrentThread());
 
   uint32_t saneLen;
   gfxUserFontType fontType;
-  nsTArray<nsCString> messages;
+  nsTArray<OTSMessage> messages;
   const uint8_t* saneData =
       SanitizeOpenTypeData(aFontData, aLength, saneLen, fontType, messages);
 
   nsCOMPtr<nsIRunnable> event =
       NewRunnableMethod<const uint8_t*, uint32_t, gfxUserFontType,
-                        const uint8_t*, uint32_t, nsTArray<nsCString>&&,
+                        const uint8_t*, uint32_t, nsTArray<OTSMessage>&&,
                         nsMainThreadPtrHandle<nsIFontLoadCompleteCallback>>(
           "gfxUserFontEntry::ContinuePlatformFontLoadOnMainThread", this,
           &gfxUserFontEntry::ContinuePlatformFontLoadOnMainThread, aFontData,
           aLength, fontType, saneData, saneLen, std::move(messages), aCallback);
   NS_DispatchToMainThread(event.forget());
 }
 
 bool gfxUserFontEntry::LoadPlatformFont(const uint8_t* aOriginalFontData,
                                         uint32_t aOriginalLength,
                                         gfxUserFontType aFontType,
                                         const uint8_t* aSanitizedFontData,
                                         uint32_t aSanitizedLength,
-                                        nsTArray<nsCString>&& aMessages) {
+                                        nsTArray<OTSMessage>&& aMessages) {
   MOZ_ASSERT(NS_IsMainThread());
 
   for (const auto& msg : aMessages) {
-    mFontSet->LogMessage(this, msg.get());
+    mFontSet->LogMessage(this, msg.mMessage.get(),
+                         msg.mLevel > 0 ? nsIScriptError::warningFlag
+                                        : nsIScriptError::errorFlag);
   }
 
   if (!aSanitizedFontData) {
     mFontSet->LogMessage(this, "rejected by sanitizer");
   } else {
     // Check whether aSanitizedFontData is a known OpenType format; it might be
     // a TrueType Collection, which OTS would accept but we don't yet
     // know how to handle. If so, discard.
@@ -944,17 +948,17 @@ void gfxUserFontEntry::LoadPlatformFontA
           aLength, cb);
   MOZ_ALWAYS_SUCCEEDS(
       sFontLoadingThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL));
 }
 
 void gfxUserFontEntry::ContinuePlatformFontLoadOnMainThread(
     const uint8_t* aOriginalFontData, uint32_t aOriginalLength,
     gfxUserFontType aFontType, const uint8_t* aSanitizedFontData,
-    uint32_t aSanitizedLength, nsTArray<nsCString>&& aMessages,
+    uint32_t aSanitizedLength, nsTArray<OTSMessage>&& aMessages,
     nsMainThreadPtrHandle<nsIFontLoadCompleteCallback> aCallback) {
   MOZ_ASSERT(NS_IsMainThread());
 
   bool loaded = LoadPlatformFont(aOriginalFontData, aOriginalLength, aFontType,
                                  aSanitizedFontData, aSanitizedLength,
                                  std::move(aMessages));
   aOriginalFontData = nullptr;
   aSanitizedFontData = nullptr;
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -639,20 +639,25 @@ class gfxUserFontEntry : public gfxFontE
   }
   void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {
     MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
   }
 
   static void Shutdown() { sFontLoadingThread = nullptr; }
 
  protected:
+  struct OTSMessage {
+    nsCString mMessage;
+    int mLevel;  // see OTSContext in gfx/ots/include/opentype-sanitizer.h
+  };
+
   const uint8_t* SanitizeOpenTypeData(const uint8_t* aData, uint32_t aLength,
                                       uint32_t& aSaneLength,
                                       gfxUserFontType& aFontType,
-                                      nsTArray<nsCString>& aMessages);
+                                      nsTArray<OTSMessage>& aMessages);
 
   // attempt to load the next resource in the src list.
   void LoadNextSrc();
   void ContinueLoad();
   void DoLoadNextSrc(bool aForceAsync);
 
   // change the load state
   virtual void SetLoadState(UserFontLoadState aLoadState);
@@ -678,26 +683,26 @@ class gfxUserFontEntry : public gfxFontE
   void StartPlatformFontLoadOnWorkerThread(
       const uint8_t* aFontData, uint32_t aLength,
       nsMainThreadPtrHandle<nsIFontLoadCompleteCallback> aCallback);
 
   // helper method for LoadPlatformFontAsync; runs on the main thread
   void ContinuePlatformFontLoadOnMainThread(
       const uint8_t* aOriginalFontData, uint32_t aOriginalLength,
       gfxUserFontType aFontType, const uint8_t* aSanitizedFontData,
-      uint32_t aSanitizedLength, nsTArray<nsCString>&& aMessages,
+      uint32_t aSanitizedLength, nsTArray<OTSMessage>&& aMessages,
       nsMainThreadPtrHandle<nsIFontLoadCompleteCallback> aCallback);
 
   // helper method for LoadPlatformFontSync and
   // ContinuePlatformFontLoadOnMainThread; runs on the main thread
   bool LoadPlatformFont(const uint8_t* aOriginalFontData,
                         uint32_t aOriginalLength, gfxUserFontType aFontType,
                         const uint8_t* aSanitizedFontData,
                         uint32_t aSanitizedLength,
-                        nsTArray<nsCString>&& aMessages);
+                        nsTArray<OTSMessage>&& aMessages);
 
   // helper method for FontDataDownloadComplete and
   // ContinuePlatformFontLoadOnMainThread; runs on the main thread
   void FontLoadFailed(nsIFontLoadCompleteCallback* aCallback);
 
   // store metadata and src details for current src into aFontEntry
   void StoreUserFontData(gfxFontEntry* aFontEntry, bool aPrivate,
                          const nsACString& aOriginalName,