nsTransferable.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsTransferable_h__
  6. #define nsTransferable_h__
  7. #include "nsIContentPolicyBase.h"
  8. #include "nsIFormatConverter.h"
  9. #include "nsITransferable.h"
  10. #include "nsCOMPtr.h"
  11. #include "nsString.h"
  12. #include "nsTArray.h"
  13. #include "nsIPrincipal.h"
  14. class nsIMutableArray;
  15. class nsString;
  16. //
  17. // DataStruct
  18. //
  19. // Holds a flavor (a mime type) that describes the data and the associated data.
  20. //
  21. struct DataStruct
  22. {
  23. explicit DataStruct ( const char* aFlavor )
  24. : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
  25. ~DataStruct();
  26. const nsCString& GetFlavor() const { return mFlavor; }
  27. void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData );
  28. void GetData( nsISupports** outData, uint32_t *outDataLen );
  29. already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
  30. bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
  31. protected:
  32. enum {
  33. // The size of data over which we write the data to disk rather than
  34. // keep it around in memory.
  35. kLargeDatasetSize = 1000000 // 1 million bytes
  36. };
  37. nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
  38. nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
  39. nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper
  40. uint32_t mDataLen;
  41. const nsCString mFlavor;
  42. char * mCacheFileName;
  43. };
  44. /**
  45. * XP Transferable wrapper
  46. */
  47. class nsTransferable : public nsITransferable
  48. {
  49. public:
  50. nsTransferable();
  51. // nsISupports
  52. NS_DECL_ISUPPORTS
  53. NS_DECL_NSITRANSFERABLE
  54. protected:
  55. virtual ~nsTransferable();
  56. // get flavors w/out converter
  57. already_AddRefed<nsIMutableArray> GetTransferDataFlavors();
  58. nsTArray<DataStruct> mDataArray;
  59. nsCOMPtr<nsIFormatConverter> mFormatConv;
  60. bool mPrivateData;
  61. nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
  62. nsContentPolicyType mContentPolicyType;
  63. #if DEBUG
  64. bool mInitialized;
  65. #endif
  66. };
  67. #endif // nsTransferable_h__