2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-03-25 07:14:33 +03:00
|
|
|
|
|
|
|
#ifndef nsTransferable_h__
|
|
|
|
#define nsTransferable_h__
|
|
|
|
|
1999-04-02 22:22:36 +04:00
|
|
|
#include "nsIFormatConverter.h"
|
1999-03-25 07:14:33 +03:00
|
|
|
#include "nsITransferable.h"
|
1999-04-02 22:22:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2009-03-11 05:26:03 +03:00
|
|
|
#include "nsString.h"
|
2009-02-23 04:05:24 +03:00
|
|
|
#include "nsTArray.h"
|
1999-04-02 22:22:36 +04:00
|
|
|
|
1999-05-14 01:53:57 +04:00
|
|
|
class nsString;
|
1999-03-25 07:14:33 +03:00
|
|
|
class nsDataObj;
|
2009-03-11 05:26:03 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// DataStruct
|
|
|
|
//
|
|
|
|
// Holds a flavor (a mime type) that describes the data and the associated data.
|
|
|
|
//
|
|
|
|
struct DataStruct
|
|
|
|
{
|
|
|
|
DataStruct ( const char* aFlavor )
|
2012-07-30 18:20:58 +04:00
|
|
|
: mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
|
2009-03-11 05:26:03 +03:00
|
|
|
~DataStruct();
|
|
|
|
|
|
|
|
const nsCString& GetFlavor() const { return mFlavor; }
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetData( nsISupports* inData, uint32_t inDataLen );
|
|
|
|
void GetData( nsISupports** outData, uint32_t *outDataLen );
|
2009-03-11 05:26:03 +03:00
|
|
|
nsIFile * GetFileSpec(const char * aFileName);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
|
2009-03-11 05:26:03 +03: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 19:56:38 +04:00
|
|
|
nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
|
|
|
|
nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
|
2009-03-11 05:26:03 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mDataLen;
|
2009-03-11 05:26:03 +03:00
|
|
|
const nsCString mFlavor;
|
|
|
|
char * mCacheFileName;
|
|
|
|
|
|
|
|
};
|
1999-03-25 07:14:33 +03:00
|
|
|
|
|
|
|
/**
|
1999-04-02 07:57:31 +04:00
|
|
|
* XP Transferable wrapper
|
1999-03-25 07:14:33 +03:00
|
|
|
*/
|
|
|
|
|
1999-05-14 01:53:57 +04:00
|
|
|
class nsTransferable : public nsITransferable
|
1999-03-25 07:14:33 +03:00
|
|
|
{
|
|
|
|
public:
|
1999-08-25 12:35:06 +04:00
|
|
|
|
1999-03-25 07:14:33 +03:00
|
|
|
nsTransferable();
|
|
|
|
virtual ~nsTransferable();
|
|
|
|
|
1999-08-25 12:35:06 +04:00
|
|
|
// nsISupports
|
1999-03-25 07:14:33 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-04-19 00:20:04 +04:00
|
|
|
NS_DECL_NSITRANSFERABLE
|
1999-04-02 22:22:36 +04:00
|
|
|
|
1999-03-25 07:14:33 +03:00
|
|
|
protected:
|
|
|
|
|
1999-08-25 12:35:06 +04:00
|
|
|
// get flavors w/out converter
|
2003-04-19 00:20:04 +04:00
|
|
|
nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
|
1999-08-25 12:35:06 +04:00
|
|
|
|
2009-03-11 05:26:03 +03:00
|
|
|
nsTArray<DataStruct> mDataArray;
|
1999-04-02 22:22:36 +04:00
|
|
|
nsCOMPtr<nsIFormatConverter> mFormatConv;
|
2012-04-17 06:14:01 +04:00
|
|
|
bool mPrivateData;
|
|
|
|
#if DEBUG
|
|
|
|
bool mInitialized;
|
|
|
|
#endif
|
1999-03-25 07:14:33 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTransferable_h__
|