gfx/thebes/gfxDWriteCommon.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 "gfxDWriteCommon.h"
     8 IDWriteFontFileLoader* gfxDWriteFontFileLoader::mInstance = nullptr;
    10 HRESULT STDMETHODCALLTYPE
    11 gfxDWriteFontFileLoader::CreateStreamFromKey(const void *fontFileReferenceKey, 
    12                                              UINT32 fontFileReferenceKeySize, 
    13                                              IDWriteFontFileStream **fontFileStream)
    14 {
    15     if (!fontFileReferenceKey || !fontFileStream) {
    16         return E_POINTER;
    17     }
    19     *fontFileStream = 
    20         new gfxDWriteFontFileStream(
    21         static_cast<const ffReferenceKey*>(fontFileReferenceKey)->mArray);
    23     if (!*fontFileStream) {
    24         return E_OUTOFMEMORY;
    25     }
    26     (*fontFileStream)->AddRef();
    27     return S_OK;
    28 }
    30 gfxDWriteFontFileStream::gfxDWriteFontFileStream(FallibleTArray<uint8_t> *aData)
    31 {
    32     mData.SwapElements(*aData);
    33 }
    35 gfxDWriteFontFileStream::~gfxDWriteFontFileStream()
    36 {
    37 }
    39 HRESULT STDMETHODCALLTYPE
    40 gfxDWriteFontFileStream::GetFileSize(UINT64 *fileSize)
    41 {
    42     *fileSize = mData.Length();
    43     return S_OK;
    44 }
    46 HRESULT STDMETHODCALLTYPE
    47 gfxDWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime)
    48 {
    49     return E_NOTIMPL;
    50 }
    52 HRESULT STDMETHODCALLTYPE
    53 gfxDWriteFontFileStream::ReadFileFragment(const void **fragmentStart,
    54                                           UINT64 fileOffset,
    55                                           UINT64 fragmentSize,
    56                                           void **fragmentContext)
    57 {
    58     // We are required to do bounds checking.
    59     if (fileOffset + fragmentSize > (UINT64)mData.Length()) {
    60         return E_FAIL;
    61     }
    62     // We should be alive for the duration of this.
    63     *fragmentStart = &mData[fileOffset];
    64     *fragmentContext = nullptr;
    65     return S_OK;
    66 }
    68 void STDMETHODCALLTYPE
    69 gfxDWriteFontFileStream::ReleaseFileFragment(void *fragmentContext)
    70 {
    71 }

mercurial