| 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 /** | 5 /** |
| 6 * Dictionary of constants (initialized by browser). | 6 * Dictionary of constants (initialized by browser). |
| 7 */ | 7 */ |
| 8 var LogEntryType = null; | 8 var LogEntryType = null; |
| 9 var LogEventType = null; | 9 var LogEventType = null; |
| 10 var LogEventPhase = null; | 10 var LogEventPhase = null; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 "actionBox", | 43 "actionBox", |
| 44 "splitterBox"); | 44 "splitterBox"); |
| 45 | 45 |
| 46 // Create a view which will display info on the proxy setup. | 46 // Create a view which will display info on the proxy setup. |
| 47 var proxyView = new ProxyView("proxyTabContent", | 47 var proxyView = new ProxyView("proxyTabContent", |
| 48 "proxyCurrentConfig", | 48 "proxyCurrentConfig", |
| 49 "proxyReloadSettings", | 49 "proxyReloadSettings", |
| 50 "badProxiesTableBody", | 50 "badProxiesTableBody", |
| 51 "clearBadProxies"); | 51 "clearBadProxies"); |
| 52 | 52 |
| 53 // Create a view which will display information on the host resolver. |
| 54 var dnsView = new DnsView("dnsTabContent", |
| 55 "hostResolverCacheTbody", |
| 56 "clearHostResolverCache", |
| 57 "hostResolverCacheCapacity", |
| 58 "hostResolverCacheTTLSuccess", |
| 59 "hostResolverCacheTTLFailure"); |
| 60 |
| 53 // Create a view which lets you tab between the different sub-views. | 61 // Create a view which lets you tab between the different sub-views. |
| 54 var categoryTabSwitcher = | 62 var categoryTabSwitcher = |
| 55 new TabSwitcherView(new DivView('categoryTabHandles')); | 63 new TabSwitcherView(new DivView('categoryTabHandles')); |
| 56 | 64 |
| 57 // Populate the main tabs. | 65 // Populate the main tabs. |
| 58 categoryTabSwitcher.addTab('requestsTab', requestsView, false); | 66 categoryTabSwitcher.addTab('requestsTab', requestsView, false); |
| 59 categoryTabSwitcher.addTab('proxyTab', proxyView, false); | 67 categoryTabSwitcher.addTab('proxyTab', proxyView, false); |
| 60 categoryTabSwitcher.addTab('dnsTab', new DivView('dnsTabContent'), false); | 68 categoryTabSwitcher.addTab('dnsTab', dnsView, false); |
| 61 categoryTabSwitcher.addTab('socketsTab', new DivView('socketsTabContent'), | 69 categoryTabSwitcher.addTab('socketsTab', new DivView('socketsTabContent'), |
| 62 false); | 70 false); |
| 63 categoryTabSwitcher.addTab('httpCacheTab', | 71 categoryTabSwitcher.addTab('httpCacheTab', |
| 64 new DivView('httpCacheTabContent'), false); | 72 new DivView('httpCacheTabContent'), false); |
| 65 | 73 |
| 66 // Build a map from the anchor name of each tab handle to its "tab ID". | 74 // Build a map from the anchor name of each tab handle to its "tab ID". |
| 67 // We will consider navigations to the #hash as a switch tab request. | 75 // We will consider navigations to the #hash as a switch tab request. |
| 68 var anchorMap = {}; | 76 var anchorMap = {}; |
| 69 var tabIds = categoryTabSwitcher.getAllTabIds(); | 77 var tabIds = categoryTabSwitcher.getAllTabIds(); |
| 70 for (var i = 0; i < tabIds.length; ++i) { | 78 for (var i = 0; i < tabIds.length; ++i) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 97 * This class provides a "bridge" for communicating between the javascript and | 105 * This class provides a "bridge" for communicating between the javascript and |
| 98 * the browser. | 106 * the browser. |
| 99 * | 107 * |
| 100 * @constructor | 108 * @constructor |
| 101 */ | 109 */ |
| 102 function BrowserBridge() { | 110 function BrowserBridge() { |
| 103 // List of observers for various bits of browser state. | 111 // List of observers for various bits of browser state. |
| 104 this.logObservers_ = []; | 112 this.logObservers_ = []; |
| 105 this.proxySettingsObservers_ = []; | 113 this.proxySettingsObservers_ = []; |
| 106 this.badProxiesObservers_ = []; | 114 this.badProxiesObservers_ = []; |
| 115 this.hostResolverCacheObservers_ = []; |
| 107 | 116 |
| 108 // Map from observer method name (i.e. 'onProxySettingsChanged', 'onBadProxies
Changed') | 117 // Map from observer method name (i.e. 'onProxySettingsChanged', |
| 109 // to the previously received data for that type. Used to tell if the data has | 118 // 'onBadProxiesChanged') to the previously received data for that type. Used |
| 110 // actually changed since we last polled it. | 119 // to tell if the data has actually changed since we last polled it. |
| 111 this.prevPollData_ = {}; | 120 this.prevPollData_ = {}; |
| 112 } | 121 } |
| 113 | 122 |
| 114 /** | 123 /** |
| 115 * Delay in milliseconds between polling of certain browser information. | 124 * Delay in milliseconds between polling of certain browser information. |
| 116 */ | 125 */ |
| 117 BrowserBridge.POLL_INTERVAL_MS = 5000; | 126 BrowserBridge.POLL_INTERVAL_MS = 5000; |
| 118 | 127 |
| 119 //------------------------------------------------------------------------------ | 128 //------------------------------------------------------------------------------ |
| 120 // Messages sent to the browser | 129 // Messages sent to the browser |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 | 146 |
| 138 BrowserBridge.prototype.sendReloadProxySettings = function() { | 147 BrowserBridge.prototype.sendReloadProxySettings = function() { |
| 139 chrome.send('reloadProxySettings'); | 148 chrome.send('reloadProxySettings'); |
| 140 }; | 149 }; |
| 141 | 150 |
| 142 BrowserBridge.prototype.sendGetBadProxies = function() { | 151 BrowserBridge.prototype.sendGetBadProxies = function() { |
| 143 // The browser will call receivedBadProxies on completion. | 152 // The browser will call receivedBadProxies on completion. |
| 144 chrome.send('getBadProxies'); | 153 chrome.send('getBadProxies'); |
| 145 }; | 154 }; |
| 146 | 155 |
| 156 BrowserBridge.prototype.sendGetHostResolverCache = function() { |
| 157 // The browser will call receivedHostResolverCache on completion. |
| 158 chrome.send('getHostResolverCache'); |
| 159 }; |
| 160 |
| 147 BrowserBridge.prototype.sendClearBadProxies = function() { | 161 BrowserBridge.prototype.sendClearBadProxies = function() { |
| 148 chrome.send('clearBadProxies'); | 162 chrome.send('clearBadProxies'); |
| 149 }; | 163 }; |
| 150 | 164 |
| 165 BrowserBridge.prototype.sendClearHostResolverCache = function() { |
| 166 chrome.send('clearHostResolverCache'); |
| 167 }; |
| 168 |
| 151 //------------------------------------------------------------------------------ | 169 //------------------------------------------------------------------------------ |
| 152 // Messages received from the browser | 170 // Messages received from the browser |
| 153 //------------------------------------------------------------------------------ | 171 //------------------------------------------------------------------------------ |
| 154 | 172 |
| 155 BrowserBridge.prototype.receivedLogEntry = function(logEntry) { | 173 BrowserBridge.prototype.receivedLogEntry = function(logEntry) { |
| 156 for (var i = 0; i < this.logObservers_.length; ++i) | 174 for (var i = 0; i < this.logObservers_.length; ++i) |
| 157 this.logObservers_[i].onLogEntryAdded(logEntry); | 175 this.logObservers_[i].onLogEntryAdded(logEntry); |
| 158 }; | 176 }; |
| 159 | 177 |
| 160 BrowserBridge.prototype.receivedLogEventTypeConstants = function(constantsMap) { | 178 BrowserBridge.prototype.receivedLogEventTypeConstants = function(constantsMap) { |
| 161 LogEventType = constantsMap; | 179 LogEventType = constantsMap; |
| 162 }; | 180 }; |
| 163 | 181 |
| 164 BrowserBridge.prototype.receivedLogEventPhaseConstants = function(constantsMap)
{ | 182 BrowserBridge.prototype.receivedLogEventPhaseConstants = |
| 183 function(constantsMap) { |
| 165 LogEventPhase = constantsMap; | 184 LogEventPhase = constantsMap; |
| 166 }; | 185 }; |
| 167 | 186 |
| 168 BrowserBridge.prototype.receivedLogSourceTypeConstants = function(constantsMap)
{ | 187 BrowserBridge.prototype.receivedLogSourceTypeConstants = |
| 188 function(constantsMap) { |
| 169 LogSourceType = constantsMap; | 189 LogSourceType = constantsMap; |
| 170 }; | 190 }; |
| 171 | 191 |
| 172 BrowserBridge.prototype.receivedLogEntryTypeConstants = function(constantsMap) { | 192 BrowserBridge.prototype.receivedLogEntryTypeConstants = function(constantsMap) { |
| 173 LogEntryType = constantsMap; | 193 LogEntryType = constantsMap; |
| 174 }; | 194 }; |
| 175 | 195 |
| 176 BrowserBridge.prototype.receivedTimeTickOffset = function(timeTickOffset) { | 196 BrowserBridge.prototype.receivedTimeTickOffset = function(timeTickOffset) { |
| 177 this.timeTickOffset_ = timeTickOffset; | 197 this.timeTickOffset_ = timeTickOffset; |
| 178 }; | 198 }; |
| 179 | 199 |
| 180 BrowserBridge.prototype.receivedProxySettings = function(proxySettings) { | 200 BrowserBridge.prototype.receivedProxySettings = function(proxySettings) { |
| 181 this.dispatchToObserversFromPoll_( | 201 this.dispatchToObserversFromPoll_( |
| 182 this.proxySettingsObservers_, 'onProxySettingsChanged', proxySettings); | 202 this.proxySettingsObservers_, 'onProxySettingsChanged', proxySettings); |
| 183 }; | 203 }; |
| 184 | 204 |
| 185 BrowserBridge.prototype.receivedBadProxies = function(badProxies) { | 205 BrowserBridge.prototype.receivedBadProxies = function(badProxies) { |
| 186 this.dispatchToObserversFromPoll_( | 206 this.dispatchToObserversFromPoll_( |
| 187 this.badProxiesObservers_, 'onBadProxiesChanged', badProxies); | 207 this.badProxiesObservers_, 'onBadProxiesChanged', badProxies); |
| 188 }; | 208 }; |
| 189 | 209 |
| 210 BrowserBridge.prototype.receivedHostResolverCache = |
| 211 function(hostResolverCache) { |
| 212 this.dispatchToObserversFromPoll_( |
| 213 this.hostResolverCacheObservers_, 'onHostResolverCacheChanged', |
| 214 hostResolverCache); |
| 215 }; |
| 216 |
| 190 //------------------------------------------------------------------------------ | 217 //------------------------------------------------------------------------------ |
| 191 | 218 |
| 192 /** | 219 /** |
| 193 * Adds a listener of log entries. |observer| will be called back when new log | 220 * Adds a listener of log entries. |observer| will be called back when new log |
| 194 * data arrives, through: | 221 * data arrives, through: |
| 195 * | 222 * |
| 196 * observer.onLogEntryAdded(logEntry) | 223 * observer.onLogEntryAdded(logEntry) |
| 197 */ | 224 */ |
| 198 BrowserBridge.prototype.addLogObserver = function(observer) { | 225 BrowserBridge.prototype.addLogObserver = function(observer) { |
| 199 this.logObservers_.push(observer); | 226 this.logObservers_.push(observer); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 221 * |badProxies| is an array, where each entry has the property: | 248 * |badProxies| is an array, where each entry has the property: |
| 222 * badProxies[i].proxy_uri: String identify the proxy. | 249 * badProxies[i].proxy_uri: String identify the proxy. |
| 223 * badProxies[i].bad_until: The time when the proxy stops being considered | 250 * badProxies[i].bad_until: The time when the proxy stops being considered |
| 224 * bad. Note the time is in time ticks. | 251 * bad. Note the time is in time ticks. |
| 225 */ | 252 */ |
| 226 BrowserBridge.prototype.addBadProxiesObsever = function(observer) { | 253 BrowserBridge.prototype.addBadProxiesObsever = function(observer) { |
| 227 this.badProxiesObservers_.push(observer); | 254 this.badProxiesObservers_.push(observer); |
| 228 }; | 255 }; |
| 229 | 256 |
| 230 /** | 257 /** |
| 258 * Adds a listener of the host resolver cache. |observer| will be called back |
| 259 * when data is received, through: |
| 260 * |
| 261 * observer.onHostResolverCacheChanged(hostResolverCache) |
| 262 */ |
| 263 BrowserBridge.prototype.addHostResolverCacheObserver = function(observer) { |
| 264 this.hostResolverCacheObservers_.push(observer); |
| 265 }; |
| 266 |
| 267 /** |
| 231 * The browser gives us times in terms of "time ticks" in milliseconds. | 268 * The browser gives us times in terms of "time ticks" in milliseconds. |
| 232 * This function converts the tick count to a Date() object. | 269 * This function converts the tick count to a Date() object. |
| 233 * | 270 * |
| 234 * @param {String} timeTicks. | 271 * @param {String} timeTicks. |
| 235 * @returns {Date} The time that |timeTicks| represents. | 272 * @returns {Date} The time that |timeTicks| represents. |
| 236 */ | 273 */ |
| 237 BrowserBridge.prototype.convertTimeTicksToDate = function(timeTicks) { | 274 BrowserBridge.prototype.convertTimeTicksToDate = function(timeTicks) { |
| 238 // Note that the subtraction by 0 is to cast to a number (probably a float | 275 // Note that the subtraction by 0 is to cast to a number (probably a float |
| 239 // since the numbers are big). | 276 // since the numbers are big). |
| 240 var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); | 277 var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); |
| 241 var d = new Date(); | 278 var d = new Date(); |
| 242 d.setTime(timeStampMs); | 279 d.setTime(timeStampMs); |
| 243 return d; | 280 return d; |
| 244 }; | 281 }; |
| 245 | 282 |
| 246 BrowserBridge.prototype.doPolling_ = function() { | 283 BrowserBridge.prototype.doPolling_ = function() { |
| 284 // TODO(eroman): Optimize this by using a separate polling frequency for the |
| 285 // data consumed by the currently active view. Everything else can be on a low |
| 286 // frequency poll since it won't impact the display. |
| 247 this.sendGetProxySettings(); | 287 this.sendGetProxySettings(); |
| 248 this.sendGetBadProxies(); | 288 this.sendGetBadProxies(); |
| 289 this.sendGetHostResolverCache(); |
| 249 }; | 290 }; |
| 250 | 291 |
| 251 /** | 292 /** |
| 252 * Helper function to handle calling all the observers, but ONLY if the data has | 293 * Helper function to handle calling all the observers, but ONLY if the data has |
| 253 * actually changed since last time. This is used for data we received from | 294 * actually changed since last time. This is used for data we received from |
| 254 * browser on a poll loop. | 295 * browser on a poll loop. |
| 255 */ | 296 */ |
| 256 BrowserBridge.prototype.dispatchToObserversFromPoll_ = function( | 297 BrowserBridge.prototype.dispatchToObserversFromPoll_ = function( |
| 257 observerList, method, data) { | 298 observerList, method, data) { |
| 258 var prevData = this.prevPollData_[method]; | 299 var prevData = this.prevPollData_[method]; |
| 259 | 300 |
| 260 // If the data hasn't changed since last time, no need to notify observers. | 301 // If the data hasn't changed since last time, no need to notify observers. |
| 261 if (prevData && JSON.stringify(prevData) == JSON.stringify(data)) | 302 if (prevData && JSON.stringify(prevData) == JSON.stringify(data)) |
| 262 return; | 303 return; |
| 263 | 304 |
| 264 this.prevPollData_[method] = data; | 305 this.prevPollData_[method] = data; |
| 265 | 306 |
| 266 // Ok, notify the observers of the change. | 307 // Ok, notify the observers of the change. |
| 267 for (var i = 0; i < observerList.length; ++i) | 308 for (var i = 0; i < observerList.length; ++i) |
| 268 observerList[i][method](data); | 309 observerList[i][method](data); |
| 269 }; | 310 }; |
| OLD | NEW |