Bug 1838739 - Initialize result of SetAsGPUOutOfMemoryError. r=webgpu-reviewers,nical
[gecko.git] / netwerk / dns / DNSServiceBase.cpp
blob85b2da37e34a3cb0a3983c86a59b67f58729e05f
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 #include "DNSServiceBase.h"
9 #include "DNS.h"
10 #include "mozilla/Preferences.h"
11 #include "mozilla/StaticPrefs_network.h"
12 #include "nsIDNSService.h"
13 #include "nsIProtocolProxyService2.h"
14 #include "nsIPrefBranch.h"
16 namespace mozilla::net {
18 static const char kPrefProxyType[] = "network.proxy.type";
19 static const char kPrefDisablePrefetch[] = "network.dns.disablePrefetch";
20 static const char kPrefNetworkProxySOCKS[] = "network.proxy.socks";
22 NS_IMPL_ISUPPORTS(DNSServiceBase, nsIObserver)
24 void DNSServiceBase::AddPrefObserver(nsIPrefBranch* aPrefs) {
25 aPrefs->AddObserver(kPrefProxyType, this, false);
26 aPrefs->AddObserver(kPrefDisablePrefetch, this, false);
27 // Monitor these to see if there is a change in proxy configuration
28 aPrefs->AddObserver(kPrefNetworkProxySOCKS, this, false);
31 void DNSServiceBase::ReadPrefs(const char* aName) {
32 if (!aName || !strcmp(aName, kPrefNetworkProxySOCKS)) {
33 nsAutoCString socks;
34 if (NS_SUCCEEDED(Preferences::GetCString(kPrefNetworkProxySOCKS, socks))) {
35 mHasSocksProxy = !socks.IsEmpty();
38 if (!aName || !strcmp(aName, kPrefDisablePrefetch) ||
39 !strcmp(aName, kPrefProxyType)) {
40 mDisablePrefetch = Preferences::GetBool(kPrefDisablePrefetch, false) ||
41 (StaticPrefs::network_proxy_type() ==
42 nsIProtocolProxyService::PROXYCONFIG_MANUAL);
46 bool DNSServiceBase::DNSForbiddenByActiveProxy(const nsACString& aHostname,
47 uint32_t aFlags) {
48 if (aFlags & nsIDNSService::RESOLVE_IGNORE_SOCKS_DNS) {
49 return false;
52 // We should avoid doing DNS when a proxy is in use.
53 if (StaticPrefs::network_proxy_type() ==
54 nsIProtocolProxyService::PROXYCONFIG_MANUAL &&
55 mHasSocksProxy && StaticPrefs::network_proxy_socks_remote_dns()) {
56 // Allow IP lookups through, but nothing else.
57 if (!HostIsIPLiteral(aHostname)) {
58 return true;
61 return false;
64 } // namespace mozilla::net