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