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 187 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(); | |
Dan Beam
2016/05/25 00:41:53
can't you just do
indicator.controlledBy = contro
huangs
2016/05/25 15:58:50
I'm moving existing code to this routine for reuse
| |
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 }; | |
Dan Beam
2016/05/25 00:41:54
no spaces between curlies:
{ controlledBy: cont
huangs
2016/05/25 15:58:50
Done.
| |
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 var textElt = this.querySelector('.exception-pattern .static-text'); | |
365 textElt.setAttribute('title', | |
366 loadTimeData.getString('exceptionDisabledByPolicy')); | |
367 this.appendIndicatorElement(overruledBy); | |
368 }, | |
369 | |
348 /** @override */ | 370 /** @override */ |
349 get currentInputIsValid() { | 371 get currentInputIsValid() { |
350 return this.inputValidityKnown && this.inputIsValid; | 372 return this.inputValidityKnown && this.inputIsValid; |
351 }, | 373 }, |
352 | 374 |
353 /** @override */ | 375 /** @override */ |
354 get hasBeenEdited() { | 376 get hasBeenEdited() { |
355 var livePattern = this.input.value; | 377 var livePattern = this.input.value; |
356 var liveSetting = this.select.value; | 378 var liveSetting = this.select.value; |
357 return livePattern != this.pattern || liveSetting != this.setting; | 379 return livePattern != this.pattern || liveSetting != this.setting; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 entry); | 535 entry); |
514 } else { | 536 } else { |
515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 537 var addRowItem = new ExceptionsAddRowListItem(this.contentType, |
516 this.mode); | 538 this.mode); |
517 addRowItem.deletable = false; | 539 addRowItem.deletable = false; |
518 return addRowItem; | 540 return addRowItem; |
519 } | 541 } |
520 }, | 542 }, |
521 | 543 |
522 /** | 544 /** |
545 * Updates UI to indicate that user exceptions were overruled by a source. | |
546 * | |
547 * @param {string} overruledBy The source that overrules user exceptions. | |
548 */ | |
549 setOverruledBy: function(overruledBy) { | |
550 for (var index = 0; index < this.dataModel.length; ++index) { | |
551 var item = this.getListItemByIndex(index); | |
552 if (item.dataItem.source == 'preference') { | |
Dan Beam
2016/05/25 00:41:53
no curlies
huangs
2016/05/25 15:58:50
Done.
| |
553 item.setOverruledBy(overruledBy); | |
554 } | |
555 } | |
556 }, | |
557 | |
558 /** | |
523 * Sets the exceptions in the js model. | 559 * Sets the exceptions in the js model. |
524 * | 560 * |
525 * @param {Array<options.Exception>} entries A list of dictionaries of | 561 * @param {Array<options.Exception>} entries A list of dictionaries of |
526 * values, each dictionary represents an exception. | 562 * values, each dictionary represents an exception. |
527 */ | 563 */ |
528 setExceptions: function(entries) { | 564 setExceptions: function(entries) { |
529 var deleteCount = this.dataModel.length; | 565 var deleteCount = this.dataModel.length; |
530 | 566 |
531 if (this.isEditable()) { | 567 if (this.isEditable()) { |
532 // We don't want to remove the Add New Exception row. | 568 // 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 } | 732 } |
697 }; | 733 }; |
698 | 734 |
699 return { | 735 return { |
700 ExceptionsListItem: ExceptionsListItem, | 736 ExceptionsListItem: ExceptionsListItem, |
701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 737 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
702 ExceptionsList: ExceptionsList, | 738 ExceptionsList: ExceptionsList, |
703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 739 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
704 }; | 740 }; |
705 }); | 741 }); |
OLD | NEW |