Chromium Code Reviews| 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('removeException', |
| 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 |
| 322 /** | 324 /** |
| 323 * Creates a new list item for the Add New Item row, which doesn't represent | 325 * 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... | |
| 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 this.classList.add('framed-list'); |
| 407 | |
| 408 for (var parentNode = this.parentNode; parentNode; | |
| 409 parentNode = parentNode.parentNode) { | |
| 410 if (parentNode.hasAttribute('contentType')) { | |
| 411 this.contentType = parentNode.getAttribute('contentType'); | |
| 412 break; | |
| 413 } | |
| 414 } | |
| 415 | |
| 405 this.mode = this.getAttribute('mode'); | 416 this.mode = this.getAttribute('mode'); |
| 406 | 417 |
| 407 var exceptionList = this; | 418 var exceptionList = this; |
| 408 function handleBlur(e) { | 419 function handleBlur(e) { |
| 409 // When the blur event happens we do not know who is getting focus so we | 420 // 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 | 421 // delay this a bit until we know if the new focus node is outside the |
| 411 // list. | 422 // list. |
| 412 var doc = e.target.ownerDocument; | 423 var doc = e.target.ownerDocument; |
| 413 window.setTimeout(function() { | 424 window.setTimeout(function() { |
| 414 var activeElement = doc.activeElement; | 425 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. | 506 // The null creates the Add New Exception row. |
| 496 this.dataModel = new ArrayDataModel([null]); | 507 this.dataModel = new ArrayDataModel([null]); |
| 497 } else { | 508 } else { |
| 498 this.dataModel = new ArrayDataModel([]); | 509 this.dataModel = new ArrayDataModel([]); |
| 499 } | 510 } |
| 500 }, | 511 }, |
| 501 | 512 |
| 502 /** @inheritDoc */ | 513 /** @inheritDoc */ |
| 503 deleteItemAtIndex: function(index) { | 514 deleteItemAtIndex: function(index) { |
| 504 var listItem = this.getListItemByIndex(index).contentItem; | 515 var listItem = this.getListItemByIndex(index).contentItem; |
| 516 | |
| 505 if (listItem.undeletable) { | 517 if (listItem.undeletable) { |
| 506 console.log('Tried to delete an undeletable row.'); | 518 console.log('Tried to delete an undeletable row.'); |
| 507 return; | 519 return; |
| 508 } | 520 } |
| 509 chrome.send( | 521 |
| 510 'removeExceptions', | 522 var dataItem = listItem.dataItem; |
| 511 [listItem.contentType, listItem.mode, listItem.pattern]); | 523 var args = [listItem.contentType]; |
| 524 if (listItem.contentType == 'location') | |
| 525 args.push(dataItem['origin'], dataItem['embeddingOrigin']); | |
| 526 else if (listItem.contentType == 'notifications') | |
| 527 args.push(dataItem['origin'], dataItem['setting']); | |
| 528 else | |
| 529 args.push(listItem.mode, listItem.pattern); | |
| 530 | |
| 531 chrome.send('removeException', args); | |
| 512 }, | 532 }, |
| 513 | 533 |
| 514 /** | 534 /** |
| 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. | 535 * Puts the selected row in editing mode. |
| 540 */ | 536 */ |
| 541 editSelectedRow: function() { | 537 editSelectedRow: function() { |
| 542 var li = this.getListItem(this.selectedItem); | 538 var li = this.getListItem(this.selectedItem); |
| 543 if (li) | 539 if (li) |
| 544 li.editing = true; | 540 li.editing = true; |
| 545 } | 541 } |
| 546 }; | 542 }; |
| 547 | 543 |
| 544 var OptionsPage = options.OptionsPage; | |
| 545 | |
| 546 function ContentSettingsExceptionsArea() { | |
| 547 OptionsPage.call(this, 'contentExceptions', | |
| 548 '', 'contentSettingsExceptionsArea'); | |
| 549 } | |
| 550 | |
| 551 cr.addSingletonGetter(ContentSettingsExceptionsArea); | |
| 552 | |
| 553 /** | |
| 554 * Encapsulated handling of content settings list subpage. | |
|
arv (Not doing code reviews)
2010/12/21 19:08:54
This goes on the ContentSettingsExceptionArea func
Evan Stade
2010/12/21 19:54:08
Done.
| |
| 555 * @constructor | |
| 556 */ | |
| 557 ContentSettingsExceptionsArea.prototype = { | |
| 558 __proto__: OptionsPage.prototype, | |
| 559 | |
| 560 initializePage: function() { | |
| 561 OptionsPage.prototype.initializePage.call(this); | |
| 562 | |
| 563 var exceptionsLists = this.pageDiv.querySelectorAll('list'); | |
| 564 for (var i = 0; i < exceptionsLists.length; i++) { | |
| 565 options.contentSettings.ExceptionsList.decorate(exceptionsLists[i]); | |
| 566 } | |
| 567 | |
| 568 ContentSettingsExceptionsArea.hideOTRLists(); | |
| 569 }, | |
| 570 | |
| 571 /** | |
| 572 * Shows one list and hides all others. | |
| 573 * @param {string} type The content type. | |
| 574 */ | |
| 575 showList: function(type) { | |
| 576 var header = this.pageDiv.querySelector('h1'); | |
| 577 header.textContent = templateData[type + '_header']); | |
| 578 | |
| 579 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | |
| 580 for (var i = 0; i < divs.length; i++) { | |
| 581 if (divs[i].getAttribute('contentType') == type) | |
| 582 divs[i].classList.remove('hidden'); | |
| 583 else | |
| 584 divs[i].classList.add('hidden'); | |
| 585 } | |
| 586 }, | |
| 587 }; | |
| 588 | |
| 589 /** | |
| 590 * Called when the last incognito window is closed. | |
| 591 */ | |
| 592 ContentSettingsExceptionsArea.OTRProfileDestroyed = function() { | |
| 593 this.hideOTRLists(); | |
| 594 }; | |
| 595 | |
| 596 /** | |
| 597 * Clears and hides the incognito exceptions lists. | |
| 598 */ | |
| 599 ContentSettingsExceptionsArea.hideOTRLists = function() { | |
| 600 var otrLists = document.querySelectorAll('list[mode=otr]'); | |
| 601 | |
| 602 for (var i = 0; i < otrLists.length; i++) { | |
| 603 otrLists[i].reset(); | |
| 604 otrLists[i].parentNode.classList.add('hidden'); | |
| 605 } | |
| 606 }; | |
| 607 | |
| 548 return { | 608 return { |
| 549 ExceptionsListItem: ExceptionsListItem, | 609 ExceptionsListItem: ExceptionsListItem, |
| 550 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 610 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 551 ExceptionsList: ExceptionsList, | 611 ExceptionsList: ExceptionsList, |
| 612 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | |
| 552 }; | 613 }; |
| 553 }); | 614 }); |
| OLD | NEW |