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.
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 <assert.h>
8 #include "cairo-features.h"
9 #ifdef CAIRO_HAS_QT_SURFACE
10 #include "cairo-qt.h"
11 #include "gfxQPainterSurface.h"
13 gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
14 {
15 cairo_surface_t *csurf = cairo_qt_surface_create (painter);
17 mPainter = painter;
19 Init (csurf);
20 }
22 gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format)
23 {
24 cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format,
25 size.width,
26 size.height);
27 mPainter = cairo_qt_surface_get_qpainter (csurf);
29 Init (csurf);
30 }
32 gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxContentType content)
33 {
34 cairo_surface_t *csurf = cairo_qt_surface_create_with_qpixmap ((cairo_content_t) content,
35 size.width,
36 size.height);
37 mPainter = cairo_qt_surface_get_qpainter (csurf);
39 Init (csurf);
40 }
42 gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
43 {
44 mPainter = cairo_qt_surface_get_qpainter (csurf);
46 Init(csurf, true);
47 }
49 gfxQPainterSurface::~gfxQPainterSurface()
50 {
51 }
53 QImage *
54 gfxQPainterSurface::GetQImage()
55 {
56 if (!mSurfaceValid)
57 return nullptr;
59 return cairo_qt_surface_get_qimage(CairoSurface());
60 }
62 already_AddRefed<gfxImageSurface>
63 gfxQPainterSurface::GetAsImageSurface()
64 {
65 if (!mSurfaceValid)
66 return nullptr;
68 cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface());
69 if (!isurf)
70 return nullptr;
72 assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE);
74 nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf);
75 asurf->SetOpaqueRect(GetOpaqueRect());
76 return asurf.forget();
77 }
78 #endif