michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef SerializedLoadContext_h michael@0: #define SerializedLoadContext_h michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "ipc/IPCMessageUtils.h" michael@0: michael@0: class nsILoadContext; michael@0: michael@0: /* michael@0: * This file contains the IPC::SerializedLoadContext class, which is used to michael@0: * copy data across IPDL from Child process contexts so it is available in the michael@0: * Parent. michael@0: */ michael@0: michael@0: class nsIChannel; michael@0: class nsIWebSocketChannel; michael@0: michael@0: namespace IPC { michael@0: michael@0: class SerializedLoadContext michael@0: { michael@0: public: michael@0: SerializedLoadContext() michael@0: { michael@0: Init(nullptr); michael@0: } michael@0: michael@0: SerializedLoadContext(nsILoadContext* aLoadContext); michael@0: SerializedLoadContext(nsIChannel* aChannel); michael@0: SerializedLoadContext(nsIWebSocketChannel* aChannel); michael@0: michael@0: void Init(nsILoadContext* aLoadContext); michael@0: michael@0: bool IsNotNull() const michael@0: { michael@0: return mIsNotNull; michael@0: } michael@0: michael@0: bool IsPrivateBitValid() const michael@0: { michael@0: return mIsPrivateBitValid; michael@0: } michael@0: michael@0: // used to indicate if child-side LoadContext * was null. michael@0: bool mIsNotNull; michael@0: // used to indicate if child-side mUsePrivateBrowsing flag is valid, even if michael@0: // mIsNotNull is false, i.e., child LoadContext was null. michael@0: bool mIsPrivateBitValid; michael@0: bool mIsContent; michael@0: bool mUsePrivateBrowsing; michael@0: bool mUseRemoteTabs; michael@0: bool mIsInBrowserElement; michael@0: uint32_t mAppId; michael@0: }; michael@0: michael@0: // Function to serialize over IPDL michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef SerializedLoadContext paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mIsNotNull); michael@0: WriteParam(aMsg, aParam.mIsContent); michael@0: WriteParam(aMsg, aParam.mIsPrivateBitValid); michael@0: WriteParam(aMsg, aParam.mUsePrivateBrowsing); michael@0: WriteParam(aMsg, aParam.mUseRemoteTabs); michael@0: WriteParam(aMsg, aParam.mAppId); michael@0: WriteParam(aMsg, aParam.mIsInBrowserElement); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) || michael@0: !ReadParam(aMsg, aIter, &aResult->mIsContent) || michael@0: !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) || michael@0: !ReadParam(aMsg, aIter, &aResult->mUsePrivateBrowsing) || michael@0: !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) || michael@0: !ReadParam(aMsg, aIter, &aResult->mAppId) || michael@0: !ReadParam(aMsg, aIter, &aResult->mIsInBrowserElement)) { michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // SerializedLoadContext_h michael@0: