gfx/skia/trunk/include/core/SkData.h

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.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
    11 #ifndef SkData_DEFINED
    12 #define SkData_DEFINED
    14 #include "SkRefCnt.h"
    16 struct SkFILE;
    18 /**
    19  *  SkData holds an immutable data buffer. Not only is the data immutable,
    20  *  but the actual ptr that is returned (by data() or bytes()) is guaranteed
    21  *  to always be the same for the life of this instance.
    22  */
    23 class SK_API SkData : public SkRefCnt {
    24 public:
    25     SK_DECLARE_INST_COUNT(SkData)
    27     /**
    28      *  Returns the number of bytes stored.
    29      */
    30     size_t size() const { return fSize; }
    32     bool isEmpty() const { return 0 == fSize; }
    34     /**
    35      *  Returns the ptr to the data.
    36      */
    37     const void* data() const { return fPtr; }
    39     /**
    40      *  Like data(), returns a read-only ptr into the data, but in this case
    41      *  it is cast to uint8_t*, to make it easy to add an offset to it.
    42      */
    43     const uint8_t* bytes() const {
    44         return reinterpret_cast<const uint8_t*>(fPtr);
    45     }
    47     /**
    48      *  Helper to copy a range of the data into a caller-provided buffer.
    49      *  Returns the actual number of bytes copied, after clamping offset and
    50      *  length to the size of the data. If buffer is NULL, it is ignored, and
    51      *  only the computed number of bytes is returned.
    52      */
    53     size_t copyRange(size_t offset, size_t length, void* buffer) const;
    55     /**
    56      *  Returns true if these two objects have the same length and contents,
    57      *  effectively returning 0 == memcmp(...)
    58      */
    59     bool equals(const SkData* other) const;
    61     /**
    62      *  Function that, if provided, will be called when the SkData goes out
    63      *  of scope, allowing for custom allocation/freeing of the data.
    64      */
    65     typedef void (*ReleaseProc)(const void* ptr, size_t length, void* context);
    67     /**
    68      *  Create a new dataref by copying the specified data
    69      */
    70     static SkData* NewWithCopy(const void* data, size_t length);
    72     /**
    73      *  Create a new dataref by copying the specified c-string
    74      *  (a null-terminated array of bytes). The returned SkData will have size()
    75      *  equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same
    76      *  as "".
    77      */
    78     static SkData* NewWithCString(const char cstr[]);
    80     /**
    81      *  Create a new dataref, taking the data ptr as is, and using the
    82      *  releaseproc to free it. The proc may be NULL.
    83      */
    84     static SkData* NewWithProc(const void* data, size_t length,
    85                                ReleaseProc proc, void* context);
    87     /**
    88      *  Create a new dataref from a pointer allocated by malloc. The Data object
    89      *  takes ownership of that allocation, and will handling calling sk_free.
    90      */
    91     static SkData* NewFromMalloc(const void* data, size_t length);
    93     /**
    94      *  Create a new dataref the file with the specified path.
    95      *  If the file cannot be opened, this returns NULL.
    96      */
    97     static SkData* NewFromFileName(const char path[]);
    99     /**
   100      *  Create a new dataref from a SkFILE.
   101      *  This does not take ownership of the SkFILE, nor close it.
   102      *  The caller is free to close the SkFILE at its convenience.
   103      *  The SkFILE must be open for reading only.
   104      *  Returns NULL on failure.
   105      */
   106     static SkData* NewFromFILE(SkFILE* f);
   108     /**
   109      *  Create a new dataref from a file descriptor.
   110      *  This does not take ownership of the file descriptor, nor close it.
   111      *  The caller is free to close the file descriptor at its convenience.
   112      *  The file descriptor must be open for reading only.
   113      *  Returns NULL on failure.
   114      */
   115     static SkData* NewFromFD(int fd);
   117     /**
   118      *  Create a new dataref using a subset of the data in the specified
   119      *  src dataref.
   120      */
   121     static SkData* NewSubset(const SkData* src, size_t offset, size_t length);
   123     /**
   124      *  Returns a new empty dataref (or a reference to a shared empty dataref).
   125      *  New or shared, the caller must see that unref() is eventually called.
   126      */
   127     static SkData* NewEmpty();
   129 private:
   130     ReleaseProc fReleaseProc;
   131     void*       fReleaseProcContext;
   133     const void* fPtr;
   134     size_t      fSize;
   136     SkData(const void* ptr, size_t size, ReleaseProc, void* context);
   137     virtual ~SkData();
   139     // Called the first time someone calls NewEmpty to initialize the singleton.
   140     static void NewEmptyImpl(int/*unused*/);
   142     typedef SkRefCnt INHERITED;
   143 };
   145 /** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */
   146 typedef SkAutoTUnref<SkData> SkAutoDataUnref;
   148 #endif

mercurial