Sat, 03 Jan 2015 20:18:00 +0100
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 | /* |
michael@0 | 3 | * Copyright 2010 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "SkData.h" |
michael@0 | 11 | #include "SkFlate.h" |
michael@0 | 12 | #include "SkPDFCatalog.h" |
michael@0 | 13 | #include "SkPDFStream.h" |
michael@0 | 14 | #include "SkStream.h" |
michael@0 | 15 | |
michael@0 | 16 | static bool skip_compression(SkPDFCatalog* catalog) { |
michael@0 | 17 | return SkToBool(catalog->getDocumentFlags() & |
michael@0 | 18 | SkPDFDocument::kFavorSpeedOverSize_Flags); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) { |
michael@0 | 22 | setData(stream); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { |
michael@0 | 26 | setData(data); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) |
michael@0 | 30 | : SkPDFDict(), |
michael@0 | 31 | fState(kUnused_State) { |
michael@0 | 32 | setData(pdfStream.fData.get()); |
michael@0 | 33 | bool removeLength = true; |
michael@0 | 34 | // Don't uncompress an already compressed stream, but we could. |
michael@0 | 35 | if (pdfStream.fState == kCompressed_State) { |
michael@0 | 36 | fState = kCompressed_State; |
michael@0 | 37 | removeLength = false; |
michael@0 | 38 | } |
michael@0 | 39 | SkPDFDict::Iter dict(pdfStream); |
michael@0 | 40 | SkPDFName* key; |
michael@0 | 41 | SkPDFObject* value; |
michael@0 | 42 | SkPDFName lengthName("Length"); |
michael@0 | 43 | for (key = dict.next(&value); key != NULL; key = dict.next(&value)) { |
michael@0 | 44 | if (removeLength && *key == lengthName) { |
michael@0 | 45 | continue; |
michael@0 | 46 | } |
michael@0 | 47 | this->insert(key, value); |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | SkPDFStream::~SkPDFStream() {} |
michael@0 | 52 | |
michael@0 | 53 | void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
michael@0 | 54 | bool indirect) { |
michael@0 | 55 | if (indirect) { |
michael@0 | 56 | return emitIndirectObject(stream, catalog); |
michael@0 | 57 | } |
michael@0 | 58 | if (!this->populate(catalog)) { |
michael@0 | 59 | return fSubstitute->emitObject(stream, catalog, indirect); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | this->INHERITED::emitObject(stream, catalog, false); |
michael@0 | 63 | stream->writeText(" stream\n"); |
michael@0 | 64 | stream->writeStream(fData.get(), fData->getLength()); |
michael@0 | 65 | fData->rewind(); |
michael@0 | 66 | stream->writeText("\nendstream"); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) { |
michael@0 | 70 | if (indirect) { |
michael@0 | 71 | return getIndirectOutputSize(catalog); |
michael@0 | 72 | } |
michael@0 | 73 | if (!this->populate(catalog)) { |
michael@0 | 74 | return fSubstitute->getOutputSize(catalog, indirect); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | return this->INHERITED::getOutputSize(catalog, false) + |
michael@0 | 78 | strlen(" stream\n\nendstream") + fData->getLength(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | SkPDFStream::SkPDFStream() : fState(kUnused_State) {} |
michael@0 | 82 | |
michael@0 | 83 | void SkPDFStream::setData(SkData* data) { |
michael@0 | 84 | SkMemoryStream* stream = new SkMemoryStream; |
michael@0 | 85 | stream->setData(data); |
michael@0 | 86 | fData.reset(stream); // Transfer ownership. |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void SkPDFStream::setData(SkStream* stream) { |
michael@0 | 90 | // Code assumes that the stream starts at the beginning and is rewindable. |
michael@0 | 91 | if (stream) { |
michael@0 | 92 | SkASSERT(stream->getPosition() == 0); |
michael@0 | 93 | SkASSERT(stream->rewind()); |
michael@0 | 94 | } |
michael@0 | 95 | fData.reset(stream); |
michael@0 | 96 | SkSafeRef(stream); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | bool SkPDFStream::populate(SkPDFCatalog* catalog) { |
michael@0 | 100 | if (fState == kUnused_State) { |
michael@0 | 101 | if (!skip_compression(catalog) && SkFlate::HaveFlate()) { |
michael@0 | 102 | SkDynamicMemoryWStream compressedData; |
michael@0 | 103 | |
michael@0 | 104 | SkAssertResult(SkFlate::Deflate(fData.get(), &compressedData)); |
michael@0 | 105 | if (compressedData.getOffset() < fData->getLength()) { |
michael@0 | 106 | SkMemoryStream* stream = new SkMemoryStream; |
michael@0 | 107 | stream->setData(compressedData.copyToData())->unref(); |
michael@0 | 108 | fData.reset(stream); // Transfer ownership. |
michael@0 | 109 | insertName("Filter", "FlateDecode"); |
michael@0 | 110 | } |
michael@0 | 111 | fState = kCompressed_State; |
michael@0 | 112 | } else { |
michael@0 | 113 | fState = kNoCompression_State; |
michael@0 | 114 | } |
michael@0 | 115 | insertInt("Length", fData->getLength()); |
michael@0 | 116 | } else if (fState == kNoCompression_State && !skip_compression(catalog) && |
michael@0 | 117 | SkFlate::HaveFlate()) { |
michael@0 | 118 | if (!fSubstitute.get()) { |
michael@0 | 119 | fSubstitute.reset(new SkPDFStream(*this)); |
michael@0 | 120 | catalog->setSubstitute(this, fSubstitute.get()); |
michael@0 | 121 | } |
michael@0 | 122 | return false; |
michael@0 | 123 | } |
michael@0 | 124 | return true; |
michael@0 | 125 | } |