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. |
| 14 * |
| 15 * @param {string} contentType The type of the list. |
| 16 */ |
| 17 function IsEditableType(contentType) { |
| 18 // Exceptions of the following lists are not editable for now. |
| 19 return !(contentType == 'notifications' || |
| 20 contentType == 'location' || |
| 21 contentType == 'fullscreen' || |
| 22 contentType == 'media-stream' || |
| 23 contentType == 'midi-sysex' || |
| 24 contentType == 'zoomlevels'); |
| 25 } |
| 26 |
| 27 /** |
13 * Creates a new exceptions list item. | 28 * Creates a new exceptions list item. |
14 * | 29 * |
15 * @param {string} contentType The type of the list. | 30 * @param {string} contentType The type of the list. |
16 * @param {string} mode The browser mode, 'otr' or 'normal'. | 31 * @param {string} mode The browser mode, 'otr' or 'normal'. |
17 * @param {Object} exception A dictionary that contains the data of the | 32 * @param {Object} exception A dictionary that contains the data of the |
18 * exception. | 33 * exception. |
19 * @constructor | 34 * @constructor |
20 * @extends {options.InlineEditableItem} | 35 * @extends {options.InlineEditableItem} |
21 */ | 36 */ |
22 function ExceptionsListItem(contentType, mode, exception) { | 37 function ExceptionsListItem(contentType, mode, exception) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 var videoSettingLabel = cr.doc.createElement('span'); | 132 var videoSettingLabel = cr.doc.createElement('span'); |
118 videoSettingLabel.textContent = this.videoSettingForDisplay(); | 133 videoSettingLabel.textContent = this.videoSettingForDisplay(); |
119 videoSettingLabel.className = 'exception-setting'; | 134 videoSettingLabel.className = 'exception-setting'; |
120 videoSettingLabel.classList.add('media-video-setting'); | 135 videoSettingLabel.classList.add('media-video-setting'); |
121 videoSettingLabel.setAttribute('displaymode', 'static'); | 136 videoSettingLabel.setAttribute('displaymode', 'static'); |
122 this.contentElement.appendChild(videoSettingLabel); | 137 this.contentElement.appendChild(videoSettingLabel); |
123 } | 138 } |
124 | 139 |
125 if (this.contentType == 'zoomlevels') { | 140 if (this.contentType == 'zoomlevels') { |
126 this.deletable = true; | 141 this.deletable = true; |
127 this.editable = false; | |
128 | 142 |
129 var zoomLabel = cr.doc.createElement('span'); | 143 var zoomLabel = cr.doc.createElement('span'); |
130 zoomLabel.textContent = this.dataItem.zoom; | 144 zoomLabel.textContent = this.dataItem.zoom; |
131 zoomLabel.className = 'exception-setting'; | 145 zoomLabel.className = 'exception-setting'; |
132 zoomLabel.setAttribute('displaymode', 'static'); | 146 zoomLabel.setAttribute('displaymode', 'static'); |
133 zoomLabel.setAttribute('aria-labelledby', 'exception-zoom-column'); | 147 zoomLabel.setAttribute('aria-labelledby', 'exception-zoom-column'); |
134 this.contentElement.appendChild(zoomLabel); | 148 this.contentElement.appendChild(zoomLabel); |
135 this.zoomLabel = zoomLabel; | 149 this.zoomLabel = zoomLabel; |
136 } | 150 } |
137 | 151 |
138 // Used to track whether the URL pattern in the input is valid. | 152 // Used to track whether the URL pattern in the input is valid. |
139 // This will be true if the browser process has informed us that the | 153 // This will be true if the browser process has informed us that the |
140 // current text in the input is valid. Changing the text resets this to | 154 // current text in the input is valid. Changing the text resets this to |
141 // false, and getting a response from the browser sets it back to true. | 155 // false, and getting a response from the browser sets it back to true. |
142 // It starts off as false for empty string (new exceptions) or true for | 156 // It starts off as false for empty string (new exceptions) or true for |
143 // already-existing exceptions (which we assume are valid). | 157 // already-existing exceptions (which we assume are valid). |
144 this.inputValidityKnown = this.pattern; | 158 this.inputValidityKnown = this.pattern; |
145 // This one tracks the actual validity of the pattern in the input. This | 159 // This one tracks the actual validity of the pattern in the input. This |
146 // starts off as true so as not to annoy the user when he adds a new and | 160 // starts off as true so as not to annoy the user when he adds a new and |
147 // empty input. | 161 // empty input. |
148 this.inputIsValid = true; | 162 this.inputIsValid = true; |
149 | 163 |
150 this.input = input; | 164 this.input = input; |
151 this.select = select; | 165 this.select = select; |
152 | 166 |
153 this.updateEditables(); | 167 this.updateEditables(); |
154 | 168 this.editable = this.editable && IsEditableType(this.contentType); |
155 // Editing notifications, geolocation and media-stream is disabled for | |
156 // now. | |
157 if (this.contentType == 'notifications' || | |
158 this.contentType == 'location' || | |
159 this.contentType == 'media-stream') { | |
160 this.editable = false; | |
161 } | |
162 | 169 |
163 // If the source of the content setting exception is not a user | 170 // If the source of the content setting exception is not a user |
164 // preference, that source controls the exception and the user cannot edit | 171 // preference, that source controls the exception and the user cannot edit |
165 // or delete it. | 172 // or delete it. |
166 var controlledBy = | 173 var controlledBy = |
167 this.dataItem.source && this.dataItem.source != 'preference' ? | 174 this.dataItem.source && this.dataItem.source != 'preference' ? |
168 this.dataItem.source : null; | 175 this.dataItem.source : null; |
169 | 176 |
170 if (controlledBy) { | 177 if (controlledBy) { |
171 this.setAttribute('controlled-by', controlledBy); | 178 this.setAttribute('controlled-by', controlledBy); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 if (pattern == listItem.input.value) | 540 if (pattern == listItem.input.value) |
534 listItem.setPatternValid(valid); | 541 listItem.setPatternValid(valid); |
535 } | 542 } |
536 }, | 543 }, |
537 | 544 |
538 /** | 545 /** |
539 * Returns whether the rows are editable in this list. | 546 * Returns whether the rows are editable in this list. |
540 */ | 547 */ |
541 isEditable: function() { | 548 isEditable: function() { |
542 // Exceptions of the following lists are not editable for now. | 549 // Exceptions of the following lists are not editable for now. |
543 return !(this.contentType == 'notifications' || | 550 return IsEditableType(this.contentType); |
544 this.contentType == 'location' || | |
545 this.contentType == 'fullscreen' || | |
546 this.contentType == 'media-stream' || | |
547 this.contentType == 'zoomlevels'); | |
548 }, | 551 }, |
549 | 552 |
550 /** | 553 /** |
551 * Removes all exceptions from the js model. | 554 * Removes all exceptions from the js model. |
552 */ | 555 */ |
553 reset: function() { | 556 reset: function() { |
554 if (this.isEditable()) { | 557 if (this.isEditable()) { |
555 // The null creates the Add New Exception row. | 558 // The null creates the Add New Exception row. |
556 this.dataModel = new ArrayDataModel([null]); | 559 this.dataModel = new ArrayDataModel([null]); |
557 } else { | 560 } else { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 } | 675 } |
673 }; | 676 }; |
674 | 677 |
675 return { | 678 return { |
676 ExceptionsListItem: ExceptionsListItem, | 679 ExceptionsListItem: ExceptionsListItem, |
677 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 680 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
678 ExceptionsList: ExceptionsList, | 681 ExceptionsList: ExceptionsList, |
679 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 682 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
680 }; | 683 }; |
681 }); | 684 }); |
OLD | NEW |