Bug 1806412 - Pass trr mode to content process r=necko-reviewers,valentin

We will need this to detect conditions for TRR fallback warnings.

Depends on D165558

Differential Revision: https://phabricator.services.mozilla.com/D165562
This commit is contained in:
Andrew Creskey 2023-01-16 13:12:05 +00:00
Родитель 902da73f87
Коммит 54443edd66
9 изменённых файлов: 70 добавлений и 0 удалений

Просмотреть файл

@ -690,6 +690,7 @@ mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes(
dont_AddRef(net::ChildDNSService::GetSingleton());
if (dnsServiceChild) {
dnsServiceChild->SetTRRDomain(aXPCOMInit.trrDomain());
dnsServiceChild->SetTRRModeInChild(aXPCOMInit.trrMode());
}
return IPC_OK();
}
@ -2173,6 +2174,16 @@ mozilla::ipc::IPCResult ContentChild::RecvSetCaptivePortalState(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvSetTRRMode(
const nsIDNSService::ResolverMode& mode) {
RefPtr<net::ChildDNSService> dnsServiceChild =
dont_AddRef(net::ChildDNSService::GetSingleton());
if (dnsServiceChild) {
dnsServiceChild->SetTRRModeInChild(mode);
}
return IPC_OK();
}
void ContentChild::ActorDestroy(ActorDestroyReason why) {
if (mForceKillTimer) {
mForceKillTimer->Cancel();

Просмотреть файл

@ -268,6 +268,8 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvSetConnectivity(const bool& connectivity);
mozilla::ipc::IPCResult RecvSetCaptivePortalState(const int32_t& state);
mozilla::ipc::IPCResult RecvSetTRRMode(
const nsIDNSService::ResolverMode& mode);
mozilla::ipc::IPCResult RecvBidiKeyboardNotify(const bool& isLangRTL,
const bool& haveBidiKeyboards);

Просмотреть файл

@ -649,6 +649,7 @@ static const char* sObserverTopics[] = {
"cookie-changed",
"private-cookie-changed",
NS_NETWORK_LINK_TYPE_TOPIC,
NS_NETWORK_TRR_MODE_CHANGED_TOPIC,
"network:socket-process-crashed",
DEFAULT_TIMEZONE_CHANGED_OBSERVER_TOPIC,
};
@ -3107,6 +3108,10 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
dns->GetTrrDomain(xpcomInit.trrDomain());
nsIDNSService::ResolverMode mode;
dns->GetCurrentTrrMode(&mode);
xpcomInit.trrMode() = mode;
Unused << SendSetXPCOMProcessAttributes(
xpcomInit, initialData, lnf, fontList, std::move(sharedUASheetHandle),
sharedUASheetAddress, std::move(sharedFontListBlocks),
@ -4061,6 +4066,11 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic,
Unused << SendSocketProcessCrashed();
} else if (!strcmp(aTopic, DEFAULT_TIMEZONE_CHANGED_OBSERVER_TOPIC)) {
Unused << SendSystemTimezoneChanged();
} else if (!strcmp(aTopic, NS_NETWORK_TRR_MODE_CHANGED_TOPIC)) {
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
nsIDNSService::ResolverMode mode;
dns->GetCurrentTrrMode(&mode);
Unused << SendSetTRRMode(mode);
}
return NS_OK;

Просмотреть файл

@ -79,6 +79,7 @@ include "mozilla/glean/GleanMetrics.h";
include "mozilla/ipc/ByteBufUtils.h";
include "mozilla/ipc/TransportSecurityInfoUtils.h";
include "mozilla/ipc/URIUtils.h";
include "mozilla/net/NeckoMessageUtils.h";
include "mozilla/PermissionDelegateIPCUtils.h";
[RefCounted] using class nsIDOMGeoPosition from "nsGeoPositionIPCSerialiser.h";
@ -157,6 +158,7 @@ using mozilla::dom::PerformanceTimingData from "mozilla/dom/PerformanceTiming.h"
using Wireframe from "mozilla/dom/DocumentBinding.h";
using mozilla::PerfStats::MetricMask from "mozilla/PerfStats.h";
[RefCounted] using class nsIX509Cert from "nsIX509Cert.h";
using nsIDNSService::ResolverMode from "nsIDNSService.h";
union ChromeRegistryItem
{
@ -367,6 +369,7 @@ struct XPCOMInitData
DynamicScalarDefinition[] dynamicScalarDefs;
MetricMask perfStatsMask;
nsCString trrDomain;
ResolverMode trrMode;
};
struct VisitedQueryResult
@ -654,6 +657,7 @@ child:
async SetOffline(bool offline);
async SetConnectivity(bool connectivity);
async SetCaptivePortalState(int32_t aState);
async SetTRRMode(ResolverMode aMode);
async NotifyVisited(VisitedQueryResult[] uri);

Просмотреть файл

@ -338,6 +338,10 @@ ChildDNSService::GetCurrentTrrURI(nsACString& aURI) {
NS_IMETHODIMP
ChildDNSService::GetCurrentTrrMode(nsIDNSService::ResolverMode* aMode) {
if (XRE_IsContentProcess()) {
*aMode = mTRRMode;
return NS_OK;
}
if (!mTRRServiceParent) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -346,6 +350,16 @@ ChildDNSService::GetCurrentTrrMode(nsIDNSService::ResolverMode* aMode) {
return NS_OK;
}
NS_IMETHODIMP
ChildDNSService::SetTRRModeInChild(nsIDNSService::ResolverMode mode) {
if (!XRE_IsContentProcess()) {
MOZ_ASSERT(false, "Why are we calling this?");
return NS_ERROR_NOT_AVAILABLE;
}
mTRRMode = mode;
return NS_OK;
}
NS_IMETHODIMP
ChildDNSService::GetCurrentTrrConfirmationState(uint32_t* aConfirmationState) {
if (!mTRRServiceParent) {

Просмотреть файл

@ -68,6 +68,9 @@ class ChildDNSService final : public DNSServiceBase, public nsPIDNSService {
RefPtr<TRRServiceParent> mTRRServiceParent;
nsCString mTRRDomain;
// Only set in the content process.
nsIDNSService::ResolverMode mTRRMode =
nsIDNSService::ResolverMode::MODE_NATIVEONLY;
};
} // namespace net

Просмотреть файл

@ -1469,6 +1469,12 @@ nsDNSService::GetCurrentTrrURI(nsACString& aURI) {
return NS_OK;
}
NS_IMETHODIMP
nsDNSService::SetTRRModeInChild(nsIDNSService::ResolverMode mode) {
MOZ_ASSERT(false, "Why are we calling this?");
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsDNSService::GetCurrentTrrMode(nsIDNSService::ResolverMode* aMode) {
*aMode = nsIDNSService::MODE_NATIVEONLY; // The default mode.

Просмотреть файл

@ -307,6 +307,8 @@ interface nsIDNSService : nsISupports
*/
readonly attribute nsIDNSService_ResolverMode currentTrrMode;
void setTRRModeInChild(in nsIDNSService_ResolverMode mode);
/**
* The TRRService's current confirmation state.
* This is mostly for testing purposes.

Просмотреть файл

@ -167,6 +167,24 @@ struct ParamTraits<nsIDNSService::DNSFlags>
nsIDNSService::DNSFlags, nsIDNSService::DNSFlags::ALL_DNSFLAGS_BITS> {
};
template <>
struct ParamTraits<nsIDNSService::ResolverMode> {
static void Write(MessageWriter* aWriter,
const nsIDNSService::ResolverMode& aParam) {
WriteParam(aWriter, (uint8_t)aParam);
}
static bool Read(MessageReader* aReader,
nsIDNSService::ResolverMode* aResult) {
uint8_t mode;
if (!ReadParam(aReader, &mode)) {
return false;
}
// TODO: sanity check
*aResult = static_cast<nsIDNSService::ResolverMode>(mode);
return true;
}
};
} // namespace IPC
#endif // mozilla_net_NeckoMessageUtils_h