| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * This view displays information on the host resolver: | |
| 7 * | |
| 8 * - Shows the default address family. | |
| 9 * - Has a button to enable IPv6, if it is disabled. | |
| 10 * - Shows the current host cache contents. | |
| 11 * - Has a button to clear the host cache. | |
| 12 * - Shows the parameters used to construct the host cache (capacity, ttl). | |
| 13 * | |
| 14 * @constructor | |
| 15 */ | |
| 16 function DnsView() { | |
| 17 const mainBoxId = 'dnsTabContent'; | |
| 18 const cacheTbodyId = 'hostResolverCacheTbody'; | |
| 19 const clearCacheButtonId = 'clearHostResolverCache'; | |
| 20 const defaultFamilySpanId = 'hostResolverDefaultFamily'; | |
| 21 const ipv6DisabledSpanId = 'hostResolverIPv6Disabled'; | |
| 22 const enableIPv6ButtonId = 'hostResolverEnableIPv6'; | |
| 23 const capacitySpanId = 'hostResolverCacheCapacity'; | |
| 24 const ttlSuccessSpanId = 'hostResolverCacheTTLSuccess'; | |
| 25 const ttlFailureSpanId = 'hostResolverCacheTTLFailure'; | |
| 26 | |
| 27 DivView.call(this, mainBoxId); | |
| 28 | |
| 29 // Hook up the UI components. | |
| 30 this.cacheTbody_ = $(cacheTbodyId); | |
| 31 this.defaultFamilySpan_ = $(defaultFamilySpanId); | |
| 32 this.ipv6DisabledSpan_ = $(ipv6DisabledSpanId); | |
| 33 | |
| 34 $(enableIPv6ButtonId).onclick = g_browser.enableIPv6.bind(g_browser); | |
| 35 | |
| 36 this.capacitySpan_ = $(capacitySpanId); | |
| 37 this.ttlSuccessSpan_ = $(ttlSuccessSpanId); | |
| 38 this.ttlFailureSpan_ = $(ttlFailureSpanId); | |
| 39 | |
| 40 var clearCacheButton = $(clearCacheButtonId); | |
| 41 clearCacheButton.onclick = | |
| 42 g_browser.sendClearHostResolverCache.bind(g_browser); | |
| 43 | |
| 44 // Register to receive changes to the host resolver info. | |
| 45 g_browser.addHostResolverInfoObserver(this); | |
| 46 } | |
| 47 | |
| 48 inherits(DnsView, DivView); | |
| 49 | |
| 50 DnsView.prototype.onLoadLogFinish = function(data) { | |
| 51 return this.onHostResolverInfoChanged(data.hostResolverInfo); | |
| 52 }; | |
| 53 | |
| 54 DnsView.prototype.onHostResolverInfoChanged = function(hostResolverInfo) { | |
| 55 // Clear the existing values. | |
| 56 this.defaultFamilySpan_.innerHTML = ''; | |
| 57 this.capacitySpan_.innerHTML = ''; | |
| 58 this.ttlSuccessSpan_.innerHTML = ''; | |
| 59 this.ttlFailureSpan_.innerHTML = ''; | |
| 60 this.cacheTbody_.innerHTML = ''; | |
| 61 | |
| 62 // No info. | |
| 63 if (!hostResolverInfo || !hostResolverInfo.cache) | |
| 64 return false; | |
| 65 | |
| 66 var family = hostResolverInfo.default_address_family; | |
| 67 addTextNode(this.defaultFamilySpan_, getKeyWithValue(AddressFamily, family)); | |
| 68 | |
| 69 var ipv6Disabled = (family == AddressFamily.ADDRESS_FAMILY_IPV4); | |
| 70 setNodeDisplay(this.ipv6DisabledSpan_, ipv6Disabled); | |
| 71 | |
| 72 // Fill in the basic cache information. | |
| 73 var hostResolverCache = hostResolverInfo.cache; | |
| 74 addTextNode(this.capacitySpan_, hostResolverCache.capacity); | |
| 75 addTextNode(this.ttlSuccessSpan_, hostResolverCache.ttl_success_ms); | |
| 76 addTextNode(this.ttlFailureSpan_, hostResolverCache.ttl_failure_ms); | |
| 77 | |
| 78 // Fill in the cache contents table. | |
| 79 for (var i = 0; i < hostResolverCache.entries.length; ++i) { | |
| 80 var e = hostResolverCache.entries[i]; | |
| 81 var tr = addNode(this.cacheTbody_, 'tr'); | |
| 82 | |
| 83 var hostnameCell = addNode(tr, 'td'); | |
| 84 addTextNode(hostnameCell, e.hostname); | |
| 85 | |
| 86 var familyCell = addNode(tr, 'td'); | |
| 87 addTextNode(familyCell, getKeyWithValue(AddressFamily, e.address_family)); | |
| 88 | |
| 89 var addressesCell = addNode(tr, 'td'); | |
| 90 | |
| 91 if (e.error != undefined) { | |
| 92 addTextNode(addressesCell, 'error: ' + e.error); | |
| 93 } else { | |
| 94 for (var j = 0; j < e.addresses.length; ++j) { | |
| 95 var address = e.addresses[j]; | |
| 96 if (j != 0) | |
| 97 addNode(addressesCell, 'br'); | |
| 98 addTextNode(addressesCell, address); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 var expiresDate = convertTimeTicksToDate(e.expiration); | |
| 103 var expiresCell = addNode(tr, 'td'); | |
| 104 addTextNode(expiresCell, expiresDate.toLocaleString()); | |
| 105 } | |
| 106 | |
| 107 return true; | |
| 108 }; | |
| OLD | NEW |