Bug 1834537 - Part 6: Simplify GCRuntime::checkAllocatorState a little r=sfink
[gecko.git] / ipc / glue / BackgroundUtils.h
blobdb1d48d2e003f5a9cba08540c0ded60661824b8e
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"
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(MessageWriter* aWriter, const paramType& aParam) {
30 nsAutoCString suffix;
31 aParam.CreateSuffix(suffix);
32 WriteParam(aWriter, suffix);
35 static bool Read(MessageReader* aReader, paramType* aResult) {
36 nsAutoCString suffix;
37 return ReadParam(aReader, &suffix) && aResult->PopulateFromSuffix(suffix);
40 } // namespace detail
42 template <>
43 struct ParamTraits<mozilla::OriginAttributes>
44 : public detail::OriginAttributesParamTraits<mozilla::OriginAttributes> {};
46 } // namespace IPC
48 namespace mozilla {
50 namespace dom {
51 class Document;
54 namespace net {
55 class ChildLoadInfoForwarderArgs;
56 class LoadInfoArgs;
57 class LoadInfo;
58 class ParentLoadInfoForwarderArgs;
59 class RedirectHistoryEntryInfo;
60 } // namespace net
62 namespace ipc {
64 class ContentSecurityPolicy;
65 class CSPInfo;
66 class PrincipalInfo;
68 /**
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);
76 /**
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);
85 /**
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);
93 /**
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(
139 nsILoadInfo* aLoadInfo,
140 Maybe<mozilla::net::LoadInfoArgs>* outOptionalLoadInfoArgs);
143 * Convert LoadInfoArgs to a LoadInfo.
145 nsresult LoadInfoArgsToLoadInfo(
146 const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
147 const nsACString& aOriginRemoteType, nsILoadInfo** outLoadInfo);
148 nsresult LoadInfoArgsToLoadInfo(
149 const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
150 const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
151 nsILoadInfo** outLoadInfo);
152 nsresult LoadInfoArgsToLoadInfo(
153 const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
154 const nsACString& aOriginRemoteType, mozilla::net::LoadInfo** outLoadInfo);
155 nsresult LoadInfoArgsToLoadInfo(
156 const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
157 const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
158 mozilla::net::LoadInfo** outLoadInfo);
161 * Fills ParentLoadInfoForwarderArgs with properties we want to carry to child
162 * processes.
164 void LoadInfoToParentLoadInfoForwarder(
165 nsILoadInfo* aLoadInfo,
166 mozilla::net::ParentLoadInfoForwarderArgs* aForwarderArgsOut);
169 * Merges (replaces) properties of an existing LoadInfo on a child process
170 * with properties carried down through ParentLoadInfoForwarderArgs.
172 nsresult MergeParentLoadInfoForwarder(
173 mozilla::net::ParentLoadInfoForwarderArgs const& aForwarderArgs,
174 nsILoadInfo* aLoadInfo);
177 * Fills ChildLoadInfoForwarderArgs with properties we want to carry to the
178 * parent process after the initial channel creation.
180 void LoadInfoToChildLoadInfoForwarder(
181 nsILoadInfo* aLoadInfo,
182 mozilla::net::ChildLoadInfoForwarderArgs* aForwarderArgsOut);
185 * Merges (replaces) properties of an existing LoadInfo on the parent process
186 * with properties contained in a ChildLoadInfoForwarderArgs.
188 nsresult MergeChildLoadInfoForwarder(
189 const mozilla::net::ChildLoadInfoForwarderArgs& aForwardArgs,
190 nsILoadInfo* aLoadInfo);
192 } // namespace ipc
193 } // namespace mozilla
195 #endif // mozilla_ipc_backgroundutils_h__