Android build for ungoogled-chromium. https://uc.droidware.info
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

517 lines
22 KiB

From: csagan5 <[email protected]>
Date: Sat, 23 Nov 2019 10:55:16 +0100
Subject: Add user setting for DNS-over-HTTPS (DoH) custom URL
---
chrome/android/chrome_java_resources.gni | 2
chrome/android/chrome_java_sources.gni | 2
chrome/android/java/res/layout/doh_editor.xml | 65 +++++++
chrome/android/java/res/values/values.xml | 2
chrome/android/java/res/xml/doh_preferences.xml | 25 ++
chrome/android/java/res/xml/privacy_preferences.xml | 5
chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java | 92 ++++++++++
chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java | 54 +++++
chrome/app/generated_resources.grd | 6
chrome/browser/flags/android/cached_feature_flags.cc | 25 ++
chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/CachedFeatureFlags.java | 24 ++
chrome/browser/net/stub_resolver_config_reader.cc | 36 ---
chrome/browser/ui/android/strings/android_chrome_strings.grd | 11 +
chrome/common/chrome_features.cc | 4
14 files changed, 322 insertions(+), 31 deletions(-)
create mode 100644 chrome/android/java/res/layout/doh_editor.xml
create mode 100644 chrome/android/java/res/xml/doh_preferences.xml
create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java
create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java
--- a/chrome/android/chrome_java_resources.gni
+++ b/chrome/android/chrome_java_resources.gni
@@ -953,6 +953,7 @@ chrome_java_resources = [
"java/res/layout/device_item_list.xml",
"java/res/layout/distilled_page_font_family_spinner.xml",
"java/res/layout/distilled_page_prefs_view.xml",
+ "java/res/layout/doh_editor.xml",
"java/res/layout/edit_url_suggestion_layout.xml",
"java/res/layout/editable_option_editor_footer.xml",
"java/res/layout/editable_option_editor_icons.xml",
@@ -1184,6 +1185,7 @@ chrome_java_resources = [
"java/res/xml/data_reduction_preferences.xml",
"java/res/xml/data_reduction_preferences_off_lite_mode.xml",
"java/res/xml/developer_preferences.xml",
+ "java/res/xml/doh_preferences.xml",
"java/res/xml/do_not_track_preferences.xml",
"java/res/xml/google_services_preferences.xml",
"java/res/xml/homepage_preferences.xml",
--- a/chrome/android/chrome_java_sources.gni
+++ b/chrome/android/chrome_java_sources.gni
@@ -1370,6 +1370,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/searchwidget/SearchWidgetProvider.java",
"java/src/org/chromium/chrome/browser/send_tab_to_self/DevicePickerBottomSheetAdapter.java",
"java/src/org/chromium/chrome/browser/send_tab_to_self/DevicePickerBottomSheetContent.java",
+ "java/src/org/chromium/chrome/browser/settings/DoHEditor.java",
+ "java/src/org/chromium/chrome/browser/settings/DoHPreferences.java",
"java/src/org/chromium/chrome/browser/send_tab_to_self/NotificationManager.java",
"java/src/org/chromium/chrome/browser/send_tab_to_self/NotificationSharedPrefManager.java",
"java/src/org/chromium/chrome/browser/send_tab_to_self/SendTabToSelfAndroidBridge.java",
--- /dev/null
+++ b/chrome/android/java/res/layout/doh_editor.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2015 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. -->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/scroll_view"
+ android:fillViewport="true" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:focusableInTouchMode="true" >
+
+ <com.google.android.material.textfield.TextInputLayout
+ android:id="@+id/doh_url"
+ style="@style/PreferenceScreenLayout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+ <!-- TODO(crbug.com/900912): Fix and remove lint ignore -->
+ <EditText
+ tools:ignore="Autofill"
+ android:id="@+id/doh_url_edit"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textUri"
+ android:singleLine="true"
+ android:hint="@string/options_doh_edit_label" />
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <Space style="@style/ButtonBarTopSpacer" />
+ <View style="@style/ButtonBarTopDivider" />
+
+ <LinearLayout style="@style/ButtonBar" >
+ <org.chromium.ui.widget.ButtonCompat
+ android:id="@+id/doh_reset"
+ style="@style/ButtonBarButton"
+ android:text="@string/reset" />
+
+ <org.chromium.ui.widget.ButtonCompat
+ android:id="@+id/doh_cancel"
+ style="@style/ButtonBarButton"
+ android:text="@string/cancel" />
+
+ <org.chromium.ui.widget.ButtonCompat
+ android:id="@+id/doh_save"
+ style="@style/ButtonBarButton"
+ android:text="@string/save" />
+ </LinearLayout>
+ </LinearLayout>
+ </ScrollView>
+
+ <include layout="@layout/settings_action_bar_shadow"/>
+
+</FrameLayout>
--- a/chrome/android/java/res/values/values.xml
+++ b/chrome/android/java/res/values/values.xml
@@ -72,6 +72,8 @@
<integer name="download_infobar_bar_fill_in_delay">400</integer>
<integer name="download_infobar_bar_fill_out_delay">200</integer>
+ <string name="doh_help_url">https://www.bromite.org/doh</string>
+
<!-- Bottom navigation bar styling. -->
<bool name="window_light_navigation_bar">true</bool>
--- /dev/null
+++ b/chrome/android/java/res/xml/doh_preferences.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2015 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. -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
+ android:key="doh_switch"
+ android:summaryOn="@string/text_on"
+ android:summaryOff="@string/text_off" />
+
+ <org.chromium.chrome.browser.settings.HyperlinkPreference
+ android:key="doh_help"
+ android:title="@string/doh_help"
+ app:url="@string/doh_help_url" />
+
+ <Preference
+ android:key="doh_edit"
+ android:title="@string/options_doh_edit_label"
+ android:fragment="org.chromium.chrome.browser.settings.DoHEditor" />
+
+</PreferenceScreen>
--- a/chrome/android/java/res/xml/privacy_preferences.xml
+++ b/chrome/android/java/res/xml/privacy_preferences.xml
@@ -10,6 +10,11 @@
android:key="can_make_payment"
android:title="@string/can_make_payment_title"
android:summary="@string/settings_can_make_payment_toggle_label" />
+ <Preference
+ android:fragment="org.chromium.chrome.browser.settings.DoHPreferences"
+ android:key="doh"
+ android:title="@string/options_doh_title"
+ android:summary="@string/options_doh_summary" />
<org.chromium.components.browser_ui.settings.ChromeBaseCheckBoxPreference
android:key="preload_pages"
android:title="@string/preload_pages_title"
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java
@@ -0,0 +1,92 @@
+// Copyright 2015 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.
+
+package org.chromium.chrome.browser.settings;
+
+import android.os.Bundle;
+import androidx.fragment.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+import org.chromium.components.browser_ui.settings.SettingsUtils;
+import org.chromium.chrome.browser.flags.CachedFeatureFlags;
+import org.chromium.chrome.R;
+import org.chromium.components.url_formatter.UrlFormatter;
+
+/**
+ * Provides the Java-UI for editing the DNS-over-HTTPS (DoH) preference.
+ */
+public class DoHEditor extends Fragment implements TextWatcher {
+ private EditText mDoHUrlEdit;
+ private Button mSaveButton;
+ private Button mResetButton;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getActivity().setTitle(R.string.options_doh_edit_title);
+
+ View v = inflater.inflate(R.layout.doh_editor, container, false);
+ View scrollView = v.findViewById(R.id.scroll_view);
+ scrollView.getViewTreeObserver().addOnScrollChangedListener(
+ SettingsUtils.getShowShadowOnScrollListener(v, v.findViewById(R.id.shadow)));
+ mDoHUrlEdit = (EditText) v.findViewById(R.id.doh_url_edit);
+ mDoHUrlEdit.setText(CachedFeatureFlags.getDoHTemplates());
+ mDoHUrlEdit.addTextChangedListener(this);
+ mDoHUrlEdit.requestFocus();
+
+ initializeSaveCancelResetButtons(v);
+ return v;
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ mSaveButton.setEnabled(s.length() != 0);
+ mResetButton.setEnabled(true);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+
+ private void initializeSaveCancelResetButtons(View v) {
+ mResetButton = (Button) v.findViewById(R.id.doh_reset);
+ mResetButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mDoHUrlEdit.setText(CachedFeatureFlags.getDoHTemplates());
+ getActivity().finish();
+ }
+ });
+
+ mSaveButton = (Button) v.findViewById(R.id.doh_save);
+ mSaveButton.setEnabled(false);
+ mSaveButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ CachedFeatureFlags.setDoHTemplates(
+ mDoHUrlEdit.getText().toString());
+ getActivity().finish();
+ }
+ });
+
+ Button button = (Button) v.findViewById(R.id.doh_cancel);
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+ }
+}
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java
@@ -0,0 +1,54 @@
+// Copyright 2015 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.
+
+package org.chromium.chrome.browser.settings;
+
+import android.os.Bundle;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
+
+import org.chromium.components.browser_ui.settings.SettingsUtils;
+import org.chromium.chrome.browser.flags.CachedFeatureFlags;
+import androidx.annotation.VisibleForTesting;
+import org.chromium.chrome.R;
+
+/**
+ * Fragment that allows the user to configure DoH related preferences.
+ */
+public class DoHPreferences extends PreferenceFragmentCompat {
+ @VisibleForTesting
+ public static final String PREF_DOH_SWITCH = "doh_switch";
+ private static final String PREF_DOH_EDIT = "doh_edit";
+
+ private Preference mDoHEdit;
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ getActivity().setTitle(R.string.options_doh_title);
+ SettingsUtils.addPreferencesFromResource(this, R.xml.doh_preferences);
+
+ ChromeSwitchPreference mDoHSwitch =
+ (ChromeSwitchPreference) findPreference(PREF_DOH_SWITCH);
+ boolean isDoHEnabled = CachedFeatureFlags.getDoHEnabled();
+ mDoHSwitch.setChecked(isDoHEnabled);
+ mDoHSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ CachedFeatureFlags.setDoHEnabled((boolean) newValue);
+ return true;
+ });
+
+ mDoHEdit = findPreference(PREF_DOH_EDIT);
+ updateCurrentDoHUrl();
+ }
+
+ private void updateCurrentDoHUrl() {
+ mDoHEdit.setSummary(CachedFeatureFlags.getDoHTemplates());
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateCurrentDoHUrl();
+ }
+}
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6912,6 +6912,12 @@ the Bookmarks menu.">
</if>
<if expr="is_android">
+ <message name="IDS_OPTIONS_DOH_TITLE" desc="The title of the DNS-over-HTTPS option on Android" formatter_data="android_java">
+ Secure DNS
+ </message>
+ <message name="IDS_OPTIONS_DOH_SUMMARY" desc="The title of the DNS-over-HTTPS summary on Android" formatter_data="android_java">
+ Configure DNS-over-HTTPS (DoH) secure DNS
+ </message>
<message name="IDS_OPTIONS_HOMEPAGE_TITLE" desc="The title of Chrome's homepage setting screen on Android. " formatter_data="android_java">
Homepage
</message>
--- a/chrome/browser/flags/android/cached_feature_flags.cc
+++ b/chrome/browser/flags/android/cached_feature_flags.cc
@@ -11,6 +11,10 @@
#include "content/public/common/content_features.h"
#include "content/public/common/network_service_util.h"
+#include "chrome/browser/browser_process.h"
+#include "components/prefs/pref_service.h"
+#include "chrome/common/pref_names.h"
+
using base::android::ConvertJavaStringToUTF8;
using base::android::ConvertUTF8ToJavaString;
using base::android::JavaParamRef;
@@ -41,3 +45,24 @@ static jboolean JNI_CachedFeatureFlags_I
return content::IsOutOfProcessNetworkService() &&
base::FeatureList::IsEnabled(features::kWarmUpNetworkProcess);
}
+
+static jboolean JNI_CachedFeatureFlags_GetDoHEnabled(JNIEnv* env) {
+ std::string doh_mode = g_browser_process->local_state()->GetString(prefs::kDnsOverHttpsMode);
+ return ((doh_mode == "secure") || (doh_mode == "auto"))
+ && !g_browser_process->local_state()->GetString(prefs::kDnsOverHttpsTemplates).empty();
+}
+
+static void JNI_CachedFeatureFlags_SetDoHEnabled(JNIEnv* env, jboolean enabled) {
+ if (enabled)
+ g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsMode, "secure");
+ else
+ g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsMode, "off");
+}
+
+static ScopedJavaLocalRef<jstring> JNI_CachedFeatureFlags_GetDoHTemplates(JNIEnv* env) {
+ return base::android::ConvertUTF8ToJavaString(env, g_browser_process->local_state()->GetString(prefs::kDnsOverHttpsTemplates));
+}
+
+static void JNI_CachedFeatureFlags_SetDoHTemplates(JNIEnv* env, const JavaParamRef<jstring>& templates) {
+ g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsTemplates, base::android::ConvertJavaStringToUTF8(env, templates));
+}
--- a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/CachedFeatureFlags.java
+++ b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/CachedFeatureFlags.java
@@ -127,6 +127,26 @@ public class CachedFeatureFlags {
private static Map<String, String> sOverridesTestFeatures;
private static String sReachedCodeProfilerTrialGroup;
+ /**
+ * Records whether custom URL for DoH is enabled with native-side feature utilities.
+ * @param url Whether custom URL is enabled or not.
+ */
+ public static void setDoHEnabled(boolean enabled) {
+ CachedFeatureFlagsJni.get().setDoHEnabled(enabled);
+ }
+
+ public static boolean getDoHEnabled() {
+ return CachedFeatureFlagsJni.get().getDoHEnabled();
+ }
+
+ public static void setDoHTemplates(String t) {
+ CachedFeatureFlagsJni.get().setDoHTemplates(t);
+ }
+
+ public static String getDoHTemplates() {
+ return CachedFeatureFlagsJni.get().getDoHTemplates();
+ }
+
/**
* Checks if a cached feature flag is enabled.
*
@@ -401,6 +421,10 @@ public class CachedFeatureFlags {
@NativeMethods
interface Natives {
+ void setDoHEnabled(boolean enabled);
+ boolean getDoHEnabled();
+ void setDoHTemplates(String templates);
+ String getDoHTemplates();
boolean isNetworkServiceWarmUpEnabled();
}
}
--- a/chrome/browser/net/stub_resolver_config_reader.cc
+++ b/chrome/browser/net/stub_resolver_config_reader.cc
@@ -140,28 +140,6 @@ StubResolverConfigReader::StubResolverCo
base::Value(SecureDnsConfig::ModeToString(default_secure_dns_mode)));
local_state_->SetDefaultPrefValue(prefs::kDnsOverHttpsTemplates,
base::Value(default_doh_templates));
-
- // If the user has explicitly enabled or disabled the DoH experiment in
- // chrome://flags and the DoH UI setting is not visible, store that choice
- // in the user prefs so that it can be persisted after the experiment ends.
- // Also make sure to remove the stored prefs value if the user has changed
- // their chrome://flags selection to the default.
- if (!features::kDnsOverHttpsShowUiParam.Get()) {
- flags_ui::PrefServiceFlagsStorage flags_storage(local_state_);
- std::set<std::string> entries = flags_storage.GetFlags();
- if (entries.count("[email protected]")) {
- // The user has "Enabled" selected.
- local_state_->SetString(prefs::kDnsOverHttpsMode,
- SecureDnsConfig::kModeAutomatic);
- } else if (entries.count("[email protected]")) {
- // The user has "Disabled" selected.
- local_state_->SetString(prefs::kDnsOverHttpsMode,
- SecureDnsConfig::kModeOff);
- } else {
- // The user has "Default" selected.
- local_state_->ClearPref(prefs::kDnsOverHttpsMode);
- }
- }
}
pref_change_registrar_.Add(prefs::kBuiltInDnsClientEnabled, pref_callback);
@@ -323,21 +301,21 @@ SecureDnsConfig StubResolverConfigReader
parental_controls_checked_ = true;
}
- if (record_metrics) {
- UMA_HISTOGRAM_ENUMERATION("Net.DNS.DnsConfig.SecureDnsMode", mode_details);
- }
-
std::string doh_templates =
local_state_->GetString(prefs::kDnsOverHttpsTemplates);
- std::string server_method;
+ if (doh_templates.empty()) {
+ secure_dns_mode = net::DnsConfig::SecureDnsMode::OFF;
+ }
+ LOG(INFO) << "DoH templates: '" << doh_templates << "' with mode " << SecureDnsConfig::ModeToString(secure_dns_mode);
std::vector<net::DnsOverHttpsServerConfig> dns_over_https_servers;
base::Optional<std::vector<network::mojom::DnsOverHttpsServerPtr>>
servers_mojo;
- if (!doh_templates.empty() &&
- secure_dns_mode != net::DnsConfig::SecureDnsMode::OFF) {
+ if (secure_dns_mode != net::DnsConfig::SecureDnsMode::OFF) {
+ std::string server_method;
for (base::StringPiece server_template :
chrome_browser_net::secure_dns::SplitGroup(doh_templates)) {
if (!net::dns_util::IsValidDohTemplate(server_template, &server_method)) {
+ LOG(WARNING) << "DoH templates: skipping invalid: '" << server_template << "'";
continue;
}
--- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
+++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
@@ -599,6 +599,17 @@ CHAR-LIMIT guidelines:
Chrome Passwords
</message>
+ <!-- DoH preferences -->
+ <message name="IDS_OPTIONS_DOH_EDIT_TITLE" desc="The title of the screen that allows users to change the URL that is used for DNS-over-HTTPS queries.">
+ Edit DoH template URLs
+ </message>
+ <message name="IDS_OPTIONS_DOH_EDIT_LABEL" desc="The label for the edit text field that allows the user to change the URL that is used for DNS-over-HTTPS queries.">
+ DoH template URLs
+ </message>
+ <message name="IDS_DOH_HELP" desc="The title of the hyperlink that allows users to visit the wiki page with instructions for DNS-over-HTTPS configuration.">
+ Visit help page
+ </message>
+
<!-- Homepage preferences -->
<message name="IDS_OPTIONS_HOMEPAGE_EDIT_HINT" desc="Hint for the text edit on Homepage Preference setting, guiding user to enter their customized homepage setting">
Enter custom web address
--- a/chrome/common/chrome_features.cc
+++ b/chrome/common/chrome_features.cc
@@ -281,12 +281,12 @@ const base::Feature kDefaultWebAppInstal
// Enable DNS over HTTPS (DoH).
const base::Feature kDnsOverHttps{"DnsOverHttps",
- base::FEATURE_DISABLED_BY_DEFAULT};
+ base::FEATURE_ENABLED_BY_DEFAULT};
// Set whether fallback to insecure DNS is allowed by default. This setting may
// be overridden for individual transactions.
const base::FeatureParam<bool> kDnsOverHttpsFallbackParam{&kDnsOverHttps,
- "Fallback", true};
+ "Fallback", false};
// Supply one or more space-separated DoH server URI templates to use when this
// feature is enabled. If no templates are specified, then a hardcoded mapping