Reland: NetworkConfig: Escape names before passing to i18n()

i18n() asserts if any unsafe tags are passed to it. We need to
HTMLEscape any network names passed to i18n().

Includes fix for browser tests.
Original CL:
https://chromium-review.googlesource.com/c/chromium/src/+/920903

TBR=stevenjb@chromium.org

(cherry picked from commit eaed246200f93cbe9042a56a2e609af0def6b710)

Bug: 811562
TBR: tbarzic@chromium.org
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I7762ac9309b812358799c7eb885b1b4d29f9ec7f
Reviewed-on: https://chromium-review.googlesource.com/924655
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#537518}
Reviewed-on: https://chromium-review.googlesource.com/929357
Cr-Commit-Position: refs/branch-heads/3325@{#543}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chrome/browser/resources/settings/internet_page/compiled_resources2.gyp b/chrome/browser/resources/settings/internet_page/compiled_resources2.gyp
index 7ffb7c7..cec4fe3 100644
--- a/chrome/browser/resources/settings/internet_page/compiled_resources2.gyp
+++ b/chrome/browser/resources/settings/internet_page/compiled_resources2.gyp
@@ -37,6 +37,7 @@
         '<(DEPTH)/ui/webui/resources/cr_elements/cr_dialog/compiled_resources2.gyp:cr_dialog',
         '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:assert',
         '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:i18n_behavior',
+        '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:util',
         '<(EXTERNS_GYP):networking_private',
         '<(INTERFACES_GYP):networking_private_interface',
       ],
diff --git a/chrome/browser/resources/settings/internet_page/internet_config.js b/chrome/browser/resources/settings/internet_page/internet_config.js
index b77d680..a4764b49 100644
--- a/chrome/browser/resources/settings/internet_page/internet_config.js
+++ b/chrome/browser/resources/settings/internet_page/internet_config.js
@@ -100,7 +100,7 @@
   getDialogTitle_: function() {
     const name = this.networkProperties_.Name;
     if (name)
-      return this.i18n('internetConfigName', name);
+      return this.i18n('internetConfigName', HTMLEscape(name));
     const type = this.i18n('OncType' + this.networkProperties_.Type);
     return this.i18n('internetJoinType', type);
   },
diff --git a/chrome/browser/resources/settings/internet_page/tether_connection_dialog.js b/chrome/browser/resources/settings/internet_page/tether_connection_dialog.js
index 00a9bc02..a6bc7f9 100644
--- a/chrome/browser/resources/settings/internet_page/tether_connection_dialog.js
+++ b/chrome/browser/resources/settings/internet_page/tether_connection_dialog.js
@@ -138,7 +138,8 @@
    */
   getExplanation_: function(networkProperties) {
     return this.i18n(
-        'tetherConnectionExplanation', CrOnc.getNetworkName(networkProperties));
+        'tetherConnectionExplanation',
+        CrOnc.getEscapedNetworkName(networkProperties));
   },
 
   /**
@@ -149,7 +150,7 @@
   getDescriptionTitle_: function(networkProperties) {
     return this.i18n(
         'tetherConnectionDescriptionTitle',
-        CrOnc.getNetworkName(networkProperties));
+        CrOnc.getEscapedNetworkName(networkProperties));
   },
 
   /**
diff --git a/chrome/test/data/webui/settings/cr_settings_browsertest.js b/chrome/test/data/webui/settings/cr_settings_browsertest.js
index 1d6378e..63b4dba 100644
--- a/chrome/test/data/webui/settings/cr_settings_browsertest.js
+++ b/chrome/test/data/webui/settings/cr_settings_browsertest.js
@@ -1175,6 +1175,7 @@
   extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
     ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js',
     ROOT_PATH + 'ui/webui/resources/js/assert.js',
+    ROOT_PATH + 'ui/webui/resources/js/util.js',
     '../fake_chrome_event.js',
     '../chromeos/fake_networking_private.js',
     'internet_detail_page_tests.js',
diff --git a/ui/webui/resources/cr_elements/chromeos/network/compiled_resources2.gyp b/ui/webui/resources/cr_elements/chromeos/network/compiled_resources2.gyp
index d7600a5..d4b7645 100644
--- a/ui/webui/resources/cr_elements/chromeos/network/compiled_resources2.gyp
+++ b/ui/webui/resources/cr_elements/chromeos/network/compiled_resources2.gyp
@@ -54,6 +54,7 @@
     {
       'target_name': 'cr_onc_types',
       'dependencies': [
+        '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:util',
         '<(EXTERNS_GYP):networking_private',
       ],
       'includes': ['../../../../../../third_party/closure_compiler/compile_js2.gypi'],
diff --git a/ui/webui/resources/cr_elements/chromeos/network/cr_onc_types.js b/ui/webui/resources/cr_elements/chromeos/network/cr_onc_types.js
index 9a2d13ef..5a7ed92 100644
--- a/ui/webui/resources/cr_elements/chromeos/network/cr_onc_types.js
+++ b/ui/webui/resources/cr_elements/chromeos/network/cr_onc_types.js
@@ -424,6 +424,15 @@
 
 /**
  * @param {!CrOnc.NetworkProperties|!CrOnc.NetworkStateProperties|undefined}
+ *     properties The ONC network properties or state properties.
+ * @return {string} The name to display for |network|.
+ */
+CrOnc.getEscapedNetworkName = function(properties) {
+  return HTMLEscape(CrOnc.getNetworkName(properties));
+};
+
+/**
+ * @param {!CrOnc.NetworkProperties|!CrOnc.NetworkStateProperties|undefined}
  *   properties The ONC network properties or state properties.
  * @return {boolean} True if |properties| is a Cellular network with a
  *   locked SIM.