Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Returns whether exceptions list for the type is editable. | 13 * Returns whether exceptions list for the type is editable. |
| 14 * | 14 * |
| 15 * @param {string} contentType The type of the list. | 15 * @param {string} contentType The type of the list. |
| 16 */ | 16 */ |
| 17 function IsEditableType(contentType) { | 17 function IsEditableType(contentType) { |
| 18 // Exceptions of the following lists are not editable for now. | 18 // Exceptions of the following lists are not editable for now. |
| 19 return !(contentType == 'location' || | 19 return !(contentType == 'location' || |
| 20 contentType == 'fullscreen' || | 20 contentType == 'fullscreen' || |
| 21 contentType == 'media-stream-mic' || | 21 contentType == 'media-stream-mic' || |
| 22 contentType == 'media-stream-camera' || | 22 contentType == 'media-stream-camera' || |
| 23 contentType == 'midi-sysex' || | 23 contentType == 'midi-sysex' || |
| 24 contentType == 'zoomlevels'); | 24 contentType == 'zoomlevels' || |
| 25 IsChosenObjectType(contentType)); | |
| 25 } | 26 } |
| 26 | 27 |
| 27 /** | 28 /** |
| 29 * Returns whether exceptions of this type represent chosen objects. | |
| 30 * | |
| 31 * @param {string} contentType The type of the list. | |
| 32 */ | |
| 33 function IsChosenObjectType(contentType) { | |
| 34 return contentType == 'usb-devices'; | |
| 35 } | |
| 36 | |
| 37 function ValueColumnForContentType(contentType) { | |
| 38 if (contentType == 'usb-devices') | |
| 39 return 'exception-usb-device-column'; | |
| 40 else if (contentType == 'zoomlevels') | |
|
Bernhard Bauer
2015/11/16 12:53:30
Else is not necessary if the previous branch retur
Reilly Grant (use Gerrit)
2015/11/16 22:18:27
Done.
| |
| 41 return 'exception-zoom-column'; | |
| 42 else | |
| 43 return 'exception-behavior-column'; | |
| 44 } | |
| 45 | |
| 46 /** | |
| 28 * Creates a new exceptions list item. | 47 * Creates a new exceptions list item. |
| 29 * | 48 * |
| 30 * @param {string} contentType The type of the list. | 49 * @param {string} contentType The type of the list. |
| 31 * @param {string} mode The browser mode, 'otr' or 'normal'. | 50 * @param {string} mode The browser mode, 'otr' or 'normal'. |
| 32 * @param {Object} exception A dictionary that contains the data of the | 51 * @param {Object} exception A dictionary that contains the data of the |
| 33 * exception. | 52 * exception. |
| 34 * @constructor | 53 * @constructor |
| 35 * @extends {options.InlineEditableItem} | 54 * @extends {options.InlineEditableItem} |
| 36 */ | 55 */ |
| 37 function ExceptionsListItem(contentType, mode, exception) { | 56 function ExceptionsListItem(contentType, mode, exception) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 this.editable = false; | 126 this.editable = false; |
| 108 } | 127 } |
| 109 | 128 |
| 110 if (this.setting == 'default') { | 129 if (this.setting == 'default') { |
| 111 // Items that don't have their own settings (parents of 'embedded on' | 130 // Items that don't have their own settings (parents of 'embedded on' |
| 112 // items) aren't deletable. | 131 // items) aren't deletable. |
| 113 this.deletable = false; | 132 this.deletable = false; |
| 114 this.editable = false; | 133 this.editable = false; |
| 115 } | 134 } |
| 116 | 135 |
| 117 if (this.contentType != 'zoomlevels') { | 136 if (this.contentType != 'zoomlevels' && |
| 137 !IsChosenObjectType(this.contentType)) { | |
| 118 this.addEditField(select, this.settingLabel); | 138 this.addEditField(select, this.settingLabel); |
| 119 this.contentElement.appendChild(select); | 139 this.contentElement.appendChild(select); |
| 120 } | 140 } |
| 121 select.className = 'exception-setting'; | 141 select.className = 'exception-setting'; |
| 122 select.setAttribute('aria-labelledby', 'exception-behavior-column'); | 142 select.setAttribute('aria-labelledby', |
| 143 ValueColumnForContentType(this.contentType)); | |
| 123 | 144 |
| 124 if (this.pattern) | 145 if (this.pattern) |
| 125 select.setAttribute('displaymode', 'edit'); | 146 select.setAttribute('displaymode', 'edit'); |
| 126 | 147 |
| 127 if (this.contentType == 'zoomlevels') { | 148 if (this.contentType == 'zoomlevels') { |
| 128 this.deletable = true; | 149 this.deletable = true; |
| 129 | 150 |
| 130 var zoomLabel = cr.doc.createElement('span'); | 151 var zoomLabel = cr.doc.createElement('span'); |
| 131 zoomLabel.textContent = this.dataItem.zoom; | 152 zoomLabel.textContent = this.dataItem.zoom; |
| 132 zoomLabel.className = 'exception-setting'; | 153 zoomLabel.className = 'exception-setting'; |
| 133 zoomLabel.setAttribute('displaymode', 'static'); | 154 zoomLabel.setAttribute('displaymode', 'static'); |
| 134 zoomLabel.setAttribute('aria-labelledby', 'exception-zoom-column'); | |
| 135 this.contentElement.appendChild(zoomLabel); | 155 this.contentElement.appendChild(zoomLabel); |
| 136 this.zoomLabel = zoomLabel; | 156 this.zoomLabel = zoomLabel; |
| 137 } | 157 } |
| 138 | 158 |
| 159 if (IsChosenObjectType(this.contentType) && | |
| 160 this.dataItem.hasOwnProperty('object')) { | |
|
Bernhard Bauer
2015/11/16 12:53:30
I don't think you need to work around any Javascri
Reilly Grant (use Gerrit)
2015/11/16 22:18:27
Done.
| |
| 161 this.deletable = true; | |
| 162 | |
| 163 var objectLabel = cr.doc.createElement('span'); | |
| 164 objectLabel.textContent = this.dataItem.objectName; | |
| 165 objectLabel.className = 'exception-setting'; | |
| 166 objectLabel.setAttribute('displaymode', 'static'); | |
| 167 this.contentElement.appendChild(objectLabel); | |
| 168 this.objectLabel = objectLabel; | |
| 169 } | |
| 170 | |
| 139 // Used to track whether the URL pattern in the input is valid. | 171 // Used to track whether the URL pattern in the input is valid. |
| 140 // This will be true if the browser process has informed us that the | 172 // This will be true if the browser process has informed us that the |
| 141 // current text in the input is valid. Changing the text resets this to | 173 // current text in the input is valid. Changing the text resets this to |
| 142 // false, and getting a response from the browser sets it back to true. | 174 // false, and getting a response from the browser sets it back to true. |
| 143 // It starts off as false for empty string (new exceptions) or true for | 175 // It starts off as false for empty string (new exceptions) or true for |
| 144 // already-existing exceptions (which we assume are valid). | 176 // already-existing exceptions (which we assume are valid). |
| 145 this.inputValidityKnown = this.pattern; | 177 this.inputValidityKnown = this.pattern; |
| 146 // This one tracks the actual validity of the pattern in the input. This | 178 // This one tracks the actual validity of the pattern in the input. This |
| 147 // starts off as true so as not to annoy the user when he adds a new and | 179 // starts off as true so as not to annoy the user when he adds a new and |
| 148 // empty input. | 180 // empty input. |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 574 } |
| 543 }, | 575 }, |
| 544 | 576 |
| 545 /** @override */ | 577 /** @override */ |
| 546 deleteItemAtIndex: function(index) { | 578 deleteItemAtIndex: function(index) { |
| 547 var listItem = this.getListItemByIndex(index); | 579 var listItem = this.getListItemByIndex(index); |
| 548 if (!listItem.deletable) | 580 if (!listItem.deletable) |
| 549 return; | 581 return; |
| 550 | 582 |
| 551 var dataItem = listItem.dataItem; | 583 var dataItem = listItem.dataItem; |
| 552 chrome.send('removeException', [listItem.contentType, | 584 if (IsChosenObjectType(this.contentType)) { |
| 553 listItem.mode, | 585 chrome.send('removeException', [listItem.contentType, |
| 554 dataItem.origin, | 586 listItem.mode, |
| 555 dataItem.embeddingOrigin]); | 587 dataItem.origin, |
| 588 dataItem.embeddingOrigin, | |
| 589 dataItem.object]); | |
| 590 } else { | |
| 591 chrome.send('removeException', [listItem.contentType, | |
| 592 listItem.mode, | |
| 593 dataItem.origin, | |
| 594 dataItem.embeddingOrigin]); | |
| 595 } | |
| 556 }, | 596 }, |
| 557 }; | 597 }; |
| 558 | 598 |
| 559 var Page = cr.ui.pageManager.Page; | 599 var Page = cr.ui.pageManager.Page; |
| 560 var PageManager = cr.ui.pageManager.PageManager; | 600 var PageManager = cr.ui.pageManager.PageManager; |
| 561 | 601 |
| 562 /** | 602 /** |
| 563 * Encapsulated handling of content settings list subpage. | 603 * Encapsulated handling of content settings list subpage. |
| 564 * | 604 * |
| 565 * @constructor | 605 * @constructor |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 header.textContent = loadTimeData.getString(camelCasedType + 'Header'); | 650 header.textContent = loadTimeData.getString(camelCasedType + 'Header'); |
| 611 | 651 |
| 612 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | 652 var divs = this.pageDiv.querySelectorAll('div[contentType]'); |
| 613 for (var i = 0; i < divs.length; i++) { | 653 for (var i = 0; i < divs.length; i++) { |
| 614 if (divs[i].getAttribute('contentType') == type) | 654 if (divs[i].getAttribute('contentType') == type) |
| 615 divs[i].hidden = false; | 655 divs[i].hidden = false; |
| 616 else | 656 else |
| 617 divs[i].hidden = true; | 657 divs[i].hidden = true; |
| 618 } | 658 } |
| 619 | 659 |
| 620 $('exception-behavior-column').hidden = type == 'zoomlevels'; | 660 var valueColumnId = ValueColumnForContentType(type); |
| 621 $('exception-zoom-column').hidden = type != 'zoomlevels'; | 661 this.pageDiv.querySelectorAll('div.exception-value-column-header') |
| 662 .forEach(function(div) { div.hidden = (div.id != valueColumnId); }); | |
|
Bernhard Bauer
2015/11/16 12:53:30
Move the code inside the loop to a new line?
Reilly Grant (use Gerrit)
2015/11/16 22:18:27
Done.
| |
| 622 }, | 663 }, |
| 623 | 664 |
| 624 /** | 665 /** |
| 625 * Called after the page has been shown. Show the content type for the | 666 * Called after the page has been shown. Show the content type for the |
| 626 * location's hash. | 667 * location's hash. |
| 627 */ | 668 */ |
| 628 didShowPage: function() { | 669 didShowPage: function() { |
| 629 if (this.hash) | 670 if (this.hash) |
| 630 this.showList(this.hash.slice(1)); | 671 this.showList(this.hash.slice(1)); |
| 631 }, | 672 }, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 652 } | 693 } |
| 653 }; | 694 }; |
| 654 | 695 |
| 655 return { | 696 return { |
| 656 ExceptionsListItem: ExceptionsListItem, | 697 ExceptionsListItem: ExceptionsListItem, |
| 657 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 698 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 658 ExceptionsList: ExceptionsList, | 699 ExceptionsList: ExceptionsList, |
| 659 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 700 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
| 660 }; | 701 }; |
| 661 }); | 702 }); |
| OLD | NEW |