gfx/skia/trunk/src/utils/win/SkIStream.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 /*
michael@0 3 * Copyright 2011 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
michael@0 10 #define WIN32_LEAN_AND_MEAN
michael@0 11 #include <windows.h>
michael@0 12 #include <ole2.h>
michael@0 13 #include "SkIStream.h"
michael@0 14 #include "SkStream.h"
michael@0 15
michael@0 16 /**
michael@0 17 * SkBaseIStream
michael@0 18 */
michael@0 19 SkBaseIStream::SkBaseIStream() : _refcount(1) { }
michael@0 20 SkBaseIStream::~SkBaseIStream() { }
michael@0 21
michael@0 22 HRESULT STDMETHODCALLTYPE SkBaseIStream::QueryInterface(REFIID iid
michael@0 23 , void ** ppvObject)
michael@0 24 {
michael@0 25 if (NULL == ppvObject) {
michael@0 26 return E_INVALIDARG;
michael@0 27 }
michael@0 28 if (iid == __uuidof(IUnknown)
michael@0 29 || iid == __uuidof(IStream)
michael@0 30 || iid == __uuidof(ISequentialStream))
michael@0 31 {
michael@0 32 *ppvObject = static_cast<IStream*>(this);
michael@0 33 AddRef();
michael@0 34 return S_OK;
michael@0 35 } else {
michael@0 36 *ppvObject = NULL;
michael@0 37 return E_NOINTERFACE;
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 ULONG STDMETHODCALLTYPE SkBaseIStream::AddRef(void) {
michael@0 42 return (ULONG)InterlockedIncrement(&_refcount);
michael@0 43 }
michael@0 44
michael@0 45 ULONG STDMETHODCALLTYPE SkBaseIStream::Release(void) {
michael@0 46 ULONG res = (ULONG) InterlockedDecrement(&_refcount);
michael@0 47 if (0 == res) {
michael@0 48 delete this;
michael@0 49 }
michael@0 50 return res;
michael@0 51 }
michael@0 52
michael@0 53 // ISequentialStream Interface
michael@0 54 HRESULT STDMETHODCALLTYPE SkBaseIStream::Read(void* pv
michael@0 55 , ULONG cb
michael@0 56 , ULONG* pcbRead)
michael@0 57 { return E_NOTIMPL; }
michael@0 58
michael@0 59 HRESULT STDMETHODCALLTYPE SkBaseIStream::Write(void const* pv
michael@0 60 , ULONG cb
michael@0 61 , ULONG* pcbWritten)
michael@0 62 { return E_NOTIMPL; }
michael@0 63
michael@0 64 // IStream Interface
michael@0 65 HRESULT STDMETHODCALLTYPE SkBaseIStream::SetSize(ULARGE_INTEGER)
michael@0 66 { return E_NOTIMPL; }
michael@0 67
michael@0 68 HRESULT STDMETHODCALLTYPE SkBaseIStream::CopyTo(IStream*
michael@0 69 , ULARGE_INTEGER
michael@0 70 , ULARGE_INTEGER*
michael@0 71 , ULARGE_INTEGER*)
michael@0 72 { return E_NOTIMPL; }
michael@0 73
michael@0 74 HRESULT STDMETHODCALLTYPE SkBaseIStream::Commit(DWORD)
michael@0 75 { return E_NOTIMPL; }
michael@0 76
michael@0 77 HRESULT STDMETHODCALLTYPE SkBaseIStream::Revert(void)
michael@0 78 { return E_NOTIMPL; }
michael@0 79
michael@0 80 HRESULT STDMETHODCALLTYPE SkBaseIStream::LockRegion(ULARGE_INTEGER
michael@0 81 , ULARGE_INTEGER
michael@0 82 , DWORD)
michael@0 83 { return E_NOTIMPL; }
michael@0 84
michael@0 85 HRESULT STDMETHODCALLTYPE SkBaseIStream::UnlockRegion(ULARGE_INTEGER
michael@0 86 , ULARGE_INTEGER
michael@0 87 , DWORD)
michael@0 88 { return E_NOTIMPL; }
michael@0 89
michael@0 90 HRESULT STDMETHODCALLTYPE SkBaseIStream::Clone(IStream **)
michael@0 91 { return E_NOTIMPL; }
michael@0 92
michael@0 93 HRESULT STDMETHODCALLTYPE SkBaseIStream::Seek(LARGE_INTEGER liDistanceToMove
michael@0 94 , DWORD dwOrigin
michael@0 95 , ULARGE_INTEGER* lpNewFilePointer)
michael@0 96 { return E_NOTIMPL; }
michael@0 97
michael@0 98 HRESULT STDMETHODCALLTYPE SkBaseIStream::Stat(STATSTG* pStatstg
michael@0 99 , DWORD grfStatFlag)
michael@0 100 { return E_NOTIMPL; }
michael@0 101
michael@0 102
michael@0 103 /**
michael@0 104 * SkIStream
michael@0 105 */
michael@0 106 SkIStream::SkIStream(SkStream* stream, bool unrefOnRelease)
michael@0 107 : SkBaseIStream()
michael@0 108 , fSkStream(stream)
michael@0 109 , fUnrefOnRelease(unrefOnRelease)
michael@0 110 , fLocation()
michael@0 111 {
michael@0 112 this->fSkStream->rewind();
michael@0 113 }
michael@0 114
michael@0 115 SkIStream::~SkIStream() {
michael@0 116 if (NULL != this->fSkStream && fUnrefOnRelease) {
michael@0 117 this->fSkStream->unref();
michael@0 118 }
michael@0 119 }
michael@0 120
michael@0 121 HRESULT SkIStream::CreateFromSkStream(SkStream* stream
michael@0 122 , bool unrefOnRelease
michael@0 123 , IStream ** ppStream)
michael@0 124 {
michael@0 125 if (NULL == stream) {
michael@0 126 return E_INVALIDARG;
michael@0 127 }
michael@0 128 *ppStream = new SkIStream(stream, unrefOnRelease);
michael@0 129 return S_OK;
michael@0 130 }
michael@0 131
michael@0 132 // ISequentialStream Interface
michael@0 133 HRESULT STDMETHODCALLTYPE SkIStream::Read(void* pv, ULONG cb, ULONG* pcbRead) {
michael@0 134 *pcbRead = static_cast<ULONG>(this->fSkStream->read(pv, cb));
michael@0 135 this->fLocation.QuadPart += *pcbRead;
michael@0 136 return (*pcbRead == cb) ? S_OK : S_FALSE;
michael@0 137 }
michael@0 138
michael@0 139 HRESULT STDMETHODCALLTYPE SkIStream::Write(void const* pv
michael@0 140 , ULONG cb
michael@0 141 , ULONG* pcbWritten)
michael@0 142 {
michael@0 143 return STG_E_CANTSAVE;
michael@0 144 }
michael@0 145
michael@0 146 // IStream Interface
michael@0 147 HRESULT STDMETHODCALLTYPE SkIStream::Seek(LARGE_INTEGER liDistanceToMove
michael@0 148 , DWORD dwOrigin
michael@0 149 , ULARGE_INTEGER* lpNewFilePointer)
michael@0 150 {
michael@0 151 HRESULT hr = S_OK;
michael@0 152
michael@0 153 switch(dwOrigin) {
michael@0 154 case STREAM_SEEK_SET: {
michael@0 155 if (!this->fSkStream->rewind()) {
michael@0 156 hr = E_FAIL;
michael@0 157 } else {
michael@0 158 size_t skipped = this->fSkStream->skip(
michael@0 159 static_cast<size_t>(liDistanceToMove.QuadPart)
michael@0 160 );
michael@0 161 this->fLocation.QuadPart = skipped;
michael@0 162 if (skipped != liDistanceToMove.QuadPart) {
michael@0 163 hr = E_FAIL;
michael@0 164 }
michael@0 165 }
michael@0 166 break;
michael@0 167 }
michael@0 168 case STREAM_SEEK_CUR: {
michael@0 169 size_t skipped = this->fSkStream->skip(
michael@0 170 static_cast<size_t>(liDistanceToMove.QuadPart)
michael@0 171 );
michael@0 172 this->fLocation.QuadPart += skipped;
michael@0 173 if (skipped != liDistanceToMove.QuadPart) {
michael@0 174 hr = E_FAIL;
michael@0 175 }
michael@0 176 break;
michael@0 177 }
michael@0 178 case STREAM_SEEK_END: {
michael@0 179 if (!this->fSkStream->rewind()) {
michael@0 180 hr = E_FAIL;
michael@0 181 } else {
michael@0 182 // FIXME: Should not depend on getLength.
michael@0 183 // See https://code.google.com/p/skia/issues/detail?id=1570
michael@0 184 LONGLONG skip = this->fSkStream->getLength()
michael@0 185 + liDistanceToMove.QuadPart;
michael@0 186 size_t skipped = this->fSkStream->skip(static_cast<size_t>(skip));
michael@0 187 this->fLocation.QuadPart = skipped;
michael@0 188 if (skipped != skip) {
michael@0 189 hr = E_FAIL;
michael@0 190 }
michael@0 191 }
michael@0 192 break;
michael@0 193 }
michael@0 194 default:
michael@0 195 hr = STG_E_INVALIDFUNCTION;
michael@0 196 break;
michael@0 197 }
michael@0 198
michael@0 199 if (NULL != lpNewFilePointer) {
michael@0 200 lpNewFilePointer->QuadPart = this->fLocation.QuadPart;
michael@0 201 }
michael@0 202 return hr;
michael@0 203 }
michael@0 204
michael@0 205 HRESULT STDMETHODCALLTYPE SkIStream::Stat(STATSTG* pStatstg
michael@0 206 , DWORD grfStatFlag)
michael@0 207 {
michael@0 208 if (0 == (grfStatFlag & STATFLAG_NONAME)) {
michael@0 209 return STG_E_INVALIDFLAG;
michael@0 210 }
michael@0 211 pStatstg->pwcsName = NULL;
michael@0 212 // FIXME: Should not depend on getLength
michael@0 213 // See https://code.google.com/p/skia/issues/detail?id=1570
michael@0 214 pStatstg->cbSize.QuadPart = this->fSkStream->getLength();
michael@0 215 pStatstg->clsid = CLSID_NULL;
michael@0 216 pStatstg->type = STGTY_STREAM;
michael@0 217 pStatstg->grfMode = STGM_READ;
michael@0 218 return S_OK;
michael@0 219 }
michael@0 220
michael@0 221
michael@0 222 /**
michael@0 223 * SkIWStream
michael@0 224 */
michael@0 225 SkWIStream::SkWIStream(SkWStream* stream)
michael@0 226 : SkBaseIStream()
michael@0 227 , fSkWStream(stream)
michael@0 228 { }
michael@0 229
michael@0 230 SkWIStream::~SkWIStream() {
michael@0 231 if (NULL != this->fSkWStream) {
michael@0 232 this->fSkWStream->flush();
michael@0 233 }
michael@0 234 }
michael@0 235
michael@0 236 HRESULT SkWIStream::CreateFromSkWStream(SkWStream* stream
michael@0 237 , IStream ** ppStream)
michael@0 238 {
michael@0 239 *ppStream = new SkWIStream(stream);
michael@0 240 return S_OK;
michael@0 241 }
michael@0 242
michael@0 243 // ISequentialStream Interface
michael@0 244 HRESULT STDMETHODCALLTYPE SkWIStream::Write(void const* pv
michael@0 245 , ULONG cb
michael@0 246 , ULONG* pcbWritten)
michael@0 247 {
michael@0 248 HRESULT hr = S_OK;
michael@0 249 bool wrote = this->fSkWStream->write(pv, cb);
michael@0 250 if (wrote) {
michael@0 251 *pcbWritten = cb;
michael@0 252 } else {
michael@0 253 *pcbWritten = 0;
michael@0 254 hr = S_FALSE;
michael@0 255 }
michael@0 256 return hr;
michael@0 257 }
michael@0 258
michael@0 259 // IStream Interface
michael@0 260 HRESULT STDMETHODCALLTYPE SkWIStream::Commit(DWORD) {
michael@0 261 this->fSkWStream->flush();
michael@0 262 return S_OK;
michael@0 263 }
michael@0 264
michael@0 265 HRESULT STDMETHODCALLTYPE SkWIStream::Stat(STATSTG* pStatstg
michael@0 266 , DWORD grfStatFlag)
michael@0 267 {
michael@0 268 if (0 == (grfStatFlag & STATFLAG_NONAME)) {
michael@0 269 return STG_E_INVALIDFLAG;
michael@0 270 }
michael@0 271 pStatstg->pwcsName = NULL;
michael@0 272 pStatstg->cbSize.QuadPart = 0;
michael@0 273 pStatstg->clsid = CLSID_NULL;
michael@0 274 pStatstg->type = STGTY_STREAM;
michael@0 275 pStatstg->grfMode = STGM_WRITE;
michael@0 276 return S_OK;
michael@0 277 }

mercurial