diff options
Diffstat (limited to 'netwerk/base/NetworkConnectivityService.cpp')
-rw-r--r-- | netwerk/base/NetworkConnectivityService.cpp | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/netwerk/base/NetworkConnectivityService.cpp b/netwerk/base/NetworkConnectivityService.cpp index 1e126742ce..2f3b80b724 100644 --- a/netwerk/base/NetworkConnectivityService.cpp +++ b/netwerk/base/NetworkConnectivityService.cpp @@ -4,6 +4,7 @@ #include "DNSUtils.h" #include "NetworkConnectivityService.h" +#include "mozilla/AppShutdown.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/net/SocketProcessParent.h" #include "mozilla/Preferences.h" @@ -30,14 +31,6 @@ NS_IMPL_ISUPPORTS(NetworkConnectivityService, nsIDNSListener, nsIObserver, static StaticRefPtr<NetworkConnectivityService> gConnService; -NetworkConnectivityService::NetworkConnectivityService() - : mDNSv4(UNKNOWN), - mDNSv6(UNKNOWN), - mIPv4(UNKNOWN), - mIPv6(UNKNOWN), - mNAT64(UNKNOWN), - mLock("nat64prefixes") {} - // static already_AddRefed<NetworkConnectivityService> NetworkConnectivityService::GetSingleton() { @@ -45,6 +38,10 @@ NetworkConnectivityService::GetSingleton() { return do_AddRef(gConnService); } + if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { + return nullptr; + } + RefPtr<NetworkConnectivityService> service = new NetworkConnectivityService(); service->Init(); @@ -60,6 +57,8 @@ nsresult NetworkConnectivityService::Init() { observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, false); observerService->AddObserver(this, "network:captive-portal-connectivity", false); + observerService->AddObserver(this, "browser-idle-startup-tasks-finished", + false); return NS_OK; } @@ -79,6 +78,13 @@ NetworkConnectivityService::GetDNSv6(ConnectivityState* aState) { } NS_IMETHODIMP +NetworkConnectivityService::GetDNS_HTTPS(ConnectivityState* aState) { + NS_ENSURE_ARG(aState); + *aState = mDNS_HTTPS; + return NS_OK; +} + +NS_IMETHODIMP NetworkConnectivityService::GetIPv4(ConnectivityState* aState) { NS_ENSURE_ARG(aState); *aState = mIPv4; @@ -154,6 +160,7 @@ static inline bool NAT64PrefixCompare(const NetAddr& prefix1, void NetworkConnectivityService::PerformChecks() { mDNSv4 = UNKNOWN; mDNSv6 = UNKNOWN; + mDNS_HTTPS = UNKNOWN; mIPv4 = UNKNOWN; mIPv6 = UNKNOWN; @@ -281,12 +288,16 @@ NetworkConnectivityService::OnLookupComplete(nsICancelable* aRequest, } else if (aRequest == mDNSv6Request) { mDNSv6 = state; mDNSv6Request = nullptr; + } else if (aRequest == mDNS_HTTPSRequest) { + mDNS_HTTPS = state; + mDNS_HTTPSRequest = nullptr; } else if (aRequest == mNAT64Request) { mNAT64Request = nullptr; SaveNAT64Prefixes(aRecord); } - if (!mDNSv4Request && !mDNSv6Request && !mNAT64Request) { + if (!mDNSv4Request && !mDNSv6Request && !mDNS_HTTPSRequest && + !mNAT64Request) { NotifyObservers("network:connectivity-service:dns-checks-complete"); } return NS_OK; @@ -328,6 +339,16 @@ NetworkConnectivityService::RecheckDNS() { getter_AddRefs(mDNSv6Request)); NS_ENSURE_SUCCESS(rv, rv); + Preferences::GetCString("network.connectivity-service.DNS_HTTPS.domain", + host); + rv = dns->AsyncResolveNative(host, nsIDNSService::RESOLVE_TYPE_HTTPSSVC, + nsIDNSService::RESOLVE_TRR_DISABLED_MODE, + nullptr, this, NS_GetCurrentThread(), attrs, + getter_AddRefs(mDNS_HTTPSRequest)); + if (NS_FAILED(rv)) { + mDNS_HTTPSRequest = nullptr; + } + if (StaticPrefs::network_connectivity_service_nat64_check()) { rv = dns->AsyncResolveNative("ipv4only.arpa"_ns, nsIDNSService::RESOLVE_TYPE_DEFAULT, @@ -355,6 +376,10 @@ NetworkConnectivityService::Observe(nsISupports* aSubject, const char* aTopic, mDNSv6Request->Cancel(NS_ERROR_ABORT); mDNSv6Request = nullptr; } + if (mDNS_HTTPSRequest) { + mDNS_HTTPSRequest->Cancel(NS_ERROR_ABORT); + mDNS_HTTPSRequest = nullptr; + } if (mNAT64Request) { mNAT64Request->Cancel(NS_ERROR_ABORT); mNAT64Request = nullptr; @@ -370,6 +395,8 @@ NetworkConnectivityService::Observe(nsISupports* aSubject, const char* aTopic, !NS_LITERAL_STRING_FROM_CSTRING(NS_NETWORK_LINK_DATA_UNKNOWN) .Equals(aData)) { PerformChecks(); + } else if (!strcmp(aTopic, "browser-idle-startup-tasks-finished")) { + PerformChecks(); } return NS_OK; |