gfx/skia/trunk/src/images/SkImageDecoder_FactoryRegistrar.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 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 #include "SkErrorInternals.h"
michael@0 9 #include "SkImageDecoder.h"
michael@0 10 #include "SkStream.h"
michael@0 11 #include "SkTRegistry.h"
michael@0 12
michael@0 13 // This file is used for registration of SkImageDecoders. It also holds a function
michael@0 14 // for checking all the the registered SkImageDecoders for one that matches an
michael@0 15 // input SkStreamRewindable.
michael@0 16
michael@0 17 template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead;
michael@0 18
michael@0 19 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
michael@0 20
michael@0 21 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable* stream) {
michael@0 22 SkImageDecoder* codec = NULL;
michael@0 23 const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head();
michael@0 24 while (curr) {
michael@0 25 codec = curr->factory()(stream);
michael@0 26 // we rewind here, because we promise later when we call "decode", that
michael@0 27 // the stream will be at its beginning.
michael@0 28 bool rewindSuceeded = stream->rewind();
michael@0 29
michael@0 30 // our image decoder's require that rewind is supported so we fail early
michael@0 31 // if we are given a stream that does not support rewinding.
michael@0 32 if (!rewindSuceeded) {
michael@0 33 SkDEBUGF(("Unable to rewind the image stream."));
michael@0 34 SkDELETE(codec);
michael@0 35 return NULL;
michael@0 36 }
michael@0 37
michael@0 38 if (codec) {
michael@0 39 return codec;
michael@0 40 }
michael@0 41 curr = curr->next();
michael@0 42 }
michael@0 43 return NULL;
michael@0 44 }
michael@0 45
michael@0 46 template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead;
michael@0 47
michael@0 48 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* stream) {
michael@0 49 const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head();
michael@0 50 while (curr != NULL) {
michael@0 51 Format format = curr->factory()(stream);
michael@0 52 if (!stream->rewind()) {
michael@0 53 SkErrorInternals::SetError(kInvalidOperation_SkError,
michael@0 54 "Unable to rewind the image stream\n");
michael@0 55 return kUnknown_Format;
michael@0 56 }
michael@0 57 if (format != kUnknown_Format) {
michael@0 58 return format;
michael@0 59 }
michael@0 60 curr = curr->next();
michael@0 61 }
michael@0 62 return kUnknown_Format;
michael@0 63 }

mercurial