Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / resources / options / certificate_tree.js
blob6be4eeb2413b3bd7bbe670aac0df988feef58e8f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @typedef {{
7 * id: string,
8 * name: string,
9 * subnodes: Array<{id: string, name: string, readonly: boolean,
10 * untrusted: boolean, extractable: boolean,
11 * policy: boolean}>
12 * }}
14 var CertificateData;
16 cr.define('options', function() {
17 /** @const */ var Tree = cr.ui.Tree;
18 /** @const */ var TreeItem = cr.ui.TreeItem;
20 /**
21 * Creates a new tree folder for certificate data.
22 * @param {Object=} data Data used to create a certificate tree folder.
23 * @constructor
24 * @extends {TreeItem}
26 function CertificateTreeFolder(data) {
27 data.isCert = false;
28 var treeFolder = new TreeItem({
29 label: data.name,
30 data: data
31 });
32 treeFolder.__proto__ = CertificateTreeFolder.prototype;
34 if (data.icon)
35 treeFolder.icon = data.icon;
37 return treeFolder;
40 CertificateTreeFolder.prototype = {
41 __proto__: TreeItem.prototype,
43 /**
44 * The tree path id/.
45 * @type {string}
47 get pathId() {
48 return this.data.id;
52 /**
53 * Creates a new tree item for certificate data.
54 * @param {Object=} data Data used to create a certificate tree item.
55 * @constructor
56 * @extends {TreeItem}
58 function CertificateTreeItem(data) {
59 data.isCert = true;
60 // TODO(mattm): other columns
61 var treeItem = new TreeItem({
62 label: data.name,
63 data: data
64 });
65 treeItem.__proto__ = CertificateTreeItem.prototype;
67 if (data.icon)
68 treeItem.icon = data.icon;
70 if (data.untrusted) {
71 var badge = document.createElement('span');
72 badge.classList.add('cert-untrusted');
73 badge.textContent = loadTimeData.getString('badgeCertUntrusted');
74 treeItem.labelElement.insertBefore(
75 badge, treeItem.labelElement.firstChild);
78 if (data.policy) {
79 var policyIndicator = new options.ControlledSettingIndicator();
80 policyIndicator.controlledBy = 'policy';
81 policyIndicator.setAttribute(
82 'textpolicy', loadTimeData.getString('certPolicyInstalled'));
83 policyIndicator.classList.add('cert-policy');
84 treeItem.labelElement.appendChild(policyIndicator);
87 return treeItem;
90 CertificateTreeItem.prototype = {
91 __proto__: TreeItem.prototype,
93 /**
94 * The tree path id/.
95 * @type {string}
97 get pathId() {
98 return this.parentItem.pathId + ',' + this.data.id;
103 * Creates a new cookies tree.
104 * @param {Object=} opt_propertyBag Optional properties.
105 * @constructor
106 * @extends {Tree}
108 var CertificatesTree = cr.ui.define('tree');
110 CertificatesTree.prototype = {
111 __proto__: Tree.prototype,
113 /** @override */
114 decorate: function() {
115 Tree.prototype.decorate.call(this);
116 this.treeLookup_ = {};
119 /** @override */
120 addAt: function(child, index) {
121 Tree.prototype.addAt.call(this, child, index);
122 if (child.data && child.data.id)
123 this.treeLookup_[child.data.id] = child;
126 /** @override */
127 remove: function(child) {
128 Tree.prototype.remove.call(this, child);
129 if (child.data && child.data.id)
130 delete this.treeLookup_[child.data.id];
134 * Clears the tree.
136 clear: function() {
137 // Remove all fields without recreating the object since other code
138 // references it.
139 for (var id in this.treeLookup_)
140 delete this.treeLookup_[id];
141 this.textContent = '';
145 * Populate the tree.
146 * @param {Array<CertificateData>} nodesData Nodes data array.
148 populate: function(nodesData) {
149 this.clear();
151 for (var i = 0; i < nodesData.length; ++i) {
152 var subnodes = nodesData[i].subnodes;
153 delete nodesData[i].subnodes;
155 var item = new CertificateTreeFolder(nodesData[i]);
156 this.addAt(item, i);
158 for (var j = 0; j < subnodes.length; ++j) {
159 var subitem = new CertificateTreeItem(subnodes[j]);
160 item.addAt(subitem, j);
162 // Make tree expanded by default.
163 item.expanded = true;
166 cr.dispatchSimpleEvent(this, 'change');
170 return {
171 CertificatesTree: CertificatesTree