2016-05-28 00:54:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-07 22:13:04 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_ipc_backgroundutils_h__
|
|
|
|
#define mozilla_ipc_backgroundutils_h__
|
|
|
|
|
2015-06-04 21:51:57 +03:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "mozilla/OriginAttributes.h"
|
2014-07-07 22:13:04 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
class nsIContentSecurityPolicy;
|
2015-07-01 16:56:00 +03:00
|
|
|
class nsILoadInfo;
|
2019-08-08 03:52:39 +03:00
|
|
|
class nsINode;
|
2014-07-07 22:13:04 +04:00
|
|
|
class nsIPrincipal;
|
2017-05-25 20:42:00 +03:00
|
|
|
class nsIRedirectHistoryEntry;
|
2014-07-07 22:13:04 +04:00
|
|
|
|
2015-06-04 21:51:57 +03:00
|
|
|
namespace IPC {
|
|
|
|
|
2015-11-03 04:50:54 +03:00
|
|
|
namespace detail {
|
|
|
|
template <class ParamType>
|
|
|
|
struct OriginAttributesParamTraits {
|
|
|
|
typedef ParamType paramType;
|
2015-06-04 21:51:57 +03:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) {
|
|
|
|
nsAutoCString suffix;
|
|
|
|
aParam.CreateSuffix(suffix);
|
|
|
|
WriteParam(aMsg, suffix);
|
|
|
|
}
|
|
|
|
|
2016-04-21 07:09:15 +03:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter,
|
|
|
|
paramType* aResult) {
|
2015-06-04 21:51:57 +03:00
|
|
|
nsAutoCString suffix;
|
|
|
|
return ReadParam(aMsg, aIter, &suffix) &&
|
|
|
|
aResult->PopulateFromSuffix(suffix);
|
|
|
|
}
|
|
|
|
};
|
2015-11-03 04:50:54 +03:00
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
template <>
|
2017-01-12 19:38:48 +03:00
|
|
|
struct ParamTraits<mozilla::OriginAttributes>
|
|
|
|
: public detail::OriginAttributesParamTraits<mozilla::OriginAttributes> {};
|
2015-06-04 21:51:57 +03:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace IPC
|
2015-06-04 21:51:57 +03:00
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
namespace mozilla {
|
2020-11-23 19:12:02 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
namespace net {
|
2018-06-04 19:26:51 +03:00
|
|
|
class ChildLoadInfoForwarderArgs;
|
2019-03-04 09:30:00 +03:00
|
|
|
class LoadInfoArgs;
|
2019-08-06 10:30:05 +03:00
|
|
|
class LoadInfo;
|
2018-03-06 09:07:00 +03:00
|
|
|
class ParentLoadInfoForwarderArgs;
|
2017-05-25 20:42:00 +03:00
|
|
|
class RedirectHistoryEntryInfo;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
2015-06-19 01:37:20 +03:00
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
namespace ipc {
|
|
|
|
|
2018-04-11 22:52:47 +03:00
|
|
|
class ContentSecurityPolicy;
|
2019-05-22 02:14:27 +03:00
|
|
|
class CSPInfo;
|
2014-07-07 22:13:04 +04:00
|
|
|
class PrincipalInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a PrincipalInfo to an nsIPrincipal.
|
|
|
|
*
|
2020-05-12 22:02:05 +03:00
|
|
|
* MUST be called on the main thread.
|
2014-07-07 22:13:04 +04:00
|
|
|
*/
|
2020-05-12 22:02:05 +03:00
|
|
|
Result<nsCOMPtr<nsIPrincipal>, nsresult> PrincipalInfoToPrincipal(
|
|
|
|
const PrincipalInfo& aPrincipalInfo);
|
2014-07-07 22:13:04 +04:00
|
|
|
|
2018-04-11 22:52:47 +03:00
|
|
|
/**
|
2019-05-22 02:14:27 +03:00
|
|
|
* Convert an nsIPrincipal to a PrincipalInfo.
|
2018-04-11 22:52:47 +03:00
|
|
|
*
|
|
|
|
* MUST be called on the main thread only.
|
|
|
|
*/
|
2019-05-22 02:14:27 +03:00
|
|
|
nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
|
|
|
PrincipalInfo* aPrincipalInfo,
|
|
|
|
bool aSkipBaseDomain = false);
|
2018-04-11 22:52:47 +03:00
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
/**
|
2019-05-22 02:14:27 +03:00
|
|
|
* Convert a CSPInfo to an nsIContentSecurityPolicy.
|
2014-07-07 22:13:04 +04:00
|
|
|
*
|
|
|
|
* MUST be called on the main thread only.
|
2019-05-22 02:14:27 +03:00
|
|
|
*
|
|
|
|
* If possible, provide a requesting doc, so policy violation events can
|
|
|
|
* be dispatched correctly. If aRequestingDoc is null, then the CSPInfo holds
|
|
|
|
* the necessary fallback information, like a serialized requestPrincipal,
|
|
|
|
* to generate a valid nsIContentSecurityPolicy.
|
2014-07-07 22:13:04 +04:00
|
|
|
*/
|
2019-05-22 02:14:27 +03:00
|
|
|
already_AddRefed<nsIContentSecurityPolicy> CSPInfoToCSP(
|
|
|
|
const CSPInfo& aCSPInfo, mozilla::dom::Document* aRequestingDoc,
|
|
|
|
nsresult* aOptionalResult = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an nsIContentSecurityPolicy to a CSPInfo.
|
|
|
|
*
|
|
|
|
* MUST be called on the main thread only.
|
|
|
|
*/
|
|
|
|
nsresult CSPToCSPInfo(nsIContentSecurityPolicy* aCSP, CSPInfo* aCSPInfo);
|
2014-07-07 22:13:04 +04:00
|
|
|
|
2017-01-28 20:29:13 +03:00
|
|
|
/**
|
|
|
|
* Return true if this PrincipalInfo is a content principal and it has
|
|
|
|
* a privateBrowsing id in its OriginAttributes
|
|
|
|
*/
|
2020-04-12 16:19:57 +03:00
|
|
|
bool IsPrincipalInfoPrivate(const PrincipalInfo& aPrincipalInfo);
|
2017-01-28 20:29:13 +03:00
|
|
|
|
2017-05-25 20:42:00 +03:00
|
|
|
/**
|
|
|
|
* Convert an RedirectHistoryEntryInfo to a nsIRedirectHistoryEntry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
already_AddRefed<nsIRedirectHistoryEntry> RHEntryInfoToRHEntry(
|
2018-05-30 22:21:17 +03:00
|
|
|
const mozilla::net::RedirectHistoryEntryInfo& aRHEntryInfo);
|
2017-05-25 20:42:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an nsIRedirectHistoryEntry to a RedirectHistoryEntryInfo.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsresult RHEntryToRHEntryInfo(
|
|
|
|
nsIRedirectHistoryEntry* aRHEntry,
|
2018-05-30 22:21:17 +03:00
|
|
|
mozilla::net::RedirectHistoryEntryInfo* aRHEntryInfo);
|
2017-05-25 20:42:00 +03:00
|
|
|
|
2015-06-19 01:37:20 +03:00
|
|
|
/**
|
|
|
|
* Convert a LoadInfo to LoadInfoArgs struct.
|
|
|
|
*/
|
|
|
|
nsresult LoadInfoToLoadInfoArgs(
|
|
|
|
nsILoadInfo* aLoadInfo,
|
2019-03-04 09:30:00 +03:00
|
|
|
Maybe<mozilla::net::LoadInfoArgs>* outOptionalLoadInfoArgs);
|
2015-06-19 01:37:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert LoadInfoArgs to a LoadInfo.
|
|
|
|
*/
|
2018-05-30 22:21:17 +03:00
|
|
|
nsresult LoadInfoArgsToLoadInfo(
|
2019-03-04 09:30:00 +03:00
|
|
|
const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
|
2015-06-19 01:37:20 +03:00
|
|
|
nsILoadInfo** outLoadInfo);
|
2019-08-08 03:52:39 +03:00
|
|
|
nsresult LoadInfoArgsToLoadInfo(
|
|
|
|
const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
|
2020-03-01 07:16:22 +03:00
|
|
|
nsINode* aCspToInheritLoadingContext, nsILoadInfo** outLoadInfo);
|
2019-08-06 10:30:05 +03:00
|
|
|
nsresult LoadInfoArgsToLoadInfo(
|
|
|
|
const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
|
|
|
|
mozilla::net::LoadInfo** outLoadInfo);
|
|
|
|
nsresult LoadInfoArgsToLoadInfo(
|
|
|
|
const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
|
2020-03-01 07:16:22 +03:00
|
|
|
nsINode* aCspToInheritLoadingContext, mozilla::net::LoadInfo** outLoadInfo);
|
2015-06-19 01:37:20 +03:00
|
|
|
|
2018-03-06 09:07:00 +03:00
|
|
|
/**
|
|
|
|
* Fills ParentLoadInfoForwarderArgs with properties we want to carry to child
|
|
|
|
* processes.
|
|
|
|
*/
|
|
|
|
void LoadInfoToParentLoadInfoForwarder(
|
|
|
|
nsILoadInfo* aLoadInfo,
|
2018-06-04 19:26:50 +03:00
|
|
|
mozilla::net::ParentLoadInfoForwarderArgs* aForwarderArgsOut);
|
2018-03-06 09:07:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges (replaces) properties of an existing LoadInfo on a child process
|
|
|
|
* with properties carried down through ParentLoadInfoForwarderArgs.
|
|
|
|
*/
|
2018-06-04 19:26:50 +03:00
|
|
|
nsresult MergeParentLoadInfoForwarder(
|
|
|
|
mozilla::net::ParentLoadInfoForwarderArgs const& aForwarderArgs,
|
2018-03-06 09:07:00 +03:00
|
|
|
nsILoadInfo* aLoadInfo);
|
|
|
|
|
2018-06-04 19:26:51 +03:00
|
|
|
/**
|
|
|
|
* Fills ChildLoadInfoForwarderArgs with properties we want to carry to the
|
|
|
|
* parent process after the initial channel creation.
|
|
|
|
*/
|
|
|
|
void LoadInfoToChildLoadInfoForwarder(
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
mozilla::net::ChildLoadInfoForwarderArgs* aForwarderArgsOut);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges (replaces) properties of an existing LoadInfo on the parent process
|
|
|
|
* with properties contained in a ChildLoadInfoForwarderArgs.
|
|
|
|
*/
|
|
|
|
nsresult MergeChildLoadInfoForwarder(
|
|
|
|
const mozilla::net::ChildLoadInfoForwarderArgs& aForwardArgs,
|
|
|
|
nsILoadInfo* aLoadInfo);
|
|
|
|
|
2014-07-07 22:13:04 +04:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ipc_backgroundutils_h__
|