Bug 1557905. Stop using [array] in nsIFontEnumerator. r=jfkthame
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 08 Jun 2019 08:50:47 +0000
changeset 477975 70c625953221148ac03b42a22934571275ebdf20
parent 477974 c9da20a36d96b34bbd0063deb6dbf6b8fea87d00
child 477976 83e6d4980c56ad867555af98dcebc67b3ac3e803
push id36129
push userncsoregi@mozilla.com
push dateSun, 09 Jun 2019 09:06:18 +0000
treeherdermozilla-central@c5ddef8c691b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1557905
milestone69.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 1557905. Stop using [array] in nsIFontEnumerator. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D34265
gfx/src/nsIFontEnumerator.idl
gfx/src/nsThebesFontEnumerator.cpp
layout/base/tests/test_bug394057.html
layout/base/tests/test_bug548545.xhtml
--- a/gfx/src/nsIFontEnumerator.idl
+++ b/gfx/src/nsIFontEnumerator.idl
@@ -7,35 +7,31 @@
 #include "nsISupports.idl"
 
 [scriptable, uuid(924d98d9-3518-4cb4-8708-c74fe8e3ec3c)]
 interface nsIFontEnumerator : nsISupports
 {
   /**
    * Return a sorted array of the names of all installed fonts.
    *
-   * @param  aCount     returns number of names returned
-   * @param  aResult    returns array of names
+   * @return array of names
    * @return void
    */
-  void EnumerateAllFonts(out uint32_t aCount,
-    [retval, array, size_is(aCount)] out wstring aResult);
+  Array<AString> EnumerateAllFonts();
 
   /**
    * Return a sorted array of names of fonts that support the given language
    * group and are suitable for use as the given CSS generic font.
    *
    * @param  aLangGroup language group
    * @param  aGeneric   CSS generic font
-   * @param  aCount     returns number of names returned
-   * @param  aResult    returns array of names
+   * @return            array of names
    * @return void
    */
-  void EnumerateFonts(in string aLangGroup, in string aGeneric,
-    out uint32_t aCount, [retval, array, size_is(aCount)] out wstring aResult);
+  Array<AString> EnumerateFonts(in string aLangGroup, in string aGeneric);
 
   /**
    * Return a promise that resolves to a sorted array of the names of all
    * installed fonts.
    *
    * @return Promise that resolves to Array
    */
   [implicit_jscontext]
--- a/gfx/src/nsThebesFontEnumerator.cpp
+++ b/gfx/src/nsThebesFontEnumerator.cpp
@@ -18,64 +18,40 @@
 #include "nsTArray.h"  // for nsTArray, nsTArray_Impl, etc
 #include "nscore.h"    // for char16_t, NS_IMETHODIMP
 
 NS_IMPL_ISUPPORTS(nsThebesFontEnumerator, nsIFontEnumerator)
 
 nsThebesFontEnumerator::nsThebesFontEnumerator() {}
 
 NS_IMETHODIMP
-nsThebesFontEnumerator::EnumerateAllFonts(uint32_t* aCount,
-                                          char16_t*** aResult) {
-  return EnumerateFonts(nullptr, nullptr, aCount, aResult);
+nsThebesFontEnumerator::EnumerateAllFonts(nsTArray<nsString>& aResult) {
+  return EnumerateFonts(nullptr, nullptr, aResult);
 }
 
 NS_IMETHODIMP
 nsThebesFontEnumerator::EnumerateFonts(const char* aLangGroup,
-                                       const char* aGeneric, uint32_t* aCount,
-                                       char16_t*** aResult) {
-  NS_ENSURE_ARG_POINTER(aCount);
-  NS_ENSURE_ARG_POINTER(aResult);
-
-  nsTArray<nsString> fontList;
-
+                                       const char* aGeneric,
+                                       nsTArray<nsString>& aResult) {
   nsAutoCString generic;
   if (aGeneric)
     generic.Assign(aGeneric);
   else
     generic.SetIsVoid(true);
 
   RefPtr<nsAtom> langGroupAtom;
   if (aLangGroup) {
     nsAutoCString lowered;
     lowered.Assign(aLangGroup);
     ToLowerCase(lowered);
     langGroupAtom = NS_Atomize(lowered);
   }
 
-  nsresult rv =
-      gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
-
-  if (NS_FAILED(rv)) {
-    *aCount = 0;
-    *aResult = nullptr;
-    /* XXX in this case, do we want to return the CSS generics? */
-    return NS_OK;
-  }
-
-  char16_t** fs = static_cast<char16_t**>(
-      moz_xmalloc(fontList.Length() * sizeof(char16_t*)));
-  for (uint32_t i = 0; i < fontList.Length(); i++) {
-    fs[i] = ToNewUnicode(fontList[i]);
-  }
-
-  *aResult = fs;
-  *aCount = fontList.Length();
-
-  return NS_OK;
+  return gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic,
+                                                 aResult);
 }
 
 struct EnumerateFontsPromise final {
   explicit EnumerateFontsPromise(mozilla::dom::Promise* aPromise)
       : mPromise(aPromise) {
     MOZ_ASSERT(aPromise);
     MOZ_ASSERT(NS_IsMainThread());
   }
--- a/layout/base/tests/test_bug394057.html
+++ b/layout/base/tests/test_bug394057.html
@@ -28,18 +28,18 @@ SimpleTest.waitForExplicitFinish();
 
 var tableElement = document.getElementById("display");
 
 var CC = SpecialPowers.Cc;
 var CI = SpecialPowers.Ci;
 
 var fe =
   CC["@mozilla.org/gfx/fontenumerator;1"].createInstance(CI.nsIFontEnumerator);
-var serifFonts = fe.EnumerateFonts("x-western", "serif", {});
-var monospaceFonts = fe.EnumerateFonts("x-western", "monospace", {});
+var serifFonts = fe.EnumerateFonts("x-western", "serif");
+var monospaceFonts = fe.EnumerateFonts("x-western", "monospace");
 
 function table_width_for_font(font) {
   tableElement.style.fontFamily = '"' + font + '"';
   var result = tableElement.offsetWidth;
   tableElement.style.fontFamily = "";
   return result;
 }
 
--- a/layout/base/tests/test_bug548545.xhtml
+++ b/layout/base/tests/test_bug548545.xhtml
@@ -23,17 +23,17 @@ SimpleTest.waitForExplicitFinish();
 
 var content = document.getElementById("content");
 
 var CC = SpecialPowers.Cc;
 var CI = SpecialPowers.Ci;
 
 var fe =
   CC["@mozilla.org/gfx/fontenumerator;1"].createInstance(CI.nsIFontEnumerator);
-var allFonts = fe.EnumerateFonts(null, null, {});
+var allFonts = fe.EnumerateFonts(null, null);
 
 var idx = 0;
 var list = "";
 for (idx in allFonts) {
   list += allFonts[idx] + "<br/>";
 }
 content.innerHTML = list;