blob: dddaea2127a5d6ddf58bfd3adc0dc73425cc5528 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/macros.h"
#include "base/values.h"
#include "chrome/browser/net/dns_probe_runner.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "components/prefs/pref_change_registrar.h"
#include "net/dns/public/doh_provider_entry.h"
#include "services/network/public/cpp/resolve_host_client_base.h"
#include "services/network/public/mojom/network_context.mojom.h"
namespace settings {
// Handler for the Secure DNS setting.
class SecureDnsHandler : public SettingsPageUIHandler {
~SecureDnsHandler() override;
// SettingsPageUIHandler:
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
// Get the list of dropdown resolver options. Each option is represented
// as a dictionary with the following keys: "name" (the text to display in the
// UI), "value" (the DoH template for this provider), and "policy" (the URL of
// the provider's privacy policy).
base::Value GetSecureDnsResolverList();
void SetNetworkContextForTesting(
network::mojom::NetworkContext* network_context);
// DohProviderEntry cannot be copied, so the entries referenced in |providers|
// must be long-lived.
void SetProvidersForTesting(net::DohProviderEntry::List providers);
// Retrieves all pre-approved secure resolvers and returns them to WebUI.
void HandleGetSecureDnsResolverList(const base::ListValue* args);
// Intended to be called once upon creation of the secure DNS setting.
void HandleGetSecureDnsSetting(const base::ListValue* args);
// Parses a custom entry into templates, if they are all valid.
void HandleParseCustomDnsEntry(const base::ListValue* args);
// Returns whether or not a test query to the resolver succeeds.
void HandleProbeCustomDnsTemplate(const base::ListValue* args);
// Records metrics on the user-initiated dropdown selection event.
void HandleRecordUserDropdownInteraction(const base::ListValue* args);
// Retrieves the current host resolver configuration, computes the
// corresponding UI representation, and sends it to javascript.
void SendSecureDnsSettingUpdatesToJavascript();
network::mojom::NetworkContext* GetNetworkContext();
void OnProbeComplete();
static net::DohProviderEntry::List GetFilteredProviders();
net::DohProviderEntry::List providers_ = GetFilteredProviders();
std::unique_ptr<chrome_browser_net::DnsProbeRunner> runner_;
network_context_getter_ =
// ID of the Javascript callback for the current pending probe, or "" if
// there is no probe currently in progress.
std::string probe_callback_id_;
PrefChangeRegistrar pref_registrar_;
} // namespace settings