Bug 1660755 [wpt PR 25207] - [scroll-animations] Allow null source in ScrollTimeline...
[gecko.git] / ipc / glue / BackgroundUtils.h
blobb2b0f66fe8ccf40a32fb2f58dad2ded8240011b1
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"
13 #include "nsCOMPtr.h"
14 #include "nscore.h"
16 class nsIContentSecurityPolicy;
17 class nsILoadInfo;
18 class nsINode;
19 class nsIPrincipal;
20 class nsIRedirectHistoryEntry;
22 namespace IPC {
24 namespace detail {
25 template <class ParamType>
26 struct OriginAttributesParamTraits {
27 typedef ParamType paramType;
29 static void Write(Message* aMsg, const paramType& aParam) {
30 nsAutoCString suffix;
31 aParam.CreateSuffix(suffix);
32 WriteParam(aMsg, suffix);
35 static bool Read(const Message* aMsg, PickleIterator* aIter,
36 paramType* aResult) {
37 nsAutoCString suffix;
38 return ReadParam(aMsg, aIter, &suffix) &&
39 aResult->PopulateFromSuffix(suffix);
42 } // namespace detail
44 template <>
45 struct ParamTraits<mozilla::OriginAttributes>
46 : public detail::OriginAttributesParamTraits<mozilla::OriginAttributes> {};
48 } // namespace IPC
50 namespace mozilla {
51 namespace net {
52 class ChildLoadInfoForwarderArgs;
53 class LoadInfoArgs;
54 class LoadInfo;
55 class ParentLoadInfoForwarderArgs;
56 class RedirectHistoryEntryInfo;
57 } // namespace net
59 namespace ipc {
61 class ContentSecurityPolicy;
62 class CSPInfo;
63 class PrincipalInfo;
65 /**
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);
73 /**
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);
82 /**
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);
96 /**
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
149 * processes.
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);
179 } // namespace ipc
180 } // namespace mozilla
182 #endif // mozilla_ipc_backgroundutils_h__