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 proxy setup: 7 * 8 * - Shows the current proxy settings. 9 * - Has a button to reload these settings. 10 * - Shows the log entries for the most recent INIT_PROXY_RESOLVER source 11 * - Shows the list of proxy hostnames that are cached as "bad". 12 * - Has a button to clear the cached bad proxies. 13 * 14 * @constructor 15 */ 16 function ProxyView(mainBoxId, 17 originalSettingsDivId, 18 effectiveSettingsDivId, 19 reloadSettingsButtonId, 20 badProxiesTbodyId, 21 clearBadProxiesButtonId, 22 proxyResolverLogPreId) { 23 DivView.call(this, mainBoxId); 24 25 this.latestProxySourceEntries_ = null; 26 this.latestProxySourceId_ = 0; 27 28 // Hook up the UI components. 29 this.originalSettingsDiv_ = document.getElementById(originalSettingsDivId); 30 this.effectiveSettingsDiv_ = 31 document.getElementById(effectiveSettingsDivId); 32 this.proxyResolverLogPre_ = document.getElementById(proxyResolverLogPreId); 33 this.badProxiesTbody_ = document.getElementById(badProxiesTbodyId); 34 35 var reloadSettingsButton = document.getElementById(reloadSettingsButtonId); 36 var clearBadProxiesButton = document.getElementById(clearBadProxiesButtonId); 37 38 clearBadProxiesButton.onclick = g_browser.sendClearBadProxies.bind(g_browser); 39 reloadSettingsButton.onclick = 40 g_browser.sendReloadProxySettings.bind(g_browser); 41 42 // Register to receive proxy information as it changes. 43 g_browser.addProxySettingsObserver(this); 44 g_browser.addBadProxiesObserver(this); 45 g_browser.addLogObserver(this); 46 } 47 48 inherits(ProxyView, DivView); 49 50 ProxyView.prototype.onProxySettingsChanged = function(proxySettings) { 51 var original = proxySettings.original; 52 var effective = proxySettings.effective; 53 54 // Both |original| and |effective| are dictionaries describing the settings. 55 this.originalSettingsDiv_.innerHTML = '' 56 this.effectiveSettingsDiv_.innerHTML = '' 57 58 addTextNode(this.originalSettingsDiv_, proxySettingsToString(original)); 59 addTextNode(this.effectiveSettingsDiv_, proxySettingsToString(effective)); 60 }; 61 62 ProxyView.prototype.onBadProxiesChanged = function(badProxies) { 63 this.badProxiesTbody_.innerHTML = ''; 64 65 // Add a table row for each bad proxy entry. 66 for (var i = 0; i < badProxies.length; ++i) { 67 var entry = badProxies[i]; 68 var badUntilDate = g_browser.convertTimeTicksToDate(entry.bad_until); 69 70 var tr = addNode(this.badProxiesTbody_, 'tr'); 71 72 var nameCell = addNode(tr, 'td'); 73 var badUntilCell = addNode(tr, 'td'); 74 75 addTextNode(nameCell, entry.proxy_uri); 76 addTextNode(badUntilCell, badUntilDate.toLocaleString()); 77 } 78 }; 79 80 ProxyView.prototype.onLogEntryAdded = function(logEntry) { 81 if (logEntry.source.type != LogSourceType.INIT_PROXY_RESOLVER || 82 this.latestProxySourceId_ > logEntry.source.id) { 83 return; 84 } 85 86 if (logEntry.source.id > this.latestProxySourceId_) { 87 this.latestProxySourceId_ = logEntry.source.id; 88 this.latestProxySourceEntries_ = []; 89 } 90 91 this.latestProxySourceEntries_.push(logEntry); 92 this.proxyResolverLogPre_.innerHTML = ''; 93 addTextNode(this.proxyResolverLogPre_, 94 PrintSourceEntriesAsText(this.latestProxySourceEntries_)); 95 }; 96 97 /** 98 * Clears the display of and log entries for the last proxy lookup. 99 */ 100 ProxyView.prototype.clearLog_ = function() { 101 this.latestProxySourceEntries_ = []; 102 // Prevents display of partial logs. 103 ++this.latestProxySourceId_; 104 105 this.proxyResolverLogPre_.innerHTML = ''; 106 addTextNode(this.proxyResolverLogPre_, 'Deleted.'); 107 }; 108 109 ProxyView.prototype.onLogEntriesDeleted = function(sourceIds) { 110 if (sourceIds.indexOf(this.latestProxySourceId_) != -1) 111 this.clearLog_(); 112 }; 113 114 ProxyView.prototype.onAllLogEntriesDeleted = function() { 115 this.clearLog_(); 116 }; 117 118 ProxyView.prototype.onSetIsViewingLogFile = function(isViewingLogFile) { 119 }; 120 121