widget/windows/IEnumFE.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef IEnumeFE_h__
michael@0 7 #define IEnumeFE_h__
michael@0 8
michael@0 9 /*
michael@0 10 * CEnumFormatEtc - implements IEnumFORMATETC
michael@0 11 */
michael@0 12
michael@0 13 #include <ole2.h>
michael@0 14
michael@0 15 #include "nsTArray.h"
michael@0 16 #include "mozilla/Attributes.h"
michael@0 17
michael@0 18 // FORMATETC container
michael@0 19 class FormatEtc
michael@0 20 {
michael@0 21 public:
michael@0 22 FormatEtc() { memset(&mFormat, 0, sizeof(FORMATETC)); }
michael@0 23 FormatEtc(const FormatEtc& copy) { CopyIn(&copy.mFormat); }
michael@0 24 ~FormatEtc() { if (mFormat.ptd) CoTaskMemFree(mFormat.ptd); }
michael@0 25
michael@0 26 void CopyIn(const FORMATETC *aSrc) {
michael@0 27 if (!aSrc) {
michael@0 28 memset(&mFormat, 0, sizeof(FORMATETC));
michael@0 29 return;
michael@0 30 }
michael@0 31 mFormat = *aSrc;
michael@0 32 if (aSrc->ptd) {
michael@0 33 mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
michael@0 34 *(mFormat.ptd) = *(aSrc->ptd);
michael@0 35 }
michael@0 36 }
michael@0 37
michael@0 38 void CopyOut(LPFORMATETC aDest) {
michael@0 39 if (!aDest)
michael@0 40 return;
michael@0 41 *aDest = mFormat;
michael@0 42 if (mFormat.ptd) {
michael@0 43 aDest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
michael@0 44 *(aDest->ptd) = *(mFormat.ptd);
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 private:
michael@0 49 FORMATETC mFormat;
michael@0 50 };
michael@0 51
michael@0 52 /*
michael@0 53 * CEnumFormatEtc is created within IDataObject::EnumFormatEtc. This object lives
michael@0 54 * on its own, that is, QueryInterface only knows IUnknown and IEnumFormatEtc,
michael@0 55 * nothing more. We still use an outer unknown for reference counting, because as
michael@0 56 * long as this enumerator lives, the data object should live, thereby keeping the
michael@0 57 * application up.
michael@0 58 */
michael@0 59
michael@0 60 class CEnumFormatEtc MOZ_FINAL : public IEnumFORMATETC
michael@0 61 {
michael@0 62 public:
michael@0 63 CEnumFormatEtc(nsTArray<FormatEtc>& aArray);
michael@0 64 CEnumFormatEtc();
michael@0 65 ~CEnumFormatEtc();
michael@0 66
michael@0 67 // IUnknown impl.
michael@0 68 STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
michael@0 69 STDMETHODIMP_(ULONG) AddRef();
michael@0 70 STDMETHODIMP_(ULONG) Release();
michael@0 71
michael@0 72 // IEnumFORMATETC impl.
michael@0 73 STDMETHODIMP Next(ULONG aMaxToFetch, FORMATETC *aResult, ULONG *aNumFetched);
michael@0 74 STDMETHODIMP Skip(ULONG aSkipNum);
michael@0 75 STDMETHODIMP Reset();
michael@0 76 STDMETHODIMP Clone(LPENUMFORMATETC *aResult); // Addrefs
michael@0 77
michael@0 78 // Utils
michael@0 79 void AddFormatEtc(LPFORMATETC aFormat);
michael@0 80
michael@0 81 private:
michael@0 82 nsTArray<FormatEtc> mFormatList; // Formats
michael@0 83 ULONG mRefCnt; // Object reference count
michael@0 84 ULONG mCurrentIdx; // Current element
michael@0 85
michael@0 86 void SetIndex(uint32_t aIdx);
michael@0 87 };
michael@0 88
michael@0 89
michael@0 90 #endif //_IENUMFE_H_

mercurial