docshell/base/SerializedLoadContext.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/base/SerializedLoadContext.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef SerializedLoadContext_h
    1.11 +#define SerializedLoadContext_h
    1.12 +
    1.13 +#include "base/basictypes.h"
    1.14 +#include "ipc/IPCMessageUtils.h"
    1.15 +
    1.16 +class nsILoadContext;
    1.17 +
    1.18 +/*
    1.19 + *  This file contains the IPC::SerializedLoadContext class, which is used to
    1.20 + *  copy data across IPDL from Child process contexts so it is available in the
    1.21 + *  Parent.
    1.22 + */
    1.23 +
    1.24 +class nsIChannel;
    1.25 +class nsIWebSocketChannel;
    1.26 +
    1.27 +namespace IPC {
    1.28 +
    1.29 +class SerializedLoadContext
    1.30 +{
    1.31 +public:
    1.32 +  SerializedLoadContext()
    1.33 +  {
    1.34 +    Init(nullptr);
    1.35 +  }
    1.36 +
    1.37 +  SerializedLoadContext(nsILoadContext* aLoadContext);
    1.38 +  SerializedLoadContext(nsIChannel* aChannel);
    1.39 +  SerializedLoadContext(nsIWebSocketChannel* aChannel);
    1.40 +
    1.41 +  void Init(nsILoadContext* aLoadContext);
    1.42 +
    1.43 +  bool IsNotNull() const
    1.44 +  {
    1.45 +    return mIsNotNull;
    1.46 +  }
    1.47 +
    1.48 +  bool IsPrivateBitValid() const
    1.49 +  {
    1.50 +    return mIsPrivateBitValid;
    1.51 +  }
    1.52 +
    1.53 +  // used to indicate if child-side LoadContext * was null.
    1.54 +  bool          mIsNotNull;
    1.55 +  // used to indicate if child-side mUsePrivateBrowsing flag is valid, even if
    1.56 +  // mIsNotNull is false, i.e., child LoadContext was null.
    1.57 +  bool          mIsPrivateBitValid;
    1.58 +  bool          mIsContent;
    1.59 +  bool          mUsePrivateBrowsing;
    1.60 +  bool          mUseRemoteTabs;
    1.61 +  bool          mIsInBrowserElement;
    1.62 +  uint32_t      mAppId;
    1.63 +};
    1.64 +
    1.65 +// Function to serialize over IPDL
    1.66 +template<>
    1.67 +struct ParamTraits<SerializedLoadContext>
    1.68 +{
    1.69 +  typedef SerializedLoadContext paramType;
    1.70 +
    1.71 +  static void Write(Message* aMsg, const paramType& aParam)
    1.72 +  {
    1.73 +    WriteParam(aMsg, aParam.mIsNotNull);
    1.74 +    WriteParam(aMsg, aParam.mIsContent);
    1.75 +    WriteParam(aMsg, aParam.mIsPrivateBitValid);
    1.76 +    WriteParam(aMsg, aParam.mUsePrivateBrowsing);
    1.77 +    WriteParam(aMsg, aParam.mUseRemoteTabs);
    1.78 +    WriteParam(aMsg, aParam.mAppId);
    1.79 +    WriteParam(aMsg, aParam.mIsInBrowserElement);
    1.80 +  }
    1.81 +
    1.82 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    1.83 +  {
    1.84 +    if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
    1.85 +        !ReadParam(aMsg, aIter, &aResult->mIsContent)  ||
    1.86 +        !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid)  ||
    1.87 +        !ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing)  ||
    1.88 +        !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs)  ||
    1.89 +        !ReadParam(aMsg, aIter, &aResult->mAppId)  ||
    1.90 +        !ReadParam(aMsg, aIter, &aResult->mIsInBrowserElement)) {
    1.91 +      return false;
    1.92 +    }
    1.93 +
    1.94 +    return true;
    1.95 +  }
    1.96 +};
    1.97 +
    1.98 +} // namespace IPC
    1.99 +
   1.100 +#endif // SerializedLoadContext_h
   1.101 +

mercurial