Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/resources/policy.js

Issue 17387002: Sending known policy names for extensions to chrome://policy page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@anita-policies
Patch Set: Sending known policy names for extensions Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('policy', function() { 5 cr.define('policy', function() {
6 /** 6 /**
7 * A box that shows the status of cloud policy for a device or user. 7 * A box that shows the status of cloud policy for a device or user.
8 * @constructor 8 * @constructor
9 * @extends {HTMLFieldSetElement} 9 * @extends {HTMLFieldSetElement}
10 */ 10 */
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 this.querySelector('.toggle-expanded-value').addEventListener( 81 this.querySelector('.toggle-expanded-value').addEventListener(
82 'click', this.toggleExpandedValue_.bind(this)); 82 'click', this.toggleExpandedValue_.bind(this));
83 }, 83 },
84 84
85 /** 85 /**
86 * Populate the table columns with information about the policy name, value 86 * Populate the table columns with information about the policy name, value
87 * and status. 87 * and status.
88 * @param {string} name The policy name. 88 * @param {string} name The policy name.
89 * @param {Object} value Dictionary with information about the policy value. 89 * @param {Object} value Dictionary with information about the policy value.
90 * @param {boolean} unknown Whether the policy name is not recognized. 90 * @param {boolean} unknown Whether the policy name is not recognized.
91 * @param {boolean} includeStatus Whether the table has a status column.
92 */ 91 */
93 initialize: function(name, value, unknown, includeStatus) { 92 initialize: function(name, value, unknown) {
94 this.name = name; 93 this.name = name;
95 this.unset = !value; 94 this.unset = !value;
96 95
97 // Populate the name column. 96 // Populate the name column.
98 this.querySelector('.name').textContent = name; 97 this.querySelector('.name').textContent = name;
99 98
100 // Populate the remaining columns with policy scope, level and value if a 99 // Populate the remaining columns with policy scope, level and value if a
101 // value has been set. Otherwise, leave them blank. 100 // value has been set. Otherwise, leave them blank.
102 if (value) { 101 if (value) {
103 this.querySelector('.scope').textContent = 102 this.querySelector('.scope').textContent =
104 loadTimeData.getString(value.scope == 'user' ? 103 loadTimeData.getString(value.scope == 'user' ?
105 'scopeUser' : 'scopeDevice'); 104 'scopeUser' : 'scopeDevice');
106 this.querySelector('.level').textContent = 105 this.querySelector('.level').textContent =
107 loadTimeData.getString(value.level == 'recommended' ? 106 loadTimeData.getString(value.level == 'recommended' ?
108 'levelRecommended' : 'levelMandatory'); 107 'levelRecommended' : 'levelMandatory');
109 this.querySelector('.value').textContent = value.value; 108 this.querySelector('.value').textContent = value.value;
110 this.querySelector('.expanded-value').textContent = value.value; 109 this.querySelector('.expanded-value').textContent = value.value;
111 } 110 }
112 111
113 if (includeStatus) { 112 // Populate the status column.
114 // Populate the status column. 113 var status;
115 var status; 114 if (!value) {
116 if (!value) { 115 // If the policy value has not been set, show an error message.
117 // If the policy value has not been set, show an error message. 116 status = loadTimeData.getString('unset');
118 status = loadTimeData.getString('unset'); 117 } else if (unknown) {
119 } else if (unknown) { 118 // If the policy name is not recognized, show an error message.
120 // If the policy name is not recognized, show an error message. 119 status = loadTimeData.getString('unknown');
121 status = loadTimeData.getString('unknown'); 120 } else if (value.error) {
122 } else if (value.error) { 121 // If an error occurred while parsing the policy value, show the error
123 // If an error occurred while parsing the policy value, show the error 122 // message.
124 // message. 123 status = value.error;
125 status = value.error;
126 } else {
127 // Otherwise, indicate that the policy value was parsed correctly.
128 status = loadTimeData.getString('ok');
129 }
130 this.querySelector('.status').textContent = status;
131 } else { 124 } else {
132 // Remove status column. 125 // Otherwise, indicate that the policy value was parsed correctly.
133 this.querySelector('.status-container').remove(); 126 status = loadTimeData.getString('ok');
134 this.querySelector('.expanded-value').setAttribute('colspan', 4);
135 } 127 }
128 this.querySelector('.status').textContent = status;
136 }, 129 },
137 130
138 /** 131 /**
139 * Check the table columns for overflow. Most columns are automatically 132 * Check the table columns for overflow. Most columns are automatically
140 * elided when overflow occurs. The only action required is to add a tooltip 133 * elided when overflow occurs. The only action required is to add a tooltip
141 * that shows the complete content. The value column is an exception. If 134 * that shows the complete content. The value column is an exception. If
142 * overflow occurs here, the contents is replaced with a link that toggles 135 * overflow occurs here, the contents is replaced with a link that toggles
143 * the visibility of an additional row containing the complete value. 136 * the visibility of an additional row containing the complete value.
144 */ 137 */
145 checkOverflow: function() { 138 checkOverflow: function() {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 293
301 /** 294 /**
302 * Add a policy with the given |name| and |value| to the table. 295 * Add a policy with the given |name| and |value| to the table.
303 * @param {string} name The policy name. 296 * @param {string} name The policy name.
304 * @param {Object} value Dictionary with information about the policy value. 297 * @param {Object} value Dictionary with information about the policy value.
305 * @param {boolean} unknown Whether the policy name is not recoginzed. 298 * @param {boolean} unknown Whether the policy name is not recoginzed.
306 * @private 299 * @private
307 */ 300 */
308 setPolicyValue_: function(name, value, unknown) { 301 setPolicyValue_: function(name, value, unknown) {
309 var policy = new Policy; 302 var policy = new Policy;
310 var includeStatus = this.querySelector('.status-column') != null; 303 policy.initialize(name, value, unknown);
311 policy.initialize(name, value, unknown, includeStatus);
312 this.appendChild(policy); 304 this.appendChild(policy);
313 }, 305 },
314 }; 306 };
315 307
316 /** 308 /**
317 * A singelton object that handles communication between browser and WebUI. 309 * A singelton object that handles communication between browser and WebUI.
318 * @constructor 310 * @constructor
319 */ 311 */
320 function Page() { 312 function Page() {
321 } 313 }
322 314
323 // Make Page a singleton. 315 // Make Page a singleton.
324 cr.addSingletonGetter(Page); 316 cr.addSingletonGetter(Page);
325 317
326 /** 318 /**
327 * Provide a list of all known policies to the UI. Called by the browser on 319 * Provide a list of all known policies to the UI. Called by the browser on
328 * page load. 320 * page load.
329 * @param {Object} names Dictionary containing all known policy names. 321 * @param {Object} names Dictionary containing all known policy names.
330 */ 322 */
331 Page.setPolicyNames = function(names) { 323 Page.setPolicyNames = function(names) {
332 var table = this.getInstance().policyTables['chrome']; 324 var page = this.getInstance();
333 table.setPolicyNames(names); 325 if (names.hasOwnProperty('chromePolicyNames')) {
326 var table = page.policyTables['chrome'];
327 table.setPolicyNames(names.chromePolicyNames);
328 }
329 if (names.hasOwnProperty('extensionPolicyNames')) {
330 for (var ext in names.extensionPolicyNames) {
331 var table = page.getOrCreateTable('extension-' + ext,
332 names.extensionPolicyNames[ext].name, 'ID: ' + ext);
333 table.setPolicyNames(names.extensionPolicyNames[ext].policyNames);
334 }
335 }
334 }; 336 };
335 337
336 /** 338 /**
337 * Provide a list of the currently set policy values and any errors detected 339 * Provide a list of the currently set policy values and any errors detected
338 * while parsing these to the UI. Called by the browser on page load and 340 * while parsing these to the UI. Called by the browser on page load and
339 * whenever policy values change. 341 * whenever policy values change.
340 * @param {Object} values Dictionary containing the current policy values. 342 * @param {Object} values Dictionary containing the current policy values.
341 */ 343 */
342 Page.setPolicyValues = function(values) { 344 Page.setPolicyValues = function(values) {
343 var page = this.getInstance(); 345 var page = this.getInstance();
344
345 if (values.hasOwnProperty('chromePolicies')) { 346 if (values.hasOwnProperty('chromePolicies')) {
346 var table = page.policyTables['chrome']; 347 var table = page.policyTables['chrome'];
347 table.setPolicyValues(values.chromePolicies); 348 table.setPolicyValues(values.chromePolicies);
348 } 349 }
349 350
350 if (values.hasOwnProperty('extensionPolicies')) { 351 if (values.hasOwnProperty('extensionPolicies')) {
351 for (var extensionId in values.extensionPolicies) { 352 for (var extensionId in values.extensionPolicies) {
352 var tableId = 'extension-' + extensionId; 353 var table = page.policyTables['extension-' + extensionId];
353 var table = page.policyTables[tableId]; 354 if (table)
354 if (!table) { 355 table.setPolicyValues(values.extensionPolicies[extensionId]);
355 var tableName = values.extensionPolicies[extensionId].name;
356 table = page.createTable(tableId, tableName, 'ID: ' + extensionId,
357 false);
358 }
359 table.setPolicyValues(values.extensionPolicies[extensionId].policies);
360 } 356 }
361 } 357 }
362 }; 358 };
363 359
364 /** 360 /**
365 * Provide the current cloud policy status to the UI. Called by the browser on 361 * Provide the current cloud policy status to the UI. Called by the browser on
366 * page load if cloud policy is present and whenever the status changes. 362 * page load if cloud policy is present and whenever the status changes.
367 * @param {Object} status Dictionary containing the current policy status. 363 * @param {Object} status Dictionary containing the current policy status.
368 */ 364 */
369 Page.setStatus = function(status) { 365 Page.setStatus = function(status) {
(...skipping 10 matching lines...) Expand all
380 376
381 Page.prototype = { 377 Page.prototype = {
382 /** 378 /**
383 * Main initialization function. Called by the browser on page load. 379 * Main initialization function. Called by the browser on page load.
384 */ 380 */
385 initialize: function() { 381 initialize: function() {
386 uber.onContentFrameLoaded(); 382 uber.onContentFrameLoaded();
387 383
388 this.mainSection = $('main-section'); 384 this.mainSection = $('main-section');
389 this.policyTables = {}; 385 this.policyTables = {};
390 this.createTable('chrome', 'Chrome policies', '', true); 386 var chromeTable = this.createTable('chrome', 'Chrome policies', '');
387 this.mainSection.appendChild(chromeTable);
391 388
392 // Place the initial focus on the filter input field. 389 // Place the initial focus on the filter input field.
393 $('filter').focus(); 390 $('filter').focus();
394 391
395 var self = this; 392 var self = this;
396 $('filter').onsearch = function(event) { 393 $('filter').onsearch = function(event) {
397 for (policyTable in self.policyTables) { 394 for (policyTable in self.policyTables) {
398 self.policyTables[policyTable].setFilterPattern(this.value); 395 self.policyTables[policyTable].setFilterPattern(this.value);
399 } 396 }
400 }; 397 };
401 $('reload-policies').onclick = function(event) { 398 $('reload-policies').onclick = function(event) {
402 this.disabled = true; 399 this.disabled = true;
403 chrome.send('reloadPolicies'); 400 chrome.send('reloadPolicies');
404 }; 401 };
405 402
406 $('show-unset').onchange = function() { 403 $('show-unset').onchange = function() {
407 for (policyTable in self.policyTables) { 404 for (policyTable in self.policyTables) {
408 self.policyTables[policyTable].filter(); 405 self.policyTables[policyTable].filter();
409 } 406 }
410 }; 407 };
411 408
412 // Notify the browser that the page has loaded, causing it to send the 409 // Notify the browser that the page has loaded, causing it to send the
413 // list of all known policies, the current policy values and the cloud 410 // list of all known policies, the current policy values and the cloud
414 // policy status. 411 // policy status.
415 chrome.send('initialized'); 412 chrome.send('initialized');
416 }, 413 },
417 414
418 /** 415 /**
419 * Creates a new table and adds it to the main section. 416 * Gets the existing policy table for the given id, or if none exists,
417 * creates a new table and adds it to the page.
420 * @param {string} id Used as key when storing new table in policyTables. 418 * @param {string} id Used as key when storing new table in policyTables.
421 * @param {string} label_title Title for this policy table. 419 * @param {string} label_title Title for this policy table.
422 * @param {string} label_content Description for the policy table. 420 * @param {string} label_content Description for the policy table.
423 * @param {boolean} includeStatus Whether to display a status column.
424 */ 421 */
425 createTable: function(id, label_title, label_content, includeStatus) { 422 getOrCreateTable: function(id, label_title, label_content) {
423 if (this.policyTables.hasOwnProperty(id))
424 return this.policyTables[id];
425 else {
426 var section = this.createTable(id, label_title, label_content);
427 this.mainSection.appendChild(section);
428 return section.getElementsByTagName('table')[0];
429 }
430 },
431
432 /**
433 * Creates a new table for displaying policies.
434 * @param {string} id Used as key when storing new table in policyTables.
435 * @param {string} label_title Title for this policy table.
436 * @param {string} label_content Description for the policy table.
437 */
438 createTable: function(id, label_title, label_content) {
439 if (this.policyTables.hasOwnProperty(id)) {
440 return this.policyTables[id];
441 }
426 var section = document.createElement('section'); 442 var section = document.createElement('section');
427 443
428 // Add title and description. 444 // Add title and description.
429 var title = window.document.createElement('h3'); 445 var title = window.document.createElement('h3');
430 title.textContent = label_title; 446 title.textContent = label_title;
431 section.appendChild(title); 447 section.appendChild(title);
432 448
433 if (label_content) { 449 if (label_content) {
434 var description = window.document.createElement('div'); 450 var description = window.document.createElement('div');
435 description.classList.add('table-description'); 451 description.classList.add('table-description');
436 description.textContent = label_content; 452 description.textContent = label_content;
437 section.appendChild(description); 453 section.appendChild(description);
438 } 454 }
439 455
440 // Add 'No Policies Set' element. 456 // Add 'No Policies Set' element.
441 var noPolicies = window.document.createElement('div'); 457 var noPolicies = window.document.createElement('div');
442 noPolicies.classList.add('no-policies-set'); 458 noPolicies.classList.add('no-policies-set');
443 noPolicies.textContent = loadTimeData.getString('noPoliciesSet'); 459 noPolicies.textContent = loadTimeData.getString('noPoliciesSet');
444 section.appendChild(noPolicies); 460 section.appendChild(noPolicies);
445 461
446 // Add table of policies 462 // Add table of policies
447 var newTable = window.document.createElement('table'); 463 var newTable = window.document.createElement('table');
448 var tableHead = window.document.createElement('thead'); 464 var tableHead = window.document.createElement('thead');
449 var tableRow = window.document.createElement('tr'); 465 var tableRow = window.document.createElement('tr');
450 var tableHeadings = ['headerScope', 'headerLevel', 466 var tableHeadings = ['headerScope', 'headerLevel',
451 'headerName', 'headerValue']; 467 'headerName', 'headerValue', 'headerStatus'];
452 for (var i = 0; i < tableHeadings.length; i++) { 468 for (var i = 0; i < tableHeadings.length; i++) {
453 var tableHeader = window.document.createElement('th'); 469 var tableHeader = window.document.createElement('th');
454 tableHeader.textContent = loadTimeData.getString(tableHeadings[i]); 470 tableHeader.textContent = loadTimeData.getString(tableHeadings[i]);
455 tableRow.appendChild(tableHeader); 471 tableRow.appendChild(tableHeader);
456 } 472 }
457
458 if (includeStatus) {
459 var statusHeader = window.document.createElement('th');
460 statusHeader.classList.add('status-column');
461 statusHeader.textContent = loadTimeData.getString('headerStatus');
462 tableRow.appendChild(statusHeader);
463 }
464
465 tableHead.appendChild(tableRow); 473 tableHead.appendChild(tableRow);
466 newTable.appendChild(tableHead); 474 newTable.appendChild(tableHead);
467 cr.ui.decorate(newTable, PolicyTable); 475 cr.ui.decorate(newTable, PolicyTable);
468 476
469 section.appendChild(newTable); 477 section.appendChild(newTable);
470 section.setAttribute('class', 'policy-table-section'); 478 section.setAttribute('class', 'policy-table-section');
471 479
472 this.mainSection.appendChild(section);
473 this.policyTables[id] = newTable; 480 this.policyTables[id] = newTable;
474 return newTable; 481 return section;
475 }, 482 },
476 483
477 /** 484 /**
478 * Update the status section of the page to show the current cloud policy 485 * Update the status section of the page to show the current cloud policy
479 * status. 486 * status.
480 * @param {Object} status Dictionary containing the current policy status. 487 * @param {Object} status Dictionary containing the current policy status.
481 */ 488 */
482 setStatus: function(status) { 489 setStatus: function(status) {
483 // Remove any existing status boxes. 490 // Remove any existing status boxes.
484 var container = $('status-box-container'); 491 var container = $('status-box-container');
(...skipping 25 matching lines...) Expand all
510 return { 517 return {
511 Page: Page 518 Page: Page
512 }; 519 };
513 }); 520 });
514 521
515 // Have the main initialization function be called when the page finishes 522 // Have the main initialization function be called when the page finishes
516 // loading. 523 // loading.
517 document.addEventListener( 524 document.addEventListener(
518 'DOMContentLoaded', 525 'DOMContentLoaded',
519 policy.Page.getInstance().initialize.bind(policy.Page.getInstance())); 526 policy.Page.getInstance().initialize.bind(policy.Page.getInstance()));
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/policy_ui.cc » ('j') | chrome/browser/ui/webui/policy_ui.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698