widget/xpwidgets/nsTransferable.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
parent 11
deefc01c0e14
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef nsTransferable_h__
     7 #define nsTransferable_h__
     9 #include "nsIFormatConverter.h"
    10 #include "nsITransferable.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsString.h"
    13 #include "nsTArray.h"
    15 class nsString;
    16 class nsDataObj;
    18 //
    19 // DataStruct
    20 //
    21 // Holds a flavor (a mime type) that describes the data and the associated data.
    22 //
    23 struct DataStruct
    24 {
    25   DataStruct ( const char* aFlavor )
    26     : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
    27   ~DataStruct();
    29   const nsCString& GetFlavor() const { return mFlavor; }
    30   void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData );
    31   void GetData( nsISupports** outData, uint32_t *outDataLen );
    32   already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
    33   bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
    35 protected:
    37   enum {
    38     // The size of data over which we write the data to disk rather than
    39     // keep it around in memory.
    40     kLargeDatasetSize = 1000000        // 1 million bytes
    41   };
    43   nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
    44   nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
    46   nsCOMPtr<nsISupports> mData;   // OWNER - some varient of primitive wrapper
    47   uint32_t mDataLen;
    48   const nsCString mFlavor;
    49   char *   mCacheFileName;
    51 };
    53 /**
    54  * XP Transferable wrapper
    55  */
    57 class nsTransferable : public nsITransferable
    58 {
    59 public:
    61   nsTransferable();
    62   virtual ~nsTransferable();
    64     // nsISupports
    65   NS_DECL_ISUPPORTS
    66   NS_DECL_NSITRANSFERABLE
    68 protected:
    70     // get flavors w/out converter
    71   nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
    73   nsTArray<DataStruct> mDataArray;
    74   nsCOMPtr<nsIFormatConverter> mFormatConv;
    75   bool mPrivateData;
    76 #if DEBUG
    77   bool mInitialized;
    78 #endif
    80 };
    82 #endif // nsTransferable_h__

mercurial