| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Populated by constants from the browser. Used only by this file. |
| 6 var NetInfoSources = null; |
| 7 |
| 5 /** | 8 /** |
| 6 * This class provides a "bridge" for communicating between the javascript and | 9 * This class provides a "bridge" for communicating between the javascript and |
| 7 * the browser. | 10 * the browser. |
| 8 */ | 11 */ |
| 9 var BrowserBridge = (function() { | 12 var BrowserBridge = (function() { |
| 10 'use strict'; | 13 'use strict'; |
| 11 | 14 |
| 12 /** | 15 /** |
| 13 * Delay in milliseconds between updates of certain browser information. | 16 * Delay in milliseconds between updates of certain browser information. |
| 14 */ | 17 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 26 this.constantsObservers_ = []; | 29 this.constantsObservers_ = []; |
| 27 this.crosONCFileParseObservers_ = []; | 30 this.crosONCFileParseObservers_ = []; |
| 28 this.storeDebugLogsObservers_ = []; | 31 this.storeDebugLogsObservers_ = []; |
| 29 this.setNetworkDebugModeObservers_ = []; | 32 this.setNetworkDebugModeObservers_ = []; |
| 30 // Unprocessed data received before the constants. This serves to protect | 33 // Unprocessed data received before the constants. This serves to protect |
| 31 // against passing along data before having information on how to interpret | 34 // against passing along data before having information on how to interpret |
| 32 // it. | 35 // it. |
| 33 this.earlyReceivedData_ = []; | 36 this.earlyReceivedData_ = []; |
| 34 | 37 |
| 35 this.pollableDataHelpers_ = {}; | 38 this.pollableDataHelpers_ = {}; |
| 36 this.pollableDataHelpers_.proxySettings = | 39 this.addNetInfoPollableDataHelper('proxySettings', |
| 37 new PollableDataHelper('onProxySettingsChanged', | 40 'onProxySettingsChanged'); |
| 38 this.sendGetProxySettings.bind(this)); | 41 this.addNetInfoPollableDataHelper('badProxies', 'onBadProxiesChanged'); |
| 39 this.pollableDataHelpers_.badProxies = | 42 this.addNetInfoPollableDataHelper('hostResolverInfo', |
| 40 new PollableDataHelper('onBadProxiesChanged', | 43 'onHostResolverInfoChanged'); |
| 41 this.sendGetBadProxies.bind(this)); | 44 this.addNetInfoPollableDataHelper('socketPoolInfo', |
| 42 this.pollableDataHelpers_.httpCacheInfo = | 45 'onSocketPoolInfoChanged'); |
| 43 new PollableDataHelper('onHttpCacheInfoChanged', | 46 this.addNetInfoPollableDataHelper('spdySessionInfo', |
| 44 this.sendGetHttpCacheInfo.bind(this)); | 47 'onSpdySessionInfoChanged'); |
| 45 this.pollableDataHelpers_.hostResolverInfo = | 48 this.addNetInfoPollableDataHelper('spdyStatus', 'onSpdyStatusChanged'); |
| 46 new PollableDataHelper('onHostResolverInfoChanged', | 49 this.addNetInfoPollableDataHelper('spdyAlternateProtocolMappings', |
| 47 this.sendGetHostResolverInfo.bind(this)); | 50 'onSpdyAlternateProtocolMappingsChanged'); |
| 48 this.pollableDataHelpers_.socketPoolInfo = | 51 this.addNetInfoPollableDataHelper('quicInfo', 'onQuicInfoChanged'); |
| 49 new PollableDataHelper('onSocketPoolInfoChanged', | 52 this.addNetInfoPollableDataHelper('httpCacheInfo', |
| 50 this.sendGetSocketPoolInfo.bind(this)); | 53 'onHttpCacheInfoChanged'); |
| 54 |
| 51 this.pollableDataHelpers_.sessionNetworkStats = | 55 this.pollableDataHelpers_.sessionNetworkStats = |
| 52 new PollableDataHelper('onSessionNetworkStatsChanged', | 56 new PollableDataHelper('onSessionNetworkStatsChanged', |
| 53 this.sendGetSessionNetworkStats.bind(this)); | 57 this.sendGetSessionNetworkStats.bind(this)); |
| 54 this.pollableDataHelpers_.historicNetworkStats = | 58 this.pollableDataHelpers_.historicNetworkStats = |
| 55 new PollableDataHelper('onHistoricNetworkStatsChanged', | 59 new PollableDataHelper('onHistoricNetworkStatsChanged', |
| 56 this.sendGetHistoricNetworkStats.bind(this)); | 60 this.sendGetHistoricNetworkStats.bind(this)); |
| 57 this.pollableDataHelpers_.quicInfo = | |
| 58 new PollableDataHelper('onQuicInfoChanged', | |
| 59 this.sendGetQuicInfo.bind(this)); | |
| 60 this.pollableDataHelpers_.spdySessionInfo = | |
| 61 new PollableDataHelper('onSpdySessionInfoChanged', | |
| 62 this.sendGetSpdySessionInfo.bind(this)); | |
| 63 this.pollableDataHelpers_.spdyStatus = | |
| 64 new PollableDataHelper('onSpdyStatusChanged', | |
| 65 this.sendGetSpdyStatus.bind(this)); | |
| 66 this.pollableDataHelpers_.spdyAlternateProtocolMappings = | |
| 67 new PollableDataHelper('onSpdyAlternateProtocolMappingsChanged', | |
| 68 this.sendGetSpdyAlternateProtocolMappings.bind( | |
| 69 this)); | |
| 70 if (cr.isWindows) { | 61 if (cr.isWindows) { |
| 71 this.pollableDataHelpers_.serviceProviders = | 62 this.pollableDataHelpers_.serviceProviders = |
| 72 new PollableDataHelper('onServiceProvidersChanged', | 63 new PollableDataHelper('onServiceProvidersChanged', |
| 73 this.sendGetServiceProviders.bind(this)); | 64 this.sendGetServiceProviders.bind(this)); |
| 74 } | 65 } |
| 75 this.pollableDataHelpers_.prerenderInfo = | 66 this.pollableDataHelpers_.prerenderInfo = |
| 76 new PollableDataHelper('onPrerenderInfoChanged', | 67 new PollableDataHelper('onPrerenderInfoChanged', |
| 77 this.sendGetPrerenderInfo.bind(this)); | 68 this.sendGetPrerenderInfo.bind(this)); |
| 78 this.pollableDataHelpers_.extensionInfo = | 69 this.pollableDataHelpers_.extensionInfo = |
| 79 new PollableDataHelper('onExtensionInfoChanged', | 70 new PollableDataHelper('onExtensionInfoChanged', |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 this.pollIntervalId_ = null; | 124 this.pollIntervalId_ = null; |
| 134 } | 125 } |
| 135 | 126 |
| 136 if (intervalMs > 0) { | 127 if (intervalMs > 0) { |
| 137 this.pollIntervalId_ = | 128 this.pollIntervalId_ = |
| 138 window.setInterval(this.checkForUpdatedInfo.bind(this, false), | 129 window.setInterval(this.checkForUpdatedInfo.bind(this, false), |
| 139 intervalMs); | 130 intervalMs); |
| 140 } | 131 } |
| 141 }, | 132 }, |
| 142 | 133 |
| 143 sendGetProxySettings: function() { | 134 sendGetNetInfo: function(netInfoSource) { |
| 144 // The browser will call receivedProxySettings on completion. | 135 // If don't have constants yet, don't do anything yet. |
| 145 this.send('getProxySettings'); | 136 if (NetInfoSources) |
| 137 this.send('getNetInfo', [NetInfoSources[netInfoSource]]); |
| 146 }, | 138 }, |
| 147 | 139 |
| 148 sendReloadProxySettings: function() { | 140 sendReloadProxySettings: function() { |
| 149 this.send('reloadProxySettings'); | 141 this.send('reloadProxySettings'); |
| 150 }, | 142 }, |
| 151 | 143 |
| 152 sendGetBadProxies: function() { | |
| 153 // The browser will call receivedBadProxies on completion. | |
| 154 this.send('getBadProxies'); | |
| 155 }, | |
| 156 | |
| 157 sendGetHostResolverInfo: function() { | |
| 158 // The browser will call receivedHostResolverInfo on completion. | |
| 159 this.send('getHostResolverInfo'); | |
| 160 }, | |
| 161 | |
| 162 sendClearBadProxies: function() { | 144 sendClearBadProxies: function() { |
| 163 this.send('clearBadProxies'); | 145 this.send('clearBadProxies'); |
| 164 }, | 146 }, |
| 165 | 147 |
| 166 sendClearHostResolverCache: function() { | 148 sendClearHostResolverCache: function() { |
| 167 this.send('clearHostResolverCache'); | 149 this.send('clearHostResolverCache'); |
| 168 }, | 150 }, |
| 169 | 151 |
| 170 sendClearBrowserCache: function() { | 152 sendClearBrowserCache: function() { |
| 171 this.send('clearBrowserCache'); | 153 this.send('clearBrowserCache'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 sendHSTSAdd: function(domain, sts_include_subdomains, | 169 sendHSTSAdd: function(domain, sts_include_subdomains, |
| 188 pkp_include_subdomains, pins) { | 170 pkp_include_subdomains, pins) { |
| 189 this.send('hstsAdd', [domain, sts_include_subdomains, | 171 this.send('hstsAdd', [domain, sts_include_subdomains, |
| 190 pkp_include_subdomains, pins]); | 172 pkp_include_subdomains, pins]); |
| 191 }, | 173 }, |
| 192 | 174 |
| 193 sendHSTSDelete: function(domain) { | 175 sendHSTSDelete: function(domain) { |
| 194 this.send('hstsDelete', [domain]); | 176 this.send('hstsDelete', [domain]); |
| 195 }, | 177 }, |
| 196 | 178 |
| 197 sendGetHttpCacheInfo: function() { | |
| 198 this.send('getHttpCacheInfo'); | |
| 199 }, | |
| 200 | |
| 201 sendGetSocketPoolInfo: function() { | |
| 202 this.send('getSocketPoolInfo'); | |
| 203 }, | |
| 204 | |
| 205 sendGetSessionNetworkStats: function() { | 179 sendGetSessionNetworkStats: function() { |
| 206 this.send('getSessionNetworkStats'); | 180 this.send('getSessionNetworkStats'); |
| 207 }, | 181 }, |
| 208 | 182 |
| 209 sendGetHistoricNetworkStats: function() { | 183 sendGetHistoricNetworkStats: function() { |
| 210 this.send('getHistoricNetworkStats'); | 184 this.send('getHistoricNetworkStats'); |
| 211 }, | 185 }, |
| 212 | 186 |
| 213 sendCloseIdleSockets: function() { | 187 sendCloseIdleSockets: function() { |
| 214 this.send('closeIdleSockets'); | 188 this.send('closeIdleSockets'); |
| 215 }, | 189 }, |
| 216 | 190 |
| 217 sendFlushSocketPools: function() { | 191 sendFlushSocketPools: function() { |
| 218 this.send('flushSocketPools'); | 192 this.send('flushSocketPools'); |
| 219 }, | 193 }, |
| 220 | 194 |
| 221 sendGetQuicInfo: function() { | |
| 222 this.send('getQuicInfo'); | |
| 223 }, | |
| 224 | |
| 225 sendGetSpdySessionInfo: function() { | |
| 226 this.send('getSpdySessionInfo'); | |
| 227 }, | |
| 228 | |
| 229 sendGetSpdyStatus: function() { | |
| 230 this.send('getSpdyStatus'); | |
| 231 }, | |
| 232 | |
| 233 sendGetSpdyAlternateProtocolMappings: function() { | |
| 234 this.send('getSpdyAlternateProtocolMappings'); | |
| 235 }, | |
| 236 | |
| 237 sendGetServiceProviders: function() { | 195 sendGetServiceProviders: function() { |
| 238 this.send('getServiceProviders'); | 196 this.send('getServiceProviders'); |
| 239 }, | 197 }, |
| 240 | 198 |
| 241 sendGetPrerenderInfo: function() { | 199 sendGetPrerenderInfo: function() { |
| 242 this.send('getPrerenderInfo'); | 200 this.send('getPrerenderInfo'); |
| 243 }, | 201 }, |
| 244 | 202 |
| 245 sendGetExtensionInfo: function() { | 203 sendGetExtensionInfo: function() { |
| 246 this.send('getExtensionInfo'); | 204 this.send('getExtensionInfo'); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (this.earlyReceivedData_ != null) { | 255 if (this.earlyReceivedData_ != null) { |
| 298 for (var i = 0; i < this.earlyReceivedData_.length; i++) { | 256 for (var i = 0; i < this.earlyReceivedData_.length; i++) { |
| 299 var command = this.earlyReceivedData_[i]; | 257 var command = this.earlyReceivedData_[i]; |
| 300 this[command.command](command.params); | 258 this[command.command](command.params); |
| 301 } | 259 } |
| 302 this.earlyReceivedData_ = null; | 260 this.earlyReceivedData_ = null; |
| 303 } | 261 } |
| 304 }, | 262 }, |
| 305 | 263 |
| 306 receivedConstants: function(constants) { | 264 receivedConstants: function(constants) { |
| 265 NetInfoSources = constants.netInfoSources; |
| 307 for (var i = 0; i < this.constantsObservers_.length; i++) | 266 for (var i = 0; i < this.constantsObservers_.length; i++) |
| 308 this.constantsObservers_[i].onReceivedConstants(constants); | 267 this.constantsObservers_[i].onReceivedConstants(constants); |
| 268 // May have been waiting for the constants to be received before getting |
| 269 // information for the currently displayed tab. |
| 270 this.checkForUpdatedInfo(); |
| 309 }, | 271 }, |
| 310 | 272 |
| 311 receivedLogEntries: function(logEntries) { | 273 receivedLogEntries: function(logEntries) { |
| 312 EventsTracker.getInstance().addLogEntries(logEntries); | 274 EventsTracker.getInstance().addLogEntries(logEntries); |
| 313 }, | 275 }, |
| 314 | 276 |
| 315 receivedProxySettings: function(proxySettings) { | 277 receivedNetInfo: function(netInfo) { |
| 316 this.pollableDataHelpers_.proxySettings.update(proxySettings); | 278 // Currently information is only received from one source at a time, but |
| 317 }, | 279 // could allow more. |
| 318 | 280 for (var source in netInfo) |
| 319 receivedBadProxies: function(badProxies) { | 281 this.pollableDataHelpers_[source].update(netInfo[source]); |
| 320 this.pollableDataHelpers_.badProxies.update(badProxies); | |
| 321 }, | |
| 322 | |
| 323 receivedHostResolverInfo: function(hostResolverInfo) { | |
| 324 this.pollableDataHelpers_.hostResolverInfo.update(hostResolverInfo); | |
| 325 }, | |
| 326 | |
| 327 receivedSocketPoolInfo: function(socketPoolInfo) { | |
| 328 this.pollableDataHelpers_.socketPoolInfo.update(socketPoolInfo); | |
| 329 }, | 282 }, |
| 330 | 283 |
| 331 receivedSessionNetworkStats: function(sessionNetworkStats) { | 284 receivedSessionNetworkStats: function(sessionNetworkStats) { |
| 332 this.pollableDataHelpers_.sessionNetworkStats.update(sessionNetworkStats); | 285 this.pollableDataHelpers_.sessionNetworkStats.update(sessionNetworkStats); |
| 333 }, | 286 }, |
| 334 | 287 |
| 335 receivedHistoricNetworkStats: function(historicNetworkStats) { | 288 receivedHistoricNetworkStats: function(historicNetworkStats) { |
| 336 this.pollableDataHelpers_.historicNetworkStats.update( | 289 this.pollableDataHelpers_.historicNetworkStats.update( |
| 337 historicNetworkStats); | 290 historicNetworkStats); |
| 338 }, | 291 }, |
| 339 | 292 |
| 340 receivedQuicInfo: function(quicInfo) { | |
| 341 this.pollableDataHelpers_.quicInfo.update(quicInfo); | |
| 342 }, | |
| 343 | |
| 344 receivedSpdySessionInfo: function(spdySessionInfo) { | |
| 345 this.pollableDataHelpers_.spdySessionInfo.update(spdySessionInfo); | |
| 346 }, | |
| 347 | |
| 348 receivedSpdyStatus: function(spdyStatus) { | |
| 349 this.pollableDataHelpers_.spdyStatus.update(spdyStatus); | |
| 350 }, | |
| 351 | |
| 352 receivedSpdyAlternateProtocolMappings: | |
| 353 function(spdyAlternateProtocolMappings) { | |
| 354 this.pollableDataHelpers_.spdyAlternateProtocolMappings.update( | |
| 355 spdyAlternateProtocolMappings); | |
| 356 }, | |
| 357 | |
| 358 receivedServiceProviders: function(serviceProviders) { | 293 receivedServiceProviders: function(serviceProviders) { |
| 359 this.pollableDataHelpers_.serviceProviders.update(serviceProviders); | 294 this.pollableDataHelpers_.serviceProviders.update(serviceProviders); |
| 360 }, | 295 }, |
| 361 | 296 |
| 362 receivedStartConnectionTestSuite: function() { | 297 receivedStartConnectionTestSuite: function() { |
| 363 for (var i = 0; i < this.connectionTestsObservers_.length; i++) | 298 for (var i = 0; i < this.connectionTestsObservers_.length; i++) |
| 364 this.connectionTestsObservers_[i].onStartedConnectionTestSuite(); | 299 this.connectionTestsObservers_[i].onStartedConnectionTestSuite(); |
| 365 }, | 300 }, |
| 366 | 301 |
| 367 receivedStartConnectionTestExperiment: function(experiment) { | 302 receivedStartConnectionTestExperiment: function(experiment) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 396 receivedStoreDebugLogs: function(status) { | 331 receivedStoreDebugLogs: function(status) { |
| 397 for (var i = 0; i < this.storeDebugLogsObservers_.length; i++) | 332 for (var i = 0; i < this.storeDebugLogsObservers_.length; i++) |
| 398 this.storeDebugLogsObservers_[i].onStoreDebugLogs(status); | 333 this.storeDebugLogsObservers_[i].onStoreDebugLogs(status); |
| 399 }, | 334 }, |
| 400 | 335 |
| 401 receivedSetNetworkDebugMode: function(status) { | 336 receivedSetNetworkDebugMode: function(status) { |
| 402 for (var i = 0; i < this.setNetworkDebugModeObservers_.length; i++) | 337 for (var i = 0; i < this.setNetworkDebugModeObservers_.length; i++) |
| 403 this.setNetworkDebugModeObservers_[i].onSetNetworkDebugMode(status); | 338 this.setNetworkDebugModeObservers_[i].onSetNetworkDebugMode(status); |
| 404 }, | 339 }, |
| 405 | 340 |
| 406 receivedHttpCacheInfo: function(info) { | |
| 407 this.pollableDataHelpers_.httpCacheInfo.update(info); | |
| 408 }, | |
| 409 | |
| 410 receivedPrerenderInfo: function(prerenderInfo) { | 341 receivedPrerenderInfo: function(prerenderInfo) { |
| 411 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo); | 342 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo); |
| 412 }, | 343 }, |
| 413 | 344 |
| 414 receivedExtensionInfo: function(extensionInfo) { | 345 receivedExtensionInfo: function(extensionInfo) { |
| 415 this.pollableDataHelpers_.extensionInfo.update(extensionInfo); | 346 this.pollableDataHelpers_.extensionInfo.update(extensionInfo); |
| 416 }, | 347 }, |
| 417 | 348 |
| 418 getSystemLogCallback: function(systemLog) { | 349 getSystemLogCallback: function(systemLog) { |
| 419 this.pollableDataHelpers_.systemLog.update(systemLog); | 350 this.pollableDataHelpers_.systemLog.update(systemLog); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 }, | 636 }, |
| 706 | 637 |
| 707 /** | 638 /** |
| 708 * Calls all startUpdate functions and, if |callback| is non-null, | 639 * Calls all startUpdate functions and, if |callback| is non-null, |
| 709 * calls it with the results of all updates. | 640 * calls it with the results of all updates. |
| 710 */ | 641 */ |
| 711 updateAllInfo: function(callback) { | 642 updateAllInfo: function(callback) { |
| 712 if (callback) | 643 if (callback) |
| 713 new UpdateAllObserver(callback, this.pollableDataHelpers_); | 644 new UpdateAllObserver(callback, this.pollableDataHelpers_); |
| 714 this.checkForUpdatedInfo(true); | 645 this.checkForUpdatedInfo(true); |
| 715 } | 646 }, |
| 647 |
| 648 /** |
| 649 * Adds a PollableDataHelper that listens to the secified netInfo source. |
| 650 */ |
| 651 addNetInfoPollableDataHelper: function(sourceName, observerMethodName) { |
| 652 this.pollableDataHelpers_[sourceName] = new PollableDataHelper( |
| 653 observerMethodName, this.sendGetNetInfo.bind(this, sourceName)); |
| 654 }, |
| 716 }; | 655 }; |
| 717 | 656 |
| 718 /** | 657 /** |
| 719 * This is a helper class used by BrowserBridge, to keep track of: | 658 * This is a helper class used by BrowserBridge, to keep track of: |
| 720 * - the list of observers interested in some piece of data. | 659 * - the list of observers interested in some piece of data. |
| 721 * - the last known value of that piece of data. | 660 * - the last known value of that piece of data. |
| 722 * - the name of the callback method to invoke on observers. | 661 * - the name of the callback method to invoke on observers. |
| 723 * - the update function. | 662 * - the update function. |
| 724 * @constructor | 663 * @constructor |
| 725 */ | 664 */ |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 helper.removeObserver(this); | 784 helper.removeObserver(this); |
| 846 --this.observingCount_; | 785 --this.observingCount_; |
| 847 this.updatedData_[name] = data; | 786 this.updatedData_[name] = data; |
| 848 if (this.observingCount_ == 0) | 787 if (this.observingCount_ == 0) |
| 849 this.callback_(this.updatedData_); | 788 this.callback_(this.updatedData_); |
| 850 } | 789 } |
| 851 }; | 790 }; |
| 852 | 791 |
| 853 return BrowserBridge; | 792 return BrowserBridge; |
| 854 })(); | 793 })(); |
| OLD | NEW |