gfx/skia/trunk/src/doc/SkDocument_PDF.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkDocument.h"
michael@0 9 #include "SkPDFDocument.h"
michael@0 10 #include "SkPDFDeviceFlattener.h"
michael@0 11
michael@0 12 class SkDocument_PDF : public SkDocument {
michael@0 13 public:
michael@0 14 SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool),
michael@0 15 SkPicture::EncodeBitmap encoder,
michael@0 16 SkScalar rasterDpi)
michael@0 17 : SkDocument(stream, doneProc)
michael@0 18 , fEncoder(encoder)
michael@0 19 , fRasterDpi(rasterDpi) {
michael@0 20 fDoc = SkNEW(SkPDFDocument);
michael@0 21 fCanvas = NULL;
michael@0 22 fDevice = NULL;
michael@0 23 }
michael@0 24
michael@0 25 virtual ~SkDocument_PDF() {
michael@0 26 // subclasses must call close() in their destructors
michael@0 27 this->close();
michael@0 28 }
michael@0 29
michael@0 30 protected:
michael@0 31 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
michael@0 32 const SkRect& trimBox) SK_OVERRIDE {
michael@0 33 SkASSERT(NULL == fCanvas);
michael@0 34 SkASSERT(NULL == fDevice);
michael@0 35
michael@0 36 SkSize mediaBoxSize;
michael@0 37 mediaBoxSize.set(width, height);
michael@0 38
michael@0 39 fDevice = SkNEW_ARGS(SkPDFDeviceFlattener, (mediaBoxSize, &trimBox));
michael@0 40 if (fEncoder) {
michael@0 41 fDevice->setDCTEncoder(fEncoder);
michael@0 42 }
michael@0 43 if (fRasterDpi != 0) {
michael@0 44 fDevice->setRasterDpi(fRasterDpi);
michael@0 45 }
michael@0 46 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
michael@0 47 return fCanvas;
michael@0 48 }
michael@0 49
michael@0 50 virtual void onEndPage() SK_OVERRIDE {
michael@0 51 SkASSERT(fCanvas);
michael@0 52 SkASSERT(fDevice);
michael@0 53
michael@0 54 fCanvas->flush();
michael@0 55 fDoc->appendPage(fDevice);
michael@0 56
michael@0 57 fCanvas->unref();
michael@0 58 fDevice->unref();
michael@0 59
michael@0 60 fCanvas = NULL;
michael@0 61 fDevice = NULL;
michael@0 62 }
michael@0 63
michael@0 64 virtual bool onClose(SkWStream* stream) SK_OVERRIDE {
michael@0 65 SkASSERT(NULL == fCanvas);
michael@0 66 SkASSERT(NULL == fDevice);
michael@0 67
michael@0 68 bool success = fDoc->emitPDF(stream);
michael@0 69 SkDELETE(fDoc);
michael@0 70 fDoc = NULL;
michael@0 71 return success;
michael@0 72 }
michael@0 73
michael@0 74 virtual void onAbort() SK_OVERRIDE {
michael@0 75 SkDELETE(fDoc);
michael@0 76 fDoc = NULL;
michael@0 77 }
michael@0 78
michael@0 79 private:
michael@0 80 SkPDFDocument* fDoc;
michael@0 81 SkPDFDeviceFlattener* fDevice;
michael@0 82 SkCanvas* fCanvas;
michael@0 83 SkPicture::EncodeBitmap fEncoder;
michael@0 84 SkScalar fRasterDpi;
michael@0 85 };
michael@0 86
michael@0 87 ///////////////////////////////////////////////////////////////////////////////
michael@0 88
michael@0 89 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,bool),
michael@0 90 SkPicture::EncodeBitmap enc,
michael@0 91 SkScalar dpi) {
michael@0 92 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL;
michael@0 93 }
michael@0 94
michael@0 95 static void delete_wstream(SkWStream* stream, bool aborted) {
michael@0 96 SkDELETE(stream);
michael@0 97 }
michael@0 98
michael@0 99 SkDocument* SkDocument::CreatePDF(const char path[],
michael@0 100 SkPicture::EncodeBitmap enc,
michael@0 101 SkScalar dpi) {
michael@0 102 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
michael@0 103 if (!stream->isValid()) {
michael@0 104 SkDELETE(stream);
michael@0 105 return NULL;
michael@0 106 }
michael@0 107 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi));
michael@0 108 }

mercurial