Bug 1412090 - patch 4 - Also adopt the ContentParent::NotifyUpdatedFonts method on macOS, so that only the parent process needs to register with CFNotificationCenter for font-changed notifications. r=lsalzman
☠☠ backed out by df53224b9171 ☠ ☠
authorJonathan Kew <jkew@mozilla.com>
Sun, 05 Nov 2017 08:42:32 +0000
changeset 390223 f9763adebe6847072575978df2f8e010d790b083
parent 390222 a1c1fe33a052ac9ff96fbbe389f53687d25e2afc
child 390224 df53224b917158a08bccadeef488f30a2b2ac89b
push id96994
push userjkew@mozilla.com
push dateSun, 05 Nov 2017 08:44:44 +0000
treeherdermozilla-inbound@f9763adebe68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1412090
milestone58.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 1412090 - patch 4 - Also adopt the ContentParent::NotifyUpdatedFonts method on macOS, so that only the parent process needs to register with CFNotificationCenter for font-changed notifications. r=lsalzman
gfx/thebes/gfxMacPlatformFontList.mm
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -59,16 +59,17 @@
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsISimpleEnumerator.h"
 #include "nsCharTraits.h"
 #include "nsCocoaFeatures.h"
 #include "nsCocoaUtils.h"
 #include "gfxFontConstants.h"
 
 #include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/ContentParent.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/gfx/2D.h"
 
 #include <unistd.h>
 #include <time.h>
@@ -983,34 +984,42 @@ gfxMacPlatformFontList::gfxMacPlatformFo
     nsCOMPtr<nsIFile> langFonts(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
     if (NS_SUCCEEDED(rv)) {
         rv = langFonts->InitWithNativePath(NS_LITERAL_CSTRING(LANG_FONTS_DIR));
         if (NS_SUCCEEDED(rv)) {
             ActivateFontsFromDir(langFonts);
         }
     }
 
-    ::CFNotificationCenterAddObserver(::CFNotificationCenterGetLocalCenter(),
-                                      this,
-                                      RegisteredFontsChangedNotificationCallback,
-                                      kCTFontManagerRegisteredFontsChangedNotification,
-                                      0,
-                                      CFNotificationSuspensionBehaviorDeliverImmediately);
+    // Only the parent process listens for OS font-changed notifications;
+    // after rebuilding its list, it will update the content processes.
+    if (XRE_IsParentProcess()) {
+        ::CFNotificationCenterAddObserver(
+            ::CFNotificationCenterGetLocalCenter(),
+            this,
+            RegisteredFontsChangedNotificationCallback,
+            kCTFontManagerRegisteredFontsChangedNotification,
+            0,
+            CFNotificationSuspensionBehaviorDeliverImmediately);
+    }
 
     // cache this in a static variable so that MacOSFontFamily objects
     // don't have to repeatedly look it up
     sFontManager = [NSFontManager sharedFontManager];
 }
 
 gfxMacPlatformFontList::~gfxMacPlatformFontList()
 {
-    ::CFNotificationCenterRemoveObserver(::CFNotificationCenterGetLocalCenter(),
-                                         this,
-                                         kCTFontManagerRegisteredFontsChangedNotification,
-                                         0);
+    if (XRE_IsParentProcess()) {
+        ::CFNotificationCenterRemoveObserver(
+            ::CFNotificationCenterGetLocalCenter(),
+            this,
+            kCTFontManagerRegisteredFontsChangedNotification,
+            0);
+    }
 
     if (mDefaultFont) {
         ::CFRelease(mDefaultFont);
     }
 }
 
 void
 gfxMacPlatformFontList::AddFamily(const nsAString& aFamilyName,
@@ -1095,19 +1104,18 @@ gfxMacPlatformFontList::InitFontListForP
 
     // reset system font list
     mSystemFontFamilies.Clear();
 
     if (XRE_IsContentProcess()) {
         // Content process: use font list passed from the chrome process via
         // the GetXPCOMProcessAttributes message, because it's much faster than
         // querying Core Text again in the child.
-        mozilla::dom::ContentChild* cc =
-            mozilla::dom::ContentChild::GetSingleton();
-        for (SystemFontListEntry& fle : cc->SystemFontList()) {
+        auto& fontList = dom::ContentChild::GetSingleton()->SystemFontList();
+        for (SystemFontListEntry& fle : fontList) {
             MOZ_ASSERT(fle.type() ==
                        SystemFontListEntry::Type::TFontFamilyListEntry);
             FontFamilyListEntry& ffe(fle);
             switch (ffe.entryType()) {
             case kStandardFontFamily:
                 AddFamily(ffe.familyName(), false);
                 break;
             case kHiddenSystemFontFamily:
@@ -1117,18 +1125,16 @@ gfxMacPlatformFontList::InitFontListForP
                 mSystemTextFontFamilyName = ffe.familyName();
                 break;
             case kDisplaySizeSystemFontFamily:
                 mSystemDisplayFontFamilyName = ffe.familyName();
                 mUseSizeSensitiveSystemFont = true;
                 break;
             }
         }
-        // The ContentChild doesn't need the font list any longer.
-        cc->SystemFontList().Clear();
     }
 
     // If this is the chrome process, or if for some reason we failed to get
     // a usable list above, get the available fonts from Core Text.
     if (!mFontFamilies.Count()) {
         InitSystemFontNames();
         CFArrayRef familyNames = CTFontManagerCopyAvailableFontFamilyNames();
         for (NSString* familyName in (NSArray*)familyNames) {
@@ -1342,16 +1348,18 @@ gfxMacPlatformFontList::RegisteredFontsC
 
     gfxMacPlatformFontList* fl = static_cast<gfxMacPlatformFontList*>(observer);
 
     // xxx - should be carefully pruning the list of fonts, not rebuilding it from scratch
     fl->UpdateFontList();
 
     // modify a preference that will trigger reflow everywhere
     fl->ForceGlobalReflow();
+
+    mozilla::dom::ContentParent::NotifyUpdatedFonts();
 }
 
 gfxFontEntry*
 gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t aCh,
                                                    Script aRunScript,
                                                    const gfxFontStyle* aMatchStyle,
                                                    gfxFontFamily** aMatchedFamily)
 {