Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uplift Unstoppable Domains & ENS native support to 1.22.x #8291

Merged
merged 6 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,12 @@ 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_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
6 changes: 6 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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")
Expand Down Expand Up @@ -143,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 Down Expand Up @@ -289,6 +291,10 @@ source_set("browser_process") {
]
}

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

if (ipfs_enabled) {
sources += [
"ipfs/content_browser_client_helper.cc",
Expand Down
18 changes: 17 additions & 1 deletion browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#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"
Expand Down Expand Up @@ -88,6 +89,10 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "brave/components/ipfs/ipfs_navigation_throttle.h"
#endif

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

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
#include "brave/components/brave_rewards/browser/rewards_protocol_handler.h"
#endif
Expand Down Expand Up @@ -585,7 +590,8 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
std::make_unique<extensions::BraveWebTorrentNavigationThrottle>(handle));
#endif

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

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

return throttles;
}
9 changes: 9 additions & 0 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#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"
Expand Down Expand Up @@ -42,6 +43,10 @@
#include "brave/browser/widevine/widevine_utils.h"
#endif

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

namespace brave {

void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
Expand Down Expand Up @@ -95,6 +100,10 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
RegisterWidevineLocalstatePrefs(registry);
#endif

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

RegisterLocalStatePrefsForMigration(registry);
}

Expand Down
28 changes: 28 additions & 0 deletions browser/decentralized_dns/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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/. */

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

sources = [
"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/decentralized_dns",
"//components/keyed_service/content",
]

# 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,
# we could encounter error due to some files included are not generated yet.
deps += [ "//services/network/public/mojom" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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_delegate_impl.h"

#include "chrome/browser/net/stub_resolver_config_reader.h"
#include "chrome/browser/net/system_network_context_manager.h"

namespace decentralized_dns {

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

} // 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_
55 changes: 55 additions & 0 deletions browser/decentralized_dns/test/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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/. */

import("//brave/build/config.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//testing/test.gni")

source_set("browser_tests") {
testonly = true
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
sources = [
"//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/decentralized_dns",
"//chrome/browser:browser_process",
"//chrome/test:test_support",
"//chrome/test:test_support_ui",
"//components/prefs",
"//components/security_interstitials/content:security_interstitial_page",
"//content/test:test_support",
"//testing/gtest",
]
} # source_set("browser_tests") {

source_set("unit_tests") {
testonly = true
sources = [
"//brave/browser/decentralized_dns/test/decentralized_dns_navigation_throttle_unittest.cc",
"//brave/browser/decentralized_dns/test/utils_unittest.cc",
"//brave/net/dns/brave_resolve_context_unittest.cc",
"//brave/net/dns/dns_transaction_unittest.cc",
]

deps = [
"//base",
"//base/test:test_support",
"//brave/components/decentralized_dns",
"//brave/components/tor/buildflags",
"//chrome/test:test_support",
"//components/prefs",
"//net",
"//net:test_support",
"//testing/gmock",
"//testing/gtest",
]

if (enable_tor) {
deps += [ "//brave/browser/tor" ]
}
} # source_set("unit_tests")
Loading