Chromium Code Reviews| 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', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var DeletableItemList = options.DeletableItemList; | 6 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
| 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); | 70 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); |
| 71 // Insert [start, 0] at the beginning of the array of nodes, making it | 71 // Insert [start, 0] at the beginning of the array of nodes, making it |
| 72 // into the arguments we want to pass to @{code list.splice} below. | 72 // into the arguments we want to pass to @{code list.splice} below. |
| 73 nodes.splice(0, 0, start, 0); | 73 nodes.splice(0, 0, start, 0); |
| 74 list.splice.apply(list, nodes); | 74 list.splice.apply(list, nodes); |
| 75 // Remove the [start, 0] prefix and return the array of nodes. | 75 // Remove the [start, 0] prefix and return the array of nodes. |
| 76 nodes.splice(0, 2); | 76 nodes.splice(0, 2); |
| 77 return nodes; | 77 return nodes; |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | |
| 81 * Adds information about an app that protects this data item to the | |
| 82 * @{code element}. | |
| 83 * @param {Element} element The DOM element the information should be | |
| 84 appended to. | |
| 85 * @param {{id: string, name: string}} appInfo Information about an app. | |
| 86 */ | |
| 87 function addAppInfo(element, appInfo) { | |
| 88 var img = element.ownerDocument.createElement('img'); | |
| 89 img.src = 'chrome://extension-icon/' + appInfo.id + '/16/1'; | |
| 90 img.title = loadTimeData.getString('label_protected_by_apps') + | |
| 91 ' ' + appInfo.name; | |
| 92 img.className = 'protecting-app'; | |
| 93 element.appendChild(img); | |
| 94 } | |
| 95 | |
| 80 var parentLookup = {}; | 96 var parentLookup = {}; |
| 81 var lookupRequests = {}; | 97 var lookupRequests = {}; |
| 82 | 98 |
| 83 /** | 99 /** |
| 84 * Creates a new list item for sites data. Note that these are created and | 100 * Creates a new list item for sites data. Note that these are created and |
| 85 * destroyed lazily as they scroll into and out of view, so they must be | 101 * destroyed lazily as they scroll into and out of view, so they must be |
| 86 * stateless. We cache the expanded item in @{code CookiesList} though, so it | 102 * stateless. We cache the expanded item in @{code CookiesList} though, so it |
| 87 * can keep state. (Mostly just which item is selected.) | 103 * can keep state. (Mostly just which item is selected.) |
| 88 * @param {Object} origin Data used to create a cookie list item. | 104 * @param {Object} origin Data used to create a cookie list item. |
| 89 * @param {CookiesList} list The list that will contain this item. | 105 * @param {CookiesList} list The list that will contain this item. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 cookies: 0, | 242 cookies: 0, |
| 227 database: false, | 243 database: false, |
| 228 localStorage: false, | 244 localStorage: false, |
| 229 appCache: false, | 245 appCache: false, |
| 230 indexedDb: false, | 246 indexedDb: false, |
| 231 fileSystem: false, | 247 fileSystem: false, |
| 232 serverBoundCerts: 0, | 248 serverBoundCerts: 0, |
| 233 }; | 249 }; |
| 234 if (this.origin) | 250 if (this.origin) |
| 235 this.origin.collectSummaryInfo(info); | 251 this.origin.collectSummaryInfo(info); |
| 252 | |
| 236 var list = []; | 253 var list = []; |
| 237 if (info.cookies > 1) | 254 if (info.cookies > 1) |
| 238 list.push(loadTimeData.getStringF('cookie_plural', info.cookies)); | 255 list.push(loadTimeData.getStringF('cookie_plural', info.cookies)); |
| 239 else if (info.cookies > 0) | 256 else if (info.cookies > 0) |
| 240 list.push(loadTimeData.getString('cookie_singular')); | 257 list.push(loadTimeData.getString('cookie_singular')); |
| 241 if (info.database || info.indexedDb) | 258 if (info.database || info.indexedDb) |
| 242 list.push(loadTimeData.getString('cookie_database_storage')); | 259 list.push(loadTimeData.getString('cookie_database_storage')); |
| 243 if (info.localStorage) | 260 if (info.localStorage) |
| 244 list.push(loadTimeData.getString('cookie_local_storage')); | 261 list.push(loadTimeData.getString('cookie_local_storage')); |
| 245 if (info.appCache) | 262 if (info.appCache) |
| 246 list.push(loadTimeData.getString('cookie_app_cache')); | 263 list.push(loadTimeData.getString('cookie_app_cache')); |
| 247 if (info.fileSystem) | 264 if (info.fileSystem) |
| 248 list.push(loadTimeData.getString('cookie_file_system')); | 265 list.push(loadTimeData.getString('cookie_file_system')); |
| 249 if (info.serverBoundCerts) | 266 if (info.serverBoundCerts) |
| 250 list.push(loadTimeData.getString('cookie_server_bound_cert')); | 267 list.push(loadTimeData.getString('cookie_server_bound_cert')); |
| 268 | |
| 251 var text = ''; | 269 var text = ''; |
| 252 for (var i = 0; i < list.length; ++i) | 270 for (var i = 0; i < list.length; ++i) { |
| 253 if (text.length > 0) | 271 if (text.length > 0) |
| 254 text += ', ' + list[i]; | 272 text += ', ' + list[i]; |
| 255 else | 273 else |
| 256 text = list[i]; | 274 text = list[i]; |
| 275 } | |
| 257 this.dataChild.textContent = text; | 276 this.dataChild.textContent = text; |
| 258 if (info.quota && info.quota.totalUsage) { | 277 |
| 278 var apps = info.appsProtectingThis; | |
| 279 if (apps) { | |
|
Evan Stade
2012/07/11 01:45:44
as it turns out I don't think this check is necess
Bernhard Bauer
2012/07/11 08:42:11
Oh, cool. Removed.
| |
| 280 for (var key in apps) { | |
| 281 addAppInfo(this.dataChild, apps[key]); | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 if (info.quota && info.quota.totalUsage) | |
| 259 this.sizeChild.textContent = info.quota.totalUsage; | 286 this.sizeChild.textContent = info.quota.totalUsage; |
| 260 } | |
| 261 | 287 |
| 262 if (this.expanded) | 288 if (this.expanded) |
| 263 this.updateItems_(); | 289 this.updateItems_(); |
| 264 }, | 290 }, |
| 265 | 291 |
| 266 /** | 292 /** |
| 267 * Updates the items section to reflect changes, animating to the new state. | 293 * Updates the items section to reflect changes, animating to the new state. |
| 268 * Removes existing contents and calls @{code CookieTreeNode.createItems}. | 294 * Removes existing contents and calls @{code CookieTreeNode.createItems}. |
| 269 * @private | 295 * @private |
| 270 */ | 296 */ |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 info.appCache = true; | 475 info.appCache = true; |
| 450 } else if (this.data.type == 'indexed_db') { | 476 } else if (this.data.type == 'indexed_db') { |
| 451 info.indexedDb = true; | 477 info.indexedDb = true; |
| 452 } else if (this.data.type == 'file_system') { | 478 } else if (this.data.type == 'file_system') { |
| 453 info.fileSystem = true; | 479 info.fileSystem = true; |
| 454 } else if (this.data.type == 'quota') { | 480 } else if (this.data.type == 'quota') { |
| 455 info.quota = this.data; | 481 info.quota = this.data; |
| 456 } else if (this.data.type == 'server_bound_cert') { | 482 } else if (this.data.type == 'server_bound_cert') { |
| 457 info.serverBoundCerts++; | 483 info.serverBoundCerts++; |
| 458 } | 484 } |
| 485 | |
| 486 var apps = this.data.appsProtectingThis; | |
| 487 if (apps) { | |
| 488 if (!info.appsProtectingThis) | |
| 489 info.appsProtectingThis = {}; | |
| 490 apps.forEach(function(appInfo) { | |
| 491 info.appsProtectingThis[appInfo.id] = appInfo; | |
| 492 }); | |
| 493 } | |
| 459 } | 494 } |
| 460 }, | 495 }, |
| 461 | 496 |
| 462 /** | 497 /** |
| 463 * Create the cookie "bubbles" for this node, recursing into children | 498 * Create the cookie "bubbles" for this node, recursing into children |
| 464 * if there are any. Append the cookie bubbles to @{code item}. | 499 * if there are any. Append the cookie bubbles to @{code item}. |
| 465 * @param {CookieListItem} item The cookie list item to create items in. | 500 * @param {CookieListItem} item The cookie list item to create items in. |
| 466 */ | 501 */ |
| 467 createItems: function(item) { | 502 createItems: function(item) { |
| 468 if (this.children.length > 0) { | 503 if (this.children.length > 0) { |
| 469 for (var i = 0; i < this.children.length; ++i) | 504 for (var i = 0; i < this.children.length; ++i) |
| 470 this.children[i].createItems(item); | 505 this.children[i].createItems(item); |
| 471 } else if (this.data && !this.data.hasChildren) { | 506 return; |
| 472 var text = ''; | |
| 473 switch (this.data.type) { | |
| 474 case 'cookie': | |
| 475 case 'database': | |
| 476 text = this.data.name; | |
| 477 break; | |
| 478 case 'local_storage': | |
| 479 text = loadTimeData.getString('cookie_local_storage'); | |
| 480 break; | |
| 481 case 'app_cache': | |
| 482 text = loadTimeData.getString('cookie_app_cache'); | |
| 483 break; | |
| 484 case 'indexed_db': | |
| 485 text = loadTimeData.getString('cookie_indexed_db'); | |
| 486 break; | |
| 487 case 'file_system': | |
| 488 text = loadTimeData.getString('cookie_file_system'); | |
| 489 break; | |
| 490 case 'server_bound_cert': | |
| 491 text = loadTimeData.getString('cookie_server_bound_cert'); | |
| 492 break; | |
| 493 } | |
| 494 if (!text) | |
| 495 return; | |
| 496 var div = item.ownerDocument.createElement('div'); | |
| 497 div.className = 'cookie-item'; | |
| 498 // Help out screen readers and such: this is a clickable thing. | |
| 499 div.setAttribute('role', 'button'); | |
| 500 div.textContent = text; | |
| 501 var index = item.appendItem(this, div); | |
| 502 div.onclick = function() { | |
| 503 if (item.selectedIndex == index) | |
| 504 item.selectedIndex = -1; | |
| 505 else | |
| 506 item.selectedIndex = index; | |
| 507 }; | |
| 508 } | 507 } |
| 508 | |
| 509 if (!this.data || this.data.hasChildren) | |
| 510 return; | |
| 511 | |
| 512 var text = ''; | |
| 513 switch (this.data.type) { | |
| 514 case 'cookie': | |
| 515 case 'database': | |
| 516 text = this.data.name; | |
| 517 break; | |
| 518 case 'local_storage': | |
|
Evan Stade
2012/07/11 01:45:44
you could potentially do
default:
text = loadTi
Bernhard Bauer
2012/07/11 08:42:11
Sure, done.
| |
| 519 text = loadTimeData.getString('cookie_local_storage'); | |
| 520 break; | |
| 521 case 'app_cache': | |
| 522 text = loadTimeData.getString('cookie_app_cache'); | |
| 523 break; | |
| 524 case 'indexed_db': | |
| 525 text = loadTimeData.getString('cookie_indexed_db'); | |
| 526 break; | |
| 527 case 'file_system': | |
| 528 text = loadTimeData.getString('cookie_file_system'); | |
| 529 break; | |
| 530 case 'server_bound_cert': | |
| 531 text = loadTimeData.getString('cookie_server_bound_cert'); | |
| 532 break; | |
| 533 } | |
| 534 if (!text) | |
| 535 return; | |
| 536 | |
| 537 var div = item.ownerDocument.createElement('div'); | |
| 538 div.className = 'cookie-item'; | |
| 539 // Help out screen readers and such: this is a clickable thing. | |
|
Evan Stade
2012/07/11 01:45:44
could be wrong but I think you also need to tabind
Bernhard Bauer
2012/07/11 08:42:11
Done.
| |
| 540 div.setAttribute('role', 'button'); | |
| 541 div.textContent = text; | |
| 542 var apps = this.data.appsProtectingThis; | |
| 543 if (apps) | |
| 544 apps.forEach(addAppInfo.bind(null, div)); | |
| 545 | |
| 546 var index = item.appendItem(this, div); | |
| 547 div.onclick = function() { | |
| 548 if (item.selectedIndex == index) | |
|
Evan Stade
2012/07/11 01:45:44
ternary operator
Bernhard Bauer
2012/07/11 08:42:11
Done.
| |
| 549 item.selectedIndex = -1; | |
| 550 else | |
| 551 item.selectedIndex = index; | |
| 552 }; | |
| 509 }, | 553 }, |
| 510 | 554 |
| 511 /** | 555 /** |
| 512 * Set the detail text to be displayed to that of this cookie tree node. | 556 * Set the detail text to be displayed to that of this cookie tree node. |
| 513 * Uses preallocated DOM elements for each cookie node type from @{code | 557 * Uses preallocated DOM elements for each cookie node type from @{code |
| 514 * infoNodes}, and inserts the appropriate elements to @{code element}. | 558 * infoNodes}, and inserts the appropriate elements to @{code element}. |
| 515 * @param {Element} element The DOM element to insert elements to. | 559 * @param {Element} element The DOM element to insert elements to. |
| 516 * @param {Object.<string, {table: Element, info: Object.<string, | 560 * @param {Object.<string, {table: Element, info: Object.<string, |
| 517 * Element>}>} infoNodes The map from cookie node types to maps from | 561 * Element>}>} infoNodes The map from cookie node types to maps from |
| 518 * cookie attribute names to DOM elements to display cookie attribute | 562 * cookie attribute names to DOM elements to display cookie attribute |
| 519 * values, created by @{code CookiesList.decorate}. | 563 * values, created by @{code CookiesList.decorate}. |
| 520 */ | 564 */ |
| 521 setDetailText: function(element, infoNodes) { | 565 setDetailText: function(element, infoNodes) { |
| 522 var table; | 566 var table; |
| 523 if (this.data && !this.data.hasChildren) { | 567 if (this.data && !this.data.hasChildren && cookieInfo[this.data.type]) { |
| 524 if (cookieInfo[this.data.type]) { | 568 var info = cookieInfo[this.data.type]; |
| 525 var info = cookieInfo[this.data.type]; | 569 var nodes = infoNodes[this.data.type].info; |
| 526 var nodes = infoNodes[this.data.type].info; | 570 for (var i = 0; i < info.length; ++i) { |
| 527 for (var i = 0; i < info.length; ++i) { | 571 var name = info[i][0]; |
| 528 var name = info[i][0]; | 572 if (name != 'id' && this.data[name]) |
| 529 if (name != 'id' && this.data[name]) | 573 nodes[name].textContent = this.data[name]; |
| 530 nodes[name].textContent = this.data[name]; | 574 else |
| 531 else | 575 nodes[name].textContent = ''; |
| 532 nodes[name].textContent = ''; | |
| 533 } | |
| 534 table = infoNodes[this.data.type].table; | |
| 535 } | 576 } |
| 577 table = infoNodes[this.data.type].table; | |
| 536 } | 578 } |
| 579 | |
| 537 while (element.childNodes.length > 1) | 580 while (element.childNodes.length > 1) |
| 538 element.removeChild(element.firstChild); | 581 element.removeChild(element.firstChild); |
| 582 | |
| 539 if (table) | 583 if (table) |
| 540 element.insertBefore(table, element.firstChild); | 584 element.insertBefore(table, element.firstChild); |
| 541 }, | 585 }, |
| 542 | 586 |
| 543 /** | 587 /** |
| 544 * The parent of this cookie tree node. | 588 * The parent of this cookie tree node. |
| 545 * @type {?CookieTreeNode|CookieListItem} | 589 * @type {?CookieTreeNode|CookieListItem} |
| 546 */ | 590 */ |
| 547 get parent() { | 591 get parent() { |
| 548 // See below for an explanation of this special case. | 592 // See below for an explanation of this special case. |
| 549 if (typeof this.parent_ == 'number') | 593 if (typeof this.parent_ == 'number') |
| 550 return this.list_.getListItemByIndex(this.parent_); | 594 return this.list_.getListItemByIndex(this.parent_); |
| 551 return this.parent_; | 595 return this.parent_; |
| 552 }, | 596 }, |
| 553 set parent(parent) { | 597 set parent(parent) { |
| 554 if (parent == this.parent) | 598 if (parent == this.parent) |
| 555 return; | 599 return; |
| 600 | |
| 556 if (parent instanceof CookieListItem) { | 601 if (parent instanceof CookieListItem) { |
| 557 // If the parent is to be a CookieListItem, then we keep the reference | 602 // If the parent is to be a CookieListItem, then we keep the reference |
| 558 // to it by its containing list and list index, rather than directly. | 603 // to it by its containing list and list index, rather than directly. |
| 559 // This allows the list items to be garbage collected when they scroll | 604 // This allows the list items to be garbage collected when they scroll |
| 560 // out of view (except the expanded item, which we cache). This is | 605 // out of view (except the expanded item, which we cache). This is |
| 561 // transparent except in the setter and getter, where we handle it. | 606 // transparent except in the setter and getter, where we handle it. |
| 562 this.parent_ = parent.listIndex; | 607 this.parent_ = parent.listIndex; |
| 563 this.list_ = parent.list; | 608 this.list_ = parent.list; |
| 564 parent.addEventListener('listIndexChange', | 609 parent.addEventListener('listIndexChange', |
| 565 this.parentIndexChanged_.bind(this)); | 610 this.parentIndexChanged_.bind(this)); |
| 566 } else { | 611 } else { |
| 567 this.parent_ = parent; | 612 this.parent_ = parent; |
| 568 } | 613 } |
| 614 | |
| 569 if (this.data && this.data.id) { | 615 if (this.data && this.data.id) { |
| 570 if (parent) | 616 if (parent) |
| 571 parentLookup[this.data.id] = this; | 617 parentLookup[this.data.id] = this; |
| 572 else | 618 else |
| 573 delete parentLookup[this.data.id]; | 619 delete parentLookup[this.data.id]; |
| 574 } | 620 } |
| 621 | |
| 575 if (this.data && this.data.hasChildren && | 622 if (this.data && this.data.hasChildren && |
| 576 !this.children.length && !lookupRequests[this.data.id]) { | 623 !this.children.length && !lookupRequests[this.data.id]) { |
| 577 lookupRequests[this.data.id] = true; | 624 lookupRequests[this.data.id] = true; |
| 578 chrome.send('loadCookie', [this.pathId]); | 625 chrome.send('loadCookie', [this.pathId]); |
| 579 } | 626 } |
| 580 }, | 627 }, |
| 581 | 628 |
| 582 /** | 629 /** |
| 583 * Called when the parent is a CookieListItem whose index has changed. | 630 * Called when the parent is a CookieListItem whose index has changed. |
| 584 * See the code above that avoids keeping a direct reference to | 631 * See the code above that avoids keeping a direct reference to |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 parent.clear(); | 901 parent.clear(); |
| 855 this.addByParent_(parent, 0, children); | 902 this.addByParent_(parent, 0, children); |
| 856 parent.endBatchUpdates(); | 903 parent.endBatchUpdates(); |
| 857 }, | 904 }, |
| 858 }; | 905 }; |
| 859 | 906 |
| 860 return { | 907 return { |
| 861 CookiesList: CookiesList | 908 CookiesList: CookiesList |
| 862 }; | 909 }; |
| 863 }); | 910 }); |
| OLD | NEW |