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 LoadContext_h
8
#define LoadContext_h
9
10
#include "SerializedLoadContext.h"
11
#include "mozilla/Attributes.h"
12
#include "mozilla/BasePrincipal.h"
13
#include "nsIWeakReferenceUtils.h"
14
#include "mozilla/dom/Element.h"
15
#include "nsIInterfaceRequestor.h"
16
#include "nsILoadContext.h"
17
18
namespace mozilla {
19
20
/**
21
* Class that provides nsILoadContext info in Parent process. Typically copied
22
* from Child via SerializedLoadContext.
23
*
24
* Note: this is not the "normal" or "original" nsILoadContext. That is
25
* typically provided by nsDocShell. This is only used when the original
26
* docshell is in a different process and we need to copy certain values from
27
* it.
28
*/
29
30
class LoadContext final : public nsILoadContext, public nsIInterfaceRequestor {
31
public:
32
NS_DECL_ISUPPORTS
33
NS_DECL_NSILOADCONTEXT
34
NS_DECL_NSIINTERFACEREQUESTOR
35
36
LoadContext(const IPC::SerializedLoadContext& aToCopy,
37
dom::Element* aTopFrameElement, OriginAttributes& aAttrs)
38
: mTopFrameElement(do_GetWeakReference(aTopFrameElement)),
39
mNestedFrameId(0),
40
mIsContent(aToCopy.mIsContent),
41
mUseRemoteTabs(aToCopy.mUseRemoteTabs),
42
mUseRemoteSubframes(aToCopy.mUseRemoteSubframes),
43
mUseTrackingProtection(aToCopy.mUseTrackingProtection),
44
#ifdef DEBUG
45
mIsNotNull(aToCopy.mIsNotNull),
46
#endif
47
mOriginAttributes(aAttrs) {
48
}
49
50
LoadContext(const IPC::SerializedLoadContext& aToCopy,
51
uint64_t aNestedFrameId, OriginAttributes& aAttrs)
52
: mTopFrameElement(nullptr),
53
mNestedFrameId(aNestedFrameId),
54
mIsContent(aToCopy.mIsContent),
55
mUseRemoteTabs(aToCopy.mUseRemoteTabs),
56
mUseRemoteSubframes(aToCopy.mUseRemoteSubframes),
57
mUseTrackingProtection(aToCopy.mUseTrackingProtection),
58
#ifdef DEBUG
59
mIsNotNull(aToCopy.mIsNotNull),
60
#endif
61
mOriginAttributes(aAttrs) {
62
}
63
64
LoadContext(dom::Element* aTopFrameElement, bool aIsContent,
65
bool aUsePrivateBrowsing, bool aUseRemoteTabs,
66
bool aUseRemoteSubframes, bool aUseTrackingProtection,
67
const OriginAttributes& aAttrs)
68
: mTopFrameElement(do_GetWeakReference(aTopFrameElement)),
69
mNestedFrameId(0),
70
mIsContent(aIsContent),
71
mUseRemoteTabs(aUseRemoteTabs),
72
mUseRemoteSubframes(aUseRemoteSubframes),
73
mUseTrackingProtection(aUseTrackingProtection),
74
#ifdef DEBUG
75
mIsNotNull(true),
76
#endif
77
mOriginAttributes(aAttrs) {
78
MOZ_DIAGNOSTIC_ASSERT(aUsePrivateBrowsing ==
79
(aAttrs.mPrivateBrowsingId > 0));
80
}
81
82
// Constructor taking reserved origin attributes.
83
explicit LoadContext(OriginAttributes& aAttrs)
84
: mTopFrameElement(nullptr),
85
mNestedFrameId(0),
86
mIsContent(false),
87
mUseRemoteTabs(false),
88
mUseRemoteSubframes(false),
89
mUseTrackingProtection(false),
90
#ifdef DEBUG
91
mIsNotNull(true),
92
#endif
93
mOriginAttributes(aAttrs) {
94
}
95
96
// Constructor for creating a LoadContext with a given browser flag.
97
explicit LoadContext(nsIPrincipal* aPrincipal,
98
nsILoadContext* aOptionalBase = nullptr);
99
100
private:
101
~LoadContext() {}
102
103
nsWeakPtr mTopFrameElement;
104
uint64_t mNestedFrameId;
105
bool mIsContent;
106
bool mUseRemoteTabs;
107
bool mUseRemoteSubframes;
108
bool mUseTrackingProtection;
109
#ifdef DEBUG
110
bool mIsNotNull;
111
#endif
112
OriginAttributes mOriginAttributes;
113
};
114
115
already_AddRefed<nsILoadContext> CreateLoadContext();
116
already_AddRefed<nsILoadContext> CreatePrivateLoadContext();
117
118
} // namespace mozilla
119
120
#endif // LoadContext_h