widget/xpwidgets/nsTransferable.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
parent 0
6474c204b198
child 11
deefc01c0e14
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 );
    31   void SetData( nsISupports* inData, uint32_t inDataLen, bool inPrivBrowse );
    32   void GetData( nsISupports** outData, uint32_t *outDataLen );
    33   already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
    34   bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
    36 protected:
    38   enum {
    39     // The size of data over which we write the data to disk rather than
    40     // keep it around in memory.
    41     kLargeDatasetSize = 1000000        // 1 million bytes
    42   };
    44   nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
    45   nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
    47   nsCOMPtr<nsISupports> mData;   // OWNER - some varient of primitive wrapper
    48   uint32_t mDataLen;
    49   const nsCString mFlavor;
    50   char *   mCacheFileName;
    52 };
    54 /**
    55  * XP Transferable wrapper
    56  */
    58 class nsTransferable : public nsITransferable
    59 {
    60 public:
    62   nsTransferable();
    63   virtual ~nsTransferable();
    65     // nsISupports
    66   NS_DECL_ISUPPORTS
    67   NS_DECL_NSITRANSFERABLE
    69 protected:
    71     // get flavors w/out converter
    72   nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
    74   nsTArray<DataStruct> mDataArray;
    75   nsCOMPtr<nsIFormatConverter> mFormatConv;
    76   bool mPrivateData;
    77 #if DEBUG
    78   bool mInitialized;
    79 #endif
    81 };
    83 #endif // nsTransferable_h__

mercurial