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 LogEventType = null; | 8 var LogEventType = null; |
9 var LogEventPhase = null; | 9 var LogEventPhase = null; |
10 var LogSourceType = null; | 10 var LogSourceType = null; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 "clearBadProxies"); | 50 "clearBadProxies"); |
51 | 51 |
52 // Create a view which will display information on the host resolver. | 52 // Create a view which will display information on the host resolver. |
53 var dnsView = new DnsView("dnsTabContent", | 53 var dnsView = new DnsView("dnsTabContent", |
54 "hostResolverCacheTbody", | 54 "hostResolverCacheTbody", |
55 "clearHostResolverCache", | 55 "clearHostResolverCache", |
56 "hostResolverCacheCapacity", | 56 "hostResolverCacheCapacity", |
57 "hostResolverCacheTTLSuccess", | 57 "hostResolverCacheTTLSuccess", |
58 "hostResolverCacheTTLFailure"); | 58 "hostResolverCacheTTLFailure"); |
59 | 59 |
| 60 // Create a view which will display import/export options to control the |
| 61 // captured data. |
| 62 var dataView = new DataView("dataTabContent", "exportToJson", "exportToText"); |
| 63 |
60 // Create a view which lets you tab between the different sub-views. | 64 // Create a view which lets you tab between the different sub-views. |
61 var categoryTabSwitcher = | 65 var categoryTabSwitcher = |
62 new TabSwitcherView(new DivView('categoryTabHandles')); | 66 new TabSwitcherView(new DivView('categoryTabHandles')); |
63 | 67 |
64 // Populate the main tabs. | 68 // Populate the main tabs. |
65 categoryTabSwitcher.addTab('requestsTab', requestsView, false); | 69 categoryTabSwitcher.addTab('requestsTab', requestsView, false); |
66 categoryTabSwitcher.addTab('proxyTab', proxyView, false); | 70 categoryTabSwitcher.addTab('proxyTab', proxyView, false); |
67 categoryTabSwitcher.addTab('dnsTab', dnsView, false); | 71 categoryTabSwitcher.addTab('dnsTab', dnsView, false); |
68 categoryTabSwitcher.addTab('socketsTab', new DivView('socketsTabContent'), | 72 categoryTabSwitcher.addTab('socketsTab', new DivView('socketsTabContent'), |
69 false); | 73 false); |
70 categoryTabSwitcher.addTab('httpCacheTab', | 74 categoryTabSwitcher.addTab('httpCacheTab', |
71 new DivView('httpCacheTabContent'), false); | 75 new DivView('httpCacheTabContent'), false); |
| 76 categoryTabSwitcher.addTab('dataTab', dataView, false); |
72 | 77 |
73 // Build a map from the anchor name of each tab handle to its "tab ID". | 78 // Build a map from the anchor name of each tab handle to its "tab ID". |
74 // We will consider navigations to the #hash as a switch tab request. | 79 // We will consider navigations to the #hash as a switch tab request. |
75 var anchorMap = {}; | 80 var anchorMap = {}; |
76 var tabIds = categoryTabSwitcher.getAllTabIds(); | 81 var tabIds = categoryTabSwitcher.getAllTabIds(); |
77 for (var i = 0; i < tabIds.length; ++i) { | 82 for (var i = 0; i < tabIds.length; ++i) { |
78 var aNode = document.getElementById(tabIds[i]); | 83 var aNode = document.getElementById(tabIds[i]); |
79 anchorMap[aNode.hash] = tabIds[i]; | 84 anchorMap[aNode.hash] = tabIds[i]; |
80 } | 85 } |
81 // Default the empty hash to the requests tab. | 86 // Default the empty hash to the requests tab. |
(...skipping 20 matching lines...) Expand all Loading... |
102 | 107 |
103 /** | 108 /** |
104 * This class provides a "bridge" for communicating between the javascript and | 109 * This class provides a "bridge" for communicating between the javascript and |
105 * the browser. | 110 * the browser. |
106 * | 111 * |
107 * @constructor | 112 * @constructor |
108 */ | 113 */ |
109 function BrowserBridge() { | 114 function BrowserBridge() { |
110 // List of observers for various bits of browser state. | 115 // List of observers for various bits of browser state. |
111 this.logObservers_ = []; | 116 this.logObservers_ = []; |
112 this.proxySettingsObservers_ = []; | 117 this.proxySettings_ = new PollableDataHelper('onProxySettingsChanged'); |
113 this.badProxiesObservers_ = []; | 118 this.badProxies_ = new PollableDataHelper('onBadProxiesChanged'); |
114 this.hostResolverCacheObservers_ = []; | 119 this.hostResolverCache_ = new PollableDataHelper('onHostResolverCacheChanged')
; |
115 | 120 |
116 // Map from observer method name (i.e. 'onProxySettingsChanged', | 121 // Cache of the data received. |
117 // 'onBadProxiesChanged') to the previously received data for that type. Used | 122 // TODO(eroman): the controls to clear data in the "Requests" tab should be |
118 // to tell if the data has actually changed since we last polled it. | 123 // affecting this as well. |
119 this.prevPollData_ = {}; | 124 this.passivelyCapturedEvents_ = []; |
| 125 this.activelyCapturedEvents_ = []; |
120 } | 126 } |
121 | 127 |
122 /** | 128 /** |
123 * Delay in milliseconds between polling of certain browser information. | 129 * Delay in milliseconds between polling of certain browser information. |
124 */ | 130 */ |
125 BrowserBridge.POLL_INTERVAL_MS = 5000; | 131 BrowserBridge.POLL_INTERVAL_MS = 5000; |
126 | 132 |
127 //------------------------------------------------------------------------------ | 133 //------------------------------------------------------------------------------ |
128 // Messages sent to the browser | 134 // Messages sent to the browser |
129 //------------------------------------------------------------------------------ | 135 //------------------------------------------------------------------------------ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 }; | 168 }; |
163 | 169 |
164 BrowserBridge.prototype.sendClearHostResolverCache = function() { | 170 BrowserBridge.prototype.sendClearHostResolverCache = function() { |
165 chrome.send('clearHostResolverCache'); | 171 chrome.send('clearHostResolverCache'); |
166 }; | 172 }; |
167 | 173 |
168 //------------------------------------------------------------------------------ | 174 //------------------------------------------------------------------------------ |
169 // Messages received from the browser | 175 // Messages received from the browser |
170 //------------------------------------------------------------------------------ | 176 //------------------------------------------------------------------------------ |
171 | 177 |
172 BrowserBridge.prototype.receivedLogEntry = function(logEntry) { | 178 BrowserBridge.prototype.receivedLogEntry = function(logEntry, |
| 179 wasCapturedPassively) { |
| 180 if (!wasCapturedPassively) { |
| 181 this.activelyCapturedEvents_.push(logEntry); |
| 182 } |
173 for (var i = 0; i < this.logObservers_.length; ++i) | 183 for (var i = 0; i < this.logObservers_.length; ++i) |
174 this.logObservers_[i].onLogEntryAdded(logEntry); | 184 this.logObservers_[i].onLogEntryAdded(logEntry); |
175 }; | 185 }; |
176 | 186 |
177 BrowserBridge.prototype.receivedLogEventTypeConstants = function(constantsMap) { | 187 BrowserBridge.prototype.receivedLogEventTypeConstants = function(constantsMap) { |
178 LogEventType = constantsMap; | 188 LogEventType = constantsMap; |
179 }; | 189 }; |
180 | 190 |
181 BrowserBridge.prototype.receivedLogEventPhaseConstants = | 191 BrowserBridge.prototype.receivedLogEventPhaseConstants = |
182 function(constantsMap) { | 192 function(constantsMap) { |
183 LogEventPhase = constantsMap; | 193 LogEventPhase = constantsMap; |
184 }; | 194 }; |
185 | 195 |
186 BrowserBridge.prototype.receivedLogSourceTypeConstants = | 196 BrowserBridge.prototype.receivedLogSourceTypeConstants = |
187 function(constantsMap) { | 197 function(constantsMap) { |
188 LogSourceType = constantsMap; | 198 LogSourceType = constantsMap; |
189 }; | 199 }; |
190 | 200 |
191 BrowserBridge.prototype.receivedTimeTickOffset = function(timeTickOffset) { | 201 BrowserBridge.prototype.receivedTimeTickOffset = function(timeTickOffset) { |
192 this.timeTickOffset_ = timeTickOffset; | 202 this.timeTickOffset_ = timeTickOffset; |
193 }; | 203 }; |
194 | 204 |
195 BrowserBridge.prototype.receivedProxySettings = function(proxySettings) { | 205 BrowserBridge.prototype.receivedProxySettings = function(proxySettings) { |
196 this.dispatchToObserversFromPoll_( | 206 this.proxySettings_.update(proxySettings); |
197 this.proxySettingsObservers_, 'onProxySettingsChanged', proxySettings); | |
198 }; | 207 }; |
199 | 208 |
200 BrowserBridge.prototype.receivedBadProxies = function(badProxies) { | 209 BrowserBridge.prototype.receivedBadProxies = function(badProxies) { |
201 this.dispatchToObserversFromPoll_( | 210 this.badProxies_.update(badProxies); |
202 this.badProxiesObservers_, 'onBadProxiesChanged', badProxies); | |
203 }; | 211 }; |
204 | 212 |
205 BrowserBridge.prototype.receivedHostResolverCache = | 213 BrowserBridge.prototype.receivedHostResolverCache = |
206 function(hostResolverCache) { | 214 function(hostResolverCache) { |
207 this.dispatchToObserversFromPoll_( | 215 this.hostResolverCache_.update(hostResolverCache); |
208 this.hostResolverCacheObservers_, 'onHostResolverCacheChanged', | |
209 hostResolverCache); | |
210 }; | 216 }; |
211 | 217 |
212 BrowserBridge.prototype.receivedPassiveLogEntries = function(entries) { | 218 BrowserBridge.prototype.receivedPassiveLogEntries = function(entries) { |
| 219 this.passivelyCapturedEvents_ = |
| 220 this.passivelyCapturedEvents_.concat(entries); |
213 for (var i = 0; i < entries.length; ++i) | 221 for (var i = 0; i < entries.length; ++i) |
214 this.receivedLogEntry(entries[i]); | 222 this.receivedLogEntry(entries[i], true); |
215 }; | 223 }; |
216 | 224 |
217 //------------------------------------------------------------------------------ | 225 //------------------------------------------------------------------------------ |
218 | 226 |
219 /** | 227 /** |
220 * Adds a listener of log entries. |observer| will be called back when new log | 228 * Adds a listener of log entries. |observer| will be called back when new log |
221 * data arrives, through: | 229 * data arrives, through: |
222 * | 230 * |
223 * observer.onLogEntryAdded(logEntry) | 231 * observer.onLogEntryAdded(logEntry) |
224 */ | 232 */ |
225 BrowserBridge.prototype.addLogObserver = function(observer) { | 233 BrowserBridge.prototype.addLogObserver = function(observer) { |
226 this.logObservers_.push(observer); | 234 this.logObservers_.push(observer); |
227 }; | 235 }; |
228 | 236 |
229 /** | 237 /** |
230 * Adds a listener of the proxy settings. |observer| will be called back when | 238 * Adds a listener of the proxy settings. |observer| will be called back when |
231 * data is received, through: | 239 * data is received, through: |
232 * | 240 * |
233 * observer.onProxySettingsChanged(proxySettings) | 241 * observer.onProxySettingsChanged(proxySettings) |
234 * | 242 * |
235 * |proxySettings| is a formatted string describing the settings. | 243 * |proxySettings| is a formatted string describing the settings. |
236 * TODO(eroman): send a dictionary instead. | 244 * TODO(eroman): send a dictionary instead. |
237 */ | 245 */ |
238 BrowserBridge.prototype.addProxySettingsObserver = function(observer) { | 246 BrowserBridge.prototype.addProxySettingsObserver = function(observer) { |
239 this.proxySettingsObservers_.push(observer); | 247 this.proxySettings_.addObserver(observer); |
240 }; | 248 }; |
241 | 249 |
242 /** | 250 /** |
243 * Adds a listener of the proxy settings. |observer| will be called back when | 251 * Adds a listener of the proxy settings. |observer| will be called back when |
244 * data is received, through: | 252 * data is received, through: |
245 * | 253 * |
246 * observer.onBadProxiesChanged(badProxies) | 254 * observer.onBadProxiesChanged(badProxies) |
247 * | 255 * |
248 * |badProxies| is an array, where each entry has the property: | 256 * |badProxies| is an array, where each entry has the property: |
249 * badProxies[i].proxy_uri: String identify the proxy. | 257 * badProxies[i].proxy_uri: String identify the proxy. |
250 * badProxies[i].bad_until: The time when the proxy stops being considered | 258 * badProxies[i].bad_until: The time when the proxy stops being considered |
251 * bad. Note the time is in time ticks. | 259 * bad. Note the time is in time ticks. |
252 */ | 260 */ |
253 BrowserBridge.prototype.addBadProxiesObsever = function(observer) { | 261 BrowserBridge.prototype.addBadProxiesObsever = function(observer) { |
254 this.badProxiesObservers_.push(observer); | 262 this.badProxies_.addObserver(observer); |
255 }; | 263 }; |
256 | 264 |
257 /** | 265 /** |
258 * Adds a listener of the host resolver cache. |observer| will be called back | 266 * Adds a listener of the host resolver cache. |observer| will be called back |
259 * when data is received, through: | 267 * when data is received, through: |
260 * | 268 * |
261 * observer.onHostResolverCacheChanged(hostResolverCache) | 269 * observer.onHostResolverCacheChanged(hostResolverCache) |
262 */ | 270 */ |
263 BrowserBridge.prototype.addHostResolverCacheObserver = function(observer) { | 271 BrowserBridge.prototype.addHostResolverCacheObserver = function(observer) { |
264 this.hostResolverCacheObservers_.push(observer); | 272 this.hostResolverCache_.addObserver(observer); |
265 }; | 273 }; |
266 | 274 |
267 /** | 275 /** |
268 * The browser gives us times in terms of "time ticks" in milliseconds. | 276 * The browser gives us times in terms of "time ticks" in milliseconds. |
269 * This function converts the tick count to a Date() object. | 277 * This function converts the tick count to a Date() object. |
270 * | 278 * |
271 * @param {String} timeTicks. | 279 * @param {String} timeTicks. |
272 * @returns {Date} The time that |timeTicks| represents. | 280 * @returns {Date} The time that |timeTicks| represents. |
273 */ | 281 */ |
274 BrowserBridge.prototype.convertTimeTicksToDate = function(timeTicks) { | 282 BrowserBridge.prototype.convertTimeTicksToDate = function(timeTicks) { |
275 // Note that the subtraction by 0 is to cast to a number (probably a float | 283 // Note that the subtraction by 0 is to cast to a number (probably a float |
276 // since the numbers are big). | 284 // since the numbers are big). |
277 var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); | 285 var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); |
278 var d = new Date(); | 286 var d = new Date(); |
279 d.setTime(timeStampMs); | 287 d.setTime(timeStampMs); |
280 return d; | 288 return d; |
281 }; | 289 }; |
282 | 290 |
| 291 /** |
| 292 * Returns a list of all the events that were captured while we were |
| 293 * listening for events. |
| 294 */ |
| 295 BrowserBridge.prototype.getAllActivelyCapturedEvents = function() { |
| 296 return this.activelyCapturedEvents_; |
| 297 }; |
| 298 |
| 299 /** |
| 300 * Returns a list of all the events that were captured passively by the |
| 301 * browser prior to when the net-internals page was started. |
| 302 */ |
| 303 BrowserBridge.prototype.getAllPassivelyCapturedEvents = function() { |
| 304 return this.passivelyCapturedEvents_; |
| 305 }; |
| 306 |
283 BrowserBridge.prototype.doPolling_ = function() { | 307 BrowserBridge.prototype.doPolling_ = function() { |
284 // TODO(eroman): Optimize this by using a separate polling frequency for the | 308 // 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 | 309 // data consumed by the currently active view. Everything else can be on a low |
286 // frequency poll since it won't impact the display. | 310 // frequency poll since it won't impact the display. |
287 this.sendGetProxySettings(); | 311 this.sendGetProxySettings(); |
288 this.sendGetBadProxies(); | 312 this.sendGetBadProxies(); |
289 this.sendGetHostResolverCache(); | 313 this.sendGetHostResolverCache(); |
290 }; | 314 }; |
291 | 315 |
292 /** | 316 /** |
| 317 * This is a helper class used by BrowserBridge, to keep track of: |
| 318 * - the list of observers interested in some piece of data. |
| 319 * - the last known value of that piece of data. |
| 320 * - the name of the callback method to invoke on observers. |
| 321 * @constructor |
| 322 */ |
| 323 function PollableDataHelper(observerMethodName) { |
| 324 this.observerMethodName_ = observerMethodName; |
| 325 this.observers_ = []; |
| 326 } |
| 327 |
| 328 PollableDataHelper.prototype.addObserver = function(observer) { |
| 329 this.observers_.push(observer); |
| 330 }; |
| 331 |
| 332 /** |
293 * Helper function to handle calling all the observers, but ONLY if the data has | 333 * Helper function to handle calling all the observers, but ONLY if the data has |
294 * actually changed since last time. This is used for data we received from | 334 * actually changed since last time. This is used for data we received from |
295 * browser on a poll loop. | 335 * browser on a poll loop. |
296 */ | 336 */ |
297 BrowserBridge.prototype.dispatchToObserversFromPoll_ = function( | 337 PollableDataHelper.prototype.update = function(data) { |
298 observerList, method, data) { | 338 var prevData = this.currentData_; |
299 var prevData = this.prevPollData_[method]; | |
300 | 339 |
301 // If the data hasn't changed since last time, no need to notify observers. | 340 // If the data hasn't changed since last time, no need to notify observers. |
302 if (prevData && JSON.stringify(prevData) == JSON.stringify(data)) | 341 if (prevData && JSON.stringify(prevData) == JSON.stringify(data)) |
303 return; | 342 return; |
304 | 343 |
305 this.prevPollData_[method] = data; | 344 this.currentData_ = data; |
306 | 345 |
307 // Ok, notify the observers of the change. | 346 // Ok, notify the observers of the change. |
308 for (var i = 0; i < observerList.length; ++i) | 347 for (var i = 0; i < this.observers_.length; ++i) |
309 observerList[i][method](data); | 348 var observer = this.observers_[i]; |
| 349 observer[this.observerMethodName_](data); |
310 }; | 350 }; |
OLD | NEW |