gfx/src/nsThebesFontEnumerator.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsThebesFontEnumerator.h"
     7 #include <stdint.h>                     // for uint32_t
     8 #include "gfxPlatform.h"                // for gfxPlatform
     9 #include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2
    10 #include "nsCOMPtr.h"                   // for nsCOMPtr
    11 #include "nsDebug.h"                    // for NS_ENSURE_ARG_POINTER
    12 #include "nsError.h"                    // for NS_OK, NS_FAILED, nsresult
    13 #include "nsIAtom.h"                    // for nsIAtom, do_GetAtom
    14 #include "nsID.h"
    15 #include "nsMemory.h"                   // for nsMemory
    16 #include "nsString.h"               // for nsAutoCString, nsAutoString, etc
    17 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl, etc
    18 #include "nscore.h"                     // for char16_t, NS_IMETHODIMP
    20 NS_IMPL_ISUPPORTS(nsThebesFontEnumerator, nsIFontEnumerator)
    22 nsThebesFontEnumerator::nsThebesFontEnumerator()
    23 {
    24 }
    26 NS_IMETHODIMP
    27 nsThebesFontEnumerator::EnumerateAllFonts(uint32_t *aCount,
    28                                           char16_t ***aResult)
    29 {
    30     return EnumerateFonts (nullptr, nullptr, aCount, aResult);
    31 }
    33 NS_IMETHODIMP
    34 nsThebesFontEnumerator::EnumerateFonts(const char *aLangGroup,
    35                                        const char *aGeneric,
    36                                        uint32_t *aCount,
    37                                        char16_t ***aResult)
    38 {
    39     NS_ENSURE_ARG_POINTER(aCount);
    40     NS_ENSURE_ARG_POINTER(aResult);
    42     nsTArray<nsString> fontList;
    44     nsAutoCString generic;
    45     if (aGeneric)
    46         generic.Assign(aGeneric);
    47     else
    48         generic.SetIsVoid(true);
    50     nsCOMPtr<nsIAtom> langGroupAtom;
    51     if (aLangGroup) {
    52         nsAutoCString lowered;
    53         lowered.Assign(aLangGroup);
    54         ToLowerCase(lowered);
    55         langGroupAtom = do_GetAtom(lowered);
    56     }
    58     nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
    60     if (NS_FAILED(rv)) {
    61         *aCount = 0;
    62         *aResult = nullptr;
    63         /* XXX in this case, do we want to return the CSS generics? */
    64         return NS_OK;
    65     }
    67     char16_t **fs = static_cast<char16_t **>
    68                                 (nsMemory::Alloc(fontList.Length() * sizeof(char16_t*)));
    69     for (uint32_t i = 0; i < fontList.Length(); i++) {
    70         fs[i] = ToNewUnicode(fontList[i]);
    71     }
    73     *aResult = fs;
    74     *aCount = fontList.Length();
    76     return NS_OK;
    77 }
    79 NS_IMETHODIMP
    80 nsThebesFontEnumerator::HaveFontFor(const char *aLangGroup,
    81                                     bool *aResult)
    82 {
    83     NS_ENSURE_ARG_POINTER(aResult);
    85     *aResult = true;
    86     return NS_OK;
    87 }
    89 NS_IMETHODIMP
    90 nsThebesFontEnumerator::GetDefaultFont(const char *aLangGroup,
    91                                        const char *aGeneric,
    92                                        char16_t **aResult)
    93 {
    94     NS_ENSURE_ARG_POINTER(aResult);
    95     *aResult = nullptr;
    96     return NS_OK;
    97 }
    99 NS_IMETHODIMP
   100 nsThebesFontEnumerator::UpdateFontList(bool *_retval)
   101 {
   102     gfxPlatform::GetPlatform()->UpdateFontList();
   103     *_retval = false; // always return false for now
   104     return NS_OK;
   105 }
   107 NS_IMETHODIMP
   108 nsThebesFontEnumerator::GetStandardFamilyName(const char16_t *aName,
   109                                               char16_t **aResult)
   110 {
   111     NS_ENSURE_ARG_POINTER(aResult);
   112     NS_ENSURE_ARG_POINTER(aName);
   114     nsAutoString name(aName);
   115     if (name.IsEmpty()) {
   116         *aResult = nullptr;
   117         return NS_OK;
   118     }
   120     nsAutoString family;
   121     nsresult rv = gfxPlatform::GetPlatform()->
   122         GetStandardFamilyName(nsDependentString(aName), family);
   123     if (NS_FAILED(rv) || family.IsEmpty()) {
   124         *aResult = nullptr;
   125         return NS_OK;
   126     }
   127     *aResult = ToNewUnicode(family);
   128     return NS_OK;
   129 }

mercurial