Thu, 15 Jan 2015 15:59:08 +0100
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 _NSDATAOBJ_H_ |
michael@0 | 7 | #define _NSDATAOBJ_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include <oleidl.h> |
michael@0 | 10 | #include <shldisp.h> |
michael@0 | 11 | |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | #include "nsIFile.h" |
michael@0 | 15 | #include "nsIURI.h" |
michael@0 | 16 | #include "nsIInputStream.h" |
michael@0 | 17 | #include "nsIStreamListener.h" |
michael@0 | 18 | #include "nsIChannel.h" |
michael@0 | 19 | #include "nsCOMArray.h" |
michael@0 | 20 | #include "nsITimer.h" |
michael@0 | 21 | |
michael@0 | 22 | class nsIThread; |
michael@0 | 23 | |
michael@0 | 24 | // The SDK shipping with VC11 has renamed IAsyncOperation to |
michael@0 | 25 | // IDataObjectAsyncCapability. We try to detect this, and rename this in our |
michael@0 | 26 | // code too to make sure that we pick the correct name when building. |
michael@0 | 27 | #ifdef __IDataObjectAsyncCapability_INTERFACE_DEFINED__ |
michael@0 | 28 | #define IAsyncOperation IDataObjectAsyncCapability |
michael@0 | 29 | #define IID_IAsyncOperation IID_IDataObjectAsyncCapability |
michael@0 | 30 | #else |
michael@0 | 31 | // XXX for older version of PSDK where IAsyncOperation and related stuff is not available |
michael@0 | 32 | // but thisdefine should be removed when parocles config is updated |
michael@0 | 33 | #ifndef __IAsyncOperation_INTERFACE_DEFINED__ |
michael@0 | 34 | // IAsyncOperation interface definition |
michael@0 | 35 | EXTERN_C const IID IID_IAsyncOperation; |
michael@0 | 36 | |
michael@0 | 37 | MIDL_INTERFACE("3D8B0590-F691-11d2-8EA9-006097DF5BD4") |
michael@0 | 38 | IAsyncOperation : public IUnknown |
michael@0 | 39 | { |
michael@0 | 40 | virtual HRESULT STDMETHODCALLTYPE SetAsyncMode(BOOL fDoOpAsync) = 0; |
michael@0 | 41 | virtual HRESULT STDMETHODCALLTYPE GetAsyncMode(BOOL *pfIsOpAsync) = 0; |
michael@0 | 42 | virtual HRESULT STDMETHODCALLTYPE StartOperation(IBindCtx *pbcReserved) = 0; |
michael@0 | 43 | virtual HRESULT STDMETHODCALLTYPE InOperation(BOOL *pfInAsyncOp) = 0; |
michael@0 | 44 | virtual HRESULT STDMETHODCALLTYPE EndOperation(HRESULT hResult, |
michael@0 | 45 | IBindCtx *pbcReserved, |
michael@0 | 46 | DWORD dwEffects) = 0; |
michael@0 | 47 | }; |
michael@0 | 48 | // this is not defined in the old headers for some reason |
michael@0 | 49 | #ifndef FD_PROGRESSUI |
michael@0 | 50 | #define FD_PROGRESSUI 0x4000 |
michael@0 | 51 | #endif |
michael@0 | 52 | |
michael@0 | 53 | #endif // __IAsyncOperation_INTERFACE_DEFINED__ |
michael@0 | 54 | #endif // __IDataObjectAsyncCapability_INTERFACE_DEFINED__ |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * CFSTR_SHELLURL is deprecated and doesn't have a Unicode version. |
michael@0 | 58 | * Therefore we are using CFSTR_INETURL instead of CFSTR_SHELLURL. |
michael@0 | 59 | * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/transferring/clipboard.asp |
michael@0 | 60 | */ |
michael@0 | 61 | #ifndef CFSTR_INETURLA |
michael@0 | 62 | #define CFSTR_INETURLA L"UniformResourceLocator" |
michael@0 | 63 | #endif |
michael@0 | 64 | #ifndef CFSTR_INETURLW |
michael@0 | 65 | #define CFSTR_INETURLW L"UniformResourceLocatorW" |
michael@0 | 66 | #endif |
michael@0 | 67 | |
michael@0 | 68 | // For support of MinGW w32api v2.4. |
michael@0 | 69 | // When the next version of w32api is released with shlobj.h rev 1.35 |
michael@0 | 70 | // http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/winsup/w32api/include/shlobj.h?cvsroot=src |
michael@0 | 71 | // then that can be made the base required version and this code should be removed. |
michael@0 | 72 | #ifndef CFSTR_FILEDESCRIPTORA |
michael@0 | 73 | # define CFSTR_FILEDESCRIPTORA L"FileGroupDescriptor" |
michael@0 | 74 | #endif |
michael@0 | 75 | #ifndef CFSTR_FILEDESCRIPTORW |
michael@0 | 76 | # define CFSTR_FILEDESCRIPTORW L"FileGroupDescriptorW" |
michael@0 | 77 | #endif |
michael@0 | 78 | |
michael@0 | 79 | class CEnumFormatEtc; |
michael@0 | 80 | class nsITransferable; |
michael@0 | 81 | |
michael@0 | 82 | /* |
michael@0 | 83 | * This ole registered class is used to facilitate drag-drop of objects which |
michael@0 | 84 | * can be adapted by an object derived from CfDragDrop. The CfDragDrop is |
michael@0 | 85 | * associated with instances via SetDragDrop(). |
michael@0 | 86 | */ |
michael@0 | 87 | class nsDataObj : public IDataObject, |
michael@0 | 88 | public IAsyncOperation |
michael@0 | 89 | { |
michael@0 | 90 | |
michael@0 | 91 | protected: |
michael@0 | 92 | nsCOMPtr<nsIThread> mIOThread; |
michael@0 | 93 | |
michael@0 | 94 | public: // construction, destruction |
michael@0 | 95 | nsDataObj(nsIURI *uri = nullptr); |
michael@0 | 96 | virtual ~nsDataObj(); |
michael@0 | 97 | |
michael@0 | 98 | public: // IUnknown methods - see iunknown.h for documentation |
michael@0 | 99 | STDMETHODIMP_(ULONG) AddRef (); |
michael@0 | 100 | STDMETHODIMP QueryInterface(REFIID, void**); |
michael@0 | 101 | STDMETHODIMP_(ULONG) Release (); |
michael@0 | 102 | |
michael@0 | 103 | // support for clipboard |
michael@0 | 104 | void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE); |
michael@0 | 105 | void SetTransferable(nsITransferable * aTransferable); |
michael@0 | 106 | |
michael@0 | 107 | // Return the registered OLE class ID of this object's CfDataObj. |
michael@0 | 108 | CLSID GetClassID() const; |
michael@0 | 109 | |
michael@0 | 110 | public: // IDataObject methods - these are general comments. see CfDragDrop |
michael@0 | 111 | // for overriding behavior |
michael@0 | 112 | |
michael@0 | 113 | // Store data in pSTM according to the format specified by pFE, if the |
michael@0 | 114 | // format is supported (supported formats are specified in CfDragDrop:: |
michael@0 | 115 | // GetFormats) and return NOERROR; otherwise return DATA_E_FORMATETC. It |
michael@0 | 116 | // is the callers responsibility to free pSTM if NOERROR is returned. |
michael@0 | 117 | STDMETHODIMP GetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM); |
michael@0 | 118 | |
michael@0 | 119 | // Similar to GetData except that the caller allocates the structure |
michael@0 | 120 | // referenced by pSTM. |
michael@0 | 121 | STDMETHODIMP GetDataHere (LPFORMATETC pFE, LPSTGMEDIUM pSTM); |
michael@0 | 122 | |
michael@0 | 123 | // Returns S_TRUE if this object supports the format specified by pSTM, |
michael@0 | 124 | // S_FALSE otherwise. |
michael@0 | 125 | STDMETHODIMP QueryGetData (LPFORMATETC pFE); |
michael@0 | 126 | |
michael@0 | 127 | // Set pCanonFE to the canonical format of pFE if one exists and return |
michael@0 | 128 | // NOERROR, otherwise return DATA_S_SAMEFORMATETC. A canonical format |
michael@0 | 129 | // implies an identical rendering. |
michael@0 | 130 | STDMETHODIMP GetCanonicalFormatEtc (LPFORMATETC pFE, LPFORMATETC pCanonFE); |
michael@0 | 131 | |
michael@0 | 132 | // Set this objects data according to the format specified by pFE and |
michael@0 | 133 | // the storage medium specified by pSTM and return NOERROR, if the format |
michael@0 | 134 | // is supported. If release is TRUE this object must release the storage |
michael@0 | 135 | // associated with pSTM. |
michael@0 | 136 | STDMETHODIMP SetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release); |
michael@0 | 137 | |
michael@0 | 138 | // Set ppEnum to an IEnumFORMATETC object which will iterate all of the |
michael@0 | 139 | // data formats that this object supports. direction is either DATADIR_GET |
michael@0 | 140 | // or DATADIR_SET. |
michael@0 | 141 | STDMETHODIMP EnumFormatEtc (DWORD direction, LPENUMFORMATETC* ppEnum); |
michael@0 | 142 | |
michael@0 | 143 | // Set up an advisory connection to this object based on the format specified |
michael@0 | 144 | // by pFE, flags, and the pAdvise. Set pConn to the established advise |
michael@0 | 145 | // connection. |
michael@0 | 146 | STDMETHODIMP DAdvise (LPFORMATETC pFE, DWORD flags, LPADVISESINK pAdvise, |
michael@0 | 147 | DWORD* pConn); |
michael@0 | 148 | |
michael@0 | 149 | // Turn off advising of a previous call to DAdvise which set pConn. |
michael@0 | 150 | STDMETHODIMP DUnadvise (DWORD pConn); |
michael@0 | 151 | |
michael@0 | 152 | // Set ppEnum to an IEnumSTATDATA object which will iterate over the |
michael@0 | 153 | // existing objects which have established advisory connections to this |
michael@0 | 154 | // object. |
michael@0 | 155 | STDMETHODIMP EnumDAdvise (LPENUMSTATDATA *ppEnum); |
michael@0 | 156 | |
michael@0 | 157 | // IAsyncOperation methods |
michael@0 | 158 | STDMETHOD(EndOperation)(HRESULT hResult, IBindCtx *pbcReserved, DWORD dwEffects); |
michael@0 | 159 | STDMETHOD(GetAsyncMode)(BOOL *pfIsOpAsync); |
michael@0 | 160 | STDMETHOD(InOperation)(BOOL *pfInAsyncOp); |
michael@0 | 161 | STDMETHOD(SetAsyncMode)(BOOL fDoOpAsync); |
michael@0 | 162 | STDMETHOD(StartOperation)(IBindCtx *pbcReserved); |
michael@0 | 163 | |
michael@0 | 164 | public: // other methods |
michael@0 | 165 | |
michael@0 | 166 | // Gets the filename from the kFilePromiseURLMime flavour |
michael@0 | 167 | HRESULT GetDownloadDetails(nsIURI **aSourceURI, |
michael@0 | 168 | nsAString &aFilename); |
michael@0 | 169 | |
michael@0 | 170 | protected: |
michael@0 | 171 | // help determine the kind of drag |
michael@0 | 172 | bool IsFlavourPresent(const char *inFlavour); |
michael@0 | 173 | |
michael@0 | 174 | virtual HRESULT AddSetFormat(FORMATETC& FE); |
michael@0 | 175 | virtual HRESULT AddGetFormat(FORMATETC& FE); |
michael@0 | 176 | |
michael@0 | 177 | virtual HRESULT GetFile ( FORMATETC& aFE, STGMEDIUM& aSTG ); |
michael@0 | 178 | virtual HRESULT GetText ( const nsACString& aDF, FORMATETC& aFE, STGMEDIUM & aSTG ); |
michael@0 | 179 | virtual HRESULT GetDib ( const nsACString& inFlavor, FORMATETC &, STGMEDIUM & aSTG ); |
michael@0 | 180 | virtual HRESULT GetMetafilePict(FORMATETC& FE, STGMEDIUM& STM); |
michael@0 | 181 | |
michael@0 | 182 | virtual HRESULT DropImage( FORMATETC& aFE, STGMEDIUM& aSTG ); |
michael@0 | 183 | virtual HRESULT DropFile( FORMATETC& aFE, STGMEDIUM& aSTG ); |
michael@0 | 184 | virtual HRESULT DropTempFile( FORMATETC& aFE, STGMEDIUM& aSTG ); |
michael@0 | 185 | |
michael@0 | 186 | virtual HRESULT GetUniformResourceLocator ( FORMATETC& aFE, STGMEDIUM& aSTG, bool aIsUnicode ) ; |
michael@0 | 187 | virtual HRESULT ExtractUniformResourceLocatorA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 188 | virtual HRESULT ExtractUniformResourceLocatorW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 189 | virtual HRESULT GetFileDescriptor ( FORMATETC& aFE, STGMEDIUM& aSTG, bool aIsUnicode ) ; |
michael@0 | 190 | virtual HRESULT GetFileContents ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 191 | virtual HRESULT GetPreferredDropEffect ( FORMATETC& aFE, STGMEDIUM& aSTG ); |
michael@0 | 192 | |
michael@0 | 193 | virtual HRESULT SetBitmap(FORMATETC& FE, STGMEDIUM& STM); |
michael@0 | 194 | virtual HRESULT SetDib (FORMATETC& FE, STGMEDIUM& STM); |
michael@0 | 195 | virtual HRESULT SetText (FORMATETC& FE, STGMEDIUM& STM); |
michael@0 | 196 | virtual HRESULT SetMetafilePict(FORMATETC& FE, STGMEDIUM& STM); |
michael@0 | 197 | |
michael@0 | 198 | // Provide the structures needed for an internet shortcut by the shell |
michael@0 | 199 | virtual HRESULT GetFileDescriptorInternetShortcutA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 200 | virtual HRESULT GetFileDescriptorInternetShortcutW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 201 | virtual HRESULT GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 202 | |
michael@0 | 203 | // IStream implementation |
michael@0 | 204 | virtual HRESULT GetFileDescriptor_IStreamA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 205 | virtual HRESULT GetFileDescriptor_IStreamW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 206 | virtual HRESULT GetFileContents_IStream ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; |
michael@0 | 207 | |
michael@0 | 208 | nsresult ExtractShortcutURL ( nsString & outURL ) ; |
michael@0 | 209 | nsresult ExtractShortcutTitle ( nsString & outTitle ) ; |
michael@0 | 210 | |
michael@0 | 211 | // munge our HTML data to win32's CF_HTML spec. Will null terminate |
michael@0 | 212 | nsresult BuildPlatformHTML ( const char* inOurHTML, char** outPlatformHTML ) ; |
michael@0 | 213 | |
michael@0 | 214 | // Used for the SourceURL part of CF_HTML |
michael@0 | 215 | nsCString mSourceURL; |
michael@0 | 216 | |
michael@0 | 217 | BOOL FormatsMatch(const FORMATETC& source, const FORMATETC& target) const; |
michael@0 | 218 | |
michael@0 | 219 | ULONG m_cRef; // the reference count |
michael@0 | 220 | |
michael@0 | 221 | nsTArray<nsCString> mDataFlavors; |
michael@0 | 222 | |
michael@0 | 223 | nsITransferable * mTransferable; // nsDataObj owns and ref counts nsITransferable, |
michael@0 | 224 | // the nsITransferable does know anything about the nsDataObj |
michael@0 | 225 | |
michael@0 | 226 | CEnumFormatEtc * m_enumFE; // Ownership Rules: |
michael@0 | 227 | // nsDataObj owns and ref counts CEnumFormatEtc, |
michael@0 | 228 | |
michael@0 | 229 | nsCOMPtr<nsIFile> mCachedTempFile; |
michael@0 | 230 | |
michael@0 | 231 | BOOL mIsAsyncMode; |
michael@0 | 232 | BOOL mIsInOperation; |
michael@0 | 233 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 234 | // CStream class implementation |
michael@0 | 235 | // this class is used in Drag and drop with download sample |
michael@0 | 236 | // called from IDataObject::GetData |
michael@0 | 237 | class CStream : public IStream, public nsIStreamListener |
michael@0 | 238 | { |
michael@0 | 239 | nsCOMPtr<nsIChannel> mChannel; |
michael@0 | 240 | nsTArray<uint8_t> mChannelData; |
michael@0 | 241 | bool mChannelRead; |
michael@0 | 242 | nsresult mChannelResult; |
michael@0 | 243 | uint32_t mStreamRead; |
michael@0 | 244 | |
michael@0 | 245 | protected: |
michael@0 | 246 | virtual ~CStream(); |
michael@0 | 247 | nsresult WaitForCompletion(); |
michael@0 | 248 | |
michael@0 | 249 | public: |
michael@0 | 250 | CStream(); |
michael@0 | 251 | nsresult Init(nsIURI *pSourceURI); |
michael@0 | 252 | |
michael@0 | 253 | NS_DECL_ISUPPORTS |
michael@0 | 254 | NS_DECL_NSIREQUESTOBSERVER |
michael@0 | 255 | NS_DECL_NSISTREAMLISTENER |
michael@0 | 256 | |
michael@0 | 257 | // IUnknown |
michael@0 | 258 | STDMETHOD(QueryInterface)(REFIID refiid, void** ppvResult); |
michael@0 | 259 | |
michael@0 | 260 | // IStream |
michael@0 | 261 | STDMETHOD(Clone)(IStream** ppStream); |
michael@0 | 262 | STDMETHOD(Commit)(DWORD dwFrags); |
michael@0 | 263 | STDMETHOD(CopyTo)(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead, ULARGE_INTEGER* nBytesWritten); |
michael@0 | 264 | STDMETHOD(LockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags); |
michael@0 | 265 | STDMETHOD(Read)(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead); |
michael@0 | 266 | STDMETHOD(Revert)(void); |
michael@0 | 267 | STDMETHOD(Seek)(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos); |
michael@0 | 268 | STDMETHOD(SetSize)(ULARGE_INTEGER nNewSize); |
michael@0 | 269 | STDMETHOD(Stat)(STATSTG* statstg, DWORD dwFlags); |
michael@0 | 270 | STDMETHOD(UnlockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags); |
michael@0 | 271 | STDMETHOD(Write)(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead); |
michael@0 | 272 | }; |
michael@0 | 273 | |
michael@0 | 274 | HRESULT CreateStream(IStream **outStream); |
michael@0 | 275 | |
michael@0 | 276 | private: |
michael@0 | 277 | |
michael@0 | 278 | // Drag and drop helper data for implementing drag and drop image support |
michael@0 | 279 | typedef struct { |
michael@0 | 280 | FORMATETC fe; |
michael@0 | 281 | STGMEDIUM stgm; |
michael@0 | 282 | } DATAENTRY, *LPDATAENTRY; |
michael@0 | 283 | |
michael@0 | 284 | nsTArray <LPDATAENTRY> mDataEntryList; |
michael@0 | 285 | nsCOMPtr<nsITimer> mTimer; |
michael@0 | 286 | |
michael@0 | 287 | bool LookupArbitraryFormat(FORMATETC *aFormat, LPDATAENTRY *aDataEntry, BOOL aAddorUpdate); |
michael@0 | 288 | bool CopyMediumData(STGMEDIUM *aMediumDst, STGMEDIUM *aMediumSrc, LPFORMATETC aFormat, BOOL aSetData); |
michael@0 | 289 | static void RemoveTempFile(nsITimer* aTimer, void* aClosure); |
michael@0 | 290 | }; |
michael@0 | 291 | |
michael@0 | 292 | |
michael@0 | 293 | #endif // _NSDATAOBJ_H_ |
michael@0 | 294 |