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 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
31 : : public nsILoadContext
32 : , public nsIInterfaceRequestor
33 : {
34 : public:
35 : NS_DECL_ISUPPORTS
36 : NS_DECL_NSILOADCONTEXT
37 : NS_DECL_NSIINTERFACEREQUESTOR
38 :
39 : // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
40 : // provided by child process.
41 3 : LoadContext(const IPC::SerializedLoadContext& aToCopy,
42 : dom::Element* aTopFrameElement,
43 : OriginAttributes& aAttrs)
44 9 : : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
45 : , mNestedFrameId(0)
46 3 : , mIsContent(aToCopy.mIsContent)
47 3 : , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
48 3 : , mUseTrackingProtection(aToCopy.mUseTrackingProtection)
49 : , mOriginAttributes(aAttrs)
50 : #ifdef DEBUG
51 18 : , mIsNotNull(aToCopy.mIsNotNull)
52 : #endif
53 : {
54 3 : }
55 :
56 : // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
57 : // provided by child process.
58 0 : LoadContext(const IPC::SerializedLoadContext& aToCopy,
59 : uint64_t aNestedFrameId,
60 : OriginAttributes& aAttrs)
61 0 : : mTopFrameElement(nullptr)
62 : , mNestedFrameId(aNestedFrameId)
63 0 : , mIsContent(aToCopy.mIsContent)
64 0 : , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
65 0 : , mUseTrackingProtection(aToCopy.mUseTrackingProtection)
66 : , mOriginAttributes(aAttrs)
67 : #ifdef DEBUG
68 0 : , mIsNotNull(aToCopy.mIsNotNull)
69 : #endif
70 : {
71 0 : }
72 :
73 1 : LoadContext(dom::Element* aTopFrameElement,
74 : bool aIsContent,
75 : bool aUsePrivateBrowsing,
76 : bool aUseRemoteTabs,
77 : bool aUseTrackingProtection,
78 : const OriginAttributes& aAttrs)
79 3 : : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
80 : , mNestedFrameId(0)
81 : , mIsContent(aIsContent)
82 : , mUseRemoteTabs(aUseRemoteTabs)
83 : , mUseTrackingProtection(aUseTrackingProtection)
84 : , mOriginAttributes(aAttrs)
85 : #ifdef DEBUG
86 3 : , mIsNotNull(true)
87 : #endif
88 : {
89 1 : MOZ_DIAGNOSTIC_ASSERT(aUsePrivateBrowsing == (aAttrs.mPrivateBrowsingId > 0));
90 1 : }
91 :
92 : // Constructor taking reserved origin attributes.
93 0 : explicit LoadContext(OriginAttributes& aAttrs)
94 0 : : mTopFrameElement(nullptr)
95 : , mNestedFrameId(0)
96 : , mIsContent(false)
97 : , mUseRemoteTabs(false)
98 : , mUseTrackingProtection(false)
99 : , mOriginAttributes(aAttrs)
100 : #ifdef DEBUG
101 0 : , mIsNotNull(true)
102 : #endif
103 : {
104 0 : }
105 :
106 : // Constructor for creating a LoadContext with a given principal's appId and
107 : // browser flag.
108 : explicit LoadContext(nsIPrincipal* aPrincipal,
109 : nsILoadContext* aOptionalBase = nullptr);
110 :
111 : private:
112 3 : ~LoadContext() {}
113 :
114 : nsWeakPtr mTopFrameElement;
115 : uint64_t mNestedFrameId;
116 : bool mIsContent;
117 : bool mUseRemoteTabs;
118 : bool mUseTrackingProtection;
119 : OriginAttributes mOriginAttributes;
120 : #ifdef DEBUG
121 : bool mIsNotNull;
122 : #endif
123 : };
124 :
125 : nsresult CreateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult);
126 : nsresult CreatePrivateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult);
127 :
128 : } // namespace mozilla
129 :
130 : #endif // LoadContext_h
|