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 2013 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 | #ifdef SK_BUILD_FOR_WIN32 |
michael@0 | 10 | #pragma warning(push) |
michael@0 | 11 | #pragma warning(disable : 4530) |
michael@0 | 12 | #endif |
michael@0 | 13 | |
michael@0 | 14 | #include "SkPDFRasterizer.h" |
michael@0 | 15 | #include "SkColorPriv.h" |
michael@0 | 16 | |
michael@0 | 17 | #ifdef SK_BUILD_NATIVE_PDF_RENDERER |
michael@0 | 18 | #include "SkPdfRenderer.h" |
michael@0 | 19 | #endif // SK_BUILD_NATIVE_PDF_RENDERER |
michael@0 | 20 | |
michael@0 | 21 | #ifdef SK_BUILD_POPPLER |
michael@0 | 22 | #include <poppler-document.h> |
michael@0 | 23 | #include <poppler-image.h> |
michael@0 | 24 | #include <poppler-page.h> |
michael@0 | 25 | #include <poppler-page-renderer.h> |
michael@0 | 26 | #endif // SK_BUILD_POPPLER |
michael@0 | 27 | |
michael@0 | 28 | #ifdef SK_BUILD_POPPLER |
michael@0 | 29 | bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output) { |
michael@0 | 30 | size_t size = pdf->getLength(); |
michael@0 | 31 | SkAutoFree buffer(sk_malloc_throw(size)); |
michael@0 | 32 | pdf->read(buffer.get(), size); |
michael@0 | 33 | |
michael@0 | 34 | SkAutoTDelete<poppler::document> doc( |
michael@0 | 35 | poppler::document::load_from_raw_data((const char*)buffer.get(), size)); |
michael@0 | 36 | if (!doc.get() || doc->is_locked()) { |
michael@0 | 37 | return false; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | SkAutoTDelete<poppler::page> page(doc->create_page(0)); |
michael@0 | 41 | poppler::page_renderer renderer; |
michael@0 | 42 | poppler::image image = renderer.render_page(page.get()); |
michael@0 | 43 | |
michael@0 | 44 | if (!image.is_valid() || image.format() != poppler::image::format_argb32) { |
michael@0 | 45 | return false; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | int width = image.width(), height = image.height(); |
michael@0 | 49 | size_t rowSize = image.bytes_per_row(); |
michael@0 | 50 | char *imgData = image.data(); |
michael@0 | 51 | |
michael@0 | 52 | SkBitmap bitmap; |
michael@0 | 53 | if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height))) { |
michael@0 | 54 | return false; |
michael@0 | 55 | } |
michael@0 | 56 | bitmap.eraseColor(SK_ColorWHITE); |
michael@0 | 57 | SkPMColor* bitmapPixels = (SkPMColor*)bitmap.getPixels(); |
michael@0 | 58 | |
michael@0 | 59 | // do pixel-by-pixel copy to deal with RGBA ordering conversions |
michael@0 | 60 | for (int y = 0; y < height; y++) { |
michael@0 | 61 | char *rowData = imgData; |
michael@0 | 62 | for (int x = 0; x < width; x++) { |
michael@0 | 63 | uint8_t a = rowData[3]; |
michael@0 | 64 | uint8_t r = rowData[2]; |
michael@0 | 65 | uint8_t g = rowData[1]; |
michael@0 | 66 | uint8_t b = rowData[0]; |
michael@0 | 67 | |
michael@0 | 68 | *bitmapPixels = SkPreMultiplyARGB(a, r, g, b); |
michael@0 | 69 | |
michael@0 | 70 | bitmapPixels++; |
michael@0 | 71 | rowData += 4; |
michael@0 | 72 | } |
michael@0 | 73 | imgData += rowSize; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | output->swap(bitmap); |
michael@0 | 77 | |
michael@0 | 78 | return true; |
michael@0 | 79 | } |
michael@0 | 80 | #endif // SK_BUILD_POPPLER |
michael@0 | 81 | |
michael@0 | 82 | #ifdef SK_BUILD_NATIVE_PDF_RENDERER |
michael@0 | 83 | bool SkNativeRasterizePDF(SkStream* pdf, SkBitmap* output) { |
michael@0 | 84 | return SkPDFNativeRenderToBitmap(pdf, output); |
michael@0 | 85 | } |
michael@0 | 86 | #endif // SK_BUILD_NATIVE_PDF_RENDERER |