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';
import {Tree, TreeItem} from 'chrome://resources/js/cr/ui/tree.m.js';
import {$} from 'chrome://resources/js/util.m.js';
/**
/**
* @typedef {{
* general: !Object,
* hierarchy: !Object,
* }}
*/
let CertificateInfo;
let CertificateInfo;
/**
/**
* Initialize the certificate viewer dialog by wiring up the close button,
* substituting in translated strings and requesting certificate details.
*/
function initialize() {
function initialize() {
decorate('tabbox', TabBox);
const args = JSON.parse(chrome.getVariableValue('dialogArguments'));
......@@ -58,12 +58,12 @@ import {$} from 'chrome://resources/js/util.m.js';
stripGtkAccessorKeys();
$('export').onclick = exportCertificate;
}
}
/**
/**
* Decorate a function so that it can only be invoked once.
*/
function oneShot(fn) {
function oneShot(fn) {
let fired = false;
return function() {
if (fired) {
......@@ -72,62 +72,62 @@ import {$} from 'chrome://resources/js/util.m.js';
fired = true;
fn();
};
}
}
/**
/**
* Initialize a Tree object from a given element using the specified
* change handler.
* @param {!HTMLElement} tree The HTMLElement to style as a tree.
* @param {function()} handler Function to call when a node is selected.
*/
function initializeTree(tree, handler) {
function initializeTree(tree, handler) {
decorate(tree, Tree);
tree['detail'] = {payload: {}, children: {}};
tree.addEventListener('change', handler);
}
}
/**
/**
* The tab name strings in the languages file have accessor keys indicated
* by a preceding & sign. Strip these out for now.
* TODO(flackr) These accessor keys could be implemented with Javascript or
* translated strings could be added / modified to remove the & sign.
*/
function stripGtkAccessorKeys() {
function stripGtkAccessorKeys() {
// Copy all the tab labels into an array.
const nodes = Array.prototype.slice.call($('tabs').childNodes, 0);
nodes.push($('export'));
for (let i = 0; i < nodes.length; i++) {
nodes[i].textContent = nodes[i].textContent.replace('&', '');
}
}
}
/**
/**
* Expand all nodes of the given tree object.
* @param {!Tree} tree The tree object to expand all nodes on.
*/
function revealTree(tree) {
function revealTree(tree) {
tree.expanded = true;
for (const key in tree['detail'].children) {
revealTree(tree['detail'].children[key]);
}
}
}
/**
/**
* This function is called from certificate_viewer_ui.cc with the certificate
* information. Display all returned information to the user.
* @param {!CertificateInfo} certInfo Certificate information in named fields.
*/
function getCertificateInfo(certInfo) {
function getCertificateInfo(certInfo) {
for (const key in certInfo.general) {
$(key).textContent = certInfo.general[key];
}
}
}
/**
/**
* This function populates the certificate hierarchy.
* @param {Object} hierarchy A dictionary containing the hierarchy.
*/
function createCertificateHierarchy(hierarchy) {
function createCertificateHierarchy(hierarchy) {
const treeItem = /** @type {!Tree} */ ($('hierarchy'));
const root = constructTree(hierarchy[0]);
treeItem['detail'].children['root'] = root;
......@@ -141,14 +141,14 @@ import {$} from 'chrome://resources/js/util.m.js';
last = last.detail.children[0];
}
last.selected = true;
}
}
/**
/**
* Constructs a TreeItem corresponding to the passed in tree
* @param {Object} tree Dictionary describing the tree structure.
* @return {!TreeItem} Tree node corresponding to the input dictionary.
*/
function constructTree(tree) {
function constructTree(tree) {
const treeItem = new TreeItem({
label: tree.label,
detail: {payload: tree.payload ? tree.payload : {}, children: {}}
......@@ -160,37 +160,37 @@ import {$} from 'chrome://resources/js/util.m.js';
}
}
return treeItem;
}
}
/**
/**
* Clear any previous certificate fields in the tree.
*/
function clearCertificateFields() {
function clearCertificateFields() {
const treeItem = /** @type {!Tree} */ ($('cert-fields'));
for (const key in treeItem['detail'].children) {
treeItem.remove(treeItem['detail'].children[key]);
delete treeItem['detail'].children[key];
}
}
}
/**
/**
* Request certificate fields for the selected certificate in the hierarchy.
*/
function showCertificateFields() {
function showCertificateFields() {
clearCertificateFields();
const item = $('hierarchy').selectedItem;
if (item && item.detail.payload.index !== undefined) {
sendWithPromise('requestCertificateFields', item.detail.payload.index)
.then(onCertificateFields);
}
}
}
/**
/**
* Show the returned certificate fields for the selected certificate.
* @param {Object} certFields A dictionary containing the fields tree
* structure.
*/
function onCertificateFields(certFields) {
function onCertificateFields(certFields) {
clearCertificateFields();
const treeItem = /** @type {!Tree} */ ($('cert-fields'));
treeItem.add(
......@@ -200,28 +200,28 @@ import {$} from 'chrome://resources/js/util.m.js';
treeItem.children[0].selected = true;
document.body.dispatchEvent(
new CustomEvent('certificate-fields-updated-for-testing'));
}
}
/**
/**
* Show certificate field value for a selected certificate field.
*/
function showCertificateFieldValue() {
function showCertificateFieldValue() {
const item = $('cert-fields').selectedItem;
if (item && item.detail.payload.val) {
$('cert-field-value').textContent = item.detail.payload.val;
} else {
$('cert-field-value').textContent = '';
}
}
}
/**
/**
* Export the selected certificate.
*/
function exportCertificate() {
function exportCertificate() {
const item = $('hierarchy').selectedItem;
if (item && item.detail.payload.index !== undefined) {
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