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

Side by Side Diff: chrome/browser/resources/options/content_settings_exceptions_area.js

Issue 1855393006: [Chrome Settings UI] If User Exceptions are not allowed, prevent editing / viewing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix incorrect ArrayDataModel.splice() usage. Created 4 years, 7 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) 2012 The Chromium Authors. All rights reserved. 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 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('options.contentSettings', function() { 5 cr.define('options.contentSettings', function() {
6 /** @const */ var ControlledSettingIndicator = 6 /** @const */ var ControlledSettingIndicator =
7 options.ControlledSettingIndicator; 7 options.ControlledSettingIndicator;
8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; 8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList;
9 /** @const */ var InlineEditableItem = options.InlineEditableItem; 9 /** @const */ var InlineEditableItem = options.InlineEditableItem;
10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; 10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 entry); 513 entry);
514 } else { 514 } else {
515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, 515 var addRowItem = new ExceptionsAddRowListItem(this.contentType,
516 this.mode); 516 this.mode);
517 addRowItem.deletable = false; 517 addRowItem.deletable = false;
518 return addRowItem; 518 return addRowItem;
519 } 519 }
520 }, 520 },
521 521
522 /** 522 /**
523 * Updates visibility of each row, depending on content.
524 */
525 updateRowVisibility: function() {
526 // Rows with user exceptions are visible iff this.isEditable().
527 // All other rows are visible.
528 var isEditable = this.isEditable();
529 for (var index = 0; index < this.dataModel.length; ++index) {
530 var item = this.getListItemByIndex(index);
531 if (item.dataItem.source == 'preference')
532 item.hidden = !isEditable;
533 }
534 },
535
536 /**
537 * Sets whether user is allowed to set preference exceptions. Updates UI.
538 *
539 * @param {string} allowEdit Whether or not user may set preference
540 * exceptions.
541 */
542 setAllowEdit: function(allowEdit) {
543 var oldIsEditable = this.isEditable();
544 this.allowEdit = allowEdit;
545 var newIsEditable = this.isEditable();
546
547 // If visibility changed, add or remove the Add New Exception row.
548 if (oldIsEditable != newIsEditable) {
549 var oldSize = this.dataModel.length;
550 if (newIsEditable) {
551 this.dataModel.push(null);
552 } else {
553 this.dataModel.splice(oldSize - 1, 1); // pop.
Evan Stade 2016/04/26 16:05:16 I would be in favor of adding pop to ArrayDataMode
huangs 2016/04/26 17:37:03 ArrayDataModel stores raw list of data in |this.ar
Evan Stade 2016/04/26 22:58:09 Don't you think pop() would be useful in other pla
huangs 2016/04/26 23:18:20 My preference is to keep the CL small. It seems a
Dan Beam 2016/04/27 02:29:39 i don't really know much about ArrayDataModel, but
huangs 2016/04/27 14:28:01 Added pop(). It returns the last item as well, for
554 }
555 }
556 this.updateRowVisibility();
557 },
558
559 /**
523 * Sets the exceptions in the js model. 560 * Sets the exceptions in the js model.
524 * 561 *
525 * @param {Array<options.Exception>} entries A list of dictionaries of 562 * @param {Array<options.Exception>} entries A list of dictionaries of
526 * values, each dictionary represents an exception. 563 * values, each dictionary represents an exception.
527 */ 564 */
528 setExceptions: function(entries) { 565 setExceptions: function(entries) {
529 var deleteCount = this.dataModel.length; 566 var deleteCount = this.dataModel.length;
530 567
531 if (this.isEditable()) { 568 if (this.isEditable()) {
532 // We don't want to remove the Add New Exception row. 569 // We don't want to remove the Add New Exception row.
533 deleteCount = deleteCount - 1; 570 deleteCount = deleteCount - 1;
534 } 571 }
535 572
536 var args = [0, deleteCount]; 573 var args = [0, deleteCount];
537 args.push.apply(args, entries); 574 args.push.apply(args, entries);
538 this.dataModel.splice.apply(this.dataModel, args); 575 this.dataModel.splice.apply(this.dataModel, args);
576 this.updateRowVisibility();
539 }, 577 },
540 578
541 /** 579 /**
542 * The browser has finished checking a pattern for validity. Update the list 580 * The browser has finished checking a pattern for validity. Update the list
543 * item to reflect this. 581 * item to reflect this.
544 * 582 *
545 * @param {string} pattern The pattern. 583 * @param {string} pattern The pattern.
546 * @param {boolean} valid Whether said pattern is valid in the context of a 584 * @param {boolean} valid Whether said pattern is valid in the context of a
547 * content exception setting. 585 * content exception setting.
548 */ 586 */
549 patternValidityCheckComplete: function(pattern, valid) { 587 patternValidityCheckComplete: function(pattern, valid) {
550 var listItems = this.items; 588 var listItems = this.items;
551 for (var i = 0; i < listItems.length; i++) { 589 for (var i = 0; i < listItems.length; i++) {
552 var listItem = listItems[i]; 590 var listItem = listItems[i];
553 // Don't do anything for messages for the item if it is not the intended 591 // Don't do anything for messages for the item if it is not the intended
554 // recipient, or if the response is stale (i.e. the input value has 592 // recipient, or if the response is stale (i.e. the input value has
555 // changed since we sent the request to analyze it). 593 // changed since we sent the request to analyze it).
556 if (pattern == listItem.input.value) 594 if (pattern == listItem.input.value)
557 listItem.setPatternValid(valid); 595 listItem.setPatternValid(valid);
558 } 596 }
559 }, 597 },
560 598
561 /** 599 /**
562 * Returns whether the rows are editable in this list. 600 * Returns whether the rows are editable in this list.
563 */ 601 */
564 isEditable: function() { 602 isEditable: function() {
565 // Exceptions of the following lists are not editable for now. 603 return this.allowEdit && isEditableType(this.contentType);
566 return isEditableType(this.contentType);
567 }, 604 },
568 605
569 /** 606 /**
570 * Removes all exceptions from the js model. 607 * Removes all exceptions from the js model.
571 */ 608 */
572 reset: function() { 609 reset: function() {
610 this.allowEdit = true;
573 if (this.isEditable()) { 611 if (this.isEditable()) {
574 // The null creates the Add New Exception row. 612 // The null creates the Add New Exception row.
575 this.dataModel = new ArrayDataModel([null]); 613 this.dataModel = new ArrayDataModel([null]);
576 } else { 614 } else {
577 this.dataModel = new ArrayDataModel([]); 615 this.dataModel = new ArrayDataModel([]);
578 } 616 }
579 }, 617 },
580 618
581 /** @override */ 619 /** @override */
582 deleteItemAtIndex: function(index) { 620 deleteItemAtIndex: function(index) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 734 }
697 }; 735 };
698 736
699 return { 737 return {
700 ExceptionsListItem: ExceptionsListItem, 738 ExceptionsListItem: ExceptionsListItem,
701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, 739 ExceptionsAddRowListItem: ExceptionsAddRowListItem,
702 ExceptionsList: ExceptionsList, 740 ExceptionsList: ExceptionsList,
703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, 741 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea,
704 }; 742 };
705 }); 743 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/content_settings.js ('k') | chrome/browser/ui/webui/options/content_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698