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) { |
|
Dan Beam
2015/12/02 04:09:49
ah, this shouldn't be capitalized either. bummer
| |
| 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) { | |
|
Dan Beam
2015/12/02 04:09:49
should be isChosenObjectType
| |
| 34 return contentType == 'usb-devices'; | |
| 35 } | |
| 36 | |
| 37 function ValueColumnForContentType(contentType) { | |
|
Dan Beam
2015/12/02 04:09:49
valueColumnForContentType
| |
| 38 if (contentType == 'usb-devices') | |
| 39 return 'exception-usb-device-column'; | |
| 40 if (contentType == 'zoomlevels') | |
| 41 return 'exception-zoom-column'; | |
| 42 return 'exception-behavior-column'; | |
| 43 } | |
| 44 | |
| 45 /** | |
| 28 * Creates a new exceptions list item. | 46 * Creates a new exceptions list item. |
| 29 * | 47 * |
| 30 * @param {string} contentType The type of the list. | 48 * @param {string} contentType The type of the list. |
| 31 * @param {string} mode The browser mode, 'otr' or 'normal'. | 49 * @param {string} mode The browser mode, 'otr' or 'normal'. |
| 32 * @param {Object} exception A dictionary that contains the data of the | 50 * @param {Object} exception A dictionary that contains the data of the |
| 33 * exception. | 51 * exception. |
| 34 * @constructor | 52 * @constructor |
| 35 * @extends {options.InlineEditableItem} | 53 * @extends {options.InlineEditableItem} |
| 36 */ | 54 */ |
| 37 function ExceptionsListItem(contentType, mode, exception) { | 55 function ExceptionsListItem(contentType, mode, exception) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 this.editable = false; | 125 this.editable = false; |
| 108 } | 126 } |
| 109 | 127 |
| 110 if (this.setting == 'default') { | 128 if (this.setting == 'default') { |
| 111 // Items that don't have their own settings (parents of 'embedded on' | 129 // Items that don't have their own settings (parents of 'embedded on' |
| 112 // items) aren't deletable. | 130 // items) aren't deletable. |
| 113 this.deletable = false; | 131 this.deletable = false; |
| 114 this.editable = false; | 132 this.editable = false; |
| 115 } | 133 } |
| 116 | 134 |
| 117 if (this.contentType != 'zoomlevels') { | 135 if (this.contentType != 'zoomlevels' && |
| 136 !IsChosenObjectType(this.contentType)) { | |
| 118 this.addEditField(select, this.settingLabel); | 137 this.addEditField(select, this.settingLabel); |
| 119 this.contentElement.appendChild(select); | 138 this.contentElement.appendChild(select); |
| 120 } | 139 } |
| 121 select.className = 'exception-setting'; | 140 select.className = 'exception-setting'; |
| 122 select.setAttribute('aria-labelledby', 'exception-behavior-column'); | 141 select.setAttribute('aria-labelledby', |
| 142 ValueColumnForContentType(this.contentType)); | |
| 123 | 143 |
| 124 if (this.pattern) | 144 if (this.pattern) |
| 125 select.setAttribute('displaymode', 'edit'); | 145 select.setAttribute('displaymode', 'edit'); |
| 126 | 146 |
| 127 if (this.contentType == 'zoomlevels') { | 147 if (this.contentType == 'zoomlevels') { |
| 128 this.deletable = true; | 148 this.deletable = true; |
| 129 | 149 |
| 130 var zoomLabel = cr.doc.createElement('span'); | 150 var zoomLabel = cr.doc.createElement('span'); |
| 131 zoomLabel.textContent = this.dataItem.zoom; | 151 zoomLabel.textContent = this.dataItem.zoom; |
| 132 zoomLabel.className = 'exception-setting'; | 152 zoomLabel.className = 'exception-setting'; |
| 133 zoomLabel.setAttribute('displaymode', 'static'); | 153 zoomLabel.setAttribute('displaymode', 'static'); |
| 134 zoomLabel.setAttribute('aria-labelledby', 'exception-zoom-column'); | |
| 135 this.contentElement.appendChild(zoomLabel); | 154 this.contentElement.appendChild(zoomLabel); |
| 136 this.zoomLabel = zoomLabel; | 155 this.zoomLabel = zoomLabel; |
| 137 } | 156 } |
| 138 | 157 |
| 158 if (IsChosenObjectType(this.contentType) && | |
| 159 this.dataItem.object !== undefined) { | |
| 160 this.deletable = true; | |
| 161 | |
| 162 var objectLabel = cr.doc.createElement('span'); | |
| 163 objectLabel.textContent = this.dataItem.objectName; | |
|
Dan Beam
2015/12/02 04:09:49
^ this broke the closure compile for some reason..
| |
| 164 objectLabel.className = 'exception-setting'; | |
| 165 objectLabel.setAttribute('displaymode', 'static'); | |
| 166 this.contentElement.appendChild(objectLabel); | |
| 167 this.objectLabel = objectLabel; | |
| 168 } | |
| 169 | |
| 139 // Used to track whether the URL pattern in the input is valid. | 170 // 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 | 171 // 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 | 172 // 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. | 173 // 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 | 174 // It starts off as false for empty string (new exceptions) or true for |
| 144 // already-existing exceptions (which we assume are valid). | 175 // already-existing exceptions (which we assume are valid). |
| 145 this.inputValidityKnown = this.pattern; | 176 this.inputValidityKnown = this.pattern; |
| 146 // This one tracks the actual validity of the pattern in the input. This | 177 // 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 | 178 // starts off as true so as not to annoy the user when he adds a new and |
| 148 // empty input. | 179 // empty input. |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 this.dataModel = new ArrayDataModel([]); | 572 this.dataModel = new ArrayDataModel([]); |
| 542 } | 573 } |
| 543 }, | 574 }, |
| 544 | 575 |
| 545 /** @override */ | 576 /** @override */ |
| 546 deleteItemAtIndex: function(index) { | 577 deleteItemAtIndex: function(index) { |
| 547 var listItem = this.getListItemByIndex(index); | 578 var listItem = this.getListItemByIndex(index); |
| 548 if (!listItem.deletable) | 579 if (!listItem.deletable) |
| 549 return; | 580 return; |
| 550 | 581 |
| 551 var dataItem = listItem.dataItem; | 582 var dataItem = listItem.dataItem; |
|
Dan Beam
2015/12/02 04:09:49
var params = [
listItem.contentType,
listItem.
| |
| 552 chrome.send('removeException', [listItem.contentType, | 583 if (IsChosenObjectType(this.contentType)) { |
| 553 listItem.mode, | 584 chrome.send('removeException', [listItem.contentType, |
| 554 dataItem.origin, | 585 listItem.mode, |
| 555 dataItem.embeddingOrigin]); | 586 dataItem.origin, |
| 587 dataItem.embeddingOrigin, | |
| 588 dataItem.object]); | |
| 589 } else { | |
| 590 chrome.send('removeException', [listItem.contentType, | |
| 591 listItem.mode, | |
| 592 dataItem.origin, | |
| 593 dataItem.embeddingOrigin]); | |
| 594 } | |
| 556 }, | 595 }, |
| 557 }; | 596 }; |
| 558 | 597 |
| 559 var Page = cr.ui.pageManager.Page; | 598 var Page = cr.ui.pageManager.Page; |
| 560 var PageManager = cr.ui.pageManager.PageManager; | 599 var PageManager = cr.ui.pageManager.PageManager; |
| 561 | 600 |
| 562 /** | 601 /** |
| 563 * Encapsulated handling of content settings list subpage. | 602 * Encapsulated handling of content settings list subpage. |
| 564 * | 603 * |
| 565 * @constructor | 604 * @constructor |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 header.textContent = loadTimeData.getString(camelCasedType + 'Header'); | 649 header.textContent = loadTimeData.getString(camelCasedType + 'Header'); |
| 611 | 650 |
| 612 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | 651 var divs = this.pageDiv.querySelectorAll('div[contentType]'); |
| 613 for (var i = 0; i < divs.length; i++) { | 652 for (var i = 0; i < divs.length; i++) { |
| 614 if (divs[i].getAttribute('contentType') == type) | 653 if (divs[i].getAttribute('contentType') == type) |
| 615 divs[i].hidden = false; | 654 divs[i].hidden = false; |
| 616 else | 655 else |
| 617 divs[i].hidden = true; | 656 divs[i].hidden = true; |
| 618 } | 657 } |
| 619 | 658 |
| 620 $('exception-behavior-column').hidden = type == 'zoomlevels'; | 659 var valueColumnId = ValueColumnForContentType(type); |
| 621 $('exception-zoom-column').hidden = type != 'zoomlevels'; | 660 var headers = |
| 661 this.pageDiv.querySelectorAll('div.exception-value-column-header'); | |
| 662 for (var i = 0; i < headers.length; ++i) | |
| 663 headers[i].hidden = (headers[i].id != valueColumnId); | |
| 622 }, | 664 }, |
| 623 | 665 |
| 624 /** | 666 /** |
| 625 * Called after the page has been shown. Show the content type for the | 667 * Called after the page has been shown. Show the content type for the |
| 626 * location's hash. | 668 * location's hash. |
| 627 */ | 669 */ |
| 628 didShowPage: function() { | 670 didShowPage: function() { |
| 629 if (this.hash) | 671 if (this.hash) |
| 630 this.showList(this.hash.slice(1)); | 672 this.showList(this.hash.slice(1)); |
| 631 }, | 673 }, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 652 } | 694 } |
| 653 }; | 695 }; |
| 654 | 696 |
| 655 return { | 697 return { |
| 656 ExceptionsListItem: ExceptionsListItem, | 698 ExceptionsListItem: ExceptionsListItem, |
| 657 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 699 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 658 ExceptionsList: ExceptionsList, | 700 ExceptionsList: ExceptionsList, |
| 659 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 701 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
| 660 }; | 702 }; |
| 661 }); | 703 }); |
| OLD | NEW |