Source code

Revision control

Other Tools

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
public:
29
SerializedLoadContext()
30
: mIsNotNull(false),
31
mIsPrivateBitValid(false),
32
mIsContent(false),
33
mUseRemoteTabs(false),
34
mUseRemoteSubframes(false),
35
mUseTrackingProtection(false) {
36
Init(nullptr);
37
}
38
39
explicit SerializedLoadContext(nsILoadContext* aLoadContext);
40
explicit SerializedLoadContext(nsIChannel* aChannel);
41
explicit SerializedLoadContext(nsIWebSocketChannel* aChannel);
42
43
void Init(nsILoadContext* aLoadContext);
44
45
bool IsNotNull() const { return mIsNotNull; }
46
bool IsPrivateBitValid() const { return mIsPrivateBitValid; }
47
48
// used to indicate if child-side LoadContext * was null.
49
bool mIsNotNull;
50
// used to indicate if child-side mUsePrivateBrowsing flag is valid, even if
51
// mIsNotNull is false, i.e., child LoadContext was null.
52
bool mIsPrivateBitValid;
53
bool mIsContent;
54
bool mUseRemoteTabs;
55
bool mUseRemoteSubframes;
56
bool mUseTrackingProtection;
57
mozilla::OriginAttributes mOriginAttributes;
58
};
59
60
// Function to serialize over IPDL
61
template <>
62
struct ParamTraits<SerializedLoadContext> {
63
typedef SerializedLoadContext paramType;
64
65
static void Write(Message* aMsg, const paramType& aParam) {
66
nsAutoCString suffix;
67
aParam.mOriginAttributes.CreateSuffix(suffix);
68
69
WriteParam(aMsg, aParam.mIsNotNull);
70
WriteParam(aMsg, aParam.mIsContent);
71
WriteParam(aMsg, aParam.mIsPrivateBitValid);
72
WriteParam(aMsg, aParam.mUseRemoteTabs);
73
WriteParam(aMsg, aParam.mUseRemoteSubframes);
74
WriteParam(aMsg, aParam.mUseTrackingProtection);
75
WriteParam(aMsg, suffix);
76
}
77
78
static bool Read(const Message* aMsg, PickleIterator* aIter,
79
paramType* aResult) {
80
nsAutoCString suffix;
81
if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
82
!ReadParam(aMsg, aIter, &aResult->mIsContent) ||
83
!ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
84
!ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
85
!ReadParam(aMsg, aIter, &aResult->mUseRemoteSubframes) ||
86
!ReadParam(aMsg, aIter, &aResult->mUseTrackingProtection) ||
87
!ReadParam(aMsg, aIter, &suffix)) {
88
return false;
89
}
90
return aResult->mOriginAttributes.PopulateFromSuffix(suffix);
91
}
92
};
93
94
} // namespace IPC
95
96
#endif // SerializedLoadContext_h