LCOV - code coverage report
Current view: top level - docshell/base - SerializedLoadContext.h (source / functions) Hit Total Coverage
Test: output.info Lines: 26 28 92.9 %
Date: 2017-07-14 16:53:18 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef SerializedLoadContext_h
       8             : #define SerializedLoadContext_h
       9             : 
      10             : #include "base/basictypes.h"
      11             : #include "ipc/IPCMessageUtils.h"
      12             : #include "mozilla/BasePrincipal.h"
      13             : 
      14             : class nsILoadContext;
      15             : 
      16             : /*
      17             :  *  This file contains the IPC::SerializedLoadContext class, which is used to
      18             :  *  copy data across IPDL from Child process contexts so it is available in the
      19             :  *  Parent.
      20             :  */
      21             : 
      22             : class nsIChannel;
      23             : class nsIWebSocketChannel;
      24             : 
      25             : namespace IPC {
      26             : 
      27           6 : class SerializedLoadContext
      28             : {
      29             : public:
      30           3 :   SerializedLoadContext()
      31           3 :     : mIsNotNull(false)
      32             :     , mIsPrivateBitValid(false)
      33             :     , mIsContent(false)
      34             :     , mUseRemoteTabs(false)
      35           3 :     , mUseTrackingProtection(false)
      36             :   {
      37           3 :     Init(nullptr);
      38           3 :   }
      39             : 
      40             :   explicit SerializedLoadContext(nsILoadContext* aLoadContext);
      41             :   explicit SerializedLoadContext(nsIChannel* aChannel);
      42             :   explicit SerializedLoadContext(nsIWebSocketChannel* aChannel);
      43             : 
      44             :   void Init(nsILoadContext* aLoadContext);
      45             : 
      46           9 :   bool IsNotNull() const { return mIsNotNull; }
      47           0 :   bool IsPrivateBitValid() const { return mIsPrivateBitValid; }
      48             : 
      49             :   // used to indicate if child-side LoadContext * was null.
      50             :   bool mIsNotNull;
      51             :   // used to indicate if child-side mUsePrivateBrowsing flag is valid, even if
      52             :   // mIsNotNull is false, i.e., child LoadContext was null.
      53             :   bool mIsPrivateBitValid;
      54             :   bool mIsContent;
      55             :   bool mUseRemoteTabs;
      56             :   bool mUseTrackingProtection;
      57             :   mozilla::OriginAttributes mOriginAttributes;
      58             : };
      59             : 
      60             : // Function to serialize over IPDL
      61             : template<>
      62             : struct ParamTraits<SerializedLoadContext>
      63             : {
      64             :   typedef SerializedLoadContext paramType;
      65             : 
      66           3 :   static void Write(Message* aMsg, const paramType& aParam)
      67             :   {
      68           6 :     nsAutoCString suffix;
      69           3 :     aParam.mOriginAttributes.CreateSuffix(suffix);
      70             : 
      71           3 :     WriteParam(aMsg, aParam.mIsNotNull);
      72           3 :     WriteParam(aMsg, aParam.mIsContent);
      73           3 :     WriteParam(aMsg, aParam.mIsPrivateBitValid);
      74           3 :     WriteParam(aMsg, aParam.mUseRemoteTabs);
      75           3 :     WriteParam(aMsg, aParam.mUseTrackingProtection);
      76           3 :     WriteParam(aMsg, suffix);
      77           3 :   }
      78             : 
      79           3 :   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
      80             :   {
      81           6 :     nsAutoCString suffix;
      82           9 :     if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
      83           6 :         !ReadParam(aMsg, aIter, &aResult->mIsContent) ||
      84           6 :         !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
      85           6 :         !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
      86           9 :         !ReadParam(aMsg, aIter, &aResult->mUseTrackingProtection) ||
      87           3 :         !ReadParam(aMsg, aIter, &suffix)) {
      88           0 :       return false;
      89             :     }
      90           3 :     return aResult->mOriginAttributes.PopulateFromSuffix(suffix);
      91             :   }
      92             : };
      93             : 
      94             : } // namespace IPC
      95             : 
      96             : #endif // SerializedLoadContext_h

Generated by: LCOV version 1.13