WebUI: Convert remaining usages of var to let/const, part 3/3.

Conversions performed with a tool (lebab). In a few occasions had to
manually convert, where the tool could not determine if the conversion
was safe.

This is in preparation of turning on no-var, and prefer-const ESLint
checks for all of chrome/browser/resources/

Bug: 792774
Change-Id: I6df38ac00c27a412108ed841660bd758f5db0d67
Reviewed-on: https://chromium-review.googlesource.com/c/1361795
Reviewed-by: Dan Beam <[email protected]>
Commit-Queue: Demetrios Papadopoulos <[email protected]>
Cr-Commit-Position: refs/heads/master@{#614050}
diff --git a/chrome/browser/resources/about_flash.js b/chrome/browser/resources/about_flash.js
index 5b213955..cbcb627 100644
--- a/chrome/browser/resources/about_flash.js
+++ b/chrome/browser/resources/about_flash.js
@@ -10,8 +10,8 @@
  */
 function renderTemplate(moduleListData) {
   // This is the javascript code that processes the template:
-  var input = new JsEvalContext(moduleListData);
-  var output = $('flashInfoTemplate');
+  const input = new JsEvalContext(moduleListData);
+  const output = $('flashInfoTemplate');
   jstProcess(input, output);
 }
 
diff --git a/chrome/browser/resources/about_invalidations.js b/chrome/browser/resources/about_invalidations.js
index 46cbefed..adde733 100644
--- a/chrome/browser/resources/about_invalidations.js
+++ b/chrome/browser/resources/about_invalidations.js
@@ -9,14 +9,14 @@
    * log any invalidations ocurred prior to opening the about:invalidation
    * page).
    */
-  var tableObjects = {};
+  const tableObjects = {};
 
   /**
    * Local variable that contains the detailed information in an object form.
    * This was done this way as to allow multiple calls to updateDetailedStatus
    * to keep adding new items.
    */
-  var cachedDetails = {};
+  let cachedDetails = {};
 
   function quote(str) {
     return '\"' + str + '\"';
@@ -31,23 +31,23 @@
    * @param {string} logMessage The string to be appended.
    */
   function appendToLog(logMessage) {
-    var invalidationsLog = $('invalidations-log');
+    const invalidationsLog = $('invalidations-log');
     invalidationsLog.value += logMessage + '\n';
   }
   /**
    *  Updates the jstemplate with the latest ObjectIds, ordered by registrar.
    */
   function repaintTable() {
-    var keys = [];
-    for (var key in tableObjects) {
+    const keys = [];
+    for (const key in tableObjects) {
       keys.push(key);
     }
     keys.sort();
-    var sortedInvalidations = [];
-    for (var i = 0; i < keys.length; i++) {
+    const sortedInvalidations = [];
+    for (let i = 0; i < keys.length; i++) {
       sortedInvalidations.push(tableObjects[keys[i]]);
     }
-    var wrapped = {objectsidtable: sortedInvalidations};
+    const wrapped = {objectsidtable: sortedInvalidations};
     jstProcess(new JsEvalContext(wrapped), $('objectsid-table-div'));
   }
 
@@ -58,7 +58,7 @@
    *     changed.
    */
   function updateInvalidatorState(newState, lastChangedTime) {
-    var logMessage = nowTimeString() +
+    const logMessage = nowTimeString() +
         'Invalidations service state changed to ' + quote(newState);
 
     appendToLog(logMessage);
@@ -72,16 +72,17 @@
    *     that contains the invalidations received by the InvalidatorService.
    */
   function logInvalidations(allInvalidations) {
-    for (var i = 0; i < allInvalidations.length; i++) {
-      var inv = allInvalidations[i];
+    for (let i = 0; i < allInvalidations.length; i++) {
+      const inv = allInvalidations[i];
       if (inv.hasOwnProperty('objectId')) {
-        var logMessage = nowTimeString() + 'Received Invalidation with type ' +
-            quote(inv.objectId.name) + ' version ' +
+        const logMessage = nowTimeString() +
+            'Received Invalidation with type ' + quote(inv.objectId.name) +
+            ' version ' +
             quote((inv.isUnknownVersion ? 'Unknown' : inv.version)) +
             ' with payload ' + quote(inv.payload);
 
         appendToLog(logMessage);
-        var isInvalidation = true;
+        const isInvalidation = true;
         logToTable(inv, isInvalidation);
       }
     }
@@ -97,14 +98,14 @@
    *     as it was just updated its state.
    */
   function logToTable(oId, isInvalidation) {
-    var registrar = oId.registrar;
-    var name = oId.objectId.name;
-    var source = oId.objectId.source;
-    var totalCount = oId.objectId.totalCount || 0;
-    var key = source + '-' + name;
-    var time = new Date();
-    var version = oId.isUnknownVersion ? '?' : oId.version;
-    var payload = '';
+    const registrar = oId.registrar;
+    const name = oId.objectId.name;
+    const source = oId.objectId.source;
+    const totalCount = oId.objectId.totalCount || 0;
+    const key = source + '-' + name;
+    const time = new Date();
+    const version = oId.isUnknownVersion ? '?' : oId.version;
+    let payload = '';
     if (oId.hasOwnProperty('payload'))
       payload = oId.payload;
     if (!(key in tableObjects)) {
@@ -140,9 +141,9 @@
    *     InvalidatorService.
    */
   function updateHandlers(allHandlers) {
-    var allHandlersFormatted = allHandlers.join(', ');
+    const allHandlersFormatted = allHandlers.join(', ');
     $('registered-handlers').textContent = allHandlersFormatted;
-    var logMessage = nowTimeString() +
+    const logMessage = nowTimeString() +
         'InvalidatorHandlers currently registered: ' + allHandlersFormatted;
     appendToLog(logMessage);
   }
@@ -159,14 +160,14 @@
   function updateIds(registrar, allIds) {
     // Grey out every datatype assigned to this registrar
     // (and reenable them later in case they are still registered).
-    for (var key in tableObjects) {
+    for (const key in tableObjects) {
       if (tableObjects[key]['registrar'] === registrar)
         tableObjects[key].type = 'greyed';
     }
     // Reenable those ObjectsIds still registered with this registrar.
-    for (var i = 0; i < allIds.length; i++) {
-      var oId = {objectId: allIds[i], registrar: registrar};
-      var isInvalidation = false;
+    for (let i = 0; i < allIds.length; i++) {
+      const oId = {objectId: allIds[i], registrar: registrar};
+      const isInvalidation = false;
       logToTable(oId, isInvalidation);
     }
     repaintTable();
@@ -178,7 +179,7 @@
    *      details (e.g. Network Channel information).
    */
   function updateDetailedStatus(newDetails) {
-    for (var key in newDetails) {
+    for (const key in newDetails) {
       cachedDetails[key] = newDetails[key];
     }
     $('internal-display').value = JSON.stringify(cachedDetails, null, 2);
diff --git a/chrome/browser/resources/about_nacl.js b/chrome/browser/resources/about_nacl.js
index 7bbc87c..08552f96 100644
--- a/chrome/browser/resources/about_nacl.js
+++ b/chrome/browser/resources/about_nacl.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-var nacl = nacl || {};
+const nacl = {};
 
 (function() {
 /**
@@ -13,8 +13,8 @@
  */
 function renderTemplate(moduleListData) {
   // Process the template.
-  var input = new JsEvalContext(moduleListData);
-  var output = $('naclInfoTemplate');
+  const input = new JsEvalContext(moduleListData);
+  const output = $('naclInfoTemplate');
   jstProcess(input, output);
 }
 
diff --git a/chrome/browser/resources/certificate_viewer.js b/chrome/browser/resources/certificate_viewer.js
index 447534b0..a47bbc76f 100644
--- a/chrome/browser/resources/certificate_viewer.js
+++ b/chrome/browser/resources/certificate_viewer.js
@@ -12,7 +12,7 @@
   function initialize() {
     cr.ui.decorate('tabbox', cr.ui.TabBox);
 
-    var args = JSON.parse(chrome.getVariableValue('dialogArguments'));
+    const args = JSON.parse(chrome.getVariableValue('dialogArguments'));
     getCertificateInfo(args);
 
     /**
@@ -22,7 +22,7 @@
      * purposes in case a test needs to initialize the tab before the timer
      * fires.
      */
-    var initializeDetailTab = oneShot(function() {
+    const initializeDetailTab = oneShot(function() {
       initializeTree($('hierarchy'), showCertificateFields);
       initializeTree($('cert-fields'), showCertificateFieldValue);
       createCertificateHierarchy(args.hierarchy);
@@ -50,7 +50,7 @@
    * Decorate a function so that it can only be invoked once.
    */
   function oneShot(fn) {
-    var fired = false;
+    let fired = false;
     return function() {
       if (fired)
         return;
@@ -79,9 +79,9 @@
    */
   function stripGtkAccessorKeys() {
     // Copy all the tab labels into an array.
-    var nodes = Array.prototype.slice.call($('tabs').childNodes, 0);
+    const nodes = Array.prototype.slice.call($('tabs').childNodes, 0);
     nodes.push($('export'));
-    for (var i = 0; i < nodes.length; i++)
+    for (let i = 0; i < nodes.length; i++)
       nodes[i].textContent = nodes[i].textContent.replace('&', '');
   }
 
@@ -91,7 +91,7 @@
    */
   function revealTree(tree) {
     tree.expanded = true;
-    for (var key in tree.detail.children) {
+    for (const key in tree.detail.children) {
       revealTree(tree.detail.children[key]);
     }
   }
@@ -102,7 +102,7 @@
    * @param {Object} certInfo Certificate information in named fields.
    */
   function getCertificateInfo(certInfo) {
-    for (var key in certInfo.general) {
+    for (const key in certInfo.general) {
       $(key).textContent = certInfo.general[key];
     }
   }
@@ -112,15 +112,15 @@
    * @param {Object} hierarchy A dictionary containing the hierarchy.
    */
   function createCertificateHierarchy(hierarchy) {
-    var treeItem = $('hierarchy');
-    var root = constructTree(hierarchy[0]);
+    const treeItem = $('hierarchy');
+    const root = constructTree(hierarchy[0]);
     treeItem.detail.children['root'] = root;
     treeItem.add(root);
 
     // Select the last item in the hierarchy (really we have a list here - each
     // node has at most one child).  This will reveal the parent nodes and
     // populate the fields view.
-    var last = root;
+    let last = root;
     while (last.detail.children && last.detail.children[0])
       last = last.detail.children[0];
     last.selected = true;
@@ -132,12 +132,12 @@
    * @return {cr.ui.TreeItem} Tree node corresponding to the input dictionary.
    */
   function constructTree(tree) {
-    var treeItem = new cr.ui.TreeItem({
+    const treeItem = new cr.ui.TreeItem({
       label: tree.label,
       detail: {payload: tree.payload ? tree.payload : {}, children: {}}
     });
     if (tree.children) {
-      for (var i = 0; i < tree.children.length; i++) {
+      for (let i = 0; i < tree.children.length; i++) {
         treeItem.add(
             treeItem.detail.children[i] = constructTree(tree.children[i]));
       }
@@ -149,8 +149,8 @@
    * Clear any previous certificate fields in the tree.
    */
   function clearCertificateFields() {
-    var treeItem = $('cert-fields');
-    for (var key in treeItem.detail.children) {
+    const treeItem = $('cert-fields');
+    for (const key in treeItem.detail.children) {
       treeItem.remove(treeItem.detail.children[key]);
       delete treeItem.detail.children[key];
     }
@@ -161,7 +161,7 @@
    */
   function showCertificateFields() {
     clearCertificateFields();
-    var item = $('hierarchy').selectedItem;
+    const item = $('hierarchy').selectedItem;
     if (item && item.detail.payload.index !== undefined)
       chrome.send('requestCertificateFields', [item.detail.payload.index]);
   }
@@ -173,7 +173,7 @@
    */
   function getCertificateFields(certFields) {
     clearCertificateFields();
-    var treeItem = $('cert-fields');
+    const treeItem = $('cert-fields');
     treeItem.add(
         treeItem.detail.children['root'] = constructTree(certFields[0]));
     revealTree(treeItem);
@@ -185,7 +185,7 @@
    * Show certificate field value for a selected certificate field.
    */
   function showCertificateFieldValue() {
-    var item = $('cert-fields').selectedItem;
+    const item = $('cert-fields').selectedItem;
     if (item && item.detail.payload.val)
       $('cert-field-value').textContent = item.detail.payload.val;
     else
@@ -196,7 +196,7 @@
    * Export the selected certificate.
    */
   function exportCertificate() {
-    var item = $('hierarchy').selectedItem;
+    const item = $('hierarchy').selectedItem;
     if (item && item.detail.payload.index !== undefined)
       chrome.send('exportCertificate', [item.detail.payload.index]);
   }
diff --git a/chrome/browser/resources/components.js b/chrome/browser/resources/components.js
index 8d29201..7c357471 100644
--- a/chrome/browser/resources/components.js
+++ b/chrome/browser/resources/components.js
@@ -9,7 +9,7 @@
  * version. This is populated in returnComponentsData() for the convenience of
  * tests.
  */
-var currentComponentsData = null;
+let currentComponentsData = null;
 
 /**
  * Takes the |componentsData| input argument which represents data about the
@@ -20,8 +20,8 @@
  */
 function renderTemplate(componentsData) {
   // This is the javascript code that processes the template:
-  var input = new JsEvalContext(componentsData);
-  var output = $('component-template').cloneNode(true);
+  const input = new JsEvalContext(componentsData);
+  const output = $('component-template').cloneNode(true);
   $('component-placeholder').innerHTML = '';
   $('component-placeholder').appendChild(output);
   jstProcess(input, output);
@@ -58,8 +58,8 @@
  *   }
  */
 function returnComponentsData(componentsData) {
-  var bodyContainer = $('body-container');
-  var body = document.body;
+  const bodyContainer = $('body-container');
+  const body = document.body;
 
   bodyContainer.style.visibility = 'hidden';
   body.className = '';
@@ -71,8 +71,8 @@
   renderTemplate(componentsData);
 
   // Add handlers to dynamically created HTML elements.
-  var links = document.getElementsByClassName('button-check-update');
-  for (var i = 0; i < links.length; i++) {
+  const links = document.getElementsByClassName('button-check-update');
+  for (let i = 0; i < links.length; i++) {
     links[i].onclick = function(e) {
       handleCheckUpdate(this);
       e.preventDefault();
@@ -100,19 +100,19 @@
   if (!eventArgs['id'])
     return;
 
-  var id = eventArgs['id'];
+  const id = eventArgs['id'];
 
-  var filteredComponents = currentComponentsData.filter(function(entry) {
+  const filteredComponents = currentComponentsData.filter(function(entry) {
     return entry.id === id;
   });
-  var component = filteredComponents[0];
+  const component = filteredComponents[0];
 
-  var status = eventArgs['event'];
+  const status = eventArgs['event'];
   $('status-' + id).textContent = status;
   component['status'] = status;
 
   if (eventArgs['version']) {
-    var version = eventArgs['version'];
+    const version = eventArgs['version'];
     $('version-' + id).textContent = version;
     component['version'] = version;
   }
diff --git a/chrome/browser/resources/connection_manager.js b/chrome/browser/resources/connection_manager.js
index 12cb0487..9bc3e9a 100644
--- a/chrome/browser/resources/connection_manager.js
+++ b/chrome/browser/resources/connection_manager.js
@@ -16,7 +16,7 @@
 };
 
 chromeos.connectionManager.reportTransactionStatus_ = function(status) {
-  var msg = {
+  const msg = {
     'type': 'reportTransactionStatusMsg',
     'domain': location.href,
     'status': status
diff --git a/chrome/browser/resources/identity_internals.js b/chrome/browser/resources/identity_internals.js
index bdd44ac..1dd93df 100644
--- a/chrome/browser/resources/identity_internals.js
+++ b/chrome/browser/resources/identity_internals.js
@@ -11,7 +11,7 @@
    * @constructor
    */
   function TokenListItem(tokenInfo) {
-    var el = cr.doc.createElement('div');
+    const el = cr.doc.createElement('div');
     el.data_ = tokenInfo;
     el.__proto__ = TokenListItem.prototype;
     el.decorate();
@@ -26,8 +26,8 @@
       this.textContent = '';
       this.id = this.data_.accessToken;
 
-      var table = this.ownerDocument.createElement('table');
-      var tbody = this.ownerDocument.createElement('tbody');
+      const table = this.ownerDocument.createElement('table');
+      const tbody = this.ownerDocument.createElement('tbody');
       tbody.appendChild(this.createEntry_(
           'accessToken', this.data_.accessToken, 'access-token'));
       tbody.appendChild(this.createEntry_(
@@ -40,7 +40,7 @@
           'expirationTime', this.data_.expirationTime, 'expiration-time'));
       tbody.appendChild(this.createEntryForScopes_());
       table.appendChild(tbody);
-      var tfoot = this.ownerDocument.createElement('tfoot');
+      const tfoot = this.ownerDocument.createElement('tfoot');
       tfoot.appendChild(this.createButtons_());
       table.appendChild(tfoot);
       this.appendChild(table);
@@ -54,12 +54,12 @@
      * @return {HTMLElement} An HTML element with the property name and value.
      */
     createEntry_: function(label, value, accessor) {
-      var row = this.ownerDocument.createElement('tr');
-      var labelField = this.ownerDocument.createElement('td');
+      const row = this.ownerDocument.createElement('tr');
+      const labelField = this.ownerDocument.createElement('td');
       labelField.classList.add('label');
       labelField.textContent = loadTimeData.getString(label);
       row.appendChild(labelField);
-      var valueField = this.ownerDocument.createElement('td');
+      const valueField = this.ownerDocument.createElement('td');
       valueField.classList.add('value');
       valueField.classList.add(accessor);
       valueField.textContent = value;
@@ -72,12 +72,12 @@
      * @return {!HTMLElement} An HTML element with scopes.
      */
     createEntryForScopes_: function() {
-      var row = this.ownerDocument.createElement('tr');
-      var labelField = this.ownerDocument.createElement('td');
+      const row = this.ownerDocument.createElement('tr');
+      const labelField = this.ownerDocument.createElement('td');
       labelField.classList.add('label');
       labelField.textContent = loadTimeData.getString('scopes');
       row.appendChild(labelField);
-      var valueField = this.ownerDocument.createElement('td');
+      const valueField = this.ownerDocument.createElement('td');
       valueField.classList.add('value');
       valueField.classList.add('scope-list');
       this.data_.scopes.forEach(function(scope) {
@@ -94,8 +94,8 @@
      *     token.
      */
     createButtons_: function() {
-      var row = this.ownerDocument.createElement('tr');
-      var buttonHolder = this.ownerDocument.createElement('td');
+      const row = this.ownerDocument.createElement('tr');
+      const buttonHolder = this.ownerDocument.createElement('td');
       buttonHolder.colSpan = 2;
       buttonHolder.classList.add('token-actions');
       buttonHolder.appendChild(this.createRevokeButton_());
@@ -110,7 +110,7 @@
      * @private
      */
     createRevokeButton_: function() {
-      var revokeButton = this.ownerDocument.createElement('button');
+      const revokeButton = this.ownerDocument.createElement('button');
       revokeButton.classList.add('revoke-button');
       revokeButton.addEventListener('click', function() {
         chrome.send(
@@ -128,7 +128,7 @@
    * @constructor
    * @extends {cr.ui.div}
    */
-  var TokenList = cr.ui.define('div');
+  const TokenList = cr.ui.define('div');
 
   TokenList.prototype = {
     __proto__: HTMLDivElement.prototype,
@@ -155,8 +155,8 @@
      * @private
      */
     removeTokenNode_: function(accessToken) {
-      var tokenIndex;
-      for (var index = 0; index < this.data_.length; index++) {
+      let tokenIndex;
+      for (let index = 0; index < this.data_.length; index++) {
         if (this.data_[index].accessToken == accessToken) {
           tokenIndex = index;
           break;
@@ -168,13 +168,13 @@
         this.data_.splice(tokenIndex, 1);
 
       // Remove from the user interface.
-      var tokenNode = $(accessToken);
+      const tokenNode = $(accessToken);
       if (tokenNode)
         this.removeChild(tokenNode);
     },
   };
 
-  var tokenList;
+  let tokenList;
 
   /**
    * Initializes the UI by asking the contoller for list of identity tokens.
diff --git a/chrome/browser/resources/policy_base.js b/chrome/browser/resources/policy_base.js
index 200722b..202305b 100644
--- a/chrome/browser/resources/policy_base.js
+++ b/chrome/browser/resources/policy_base.js
@@ -9,7 +9,7 @@
    * checking if the first column is hidden.
    * @return {boolean} True if this is the mobile version.
    */
-  var isMobilePage = function() {
+  const isMobilePage = function() {
     return document.defaultView
                .getComputedStyle(document.querySelector('.scope-column'))
                .display == 'none';
@@ -20,8 +20,8 @@
    * @constructor
    * @extends {HTMLFieldSetElement}
    */
-  var StatusBox = cr.ui.define(function() {
-    var node = $('status-box-template').cloneNode(true);
+  const StatusBox = cr.ui.define(function() {
+    const node = $('status-box-template').cloneNode(true);
     node.removeAttribute('id');
     return node;
   });
@@ -45,7 +45,7 @@
      *     False otherwise.
      */
     setLabelAndShow_: function(labelName, labelValue, needsToBeShown = true) {
-      var labelElement = this.querySelector(labelName);
+      const labelElement = this.querySelector(labelName);
       labelElement.textContent = labelValue || '';
       if (needsToBeShown)
         labelElement.parentElement.hidden = false;
@@ -115,8 +115,8 @@
    * @constructor
    * @extends {HTMLTableSectionElement}
    */
-  var Policy = cr.ui.define(function() {
-    var node = $('policy-template').cloneNode(true);
+  const Policy = cr.ui.define(function() {
+    const node = $('policy-template').cloneNode(true);
     node.removeAttribute('id');
     return node;
   });
@@ -171,7 +171,7 @@
       }
 
       // Populate the status column.
-      var status;
+      let status;
       if (!value) {
         // If the policy value has not been set, show an error message.
         status = loadTimeData.getString('unset');
@@ -191,9 +191,9 @@
       if (isMobilePage()) {
         // The number of columns which are hidden by the css file for the mobile
         // (Android) version of this page.
-        /** @const */ var HIDDEN_COLUMNS_IN_MOBILE_VERSION = 2;
+        /** @const */ const HIDDEN_COLUMNS_IN_MOBILE_VERSION = 2;
 
-        var expandedValue = this.querySelector('.expanded-value');
+        const expandedValue = this.querySelector('.expanded-value');
         expandedValue.setAttribute(
             'colspan',
             expandedValue.colSpan - HIDDEN_COLUMNS_IN_MOBILE_VERSION);
@@ -228,16 +228,16 @@
      */
     checkOverflow: function() {
       // Set a tooltip on all overflowed columns except the value column.
-      var divs = this.querySelectorAll('div.elide');
-      for (var i = 0; i < divs.length; i++) {
-        var div = divs[i];
+      const divs = this.querySelectorAll('div.elide');
+      for (let i = 0; i < divs.length; i++) {
+        const div = divs[i];
         div.title = div.offsetWidth < div.scrollWidth ? div.textContent : '';
       }
 
       // Cache the width of the value column's contents when it is first shown.
       // This is required to be able to check whether the contents would still
       // overflow the column once it has been hidden and replaced by a link.
-      var valueContainer = this.querySelector('.value-container');
+      const valueContainer = this.querySelector('.value-container');
       this.updateValueWidth_(valueContainer);
 
       // Determine whether the contents of the value column overflows. The
@@ -278,7 +278,7 @@
    * @constructor
    * @extends {HTMLTableElement}
    */
-  var PolicyTable = cr.ui.define('tbody');
+  const PolicyTable = cr.ui.define('tbody');
 
   PolicyTable.prototype = {
     // Set up the prototype chain.
@@ -309,13 +309,13 @@
      */
     setPolicyValues: function(values) {
       // Remove all policies from the table.
-      var policies = this.getElementsByTagName('tbody');
+      const policies = this.getElementsByTagName('tbody');
       while (policies.length > 0)
         this.removeChild(policies.item(0));
 
       // First, add known policies whose value is currently set.
-      var unset = [];
-      for (var name in this.policies_) {
+      const unset = [];
+      for (let name in this.policies_) {
         if (name in values)
           this.setPolicyValue_(name, values[name], false);
         else
@@ -324,13 +324,13 @@
 
       // Second, add policies whose value is currently set but whose name is not
       // recognized.
-      for (var name in values) {
+      for (let name in values) {
         if (!(name in this.policies_))
           this.setPolicyValue_(name, values[name], true);
       }
 
       // Finally, add known policies whose value is not currently set.
-      for (var i = 0; i < unset.length; i++)
+      for (let i = 0; i < unset.length; i++)
         this.setPolicyValue_(unset[i], undefined, false);
 
       // Filter the policies.
@@ -354,10 +354,10 @@
      * set are only shown if the corresponding checkbox is checked.
      */
     filter: function() {
-      var showUnset = $('show-unset').checked;
-      var policies = this.getElementsByTagName('tbody');
-      for (var i = 0; i < policies.length; i++) {
-        var policy = policies[i];
+      const showUnset = $('show-unset').checked;
+      const policies = this.getElementsByTagName('tbody');
+      for (let i = 0; i < policies.length; i++) {
+        const policy = policies[i];
         policy.hidden = policy.unset && !showUnset ||
             policy.name.toLowerCase().indexOf(this.filterPattern_) == -1;
       }
@@ -373,8 +373,8 @@
      * @private
      */
     checkOverflow_: function() {
-      var policies = this.getElementsByTagName('tbody');
-      for (var i = 0; i < policies.length; i++) {
+      const policies = this.getElementsByTagName('tbody');
+      for (let i = 0; i < policies.length; i++) {
         if (!policies[i].hidden)
           policies[i].checkOverflow();
       }
@@ -388,7 +388,7 @@
      * @private
      */
     setPolicyValue_: function(name, value, unknown) {
-      var policy = new Policy;
+      const policy = new Policy;
       policy.initialize(name, value, unknown);
       this.appendChild(policy);
     },
@@ -409,21 +409,22 @@
    * @param {Object} names Dictionary containing all known policy names.
    */
   Page.setPolicyNames = function(names) {
-    var page = this.getInstance();
+    const page = this.getInstance();
 
     // Clear all policy tables.
     page.mainSection.innerHTML = '';
     page.policyTables = {};
 
+    let table;
     // Create tables and set known policy names for Chrome and extensions.
     if (names.hasOwnProperty('chromePolicyNames')) {
-      var table = page.appendNewTable('chrome', 'Chrome policies', '');
+      table = page.appendNewTable('chrome', 'Chrome policies', '');
       table.setPolicyNames(names.chromePolicyNames);
     }
 
     if (names.hasOwnProperty('extensionPolicyNames')) {
-      for (var ext in names.extensionPolicyNames) {
-        var table = page.appendNewTable(
+      for (const ext in names.extensionPolicyNames) {
+        table = page.appendNewTable(
             'extension-' + ext, names.extensionPolicyNames[ext].name,
             'ID: ' + ext);
         table.setPolicyNames(names.extensionPolicyNames[ext].policyNames);
@@ -438,15 +439,16 @@
    * @param {Object} values Dictionary containing the current policy values.
    */
   Page.setPolicyValues = function(values) {
-    var page = this.getInstance();
+    const page = this.getInstance();
+    let table;
     if (values.hasOwnProperty('chromePolicies')) {
-      var table = page.policyTables['chrome'];
+      table = page.policyTables['chrome'];
       table.setPolicyValues(values.chromePolicies);
     }
 
     if (values.hasOwnProperty('extensionPolicies')) {
-      for (var extensionId in values.extensionPolicies) {
-        var table = page.policyTables['extension-' + extensionId];
+      for (const extensionId in values.extensionPolicies) {
+        table = page.policyTables['extension-' + extensionId];
         if (table)
           table.setPolicyValues(values.extensionPolicies[extensionId]);
       }
@@ -483,7 +485,7 @@
       // Place the initial focus on the filter input field.
       $('filter').focus();
 
-      var self = this;
+      const self = this;
       $('filter').onsearch = function(event) {
         for (policyTable in self.policyTables) {
           self.policyTables[policyTable].setFilterPattern(this.value);
@@ -519,7 +521,7 @@
      * @return {Element} The newly created table.
      */
     appendNewTable: function(id, label_title, label_content) {
-      var newSection =
+      const newSection =
           this.createPolicyTableSection(id, label_title, label_content);
       if (id != 'chrome') {
         newSection.classList.add('no-help-link');
@@ -537,29 +539,29 @@
      * @return {Element} The newly created section.
      */
     createPolicyTableSection: function(id, label_title, label_content) {
-      var section = document.createElement('section');
+      const section = document.createElement('section');
       section.setAttribute('class', 'policy-table-section');
 
       // Add title and description.
-      var title = window.document.createElement('h3');
+      const title = window.document.createElement('h3');
       title.textContent = label_title;
       section.appendChild(title);
 
       if (label_content) {
-        var description = window.document.createElement('div');
+        const description = window.document.createElement('div');
         description.classList.add('table-description');
         description.textContent = label_content;
         section.appendChild(description);
       }
 
       // Add 'No Policies Set' element.
-      var noPolicies = window.document.createElement('div');
+      const noPolicies = window.document.createElement('div');
       noPolicies.classList.add('no-policies-set');
       noPolicies.textContent = loadTimeData.getString('noPoliciesSet');
       section.appendChild(noPolicies);
 
       // Add table of policies.
-      var newTable = this.createPolicyTable();
+      const newTable = this.createPolicyTable();
       this.policyTables[id] = newTable;
       section.appendChild(newTable);
 
@@ -573,11 +575,11 @@
      * @return {Element} The newly created table.
      */
     createPolicyTable: function() {
-      var newTable = window.document.createElement('table');
-      var tableHead = window.document.createElement('thead');
-      var tableRow = window.document.createElement('tr');
-      for (var i = 0; i < this.tableHeadings.length; i++) {
-        var tableHeader = window.document.createElement('th');
+      const newTable = window.document.createElement('table');
+      const tableHead = window.document.createElement('thead');
+      const tableRow = window.document.createElement('tr');
+      for (let i = 0; i < this.tableHeadings.length; i++) {
+        const tableHeader = window.document.createElement('th');
         tableHeader.classList.add(
             this.tableHeadings[i].toLowerCase() + '-column');
         tableHeader.textContent =
@@ -597,16 +599,16 @@
      */
     setStatus: function(status) {
       // Remove any existing status boxes.
-      var container = $('status-box-container');
+      const container = $('status-box-container');
       while (container.firstChild)
         container.removeChild(container.firstChild);
       // Hide the status section.
-      var section = $('status-section');
+      const section = $('status-section');
       section.hidden = true;
 
       // Add a status box for each scope that has a cloud policy status.
-      for (var scope in status) {
-        var box = new StatusBox;
+      for (const scope in status) {
+        const box = new StatusBox;
         box.initialize(scope, status[scope]);
         container.appendChild(box);
         // Show the status section.
diff --git a/chrome/browser/resources/policy_tool.js b/chrome/browser/resources/policy_tool.js
index 04c2ab2..e9d73b2 100644
--- a/chrome/browser/resources/policy_tool.js
+++ b/chrome/browser/resources/policy_tool.js
@@ -7,14 +7,14 @@
  * @param {!Array<string>} sessions List of session names.
  */
 policy.Page.setSessionsList = function(sessions) {
-  var list = $('session-list');
+  const list = $('session-list');
 
   // Clear the sessions list.
   list.innerHTML = '';
 
   // Set the new sessions list.
-  for (var i = 0; i < sessions.length; ++i) {
-    var option = document.createElement('OPTION');
+  for (let i = 0; i < sessions.length; ++i) {
+    const option = document.createElement('OPTION');
     option.value = sessions[i];
     option.textContent = sessions[i];
     list.appendChild(option);
@@ -71,19 +71,19 @@
 
 /** @override */
 policy.Page.setPolicyValues = function(values) {
-  var page = this.getInstance();
+  const page = this.getInstance();
   page.enableEditing();
-  var table = page.policyTables['chrome'];
+  let table = page.policyTables['chrome'];
   table.setPolicyValues(values.chromePolicies || {});
   if (values.hasOwnProperty('extensionPolicies')) {
-    for (var extensionId in values.extensionPolicies) {
+    for (const extensionId in values.extensionPolicies) {
       table = page.policyTables['extension-' + extensionId];
       if (table) {
         table.setPolicyValues(values.extensionPolicies[extensionId]);
       }
     }
   } else {
-    for (var extension in page.policyTables) {
+    for (const extension in page.policyTables) {
       if (extension == 'chrome') {
         continue;
       }
@@ -140,7 +140,7 @@
   };
 
   $('delete-session-button').onclick = () => {
-    var sessionName = $('session-list').value;
+    const sessionName = $('session-list').value;
     if (sessionName) {
       chrome.send('deleteSession', [sessionName]);
     }
@@ -148,7 +148,7 @@
 
   $('rename-session-button').onclick = () => {
     $('session-rename-error').hidden = true;
-    var sessionName = $('session-list').value;
+    const sessionName = $('session-list').value;
     if (sessionName) {
       $('rename-dialog').showModal();
       $('new-session-name-field').value = '';
@@ -162,8 +162,8 @@
 
   $('confirm-rename-button').onclick = () => {
     $('session-rename-error').textContent = '';
-    var sessionName = $('session-list').value;
-    var newSessionName = $('new-session-name-field').value;
+    const sessionName = $('session-list').value;
+    const newSessionName = $('new-session-name-field').value;
     if (sessionName && newSessionName) {
       chrome.send('renameSession', [sessionName, newSessionName]);
     }
@@ -192,13 +192,13 @@
  * @return {Object} The dictionary containing policy values.
  */
 policy.Page.prototype.getDictionary = function() {
-  var result = {chromePolicies: {}, extensionPolicies: {}};
-  for (var id in this.policyTables) {
+  const result = {chromePolicies: {}, extensionPolicies: {}};
+  for (const id in this.policyTables) {
     if (id == 'chrome') {
       result.chromePolicies = this.policyTables[id].getDictionary();
     } else {
       const PREFIX_LENGTH = 'extension-'.length;
-      var extensionId = id.substr(PREFIX_LENGTH);
+      const extensionId = id.substr(PREFIX_LENGTH);
       result.extensionPolicies[extensionId] =
           this.policyTables[id].getDictionary();
     }
@@ -240,7 +240,7 @@
  * @private
  */
 policy.Policy.prototype.setStatus_ = function(value) {
-  var status;
+  let status;
   if (this.unknown) {
     status = loadTimeData.getString('unknown');
   } else if (!value) {
@@ -294,13 +294,13 @@
  * @private
  */
 policy.Policy.prototype.submitEditedValue_ = function() {
-  var newValue = this.querySelector('.value-edit-field').value;
+  const newValue = this.querySelector('.value-edit-field').value;
   this.setValue_(newValue);
   this.setStatus_(newValue);
   this.classList.remove('value-editing-on');
   this.querySelector('.value-container').valueWidth = undefined;
   this.checkOverflow();
-  var showUnset = $('show-unset').checked;
+  const showUnset = $('show-unset').checked;
   this.hidden = this.unset && !showUnset ||
       this.name.toLowerCase().indexOf(this.parentNode.filterPattern_) == -1;
   chrome.send('updateSession', [policy.Page.getInstance().getDictionary()]);
@@ -314,10 +314,10 @@
  * @returns {Object} Dictionary with policy values.
  */
 policy.PolicyTable.prototype.getDictionary = function() {
-  var result = {};
-  var policies = this.getElementsByTagName('tbody');
-  for (var i = 0; i < policies.length; i++) {
-    var policy = policies[i];
+  const result = {};
+  const policies = this.getElementsByTagName('tbody');
+  for (let i = 0; i < policies.length; i++) {
+    const policy = policies[i];
     if (policy.unset) {
       continue;
     }
diff --git a/chrome/browser/resources/supervised_user_internals.js b/chrome/browser/resources/supervised_user_internals.js
index beb982ac..58804d0 100644
--- a/chrome/browser/resources/supervised_user_internals.js
+++ b/chrome/browser/resources/supervised_user_internals.js
@@ -29,8 +29,8 @@
       this.removeAttribute('highlighted');
     }
 
-    var oldStr = oldVal.toString();
-    var newStr = newVal.toString();
+    const oldStr = oldVal.toString();
+    const newStr = newVal.toString();
     if (oldStr != '' && oldStr != newStr) {
       // Note the addListener function does not end up creating duplicate
       // listeners.  There can be only one listener per event at a time.
@@ -63,7 +63,7 @@
     // list of key/value pairs for easier consumption by the HTML template.
     // This is not done recursively, values are passed as their JSON
     // representation.
-    var kvpairs = Object.keys(settings).map(function(key) {
+    const kvpairs = Object.keys(settings).map(function(key) {
       return {key: key, value: JSON.stringify(settings[key], null, 2)};
     });
 
@@ -94,7 +94,7 @@
   }
 
   /** Container for accumulated filtering results. */
-  var filteringResults = [];
+  const filteringResults = [];
 
   /**
    * Callback for incoming filtering results.
@@ -103,11 +103,11 @@
   function receiveFilteringResult(result) {
     filteringResults.push(result);
 
-    var container = $('filtering-results-container');
+    const container = $('filtering-results-container');
 
     // Scroll to the bottom if we were already at the bottom.  Otherwise, leave
     // the scrollbar alone.
-    var shouldScrollDown = isScrolledToBottom(container);
+    const shouldScrollDown = isScrolledToBottom(container);
 
     jstProcess(new JsEvalContext({results: filteringResults}), container);