2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsTransferable_h__
|
|
|
|
#define nsTransferable_h__
|
|
|
|
|
|
|
|
#include "nsIFormatConverter.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2009-03-10 19:26:03 -07:00
|
|
|
#include "nsString.h"
|
2009-02-22 17:05:24 -08:00
|
|
|
#include "nsTArray.h"
|
2014-09-21 09:41:56 -07:00
|
|
|
#include "nsWeakPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsString;
|
2009-03-10 19:26:03 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// DataStruct
|
|
|
|
//
|
|
|
|
// Holds a flavor (a mime type) that describes the data and the associated data.
|
|
|
|
//
|
|
|
|
struct DataStruct
|
|
|
|
{
|
2014-08-31 20:33:13 -07:00
|
|
|
explicit DataStruct ( const char* aFlavor )
|
2012-07-30 07:20:58 -07:00
|
|
|
: mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
|
2009-03-10 19:26:03 -07:00
|
|
|
~DataStruct();
|
|
|
|
|
|
|
|
const nsCString& GetFlavor() const { return mFlavor; }
|
2015-02-18 03:52:00 -08:00
|
|
|
void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData );
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetData( nsISupports** outData, uint32_t *outDataLen );
|
2013-07-10 02:56:21 -07:00
|
|
|
already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
|
2009-03-10 19:26:03 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
enum {
|
|
|
|
// The size of data over which we write the data to disk rather than
|
|
|
|
// keep it around in memory.
|
|
|
|
kLargeDatasetSize = 1000000 // 1 million bytes
|
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
|
|
|
|
nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
|
2009-03-10 19:26:03 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mDataLen;
|
2009-03-10 19:26:03 -07:00
|
|
|
const nsCString mFlavor;
|
|
|
|
char * mCacheFileName;
|
|
|
|
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* XP Transferable wrapper
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsTransferable : public nsITransferable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsTransferable();
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITRANSFERABLE
|
|
|
|
|
|
|
|
protected:
|
2014-06-24 09:36:44 -07:00
|
|
|
virtual ~nsTransferable();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get flavors w/out converter
|
|
|
|
nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
|
|
|
|
|
2009-03-10 19:26:03 -07:00
|
|
|
nsTArray<DataStruct> mDataArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIFormatConverter> mFormatConv;
|
2012-04-16 19:14:01 -07:00
|
|
|
bool mPrivateData;
|
2014-09-21 09:41:56 -07:00
|
|
|
nsWeakPtr mRequestingNode;
|
2012-04-16 19:14:01 -07:00
|
|
|
#if DEBUG
|
|
|
|
bool mInitialized;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTransferable_h__
|