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; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 this.contentElement.appendChild(patternCell); | 84 this.contentElement.appendChild(patternCell); |
85 if (this.pattern) | 85 if (this.pattern) |
86 this.patternLabel = patternCell.querySelector('.static-text'); | 86 this.patternLabel = patternCell.querySelector('.static-text'); |
87 var input = patternCell.querySelector('input'); | 87 var input = patternCell.querySelector('input'); |
88 | 88 |
89 // Setting label for display mode. |pattern| will be null for the 'add new | 89 // Setting label for display mode. |pattern| will be null for the 'add new |
90 // exception' row. | 90 // exception' row. |
91 if (this.pattern) { | 91 if (this.pattern) { |
92 var settingLabel = cr.doc.createElement('span'); | 92 var settingLabel = cr.doc.createElement('span'); |
93 settingLabel.textContent = this.settingForDisplay(); | 93 settingLabel.textContent = this.settingForDisplay(); |
94 settingLabel.className = 'exception-setting'; | 94 settingLabel.className = 'exception-setting overruleable'; |
95 settingLabel.setAttribute('displaymode', 'static'); | 95 settingLabel.setAttribute('displaymode', 'static'); |
96 this.contentElement.appendChild(settingLabel); | 96 this.contentElement.appendChild(settingLabel); |
97 this.settingLabel = settingLabel; | 97 this.settingLabel = settingLabel; |
98 } | 98 } |
99 | 99 |
100 // Setting select element for edit mode. | 100 // Setting select element for edit mode. |
101 var select = cr.doc.createElement('select'); | 101 var select = cr.doc.createElement('select'); |
102 var optionAllow = cr.doc.createElement('option'); | 102 var optionAllow = cr.doc.createElement('option'); |
103 optionAllow.textContent = loadTimeData.getString('allowException'); | 103 optionAllow.textContent = loadTimeData.getString('allowException'); |
104 optionAllow.value = 'allow'; | 104 optionAllow.value = 'allow'; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 this.dataItem.source : null; | 198 this.dataItem.source : null; |
199 | 199 |
200 if (controlledBy) { | 200 if (controlledBy) { |
201 this.setAttribute('controlled-by', controlledBy); | 201 this.setAttribute('controlled-by', controlledBy); |
202 this.deletable = false; | 202 this.deletable = false; |
203 this.editable = false; | 203 this.editable = false; |
204 } | 204 } |
205 | 205 |
206 if (controlledBy == 'policy' || controlledBy == 'extension') { | 206 if (controlledBy == 'policy' || controlledBy == 'extension') { |
207 this.querySelector('.row-delete-button').hidden = true; | 207 this.querySelector('.row-delete-button').hidden = true; |
208 var indicator = new ControlledSettingIndicator(); | 208 this.appendIndicatorElement(controlledBy); |
209 indicator.setAttribute('content-exception', this.contentType); | |
210 // Create a synthetic pref change event decorated as | |
211 // CoreOptionsHandler::CreateValueForPref() does. | |
212 var event = new Event(this.contentType); | |
213 event.value = { controlledBy: controlledBy }; | |
214 indicator.handlePrefChange(event); | |
215 this.appendChild(indicator); | |
216 } | 209 } |
217 | 210 |
218 // If the exception comes from a hosted app, display the name and the | 211 // If the exception comes from a hosted app, display the name and the |
219 // icon of the app. | 212 // icon of the app. |
220 if (controlledBy == 'HostedApp') { | 213 if (controlledBy == 'HostedApp') { |
221 this.title = | 214 this.title = |
222 loadTimeData.getString('setBy') + ' ' + this.dataItem.appName; | 215 loadTimeData.getString('setBy') + ' ' + this.dataItem.appName; |
223 var button = this.querySelector('.row-delete-button'); | 216 var button = this.querySelector('.row-delete-button'); |
224 // Use the host app's favicon (16px, match bigger size). | 217 // Use the host app's favicon (16px, match bigger size). |
225 // See c/b/ui/webui/extensions/extension_icon_source.h | 218 // See c/b/ui/webui/extensions/extension_icon_source.h |
226 // for a description of the chrome://extension-icon URL. | 219 // for a description of the chrome://extension-icon URL. |
227 button.style.backgroundImage = | 220 button.style.backgroundImage = |
228 'url(\'chrome://extension-icon/' + this.dataItem.appId + '/16/1\')'; | 221 'url(\'chrome://extension-icon/' + this.dataItem.appId + '/16/1\')'; |
229 } | 222 } |
230 | 223 |
231 var listItem = this; | 224 var listItem = this; |
232 // Handle events on the editable nodes. | 225 // Handle events on the editable nodes. |
233 input.oninput = function(event) { | 226 input.oninput = function(event) { |
234 listItem.inputValidityKnown = false; | 227 listItem.inputValidityKnown = false; |
235 chrome.send('checkExceptionPatternValidity', | 228 chrome.send('checkExceptionPatternValidity', |
236 [listItem.contentType, listItem.mode, input.value]); | 229 [listItem.contentType, listItem.mode, input.value]); |
237 }; | 230 }; |
238 | 231 |
239 // Listen for edit events. | 232 // Listen for edit events. |
240 this.addEventListener('canceledit', this.onEditCancelled_); | 233 this.addEventListener('canceledit', this.onEditCancelled_); |
241 this.addEventListener('commitedit', this.onEditCommitted_); | 234 this.addEventListener('commitedit', this.onEditCommitted_); |
242 }, | 235 }, |
243 | 236 |
| 237 /** |
| 238 * Appends an indicator element to the item. Should be called at most once. |
| 239 * |
| 240 * @param {string} controlledBy The source that controls the item. |
| 241 */ |
| 242 appendIndicatorElement: function(controlledBy) { |
| 243 var indicator = new ControlledSettingIndicator(); |
| 244 indicator.setAttribute('content-exception', this.contentType); |
| 245 // Create a synthetic pref change event decorated as |
| 246 // CoreOptionsHandler::CreateValueForPref() does. |
| 247 var event = new Event(this.contentType); |
| 248 event.value = {controlledBy: controlledBy}; |
| 249 indicator.handlePrefChange(event); |
| 250 this.appendChild(indicator); |
| 251 }, |
| 252 |
244 isEmbeddingRule: function() { | 253 isEmbeddingRule: function() { |
245 return this.dataItem.embeddingOrigin && | 254 return this.dataItem.embeddingOrigin && |
246 this.dataItem.embeddingOrigin !== this.dataItem.origin; | 255 this.dataItem.embeddingOrigin !== this.dataItem.origin; |
247 }, | 256 }, |
248 | 257 |
249 /** | 258 /** |
250 * The pattern (e.g., a URL) for the exception. | 259 * The pattern (e.g., a URL) for the exception. |
251 * | 260 * |
252 * @type {string} | 261 * @type {string} |
253 */ | 262 */ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 */ | 347 */ |
339 updateEditables: function() { | 348 updateEditables: function() { |
340 this.resetInput(); | 349 this.resetInput(); |
341 | 350 |
342 var settingOption = | 351 var settingOption = |
343 this.select.querySelector('[value=\'' + this.setting + '\']'); | 352 this.select.querySelector('[value=\'' + this.setting + '\']'); |
344 if (settingOption) | 353 if (settingOption) |
345 settingOption.selected = true; | 354 settingOption.selected = true; |
346 }, | 355 }, |
347 | 356 |
| 357 /** |
| 358 * Updates UI to indicate that the exception was overruled by a source. |
| 359 * |
| 360 * @param {string} overruledBy The source that overrules the exception. |
| 361 */ |
| 362 setOverruledBy: function(overruledBy) { |
| 363 this.classList.toggle('overruled', !!overruledBy); |
| 364 this.appendIndicatorElement(overruledBy); |
| 365 }, |
| 366 |
348 /** @override */ | 367 /** @override */ |
349 get currentInputIsValid() { | 368 get currentInputIsValid() { |
350 return this.inputValidityKnown && this.inputIsValid; | 369 return this.inputValidityKnown && this.inputIsValid; |
351 }, | 370 }, |
352 | 371 |
353 /** @override */ | 372 /** @override */ |
354 get hasBeenEdited() { | 373 get hasBeenEdited() { |
355 var livePattern = this.input.value; | 374 var livePattern = this.input.value; |
356 var liveSetting = this.select.value; | 375 var liveSetting = this.select.value; |
357 return livePattern != this.pattern || liveSetting != this.setting; | 376 return livePattern != this.pattern || liveSetting != this.setting; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 entry); | 532 entry); |
514 } else { | 533 } else { |
515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 534 var addRowItem = new ExceptionsAddRowListItem(this.contentType, |
516 this.mode); | 535 this.mode); |
517 addRowItem.deletable = false; | 536 addRowItem.deletable = false; |
518 return addRowItem; | 537 return addRowItem; |
519 } | 538 } |
520 }, | 539 }, |
521 | 540 |
522 /** | 541 /** |
| 542 * Updates UI to indicate that user exceptions were overruled by a source. |
| 543 * |
| 544 * @param {string} overruledBy The source that overrules user exceptions. |
| 545 */ |
| 546 setOverruledBy: function(overruledBy) { |
| 547 for (var index = 0; index < this.dataModel.length; ++index) { |
| 548 var item = this.getListItemByIndex(index); |
| 549 if (item.dataItem.source == 'preference') |
| 550 item.setOverruledBy(overruledBy); |
| 551 } |
| 552 }, |
| 553 |
| 554 /** |
523 * Sets the exceptions in the js model. | 555 * Sets the exceptions in the js model. |
524 * | 556 * |
525 * @param {Array<options.Exception>} entries A list of dictionaries of | 557 * @param {Array<options.Exception>} entries A list of dictionaries of |
526 * values, each dictionary represents an exception. | 558 * values, each dictionary represents an exception. |
527 */ | 559 */ |
528 setExceptions: function(entries) { | 560 setExceptions: function(entries) { |
529 var deleteCount = this.dataModel.length; | 561 var deleteCount = this.dataModel.length; |
530 | 562 |
531 if (this.isEditable()) { | 563 if (this.isEditable()) { |
532 // We don't want to remove the Add New Exception row. | 564 // We don't want to remove the Add New Exception row. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 728 } |
697 }; | 729 }; |
698 | 730 |
699 return { | 731 return { |
700 ExceptionsListItem: ExceptionsListItem, | 732 ExceptionsListItem: ExceptionsListItem, |
701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 733 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
702 ExceptionsList: ExceptionsList, | 734 ExceptionsList: ExceptionsList, |
703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 735 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
704 }; | 736 }; |
705 }); | 737 }); |
OLD | NEW |