diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-05 19:28:36 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-05 19:28:36 +0000 |
commit | a0360d8b084eb8908b5bc57e409304aa96947bd4 (patch) | |
tree | ddfbcfe03a7d2ed1722e6da00809155dc12a9b96 /chrome/browser/resources | |
parent | 678223eaf6708d2d3839d488c99729c80ddb8f6f (diff) | |
download | chromium_src-a0360d8b084eb8908b5bc57e409304aa96947bd4.zip chromium_src-a0360d8b084eb8908b5bc57e409304aa96947bd4.tar.gz chromium_src-a0360d8b084eb8908b5bc57e409304aa96947bd4.tar.bz2 |
Add the proxy information to the new net internals page.
BUG=37421
Review URL: http://codereview.chromium.org/1607004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources')
-rw-r--r-- | chrome/browser/resources/net_internals/index.html | 22 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/main.css | 12 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/main.js | 190 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/proxyview.js | 62 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/requestsview.js | 2 |
5 files changed, 260 insertions, 28 deletions
diff --git a/chrome/browser/resources/net_internals/index.html b/chrome/browser/resources/net_internals/index.html index fb7ff9a..f6df28d 100644 --- a/chrome/browser/resources/net_internals/index.html +++ b/chrome/browser/resources/net_internals/index.html @@ -18,6 +18,7 @@ found in the LICENSE file. <script src="timelineviewpainter.js"></script> <script src="logviewpainter.js"></script> <script src="loggrouper.js"></script> + <script src="proxyview.js"></script> </head> <body onload="onLoaded()"> <!-- Tab switcher for main categories. --> @@ -31,8 +32,27 @@ found in the LICENSE file. </ul> <div style="clear: both;"></div> </div> + <!-- Proxy info --> + <div id=proxyTabContent> + <h4> + Current proxy settings + <input type=button value="Reload settings" id=proxyReloadSettings /> + </h4> + <pre id=proxyCurrentConfig></pre> + + <h4> + Proxies which have failed recently, and are marked as bad + <input type=button value="Clear bad proxies" id=clearBadProxies /> + </h4> + <table border=1> + <thead> + <th>Bad proxy server</th> + <th>Time for next retry</th> + </thead> + <tbody id=badProxiesTableBody></tbody> + </table> + </div> <!-- Sections TODO --> - <div id=proxyTabContent>TODO: display proxy information (PAC error log, initialization log, current settings.)</div> <div id=dnsTabContent>TODO: display dns information (outstanding jobs, host cache).</div> <div id=socketsTabContent>TODO: display socket information (outstanding connect jobs)</div> <div id=httpCacheTabContent>TODO: display http cache information (disk cache navigator)</div> diff --git a/chrome/browser/resources/net_internals/main.css b/chrome/browser/resources/net_internals/main.css index cc87520..76c608d 100644 --- a/chrome/browser/resources/net_internals/main.css +++ b/chrome/browser/resources/net_internals/main.css @@ -180,6 +180,16 @@ body { } #detailsLogBox, -#detailsTimelineBox { +#detailsTimelineBox, +#proxyTabContent { overflow: auto; } + +#proxyTabContent { + padding-left: 20px; +} + +#proxyTabContent td, +#proxyTabContent th { + font-size: 12px; +} diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js index 7b9d3c9..c9bf433 100644 --- a/chrome/browser/resources/net_internals/main.js +++ b/chrome/browser/resources/net_internals/main.js @@ -11,9 +11,17 @@ var LogEventPhase = null; var LogSourceType = null; /** + * Object to communicate between the renderer and the browser. + * @type {!BrowserBridge} + */ +var g_browser = null; + +/** * Main entry point. called once the page has loaded. */ function onLoaded() { + g_browser = new BrowserBridge(); + // Create the view which displays requests lists, and lets you select, filter // and delete them. var requestsView = new RequestsView('requestsListTableBody', @@ -35,13 +43,20 @@ function onLoaded() { "actionBox", "splitterBox"); + // Create a view which will display info on the proxy setup. + var proxyView = new ProxyView("proxyTabContent", + "proxyCurrentConfig", + "proxyReloadSettings", + "badProxiesTableBody", + "clearBadProxies"); + // Create a view which lets you tab between the different sub-views. var categoryTabSwitcher = new TabSwitcherView(new DivView('categoryTabHandles')); // Populate the main tabs. categoryTabSwitcher.addTab('requestsTab', requestsView); - categoryTabSwitcher.addTab('proxyTab', new DivView('proxyTabContent')); + categoryTabSwitcher.addTab('proxyTab', proxyView); categoryTabSwitcher.addTab('dnsTab', new DivView('dnsTabContent')); categoryTabSwitcher.addTab('socketsTab', new DivView('socketsTabContent')); categoryTabSwitcher.addTab('httpCacheTab', @@ -57,55 +72,180 @@ function onLoaded() { windowView.resetGeometry(); // Tell the browser that we are ready to start receiving log events. - notifyApplicationReady(); + g_browser.sendReady(); } +/** + * This class provides a "bridge" for communicating between the javascript and + * the browser. + * + * @constructor + */ +function BrowserBridge() { + // List of observers for various bits of browser state. + this.logObservers_ = []; + this.proxySettingsObservers_ = []; + this.badProxiesObservers_ = []; + + // Map from observer method name (i.e. 'onProxySettingsChanged', 'onBadProxiesChanged') + // to the previously received data for that type. Used to tell if the data has + // actually changed since we last polled it. + this.prevPollData_ = {}; +} + +/** + * Delay in milliseconds between polling of certain browser information. + */ +BrowserBridge.POLL_INTERVAL_MS = 5000; + //------------------------------------------------------------------------------ // Messages sent to the browser //------------------------------------------------------------------------------ -function notifyApplicationReady() { +BrowserBridge.prototype.sendReady = function() { chrome.send('notifyReady'); -} + + // Some of the data we are interested is not currently exposed as a stream, + // so we will poll the browser to find out when it changes and then notify + // the observers. + window.setInterval( + this.doPolling_.bind(this), BrowserBridge.POLL_INTERVAL_MS); +}; + +BrowserBridge.prototype.sendGetProxySettings = function() { + // The browser will call receivedProxySettings on completion. + chrome.send('getProxySettings'); +}; + +BrowserBridge.prototype.sendReloadProxySettings = function() { + chrome.send('reloadProxySettings'); +}; + +BrowserBridge.prototype.sendGetBadProxies = function() { + // The browser will call receivedBadProxies on completion. + chrome.send('getBadProxies'); +}; + +BrowserBridge.prototype.sendClearBadProxies = function() { + chrome.send('clearBadProxies'); +}; //------------------------------------------------------------------------------ // Messages received from the browser //------------------------------------------------------------------------------ -function onLogEntryAdded(logEntry) { - LogDataProvider.broadcast(logEntry); -} +BrowserBridge.prototype.receivedLogEntry = function(logEntry) { + for (var i = 0; i < this.logObservers_.length; ++i) + this.logObservers_[i].onLogEntryAdded(logEntry); +}; -function setLogEventTypeConstants(constantsMap) { +BrowserBridge.prototype.receivedLogEventTypeConstants = function(constantsMap) { LogEventType = constantsMap; -} +}; -function setLogEventPhaseConstants(constantsMap) { +BrowserBridge.prototype.receivedLogEventPhaseConstants = function(constantsMap) { LogEventPhase = constantsMap; -} +}; -function setLogSourceTypeConstants(constantsMap) { +BrowserBridge.prototype.receivedLogSourceTypeConstants = function(constantsMap) { LogSourceType = constantsMap; -} +}; -function setLogEntryTypeConstants(constantsMap) { +BrowserBridge.prototype.receivedLogEntryTypeConstants = function(constantsMap) { LogEntryType = constantsMap; -} +}; + +BrowserBridge.prototype.receivedTimeTickOffset = function(timeTickOffset) { + this.timeTickOffset_ = timeTickOffset; +}; + +BrowserBridge.prototype.receivedProxySettings = function(proxySettings) { + this.dispatchToObserversFromPoll_( + this.proxySettingsObservers_, 'onProxySettingsChanged', proxySettings); +}; + +BrowserBridge.prototype.receivedBadProxies = function(badProxies) { + this.dispatchToObserversFromPoll_( + this.badProxiesObservers_, 'onBadProxiesChanged', badProxies); +}; -//------------------------------------------------------------------------------ -// LogDataProvider //------------------------------------------------------------------------------ -var LogDataProvider = {} +/** + * Adds a listener of log entries. |observer| will be called back when new log + * data arrives, through: + * + * observer.onLogEntryAdded(logEntry) + */ +BrowserBridge.prototype.addLogObserver = function(observer) { + this.logObservers_.push(observer); +}; -LogDataProvider.observers_ = []; +/** + * Adds a listener of the proxy settings. |observer| will be called back when + * data is received, through: + * + * observer.onProxySettingsChanged(proxySettings) + * + * |proxySettings| is a formatted string describing the settings. + * TODO(eroman): send a dictionary instead. + */ +BrowserBridge.prototype.addProxySettingsObserver = function(observer) { + this.proxySettingsObservers_.push(observer); +}; + +/** + * Adds a listener of the proxy settings. |observer| will be called back when + * data is received, through: + * + * observer.onBadProxiesChanged(badProxies) + * + * |badProxies| is an array, where each entry has the property: + * badProxies[i].proxy_uri: String identify the proxy. + * badProxies[i].bad_until: The time when the proxy stops being considered + * bad. Note the time is in time ticks. + */ +BrowserBridge.prototype.addBadProxiesObsever = function(observer) { + this.badProxiesObservers_.push(observer); +}; + +/** + * The browser gives us times in terms of "time ticks" in milliseconds. + * This function converts the tick count to a Date() object. + * + * @param {String} timeTicks. + * @returns {Date} The time that |timeTicks| represents. + */ +BrowserBridge.prototype.convertTimeTicksToDate = function(timeTicks) { + // Note that the subtraction by 0 is to cast to a number (probably a float + // since the numbers are big). + var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); + var d = new Date(); + d.setTime(timeStampMs); + return d; +}; -LogDataProvider.broadcast = function(logEntry) { - for (var i = 0; i < this.observers_.length; ++i) { - this.observers_[i].onLogEntryAdded(logEntry); - } +BrowserBridge.prototype.doPolling_ = function() { + this.sendGetProxySettings(); + this.sendGetBadProxies(); }; -LogDataProvider.addObserver = function(observer) { - this.observers_.push(observer); +/** + * Helper function to handle calling all the observers, but ONLY if the data has + * actually changed since last time. This is used for data we received from + * browser on a poll loop. + */ +BrowserBridge.prototype.dispatchToObserversFromPoll_ = function( + observerList, method, data) { + var prevData = this.prevPollData_[method]; + + // If the data hasn't changed since last time, no need to notify observers. + if (prevData && JSON.stringify(prevData) == JSON.stringify(data)) + return; + + this.prevPollData_[method] = data; + + // Ok, notify the observers of the change. + for (var i = 0; i < observerList.length; ++i) + observerList[i][method](data); }; diff --git a/chrome/browser/resources/net_internals/proxyview.js b/chrome/browser/resources/net_internals/proxyview.js new file mode 100644 index 0000000..4d7d885 --- /dev/null +++ b/chrome/browser/resources/net_internals/proxyview.js @@ -0,0 +1,62 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * This view displays information on the proxy setup: + * + * - Shows the current proxy settings. + * - Has a button to reload these settings. + * - Shows the list of proxy hostnames that are cached as "bad". + * - Has a button to clear the cached bad proxies. + * + * @constructor + */ +function ProxyView(mainBoxId, + currentConfigDivId, + reloadSettingsButtonId, + badProxiesTbodyId, + clearBadProxiesButtonId) { + DivView.call(this, mainBoxId); + + // Hook up the UI components. + this.currentConfigDiv_ = document.getElementById(currentConfigDivId); + this.badProxiesTbody_ = document.getElementById(badProxiesTbodyId); + + var reloadSettingsButton = document.getElementById(reloadSettingsButtonId); + var clearBadProxiesButton = document.getElementById(clearBadProxiesButtonId); + + clearBadProxiesButton.onclick = g_browser.sendClearBadProxies.bind(g_browser); + reloadSettingsButton.onclick = + g_browser.sendReloadProxySettings.bind(g_browser); + + // Register to receive proxy information as it changes. + g_browser.addProxySettingsObserver(this); + g_browser.addBadProxiesObsever(this); +} + +inherits(ProxyView, DivView); + +ProxyView.prototype.onProxySettingsChanged = function(proxySettings) { + // |proxySettings| is a formatted string describing the settings. + this.currentConfigDiv_.innerHTML = '' + addTextNode(this.currentConfigDiv_, proxySettings); +}; + +ProxyView.prototype.onBadProxiesChanged = function(badProxies) { + this.badProxiesTbody_.innerHTML = ''; + + // Add a table row for each bad proxy entry. + for (var i = 0; i < badProxies.length; ++i) { + var entry = badProxies[i]; + var badUntilDate = g_browser.convertTimeTicksToDate(entry.bad_until); + + var tr = addNode(this.badProxiesTbody_, 'tr'); + + var nameCell = addNode(tr, 'td'); + var badUntilCell = addNode(tr, 'td'); + + addTextNode(nameCell, entry.proxy_uri); + addTextNode(badUntilCell, badUntilDate.toLocaleString()); + } +}; diff --git a/chrome/browser/resources/net_internals/requestsview.js b/chrome/browser/resources/net_internals/requestsview.js index 16b39b9..2d16704 100644 --- a/chrome/browser/resources/net_internals/requestsview.js +++ b/chrome/browser/resources/net_internals/requestsview.js @@ -49,7 +49,7 @@ function RequestsView(tableBodyId, filterInputId, filterCountId, this.sourceIdToEntryMap_ = {}; this.currentSelectedSources_ = []; - LogDataProvider.addObserver(this); + g_browser.addLogObserver(this); this.tableBody_ = document.getElementById(tableBodyId); |