Skip to content

Commit

Permalink
Merge pull request #7702 from brave/unstoppable_domains
Browse files Browse the repository at this point in the history
Support Unstoppable Domains via DNS over HTTPS behind a feature flag
  • Loading branch information
yrliou committed Mar 18, 2021
1 parent 730bac6 commit bbbcc62
Show file tree
Hide file tree
Showing 66 changed files with 2,746 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -289,6 +291,10 @@ source_set("browser_process") {
]
}

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

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 @@ -35,6 +35,7 @@
#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 @@ -88,6 +89,10 @@ 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"
#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(UNSTOPPABLE_DOMAINS_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(UNSTOPPABLE_DOMAINS_ENABLED)
std::unique_ptr<content::NavigationThrottle>
unstoppable_domains_navigation_throttle = unstoppable_domains::
UnstoppableDomainsNavigationThrottle::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));
#endif

return throttles;
}
10 changes: 10 additions & 0 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -95,6 +100,11 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
RegisterWidevineLocalstatePrefs(registry);
#endif

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

RegisterLocalStatePrefsForMigration(registry);
}

Expand Down
6 changes: 6 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions browser/profiles/brave_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ cr.define('settings', function () {
wasSignInEnabledAtStartup () {
return loadTimeData.getBoolean('signInAllowedOnNextStartupInitialValue')
}

isUnstoppableDomainsEnabled () {
return cr.sendWithPromise('isUnstoppableDomainsEnabled')
}
}

cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
sub-label="$i18n{hangoutsEnabledDesc}"
on-settings-boolean-control-change="onHangoutsEnabledChange_">
</settings-toggle-button>
<template is="dom-if" if="{{ unstoppableDomainsEnabled_ }}">
<div class="settings-box">
<div class="start">$i18n{resolveUnstoppableDomainsDesc}</div>
<settings-dropdown-menu id="unstoppableDomainsResolveMethodType"
pref="{{prefs.brave.unstoppable_domains.resolve_method}}"
menu-options="[[unstoppableDomainsResolveMethod_]]">
</div>
</template>
<settings-toggle-button id="mediaRouterEnabled"
class="cr-row"
pref="{{prefs.brave.enable_media_router}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ Polymer({
showRestartToast_: Boolean,
torEnabled_: Boolean,
widevineEnabled_: Boolean,
disableTorOption_: Boolean
disableTorOption_: Boolean,
unstoppableDomainsEnabled_: Boolean,
unstoppableDomainsResolveMethod_: {
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} */
Expand Down Expand Up @@ -63,6 +75,9 @@ Polymer({
this.browserProxy_.isWidevineEnabled().then(enabled => {
this.widevineEnabled_ = enabled
})
this.browserProxy_.isUnstoppableDomainsEnabled().then(enabled => {
this.unstoppableDomainsEnabled_ = enabled
});
},

onWebTorrentEnabledChange_: function() {
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -237,6 +238,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",
Expand Down Expand Up @@ -372,6 +374,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",
Expand Down
23 changes: 23 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "brave/browser/extensions/brave_component_loader.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
Expand Down Expand Up @@ -47,6 +48,10 @@
#include "brave/browser/widevine/widevine_utils.h"
#endif

#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
#include "brave/components/unstoppable_domains/utils.h"
#endif

BraveDefaultExtensionsHandler::BraveDefaultExtensionsHandler()
: weak_ptr_factory_(this) {
#if BUILDFLAG(ENABLE_WIDEVINE)
Expand Down Expand Up @@ -108,6 +113,11 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
"isWidevineEnabled",
base::BindRepeating(&BraveDefaultExtensionsHandler::IsWidevineEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"isUnstoppableDomainsEnabled",
base::BindRepeating(
&BraveDefaultExtensionsHandler::IsUnstoppableDomainsEnabled,
base::Unretained(this)));

// Can't call this in ctor because it needs to access web_ui().
InitializePrefCallbacks();
Expand Down Expand Up @@ -394,3 +404,16 @@ void BraveDefaultExtensionsHandler::SetBraveWalletEnabled(
}
}
#endif

void BraveDefaultExtensionsHandler::IsUnstoppableDomainsEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
AllowJavascript();
ResolveJavascriptCallback(
args->GetList()[0],
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
base::Value(unstoppable_domains::IsUnstoppableDomainsEnabled()));
#else
base::Value(false));
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
void SetWidevineEnabled(const base::ListValue* args);
void IsWidevineEnabled(const base::ListValue* args);
void OnWidevineEnabledChanged();
void IsUnstoppableDomainsEnabled(const base::ListValue* args);

void InitializePrefCallbacks();

Expand Down
28 changes: 28 additions & 0 deletions browser/unstoppable_domains/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("unstoppable_domains") {
# 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",
]

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

# Below deps are not directly used by unstoppable_domains 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" ]
}
Loading

0 comments on commit bbbcc62

Please sign in to comment.