Add unstoppable domains support via DNS over HTTPS

This commit is contained in:
Jocelyn Liu
2021-03-02 15:04:09 -08:00
parent 49653b54d9
commit 4f9dcad863
33 changed files with 622 additions and 3 deletions
+3
View File
@@ -694,6 +694,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_GOOGLE_LOGIN_FOR_EXTENSIONS" desc="Label for a switch control which allows Google login for extension">
Allow Google login for extensions
</message>
<message name="IDS_SETTINGS_RESOLVE_UNSTOPPABLE_DOMAINS_DESC" desc="The description for how to handle Unstoppable Domains">
Method to resolve Unstoppable Domains
</message>
<message name="IDS_SETTINGS_RESOLVE_IPFS_URLS_DESC" desc="The description for how to handle IPFS URIs">
Method to resolve IPFS resources
</message>
+13
View File
@@ -16,6 +16,7 @@ import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/sidebar/buildflags/buildflags.gni")
import("//brave/components/speedreader/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//brave/components/unstoppable_domains/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")
import("//build/config/features.gni")
import("//chrome/common/features.gni")
@@ -154,6 +155,7 @@ source_set("browser_process") {
"//brave/components/sidebar/buildflags",
"//brave/components/speedreader:buildflags",
"//brave/components/tor/buildflags",
"//brave/components/unstoppable_domains/buildflags",
"//brave/components/weekly_storage",
"//brave/services/network/public/cpp",
"//brave/ui/brave_ads",
@@ -289,6 +291,17 @@ source_set("browser_process") {
]
}
if (unstoppable_domains_enabled) {
sources += [
"unstoppable_domains/unstoppable_domains_service_delegate_impl.cc",
"unstoppable_domains/unstoppable_domains_service_delegate_impl.h",
"unstoppable_domains/unstoppable_domains_service_factory.cc",
"unstoppable_domains/unstoppable_domains_service_factory.h",
]
deps += [ "//brave/components/unstoppable_domains" ]
}
if (ipfs_enabled) {
sources += [
"ipfs/content_browser_client_helper.cc",
+10
View File
@@ -18,6 +18,7 @@
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
@@ -42,6 +43,10 @@
#include "brave/browser/widevine/widevine_utils.h"
#endif
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/unstoppable_domains_service.h"
#endif
namespace brave {
void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -95,6 +100,11 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
RegisterWidevineLocalstatePrefs(registry);
#endif
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
unstoppable_domains::UnstoppableDomainsService::RegisterLocalStatePrefs(
registry);
#endif
RegisterLocalStatePrefsForMigration(registry);
}
+6
View File
@@ -10,6 +10,7 @@ import("//brave/components/gemini/browser/buildflags/buildflags.gni")
import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/sidebar/buildflags/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//brave/components/unstoppable_domains/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//components/gcm_driver/config.gni")
@@ -67,6 +68,7 @@ source_set("extensions") {
"//brave/components/ipfs/buildflags",
"//brave/components/sidebar/buildflags",
"//brave/components/tor/buildflags",
"//brave/components/unstoppable_domains/buildflags",
"//chrome/browser/extensions",
"//chrome/common",
"//components/gcm_driver:gcm_buildflags",
@@ -111,6 +113,10 @@ source_set("extensions") {
deps += [ "//brave/components/ipfs" ]
}
if (unstoppable_domains_enabled) {
deps += [ "//brave/components/unstoppable_domains" ]
}
if (brave_rewards_enabled) {
sources += [
"api/brave_rewards_api.cc",
@@ -14,6 +14,7 @@
#include "brave/components/ntp_background_images/common/pref_names.h"
#include "brave/components/sidebar/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "chrome/browser/extensions/api/settings_private/prefs_util.h"
#include "chrome/common/extensions/api/settings_private.h"
#include "chrome/common/pref_names.h"
@@ -45,6 +46,10 @@
#include "brave/components/tor/pref_names.h"
#endif
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/pref_names.h"
#endif
namespace extensions {
using ntp_background_images::prefs::kNewTabPageShowBackgroundImage;
@@ -207,6 +212,12 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
(*s_brave_allowlist)[prefs::kWebRTCIPHandlingPolicy] =
settings_api::PrefType::PREF_TYPE_STRING;
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
// Unstoppable Domains pref
(*s_brave_allowlist)[unstoppable_domains::kResolveMethod] =
settings_api::PrefType::PREF_TYPE_NUMBER;
#endif
return *s_brave_allowlist;
}
+1 -1
View File
@@ -33,11 +33,11 @@ source_set("profiles") {
"//brave/components/brave_rewards/browser",
"//brave/components/brave_sync:prefs",
"//brave/components/brave_wallet/buildflags",
"//brave/components/brave_wallet/buildflags",
"//brave/components/content_settings/core/browser",
"//brave/components/ipfs/buildflags",
"//brave/components/ntp_background_images/common",
"//brave/components/tor",
"//brave/components/unstoppable_domains/buildflags",
"//brave/content:browser",
"//chrome/common",
"//components/gcm_driver:gcm_buildflags",
@@ -19,6 +19,7 @@
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/tor/tor_constants.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "brave/content/browser/webui/brave_shared_resources_data_source.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -50,6 +51,10 @@
#include "brave/browser/ipfs/ipfs_service_factory.h"
#endif
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/browser/unstoppable_domains/unstoppable_domains_service_factory.h"
#endif
using content::BrowserThread;
BraveProfileManager::BraveProfileManager(const base::FilePath& user_data_dir)
@@ -108,6 +113,9 @@ void BraveProfileManager::DoFinalInitForServices(Profile* profile,
#if BUILDFLAG(IPFS_ENABLED)
ipfs::IpfsServiceFactory::GetForContext(profile);
#endif
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
unstoppable_domains::UnstoppableDomainsServiceFactory::GetForContext(profile);
#endif
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
gcm::BraveGCMChannelStatus* status =
gcm::BraveGCMChannelStatus::GetForProfile(profile);
@@ -85,6 +85,12 @@
sub-label="$i18n{hangoutsEnabledDesc}"
on-settings-boolean-control-change="onHangoutsEnabledChange_">
</settings-toggle-button>
<div class="settings-box">
<div class="start">$i18n{resolveUnstoppableDomainsDesc}</div>
<settings-dropdown-menu id="udResolveMethodType"
pref="{{prefs.brave.unstoppable_domains.resolve_method}}"
menu-options="[[udResolveMethod_]]">
</div>
<settings-toggle-button id="mediaRouterEnabled"
class="cr-row"
pref="{{prefs.brave.enable_media_router}}"
@@ -20,7 +20,18 @@ Polymer({
showRestartToast_: Boolean,
torEnabled_: Boolean,
widevineEnabled_: Boolean,
disableTorOption_: Boolean
disableTorOption_: Boolean,
udResolveMethod_: {
readOnly: true,
type: Array,
value() {
return [
{value:0, name: "Ask"},
{value:1, name: "Disabled"},
{value:2, name: "Public DNS over HTTPS server"},
];
},
},
},
/** @private {?settings.BraveDefaultExtensionsBrowserProxy} */
+6
View File
@@ -7,6 +7,7 @@ import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/sidebar/buildflags/buildflags.gni")
import("//brave/components/speedreader/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//brave/components/unstoppable_domains/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//chrome/common/features.gni")
import("//components/gcm_driver/config.gni")
@@ -239,6 +240,7 @@ source_set("ui") {
"//brave/components/p3a:buildflags",
"//brave/components/sidebar/buildflags",
"//brave/components/tor:pref_names",
"//brave/components/unstoppable_domains/buildflags",
"//brave/components/vector_icons",
"//brave/components/webcompat_reporter/browser",
"//brave/components/webcompat_reporter/ui:generated_resources",
@@ -374,6 +376,10 @@ source_set("ui") {
}
}
if (unstoppable_domains_enabled) {
deps += [ "//brave/components/unstoppable_domains" ]
}
if (brave_rewards_enabled) {
sources += [
"views/brave_actions/brave_rewards_action_stub_view.cc",
@@ -0,0 +1,18 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/browser/unstoppable_domains/unstoppable_domains_service_delegate_impl.h"
#include "chrome/browser/net/stub_resolver_config_reader.h"
#include "chrome/browser/net/system_network_context_manager.h"
namespace unstoppable_domains {
void UnstoppableDomainsServiceDelegateImpl::UpdateNetworkService() {
SystemNetworkContextManager::GetStubResolverConfigReader()
->UpdateNetworkService(false /* record_metrics */);
}
} // namespace unstoppable_domains
@@ -0,0 +1,29 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_IMPL_H_
#define BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_IMPL_H_
#include "brave/components/unstoppable_domains/unstoppable_domains_service_delegate.h"
namespace unstoppable_domains {
class UnstoppableDomainsServiceDelegateImpl
: public UnstoppableDomainsServiceDelegate {
public:
UnstoppableDomainsServiceDelegateImpl() = default;
~UnstoppableDomainsServiceDelegateImpl() override = default;
UnstoppableDomainsServiceDelegateImpl(
const UnstoppableDomainsServiceDelegateImpl&) = delete;
UnstoppableDomainsServiceDelegateImpl& operator=(
UnstoppableDomainsServiceDelegateImpl&) = delete;
void UpdateNetworkService() override;
};
} // namespace unstoppable_domains
#endif // BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_IMPL_H_
@@ -0,0 +1,45 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/browser/unstoppable_domains/unstoppable_domains_service_factory.h"
#include <memory>
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/unstoppable_domains/unstoppable_domains_service_delegate_impl.h"
#include "brave/components/unstoppable_domains/unstoppable_domains_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace unstoppable_domains {
UnstoppableDomainsServiceFactory::UnstoppableDomainsServiceFactory()
: BrowserContextKeyedServiceFactory(
"UnstoppableDomainsService",
BrowserContextDependencyManager::GetInstance()) {}
UnstoppableDomainsServiceFactory::~UnstoppableDomainsServiceFactory() {}
// static
UnstoppableDomainsServiceFactory*
UnstoppableDomainsServiceFactory::GetInstance() {
return base::Singleton<UnstoppableDomainsServiceFactory>::get();
}
// static
UnstoppableDomainsService* UnstoppableDomainsServiceFactory::GetForContext(
content::BrowserContext* context) {
return static_cast<UnstoppableDomainsService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
KeyedService* UnstoppableDomainsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new UnstoppableDomainsService(
std::make_unique<UnstoppableDomainsServiceDelegateImpl>(), context,
g_brave_browser_process ? g_brave_browser_process->local_state()
: nullptr);
}
} // namespace unstoppable_domains
@@ -0,0 +1,41 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace unstoppable_domains {
class UnstoppableDomainsService;
class UnstoppableDomainsServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static UnstoppableDomainsService* GetForContext(
content::BrowserContext* context);
static UnstoppableDomainsServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<UnstoppableDomainsServiceFactory>;
UnstoppableDomainsServiceFactory();
~UnstoppableDomainsServiceFactory() override;
UnstoppableDomainsServiceFactory(const UnstoppableDomainsServiceFactory&) =
delete;
UnstoppableDomainsServiceFactory& operator=(
const UnstoppableDomainsServiceFactory&) = delete;
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};
} // namespace unstoppable_domains
#endif // BRAVE_BROWSER_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_FACTORY_H_
@@ -0,0 +1,47 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/strings/strcat.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/constants.h"
#include "brave/components/unstoppable_domains/pref_names.h"
#endif
namespace {
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
void AddUnstoppableDomainsResolver(std::string* doh_templates,
PrefService* local_state) {
bool resolve_ud_enabled =
local_state->FindPreference(unstoppable_domains::kResolveMethod) &&
local_state->GetInteger(unstoppable_domains::kResolveMethod) ==
static_cast<int>(
unstoppable_domains::ResolveMethodTypes::DNS_OVER_HTTPS);
if (resolve_ud_enabled &&
doh_templates->find(unstoppable_domains::kDoHResolver) ==
std::string::npos) {
*doh_templates =
base::StrCat({unstoppable_domains::kDoHResolver, " ", *doh_templates});
}
}
#endif // BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
void AddDoHServers(std::string* doh_templates, PrefService* local_state) {
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
AddUnstoppableDomainsResolver(doh_templates, local_state);
#endif
}
} // namespace
#define BRAVE_GET_AND_UPDATE_CONFIGURATION \
AddDoHServers(&doh_templates, local_state_);
#include "../../../../../chrome/browser/net/stub_resolver_config_reader.cc"
#undef BRAVE_GET_AND_UPDATE_CONFIGURATION
@@ -219,6 +219,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_LOAD_CRYPTO_WALLETS_ON_STARTUP},
{"googleLoginForExtensionsDesc", IDS_SETTINGS_GOOGLE_LOGIN_FOR_EXTENSIONS},
{"hangoutsEnabledDesc", IDS_SETTINGS_HANGOUTS_ENABLED_DESC},
{"resolveUnstoppableDomainsDesc",
IDS_SETTINGS_RESOLVE_UNSTOPPABLE_DOMAINS_DESC},
{"resolveIPFSURLDesc", IDS_SETTINGS_RESOLVE_IPFS_URLS_DESC},
{"ipfsPublicGatewayDesc", IDS_SETTINGS_IPFS_PUBLIC_GATEWAY_DESC},
{"ipfsChangeGatewayButtonLabel",
@@ -0,0 +1,50 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/values.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/constants.h"
#endif
namespace settings {
namespace {
std::unique_ptr<base::DictionaryValue> CreateSecureDnsSettingDict();
} // namespace
} // namespace settings
#include "../../../../../../../chrome/browser/ui/webui/settings/settings_secure_dns_handler.cc"
namespace settings {
namespace {
// Hide Unstoppable Domains resolver in the custom provider list in settings
// because it will be used for name resolution only for TLDs from Unstoppable
// Domains, instaed of a global DoH settings.
std::unique_ptr<base::DictionaryValue> CreateSecureDnsSettingDict() {
auto dict = CreateSecureDnsSettingDict_ChromiumImpl();
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
if (!dict->FindListPath("templates")) {
return dict;
}
auto secure_dns_templates = std::make_unique<base::ListValue>();
for (const auto& template_str : dict->FindListPath("templates")->GetList()) {
if (!template_str.is_string())
return dict;
if (template_str.GetString() != unstoppable_domains::kDoHResolver)
secure_dns_templates->Append(template_str.GetString());
}
dict->SetList("templates", std::move(secure_dns_templates));
#endif // BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
return dict;
}
} // namespace
} // namespace settings
+47
View File
@@ -0,0 +1,47 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/strings/string_util.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_server_iterator.h"
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/constants.h"
#endif
namespace {
bool GetNextIndex(const std::string& hostname,
const net::DnsConfig& config,
net::DnsServerIterator* dns_server_iterator,
size_t* doh_server_index) {
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
// Skip unstoppable domains resolver for non-crypto domains.
if (!base::EndsWith(hostname, unstoppable_domains::kCryptoDomain) &&
config.dns_over_https_servers[*doh_server_index].server_template ==
unstoppable_domains::kDoHResolver) {
// No next available index to attempt.
if (!dns_server_iterator->AttemptAvailable()) {
return false;
}
*doh_server_index = dns_server_iterator->GetNextAttemptIndex();
}
#endif
return true;
}
} // namespace
#define BRAVE_MAKE_HTTP_ATTEMPT \
if (!GetNextIndex(hostname_, session_.get()->config(), \
dns_server_iterator_.get(), &doh_server_index)) { \
return AttemptResult(ERR_BLOCKED_BY_CLIENT, nullptr); \
}
#include "../../../../net/dns/dns_transaction.cc"
#undef BRAVE_MAKE_HTTP_ATTEMPT
+23
View File
@@ -0,0 +1,23 @@
source_set("constants") {
sources = [
"constants.cc",
"constants.h",
]
}
source_set("unstoppable_domains") {
sources = [
"pref_names.cc",
"pref_names.h",
"unstoppable_domains_service.cc",
"unstoppable_domains_service.h",
"unstoppable_domains_service_delegate.h",
]
public_deps = [ ":constants" ]
deps = [
"//components/keyed_service/core",
"//components/prefs",
]
}
@@ -0,0 +1,7 @@
import("//brave/components/unstoppable_domains/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [ "UNSTOPPABLE_DOMAINS_ENABLED=$unstoppable_domains_enabled" ]
}
@@ -0,0 +1,5 @@
import("//build/config/features.gni")
declare_args() {
unstoppable_domains_enabled = is_mac || is_linux || is_win
}
@@ -0,0 +1,14 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/components/unstoppable_domains/constants.h"
namespace unstoppable_domains {
const char kCryptoDomain[] = ".crypto";
const char kDoHResolver[] =
"https://resolver.unstoppable.io/dns-query{?brave_UD}";
} // namespace unstoppable_domains
@@ -0,0 +1,22 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
namespace unstoppable_domains {
extern const char kCryptoDomain[];
extern const char kDoHResolver[];
enum class ResolveMethodTypes {
ASK,
DISABLED,
DNS_OVER_HTTPS,
};
} // namespace unstoppable_domains
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
@@ -0,0 +1,16 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/components/unstoppable_domains/pref_names.h"
namespace unstoppable_domains {
// Used to determine which method should be used to resolve unstoppable
// domains, between:
// Disabled: Disable all unstoppable domains resolution.
// DNS Over HTTPS: Resolve domain name using a public DNS over HTTPS server.
const char kResolveMethod[] = "brave.unstoppable_domains.resolve_method";
} // namespace unstoppable_domains
@@ -0,0 +1,15 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_PREF_NAMES_H_
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_PREF_NAMES_H_
namespace unstoppable_domains {
extern const char kResolveMethod[];
} // namespace unstoppable_domains
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_PREF_NAMES_H_
@@ -0,0 +1,45 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/components/unstoppable_domains/unstoppable_domains_service.h"
#include <utility>
#include "brave/components/unstoppable_domains/constants.h"
#include "brave/components/unstoppable_domains/pref_names.h"
#include "brave/components/unstoppable_domains/unstoppable_domains_service_delegate.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace unstoppable_domains {
UnstoppableDomainsService::UnstoppableDomainsService(
std::unique_ptr<UnstoppableDomainsServiceDelegate> delegate,
content::BrowserContext* context,
PrefService* local_state)
: local_state_(local_state), delegate_(std::move(delegate)) {
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(local_state_);
pref_change_registrar_->Add(
kResolveMethod,
base::Bind(&UnstoppableDomainsService::OnPreferenceChanged,
base::Unretained(this)));
}
UnstoppableDomainsService::~UnstoppableDomainsService() = default;
// static
void UnstoppableDomainsService::RegisterLocalStatePrefs(
PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(kResolveMethod,
static_cast<int>(ResolveMethodTypes::ASK));
}
void UnstoppableDomainsService::OnPreferenceChanged() {
delegate_->UpdateNetworkService();
}
} // namespace unstoppable_domains
@@ -0,0 +1,49 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_H_
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_H_
#include <memory>
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
} // namespace content
class PrefChangeRegistrar;
class PrefRegistrySimple;
class PrefService;
namespace unstoppable_domains {
class UnstoppableDomainsServiceDelegate;
class UnstoppableDomainsService : public KeyedService {
public:
UnstoppableDomainsService(
std::unique_ptr<UnstoppableDomainsServiceDelegate> delegate,
content::BrowserContext* context,
PrefService* local_state);
~UnstoppableDomainsService() override;
UnstoppableDomainsService(const UnstoppableDomainsService&) = delete;
UnstoppableDomainsService& operator=(const UnstoppableDomainsService&) =
delete;
static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
private:
void OnPreferenceChanged();
PrefService* local_state_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
std::unique_ptr<UnstoppableDomainsServiceDelegate> delegate_;
};
} // namespace unstoppable_domains
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_H_
@@ -0,0 +1,20 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_H_
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_H_
namespace unstoppable_domains {
class UnstoppableDomainsServiceDelegate {
public:
UnstoppableDomainsServiceDelegate() = default;
virtual ~UnstoppableDomainsServiceDelegate() = default;
virtual void UpdateNetworkService() = 0;
};
} // namespace unstoppable_domains
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_SERVICE_DELEGATE_H_
+5
View File
@@ -7,3 +7,8 @@ brave_net_sources = [
"//brave/net/proxy_resolution/proxy_config_service_tor.cc",
"//brave/net/proxy_resolution/proxy_config_service_tor.h",
]
brave_net_deps = [
"//brave/components/unstoppable_domains:constants",
"//brave/components/unstoppable_domains/buildflags",
]
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/net/stub_resolver_config_reader.cc b/chrome/browser/net/stub_resolver_config_reader.cc
index 677f6c50fc602a1c5ba6ca52f4ea6496d7d60e7f..d736b6e06fcbee8fb17e3397cee86f3dbe09ad8e 100644
--- a/chrome/browser/net/stub_resolver_config_reader.cc
+++ b/chrome/browser/net/stub_resolver_config_reader.cc
@@ -353,6 +353,7 @@ SecureDnsConfig StubResolverConfigReader::GetAndUpdateConfiguration(
std::string doh_templates =
local_state_->GetString(prefs::kDnsOverHttpsTemplates);
+ BRAVE_GET_AND_UPDATE_CONFIGURATION
std::string server_method;
std::vector<net::DnsOverHttpsServerConfig> dns_over_https_servers;
base::Optional<std::vector<network::mojom::DnsOverHttpsServerPtr>>
@@ -0,0 +1,13 @@
diff --git a/chrome/browser/ui/webui/settings/settings_secure_dns_handler.cc b/chrome/browser/ui/webui/settings/settings_secure_dns_handler.cc
index 36ddfefcbc527e43d7efcb2210614b9df8c9919f..399f34639a082ea071801de7bc89ebbff275d652 100644
--- a/chrome/browser/ui/webui/settings/settings_secure_dns_handler.cc
+++ b/chrome/browser/ui/webui/settings/settings_secure_dns_handler.cc
@@ -33,7 +33,7 @@ namespace settings {
namespace {
-std::unique_ptr<base::DictionaryValue> CreateSecureDnsSettingDict() {
+std::unique_ptr<base::DictionaryValue> CreateSecureDnsSettingDict_ChromiumImpl() {
// Fetch the current host resolver configuration. It is not sufficient to read
// the secure DNS prefs directly since the host resolver configuration takes
// other factors into account such as whether a managed environment or
+9 -1
View File
@@ -1,5 +1,5 @@
diff --git a/net/BUILD.gn b/net/BUILD.gn
index d214ac4959ff76dd8e95d327c9839ee967d14444..292ce4d3c2c294be04cc8d7ba8ed5ac06e2d58f4 100644
index d214ac4959ff76dd8e95d327c9839ee967d14444..709ca7acfa482e5d85f2e4207bbbe2d93dd61fee 100644
--- a/net/BUILD.gn
+++ b/net/BUILD.gn
@@ -1176,6 +1176,7 @@ component("net") {
@@ -10,3 +10,11 @@ index d214ac4959ff76dd8e95d327c9839ee967d14444..292ce4d3c2c294be04cc8d7ba8ed5ac0
if (is_android) {
sources += [
@@ -1695,6 +1696,7 @@ source_set("net_deps") {
]
public_configs = net_configs
+ public_deps += brave_net_deps
if (!is_nacl) {
public_deps += [
+12
View File
@@ -0,0 +1,12 @@
diff --git a/net/dns/dns_transaction.cc b/net/dns/dns_transaction.cc
index 9bfd4cace384ca502716efa191eaa6ccfd6a54a8..9123e8cb94b566ef1a25cbc498dfc859e4165e73 100644
--- a/net/dns/dns_transaction.cc
+++ b/net/dns/dns_transaction.cc
@@ -1299,6 +1299,7 @@ class DnsTransactionImpl : public DnsTransaction,
DCHECK(secure_);
size_t doh_server_index = dns_server_iterator_->GetNextAttemptIndex();
+ BRAVE_MAKE_HTTP_ATTEMPT
unsigned attempt_number = attempts_.size();
ConstructDnsHTTPAttempt(