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 | * Copyright 2010 The Android Open Source Project |
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 | |
michael@0 | 9 | #include "SkJpegUtility.h" |
michael@0 | 10 | |
michael@0 | 11 | ///////////////////////////////////////////////////////////////////// |
michael@0 | 12 | static void sk_init_source(j_decompress_ptr cinfo) { |
michael@0 | 13 | skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
michael@0 | 14 | src->next_input_byte = (const JOCTET*)src->fBuffer; |
michael@0 | 15 | src->bytes_in_buffer = 0; |
michael@0 | 16 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 17 | src->current_offset = 0; |
michael@0 | 18 | #endif |
michael@0 | 19 | if (!src->fStream->rewind()) { |
michael@0 | 20 | SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); |
michael@0 | 21 | cinfo->err->error_exit((j_common_ptr)cinfo); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 26 | static boolean sk_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { |
michael@0 | 27 | skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
michael@0 | 28 | size_t bo = (size_t) byte_offset; |
michael@0 | 29 | |
michael@0 | 30 | if (bo > src->current_offset) { |
michael@0 | 31 | (void)src->fStream->skip(bo - src->current_offset); |
michael@0 | 32 | } else { |
michael@0 | 33 | if (!src->fStream->rewind()) { |
michael@0 | 34 | SkDebugf("xxxxxxxxxxxxxx failure to rewind\n"); |
michael@0 | 35 | cinfo->err->error_exit((j_common_ptr)cinfo); |
michael@0 | 36 | return false; |
michael@0 | 37 | } |
michael@0 | 38 | (void)src->fStream->skip(bo); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | src->current_offset = bo; |
michael@0 | 42 | src->next_input_byte = (const JOCTET*)src->fBuffer; |
michael@0 | 43 | src->bytes_in_buffer = 0; |
michael@0 | 44 | return true; |
michael@0 | 45 | } |
michael@0 | 46 | #endif |
michael@0 | 47 | |
michael@0 | 48 | static boolean sk_fill_input_buffer(j_decompress_ptr cinfo) { |
michael@0 | 49 | skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
michael@0 | 50 | if (src->fDecoder != NULL && src->fDecoder->shouldCancelDecode()) { |
michael@0 | 51 | return FALSE; |
michael@0 | 52 | } |
michael@0 | 53 | size_t bytes = src->fStream->read(src->fBuffer, skjpeg_source_mgr::kBufferSize); |
michael@0 | 54 | // note that JPEG is happy with less than the full read, |
michael@0 | 55 | // as long as the result is non-zero |
michael@0 | 56 | if (bytes == 0) { |
michael@0 | 57 | return FALSE; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 61 | src->current_offset += bytes; |
michael@0 | 62 | #endif |
michael@0 | 63 | src->next_input_byte = (const JOCTET*)src->fBuffer; |
michael@0 | 64 | src->bytes_in_buffer = bytes; |
michael@0 | 65 | return TRUE; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | static void sk_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { |
michael@0 | 69 | skjpeg_source_mgr* src = (skjpeg_source_mgr*)cinfo->src; |
michael@0 | 70 | |
michael@0 | 71 | if (num_bytes > (long)src->bytes_in_buffer) { |
michael@0 | 72 | size_t bytesToSkip = num_bytes - src->bytes_in_buffer; |
michael@0 | 73 | while (bytesToSkip > 0) { |
michael@0 | 74 | size_t bytes = src->fStream->skip(bytesToSkip); |
michael@0 | 75 | if (bytes <= 0 || bytes > bytesToSkip) { |
michael@0 | 76 | // SkDebugf("xxxxxxxxxxxxxx failure to skip request %d returned %d\n", bytesToSkip, bytes); |
michael@0 | 77 | cinfo->err->error_exit((j_common_ptr)cinfo); |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 81 | src->current_offset += bytes; |
michael@0 | 82 | #endif |
michael@0 | 83 | bytesToSkip -= bytes; |
michael@0 | 84 | } |
michael@0 | 85 | src->next_input_byte = (const JOCTET*)src->fBuffer; |
michael@0 | 86 | src->bytes_in_buffer = 0; |
michael@0 | 87 | } else { |
michael@0 | 88 | src->next_input_byte += num_bytes; |
michael@0 | 89 | src->bytes_in_buffer -= num_bytes; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | static void sk_term_source(j_decompress_ptr /*cinfo*/) {} |
michael@0 | 94 | |
michael@0 | 95 | |
michael@0 | 96 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 97 | |
michael@0 | 98 | skjpeg_source_mgr::skjpeg_source_mgr(SkStream* stream, SkImageDecoder* decoder) |
michael@0 | 99 | : fStream(SkRef(stream)) |
michael@0 | 100 | , fDecoder(decoder) { |
michael@0 | 101 | |
michael@0 | 102 | init_source = sk_init_source; |
michael@0 | 103 | fill_input_buffer = sk_fill_input_buffer; |
michael@0 | 104 | skip_input_data = sk_skip_input_data; |
michael@0 | 105 | resync_to_restart = jpeg_resync_to_restart; |
michael@0 | 106 | term_source = sk_term_source; |
michael@0 | 107 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 108 | seek_input_data = sk_seek_input_data; |
michael@0 | 109 | #endif |
michael@0 | 110 | // SkDebugf("**************** use memorybase %p %d\n", fMemoryBase, fMemoryBaseSize); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | skjpeg_source_mgr::~skjpeg_source_mgr() { |
michael@0 | 114 | SkSafeUnref(fStream); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 118 | |
michael@0 | 119 | static void sk_init_destination(j_compress_ptr cinfo) { |
michael@0 | 120 | skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; |
michael@0 | 121 | |
michael@0 | 122 | dest->next_output_byte = dest->fBuffer; |
michael@0 | 123 | dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | static boolean sk_empty_output_buffer(j_compress_ptr cinfo) { |
michael@0 | 127 | skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; |
michael@0 | 128 | |
michael@0 | 129 | // if (!dest->fStream->write(dest->fBuffer, skjpeg_destination_mgr::kBufferSize - dest->free_in_buffer)) |
michael@0 | 130 | if (!dest->fStream->write(dest->fBuffer, |
michael@0 | 131 | skjpeg_destination_mgr::kBufferSize)) { |
michael@0 | 132 | ERREXIT(cinfo, JERR_FILE_WRITE); |
michael@0 | 133 | return false; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | dest->next_output_byte = dest->fBuffer; |
michael@0 | 137 | dest->free_in_buffer = skjpeg_destination_mgr::kBufferSize; |
michael@0 | 138 | return TRUE; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | static void sk_term_destination (j_compress_ptr cinfo) { |
michael@0 | 142 | skjpeg_destination_mgr* dest = (skjpeg_destination_mgr*)cinfo->dest; |
michael@0 | 143 | |
michael@0 | 144 | size_t size = skjpeg_destination_mgr::kBufferSize - dest->free_in_buffer; |
michael@0 | 145 | if (size > 0) { |
michael@0 | 146 | if (!dest->fStream->write(dest->fBuffer, size)) { |
michael@0 | 147 | ERREXIT(cinfo, JERR_FILE_WRITE); |
michael@0 | 148 | return; |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | dest->fStream->flush(); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | skjpeg_destination_mgr::skjpeg_destination_mgr(SkWStream* stream) |
michael@0 | 155 | : fStream(stream) { |
michael@0 | 156 | this->init_destination = sk_init_destination; |
michael@0 | 157 | this->empty_output_buffer = sk_empty_output_buffer; |
michael@0 | 158 | this->term_destination = sk_term_destination; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | void skjpeg_error_exit(j_common_ptr cinfo) { |
michael@0 | 162 | skjpeg_error_mgr* error = (skjpeg_error_mgr*)cinfo->err; |
michael@0 | 163 | |
michael@0 | 164 | (*error->output_message) (cinfo); |
michael@0 | 165 | |
michael@0 | 166 | /* Let the memory manager delete any temp files before we die */ |
michael@0 | 167 | jpeg_destroy(cinfo); |
michael@0 | 168 | |
michael@0 | 169 | longjmp(error->fJmpBuf, -1); |
michael@0 | 170 | } |