Skip to content

Commit

Permalink
Uplift of #8317 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases committed Mar 23, 2021
1 parent 7653bde commit ad63c8b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cr.define('settings', function () {
isWidevineEnabled() {}
getRestartNeeded () {}
wasSignInEnabledAtStartup () {}
isDecentralizedDnsEnabled() {}
getDecentralizedDnsResolveMethodList() {}
}

/**
Expand Down Expand Up @@ -71,6 +73,10 @@ cr.define('settings', function () {
isDecentralizedDnsEnabled () {
return cr.sendWithPromise('isDecentralizedDnsEnabled')
}

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

cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@
<div class="start">$i18n{resolveUnstoppableDomainsDesc}</div>
<settings-dropdown-menu id="unstoppableDomainsResolveMethodType"
pref="{{prefs.brave.unstoppable_domains.resolve_method}}"
menu-options="[[unstoppableDomainsResolveMethod_]]">
menu-options="[[decentralizedDnsResolveMethod_]]">
</div>
<div class="settings-box">
<div class="start">$i18n{resolveENSDesc}</div>
<settings-dropdown-menu id="ensResolveMethodType"
pref="{{prefs.brave.ens.resolve_method}}"
menu-options="[[ensResolveMethod_]]">
menu-options="[[decentralizedDnsResolveMethod_]]">
</div>
</template>
<settings-toggle-button id="mediaRouterEnabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,7 @@ Polymer({
widevineEnabled_: Boolean,
disableTorOption_: Boolean,
decentralizedDnsEnabled_: Boolean,
unstoppableDomainsResolveMethod_: {
readOnly: true,
type: Array,
value() {
return [
{value:0, name: "Ask"},
{value:1, name: "Disabled"},
{value:2, name: "Public DNS over HTTPS server"},
];
},
},
ensResolveMethod_: {
readOnly: true,
type: Array,
value() {
return [
{value:0, name: "Ask"},
{value:1, name: "Disabled"},
{value:2, name: "Public DNS over HTTPS server"},
];
},
},
decentralizedDnsResolveMethod_: Array,
},

/** @private {?settings.BraveDefaultExtensionsBrowserProxy} */
Expand Down Expand Up @@ -88,7 +67,10 @@ Polymer({
})
this.browserProxy_.isDecentralizedDnsEnabled().then(enabled => {
this.decentralizedDnsEnabled_ = enabled
});
})
this.browserProxy_.getDecentralizedDnsResolveMethodList().then(list => {
this.decentralizedDnsResolveMethod_ = list
})
},

onWebTorrentEnabledChange_: function() {
Expand Down
18 changes: 18 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
base::BindRepeating(
&BraveDefaultExtensionsHandler::IsDecentralizedDnsEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getDecentralizedDnsResolveMethodList",
base::BindRepeating(
&BraveDefaultExtensionsHandler::GetDecentralizedDnsResolveMethodList,
base::Unretained(this)));

// Can't call this in ctor because it needs to access web_ui().
InitializePrefCallbacks();
Expand Down Expand Up @@ -443,3 +448,16 @@ void BraveDefaultExtensionsHandler::IsDecentralizedDnsEnabled(
base::Value(false));
#endif
}

void BraveDefaultExtensionsHandler::GetDecentralizedDnsResolveMethodList(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
AllowJavascript();

ResolveJavascriptCallback(args->GetList()[0],
#if BUILDFLAG(DECENTRALIZED_DNS_ENABLED)
decentralized_dns::GetResolveMethodList());
#else
base::Value(base::Value::Type::LIST));
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
void IsWidevineEnabled(const base::ListValue* args);
void OnWidevineEnabledChanged();
void IsDecentralizedDnsEnabled(const base::ListValue* args);
void GetDecentralizedDnsResolveMethodList(const base::ListValue* args);

void InitializePrefCallbacks();

Expand Down
1 change: 1 addition & 0 deletions components/decentralized_dns/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ source_set("decentralized_dns") {
"//components/user_prefs",
"//content/public/browser",
"//net",
"//ui/base",
"//url",
]
}
31 changes: 31 additions & 0 deletions components/decentralized_dns/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@

#include "base/feature_list.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "brave/components/decentralized_dns/constants.h"
#include "brave/components/decentralized_dns/features.h"
#include "brave/components/decentralized_dns/pref_names.h"
#include "brave/net/decentralized_dns/constants.h"
#include "components/grit/brave_components_strings.h"
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"

namespace decentralized_dns {

namespace {

base::Value MakeSelectValue(ResolveMethodTypes value,
const base::string16& name) {
base::Value item(base::Value::Type::DICTIONARY);
item.SetKey("value", base::Value(static_cast<int>(value)));
item.SetKey("name", base::Value(name));
return item;
}

} // namespace

bool IsDecentralizedDnsEnabled() {
return base::FeatureList::IsEnabled(features::kDecentralizedDns);
}
Expand Down Expand Up @@ -64,4 +79,20 @@ bool IsENSResolveMethodDoH(PrefService* local_state) {
static_cast<int>(ResolveMethodTypes::DNS_OVER_HTTPS);
}

base::Value GetResolveMethodList() {
base::Value list(base::Value::Type::LIST);
list.Append(MakeSelectValue(
ResolveMethodTypes::ASK,
l10n_util::GetStringUTF16(IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_ASK)));
list.Append(
MakeSelectValue(ResolveMethodTypes::DISABLED,
l10n_util::GetStringUTF16(
IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_DISABLED)));
list.Append(MakeSelectValue(
ResolveMethodTypes::DNS_OVER_HTTPS,
l10n_util::GetStringUTF16(
IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_DNS_OVER_HTTPS)));
return list;
}

} // namespace decentralized_dns
6 changes: 6 additions & 0 deletions components/decentralized_dns/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
class GURL;
class PrefService;

namespace base {
class Value;
}

namespace decentralized_dns {

bool IsDecentralizedDnsEnabled();
Expand All @@ -21,6 +25,8 @@ bool IsENSTLD(const GURL& url);
bool IsENSResolveMethodAsk(PrefService* local_state);
bool IsENSResolveMethodDoH(PrefService* local_state);

base::Value GetResolveMethodList();

} // namespace decentralized_dns

#endif // BRAVE_COMPONENTS_DECENTRALIZED_DNS_UTILS_H_
9 changes: 9 additions & 0 deletions components/resources/decentralized_dns_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_DONT_PROCEED_BUTTON" desc="The text for the don't proceed button in decentralized DNS opt-in interstitial page.">
Disable
</message>
<message name="IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_ASK" desc="Select control value for which decentralized DNS resolve method to use">
Ask
</message>
<message name="IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_DISABLED" desc="Select control value for which decentralized DNS resolve method to use">
Disabled
</message>
<message name="IDS_DECENTRALIZED_DNS_RESOLVE_OPTION_DNS_OVER_HTTPS" desc="Select control value for which decentralized DNS resolve method to use">
DNS over HTTPS
</message>
</if>
</grit-part>

0 comments on commit ad63c8b

Please sign in to comment.