Bug 1519918 - Make nsFontFaceLoader::mFontFaceSet a weak reference. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 21 Jan 2019 11:10:26 +0000
changeset 454664 e9570ad88e6d4ac55d26342dca0ded559b8c2ff9
parent 454663 4c05fb631121d80c6c41a9b0ffcf3eeb9cd5459f
child 454665 2885dbea4efe7f400bef8f594c0798e8aab6bd01
push id35409
push userrmaries@mozilla.com
push dateMon, 21 Jan 2019 17:48:45 +0000
treeherdermozilla-central@4977d02e1191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1519918
milestone66.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 1519918 - Make nsFontFaceLoader::mFontFaceSet a weak reference. r=heycam And start tracking the loader ASAP to be on the safe side. Both sides already take care of cleaning up pointers on destruction. Differential Revision: https://phabricator.services.mozilla.com/D16514
layout/style/FontFaceSet.cpp
layout/style/nsFontFaceLoader.h
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -576,16 +576,17 @@ nsresult FontFaceSet::StartLoad(gfxUserF
       principal ? principal->get() : nullptr,
       nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, nsIContentPolicy::TYPE_FONT,
       nullptr,  // PerformanceStorage
       loadGroup);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<nsFontFaceLoader> fontLoader = new nsFontFaceLoader(
       aUserFontEntry, aFontFaceSrc->mURI->get(), this, channel);
+  mLoaders.PutEntry(fontLoader);
 
   if (LOG_ENABLED()) {
     LOG(
         ("userfonts (%p) download start - font uri: (%s) "
          "referrer uri: (%s)\n",
          fontLoader.get(), aFontFaceSrc->mURI->GetSpecOrDefault().get(),
          aFontFaceSrc->mReferrer
              ? aFontFaceSrc->mReferrer->GetSpecOrDefault().get()
@@ -633,17 +634,16 @@ nsresult FontFaceSet::StartLoad(gfxUserF
       nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, loadGroup);
 
   rv = channel->AsyncOpen2(streamLoader);
   if (NS_FAILED(rv)) {
     fontLoader->DropChannel();  // explicitly need to break ref cycle
   }
 
   if (NS_SUCCEEDED(rv)) {
-    mLoaders.PutEntry(fontLoader);
     fontLoader->StartedLoading(streamLoader);
     // let the font entry remember the loader, in case we need to cancel it
     aUserFontEntry->SetLoader(fontLoader);
   }
 
   return rv;
 }
 
--- a/layout/style/nsFontFaceLoader.h
+++ b/layout/style/nsFontFaceLoader.h
@@ -50,16 +50,17 @@ class nsFontFaceLoader final : public ns
   virtual ~nsFontFaceLoader();
 
   // helper method for determining the font-display value
   mozilla::StyleFontDisplay GetFontDisplay();
 
  private:
   RefPtr<gfxUserFontEntry> mUserFontEntry;
   nsCOMPtr<nsIURI> mFontURI;
-  RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
+  // Cleared in FontFaceSet::~FontFaceSet, and on cancelation and such too.
+  mozilla::dom::FontFaceSet* MOZ_NON_OWNING_REF mFontFaceSet;
   nsCOMPtr<nsIChannel> mChannel;
   nsCOMPtr<nsITimer> mLoadTimer;
   mozilla::TimeStamp mStartTime;
   nsIStreamLoader* mStreamLoader;
 };
 
 #endif /* !defined(nsFontFaceLoader_h_) */