author Rob Wu <rob@robwu.nl>
Sat, 24 Sep 2016 11:16:32 +0200
changeset 320058 a41f871e2d1b37754bbd1001c36c075511b49342
parent 318173 bd7461a1ed09447f4d38b4911f0e83933f9d875b
permissions -rw-r--r--
Bug 1299411 - Decouple Port implementation from API r=aswan Decoupled the API from the implementation. From now on it is possible to create Port instances without generating an API. This allows us to internally use Ports to pass around messages with minimal overhead (in the form of unnecessary clones of messages). This will be used by native messaging. This commit has no behavioral change, it is mostly moving around some code and storing the internal message listener in a set. MozReview-Commit-ID: 4h0LNJvTH9R

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

#ifndef nsTransferable_h__
#define nsTransferable_h__

#include "nsIContentPolicyBase.h"
#include "nsIFormatConverter.h"
#include "nsITransferable.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsIPrincipal.h"

class nsIMutableArray;
class nsString;

// DataStruct
// Holds a flavor (a mime type) that describes the data and the associated data.
struct DataStruct
  explicit DataStruct ( const char* aFlavor )
    : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
  const nsCString& GetFlavor() const { return mFlavor; }
  void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData );
  void GetData( nsISupports** outData, uint32_t *outDataLen );
  already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
  bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }

  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
  nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
  nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
  nsCOMPtr<nsISupports> mData;   // OWNER - some varient of primitive wrapper
  uint32_t mDataLen;
  const nsCString mFlavor;
  char *   mCacheFileName;


 * XP Transferable wrapper

class nsTransferable : public nsITransferable


    // nsISupports

  virtual ~nsTransferable();

    // get flavors w/out converter
  already_AddRefed<nsIMutableArray> GetTransferDataFlavors();
  nsTArray<DataStruct> mDataArray;
  nsCOMPtr<nsIFormatConverter> mFormatConv;
  bool mPrivateData;
  nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
  nsContentPolicyType mContentPolicyType;
  bool mInitialized;


#endif // nsTransferable_h__