 Chromium Code Reviews
 Chromium Code Reviews Issue 5964003:
  Content settings lists moved to sub-sub pages.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5964003:
  Content settings lists moved to sub-sub pages.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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']); | |
| 
arv (Not doing code reviews)
2010/12/21 00:34:27
push takes var args
args.push(ataItem['origin'],
 
Evan Stade
2010/12/21 02:09:00
Done.
 | |
| 526 args.push(dataItem['embeddingOrigin']); | |
| 527 } else if (listItem.contentType == 'notifications') { | |
| 528 args.push(dataItem['origin']); | |
| 529 args.push(dataItem['setting']); | |
| 530 } else { | |
| 531 args.push(listItem.mode); | |
| 532 args.push(listItem.pattern); | |
| 533 } | |
| 534 | |
| 535 chrome.send('removeException', args); | |
| 512 }, | 536 }, | 
| 513 | 537 | 
| 514 /** | 538 /** | 
| 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. | 539 * Puts the selected row in editing mode. | 
| 540 */ | 540 */ | 
| 541 editSelectedRow: function() { | 541 editSelectedRow: function() { | 
| 542 var li = this.getListItem(this.selectedItem); | 542 var li = this.getListItem(this.selectedItem); | 
| 543 if (li) | 543 if (li) | 
| 544 li.editing = true; | 544 li.editing = true; | 
| 545 } | 545 } | 
| 546 }; | 546 }; | 
| 547 | 547 | 
| 548 var OptionsPage = options.OptionsPage; | |
| 549 | |
| 550 function ContentSettingsExceptionsArea() { | |
| 
arv (Not doing code reviews)
2010/12/21 00:34:27
JSDoc?
 
Evan Stade
2010/12/21 02:09:00
Done.
 | |
| 551 OptionsPage.call(this, 'contentExceptions', | |
| 552 '', 'contentSettingsExceptionsArea'); | |
| 553 } | |
| 554 | |
| 555 cr.addSingletonGetter(ContentSettingsExceptionsArea); | |
| 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 = eval('templateData.' + type + '_header'); | |
| 
arv (Not doing code reviews)
2010/12/21 00:34:27
Do not use eval
object.foo is just syntactic suga
 
Evan Stade
2010/12/21 02:09:00
Done.
 | |
| 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 |