Skip to content

Commit

Permalink
Merge pull request #8125 from brave/ens_support_rebase
Browse files Browse the repository at this point in the history
Add ENS support
  • Loading branch information
bbondy authored Mar 6, 2021
2 parents b682590 + 513c102 commit dd8962f
Show file tree
Hide file tree
Showing 77 changed files with 1,022 additions and 773 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<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_ENS_DESC" desc="The description for how to handle ENS">
Method to resolve Ethereum Name Service (ENS)
</message>
<message name="IDS_SETTINGS_RESOLVE_IPFS_URLS_DESC" desc="The description for how to handle IPFS URIs">
Method to resolve IPFS resources
</message>
Expand Down
8 changes: 4 additions & 4 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import("//brave/components/brave_wallet/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/crypto_dot_com/browser/buildflags/buildflags.gni")
import("//brave/components/decentralized_dns/buildflags/buildflags.gni")
import("//brave/components/gemini/browser/buildflags/buildflags.gni")
import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
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")
Expand Down Expand Up @@ -144,6 +144,7 @@ source_set("browser_process") {
"//brave/components/cosmetic_filters/browser",
"//brave/components/cosmetic_filters/common:mojom",
"//brave/components/crypto_dot_com/browser/buildflags",
"//brave/components/decentralized_dns/buildflags",
"//brave/components/gemini/browser/buildflags",
"//brave/components/greaselion/browser/buildflags",
"//brave/components/ipfs/buildflags",
Expand All @@ -155,7 +156,6 @@ 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",
Expand Down Expand Up @@ -291,8 +291,8 @@ source_set("browser_process") {
]
}

if (unstoppable_domains_enabled) {
deps += [ "//brave/browser/unstoppable_domains" ]
if (decentralized_dns_enabled) {
deps += [ "//brave/browser/decentralized_dns" ]
}

if (ipfs_enabled) {
Expand Down
18 changes: 9 additions & 9 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/cosmetic_filters/browser/cosmetic_filters_resources.h"
#include "brave/components/cosmetic_filters/common/cosmetic_filters.mojom.h"
#include "brave/components/decentralized_dns/buildflags/buildflags.h"
#include "brave/components/gemini/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Expand Down Expand Up @@ -90,8 +90,8 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "brave/components/ipfs/ipfs_navigation_throttle.h"
#endif

#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/unstoppable_domains_navigation_throttle.h"
#if BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
#include "brave/components/decentralized_dns/decentralized_dns_navigation_throttle.h"
#endif

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
Expand Down Expand Up @@ -581,7 +581,7 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
#endif

#if BUILDFLAG(ENABLE_TOR) || BUILDFLAG(IPFS_ENABLED) || \
BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
content::BrowserContext* context =
handle->GetWebContents()->GetBrowserContext();
#endif
Expand Down Expand Up @@ -614,14 +614,14 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
throttles.push_back(std::move(ipfs_navigation_throttle));
#endif

#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#if BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
std::unique_ptr<content::NavigationThrottle>
unstoppable_domains_navigation_throttle = unstoppable_domains::
UnstoppableDomainsNavigationThrottle::MaybeCreateThrottleFor(
decentralized_dns_navigation_throttle = decentralized_dns::
DecentralizedDnsNavigationThrottle::MaybeCreateThrottleFor(
handle, g_brave_browser_process->local_state(),
g_brave_browser_process->GetApplicationLocale());
if (unstoppable_domains_navigation_throttle)
throttles.push_back(std::move(unstoppable_domains_navigation_throttle));
if (decentralized_dns_navigation_throttle)
throttles.push_back(std::move(decentralized_dns_navigation_throttle));
#endif

if (std::unique_ptr<
Expand Down
11 changes: 5 additions & 6 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/decentralized_dns/buildflags/buildflags.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#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"
Expand All @@ -43,8 +43,8 @@
#include "brave/browser/widevine/widevine_utils.h"
#endif

#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/unstoppable_domains_service.h"
#if BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
#include "brave/components/decentralized_dns/decentralized_dns_service.h"
#endif

namespace brave {
Expand Down Expand Up @@ -100,9 +100,8 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
RegisterWidevineLocalstatePrefs(registry);
#endif

#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
unstoppable_domains::UnstoppableDomainsService::RegisterLocalStatePrefs(
registry);
#if BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
decentralized_dns::DecentralizedDnsService::RegisterLocalStatePrefs(registry);
#endif

RegisterLocalStatePrefsForMigration(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
# 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/. */

source_set("unstoppable_domains") {
source_set("decentralized_dns") {
# See https://github.com/brave/brave-browser/issues/14441
check_includes = false

sources = [
"unstoppable_domains_service_delegate_impl.cc",
"unstoppable_domains_service_delegate_impl.h",
"unstoppable_domains_service_factory.cc",
"unstoppable_domains_service_factory.h",
"decentralized_dns_service_delegate_impl.cc",
"decentralized_dns_service_delegate_impl.h",
"decentralized_dns_service_factory.cc",
"decentralized_dns_service_factory.h",
]

deps = [
"//brave/components/unstoppable_domains",
"//brave/components/decentralized_dns",
"//components/keyed_service/content",
]

# Below deps are not directly used by unstoppable_domains target.
# Below deps are not directly used by decentralized_dns target.
# This is added due to our include of
# `chrome/browser/net/system_network_context_manager.h` without adding
# //chrome/browser into deps to avoid circulate dependency. Without this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* 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 "brave/browser/decentralized_dns/decentralized_dns_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 {
namespace decentralized_dns {

void UnstoppableDomainsServiceDelegateImpl::UpdateNetworkService() {
void DecentralizedDnsServiceDelegateImpl::UpdateNetworkService() {
// Trigger a DoH config update in network service.
SystemNetworkContextManager::GetStubResolverConfigReader()
->UpdateNetworkService(false /* record_metrics */);
}

} // namespace unstoppable_domains
} // namespace decentralized_dns
Original file line number Diff line number Diff line change
@@ -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_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_DELEGATE_IMPL_H_
#define BRAVE_BROWSER_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_DELEGATE_IMPL_H_

#include "brave/components/decentralized_dns/decentralized_dns_service_delegate.h"

namespace decentralized_dns {

class DecentralizedDnsServiceDelegateImpl
: public DecentralizedDnsServiceDelegate {
public:
DecentralizedDnsServiceDelegateImpl() = default;
~DecentralizedDnsServiceDelegateImpl() override = default;

DecentralizedDnsServiceDelegateImpl(
const DecentralizedDnsServiceDelegateImpl&) = delete;
DecentralizedDnsServiceDelegateImpl& operator=(
DecentralizedDnsServiceDelegateImpl&) = delete;

void UpdateNetworkService() override;
};

} // namespace decentralized_dns

#endif // BRAVE_BROWSER_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_DELEGATE_IMPL_H_
48 changes: 48 additions & 0 deletions browser/decentralized_dns/decentralized_dns_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* 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/decentralized_dns/decentralized_dns_service_factory.h"

#include <memory>

#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/decentralized_dns/decentralized_dns_service_delegate_impl.h"
#include "brave/components/decentralized_dns/decentralized_dns_service.h"
#include "brave/components/decentralized_dns/utils.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

namespace decentralized_dns {

DecentralizedDnsServiceFactory::DecentralizedDnsServiceFactory()
: BrowserContextKeyedServiceFactory(
"DecentralizedDnsService",
BrowserContextDependencyManager::GetInstance()) {}

DecentralizedDnsServiceFactory::~DecentralizedDnsServiceFactory() {}

// static
DecentralizedDnsServiceFactory* DecentralizedDnsServiceFactory::GetInstance() {
return base::Singleton<DecentralizedDnsServiceFactory>::get();
}

// static
DecentralizedDnsService* DecentralizedDnsServiceFactory::GetForContext(
content::BrowserContext* context) {
if (!IsDecentralizedDnsEnabled())
return nullptr;

return static_cast<DecentralizedDnsService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}

KeyedService* DecentralizedDnsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new DecentralizedDnsService(
std::make_unique<DecentralizedDnsServiceDelegateImpl>(), context,
g_brave_browser_process ? g_brave_browser_process->local_state()
: nullptr);
}

} // namespace decentralized_dns
41 changes: 41 additions & 0 deletions browser/decentralized_dns/decentralized_dns_service_factory.h
Original file line number Diff line number Diff line change
@@ -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_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

namespace decentralized_dns {

class DecentralizedDnsService;

class DecentralizedDnsServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static DecentralizedDnsService* GetForContext(
content::BrowserContext* context);
static DecentralizedDnsServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<DecentralizedDnsServiceFactory>;

DecentralizedDnsServiceFactory();
~DecentralizedDnsServiceFactory() override;

DecentralizedDnsServiceFactory(const DecentralizedDnsServiceFactory&) =
delete;
DecentralizedDnsServiceFactory& operator=(
const DecentralizedDnsServiceFactory&) = delete;

// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};

} // namespace decentralized_dns

#endif // BRAVE_BROWSER_DECENTRALIZED_DNS_DECENTRALIZED_DNS_SERVICE_FACTORY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ source_set("browser_tests") {
testonly = true
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
sources = [
"//brave/browser/unstoppable_domains/test/unstoppable_domains_navigation_throttle_browsertest.cc",
"//brave/browser/unstoppable_domains/test/unstoppable_domains_service_browsertest.cc",
"//brave/browser/decentralized_dns/test/decentralized_dns_navigation_throttle_browsertest.cc",
"//brave/browser/decentralized_dns/test/decentralized_dns_service_browsertest.cc",
]
deps = [
"//base/test:test_support",
"//brave/components/unstoppable_domains",
"//brave/components/decentralized_dns",
"//chrome/browser:browser_process",
"//chrome/test:test_support",
"//chrome/test:test_support_ui",
Expand All @@ -29,14 +29,14 @@ source_set("browser_tests") {
source_set("unit_tests") {
testonly = true
sources = [
"//brave/browser/unstoppable_domains/test/utils_unittest.cc",
"//brave/browser/decentralized_dns/test/utils_unittest.cc",
"//brave/net/dns/dns_transaction_unittest.cc",
]

deps = [
"//base",
"//base/test:test_support",
"//brave/components/unstoppable_domains",
"//brave/components/decentralized_dns",
"//chrome/test:test_support",
"//components/prefs",
"//net",
Expand Down
Loading

0 comments on commit dd8962f

Please sign in to comment.