/work/obj-fuzz/dist/include/SerializedLoadContext.h
Line | Count | Source (jump to first uncovered line) |
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 | | class SerializedLoadContext |
28 | | { |
29 | | public: |
30 | | SerializedLoadContext() |
31 | | : mIsNotNull(false) |
32 | | , mIsPrivateBitValid(false) |
33 | | , mIsContent(false) |
34 | | , mUseRemoteTabs(false) |
35 | | , mUseTrackingProtection(false) |
36 | 0 | { |
37 | 0 | Init(nullptr); |
38 | 0 | } |
39 | | |
40 | | explicit SerializedLoadContext(nsILoadContext* aLoadContext); |
41 | | explicit SerializedLoadContext(nsIChannel* aChannel); |
42 | | explicit SerializedLoadContext(nsIWebSocketChannel* aChannel); |
43 | | |
44 | | void Init(nsILoadContext* aLoadContext); |
45 | | |
46 | 0 | 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 | | static void Write(Message* aMsg, const paramType& aParam) |
67 | 0 | { |
68 | 0 | nsAutoCString suffix; |
69 | 0 | aParam.mOriginAttributes.CreateSuffix(suffix); |
70 | 0 |
|
71 | 0 | WriteParam(aMsg, aParam.mIsNotNull); |
72 | 0 | WriteParam(aMsg, aParam.mIsContent); |
73 | 0 | WriteParam(aMsg, aParam.mIsPrivateBitValid); |
74 | 0 | WriteParam(aMsg, aParam.mUseRemoteTabs); |
75 | 0 | WriteParam(aMsg, aParam.mUseTrackingProtection); |
76 | 0 | WriteParam(aMsg, suffix); |
77 | 0 | } |
78 | | |
79 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
80 | 0 | { |
81 | 0 | nsAutoCString suffix; |
82 | 0 | if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) || |
83 | 0 | !ReadParam(aMsg, aIter, &aResult->mIsContent) || |
84 | 0 | !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) || |
85 | 0 | !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) || |
86 | 0 | !ReadParam(aMsg, aIter, &aResult->mUseTrackingProtection) || |
87 | 0 | !ReadParam(aMsg, aIter, &suffix)) { |
88 | 0 | return false; |
89 | 0 | } |
90 | 0 | return aResult->mOriginAttributes.PopulateFromSuffix(suffix); |
91 | 0 | } |
92 | | }; |
93 | | |
94 | | } // namespace IPC |
95 | | |
96 | | #endif // SerializedLoadContext_h |