OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 List = cr.ui.List; | 6 const List = cr.ui.List; |
7 const ListItem = cr.ui.ListItem; | 7 const ListItem = cr.ui.ListItem; |
8 const ArrayDataModel = cr.ui.ArrayDataModel; | 8 const ArrayDataModel = cr.ui.ArrayDataModel; |
9 const DeletableItemList = options.DeletableItemList; | 9 const DeletableItemList = options.DeletableItemList; |
10 | 10 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 // Empty edit - do nothing. | 302 // Empty edit - do nothing. |
303 if (newPattern == this.pattern && newSetting == this.setting) | 303 if (newPattern == this.pattern && newSetting == this.setting) |
304 return; | 304 return; |
305 | 305 |
306 this.patternLabel.textContent = newPattern; | 306 this.patternLabel.textContent = newPattern; |
307 this.settingLabel.textContent = this.settingForDisplay(); | 307 this.settingLabel.textContent = this.settingForDisplay(); |
308 var oldPattern = this.pattern; | 308 var oldPattern = this.pattern; |
309 this.pattern = newPattern; | 309 this.pattern = newPattern; |
310 this.setting = newSetting; | 310 this.setting = newSetting; |
311 | 311 |
312 // TODO(estade): this will need to be updated if geolocation/notifications | |
313 // become editable. | |
312 if (oldPattern != newPattern) { | 314 if (oldPattern != newPattern) { |
313 chrome.send('removeExceptions', | 315 chrome.send('removeExceptions', |
314 [this.contentType, this.mode, oldPattern]); | 316 [this.contentType, this.mode, oldPattern]); |
315 } | 317 } |
316 | 318 |
317 chrome.send('setException', | 319 chrome.send('setException', |
318 [this.contentType, this.mode, newPattern, newSetting]); | 320 [this.contentType, this.mode, newPattern, newSetting]); |
319 } | 321 } |
320 }; | 322 }; |
321 | 323 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 | 396 |
395 ExceptionsList.prototype = { | 397 ExceptionsList.prototype = { |
396 __proto__: DeletableItemList.prototype, | 398 __proto__: DeletableItemList.prototype, |
397 | 399 |
398 /** | 400 /** |
399 * Called when an element is decorated as a list. | 401 * Called when an element is decorated as a list. |
400 */ | 402 */ |
401 decorate: function() { | 403 decorate: function() { |
402 DeletableItemList.prototype.decorate.call(this); | 404 DeletableItemList.prototype.decorate.call(this); |
403 | 405 |
404 this.contentType = this.parentNode.getAttribute('contentType'); | 406 for (var parentNode = this.parentNode; parentNode; |
407 parentNode = parentNode.parentNode) { | |
408 if (parentNode.hasAttribute('contentType')) { | |
409 this.contentType = parentNode.getAttribute('contentType'); | |
410 break; | |
411 } | |
412 } | |
413 | |
405 this.mode = this.getAttribute('mode'); | 414 this.mode = this.getAttribute('mode'); |
406 | 415 |
407 var exceptionList = this; | 416 var exceptionList = this; |
408 function handleBlur(e) { | 417 function handleBlur(e) { |
409 // When the blur event happens we do not know who is getting focus so we | 418 // When the blur event happens we do not know who is getting focus so we |
410 // delay this a bit until we know if the new focus node is outside the | 419 // delay this a bit until we know if the new focus node is outside the |
411 // list. | 420 // list. |
412 var doc = e.target.ownerDocument; | 421 var doc = e.target.ownerDocument; |
413 window.setTimeout(function() { | 422 window.setTimeout(function() { |
414 var activeElement = doc.activeElement; | 423 var activeElement = doc.activeElement; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 // The null creates the Add New Exception row. | 504 // The null creates the Add New Exception row. |
496 this.dataModel = new ArrayDataModel([null]); | 505 this.dataModel = new ArrayDataModel([null]); |
497 } else { | 506 } else { |
498 this.dataModel = new ArrayDataModel([]); | 507 this.dataModel = new ArrayDataModel([]); |
499 } | 508 } |
500 }, | 509 }, |
501 | 510 |
502 /** @inheritDoc */ | 511 /** @inheritDoc */ |
503 deleteItemAtIndex: function(index) { | 512 deleteItemAtIndex: function(index) { |
504 var listItem = this.getListItemByIndex(index).contentItem; | 513 var listItem = this.getListItemByIndex(index).contentItem; |
514 | |
505 if (listItem.undeletable) { | 515 if (listItem.undeletable) { |
506 console.log('Tried to delete an undeletable row.'); | 516 console.log('Tried to delete an undeletable row.'); |
507 return; | 517 return; |
508 } | 518 } |
509 chrome.send( | 519 |
510 'removeExceptions', | 520 var dataItem = listItem.dataItem; |
511 [listItem.contentType, listItem.mode, listItem.pattern]); | 521 var args = [listItem.contentType]; |
522 if (listItem.contentType == 'location') { | |
523 args.push(dataItem['origin']); | |
524 args.push(dataItem['embeddingOrigin']); | |
525 } else if (listItem.contentType == 'notifications') { | |
526 args.push(dataItem['origin']); | |
527 args.push(dataItem['setting']); | |
528 } else { | |
529 args.push(listItem.mode); | |
530 args.push(listItem.pattern); | |
531 } | |
532 | |
533 chrome.send('removeException', args); | |
512 }, | 534 }, |
513 | 535 |
514 /** | 536 /** |
515 * Removes all selected rows from browser's model. | |
516 */ | |
517 removeSelectedRows: function() { | |
518 // The first member is the content type; the rest of the values describe | |
519 // the patterns we are removing. | |
520 var args = [this.contentType]; | |
521 var selectedItems = this.selectedItems; | |
522 for (var i = 0; i < selectedItems.length; i++) { | |
523 if (this.contentType == 'location') { | |
524 args.push(selectedItems[i]['origin']); | |
525 args.push(selectedItems[i]['embeddingOrigin']); | |
526 } else if (this.contentType == 'notifications') { | |
527 args.push(selectedItems[i]['origin']); | |
528 args.push(selectedItems[i]['setting']); | |
529 } else { | |
530 args.push(this.mode); | |
531 args.push(selectedItems[i]['displayPattern']); | |
532 } | |
533 } | |
534 | |
535 chrome.send('removeExceptions', args); | |
536 }, | |
537 | |
538 /** | |
539 * Puts the selected row in editing mode. | 537 * Puts the selected row in editing mode. |
540 */ | 538 */ |
541 editSelectedRow: function() { | 539 editSelectedRow: function() { |
542 var li = this.getListItem(this.selectedItem); | 540 var li = this.getListItem(this.selectedItem); |
543 if (li) | 541 if (li) |
544 li.editing = true; | 542 li.editing = true; |
545 } | 543 } |
546 }; | 544 }; |
547 | 545 |
546 var OptionsPage = options.OptionsPage; | |
547 | |
548 function ContentSettingsExceptionsArea() { | |
549 OptionsPage.call(this, 'contentExceptions', | |
550 '', 'contentSettingsExceptionsArea'); | |
551 } | |
552 | |
553 cr.addSingletonGetter(ContentSettingsExceptionsArea); | |
554 | |
555 ContentSettingsExceptionsArea.prototype = { | |
556 __proto__: OptionsPage.prototype, | |
557 | |
558 initializePage: function() { | |
559 OptionsPage.prototype.initializePage.call(this); | |
560 | |
561 var exceptionsLists = this.pageDiv.querySelectorAll('list'); | |
562 for (var i = 0; i < exceptionsLists.length; i++) { | |
563 options.contentSettings.ExceptionsList.decorate(exceptionsLists[i]); | |
564 } | |
565 | |
566 this.addEventListener('visibleChange', function(event) { | |
567 for (var i = 0; i < exceptionsLists.length; i++) { | |
568 exceptionsLists[i].redraw(); | |
stuartmorgan
2010/12/20 22:55:37
Do you still need this? The expectation for autoex
Evan Stade
2010/12/20 23:09:02
I'll check
| |
569 } | |
570 }); | |
571 | |
572 ContentSettingsExceptionsArea.hideOTRLists(); | |
573 }, | |
574 | |
575 /** | |
576 * Shows one list and hides all others. | |
577 * @param {string} type The content type. | |
578 */ | |
579 showList: function(type) { | |
580 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | |
581 for (var i = 0; i < divs.length; i++) { | |
582 if (divs[i].getAttribute('contentType') == type) | |
583 divs[i].classList.remove('hidden'); | |
584 else | |
585 divs[i].classList.add('hidden'); | |
586 } | |
587 }, | |
588 }; | |
589 | |
590 /** | |
591 * Called when the last incognito window is closed. | |
592 */ | |
593 ContentSettingsExceptionsArea.OTRProfileDestroyed = function() { | |
594 this.hideOTRLists(); | |
595 }; | |
596 | |
597 /** | |
598 * Clears and hides the incognito exceptions lists. | |
599 */ | |
600 ContentSettingsExceptionsArea.hideOTRLists = function() { | |
601 var otrLists = document.querySelectorAll('list[mode=otr]'); | |
602 | |
603 for (var i = 0; i < otrLists.length; i++) { | |
604 otrLists[i].reset(); | |
605 otrLists[i].parentNode.classList.add('hidden'); | |
606 } | |
607 }; | |
608 | |
548 return { | 609 return { |
549 ExceptionsListItem: ExceptionsListItem, | 610 ExceptionsListItem: ExceptionsListItem, |
550 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 611 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
551 ExceptionsList: ExceptionsList, | 612 ExceptionsList: ExceptionsList, |
613 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | |
552 }; | 614 }; |
553 }); | 615 }); |
OLD | NEW |