docshell/base/SerializedLoadContext.h
author Karl Tomlinson <karlt+@karlt.net>
Mon, 24 Aug 2015 19:30:36 +1200
changeset 261782 e4fb01e4e3cd2eed2668c0efc85c35f8a8d42224
parent 242694 db70fd907041471df8102f6bd4a3250078cda8c7
child 264424 86a7be21dfc8ef0a3c3080d58ef508732ce2d154
permissions -rw-r--r--
bug 1198656 delay AudioBuffer allocation until required r=padenot This saves an allocation and zeroing for buffers generated by AudioNodes and avoids allocation altogether for empty buffers. Incidentally, RestoreJSChannelData() now avoids unnecessary recreation of Float32Arrays if they already exist after a previous call failed.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 SerializedLoadContext_h
#define SerializedLoadContext_h

#include "base/basictypes.h"
#include "ipc/IPCMessageUtils.h"

class nsILoadContext;

/*
 *  This file contains the IPC::SerializedLoadContext class, which is used to
 *  copy data across IPDL from Child process contexts so it is available in the
 *  Parent.
 */

class nsIChannel;
class nsIWebSocketChannel;

namespace IPC {

class SerializedLoadContext
{
public:
  SerializedLoadContext()
  {
    Init(nullptr);
  }

  explicit SerializedLoadContext(nsILoadContext* aLoadContext);
  explicit SerializedLoadContext(nsIChannel* aChannel);
  explicit SerializedLoadContext(nsIWebSocketChannel* aChannel);

  void Init(nsILoadContext* aLoadContext);

  bool IsNotNull() const { return mIsNotNull; }
  bool IsPrivateBitValid() const { return mIsPrivateBitValid; }

  // used to indicate if child-side LoadContext * was null.
  bool mIsNotNull;
  // used to indicate if child-side mUsePrivateBrowsing flag is valid, even if
  // mIsNotNull is false, i.e., child LoadContext was null.
  bool mIsPrivateBitValid;
  bool mIsContent;
  bool mUsePrivateBrowsing;
  bool mUseRemoteTabs;
  bool mIsInBrowserElement;
  uint32_t mAppId;
};

// Function to serialize over IPDL
template<>
struct ParamTraits<SerializedLoadContext>
{
  typedef SerializedLoadContext paramType;

  static void Write(Message* aMsg, const paramType& aParam)
  {
    WriteParam(aMsg, aParam.mIsNotNull);
    WriteParam(aMsg, aParam.mIsContent);
    WriteParam(aMsg, aParam.mIsPrivateBitValid);
    WriteParam(aMsg, aParam.mUsePrivateBrowsing);
    WriteParam(aMsg, aParam.mUseRemoteTabs);
    WriteParam(aMsg, aParam.mAppId);
    WriteParam(aMsg, aParam.mIsInBrowserElement);
  }

  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
  {
    if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
        !ReadParam(aMsg, aIter, &aResult->mIsContent) ||
        !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
        !ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing) ||
        !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
        !ReadParam(aMsg, aIter, &aResult->mAppId) ||
        !ReadParam(aMsg, aIter, &aResult->mIsInBrowserElement)) {
      return false;
    }

    return true;
  }
};

} // namespace IPC

#endif // SerializedLoadContext_h