tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SerializedLoadContext.h (3084B)


      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 "ipc/IPCMessageUtilsSpecializations.h"
     13 #include "mozilla/BasePrincipal.h"
     14 
     15 class nsILoadContext;
     16 
     17 /*
     18 *  This file contains the IPC::SerializedLoadContext class, which is used to
     19 *  copy data across IPDL from Child process contexts so it is available in the
     20 *  Parent.
     21 */
     22 
     23 class nsIChannel;
     24 class nsIWebSocketChannel;
     25 
     26 namespace IPC {
     27 
     28 class SerializedLoadContext {
     29 public:
     30  SerializedLoadContext()
     31      : mIsNotNull(false),
     32        mIsPrivateBitValid(false),
     33        mIsContent(false),
     34        mUseRemoteTabs(false),
     35        mUseRemoteSubframes(false),
     36        mUseTrackingProtection(false) {
     37    Init(nullptr);
     38  }
     39 
     40  explicit SerializedLoadContext(nsILoadContext* aLoadContext);
     41  explicit SerializedLoadContext(nsIChannel* aChannel);
     42  explicit SerializedLoadContext(nsIWebSocketChannel* aChannel);
     43 
     44  void Init(nsILoadContext* aLoadContext);
     45 
     46  bool IsNotNull() const { return mIsNotNull; }
     47  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 mUseRemoteSubframes;
     57  bool mUseTrackingProtection;
     58  mozilla::OriginAttributes mOriginAttributes;
     59 };
     60 
     61 // Function to serialize over IPDL
     62 template <>
     63 struct ParamTraits<SerializedLoadContext> {
     64  typedef SerializedLoadContext paramType;
     65 
     66  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     67    nsAutoCString suffix;
     68    aParam.mOriginAttributes.CreateSuffix(suffix);
     69 
     70    WriteParam(aWriter, aParam.mIsNotNull);
     71    WriteParam(aWriter, aParam.mIsContent);
     72    WriteParam(aWriter, aParam.mIsPrivateBitValid);
     73    WriteParam(aWriter, aParam.mUseRemoteTabs);
     74    WriteParam(aWriter, aParam.mUseRemoteSubframes);
     75    WriteParam(aWriter, aParam.mUseTrackingProtection);
     76    WriteParam(aWriter, suffix);
     77  }
     78 
     79  static bool Read(MessageReader* aReader, paramType* aResult) {
     80    nsAutoCString suffix;
     81    if (!ReadParam(aReader, &aResult->mIsNotNull) ||
     82        !ReadParam(aReader, &aResult->mIsContent) ||
     83        !ReadParam(aReader, &aResult->mIsPrivateBitValid) ||
     84        !ReadParam(aReader, &aResult->mUseRemoteTabs) ||
     85        !ReadParam(aReader, &aResult->mUseRemoteSubframes) ||
     86        !ReadParam(aReader, &aResult->mUseTrackingProtection) ||
     87        !ReadParam(aReader, &suffix)) {
     88      return false;
     89    }
     90    return aResult->mOriginAttributes.PopulateFromSuffix(suffix);
     91  }
     92 };
     93 
     94 }  // namespace IPC
     95 
     96 #endif  // SerializedLoadContext_h