Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
DataStruct Struct Reference
Collaboration diagram for DataStruct:
Collaboration graph

List of all members.

Public Member Functions

 DataStruct (const char *aFlavor)
 ~DataStruct ()
const nsCStringGetFlavor () const
void SetData (nsISupports *inData, PRUint32 inDataLen)
void GetData (nsISupports **outData, PRUint32 *outDataLen)
nsIFileGetFileSpec (const char *aFileName)
PRBool IsDataAvailable () const

Protected Types

enum  { kLargeDatasetSize = 1000000 }

Protected Member Functions

nsresult WriteCache (nsISupports *aData, PRUint32 aDataLen)
nsresult ReadCache (nsISupports **aData, PRUint32 *aDataLen)

Protected Attributes

nsCOMPtr< nsISupports > mData
PRUint32 mDataLen
const nsCAutoString mFlavor
char * mCacheFileName

Detailed Description

Definition at line 79 of file nsTransferable.cpp.

Member Enumeration Documentation

anonymous enum [protected]

Definition at line 93 of file nsTransferable.cpp.

    // The size of data over which we write the data to disk rather than
    // keep it around in memory.
    kLargeDatasetSize = 1000000        // 1 million bytes

Constructor & Destructor Documentation

DataStruct::DataStruct ( const char *  aFlavor) [inline]

Definition at line 81 of file nsTransferable.cpp.

    : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nsnull) { }

Definition at line 123 of file nsTransferable.cpp.

  if (mCacheFileName) nsCRT::free(mCacheFileName); 

    //nsIFileSpec * cacheFile = GetFileSpec(mCacheFileName);

Member Function Documentation

void DataStruct::GetData ( nsISupports **  outData,
PRUint32 outDataLen 

Definition at line 151 of file nsTransferable.cpp.

  // check here to see if the data is cached on disk
  if ( !mData && mCacheFileName ) {
    // if so, read it in and pass it back
    // ReadCache creates memory and copies the data into it.
    if ( NS_SUCCEEDED(ReadCache(aData, aDataLen)) )
    else {
      // oh shit, something went horribly wrong here.
      NS_WARNING("Oh no, couldn't read data in from the cache file");
      *aData = nsnull;
      *aDataLen = 0;
  *aData = mData;
  if ( mData )
  *aDataLen = mDataLen;

Here is the call graph for this function:

nsIFile * DataStruct::GetFileSpec ( const char *  aFileName)

Definition at line 177 of file nsTransferable.cpp.

  nsIFile* cacheFile;
  NS_GetSpecialDirectory(NS_OS_TEMP_DIR, &cacheFile);
  if (cacheFile == nsnull)
    return nsnull;

  // if the param aFileName contains a name we should use that
  // because the file probably already exists
  // otherwise create a unique name
  if (!aFileName) {
    cacheFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
  } else {
  return cacheFile;

Here is the call graph for this function:

Here is the caller graph for this function:

const nsCString& DataStruct::GetFlavor ( ) const [inline]

Definition at line 85 of file nsTransferable.cpp.

{ return mFlavor; }

Here is the caller graph for this function:

PRBool DataStruct::IsDataAvailable ( ) const [inline]

Definition at line 89 of file nsTransferable.cpp.

{ return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
nsresult DataStruct::ReadCache ( nsISupports **  aData,
PRUint32 aDataLen 
) [protected]

Definition at line 238 of file nsTransferable.cpp.

  // if we don't have a cache filename we are out of luck
  if (!mCacheFileName)
    return NS_ERROR_FAILURE;

  // get the path and file name
  nsCOMPtr<nsIFile> cacheFile ( getter_AddRefs(GetFileSpec(mCacheFileName)) );
  PRBool exists;
  if ( cacheFile && NS_SUCCEEDED(cacheFile->Exists(&exists)) && exists ) {
    // get the size of the file
    PRInt64 fileSize;
    PRInt64 max32(LL_INIT(0, 0xFFFFFFFF));
    if (LL_CMP(fileSize, >, max32))
      return NS_ERROR_OUT_OF_MEMORY;
    PRUint32 size;
    LL_L2UI(size, fileSize);

    // create new memory for the large clipboard data
    nsAutoArrayPtr<char> data(new char[size]);
    if ( !data )
      return NS_ERROR_OUT_OF_MEMORY;
    // now read it all in
    nsCOMPtr<nsIInputStream> inStr;
    NS_NewLocalFileInputStream( getter_AddRefs(inStr),
    if (!cacheFile) return NS_ERROR_FAILURE;

    nsresult rv = inStr->Read(data, fileSize, aDataLen);

    // make sure we got all the data ok
    if (NS_SUCCEEDED(rv) && *aDataLen == size) {
      nsPrimitiveHelpers::CreatePrimitiveForData ( mFlavor.get(), data, fileSize, aData );
      return *aData ? NS_OK : NS_ERROR_FAILURE;

    // zero the return params
    *aData    = nsnull;
    *aDataLen = 0;


Here is the call graph for this function:

Here is the caller graph for this function:

void DataStruct::SetData ( nsISupports *  inData,
PRUint32  inDataLen 

Definition at line 133 of file nsTransferable.cpp.

  // Now, check to see if we consider the data to be "too large"
  if (aDataLen > kLargeDatasetSize) {
    // if so, cache it to disk instead of memory
    if ( NS_SUCCEEDED(WriteCache(aData, aDataLen)) )
                     NS_WARNING("Oh no, couldn't write data to the cache file");   

  mData    = aData;
  mDataLen = aDataLen;  

Here is the call graph for this function:

nsresult DataStruct::WriteCache ( nsISupports *  aData,
PRUint32  aDataLen 
) [protected]

Definition at line 201 of file nsTransferable.cpp.

  // Get a new path and file to the temp directory
  nsCOMPtr<nsIFile> cacheFile ( getter_AddRefs(GetFileSpec(mCacheFileName)) );
  if (cacheFile) {
    // remember the file name
    if (!mCacheFileName) {
      nsXPIDLCString fName;
      mCacheFileName = nsCRT::strdup(fName);

    // write out the contents of the clipboard
    // to the file
    //PRUint32 bytes;
    nsCOMPtr<nsIOutputStream> outStr;


    if (!outStr) return NS_ERROR_FAILURE;

    void* buff = nsnull;
    nsPrimitiveHelpers::CreateDataFromPrimitive ( mFlavor.get(), aData, &buff, aDataLen );
    if ( buff ) {
      PRUint32 ignored;
      outStr->Write(NS_REINTERPRET_CAST(char*, buff), aDataLen, &ignored);
      return NS_OK;

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

char* DataStruct::mCacheFileName [protected]

Definition at line 105 of file nsTransferable.cpp.

nsCOMPtr<nsISupports> DataStruct::mData [protected]

Definition at line 102 of file nsTransferable.cpp.

Definition at line 103 of file nsTransferable.cpp.

Definition at line 104 of file nsTransferable.cpp.

The documentation for this struct was generated from the following file: