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 DeletableItemList = options.DeletableItemList; | 6 const DeletableItemList = options.DeletableItemList; |
7 const DeletableItem = options.DeletableItem; | 7 const DeletableItem = options.DeletableItem; |
8 const ArrayDataModel = cr.ui.ArrayDataModel; | 8 const ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 // Empty edit - do nothing. | 301 // Empty edit - do nothing. |
302 if (newPattern == this.pattern && newSetting == this.setting) | 302 if (newPattern == this.pattern && newSetting == this.setting) |
303 return; | 303 return; |
304 | 304 |
305 this.patternLabel.textContent = newPattern; | 305 this.patternLabel.textContent = newPattern; |
306 this.settingLabel.textContent = this.settingForDisplay(); | 306 this.settingLabel.textContent = this.settingForDisplay(); |
307 var oldPattern = this.pattern; | 307 var oldPattern = this.pattern; |
308 this.pattern = newPattern; | 308 this.pattern = newPattern; |
309 this.setting = newSetting; | 309 this.setting = newSetting; |
310 | 310 |
| 311 // TODO(estade): this will need to be updated if geolocation/notifications |
| 312 // become editable. |
311 if (oldPattern != newPattern) { | 313 if (oldPattern != newPattern) { |
312 chrome.send('removeExceptions', | 314 chrome.send('removeException', |
313 [this.contentType, this.mode, oldPattern]); | 315 [this.contentType, this.mode, oldPattern]); |
314 } | 316 } |
315 | 317 |
316 chrome.send('setException', | 318 chrome.send('setException', |
317 [this.contentType, this.mode, newPattern, newSetting]); | 319 [this.contentType, this.mode, newPattern, newSetting]); |
318 } | 320 } |
319 }; | 321 }; |
320 | 322 |
321 /** | 323 /** |
322 * Creates a new list item for the Add New Item row, which doesn't represent | 324 * Creates a new list item for the Add New Item row, which doesn't represent |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 395 |
394 ExceptionsList.prototype = { | 396 ExceptionsList.prototype = { |
395 __proto__: DeletableItemList.prototype, | 397 __proto__: DeletableItemList.prototype, |
396 | 398 |
397 /** | 399 /** |
398 * Called when an element is decorated as a list. | 400 * Called when an element is decorated as a list. |
399 */ | 401 */ |
400 decorate: function() { | 402 decorate: function() { |
401 DeletableItemList.prototype.decorate.call(this); | 403 DeletableItemList.prototype.decorate.call(this); |
402 | 404 |
403 this.contentType = this.parentNode.getAttribute('contentType'); | 405 this.classList.add('settings-list'); |
| 406 |
| 407 for (var parentNode = this.parentNode; parentNode; |
| 408 parentNode = parentNode.parentNode) { |
| 409 if (parentNode.hasAttribute('contentType')) { |
| 410 this.contentType = parentNode.getAttribute('contentType'); |
| 411 break; |
| 412 } |
| 413 } |
| 414 |
404 this.mode = this.getAttribute('mode'); | 415 this.mode = this.getAttribute('mode'); |
405 | 416 |
406 var exceptionList = this; | 417 var exceptionList = this; |
407 function handleBlur(e) { | 418 function handleBlur(e) { |
408 // When the blur event happens we do not know who is getting focus so we | 419 // When the blur event happens we do not know who is getting focus so we |
409 // delay this a bit until we know if the new focus node is outside the | 420 // delay this a bit until we know if the new focus node is outside the |
410 // list. | 421 // list. |
411 var doc = e.target.ownerDocument; | 422 var doc = e.target.ownerDocument; |
412 window.setTimeout(function() { | 423 window.setTimeout(function() { |
413 var activeElement = doc.activeElement; | 424 var activeElement = doc.activeElement; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 509 } |
499 }, | 510 }, |
500 | 511 |
501 /** @inheritDoc */ | 512 /** @inheritDoc */ |
502 deleteItemAtIndex: function(index) { | 513 deleteItemAtIndex: function(index) { |
503 var listItem = this.getListItemByIndex(index); | 514 var listItem = this.getListItemByIndex(index); |
504 if (listItem.undeletable) { | 515 if (listItem.undeletable) { |
505 console.log('Tried to delete an undeletable row.'); | 516 console.log('Tried to delete an undeletable row.'); |
506 return; | 517 return; |
507 } | 518 } |
508 chrome.send( | 519 |
509 'removeExceptions', | 520 var dataItem = listItem.dataItem; |
510 [listItem.contentType, listItem.mode, listItem.pattern]); | 521 var args = [listItem.contentType]; |
| 522 if (listItem.contentType == 'location') |
| 523 args.push(dataItem['origin'], dataItem['embeddingOrigin']); |
| 524 else if (listItem.contentType == 'notifications') |
| 525 args.push(dataItem['origin'], dataItem['setting']); |
| 526 else |
| 527 args.push(listItem.mode, listItem.pattern); |
| 528 |
| 529 chrome.send('removeException', args); |
511 }, | 530 }, |
512 | 531 |
513 /** | 532 /** |
514 * Removes all selected rows from browser's model. | |
515 */ | |
516 removeSelectedRows: function() { | |
517 // The first member is the content type; the rest of the values describe | |
518 // the patterns we are removing. | |
519 var args = [this.contentType]; | |
520 var selectedItems = this.selectedItems; | |
521 for (var i = 0; i < selectedItems.length; i++) { | |
522 if (this.contentType == 'location') { | |
523 args.push(selectedItems[i]['origin']); | |
524 args.push(selectedItems[i]['embeddingOrigin']); | |
525 } else if (this.contentType == 'notifications') { | |
526 args.push(selectedItems[i]['origin']); | |
527 args.push(selectedItems[i]['setting']); | |
528 } else { | |
529 args.push(this.mode); | |
530 args.push(selectedItems[i]['displayPattern']); | |
531 } | |
532 } | |
533 | |
534 chrome.send('removeExceptions', args); | |
535 }, | |
536 | |
537 /** | |
538 * Puts the selected row in editing mode. | 533 * Puts the selected row in editing mode. |
539 */ | 534 */ |
540 editSelectedRow: function() { | 535 editSelectedRow: function() { |
541 var li = this.getListItem(this.selectedItem); | 536 var li = this.getListItem(this.selectedItem); |
542 if (li) | 537 if (li) |
543 li.editing = true; | 538 li.editing = true; |
544 } | 539 } |
545 }; | 540 }; |
546 | 541 |
| 542 var OptionsPage = options.OptionsPage; |
| 543 |
| 544 /** |
| 545 * Encapsulated handling of content settings list subpage. |
| 546 * @constructor |
| 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 ContentSettingsExceptionsArea.hideOTRLists(); |
| 567 }, |
| 568 |
| 569 /** |
| 570 * Shows one list and hides all others. |
| 571 * @param {string} type The content type. |
| 572 */ |
| 573 showList: function(type) { |
| 574 var header = this.pageDiv.querySelector('h1'); |
| 575 header.textContent = templateData[type + '_header']; |
| 576 |
| 577 var divs = this.pageDiv.querySelectorAll('div[contentType]'); |
| 578 for (var i = 0; i < divs.length; i++) { |
| 579 if (divs[i].getAttribute('contentType') == type) |
| 580 divs[i].classList.remove('hidden'); |
| 581 else |
| 582 divs[i].classList.add('hidden'); |
| 583 } |
| 584 }, |
| 585 }; |
| 586 |
| 587 /** |
| 588 * Called when the last incognito window is closed. |
| 589 */ |
| 590 ContentSettingsExceptionsArea.OTRProfileDestroyed = function() { |
| 591 this.hideOTRLists(); |
| 592 }; |
| 593 |
| 594 /** |
| 595 * Clears and hides the incognito exceptions lists. |
| 596 */ |
| 597 ContentSettingsExceptionsArea.hideOTRLists = function() { |
| 598 var otrLists = document.querySelectorAll('list[mode=otr]'); |
| 599 |
| 600 for (var i = 0; i < otrLists.length; i++) { |
| 601 otrLists[i].reset(); |
| 602 otrLists[i].parentNode.classList.add('hidden'); |
| 603 } |
| 604 }; |
| 605 |
547 return { | 606 return { |
548 ExceptionsListItem: ExceptionsListItem, | 607 ExceptionsListItem: ExceptionsListItem, |
549 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 608 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
550 ExceptionsList: ExceptionsList, | 609 ExceptionsList: ExceptionsList, |
| 610 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
551 }; | 611 }; |
552 }); | 612 }); |
OLD | NEW |