gfx/skia/trunk/src/utils/mac/SkStream_mac.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 2012 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 "SkCGUtils.h"
michael@0 9 #include "SkStream.h"
michael@0 10
michael@0 11 // This is used by CGDataProviderCreateWithData
michael@0 12
michael@0 13 static void unref_proc(void* info, const void* addr, size_t size) {
michael@0 14 SkASSERT(info);
michael@0 15 ((SkRefCnt*)info)->unref();
michael@0 16 }
michael@0 17
michael@0 18 // These are used by CGDataProviderSequentialCallbacks
michael@0 19
michael@0 20 static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) {
michael@0 21 SkASSERT(info);
michael@0 22 return ((SkStream*)info)->read(buffer, bytes);
michael@0 23 }
michael@0 24
michael@0 25 static off_t skip_forward_proc(void* info, off_t bytes) {
michael@0 26 return ((SkStream*)info)->skip((size_t) bytes);
michael@0 27 }
michael@0 28
michael@0 29 static void rewind_proc(void* info) {
michael@0 30 SkASSERT(info);
michael@0 31 ((SkStream*)info)->rewind();
michael@0 32 }
michael@0 33
michael@0 34 static void release_info_proc(void* info) {
michael@0 35 SkASSERT(info);
michael@0 36 ((SkStream*)info)->unref();
michael@0 37 }
michael@0 38
michael@0 39 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) {
michael@0 40 stream->ref(); // unref will be called when the provider is deleted
michael@0 41
michael@0 42 const void* addr = stream->getMemoryBase();
michael@0 43 if (addr) {
michael@0 44 // special-case when the stream is just a block of ram
michael@0 45 return CGDataProviderCreateWithData(stream, addr, stream->getLength(),
michael@0 46 unref_proc);
michael@0 47 }
michael@0 48
michael@0 49 CGDataProviderSequentialCallbacks rec;
michael@0 50 sk_bzero(&rec, sizeof(rec));
michael@0 51 rec.version = 0;
michael@0 52 rec.getBytes = get_bytes_proc;
michael@0 53 rec.skipForward = skip_forward_proc;
michael@0 54 rec.rewind = rewind_proc;
michael@0 55 rec.releaseInfo = release_info_proc;
michael@0 56 return CGDataProviderCreateSequential(stream, &rec);
michael@0 57 }
michael@0 58
michael@0 59 ///////////////////////////////////////////////////////////////////////////////
michael@0 60
michael@0 61 #include "SkData.h"
michael@0 62
michael@0 63 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) {
michael@0 64 data->ref();
michael@0 65 return CGDataProviderCreateWithData(data, data->data(), data->size(),
michael@0 66 unref_proc);
michael@0 67 }

mercurial