Bug 1902621 - Sanity check for TRRMode, nsITRRSkipReason, and ResolverMode, r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D218812
This commit is contained in:
Kershaw Chang 2024-08-08 12:30:15 +00:00
Родитель aa85b1859f
Коммит d4eaf72722
3 изменённых файлов: 21 добавлений и 47 удалений

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

@ -3891,8 +3891,13 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic,
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
nsIDNSService::ResolverMode mode;
dns->GetCurrentTrrMode(&mode);
Unused << SendSetTRRMode(mode, static_cast<nsIDNSService::ResolverMode>(
StaticPrefs::network_trr_mode()));
nsIDNSService::ResolverMode modeFromPref =
static_cast<nsIDNSService::ResolverMode>(
StaticPrefs::network_trr_mode());
if (modeFromPref > nsIDNSService::MODE_TRROFF) {
modeFromPref = nsIDNSService::MODE_TRROFF;
}
Unused << SendSetTRRMode(mode, modeFromPref);
}
return NS_OK;

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

@ -61,6 +61,7 @@ interface nsITRRSkipReason: nsISupports
TRR_HEURISTIC_TRIPPED_PROXY = 46, // The heuristic was tripped due to a proxy being detected
TRR_HEURISTIC_TRIPPED_NRPT = 47, // The heuristic was tripped due to a NRPT being detected
TRR_BAD_URL = 48, // We attempted to use a bad URL (doesn't parse or is not https).
eLAST_VALUE = TRR_BAD_URL, // This entry should always hold the last and largest value in the enum
};
};

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

@ -129,37 +129,16 @@ struct ParamTraits<mozilla::net::NetAddr> {
};
template <>
struct ParamTraits<nsIRequest::TRRMode> {
static void Write(MessageWriter* aWriter, const nsIRequest::TRRMode& aParam) {
WriteParam(aWriter, (uint8_t)aParam);
}
static bool Read(MessageReader* aReader, nsIRequest::TRRMode* aResult) {
uint8_t mode;
if (!ReadParam(aReader, &mode)) {
return false;
}
// TODO: sanity check
*aResult = static_cast<nsIRequest::TRRMode>(mode);
return true;
}
};
struct ParamTraits<nsIRequest::TRRMode>
: public ContiguousEnumSerializerInclusive<nsIRequest::TRRMode,
nsIRequest::TRR_DEFAULT_MODE,
nsIRequest::TRR_ONLY_MODE> {};
template <>
struct ParamTraits<nsITRRSkipReason::value> {
static void Write(MessageWriter* aWriter,
const nsITRRSkipReason::value& aParam) {
WriteParam(aWriter, (uint8_t)aParam);
}
static bool Read(MessageReader* aReader, nsITRRSkipReason::value* aResult) {
uint8_t reason;
if (!ReadParam(aReader, &reason)) {
return false;
}
// TODO: sanity check
*aResult = static_cast<nsITRRSkipReason::value>(reason);
return true;
}
};
struct ParamTraits<nsITRRSkipReason::value>
: public ContiguousEnumSerializerInclusive<
nsITRRSkipReason::value, nsITRRSkipReason::value::TRR_UNSET,
nsITRRSkipReason::value::eLAST_VALUE> {};
template <>
struct ParamTraits<nsIDNSService::DNSFlags>
@ -168,22 +147,11 @@ struct ParamTraits<nsIDNSService::DNSFlags>
};
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;
}
};
struct ParamTraits<nsIDNSService::ResolverMode>
: public ContiguousEnumSerializerInclusive<
nsIDNSService::ResolverMode,
nsIDNSService::ResolverMode::MODE_NATIVEONLY,
nsIDNSService::ResolverMode::MODE_TRROFF> {};
} // namespace IPC