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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_backgroundutils_h__
8 #define mozilla_ipc_backgroundutils_h__
10 #include "ipc/IPCMessageUtils.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/BasePrincipal.h"
16 class nsIContentSecurityPolicy
;
20 class nsIRedirectHistoryEntry
;
25 template <class ParamType
>
26 struct OriginAttributesParamTraits
{
27 typedef ParamType paramType
;
29 static void Write(Message
* aMsg
, const paramType
& aParam
) {
31 aParam
.CreateSuffix(suffix
);
32 WriteParam(aMsg
, suffix
);
35 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
38 return ReadParam(aMsg
, aIter
, &suffix
) &&
39 aResult
->PopulateFromSuffix(suffix
);
45 struct ParamTraits
<mozilla::OriginAttributes
>
46 : public detail::OriginAttributesParamTraits
<mozilla::OriginAttributes
> {};
52 class ChildLoadInfoForwarderArgs
;
55 class ParentLoadInfoForwarderArgs
;
56 class RedirectHistoryEntryInfo
;
61 class ContentSecurityPolicy
;
66 * Convert a PrincipalInfo to an nsIPrincipal.
68 * MUST be called on the main thread.
70 Result
<nsCOMPtr
<nsIPrincipal
>, nsresult
> PrincipalInfoToPrincipal(
71 const PrincipalInfo
& aPrincipalInfo
);
74 * Convert an nsIPrincipal to a PrincipalInfo.
76 * MUST be called on the main thread only.
78 nsresult
PrincipalToPrincipalInfo(nsIPrincipal
* aPrincipal
,
79 PrincipalInfo
* aPrincipalInfo
,
80 bool aSkipBaseDomain
= false);
83 * Convert a CSPInfo to an nsIContentSecurityPolicy.
85 * MUST be called on the main thread only.
87 * If possible, provide a requesting doc, so policy violation events can
88 * be dispatched correctly. If aRequestingDoc is null, then the CSPInfo holds
89 * the necessary fallback information, like a serialized requestPrincipal,
90 * to generate a valid nsIContentSecurityPolicy.
92 already_AddRefed
<nsIContentSecurityPolicy
> CSPInfoToCSP(
93 const CSPInfo
& aCSPInfo
, mozilla::dom::Document
* aRequestingDoc
,
94 nsresult
* aOptionalResult
= nullptr);
97 * Convert an nsIContentSecurityPolicy to a CSPInfo.
99 * MUST be called on the main thread only.
101 nsresult
CSPToCSPInfo(nsIContentSecurityPolicy
* aCSP
, CSPInfo
* aCSPInfo
);
104 * Return true if this PrincipalInfo is a content principal and it has
105 * a privateBrowsing id in its OriginAttributes
107 bool IsPrincipalInfoPrivate(const PrincipalInfo
& aPrincipalInfo
);
110 * Convert an RedirectHistoryEntryInfo to a nsIRedirectHistoryEntry.
113 already_AddRefed
<nsIRedirectHistoryEntry
> RHEntryInfoToRHEntry(
114 const mozilla::net::RedirectHistoryEntryInfo
& aRHEntryInfo
);
117 * Convert an nsIRedirectHistoryEntry to a RedirectHistoryEntryInfo.
120 nsresult
RHEntryToRHEntryInfo(
121 nsIRedirectHistoryEntry
* aRHEntry
,
122 mozilla::net::RedirectHistoryEntryInfo
* aRHEntryInfo
);
125 * Convert a LoadInfo to LoadInfoArgs struct.
127 nsresult
LoadInfoToLoadInfoArgs(
128 nsILoadInfo
* aLoadInfo
,
129 Maybe
<mozilla::net::LoadInfoArgs
>* outOptionalLoadInfoArgs
);
132 * Convert LoadInfoArgs to a LoadInfo.
134 nsresult
LoadInfoArgsToLoadInfo(
135 const Maybe
<mozilla::net::LoadInfoArgs
>& aOptionalLoadInfoArgs
,
136 nsILoadInfo
** outLoadInfo
);
137 nsresult
LoadInfoArgsToLoadInfo(
138 const Maybe
<mozilla::net::LoadInfoArgs
>& aOptionalLoadInfoArgs
,
139 nsINode
* aCspToInheritLoadingContext
, nsILoadInfo
** outLoadInfo
);
140 nsresult
LoadInfoArgsToLoadInfo(
141 const Maybe
<net::LoadInfoArgs
>& aOptionalLoadInfoArgs
,
142 mozilla::net::LoadInfo
** outLoadInfo
);
143 nsresult
LoadInfoArgsToLoadInfo(
144 const Maybe
<net::LoadInfoArgs
>& aOptionalLoadInfoArgs
,
145 nsINode
* aCspToInheritLoadingContext
, mozilla::net::LoadInfo
** outLoadInfo
);
148 * Fills ParentLoadInfoForwarderArgs with properties we want to carry to child
151 void LoadInfoToParentLoadInfoForwarder(
152 nsILoadInfo
* aLoadInfo
,
153 mozilla::net::ParentLoadInfoForwarderArgs
* aForwarderArgsOut
);
156 * Merges (replaces) properties of an existing LoadInfo on a child process
157 * with properties carried down through ParentLoadInfoForwarderArgs.
159 nsresult
MergeParentLoadInfoForwarder(
160 mozilla::net::ParentLoadInfoForwarderArgs
const& aForwarderArgs
,
161 nsILoadInfo
* aLoadInfo
);
164 * Fills ChildLoadInfoForwarderArgs with properties we want to carry to the
165 * parent process after the initial channel creation.
167 void LoadInfoToChildLoadInfoForwarder(
168 nsILoadInfo
* aLoadInfo
,
169 mozilla::net::ChildLoadInfoForwarderArgs
* aForwarderArgsOut
);
172 * Merges (replaces) properties of an existing LoadInfo on the parent process
173 * with properties contained in a ChildLoadInfoForwarderArgs.
175 nsresult
MergeChildLoadInfoForwarder(
176 const mozilla::net::ChildLoadInfoForwarderArgs
& aForwardArgs
,
177 nsILoadInfo
* aLoadInfo
);
180 } // namespace mozilla
182 #endif // mozilla_ipc_backgroundutils_h__