gfx/thebes/gfxPDFSurface.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 "gfxPDFSurface.h"
     8 #include "cairo.h"
     9 #include "cairo-pdf.h"
    11 static cairo_status_t
    12 write_func(void *closure, const unsigned char *data, unsigned int length)
    13 {
    14     nsCOMPtr<nsIOutputStream> out = reinterpret_cast<nsIOutputStream*>(closure);
    15     do {
    16         uint32_t wrote = 0;
    17         if (NS_FAILED(out->Write((const char*)data, length, &wrote)))
    18             break;
    19         data += wrote; length -= wrote;
    20     } while (length > 0);
    21     NS_ASSERTION(length == 0, "not everything was written to the file");
    22     return CAIRO_STATUS_SUCCESS;
    23 }
    25 gfxPDFSurface::gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints)
    26     : mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
    27 {
    28     Init(cairo_pdf_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height));
    29 }
    31 gfxPDFSurface::~gfxPDFSurface()
    32 {
    33 }
    35 nsresult
    36 gfxPDFSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName)
    37 {
    38     return NS_OK;
    39 }
    41 nsresult
    42 gfxPDFSurface::EndPrinting()
    43 {
    44     return NS_OK;
    45 }
    47 nsresult
    48 gfxPDFSurface::AbortPrinting()
    49 {
    50     return NS_OK;
    51 }
    53 nsresult
    54 gfxPDFSurface::BeginPage()
    55 {
    56     return NS_OK;
    57 }
    59 nsresult
    60 gfxPDFSurface::EndPage()
    61 {
    62     cairo_surface_show_page(CairoSurface());
    63     return NS_OK;
    64 }
    66 void
    67 gfxPDFSurface::Finish()
    68 {
    69     gfxASurface::Finish();
    70     mStream->Close();
    71 }
    73 void
    74 gfxPDFSurface::SetDPI(double xDPI, double yDPI)
    75 {
    76     mXDPI = xDPI;
    77     mYDPI = yDPI;
    78     cairo_surface_set_fallback_resolution(CairoSurface(), xDPI, yDPI);
    79 }
    81 void
    82 gfxPDFSurface::GetDPI(double *xDPI, double *yDPI)
    83 {
    84     *xDPI = mXDPI;
    85     *yDPI = mYDPI;
    86 }

mercurial