Add-user-setting-for-DNS-over-HTTPS-DoH-custom-URL.patch 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sat, 23 Nov 2019 10:55:16 +0100
  3. Subject: Add user setting for DNS-over-HTTPS (DoH) custom URL
  4. ---
  5. chrome/android/chrome_java_sources.gni | 2 +
  6. chrome/android/java/res/layout/doh_editor.xml | 65 +++++++++++++
  7. chrome/android/java/res/values/values.xml | 2 +
  8. .../android/java/res/xml/doh_preferences.xml | 25 +++++
  9. .../java/res/xml/privacy_preferences.xml | 5 +
  10. .../browser/flags/FeatureUtilities.java | 24 +++++
  11. .../chrome/browser/settings/DoHEditor.java | 92 +++++++++++++++++++
  12. .../browser/settings/DoHPreferences.java | 54 +++++++++++
  13. chrome/app/generated_resources.grd | 6 ++
  14. chrome/browser/android/feature_utilities.cc | 23 +++++
  15. .../net/system_network_context_manager.cc | 41 ++-------
  16. .../strings/android_chrome_strings.grd | 11 +++
  17. chrome/common/chrome_features.cc | 4 +-
  18. 13 files changed, 320 insertions(+), 34 deletions(-)
  19. create mode 100644 chrome/android/java/res/layout/doh_editor.xml
  20. create mode 100644 chrome/android/java/res/xml/doh_preferences.xml
  21. create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java
  22. create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java
  23. diff --git a/chrome/android/chrome_java_sources.gni b/chrome/android/chrome_java_sources.gni
  24. --- a/chrome/android/chrome_java_sources.gni
  25. +++ b/chrome/android/chrome_java_sources.gni
  26. @@ -1335,6 +1335,8 @@ chrome_java_sources = [
  27. "java/src/org/chromium/chrome/browser/searchwidget/SearchWidgetProvider.java",
  28. "java/src/org/chromium/chrome/browser/send_tab_to_self/DevicePickerBottomSheetAdapter.java",
  29. "java/src/org/chromium/chrome/browser/send_tab_to_self/DevicePickerBottomSheetContent.java",
  30. + "java/src/org/chromium/chrome/browser/settings/DoHEditor.java",
  31. + "java/src/org/chromium/chrome/browser/settings/DoHPreferences.java",
  32. "java/src/org/chromium/chrome/browser/send_tab_to_self/NotificationManager.java",
  33. "java/src/org/chromium/chrome/browser/send_tab_to_self/NotificationSharedPrefManager.java",
  34. "java/src/org/chromium/chrome/browser/send_tab_to_self/SendTabToSelfAndroidBridge.java",
  35. diff --git a/chrome/android/java/res/layout/doh_editor.xml b/chrome/android/java/res/layout/doh_editor.xml
  36. new file mode 100644
  37. --- /dev/null
  38. +++ b/chrome/android/java/res/layout/doh_editor.xml
  39. @@ -0,0 +1,65 @@
  40. +<?xml version="1.0" encoding="utf-8"?>
  41. +<!-- Copyright 2015 The Chromium Authors. All rights reserved.
  42. + Use of this source code is governed by a BSD-style license that can be
  43. + found in the LICENSE file. -->
  44. +
  45. +<FrameLayout
  46. + xmlns:android="http://schemas.android.com/apk/res/android"
  47. + xmlns:app="http://schemas.android.com/apk/res-auto"
  48. + xmlns:tools="http://schemas.android.com/tools"
  49. + android:layout_width="match_parent"
  50. + android:layout_height="match_parent" >
  51. +
  52. + <ScrollView
  53. + android:layout_width="match_parent"
  54. + android:layout_height="match_parent"
  55. + android:id="@+id/scroll_view"
  56. + android:fillViewport="true" >
  57. +
  58. + <LinearLayout
  59. + android:layout_width="match_parent"
  60. + android:layout_height="wrap_content"
  61. + android:orientation="vertical"
  62. + android:focusableInTouchMode="true" >
  63. +
  64. + <org.chromium.components.browser_ui.widget.text.ChromeTextInputLayout
  65. + android:id="@+id/doh_url"
  66. + style="@style/PreferenceScreenLayout"
  67. + android:layout_width="match_parent"
  68. + android:layout_height="wrap_content" >
  69. + <!-- TODO(crbug.com/900912): Fix and remove lint ignore -->
  70. + <EditText
  71. + tools:ignore="Autofill"
  72. + android:id="@+id/doh_url_edit"
  73. + android:layout_width="match_parent"
  74. + android:layout_height="wrap_content"
  75. + android:inputType="textUri"
  76. + android:singleLine="true"
  77. + android:hint="@string/options_doh_edit_label" />
  78. + </org.chromium.components.browser_ui.widget.text.ChromeTextInputLayout>
  79. +
  80. + <Space style="@style/ButtonBarTopSpacer" />
  81. + <View style="@style/ButtonBarTopDivider" />
  82. +
  83. + <LinearLayout style="@style/ButtonBar" >
  84. + <org.chromium.ui.widget.ButtonCompat
  85. + android:id="@+id/doh_reset"
  86. + style="@style/ButtonBarButton"
  87. + android:text="@string/reset" />
  88. +
  89. + <org.chromium.ui.widget.ButtonCompat
  90. + android:id="@+id/doh_cancel"
  91. + style="@style/ButtonBarButton"
  92. + android:text="@string/cancel" />
  93. +
  94. + <org.chromium.ui.widget.ButtonCompat
  95. + android:id="@+id/doh_save"
  96. + style="@style/ButtonBarButton"
  97. + android:text="@string/save" />
  98. + </LinearLayout>
  99. + </LinearLayout>
  100. + </ScrollView>
  101. +
  102. + <include layout="@layout/settings_action_bar_shadow"/>
  103. +
  104. +</FrameLayout>
  105. diff --git a/chrome/android/java/res/values/values.xml b/chrome/android/java/res/values/values.xml
  106. --- a/chrome/android/java/res/values/values.xml
  107. +++ b/chrome/android/java/res/values/values.xml
  108. @@ -86,6 +86,8 @@
  109. <integer name="download_infobar_bar_fill_in_delay">400</integer>
  110. <integer name="download_infobar_bar_fill_out_delay">200</integer>
  111. + <string name="doh_help_url">https://www.bromite.org/doh</string>
  112. +
  113. <!-- Bottom navigation bar styling. -->
  114. <bool name="window_light_navigation_bar">true</bool>
  115. diff --git a/chrome/android/java/res/xml/doh_preferences.xml b/chrome/android/java/res/xml/doh_preferences.xml
  116. new file mode 100644
  117. --- /dev/null
  118. +++ b/chrome/android/java/res/xml/doh_preferences.xml
  119. @@ -0,0 +1,25 @@
  120. +<?xml version="1.0" encoding="utf-8"?>
  121. +<!-- Copyright 2015 The Chromium Authors. All rights reserved.
  122. + Use of this source code is governed by a BSD-style license that can be
  123. + found in the LICENSE file. -->
  124. +
  125. +<PreferenceScreen
  126. + xmlns:android="http://schemas.android.com/apk/res/android"
  127. + xmlns:app="http://schemas.android.com/apk/res-auto">
  128. +
  129. + <org.chromium.chrome.browser.settings.ChromeSwitchPreference
  130. + android:key="doh_switch"
  131. + android:summaryOn="@string/text_on"
  132. + android:summaryOff="@string/text_off" />
  133. +
  134. + <org.chromium.chrome.browser.settings.HyperlinkPreference
  135. + android:key="doh_help"
  136. + android:title="@string/doh_help"
  137. + app:url="@string/doh_help_url" />
  138. +
  139. + <Preference
  140. + android:key="doh_edit"
  141. + android:title="@string/options_doh_edit_label"
  142. + android:fragment="org.chromium.chrome.browser.settings.DoHEditor" />
  143. +
  144. +</PreferenceScreen>
  145. diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
  146. --- a/chrome/android/java/res/xml/privacy_preferences.xml
  147. +++ b/chrome/android/java/res/xml/privacy_preferences.xml
  148. @@ -19,6 +19,11 @@
  149. android:key="can_make_payment"
  150. android:title="@string/can_make_payment_title"
  151. android:summary="@string/settings_can_make_payment_toggle_label" />
  152. + <Preference
  153. + android:fragment="org.chromium.chrome.browser.settings.DoHPreferences"
  154. + android:key="doh"
  155. + android:title="@string/options_doh_title"
  156. + android:summary="@string/options_doh_summary" />
  157. <org.chromium.chrome.browser.settings.ChromeBaseCheckBoxPreference
  158. android:key="preload_pages"
  159. android:title="@string/preload_pages_title"
  160. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/flags/FeatureUtilities.java b/chrome/android/java/src/org/chromium/chrome/browser/flags/FeatureUtilities.java
  161. --- a/chrome/android/java/src/org/chromium/chrome/browser/flags/FeatureUtilities.java
  162. +++ b/chrome/android/java/src/org/chromium/chrome/browser/flags/FeatureUtilities.java
  163. @@ -120,6 +120,26 @@ public class FeatureUtilities {
  164. private static Boolean sEnabledTabThumbnailApsectRatioForTesting;
  165. private static final String ALLOW_TO_REFETCH = "allow_to_refetch";
  166. + /**
  167. + * Records whether custom URL for DoH is enabled with native-side feature utilities.
  168. + * @param url Whether custom URL is enabled or not.
  169. + */
  170. + public static void setDoHEnabled(boolean enabled) {
  171. + FeatureUtilitiesJni.get().setDoHEnabled(enabled);
  172. + }
  173. +
  174. + public static boolean getDoHEnabled() {
  175. + return FeatureUtilitiesJni.get().getDoHEnabled();
  176. + }
  177. +
  178. + public static void setDoHTemplates(String t) {
  179. + FeatureUtilitiesJni.get().setDoHTemplates(t);
  180. + }
  181. +
  182. + public static String getDoHTemplates() {
  183. + return FeatureUtilitiesJni.get().getDoHTemplates();
  184. + }
  185. +
  186. /**
  187. * Checks if a cached feature flag is enabled.
  188. *
  189. @@ -792,6 +812,10 @@ public class FeatureUtilities {
  190. @NativeMethods
  191. interface Natives {
  192. + void setDoHEnabled(boolean enabled);
  193. + boolean getDoHEnabled();
  194. + void setDoHTemplates(String templates);
  195. + String getDoHTemplates();
  196. boolean isNetworkServiceWarmUpEnabled();
  197. void setAdBlockFiltersURL(String url);
  198. String getAdBlockFiltersURL();
  199. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java
  200. new file mode 100644
  201. --- /dev/null
  202. +++ b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHEditor.java
  203. @@ -0,0 +1,92 @@
  204. +// Copyright 2015 The Chromium Authors. All rights reserved.
  205. +// Use of this source code is governed by a BSD-style license that can be
  206. +// found in the LICENSE file.
  207. +
  208. +package org.chromium.chrome.browser.settings;
  209. +
  210. +import android.os.Bundle;
  211. +import android.support.v4.app.Fragment;
  212. +import android.text.Editable;
  213. +import android.text.TextWatcher;
  214. +import android.view.LayoutInflater;
  215. +import android.view.View;
  216. +import android.view.ViewGroup;
  217. +import android.widget.Button;
  218. +import android.widget.EditText;
  219. +
  220. +import org.chromium.chrome.browser.settings.SettingsUtils;
  221. +import org.chromium.chrome.browser.flags.FeatureUtilities;
  222. +import org.chromium.chrome.R;
  223. +import org.chromium.components.url_formatter.UrlFormatter;
  224. +
  225. +/**
  226. + * Provides the Java-UI for editing the DNS-over-HTTPS (DoH) preference.
  227. + */
  228. +public class DoHEditor extends Fragment implements TextWatcher {
  229. + private EditText mDoHUrlEdit;
  230. + private Button mSaveButton;
  231. + private Button mResetButton;
  232. +
  233. + @Override
  234. + public View onCreateView(LayoutInflater inflater, ViewGroup container,
  235. + Bundle savedInstanceState) {
  236. + super.onCreate(savedInstanceState);
  237. + getActivity().setTitle(R.string.options_doh_edit_title);
  238. +
  239. + View v = inflater.inflate(R.layout.doh_editor, container, false);
  240. + View scrollView = v.findViewById(R.id.scroll_view);
  241. + scrollView.getViewTreeObserver().addOnScrollChangedListener(
  242. + SettingsUtils.getShowShadowOnScrollListener(v, v.findViewById(R.id.shadow)));
  243. + mDoHUrlEdit = (EditText) v.findViewById(R.id.doh_url_edit);
  244. + mDoHUrlEdit.setText(FeatureUtilities.getDoHTemplates());
  245. + mDoHUrlEdit.addTextChangedListener(this);
  246. + mDoHUrlEdit.requestFocus();
  247. +
  248. + initializeSaveCancelResetButtons(v);
  249. + return v;
  250. + }
  251. +
  252. + @Override
  253. + public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  254. + }
  255. +
  256. + @Override
  257. + public void onTextChanged(CharSequence s, int start, int before, int count) {
  258. + mSaveButton.setEnabled(s.length() != 0);
  259. + mResetButton.setEnabled(true);
  260. + }
  261. +
  262. + @Override
  263. + public void afterTextChanged(Editable s) {
  264. + }
  265. +
  266. + private void initializeSaveCancelResetButtons(View v) {
  267. + mResetButton = (Button) v.findViewById(R.id.doh_reset);
  268. + mResetButton.setOnClickListener(new View.OnClickListener() {
  269. + @Override
  270. + public void onClick(View v) {
  271. + mDoHUrlEdit.setText(FeatureUtilities.getDoHTemplates());
  272. + getActivity().finish();
  273. + }
  274. + });
  275. +
  276. + mSaveButton = (Button) v.findViewById(R.id.doh_save);
  277. + mSaveButton.setEnabled(false);
  278. + mSaveButton.setOnClickListener(new View.OnClickListener() {
  279. + @Override
  280. + public void onClick(View v) {
  281. + FeatureUtilities.setDoHTemplates(
  282. + mDoHUrlEdit.getText().toString());
  283. + getActivity().finish();
  284. + }
  285. + });
  286. +
  287. + Button button = (Button) v.findViewById(R.id.doh_cancel);
  288. + button.setOnClickListener(new View.OnClickListener() {
  289. + @Override
  290. + public void onClick(View v) {
  291. + getActivity().finish();
  292. + }
  293. + });
  294. + }
  295. +}
  296. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java
  297. new file mode 100644
  298. --- /dev/null
  299. +++ b/chrome/android/java/src/org/chromium/chrome/browser/settings/DoHPreferences.java
  300. @@ -0,0 +1,54 @@
  301. +// Copyright 2015 The Chromium Authors. All rights reserved.
  302. +// Use of this source code is governed by a BSD-style license that can be
  303. +// found in the LICENSE file.
  304. +
  305. +package org.chromium.chrome.browser.settings;
  306. +
  307. +import android.os.Bundle;
  308. +import android.support.v7.preference.Preference;
  309. +import android.support.v7.preference.PreferenceFragmentCompat;
  310. +import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
  311. +
  312. +import org.chromium.chrome.browser.settings.SettingsUtils;
  313. +import org.chromium.chrome.browser.flags.FeatureUtilities;
  314. +import androidx.annotation.VisibleForTesting;
  315. +import org.chromium.chrome.R;
  316. +
  317. +/**
  318. + * Fragment that allows the user to configure DoH related preferences.
  319. + */
  320. +public class DoHPreferences extends PreferenceFragmentCompat {
  321. + @VisibleForTesting
  322. + public static final String PREF_DOH_SWITCH = "doh_switch";
  323. + private static final String PREF_DOH_EDIT = "doh_edit";
  324. +
  325. + private Preference mDoHEdit;
  326. +
  327. + @Override
  328. + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
  329. + getActivity().setTitle(R.string.options_doh_title);
  330. + SettingsUtils.addPreferencesFromResource(this, R.xml.doh_preferences);
  331. +
  332. + ChromeSwitchPreference mDoHSwitch =
  333. + (ChromeSwitchPreference) findPreference(PREF_DOH_SWITCH);
  334. + boolean isDoHEnabled = FeatureUtilities.getDoHEnabled();
  335. + mDoHSwitch.setChecked(isDoHEnabled);
  336. + mDoHSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
  337. + FeatureUtilities.setDoHEnabled((boolean) newValue);
  338. + return true;
  339. + });
  340. +
  341. + mDoHEdit = findPreference(PREF_DOH_EDIT);
  342. + updateCurrentDoHUrl();
  343. + }
  344. +
  345. + private void updateCurrentDoHUrl() {
  346. + mDoHEdit.setSummary(FeatureUtilities.getDoHTemplates());
  347. + }
  348. +
  349. + @Override
  350. + public void onResume() {
  351. + super.onResume();
  352. + updateCurrentDoHUrl();
  353. + }
  354. +}
  355. diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
  356. --- a/chrome/app/generated_resources.grd
  357. +++ b/chrome/app/generated_resources.grd
  358. @@ -6848,6 +6848,12 @@ the Bookmarks menu.">
  359. <message name="IDS_OPTIONS_HOMEPAGE_TITLE" desc="The title of the home page overlay on Android" formatter_data="android_java">
  360. Home page
  361. </message>
  362. + <message name="IDS_OPTIONS_DOH_TITLE" desc="The title of the DNS-over-HTTPS option on Android" formatter_data="android_java">
  363. + Secure DNS
  364. + </message>
  365. + <message name="IDS_OPTIONS_DOH_SUMMARY" desc="The title of the DNS-over-HTTPS summary on Android" formatter_data="android_java">
  366. + Configure DNS-over-HTTPS (DoH) secure DNS
  367. + </message>
  368. </if>
  369. <!-- Autofill dialog: field labels. -->
  370. diff --git a/chrome/browser/android/feature_utilities.cc b/chrome/browser/android/feature_utilities.cc
  371. --- a/chrome/browser/android/feature_utilities.cc
  372. +++ b/chrome/browser/android/feature_utilities.cc
  373. @@ -7,6 +7,9 @@
  374. #include "chrome/android/chrome_jni_headers/FeatureUtilities_jni.h"
  375. #include "base/android/jni_string.h"
  376. +#include "chrome/browser/browser_process.h"
  377. +#include "components/prefs/pref_service.h"
  378. +#include "chrome/common/pref_names.h"
  379. #include "content/public/common/content_features.h"
  380. #include "content/public/common/network_service_util.h"
  381. @@ -45,3 +48,23 @@ static jboolean JNI_FeatureUtilities_IsNetworkServiceWarmUpEnabled(
  382. return content::IsOutOfProcessNetworkService() &&
  383. base::FeatureList::IsEnabled(features::kWarmUpNetworkProcess);
  384. }
  385. +
  386. +static jboolean JNI_FeatureUtilities_GetDoHEnabled(JNIEnv* env) {
  387. + std::string doh_mode = g_browser_process->local_state()->GetString(prefs::kDnsOverHttpsMode);
  388. + return ((doh_mode == "secure") || (doh_mode == "auto"));
  389. +}
  390. +
  391. +static void JNI_FeatureUtilities_SetDoHEnabled(JNIEnv* env, jboolean enabled) {
  392. + if (enabled)
  393. + g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsMode, "secure");
  394. + else
  395. + g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsMode, "off");
  396. +}
  397. +
  398. +static ScopedJavaLocalRef<jstring> JNI_FeatureUtilities_GetDoHTemplates(JNIEnv* env) {
  399. + return base::android::ConvertUTF8ToJavaString(env, g_browser_process->local_state()->GetString(prefs::kDnsOverHttpsTemplates));
  400. +}
  401. +
  402. +static void JNI_FeatureUtilities_SetDoHTemplates(JNIEnv* env, const JavaParamRef<jstring>& templates) {
  403. + g_browser_process->local_state()->SetString(prefs::kDnsOverHttpsTemplates, base::android::ConvertJavaStringToUTF8(env, templates));
  404. +}
  405. diff --git a/chrome/browser/net/system_network_context_manager.cc b/chrome/browser/net/system_network_context_manager.cc
  406. --- a/chrome/browser/net/system_network_context_manager.cc
  407. +++ b/chrome/browser/net/system_network_context_manager.cc
  408. @@ -379,40 +379,12 @@ SystemNetworkContextManager::SystemNetworkContextManager(
  409. local_state_->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
  410. base::Value(ShouldEnableAsyncDns()));
  411. std::string default_doh_mode = chrome_browser_net::kDnsOverHttpsModeOff;
  412. - std::string default_doh_templates = "";
  413. - if (base::FeatureList::IsEnabled(features::kDnsOverHttps)) {
  414. - if (features::kDnsOverHttpsFallbackParam.Get()) {
  415. - default_doh_mode = chrome_browser_net::kDnsOverHttpsModeAutomatic;
  416. - } else {
  417. - default_doh_mode = chrome_browser_net::kDnsOverHttpsModeSecure;
  418. - }
  419. - default_doh_templates = features::kDnsOverHttpsTemplatesParam.Get();
  420. - }
  421. + std::string default_doh_templates = features::kDnsOverHttpsTemplatesParam.Get();
  422. local_state_->SetDefaultPrefValue(prefs::kDnsOverHttpsMode,
  423. base::Value(default_doh_mode));
  424. local_state_->SetDefaultPrefValue(prefs::kDnsOverHttpsTemplates,
  425. base::Value(default_doh_templates));
  426. - // If the user has explicitly enabled or disabled the DoH experiment in
  427. - // chrome://flags, store that choice in the user prefs so that it can be
  428. - // persisted after the experiment ends. Also make sure to remove the stored
  429. - // prefs value if the user has changed their chrome://flags selection to the
  430. - // default.
  431. - flags_ui::PrefServiceFlagsStorage flags_storage(local_state_);
  432. - std::set<std::string> entries = flags_storage.GetFlags();
  433. - if (entries.count("dns-over-https@1")) {
  434. - // The user has "Enabled" selected.
  435. - local_state_->SetString(prefs::kDnsOverHttpsMode,
  436. - chrome_browser_net::kDnsOverHttpsModeAutomatic);
  437. - } else if (entries.count("dns-over-https@2")) {
  438. - // The user has "Disabled" selected.
  439. - local_state_->SetString(prefs::kDnsOverHttpsMode,
  440. - chrome_browser_net::kDnsOverHttpsModeOff);
  441. - } else {
  442. - // The user has "Default" selected.
  443. - local_state_->ClearPref(prefs::kDnsOverHttpsMode);
  444. - }
  445. -
  446. PrefChangeRegistrar::NamedChangeCallback dns_pref_callback =
  447. base::BindRepeating(&OnStubResolverConfigChanged,
  448. base::Unretained(local_state_));
  449. @@ -548,9 +520,14 @@ void SystemNetworkContextManager::GetStubResolverConfig(
  450. std::string doh_templates =
  451. local_state->GetString(prefs::kDnsOverHttpsTemplates);
  452. - std::string server_method;
  453. - if (!doh_templates.empty() &&
  454. - *secure_dns_mode != net::DnsConfig::SecureDnsMode::OFF) {
  455. + if (doh_templates.empty()) {
  456. + *secure_dns_mode = net::DnsConfig::SecureDnsMode::OFF;
  457. + doh_mode = chrome_browser_net::kDnsOverHttpsModeOff;
  458. + }
  459. +
  460. + LOG(INFO) << "DoH templates: '" << doh_templates << "' with mode " << doh_mode;
  461. + if (*secure_dns_mode != net::DnsConfig::SecureDnsMode::OFF) {
  462. + std::string server_method;
  463. for (const std::string& server_template :
  464. SplitString(doh_templates, " ", base::TRIM_WHITESPACE,
  465. base::SPLIT_WANT_NONEMPTY)) {
  466. diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd
  467. --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
  468. +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
  469. @@ -578,6 +578,17 @@ CHAR-LIMIT guidelines:
  470. Chrome Passwords
  471. </message>
  472. + <!-- DoH preferences -->
  473. + <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.">
  474. + Edit DoH template URLs
  475. + </message>
  476. + <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.">
  477. + DoH template URLs
  478. + </message>
  479. + <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.">
  480. + Visit help page
  481. + </message>
  482. +
  483. <!-- Homepage preferences -->
  484. <message name="IDS_OPTIONS_HOMEPAGE_EDIT_TITLE" desc="The title of the screen that allows users to change the URL that opens when they tap on the home page button in the omnibox.">
  485. Edit home page
  486. diff --git a/chrome/common/chrome_features.cc b/chrome/common/chrome_features.cc
  487. --- a/chrome/common/chrome_features.cc
  488. +++ b/chrome/common/chrome_features.cc
  489. @@ -293,12 +293,12 @@ const char kDisallowUnsafeHttpDownloadsParamName[] = "MimeTypeList";
  490. // Enable DNS over HTTPS (DoH).
  491. const base::Feature kDnsOverHttps{"DnsOverHttps",
  492. - base::FEATURE_DISABLED_BY_DEFAULT};
  493. + base::FEATURE_ENABLED_BY_DEFAULT};
  494. // Set whether fallback to insecure DNS is allowed by default. This setting may
  495. // be overridden for individual transactions.
  496. const base::FeatureParam<bool> kDnsOverHttpsFallbackParam{&kDnsOverHttps,
  497. - "Fallback", true};
  498. + "Fallback", false};
  499. // Supply one or more space-separated DoH server URI templates to use when this
  500. // feature is enabled. If no templates are specified, then a hardcoded mapping
  501. --
  502. 2.17.1