1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/nsDataObj.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,294 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef _NSDATAOBJ_H_ 1.10 +#define _NSDATAOBJ_H_ 1.11 + 1.12 +#include <oleidl.h> 1.13 +#include <shldisp.h> 1.14 + 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsString.h" 1.17 +#include "nsIFile.h" 1.18 +#include "nsIURI.h" 1.19 +#include "nsIInputStream.h" 1.20 +#include "nsIStreamListener.h" 1.21 +#include "nsIChannel.h" 1.22 +#include "nsCOMArray.h" 1.23 +#include "nsITimer.h" 1.24 + 1.25 +class nsIThread; 1.26 + 1.27 +// The SDK shipping with VC11 has renamed IAsyncOperation to 1.28 +// IDataObjectAsyncCapability. We try to detect this, and rename this in our 1.29 +// code too to make sure that we pick the correct name when building. 1.30 +#ifdef __IDataObjectAsyncCapability_INTERFACE_DEFINED__ 1.31 +#define IAsyncOperation IDataObjectAsyncCapability 1.32 +#define IID_IAsyncOperation IID_IDataObjectAsyncCapability 1.33 +#else 1.34 +// XXX for older version of PSDK where IAsyncOperation and related stuff is not available 1.35 +// but thisdefine should be removed when parocles config is updated 1.36 +#ifndef __IAsyncOperation_INTERFACE_DEFINED__ 1.37 +// IAsyncOperation interface definition 1.38 +EXTERN_C const IID IID_IAsyncOperation; 1.39 + 1.40 +MIDL_INTERFACE("3D8B0590-F691-11d2-8EA9-006097DF5BD4") 1.41 +IAsyncOperation : public IUnknown 1.42 +{ 1.43 + virtual HRESULT STDMETHODCALLTYPE SetAsyncMode(BOOL fDoOpAsync) = 0; 1.44 + virtual HRESULT STDMETHODCALLTYPE GetAsyncMode(BOOL *pfIsOpAsync) = 0; 1.45 + virtual HRESULT STDMETHODCALLTYPE StartOperation(IBindCtx *pbcReserved) = 0; 1.46 + virtual HRESULT STDMETHODCALLTYPE InOperation(BOOL *pfInAsyncOp) = 0; 1.47 + virtual HRESULT STDMETHODCALLTYPE EndOperation(HRESULT hResult, 1.48 + IBindCtx *pbcReserved, 1.49 + DWORD dwEffects) = 0; 1.50 +}; 1.51 +// this is not defined in the old headers for some reason 1.52 +#ifndef FD_PROGRESSUI 1.53 + #define FD_PROGRESSUI 0x4000 1.54 +#endif 1.55 + 1.56 +#endif // __IAsyncOperation_INTERFACE_DEFINED__ 1.57 +#endif // __IDataObjectAsyncCapability_INTERFACE_DEFINED__ 1.58 + 1.59 +/* 1.60 + * CFSTR_SHELLURL is deprecated and doesn't have a Unicode version. 1.61 + * Therefore we are using CFSTR_INETURL instead of CFSTR_SHELLURL. 1.62 + * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/transferring/clipboard.asp 1.63 + */ 1.64 +#ifndef CFSTR_INETURLA 1.65 +#define CFSTR_INETURLA L"UniformResourceLocator" 1.66 +#endif 1.67 +#ifndef CFSTR_INETURLW 1.68 +#define CFSTR_INETURLW L"UniformResourceLocatorW" 1.69 +#endif 1.70 + 1.71 +// For support of MinGW w32api v2.4. 1.72 +// When the next version of w32api is released with shlobj.h rev 1.35 1.73 +// http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/winsup/w32api/include/shlobj.h?cvsroot=src 1.74 +// then that can be made the base required version and this code should be removed. 1.75 +#ifndef CFSTR_FILEDESCRIPTORA 1.76 +# define CFSTR_FILEDESCRIPTORA L"FileGroupDescriptor" 1.77 +#endif 1.78 +#ifndef CFSTR_FILEDESCRIPTORW 1.79 +# define CFSTR_FILEDESCRIPTORW L"FileGroupDescriptorW" 1.80 +#endif 1.81 + 1.82 +class CEnumFormatEtc; 1.83 +class nsITransferable; 1.84 + 1.85 +/* 1.86 + * This ole registered class is used to facilitate drag-drop of objects which 1.87 + * can be adapted by an object derived from CfDragDrop. The CfDragDrop is 1.88 + * associated with instances via SetDragDrop(). 1.89 + */ 1.90 +class nsDataObj : public IDataObject, 1.91 + public IAsyncOperation 1.92 +{ 1.93 + 1.94 +protected: 1.95 + nsCOMPtr<nsIThread> mIOThread; 1.96 + 1.97 + public: // construction, destruction 1.98 + nsDataObj(nsIURI *uri = nullptr); 1.99 + virtual ~nsDataObj(); 1.100 + 1.101 + public: // IUnknown methods - see iunknown.h for documentation 1.102 + STDMETHODIMP_(ULONG) AddRef (); 1.103 + STDMETHODIMP QueryInterface(REFIID, void**); 1.104 + STDMETHODIMP_(ULONG) Release (); 1.105 + 1.106 + // support for clipboard 1.107 + void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE); 1.108 + void SetTransferable(nsITransferable * aTransferable); 1.109 + 1.110 + // Return the registered OLE class ID of this object's CfDataObj. 1.111 + CLSID GetClassID() const; 1.112 + 1.113 + public: // IDataObject methods - these are general comments. see CfDragDrop 1.114 + // for overriding behavior 1.115 + 1.116 + // Store data in pSTM according to the format specified by pFE, if the 1.117 + // format is supported (supported formats are specified in CfDragDrop:: 1.118 + // GetFormats) and return NOERROR; otherwise return DATA_E_FORMATETC. It 1.119 + // is the callers responsibility to free pSTM if NOERROR is returned. 1.120 + STDMETHODIMP GetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM); 1.121 + 1.122 + // Similar to GetData except that the caller allocates the structure 1.123 + // referenced by pSTM. 1.124 + STDMETHODIMP GetDataHere (LPFORMATETC pFE, LPSTGMEDIUM pSTM); 1.125 + 1.126 + // Returns S_TRUE if this object supports the format specified by pSTM, 1.127 + // S_FALSE otherwise. 1.128 + STDMETHODIMP QueryGetData (LPFORMATETC pFE); 1.129 + 1.130 + // Set pCanonFE to the canonical format of pFE if one exists and return 1.131 + // NOERROR, otherwise return DATA_S_SAMEFORMATETC. A canonical format 1.132 + // implies an identical rendering. 1.133 + STDMETHODIMP GetCanonicalFormatEtc (LPFORMATETC pFE, LPFORMATETC pCanonFE); 1.134 + 1.135 + // Set this objects data according to the format specified by pFE and 1.136 + // the storage medium specified by pSTM and return NOERROR, if the format 1.137 + // is supported. If release is TRUE this object must release the storage 1.138 + // associated with pSTM. 1.139 + STDMETHODIMP SetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release); 1.140 + 1.141 + // Set ppEnum to an IEnumFORMATETC object which will iterate all of the 1.142 + // data formats that this object supports. direction is either DATADIR_GET 1.143 + // or DATADIR_SET. 1.144 + STDMETHODIMP EnumFormatEtc (DWORD direction, LPENUMFORMATETC* ppEnum); 1.145 + 1.146 + // Set up an advisory connection to this object based on the format specified 1.147 + // by pFE, flags, and the pAdvise. Set pConn to the established advise 1.148 + // connection. 1.149 + STDMETHODIMP DAdvise (LPFORMATETC pFE, DWORD flags, LPADVISESINK pAdvise, 1.150 + DWORD* pConn); 1.151 + 1.152 + // Turn off advising of a previous call to DAdvise which set pConn. 1.153 + STDMETHODIMP DUnadvise (DWORD pConn); 1.154 + 1.155 + // Set ppEnum to an IEnumSTATDATA object which will iterate over the 1.156 + // existing objects which have established advisory connections to this 1.157 + // object. 1.158 + STDMETHODIMP EnumDAdvise (LPENUMSTATDATA *ppEnum); 1.159 + 1.160 + // IAsyncOperation methods 1.161 + STDMETHOD(EndOperation)(HRESULT hResult, IBindCtx *pbcReserved, DWORD dwEffects); 1.162 + STDMETHOD(GetAsyncMode)(BOOL *pfIsOpAsync); 1.163 + STDMETHOD(InOperation)(BOOL *pfInAsyncOp); 1.164 + STDMETHOD(SetAsyncMode)(BOOL fDoOpAsync); 1.165 + STDMETHOD(StartOperation)(IBindCtx *pbcReserved); 1.166 + 1.167 + public: // other methods 1.168 + 1.169 + // Gets the filename from the kFilePromiseURLMime flavour 1.170 + HRESULT GetDownloadDetails(nsIURI **aSourceURI, 1.171 + nsAString &aFilename); 1.172 + 1.173 + protected: 1.174 + // help determine the kind of drag 1.175 + bool IsFlavourPresent(const char *inFlavour); 1.176 + 1.177 + virtual HRESULT AddSetFormat(FORMATETC& FE); 1.178 + virtual HRESULT AddGetFormat(FORMATETC& FE); 1.179 + 1.180 + virtual HRESULT GetFile ( FORMATETC& aFE, STGMEDIUM& aSTG ); 1.181 + virtual HRESULT GetText ( const nsACString& aDF, FORMATETC& aFE, STGMEDIUM & aSTG ); 1.182 + virtual HRESULT GetDib ( const nsACString& inFlavor, FORMATETC &, STGMEDIUM & aSTG ); 1.183 + virtual HRESULT GetMetafilePict(FORMATETC& FE, STGMEDIUM& STM); 1.184 + 1.185 + virtual HRESULT DropImage( FORMATETC& aFE, STGMEDIUM& aSTG ); 1.186 + virtual HRESULT DropFile( FORMATETC& aFE, STGMEDIUM& aSTG ); 1.187 + virtual HRESULT DropTempFile( FORMATETC& aFE, STGMEDIUM& aSTG ); 1.188 + 1.189 + virtual HRESULT GetUniformResourceLocator ( FORMATETC& aFE, STGMEDIUM& aSTG, bool aIsUnicode ) ; 1.190 + virtual HRESULT ExtractUniformResourceLocatorA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.191 + virtual HRESULT ExtractUniformResourceLocatorW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.192 + virtual HRESULT GetFileDescriptor ( FORMATETC& aFE, STGMEDIUM& aSTG, bool aIsUnicode ) ; 1.193 + virtual HRESULT GetFileContents ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.194 + virtual HRESULT GetPreferredDropEffect ( FORMATETC& aFE, STGMEDIUM& aSTG ); 1.195 + 1.196 + virtual HRESULT SetBitmap(FORMATETC& FE, STGMEDIUM& STM); 1.197 + virtual HRESULT SetDib (FORMATETC& FE, STGMEDIUM& STM); 1.198 + virtual HRESULT SetText (FORMATETC& FE, STGMEDIUM& STM); 1.199 + virtual HRESULT SetMetafilePict(FORMATETC& FE, STGMEDIUM& STM); 1.200 + 1.201 + // Provide the structures needed for an internet shortcut by the shell 1.202 + virtual HRESULT GetFileDescriptorInternetShortcutA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.203 + virtual HRESULT GetFileDescriptorInternetShortcutW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.204 + virtual HRESULT GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.205 + 1.206 + // IStream implementation 1.207 + virtual HRESULT GetFileDescriptor_IStreamA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.208 + virtual HRESULT GetFileDescriptor_IStreamW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.209 + virtual HRESULT GetFileContents_IStream ( FORMATETC& aFE, STGMEDIUM& aSTG ) ; 1.210 + 1.211 + nsresult ExtractShortcutURL ( nsString & outURL ) ; 1.212 + nsresult ExtractShortcutTitle ( nsString & outTitle ) ; 1.213 + 1.214 + // munge our HTML data to win32's CF_HTML spec. Will null terminate 1.215 + nsresult BuildPlatformHTML ( const char* inOurHTML, char** outPlatformHTML ) ; 1.216 + 1.217 + // Used for the SourceURL part of CF_HTML 1.218 + nsCString mSourceURL; 1.219 + 1.220 + BOOL FormatsMatch(const FORMATETC& source, const FORMATETC& target) const; 1.221 + 1.222 + ULONG m_cRef; // the reference count 1.223 + 1.224 + nsTArray<nsCString> mDataFlavors; 1.225 + 1.226 + nsITransferable * mTransferable; // nsDataObj owns and ref counts nsITransferable, 1.227 + // the nsITransferable does know anything about the nsDataObj 1.228 + 1.229 + CEnumFormatEtc * m_enumFE; // Ownership Rules: 1.230 + // nsDataObj owns and ref counts CEnumFormatEtc, 1.231 + 1.232 + nsCOMPtr<nsIFile> mCachedTempFile; 1.233 + 1.234 + BOOL mIsAsyncMode; 1.235 + BOOL mIsInOperation; 1.236 + /////////////////////////////////////////////////////////////////////////////// 1.237 + // CStream class implementation 1.238 + // this class is used in Drag and drop with download sample 1.239 + // called from IDataObject::GetData 1.240 + class CStream : public IStream, public nsIStreamListener 1.241 + { 1.242 + nsCOMPtr<nsIChannel> mChannel; 1.243 + nsTArray<uint8_t> mChannelData; 1.244 + bool mChannelRead; 1.245 + nsresult mChannelResult; 1.246 + uint32_t mStreamRead; 1.247 + 1.248 + protected: 1.249 + virtual ~CStream(); 1.250 + nsresult WaitForCompletion(); 1.251 + 1.252 + public: 1.253 + CStream(); 1.254 + nsresult Init(nsIURI *pSourceURI); 1.255 + 1.256 + NS_DECL_ISUPPORTS 1.257 + NS_DECL_NSIREQUESTOBSERVER 1.258 + NS_DECL_NSISTREAMLISTENER 1.259 + 1.260 + // IUnknown 1.261 + STDMETHOD(QueryInterface)(REFIID refiid, void** ppvResult); 1.262 + 1.263 + // IStream 1.264 + STDMETHOD(Clone)(IStream** ppStream); 1.265 + STDMETHOD(Commit)(DWORD dwFrags); 1.266 + STDMETHOD(CopyTo)(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead, ULARGE_INTEGER* nBytesWritten); 1.267 + STDMETHOD(LockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags); 1.268 + STDMETHOD(Read)(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead); 1.269 + STDMETHOD(Revert)(void); 1.270 + STDMETHOD(Seek)(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos); 1.271 + STDMETHOD(SetSize)(ULARGE_INTEGER nNewSize); 1.272 + STDMETHOD(Stat)(STATSTG* statstg, DWORD dwFlags); 1.273 + STDMETHOD(UnlockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags); 1.274 + STDMETHOD(Write)(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead); 1.275 + }; 1.276 + 1.277 + HRESULT CreateStream(IStream **outStream); 1.278 + 1.279 + private: 1.280 + 1.281 + // Drag and drop helper data for implementing drag and drop image support 1.282 + typedef struct { 1.283 + FORMATETC fe; 1.284 + STGMEDIUM stgm; 1.285 + } DATAENTRY, *LPDATAENTRY; 1.286 + 1.287 + nsTArray <LPDATAENTRY> mDataEntryList; 1.288 + nsCOMPtr<nsITimer> mTimer; 1.289 + 1.290 + bool LookupArbitraryFormat(FORMATETC *aFormat, LPDATAENTRY *aDataEntry, BOOL aAddorUpdate); 1.291 + bool CopyMediumData(STGMEDIUM *aMediumDst, STGMEDIUM *aMediumSrc, LPFORMATETC aFormat, BOOL aSetData); 1.292 + static void RemoveTempFile(nsITimer* aTimer, void* aClosure); 1.293 +}; 1.294 + 1.295 + 1.296 +#endif // _NSDATAOBJ_H_ 1.297 +