Bug 1890277: part 4) Add CSPParser support for the `trusted-types` directive, guarded...
[gecko.git] / netwerk / dns / nsDNSService2.h
blob523abcb613b877f0015bb7a276957e4197aeabd9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et 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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDNSService2_h__
8 #define nsDNSService2_h__
10 #include "DNSServiceBase.h"
11 #include "nsClassHashtable.h"
12 #include "nsPIDNSService.h"
13 #include "nsIIDNService.h"
14 #include "nsIMemoryReporter.h"
15 #include "nsIObserver.h"
16 #include "nsHostResolver.h"
17 #include "nsString.h"
18 #include "nsTHashSet.h"
19 #include "nsHashKeys.h"
20 #include "mozilla/Mutex.h"
21 #include "mozilla/Attributes.h"
22 #include "TRRService.h"
24 class nsAuthSSPI;
26 class DNSServiceWrapper final : public nsPIDNSService {
27 public:
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_FORWARD_NSPIDNSSERVICE(PIDNSService()->)
30 NS_FORWARD_NSIDNSSERVICE(DNSService()->)
32 DNSServiceWrapper() = default;
34 static already_AddRefed<nsIDNSService> GetSingleton();
35 static void SwitchToBackupDNSService();
37 private:
38 ~DNSServiceWrapper() = default;
39 nsIDNSService* DNSService();
40 nsPIDNSService* PIDNSService();
42 mozilla::Mutex mLock{"DNSServiceWrapper.mLock"};
43 nsCOMPtr<nsIDNSService> mDNSServiceInUse;
44 nsCOMPtr<nsIDNSService> mBackupDNSService;
47 class nsDNSService final : public mozilla::net::DNSServiceBase,
48 public nsPIDNSService,
49 public nsIMemoryReporter {
50 public:
51 NS_DECL_ISUPPORTS_INHERITED
52 NS_DECL_NSPIDNSSERVICE
53 NS_DECL_NSIDNSSERVICE
54 NS_DECL_NSIOBSERVER
55 NS_DECL_NSIMEMORYREPORTER
57 nsDNSService() = default;
59 static already_AddRefed<nsIDNSService> GetXPCOMSingleton();
61 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
63 bool GetOffline() const;
65 protected:
66 friend class nsAuthSSPI;
67 friend class DNSServiceWrapper;
69 nsresult DeprecatedSyncResolve(
70 const nsACString& aHostname, nsIDNSService::DNSFlags flags,
71 const mozilla::OriginAttributes& aOriginAttributes,
72 nsIDNSRecord** result);
74 private:
75 ~nsDNSService() = default;
77 void ReadPrefs(const char* name) override;
78 static already_AddRefed<nsDNSService> GetSingleton();
80 uint16_t GetAFForLookup(const nsACString& host,
81 nsIDNSService::DNSFlags flags);
83 nsresult PreprocessHostname(bool aLocalDomain, const nsACString& aInput,
84 nsIIDNService* aIDN, nsACString& aACE);
86 bool IsLocalDomain(const nsACString& aHostname) const;
88 nsresult AsyncResolveInternal(
89 const nsACString& aHostname, uint16_t type, nsIDNSService::DNSFlags flags,
90 nsIDNSAdditionalInfo* aInfo, nsIDNSListener* aListener,
91 nsIEventTarget* target_,
92 const mozilla::OriginAttributes& aOriginAttributes,
93 nsICancelable** result);
95 nsresult CancelAsyncResolveInternal(
96 const nsACString& aHostname, uint16_t aType,
97 nsIDNSService::DNSFlags aFlags, nsIDNSAdditionalInfo* aInfo,
98 nsIDNSListener* aListener, nsresult aReason,
99 const mozilla::OriginAttributes& aOriginAttributes);
101 nsresult ResolveInternal(const nsACString& aHostname,
102 nsIDNSService::DNSFlags flags,
103 const mozilla::OriginAttributes& aOriginAttributes,
104 nsIDNSRecord** result);
106 // Locks the mutex and returns an addreffed resolver. May return null.
107 already_AddRefed<nsHostResolver> GetResolverLocked();
109 RefPtr<nsHostResolver> mResolver;
110 nsCOMPtr<nsIIDNService> mIDN;
112 // mLock protects access to mResolver, mLocalDomains, mIPv4OnlyDomains and
113 // mFailedSVCDomainNames
114 mozilla::Mutex mLock MOZ_UNANNOTATED{"nsDNSServer.mLock"};
116 // mIPv4OnlyDomains is a comma-separated list of domains for which only
117 // IPv4 DNS lookups are performed. This allows the user to disable IPv6 on
118 // a per-domain basis and work around broken DNS servers. See bug 68796.
119 nsCString mIPv4OnlyDomains;
120 nsCString mForceResolve;
121 bool mBlockDotOnion = false;
122 bool mNotifyResolution = false;
123 bool mOfflineLocalhost = false;
124 bool mForceResolveOn = false;
125 nsTHashSet<nsCString> mLocalDomains;
126 RefPtr<mozilla::net::TRRService> mTrrService;
128 uint32_t mResCacheEntries = 0;
129 uint32_t mResCacheExpiration = 0;
130 uint32_t mResCacheGrace = 0;
131 bool mResolverPrefsUpdated = false;
132 nsClassHashtable<nsCStringHashKey, nsTArray<nsCString>> mFailedSVCDomainNames;
135 already_AddRefed<nsIDNSService> GetOrInitDNSService();
137 #endif // nsDNSService2_h__