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/OriginAttributes.h"
16 class nsIContentSecurityPolicy
;
20 class nsIRedirectHistoryEntry
;
25 template <class ParamType
>
26 struct OriginAttributesParamTraits
{
27 typedef ParamType paramType
;
29 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
31 aParam
.CreateSuffix(suffix
);
32 WriteParam(aWriter
, suffix
);
35 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
37 return ReadParam(aReader
, &suffix
) && aResult
->PopulateFromSuffix(suffix
);
43 struct ParamTraits
<mozilla::OriginAttributes
>
44 : public detail::OriginAttributesParamTraits
<mozilla::OriginAttributes
> {};
55 class ChildLoadInfoForwarderArgs
;
58 class ParentLoadInfoForwarderArgs
;
59 class RedirectHistoryEntryInfo
;
64 class ContentSecurityPolicy
;
69 * Convert a PrincipalInfo to an nsIPrincipal.
71 * MUST be called on the main thread.
73 Result
<nsCOMPtr
<nsIPrincipal
>, nsresult
> PrincipalInfoToPrincipal(
74 const PrincipalInfo
& aPrincipalInfo
);
77 * Convert an nsIPrincipal to a PrincipalInfo.
79 * MUST be called on the main thread only.
81 nsresult
PrincipalToPrincipalInfo(nsIPrincipal
* aPrincipal
,
82 PrincipalInfo
* aPrincipalInfo
,
83 bool aSkipBaseDomain
= false);
86 * Compare storage keys for equivalence.
88 * Only use with storage keys retrieved from nsIGlobalObject::GetStorageKey!
89 * Bug 1776271 tracks enhancing this into a proper type.
91 bool StorageKeysEqual(const PrincipalInfo
& aLeft
, const PrincipalInfo
& aRight
);
94 * Convert a CSPInfo to an nsIContentSecurityPolicy.
96 * MUST be called on the main thread only.
98 * If possible, provide a requesting doc, so policy violation events can
99 * be dispatched correctly. If aRequestingDoc is null, then the CSPInfo holds
100 * the necessary fallback information, like a serialized requestPrincipal,
101 * to generate a valid nsIContentSecurityPolicy.
103 already_AddRefed
<nsIContentSecurityPolicy
> CSPInfoToCSP(
104 const CSPInfo
& aCSPInfo
, mozilla::dom::Document
* aRequestingDoc
,
105 nsresult
* aOptionalResult
= nullptr);
108 * Convert an nsIContentSecurityPolicy to a CSPInfo.
110 * MUST be called on the main thread only.
112 nsresult
CSPToCSPInfo(nsIContentSecurityPolicy
* aCSP
, CSPInfo
* aCSPInfo
);
115 * Return true if this PrincipalInfo is a content principal and it has
116 * a privateBrowsing id in its OriginAttributes
118 bool IsPrincipalInfoPrivate(const PrincipalInfo
& aPrincipalInfo
);
121 * Convert an RedirectHistoryEntryInfo to a nsIRedirectHistoryEntry.
124 already_AddRefed
<nsIRedirectHistoryEntry
> RHEntryInfoToRHEntry(
125 const mozilla::net::RedirectHistoryEntryInfo
& aRHEntryInfo
);
128 * Convert an nsIRedirectHistoryEntry to a RedirectHistoryEntryInfo.
131 nsresult
RHEntryToRHEntryInfo(
132 nsIRedirectHistoryEntry
* aRHEntry
,
133 mozilla::net::RedirectHistoryEntryInfo
* aRHEntryInfo
);
136 * Convert a LoadInfo to LoadInfoArgs struct.
138 nsresult
LoadInfoToLoadInfoArgs(nsILoadInfo
* aLoadInfo
,
139 mozilla::net::LoadInfoArgs
* outLoadInfoArgs
);
142 * Convert LoadInfoArgs to a LoadInfo.
144 nsresult
LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs
& aLoadInfoArgs
,
145 const nsACString
& aOriginRemoteType
,
146 nsILoadInfo
** outLoadInfo
);
147 nsresult
LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs
& aLoadInfoArgs
,
148 const nsACString
& aOriginRemoteType
,
149 nsINode
* aCspToInheritLoadingContext
,
150 nsILoadInfo
** outLoadInfo
);
151 nsresult
LoadInfoArgsToLoadInfo(const net::LoadInfoArgs
& aLoadInfoArgs
,
152 const nsACString
& aOriginRemoteType
,
153 mozilla::net::LoadInfo
** outLoadInfo
);
154 nsresult
LoadInfoArgsToLoadInfo(const net::LoadInfoArgs
& aLoadInfoArgs
,
155 const nsACString
& aOriginRemoteType
,
156 nsINode
* aCspToInheritLoadingContext
,
157 mozilla::net::LoadInfo
** outLoadInfo
);
160 * Fills ParentLoadInfoForwarderArgs with properties we want to carry to child
163 void LoadInfoToParentLoadInfoForwarder(
164 nsILoadInfo
* aLoadInfo
,
165 mozilla::net::ParentLoadInfoForwarderArgs
* aForwarderArgsOut
);
168 * Merges (replaces) properties of an existing LoadInfo on a child process
169 * with properties carried down through ParentLoadInfoForwarderArgs.
171 nsresult
MergeParentLoadInfoForwarder(
172 mozilla::net::ParentLoadInfoForwarderArgs
const& aForwarderArgs
,
173 nsILoadInfo
* aLoadInfo
);
176 * Fills ChildLoadInfoForwarderArgs with properties we want to carry to the
177 * parent process after the initial channel creation.
179 void LoadInfoToChildLoadInfoForwarder(
180 nsILoadInfo
* aLoadInfo
,
181 mozilla::net::ChildLoadInfoForwarderArgs
* aForwarderArgsOut
);
184 * Merges (replaces) properties of an existing LoadInfo on the parent process
185 * with properties contained in a ChildLoadInfoForwarderArgs.
187 nsresult
MergeChildLoadInfoForwarder(
188 const mozilla::net::ChildLoadInfoForwarderArgs
& aForwardArgs
,
189 nsILoadInfo
* aLoadInfo
);
192 } // namespace mozilla
194 #endif // mozilla_ipc_backgroundutils_h__