Commit 376b30f9 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Apply clang-format for JS under c/b/r/certificate_viewer/

This was purposefully skipped on previous CL that migrated this folder
to JS modules, to make reviewing easier.

Fixed: 1149868
Change-Id: I678d88e58a9e1412c0cda1fb9575b83ecfe431bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553288
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Commit-Queue: John Lee <johntlee@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830271}
parent 042d3094
...@@ -11,19 +11,19 @@ import {TabBox} from 'chrome://resources/js/cr/ui/tabs.m.js'; ...@@ -11,19 +11,19 @@ import {TabBox} from 'chrome://resources/js/cr/ui/tabs.m.js';
import {Tree, TreeItem} from 'chrome://resources/js/cr/ui/tree.m.js'; import {Tree, TreeItem} from 'chrome://resources/js/cr/ui/tree.m.js';
import {$} from 'chrome://resources/js/util.m.js'; import {$} from 'chrome://resources/js/util.m.js';
/** /**
* @typedef {{ * @typedef {{
* general: !Object, * general: !Object,
* hierarchy: !Object, * hierarchy: !Object,
* }} * }}
*/ */
let CertificateInfo; let CertificateInfo;
/** /**
* Initialize the certificate viewer dialog by wiring up the close button, * Initialize the certificate viewer dialog by wiring up the close button,
* substituting in translated strings and requesting certificate details. * substituting in translated strings and requesting certificate details.
*/ */
function initialize() { function initialize() {
decorate('tabbox', TabBox); decorate('tabbox', TabBox);
const args = JSON.parse(chrome.getVariableValue('dialogArguments')); const args = JSON.parse(chrome.getVariableValue('dialogArguments'));
...@@ -58,12 +58,12 @@ import {$} from 'chrome://resources/js/util.m.js'; ...@@ -58,12 +58,12 @@ import {$} from 'chrome://resources/js/util.m.js';
stripGtkAccessorKeys(); stripGtkAccessorKeys();
$('export').onclick = exportCertificate; $('export').onclick = exportCertificate;
} }
/** /**
* Decorate a function so that it can only be invoked once. * Decorate a function so that it can only be invoked once.
*/ */
function oneShot(fn) { function oneShot(fn) {
let fired = false; let fired = false;
return function() { return function() {
if (fired) { if (fired) {
...@@ -72,62 +72,62 @@ import {$} from 'chrome://resources/js/util.m.js'; ...@@ -72,62 +72,62 @@ import {$} from 'chrome://resources/js/util.m.js';
fired = true; fired = true;
fn(); fn();
}; };
} }
/** /**
* Initialize a Tree object from a given element using the specified * Initialize a Tree object from a given element using the specified
* change handler. * change handler.
* @param {!HTMLElement} tree The HTMLElement to style as a tree. * @param {!HTMLElement} tree The HTMLElement to style as a tree.
* @param {function()} handler Function to call when a node is selected. * @param {function()} handler Function to call when a node is selected.
*/ */
function initializeTree(tree, handler) { function initializeTree(tree, handler) {
decorate(tree, Tree); decorate(tree, Tree);
tree['detail'] = {payload: {}, children: {}}; tree['detail'] = {payload: {}, children: {}};
tree.addEventListener('change', handler); tree.addEventListener('change', handler);
} }
/** /**
* The tab name strings in the languages file have accessor keys indicated * The tab name strings in the languages file have accessor keys indicated
* by a preceding & sign. Strip these out for now. * by a preceding & sign. Strip these out for now.
* TODO(flackr) These accessor keys could be implemented with Javascript or * TODO(flackr) These accessor keys could be implemented with Javascript or
* translated strings could be added / modified to remove the & sign. * translated strings could be added / modified to remove the & sign.
*/ */
function stripGtkAccessorKeys() { function stripGtkAccessorKeys() {
// Copy all the tab labels into an array. // Copy all the tab labels into an array.
const nodes = Array.prototype.slice.call($('tabs').childNodes, 0); const nodes = Array.prototype.slice.call($('tabs').childNodes, 0);
nodes.push($('export')); nodes.push($('export'));
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
nodes[i].textContent = nodes[i].textContent.replace('&', ''); nodes[i].textContent = nodes[i].textContent.replace('&', '');
} }
} }
/** /**
* Expand all nodes of the given tree object. * Expand all nodes of the given tree object.
* @param {!Tree} tree The tree object to expand all nodes on. * @param {!Tree} tree The tree object to expand all nodes on.
*/ */
function revealTree(tree) { function revealTree(tree) {
tree.expanded = true; tree.expanded = true;
for (const key in tree['detail'].children) { for (const key in tree['detail'].children) {
revealTree(tree['detail'].children[key]); revealTree(tree['detail'].children[key]);
} }
} }
/** /**
* This function is called from certificate_viewer_ui.cc with the certificate * This function is called from certificate_viewer_ui.cc with the certificate
* information. Display all returned information to the user. * information. Display all returned information to the user.
* @param {!CertificateInfo} certInfo Certificate information in named fields. * @param {!CertificateInfo} certInfo Certificate information in named fields.
*/ */
function getCertificateInfo(certInfo) { function getCertificateInfo(certInfo) {
for (const key in certInfo.general) { for (const key in certInfo.general) {
$(key).textContent = certInfo.general[key]; $(key).textContent = certInfo.general[key];
} }
} }
/** /**
* This function populates the certificate hierarchy. * This function populates the certificate hierarchy.
* @param {Object} hierarchy A dictionary containing the hierarchy. * @param {Object} hierarchy A dictionary containing the hierarchy.
*/ */
function createCertificateHierarchy(hierarchy) { function createCertificateHierarchy(hierarchy) {
const treeItem = /** @type {!Tree} */ ($('hierarchy')); const treeItem = /** @type {!Tree} */ ($('hierarchy'));
const root = constructTree(hierarchy[0]); const root = constructTree(hierarchy[0]);
treeItem['detail'].children['root'] = root; treeItem['detail'].children['root'] = root;
...@@ -141,14 +141,14 @@ import {$} from 'chrome://resources/js/util.m.js'; ...@@ -141,14 +141,14 @@ import {$} from 'chrome://resources/js/util.m.js';
last = last.detail.children[0]; last = last.detail.children[0];
} }
last.selected = true; last.selected = true;
} }
/** /**
* Constructs a TreeItem corresponding to the passed in tree * Constructs a TreeItem corresponding to the passed in tree
* @param {Object} tree Dictionary describing the tree structure. * @param {Object} tree Dictionary describing the tree structure.
* @return {!TreeItem} Tree node corresponding to the input dictionary. * @return {!TreeItem} Tree node corresponding to the input dictionary.
*/ */
function constructTree(tree) { function constructTree(tree) {
const treeItem = new TreeItem({ const treeItem = new TreeItem({
label: tree.label, label: tree.label,
detail: {payload: tree.payload ? tree.payload : {}, children: {}} detail: {payload: tree.payload ? tree.payload : {}, children: {}}
...@@ -160,37 +160,37 @@ import {$} from 'chrome://resources/js/util.m.js'; ...@@ -160,37 +160,37 @@ import {$} from 'chrome://resources/js/util.m.js';
} }
} }
return treeItem; return treeItem;
} }
/** /**
* Clear any previous certificate fields in the tree. * Clear any previous certificate fields in the tree.
*/ */
function clearCertificateFields() { function clearCertificateFields() {
const treeItem = /** @type {!Tree} */ ($('cert-fields')); const treeItem = /** @type {!Tree} */ ($('cert-fields'));
for (const key in treeItem['detail'].children) { for (const key in treeItem['detail'].children) {
treeItem.remove(treeItem['detail'].children[key]); treeItem.remove(treeItem['detail'].children[key]);
delete treeItem['detail'].children[key]; delete treeItem['detail'].children[key];
} }
} }
/** /**
* Request certificate fields for the selected certificate in the hierarchy. * Request certificate fields for the selected certificate in the hierarchy.
*/ */
function showCertificateFields() { function showCertificateFields() {
clearCertificateFields(); clearCertificateFields();
const item = $('hierarchy').selectedItem; const item = $('hierarchy').selectedItem;
if (item && item.detail.payload.index !== undefined) { if (item && item.detail.payload.index !== undefined) {
sendWithPromise('requestCertificateFields', item.detail.payload.index) sendWithPromise('requestCertificateFields', item.detail.payload.index)
.then(onCertificateFields); .then(onCertificateFields);
} }
} }
/** /**
* Show the returned certificate fields for the selected certificate. * Show the returned certificate fields for the selected certificate.
* @param {Object} certFields A dictionary containing the fields tree * @param {Object} certFields A dictionary containing the fields tree
* structure. * structure.
*/ */
function onCertificateFields(certFields) { function onCertificateFields(certFields) {
clearCertificateFields(); clearCertificateFields();
const treeItem = /** @type {!Tree} */ ($('cert-fields')); const treeItem = /** @type {!Tree} */ ($('cert-fields'));
treeItem.add( treeItem.add(
...@@ -200,28 +200,28 @@ import {$} from 'chrome://resources/js/util.m.js'; ...@@ -200,28 +200,28 @@ import {$} from 'chrome://resources/js/util.m.js';
treeItem.children[0].selected = true; treeItem.children[0].selected = true;
document.body.dispatchEvent( document.body.dispatchEvent(
new CustomEvent('certificate-fields-updated-for-testing')); new CustomEvent('certificate-fields-updated-for-testing'));
} }
/** /**
* Show certificate field value for a selected certificate field. * Show certificate field value for a selected certificate field.
*/ */
function showCertificateFieldValue() { function showCertificateFieldValue() {
const item = $('cert-fields').selectedItem; const item = $('cert-fields').selectedItem;
if (item && item.detail.payload.val) { if (item && item.detail.payload.val) {
$('cert-field-value').textContent = item.detail.payload.val; $('cert-field-value').textContent = item.detail.payload.val;
} else { } else {
$('cert-field-value').textContent = ''; $('cert-field-value').textContent = '';
} }
} }
/** /**
* Export the selected certificate. * Export the selected certificate.
*/ */
function exportCertificate() { function exportCertificate() {
const item = $('hierarchy').selectedItem; const item = $('hierarchy').selectedItem;
if (item && item.detail.payload.index !== undefined) { if (item && item.detail.payload.index !== undefined) {
chrome.send('exportCertificate', [item.detail.payload.index]); chrome.send('exportCertificate', [item.detail.payload.index]);
} }
} }
document.addEventListener('DOMContentLoaded', initialize); document.addEventListener('DOMContentLoaded', initialize);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment