Merge pull request #7702 from brave/unstoppable_domains
Support Unstoppable Domains via DNS over HTTPS behind a feature flag
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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,10 @@ source_set("browser_process") {
|
||||
]
|
||||
}
|
||||
|
||||
if (unstoppable_domains_enabled) {
|
||||
deps += [ "//brave/browser/unstoppable_domains" ]
|
||||
}
|
||||
|
||||
if (ipfs_enabled) {
|
||||
sources += [
|
||||
"ipfs/content_browser_client_helper.cc",
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
@@ -67,6 +67,10 @@ cr.define('settings', function () {
|
||||
wasSignInEnabledAtStartup () {
|
||||
return loadTimeData.getBoolean('signInAllowedOnNextStartupInitialValue')
|
||||
}
|
||||
|
||||
isUnstoppableDomainsEnabled () {
|
||||
return cr.sendWithPromise('isUnstoppableDomainsEnabled')
|
||||
}
|
||||
}
|
||||
|
||||
cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl)
|
||||
|
||||
+8
@@ -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}}"
|
||||
|
||||
+16
-1
@@ -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} */
|
||||
@@ -63,6 +75,9 @@ Polymer({
|
||||
this.browserProxy_.isWidevineEnabled().then(enabled => {
|
||||
this.widevineEnabled_ = enabled
|
||||
})
|
||||
this.browserProxy_.isUnstoppableDomainsEnabled().then(enabled => {
|
||||
this.unstoppableDomainsEnabled_ = enabled
|
||||
});
|
||||
},
|
||||
|
||||
onWebTorrentEnabledChange_: function() {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
@@ -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();
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
@@ -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/. */
|
||||
|
||||
import("//brave/build/config.gni")
|
||||
import("//testing/test.gni")
|
||||
|
||||
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",
|
||||
]
|
||||
deps = [
|
||||
"//base/test:test_support",
|
||||
"//brave/components/unstoppable_domains",
|
||||
"//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/unstoppable_domains/test/utils_unittest.cc",
|
||||
"//brave/net/dns/dns_transaction_unittest.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//base/test:test_support",
|
||||
"//brave/components/unstoppable_domains",
|
||||
"//chrome/test:test_support",
|
||||
"//components/prefs",
|
||||
"//net",
|
||||
"//net:test_support",
|
||||
"//testing/gmock",
|
||||
"//testing/gtest",
|
||||
]
|
||||
} # source_set("unit_tests")
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/* 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/test/scoped_feature_list.h"
|
||||
#include "brave/components/unstoppable_domains/constants.h"
|
||||
#include "brave/components/unstoppable_domains/features.h"
|
||||
#include "brave/components/unstoppable_domains/pref_names.h"
|
||||
#include "brave/components/unstoppable_domains/unstoppable_domains_opt_in_page.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
||||
#include "chrome/test/base/in_process_browser_test.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/security_interstitials/content/security_interstitial_page.h"
|
||||
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "content/public/test/test_navigation_observer.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace {
|
||||
|
||||
security_interstitials::SecurityInterstitialPage* GetCurrentInterstitial(
|
||||
content::WebContents* web_contents) {
|
||||
security_interstitials::SecurityInterstitialTabHelper* helper =
|
||||
security_interstitials::SecurityInterstitialTabHelper::FromWebContents(
|
||||
web_contents);
|
||||
if (!helper) {
|
||||
return nullptr;
|
||||
}
|
||||
return helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting();
|
||||
}
|
||||
|
||||
security_interstitials::SecurityInterstitialPage::TypeID GetInterstitialType(
|
||||
content::WebContents* web_contents) {
|
||||
security_interstitials::SecurityInterstitialPage* page =
|
||||
GetCurrentInterstitial(web_contents);
|
||||
if (!page) {
|
||||
return nullptr;
|
||||
}
|
||||
return page->GetTypeForTesting();
|
||||
}
|
||||
|
||||
void SendInterstitialCommand(
|
||||
content::WebContents* web_contents,
|
||||
security_interstitials::SecurityInterstitialCommand command) {
|
||||
GetCurrentInterstitial(web_contents)
|
||||
->CommandReceived(base::NumberToString(command));
|
||||
}
|
||||
|
||||
void SendInterstitialCommandSync(
|
||||
Browser* browser,
|
||||
security_interstitials::SecurityInterstitialCommand command) {
|
||||
content::WebContents* web_contents =
|
||||
browser->tab_strip_model()->GetActiveWebContents();
|
||||
|
||||
EXPECT_EQ(unstoppable_domains::UnstoppableDomainsOptInPage::kTypeForTesting,
|
||||
GetInterstitialType(web_contents));
|
||||
|
||||
content::TestNavigationObserver navigation_observer(web_contents, 1);
|
||||
SendInterstitialCommand(web_contents, command);
|
||||
navigation_observer.Wait();
|
||||
|
||||
EXPECT_EQ(nullptr, GetCurrentInterstitial(web_contents));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
class UnstoppableDomainsNavigationThrottleBrowserTest
|
||||
: public InProcessBrowserTest {
|
||||
public:
|
||||
UnstoppableDomainsNavigationThrottleBrowserTest() {
|
||||
feature_list_.InitAndEnableFeature(features::kUnstoppableDomains);
|
||||
}
|
||||
|
||||
~UnstoppableDomainsNavigationThrottleBrowserTest() override = default;
|
||||
|
||||
void SetUpOnMainThread() override {
|
||||
InProcessBrowserTest::SetUpOnMainThread();
|
||||
}
|
||||
|
||||
PrefService* local_state() { return g_browser_process->local_state(); }
|
||||
|
||||
private:
|
||||
base::test::ScopedFeatureList feature_list_;
|
||||
};
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(UnstoppableDomainsNavigationThrottleBrowserTest,
|
||||
ShowInterstitialAndProceed) {
|
||||
ui_test_utils::NavigateToURL(browser(), GURL("http://test.crypto"));
|
||||
|
||||
content::WebContents* web_contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
|
||||
EXPECT_TRUE(WaitForRenderFrameReady(web_contents->GetMainFrame()));
|
||||
EXPECT_EQ(UnstoppableDomainsOptInPage::kTypeForTesting,
|
||||
GetInterstitialType(web_contents));
|
||||
|
||||
EXPECT_EQ(static_cast<int>(ResolveMethodTypes::ASK),
|
||||
local_state()->GetInteger(kResolveMethod));
|
||||
SendInterstitialCommandSync(
|
||||
browser(),
|
||||
security_interstitials::SecurityInterstitialCommand::CMD_PROCEED);
|
||||
EXPECT_EQ(static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS),
|
||||
local_state()->GetInteger(kResolveMethod));
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(UnstoppableDomainsNavigationThrottleBrowserTest,
|
||||
ShowInterstitialAndReject) {
|
||||
ui_test_utils::NavigateToURL(browser(), GURL("http://test.crypto"));
|
||||
|
||||
content::WebContents* web_contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
|
||||
EXPECT_TRUE(WaitForRenderFrameReady(web_contents->GetMainFrame()));
|
||||
EXPECT_EQ(UnstoppableDomainsOptInPage::kTypeForTesting,
|
||||
GetInterstitialType(web_contents));
|
||||
|
||||
EXPECT_EQ(static_cast<int>(ResolveMethodTypes::ASK),
|
||||
local_state()->GetInteger(kResolveMethod));
|
||||
SendInterstitialCommandSync(
|
||||
browser(),
|
||||
security_interstitials::SecurityInterstitialCommand::CMD_DONT_PROCEED);
|
||||
EXPECT_EQ(static_cast<int>(ResolveMethodTypes::DISABLED),
|
||||
local_state()->GetInteger(kResolveMethod));
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,128 @@
|
||||
/* 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/test/scoped_feature_list.h"
|
||||
#include "brave/components/unstoppable_domains/constants.h"
|
||||
#include "brave/components/unstoppable_domains/features.h"
|
||||
#include "brave/components/unstoppable_domains/pref_names.h"
|
||||
#include "brave/net/unstoppable_domains/constants.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/net/secure_dns_config.h"
|
||||
#include "chrome/browser/net/stub_resolver_config_reader.h"
|
||||
#include "chrome/browser/net/system_network_context_manager.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "chrome/test/base/in_process_browser_test.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/test/browser_test.h"
|
||||
#include "net/dns/public/secure_dns_mode.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
class UnstoppableDomainsServiceBrowserTest : public InProcessBrowserTest {
|
||||
public:
|
||||
UnstoppableDomainsServiceBrowserTest() {
|
||||
feature_list_.InitAndEnableFeature(features::kUnstoppableDomains);
|
||||
}
|
||||
|
||||
void SetUpOnMainThread() override {
|
||||
InProcessBrowserTest::SetUpOnMainThread();
|
||||
stub_config_reader_ =
|
||||
SystemNetworkContextManager::GetStubResolverConfigReader();
|
||||
ASSERT_TRUE(stub_config_reader_);
|
||||
}
|
||||
|
||||
~UnstoppableDomainsServiceBrowserTest() override = default;
|
||||
|
||||
PrefService* local_state() { return g_browser_process->local_state(); }
|
||||
|
||||
SecureDnsConfig GetSecureDnsConfiguration(
|
||||
bool force_check_parental_controls_for_automatic_mode = false) {
|
||||
return stub_config_reader_->GetSecureDnsConfiguration(
|
||||
force_check_parental_controls_for_automatic_mode);
|
||||
}
|
||||
|
||||
private:
|
||||
base::test::ScopedFeatureList feature_list_;
|
||||
StubResolverConfigReader* stub_config_reader_;
|
||||
};
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(UnstoppableDomainsServiceBrowserTest,
|
||||
UpdateConfigWhenPrefChanged) {
|
||||
// Initial state.
|
||||
EXPECT_EQ(local_state()->GetInteger(kResolveMethod),
|
||||
static_cast<int>(ResolveMethodTypes::ASK));
|
||||
SecureDnsConfig config = GetSecureDnsConfiguration();
|
||||
EXPECT_EQ(config.mode(), net::SecureDnsMode::kAutomatic);
|
||||
EXPECT_EQ(config.servers().size(), 0u);
|
||||
|
||||
// Set resolve method to DoH should update the config.
|
||||
local_state()->SetInteger(
|
||||
kResolveMethod, static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS));
|
||||
config = GetSecureDnsConfiguration();
|
||||
std::vector<net::DnsOverHttpsServerConfig> expected_doh_servers = {
|
||||
{kDoHResolver, true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
|
||||
// Set custom DoH provider should still keep the resolver for UD.
|
||||
local_state()->SetString(prefs::kDnsOverHttpsTemplates, "https://test.com");
|
||||
config = GetSecureDnsConfiguration();
|
||||
expected_doh_servers = {{kDoHResolver, true}, {"https://test.com", true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
|
||||
// Set secure mode to off should return empty DoH servers.
|
||||
local_state()->SetString(
|
||||
prefs::kDnsOverHttpsMode,
|
||||
SecureDnsConfig::ModeToString(net::SecureDnsMode::kOff));
|
||||
config = GetSecureDnsConfiguration();
|
||||
EXPECT_EQ(config.servers().size(), 0u);
|
||||
|
||||
// Turn on secure mode again should get the same result as before.
|
||||
local_state()->SetString(
|
||||
prefs::kDnsOverHttpsMode,
|
||||
SecureDnsConfig::ModeToString(net::SecureDnsMode::kSecure));
|
||||
config = GetSecureDnsConfiguration();
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
|
||||
// Set resolve method to disabled should keep user's DoH setting.
|
||||
local_state()->SetInteger(kResolveMethod,
|
||||
static_cast<int>(ResolveMethodTypes::DISABLED));
|
||||
config = GetSecureDnsConfiguration();
|
||||
expected_doh_servers = {{"https://test.com", true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(UnstoppableDomainsServiceBrowserTest,
|
||||
HideUnstoppableDomainsResolvers) {
|
||||
// Initial state.
|
||||
EXPECT_EQ(local_state()->GetInteger(kResolveMethod),
|
||||
static_cast<int>(ResolveMethodTypes::ASK));
|
||||
SecureDnsConfig config = GetSecureDnsConfiguration();
|
||||
EXPECT_EQ(config.mode(), net::SecureDnsMode::kAutomatic);
|
||||
EXPECT_EQ(config.servers().size(), 0u);
|
||||
|
||||
// Set resolve method to DoH should update the config.
|
||||
local_state()->SetInteger(
|
||||
kResolveMethod, static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS));
|
||||
config = GetSecureDnsConfiguration();
|
||||
std::vector<net::DnsOverHttpsServerConfig> expected_doh_servers = {
|
||||
{kDoHResolver, true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
|
||||
// Set custom DoH provider should still keep the resolver for UD.
|
||||
local_state()->SetString(prefs::kDnsOverHttpsTemplates, "https://test.com");
|
||||
config = GetSecureDnsConfiguration();
|
||||
expected_doh_servers = {{kDoHResolver, true}, {"https://test.com", true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
|
||||
// Should hide unstoppable domains resolver if
|
||||
// force_check_parental_controls_for_automatic_mode is true, used for hiding
|
||||
// the special resolver in settings.
|
||||
config = GetSecureDnsConfiguration(true);
|
||||
expected_doh_servers = {{"https://test.com", true}};
|
||||
EXPECT_EQ(config.servers(), expected_doh_servers);
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,73 @@
|
||||
/* 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/utils.h"
|
||||
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "brave/components/unstoppable_domains/constants.h"
|
||||
#include "brave/components/unstoppable_domains/features.h"
|
||||
#include "brave/components/unstoppable_domains/pref_names.h"
|
||||
#include "chrome/test/base/scoped_testing_local_state.h"
|
||||
#include "chrome/test/base/testing_browser_process.h"
|
||||
#include "components/prefs/testing_pref_service.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
class UtilsUnitTest : public testing::TestWithParam<bool> {
|
||||
public:
|
||||
UtilsUnitTest()
|
||||
: local_state_(TestingBrowserProcess::GetGlobal()),
|
||||
feature_enabled_(GetParam()) {}
|
||||
~UtilsUnitTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
if (feature_enabled_) {
|
||||
feature_list_.InitAndEnableFeature(features::kUnstoppableDomains);
|
||||
} else {
|
||||
feature_list_.InitAndDisableFeature(features::kUnstoppableDomains);
|
||||
}
|
||||
}
|
||||
|
||||
PrefService* local_state() { return local_state_.Get(); }
|
||||
bool feature_enabled() { return feature_enabled_; }
|
||||
|
||||
private:
|
||||
base::test::TaskEnvironment task_environment_;
|
||||
base::test::ScopedFeatureList feature_list_;
|
||||
ScopedTestingLocalState local_state_;
|
||||
bool feature_enabled_;
|
||||
};
|
||||
|
||||
TEST_P(UtilsUnitTest, IsUnstoppableDomainsTLD) {
|
||||
EXPECT_TRUE(IsUnstoppableDomainsTLD(GURL("http://test.crypto")));
|
||||
EXPECT_FALSE(IsUnstoppableDomainsTLD(GURL("http://test.com")));
|
||||
EXPECT_FALSE(IsUnstoppableDomainsTLD(GURL("http://crypto")));
|
||||
}
|
||||
|
||||
TEST_P(UtilsUnitTest, IsUnstoppableDomainsEnabled) {
|
||||
EXPECT_EQ(feature_enabled(), IsUnstoppableDomainsEnabled());
|
||||
}
|
||||
|
||||
TEST_P(UtilsUnitTest, IsResolveMethodAsk) {
|
||||
EXPECT_EQ(feature_enabled(), IsResolveMethodAsk(local_state()));
|
||||
|
||||
local_state()->SetInteger(
|
||||
kResolveMethod, static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS));
|
||||
EXPECT_FALSE(IsResolveMethodAsk(local_state()));
|
||||
}
|
||||
|
||||
TEST_P(UtilsUnitTest, IsResolveMethodDoH) {
|
||||
EXPECT_FALSE(IsResolveMethodDoH(local_state()));
|
||||
|
||||
local_state()->SetInteger(
|
||||
kResolveMethod, static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS));
|
||||
EXPECT_EQ(feature_enabled(), IsResolveMethodDoH(local_state()));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(/* no prefix */, UtilsUnitTest, testing::Bool());
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -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/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() {
|
||||
// Trigger a DoH config update in network service.
|
||||
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,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/. */
|
||||
|
||||
#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 "brave/components/unstoppable_domains/utils.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) {
|
||||
if (!IsUnstoppableDomainsEnabled())
|
||||
return nullptr;
|
||||
|
||||
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_
|
||||
@@ -3,6 +3,8 @@
|
||||
# import("//build/config/chrome_build.gni") in compiler.gni
|
||||
import("//brave/brave_repack_locales.gni")
|
||||
import("//brave/browser/extensions/resources.gni")
|
||||
import("//brave/browser/resources/extensions/sources.gni")
|
||||
import("//brave/browser/resources/settings/sources.gni")
|
||||
import("//brave/browser/sources.gni")
|
||||
import("//brave/build/config/compiler.gni")
|
||||
import("//brave/build/features.gni")
|
||||
@@ -13,8 +15,7 @@ import("//brave/components/sync/driver/sources.gni")
|
||||
import("//brave/components/sync/sources.gni")
|
||||
import("//brave/components/sync_device_info/sources.gni")
|
||||
import("//brave/installer/linux/sources.gni")
|
||||
import("//brave/net/dns/sources.gni")
|
||||
import("//brave/net/sources.gni")
|
||||
import("//brave/renderer/sources.gni")
|
||||
import("//brave/third_party/blink/renderer/includes.gni")
|
||||
import("//brave/browser/resources/settings/sources.gni")
|
||||
import("//brave/browser/resources/extensions/sources.gni")
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "brave/components/ntp_background_images/browser/features.h"
|
||||
#include "brave/components/sidebar/buildflags/buildflags.h"
|
||||
#include "brave/components/speedreader/buildflags.h"
|
||||
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/profiles/profile_manager.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
@@ -92,6 +93,18 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
|
||||
#define BRAVE_NATIVE_WALLET_FEATURE_ENTRIES
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
|
||||
#include "brave/components/unstoppable_domains/features.h"
|
||||
|
||||
#define BRAVE_UNSTOPPABLE_DOMAINS_FEATURE_ENTRIES \
|
||||
{"brave-unstoppable-domains", \
|
||||
flag_descriptions::kBraveUnstoppableDomainsName, \
|
||||
flag_descriptions::kBraveUnstoppableDomainsDescription, kOsDesktop, \
|
||||
FEATURE_VALUE_TYPE(unstoppable_domains::features::kUnstoppableDomains)},
|
||||
#else
|
||||
#define BRAVE_UNSTOPPABLE_DOMAINS_FEATURE_ENTRIES
|
||||
#endif
|
||||
|
||||
#define BRAVE_FEATURE_ENTRIES \
|
||||
{"use-dev-updater-url", \
|
||||
flag_descriptions::kUseDevUpdaterUrlName, \
|
||||
@@ -114,6 +127,7 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
|
||||
BRAVE_IPFS_FEATURE_ENTRIES \
|
||||
BRAVE_NATIVE_WALLET_FEATURE_ENTRIES \
|
||||
SIDEBAR_FEATURE_ENTRIES \
|
||||
BRAVE_UNSTOPPABLE_DOMAINS_FEATURE_ENTRIES \
|
||||
{"brave-super-referral", \
|
||||
flag_descriptions::kBraveSuperReferralName, \
|
||||
flag_descriptions::kBraveSuperReferralDescription, \
|
||||
|
||||
@@ -41,6 +41,9 @@ const char kNativeBraveWalletName[] = "Enable experimental Brave native wallet";
|
||||
const char kNativeBraveWalletDescription[] =
|
||||
"Experimental native cryptocurrency wallet support without the use of "
|
||||
"extensions";
|
||||
const char kBraveUnstoppableDomainsName[] = "Enable unstoppable domains";
|
||||
const char kBraveUnstoppableDomainsDescription[] =
|
||||
"Enable resolution support of unstoppable domains.";
|
||||
const char kBraveSuperReferralName[] = "Enable Brave Super Referral";
|
||||
const char kBraveSuperReferralDescription[] =
|
||||
"Use custom theme for Brave Super Referral";
|
||||
|
||||
@@ -27,6 +27,8 @@ extern const char kBraveIpfsName[];
|
||||
extern const char kBraveIpfsDescription[];
|
||||
extern const char kNativeBraveWalletName[];
|
||||
extern const char kNativeBraveWalletDescription[];
|
||||
extern const char kBraveUnstoppableDomainsName[];
|
||||
extern const char kBraveUnstoppableDomainsDescription[];
|
||||
extern const char kBraveSuperReferralName[];
|
||||
extern const char kBraveSuperReferralDescription[];
|
||||
extern const char kBraveEphemeralStorageName[];
|
||||
|
||||
@@ -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/. */
|
||||
|
||||
#include "brave/components/unstoppable_domains/buildflags/buildflags.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
|
||||
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
|
||||
#include "base/strings/strcat.h"
|
||||
#include "brave/components/unstoppable_domains/utils.h"
|
||||
#include "brave/net/unstoppable_domains/constants.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
|
||||
void AddUnstoppableDomainsResolver(std::string* doh_templates,
|
||||
PrefService* local_state) {
|
||||
if (unstoppable_domains::IsResolveMethodDoH(local_state) &&
|
||||
doh_templates->find(unstoppable_domains::kDoHResolver) ==
|
||||
std::string::npos) {
|
||||
*doh_templates =
|
||||
base::StrCat({unstoppable_domains::kDoHResolver, " ", *doh_templates});
|
||||
}
|
||||
}
|
||||
#endif // BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
|
||||
|
||||
// Add DoH servers to support Unstoppable Domains (and ENS in the future PR).
|
||||
// These servers are controlled using its own prefs and not
|
||||
// kDnsOverHttpsTemplates pref as the servers we added here are special and
|
||||
// only applies to certain TLD which is different from user's global DoH
|
||||
// provider settings.
|
||||
void AddDoHServers(std::string* doh_templates,
|
||||
PrefService* local_state,
|
||||
bool force_check_parental_controls_for_automatic_mode) {
|
||||
// force_check_parental_controls_for_automatic_mode is only true for
|
||||
// settings UI which we specifically do not want to display those special
|
||||
// resolvers we added.
|
||||
if (force_check_parental_controls_for_automatic_mode)
|
||||
return;
|
||||
|
||||
#if BUILDFLAG(UNSTOPPABLE_DOMAINS_ENABLED)
|
||||
AddUnstoppableDomainsResolver(doh_templates, local_state);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#define BRAVE_GET_AND_UPDATE_CONFIGURATION \
|
||||
AddDoHServers(&doh_templates, local_state_, \
|
||||
force_check_parental_controls_for_automatic_mode);
|
||||
|
||||
#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",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
include_rules = [
|
||||
"+../../../../net/base",
|
||||
"+../../../../net/cookies",
|
||||
"+../../../../net/dns",
|
||||
"+../../../../net/log",
|
||||
"+../../../../net/proxy_resolution",
|
||||
"+../../../../net/socket",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#undef LookupSuffixInReversedSet
|
||||
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brave/net/unstoppable_domains/constants.h"
|
||||
|
||||
namespace net {
|
||||
|
||||
@@ -40,6 +41,15 @@ int LookupSuffixInReversedSet(const unsigned char* graph,
|
||||
return kDafsaFound;
|
||||
}
|
||||
|
||||
// Recognize .crypto as a known TLD for unstoppable domains support. With
|
||||
// this, when users type *.crypto in omnibox, it will be parsed as
|
||||
// OmniboxInputType::URL input type instead of OmniboxInputType::UNKNOWN,
|
||||
// The first entry in the autocomplete list will be URL instead of search.
|
||||
if (base::EndsWith(host, unstoppable_domains::kCryptoDomain)) {
|
||||
*suffix_length = strlen(unstoppable_domains::kCryptoDomain) - 1;
|
||||
return kDafsaFound;
|
||||
}
|
||||
|
||||
return LookupSuffixInReversedSet_ChromiumImpl(graph, length, include_private,
|
||||
host, suffix_length);
|
||||
}
|
||||
|
||||
@@ -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/. */
|
||||
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brave/net/unstoppable_domains/constants.h"
|
||||
#include "net/dns/dns_config.h"
|
||||
#include "net/dns/dns_server_iterator.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool GetNextIndex(const std::string& hostname,
|
||||
const net::DnsConfig& config,
|
||||
net::DnsServerIterator* dns_server_iterator,
|
||||
size_t* doh_server_index) {
|
||||
// Skip unstoppable domains resolver for non-crypto domains.
|
||||
if (config.dns_over_https_servers[*doh_server_index].server_template ==
|
||||
unstoppable_domains::kDoHResolver &&
|
||||
!base::EndsWith(hostname, unstoppable_domains::kCryptoDomain)) {
|
||||
// No next available index to attempt.
|
||||
if (!dns_server_iterator->AttemptAvailable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*doh_server_index = dns_server_iterator->GetNextAttemptIndex();
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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/locales.gni")
|
||||
import("//extensions/buildflags/buildflags.gni")
|
||||
import("//tools/grit/grit_rule.gni")
|
||||
@@ -42,6 +43,7 @@ grit("static_resources") {
|
||||
"enable_speedreader=$enable_speedreader",
|
||||
"ipfs_enabled=$ipfs_enabled",
|
||||
"crypto_dot_com_enabled=$crypto_dot_com_enabled",
|
||||
"unstoppable_domains_enabled=$unstoppable_domains_enabled",
|
||||
]
|
||||
|
||||
grit_flags = [
|
||||
@@ -95,6 +97,7 @@ grit("strings") {
|
||||
defines = [
|
||||
"enable_speedreader=$enable_speedreader",
|
||||
"ipfs_enabled=$ipfs_enabled",
|
||||
"unstoppable_domains_enabled=$unstoppable_domains_enabled",
|
||||
"crypto_dot_com_enabled=$crypto_dot_com_enabled",
|
||||
"enable_tor=$enable_tor",
|
||||
"enable_sidebar=$enable_sidebar",
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
<part file="speedreader_resources.grdp" />
|
||||
<part file="brave_flags_ui_resources.grdp" />
|
||||
<part file="ipfs_resources.grdp" />
|
||||
<part file="unstoppable_domains_resources.grdp" />
|
||||
</includes>
|
||||
</release>
|
||||
</grit>
|
||||
|
||||
@@ -1090,6 +1090,7 @@
|
||||
<message name="IDS_BRAVE_WALLET_DISCLOSURE_CONFIRM" desc="">I understand</message>
|
||||
<part file="speedreader_strings.grdp" />
|
||||
<part file="ipfs_strings.grdp" />
|
||||
<part file="unstoppable_domains_strings.grdp" />
|
||||
<part file="crypto_dot_com_strings.grdp" />
|
||||
<part file="tor_strings.grdp" />
|
||||
</messages>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<grit-part>
|
||||
<if expr="unstoppable_domains_enabled">
|
||||
<include name="IDR_UNSTOPPABLE_DOMAINS_INTERSTITIAL_HTML" file="../unstoppable_domains/resources/unstoppable_domains_interstitial.html" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_UNSTOPPABLE_DOMAINS_INTERSTITIAL_JS" file="../unstoppable_domains/resources/unstoppable_domains_interstitial.js" type="BINDATA" />
|
||||
<include name="IDR_UNSTOPPABLE_DOMAINS_INTERSTITIAL_CSS" file="../unstoppable_domains/resources/unstoppable_domains_interstitial.css" type="BINDATA" />
|
||||
</if>
|
||||
</grit-part>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<grit-part>
|
||||
<if expr="unstoppable_domains_enabled">
|
||||
<message name="IDS_UNSTOPPABLE_DOMAINS_OPT_IN_TITLE" desc="Title of interstitial opt-in page for unstoppable domains.">
|
||||
Unstoppable Domains
|
||||
</message>
|
||||
<message name="IDS_UNSTOPPABLE_DOMAINS_OPT_IN_HEADING" desc="Heading of unstoppable domains opt-in interstitial opt-in page.">
|
||||
Enable support of Unstoppable Domains in Brave?
|
||||
</message>
|
||||
<message name="IDS_UNSTOPPABLE_DOMAINS_OPT_IN_PRIMARY_PARAGRAPH" desc="Main paragraph of unstoppable domains not connected interstitial page.">
|
||||
Brave can enable you to visit .crypto domains by using Cloudflare to resolve .crypto domain name lookup requests using DNS over HTTPS. If you enable this, Cloudflare will see the .crypto domain that you're trying to visit but they will not be able to see other domains. See Cloudflare's <ph name="BEGIN_CF_TOU_LINK">$1</ph>terms of use<ph name="END_CF_TOU_LINK">$2</ph> and <ph name="BEGIN_CF_PRIVACY_LINK">$3</ph>privacy policy<ph name="END_CF_PRIVACY_LINK">$4</ph>.
|
||||
</message>
|
||||
<message name="IDS_UNSTOPPABLE_DOMAINS_OPT_IN_PRIMARY_BUTTON" desc="The text for the unstoppable domains opt-in interstitial primary button.">
|
||||
Proceed using Cloudflare server
|
||||
</message>
|
||||
<message name="IDS_UNSTOPPABLE_DOMAINS_OPT_IN_DONT_PROCEED_BUTTON" desc="The text for the don't proceed button in unstoppable domains opt-in interstitial page.">
|
||||
Disable
|
||||
</message>
|
||||
</if>
|
||||
</grit-part>
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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") {
|
||||
sources = [
|
||||
"constants.h",
|
||||
"features.h",
|
||||
"pref_names.h",
|
||||
"unstoppable_domains_interstitial_controller_client.cc",
|
||||
"unstoppable_domains_interstitial_controller_client.h",
|
||||
"unstoppable_domains_navigation_throttle.cc",
|
||||
"unstoppable_domains_navigation_throttle.h",
|
||||
"unstoppable_domains_opt_in_page.cc",
|
||||
"unstoppable_domains_opt_in_page.h",
|
||||
"unstoppable_domains_service.cc",
|
||||
"unstoppable_domains_service.h",
|
||||
"unstoppable_domains_service_delegate.h",
|
||||
"utils.cc",
|
||||
"utils.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//brave/components/resources:static_resources",
|
||||
"//brave/components/resources:strings",
|
||||
"//components/keyed_service/core",
|
||||
"//components/prefs",
|
||||
"//components/security_interstitials/content:security_interstitial_page",
|
||||
"//components/security_interstitials/core",
|
||||
"//components/user_prefs",
|
||||
"//content/public/browser",
|
||||
"//net",
|
||||
"//url",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
include_rules = [
|
||||
"+base",
|
||||
"+components/keyed_service/core",
|
||||
"+components/grit",
|
||||
"+components/prefs",
|
||||
"+components/security_interstitials/content",
|
||||
"+components/security_interstitials/core",
|
||||
"+components/user_prefs",
|
||||
"+content/public/browser",
|
||||
"+content/public/common",
|
||||
"+net",
|
||||
"+ui/base",
|
||||
"+url",
|
||||
]
|
||||
@@ -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,3 @@
|
||||
declare_args() {
|
||||
unstoppable_domains_enabled = is_mac || is_linux || is_win
|
||||
}
|
||||
@@ -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/. */
|
||||
|
||||
#ifndef BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
enum class ResolveMethodTypes {
|
||||
ASK,
|
||||
DISABLED,
|
||||
DNS_OVER_HTTPS,
|
||||
};
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_CONSTANTS_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_FEATURES_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_FEATURES_H_
|
||||
|
||||
#include "base/feature_list.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
namespace features {
|
||||
|
||||
constexpr base::Feature kUnstoppableDomains{"UnstoppableDomains",
|
||||
base::FEATURE_DISABLED_BY_DEFAULT};
|
||||
|
||||
} // namespace features
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_FEATURES_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_PREF_NAMES_H_
|
||||
#define 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.
|
||||
// Ask: Ask users if they want to enable support of unstoppable domains.
|
||||
// DNS Over HTTPS: Resolve domain name using a public DNS over HTTPS server.
|
||||
constexpr char kResolveMethod[] = "brave.unstoppable_domains.resolve_method";
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_PREF_NAMES_H_
|
||||
@@ -0,0 +1,14 @@
|
||||
.unstoppable_domains #main-content a {
|
||||
color: var(--google-blue-700);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.unstoppable_domains button {
|
||||
background: var(--primary-button-fill-color);
|
||||
}
|
||||
|
||||
.unstoppable_domains .icon {
|
||||
background-image: -webkit-image-set(
|
||||
url(../../../../components/security_interstitials/core/browser/resources/images/1x/info.png) 1x,
|
||||
url(../../../../components/security_interstitials/core/browser/resources/images/2x/info.png) 2x);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="theme-color" content="#fff">
|
||||
<title>$i18n{tabTitle}</title>
|
||||
<link rel="stylesheet" href="../../../../components/security_interstitials/core/common/resources/interstitial_core.css">
|
||||
<link rel="stylesheet" href="../../../../components/security_interstitials/core/common/resources/interstitial_common.css">
|
||||
<link rel="stylesheet" href="unstoppable_domains_interstitial.css">
|
||||
<script src="../../../../ui/webui/resources/js/assert.js"></script>
|
||||
<script src="../../../../ui/webui/resources/js/util.js"></script>
|
||||
<script src="../../../../components/security_interstitials/core/common/resources/interstitial_common.js"></script>
|
||||
<script src="unstoppable_domains_interstitial.js"></script>
|
||||
</head>
|
||||
<body id="body">
|
||||
<div class="interstitial-wrapper">
|
||||
<div id="main-content">
|
||||
<div class="icon" id="icon"></div>
|
||||
<div id="main-message">
|
||||
<h1>$i18nRaw{heading}</h1>
|
||||
<p>$i18nRaw{primaryParagraph}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="nav-wrapper">
|
||||
<button id="primary-button">$i18n{primaryButtonText}</button>
|
||||
<button id="proceed-button" class="secondary-button small-link hidden"></button>
|
||||
<button id="dont-proceed-button" class="secondary-button small-link">
|
||||
$i18n{dontProceedButtonText}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 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/.
|
||||
|
||||
function setupEvents() {
|
||||
$('body').classList.add('unstoppable_domains');
|
||||
$('icon').classList.add('icon');
|
||||
|
||||
$('primary-button').addEventListener('click', function() {
|
||||
sendCommand(SecurityInterstitialCommandId.CMD_PROCEED);
|
||||
});
|
||||
|
||||
$('main-content').classList.remove(HIDDEN_CLASS);
|
||||
|
||||
$('dont-proceed-button').addEventListener('click', function(event) {
|
||||
sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED);
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', setupEvents);
|
||||
@@ -0,0 +1,59 @@
|
||||
/* 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_interstitial_controller_client.h"
|
||||
|
||||
#include "brave/components/unstoppable_domains/constants.h"
|
||||
#include "brave/components/unstoppable_domains/pref_names.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/security_interstitials/content/settings_page_helper.h"
|
||||
#include "components/security_interstitials/core/metrics_helper.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
// static
|
||||
std::unique_ptr<security_interstitials::MetricsHelper>
|
||||
UnstoppableDomainsInterstitialControllerClient::GetMetricsHelper(
|
||||
const GURL& url) {
|
||||
security_interstitials::MetricsHelper::ReportDetails report_details;
|
||||
report_details.metric_prefix = "UnstoppableDomains";
|
||||
|
||||
return std::make_unique<security_interstitials::MetricsHelper>(
|
||||
url, report_details, nullptr);
|
||||
}
|
||||
|
||||
UnstoppableDomainsInterstitialControllerClient::
|
||||
UnstoppableDomainsInterstitialControllerClient(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& request_url,
|
||||
PrefService* user_prefs,
|
||||
PrefService* local_state,
|
||||
const std::string& locale)
|
||||
: security_interstitials::SecurityInterstitialControllerClient(
|
||||
web_contents,
|
||||
GetMetricsHelper(request_url),
|
||||
user_prefs,
|
||||
locale,
|
||||
GURL("about:blank") /* default_safe_page */,
|
||||
nullptr /* settings_page_helper */),
|
||||
request_url_(request_url),
|
||||
local_state_(local_state) {}
|
||||
|
||||
void UnstoppableDomainsInterstitialControllerClient::Proceed() {
|
||||
SetResolveMethodAndReload(ResolveMethodTypes::DNS_OVER_HTTPS);
|
||||
}
|
||||
|
||||
void UnstoppableDomainsInterstitialControllerClient::DontProceed() {
|
||||
SetResolveMethodAndReload(ResolveMethodTypes::DISABLED);
|
||||
}
|
||||
|
||||
void UnstoppableDomainsInterstitialControllerClient::SetResolveMethodAndReload(
|
||||
ResolveMethodTypes type) {
|
||||
DCHECK(local_state_);
|
||||
local_state_->SetInteger(kResolveMethod, static_cast<int>(type));
|
||||
Reload();
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,60 @@
|
||||
/* 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_INTERSTITIAL_CONTROLLER_CLIENT_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_INTERSTITIAL_CONTROLLER_CLIENT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
} // namespace content
|
||||
|
||||
namespace security_interstitials {
|
||||
class MetricsHelper;
|
||||
} // namespace security_interstitials
|
||||
|
||||
class PrefService;
|
||||
|
||||
namespace unstoppable_domains {
|
||||
enum class ResolveMethodTypes;
|
||||
|
||||
class UnstoppableDomainsInterstitialControllerClient
|
||||
: public security_interstitials::SecurityInterstitialControllerClient {
|
||||
public:
|
||||
static std::unique_ptr<security_interstitials::MetricsHelper>
|
||||
GetMetricsHelper(const GURL& url);
|
||||
|
||||
UnstoppableDomainsInterstitialControllerClient(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& request_url,
|
||||
PrefService* user_prefs,
|
||||
PrefService* local_state,
|
||||
const std::string& locale);
|
||||
~UnstoppableDomainsInterstitialControllerClient() override = default;
|
||||
|
||||
UnstoppableDomainsInterstitialControllerClient(
|
||||
const UnstoppableDomainsInterstitialControllerClient&) = delete;
|
||||
UnstoppableDomainsInterstitialControllerClient& operator=(
|
||||
const UnstoppableDomainsInterstitialControllerClient&) = delete;
|
||||
|
||||
// security_interstitials::SecurityInterstitialControllerClient:
|
||||
void Proceed() override;
|
||||
void DontProceed();
|
||||
|
||||
private:
|
||||
void SetResolveMethodAndReload(ResolveMethodTypes type);
|
||||
|
||||
const GURL request_url_;
|
||||
PrefService* local_state_;
|
||||
};
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_INTERSTITIAL_CONTROLLER_CLIENT_H_
|
||||
@@ -0,0 +1,93 @@
|
||||
/* 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_navigation_throttle.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/threading/sequenced_task_runner_handle.h"
|
||||
#include "brave/components/unstoppable_domains/unstoppable_domains_interstitial_controller_client.h"
|
||||
#include "brave/components/unstoppable_domains/unstoppable_domains_opt_in_page.h"
|
||||
#include "brave/components/unstoppable_domains/utils.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
|
||||
#include "components/user_prefs/user_prefs.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "net/base/net_errors.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
// static
|
||||
std::unique_ptr<UnstoppableDomainsNavigationThrottle>
|
||||
UnstoppableDomainsNavigationThrottle::MaybeCreateThrottleFor(
|
||||
content::NavigationHandle* navigation_handle,
|
||||
PrefService* local_state,
|
||||
const std::string& locale) {
|
||||
if (!IsUnstoppableDomainsEnabled())
|
||||
return nullptr;
|
||||
|
||||
return std::make_unique<UnstoppableDomainsNavigationThrottle>(
|
||||
navigation_handle, local_state, locale);
|
||||
}
|
||||
|
||||
UnstoppableDomainsNavigationThrottle::UnstoppableDomainsNavigationThrottle(
|
||||
content::NavigationHandle* navigation_handle,
|
||||
PrefService* local_state,
|
||||
const std::string& locale)
|
||||
: content::NavigationThrottle(navigation_handle),
|
||||
local_state_(local_state),
|
||||
locale_(locale) {
|
||||
content::BrowserContext* context =
|
||||
navigation_handle->GetWebContents()->GetBrowserContext();
|
||||
user_prefs_ = user_prefs::UserPrefs::Get(context);
|
||||
}
|
||||
|
||||
UnstoppableDomainsNavigationThrottle::~UnstoppableDomainsNavigationThrottle() =
|
||||
default;
|
||||
|
||||
content::NavigationThrottle::ThrottleCheckResult
|
||||
UnstoppableDomainsNavigationThrottle::WillStartRequest() {
|
||||
GURL url = navigation_handle()->GetURL();
|
||||
if (!IsUnstoppableDomainsTLD(url) || !IsResolveMethodAsk(local_state_)) {
|
||||
return content::NavigationThrottle::PROCEED;
|
||||
}
|
||||
|
||||
base::SequencedTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&UnstoppableDomainsNavigationThrottle::ShowInterstitial,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
return content::NavigationThrottle::DEFER;
|
||||
}
|
||||
|
||||
void UnstoppableDomainsNavigationThrottle::ShowInterstitial() {
|
||||
content::NavigationHandle* handle = navigation_handle();
|
||||
content::WebContents* web_contents = handle->GetWebContents();
|
||||
const GURL& request_url = handle->GetURL();
|
||||
|
||||
auto controller_client =
|
||||
std::make_unique<UnstoppableDomainsInterstitialControllerClient>(
|
||||
web_contents, request_url, user_prefs_, local_state_, locale_);
|
||||
auto page = std::make_unique<UnstoppableDomainsOptInPage>(
|
||||
web_contents, handle->GetURL(), std::move(controller_client));
|
||||
|
||||
// Get the page content before giving up ownership of |page|.
|
||||
std::string page_content = page->GetHTMLContents();
|
||||
|
||||
security_interstitials::SecurityInterstitialTabHelper::AssociateBlockingPage(
|
||||
web_contents, handle->GetNavigationId(), std::move(page));
|
||||
|
||||
CancelDeferredNavigation(content::NavigationThrottle::ThrottleCheckResult(
|
||||
content::NavigationThrottle::CANCEL, net::ERR_BLOCKED_BY_CLIENT,
|
||||
page_content));
|
||||
}
|
||||
|
||||
const char* UnstoppableDomainsNavigationThrottle::GetNameForLogging() {
|
||||
return "UnstoppableDomainsNavigationThrottle";
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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_NAVIGATION_THROTTLE_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_NAVIGATION_THROTTLE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/navigation_throttle.h"
|
||||
|
||||
namespace content {
|
||||
class NavigationHandle;
|
||||
} // namespace content
|
||||
|
||||
class PrefService;
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
class UnstoppableDomainsNavigationThrottle
|
||||
: public content::NavigationThrottle {
|
||||
public:
|
||||
explicit UnstoppableDomainsNavigationThrottle(
|
||||
content::NavigationHandle* navigation_handle,
|
||||
PrefService* local_state,
|
||||
const std::string& locale);
|
||||
~UnstoppableDomainsNavigationThrottle() override;
|
||||
|
||||
UnstoppableDomainsNavigationThrottle(
|
||||
const UnstoppableDomainsNavigationThrottle&) = delete;
|
||||
UnstoppableDomainsNavigationThrottle& operator=(
|
||||
const UnstoppableDomainsNavigationThrottle&) = delete;
|
||||
|
||||
static std::unique_ptr<UnstoppableDomainsNavigationThrottle>
|
||||
MaybeCreateThrottleFor(content::NavigationHandle* navigation_handle,
|
||||
PrefService* local_state,
|
||||
const std::string& locale);
|
||||
|
||||
// content::NavigationThrottle implementation:
|
||||
ThrottleCheckResult WillStartRequest() override;
|
||||
const char* GetNameForLogging() override;
|
||||
|
||||
private:
|
||||
void ShowInterstitial();
|
||||
|
||||
PrefService* user_prefs_ = nullptr;
|
||||
PrefService* local_state_ = nullptr;
|
||||
std::string locale_;
|
||||
base::WeakPtrFactory<UnstoppableDomainsNavigationThrottle> weak_ptr_factory_{
|
||||
this};
|
||||
};
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_NAVIGATION_THROTTLE_H_
|
||||
@@ -0,0 +1,111 @@
|
||||
/* 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_opt_in_page.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/notreached.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
#include "brave/components/unstoppable_domains/unstoppable_domains_interstitial_controller_client.h"
|
||||
#include "components/grit/brave_components_resources.h"
|
||||
#include "components/grit/brave_components_strings.h"
|
||||
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
// static
|
||||
const security_interstitials::SecurityInterstitialPage::TypeID
|
||||
UnstoppableDomainsOptInPage::kTypeForTesting =
|
||||
&UnstoppableDomainsOptInPage::kTypeForTesting;
|
||||
|
||||
UnstoppableDomainsOptInPage::UnstoppableDomainsOptInPage(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& request_url,
|
||||
std::unique_ptr<
|
||||
security_interstitials::SecurityInterstitialControllerClient>
|
||||
controller)
|
||||
: security_interstitials::SecurityInterstitialPage(web_contents,
|
||||
request_url,
|
||||
std::move(controller)) {}
|
||||
|
||||
UnstoppableDomainsOptInPage::~UnstoppableDomainsOptInPage() = default;
|
||||
|
||||
void UnstoppableDomainsOptInPage::CommandReceived(const std::string& command) {
|
||||
if (command == "\"pageLoadComplete\"") {
|
||||
// content::WaitForRenderFrameReady sends this message when the page
|
||||
// load completes. Ignore it.
|
||||
return;
|
||||
}
|
||||
|
||||
int cmd = 0;
|
||||
bool retval = base::StringToInt(command, &cmd);
|
||||
DCHECK(retval);
|
||||
|
||||
switch (cmd) {
|
||||
case security_interstitials::CMD_DONT_PROCEED:
|
||||
static_cast<UnstoppableDomainsInterstitialControllerClient*>(controller())
|
||||
->DontProceed();
|
||||
break;
|
||||
case security_interstitials::CMD_PROCEED:
|
||||
controller()->Proceed();
|
||||
break;
|
||||
default:
|
||||
NOTREACHED() << "Unsupported command: " << command;
|
||||
}
|
||||
}
|
||||
|
||||
void UnstoppableDomainsOptInPage::PopulateInterstitialStrings(
|
||||
base::DictionaryValue* load_time_data) {
|
||||
load_time_data->SetString(
|
||||
"tabTitle",
|
||||
l10n_util::GetStringUTF16(IDS_UNSTOPPABLE_DOMAINS_OPT_IN_TITLE));
|
||||
load_time_data->SetString(
|
||||
"heading",
|
||||
l10n_util::GetStringUTF16(IDS_UNSTOPPABLE_DOMAINS_OPT_IN_HEADING));
|
||||
|
||||
const std::vector<base::string16> message_params = {
|
||||
base::ASCIIToUTF16("<a "
|
||||
"href='https://www.cloudflare.com/en-ca/"
|
||||
"distributed-web-gateway-terms/' target='_blank' "
|
||||
"rel='noopener noreferrer'>"),
|
||||
base::ASCIIToUTF16("</a>"),
|
||||
base::ASCIIToUTF16(
|
||||
"<a href='https://www.cloudflare.com/en-ca/privacypolicy/' "
|
||||
"target='_blank' rel='noopener noreferrer'>"),
|
||||
base::ASCIIToUTF16("</a>"),
|
||||
};
|
||||
load_time_data->SetString(
|
||||
"primaryParagraph",
|
||||
base::ReplaceStringPlaceholders(
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_UNSTOPPABLE_DOMAINS_OPT_IN_PRIMARY_PARAGRAPH),
|
||||
message_params, nullptr));
|
||||
|
||||
load_time_data->SetString(
|
||||
"primaryButtonText",
|
||||
l10n_util::GetStringUTF16(IDS_UNSTOPPABLE_DOMAINS_OPT_IN_PRIMARY_BUTTON));
|
||||
load_time_data->SetString(
|
||||
"dontProceedButtonText",
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_UNSTOPPABLE_DOMAINS_OPT_IN_DONT_PROCEED_BUTTON));
|
||||
load_time_data->SetString("finalParagraph", base::string16());
|
||||
}
|
||||
|
||||
int UnstoppableDomainsOptInPage::GetHTMLTemplateId() {
|
||||
return IDR_UNSTOPPABLE_DOMAINS_INTERSTITIAL_HTML;
|
||||
}
|
||||
|
||||
security_interstitials::SecurityInterstitialPage::TypeID
|
||||
UnstoppableDomainsOptInPage::GetTypeForTesting() {
|
||||
return UnstoppableDomainsOptInPage::kTypeForTesting;
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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_OPT_IN_PAGE_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_OPT_IN_PAGE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "components/security_interstitials/content/security_interstitial_page.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
} // namespace content
|
||||
|
||||
namespace security_interstitials {
|
||||
class SecurityInterstitialControllerClient;
|
||||
} // namespace security_interstitials
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
class UnstoppableDomainsOptInPage
|
||||
: public security_interstitials::SecurityInterstitialPage {
|
||||
public:
|
||||
// Interstitial type, used in tests.
|
||||
static const security_interstitials::SecurityInterstitialPage::TypeID
|
||||
kTypeForTesting;
|
||||
|
||||
UnstoppableDomainsOptInPage(
|
||||
content::WebContents* web_contents,
|
||||
const GURL& request_url,
|
||||
std::unique_ptr<
|
||||
security_interstitials::SecurityInterstitialControllerClient>
|
||||
controller);
|
||||
~UnstoppableDomainsOptInPage() override;
|
||||
|
||||
UnstoppableDomainsOptInPage(const UnstoppableDomainsOptInPage&) = delete;
|
||||
UnstoppableDomainsOptInPage& operator=(const UnstoppableDomainsOptInPage&) =
|
||||
delete;
|
||||
|
||||
// SecurityInterstitialPage::
|
||||
void OnInterstitialClosing() override {}
|
||||
void CommandReceived(const std::string& command) override;
|
||||
security_interstitials::SecurityInterstitialPage::TypeID GetTypeForTesting()
|
||||
override;
|
||||
|
||||
protected:
|
||||
// SecurityInterstitialPage::
|
||||
void PopulateInterstitialStrings(
|
||||
base::DictionaryValue* load_time_data) override;
|
||||
int GetHTMLTemplateId() override;
|
||||
};
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UNSTOPPABLE_DOMAINS_OPT_IN_PAGE_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)
|
||||
: 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,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/. */
|
||||
|
||||
#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();
|
||||
|
||||
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_
|
||||
@@ -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/utils.h"
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brave/components/unstoppable_domains/constants.h"
|
||||
#include "brave/components/unstoppable_domains/features.h"
|
||||
#include "brave/components/unstoppable_domains/pref_names.h"
|
||||
#include "brave/net/unstoppable_domains/constants.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
bool IsUnstoppableDomainsTLD(const GURL& url) {
|
||||
return base::EndsWith(url.host_piece(), kCryptoDomain);
|
||||
}
|
||||
|
||||
bool IsUnstoppableDomainsEnabled() {
|
||||
return base::FeatureList::IsEnabled(features::kUnstoppableDomains);
|
||||
}
|
||||
|
||||
bool IsResolveMethodAsk(PrefService* local_state) {
|
||||
if (!local_state || !IsUnstoppableDomainsEnabled()) {
|
||||
return false; // Treat it as disabled.
|
||||
}
|
||||
|
||||
return local_state->GetInteger(kResolveMethod) ==
|
||||
static_cast<int>(ResolveMethodTypes::ASK);
|
||||
}
|
||||
|
||||
bool IsResolveMethodDoH(PrefService* local_state) {
|
||||
if (!local_state || !IsUnstoppableDomainsEnabled()) {
|
||||
return false; // Treat it as disabled.
|
||||
}
|
||||
|
||||
return local_state->GetInteger(kResolveMethod) ==
|
||||
static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS);
|
||||
}
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
@@ -0,0 +1,21 @@
|
||||
/* 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_UTILS_H_
|
||||
#define BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UTILS_H_
|
||||
|
||||
class GURL;
|
||||
class PrefService;
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
bool IsUnstoppableDomainsTLD(const GURL& url);
|
||||
bool IsUnstoppableDomainsEnabled();
|
||||
bool IsResolveMethodAsk(PrefService* local_state);
|
||||
bool IsResolveMethodDoH(PrefService* local_state);
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_COMPONENTS_UNSTOPPABLE_DOMAINS_UTILS_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
# 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/.
|
||||
|
||||
brave_dns_friend = [ "//brave/browser/unstoppable_domains/test:unit_tests" ]
|
||||
@@ -3,7 +3,10 @@
|
||||
# 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/components/unstoppable_domains/buildflags/buildflags.gni")
|
||||
|
||||
brave_net_sources = [
|
||||
"//brave/net/proxy_resolution/proxy_config_service_tor.cc",
|
||||
"//brave/net/proxy_resolution/proxy_config_service_tor.h",
|
||||
"//brave/net/unstoppable_domains/constants.h",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/* 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_NET_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
|
||||
#define BRAVE_NET_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
|
||||
|
||||
namespace unstoppable_domains {
|
||||
|
||||
constexpr char kCryptoDomain[] = ".crypto";
|
||||
constexpr char kDoHResolver[] =
|
||||
"https://resolver.unstoppable.io/dns-query{?brave_UD}";
|
||||
|
||||
} // namespace unstoppable_domains
|
||||
|
||||
#endif // BRAVE_NET_UNSTOPPABLE_DOMAINS_CONSTANTS_H_
|
||||
@@ -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,28 @@
|
||||
diff --git a/net/dns/BUILD.gn b/net/dns/BUILD.gn
|
||||
index ea7c29d285af754ee3c1ca0537645b05602d55f4..90a40ae96ca2de9048eab86fd2f45e3e3555b6b4 100644
|
||||
--- a/net/dns/BUILD.gn
|
||||
+++ b/net/dns/BUILD.gn
|
||||
@@ -23,6 +23,7 @@ source_set("dns") {
|
||||
"//net/*",
|
||||
"//services/network/*",
|
||||
]
|
||||
+ friend += brave_dns_friend
|
||||
|
||||
public = []
|
||||
sources = [
|
||||
@@ -205,6 +206,7 @@ source_set("host_resolver") {
|
||||
# wrapper.
|
||||
"//services/proxy_resolver/*",
|
||||
]
|
||||
+ friend += brave_dns_friend
|
||||
|
||||
sources = []
|
||||
public = []
|
||||
@@ -309,6 +311,7 @@ source_set("dns_client") {
|
||||
"//net/*",
|
||||
"//services/network/*",
|
||||
]
|
||||
+ friend += brave_dns_friend
|
||||
|
||||
sources = []
|
||||
public = []
|
||||
@@ -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(
|
||||
@@ -17,6 +17,7 @@ import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
|
||||
import("//brave/components/ipfs/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("//brave/test/testing.gni")
|
||||
import("//chrome/common/features.gni")
|
||||
import("//components/gcm_driver/config.gni")
|
||||
@@ -200,6 +201,10 @@ test("brave_unit_tests") {
|
||||
"//services/preferences/public/cpp",
|
||||
]
|
||||
|
||||
if (unstoppable_domains_enabled) {
|
||||
deps += [ "//brave/browser/unstoppable_domains/test:unit_tests" ]
|
||||
}
|
||||
|
||||
if (toolkit_views) {
|
||||
deps += [ "//chrome/browser/ui/views" ]
|
||||
}
|
||||
@@ -629,6 +634,10 @@ if (!is_android) {
|
||||
"//testing/gmock",
|
||||
]
|
||||
|
||||
if (unstoppable_domains_enabled) {
|
||||
deps += [ "//brave/browser/unstoppable_domains/test:browser_tests" ]
|
||||
}
|
||||
|
||||
if (enable_brave_perf_predictor) {
|
||||
sources += [ "//brave/components/brave_perf_predictor/browser/perf_predictor_tab_helper_browsertest.cc" ]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user