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. | 5 // Populated by constants from the browser. Used only by this file. |
6 var NetInfoSources = null; | 6 var NetInfoSources = null; |
7 | 7 |
8 /** | 8 /** |
9 * This class provides a "bridge" for communicating between the javascript and | 9 * This class provides a "bridge" for communicating between the javascript and |
10 * the browser. | 10 * the browser. |
(...skipping 21 matching lines...) Expand all Loading... |
32 this.setNetworkDebugModeObservers_ = []; | 32 this.setNetworkDebugModeObservers_ = []; |
33 // Unprocessed data received before the constants. This serves to protect | 33 // Unprocessed data received before the constants. This serves to protect |
34 // against passing along data before having information on how to interpret | 34 // against passing along data before having information on how to interpret |
35 // it. | 35 // it. |
36 this.earlyReceivedData_ = []; | 36 this.earlyReceivedData_ = []; |
37 | 37 |
38 this.pollableDataHelpers_ = {}; | 38 this.pollableDataHelpers_ = {}; |
39 | 39 |
40 // Add PollableDataHelpers for NetInfoSources, which retrieve information | 40 // Add PollableDataHelpers for NetInfoSources, which retrieve information |
41 // directly from the network stack. | 41 // directly from the network stack. |
42 this.addNetInfoPollableDataHelper('proxySettings', | 42 this.addNetInfoPollableDataHelper( |
43 'onProxySettingsChanged'); | 43 'proxySettings', 'onProxySettingsChanged'); |
44 this.addNetInfoPollableDataHelper('badProxies', 'onBadProxiesChanged'); | 44 this.addNetInfoPollableDataHelper('badProxies', 'onBadProxiesChanged'); |
45 this.addNetInfoPollableDataHelper('hostResolverInfo', | 45 this.addNetInfoPollableDataHelper( |
46 'onHostResolverInfoChanged'); | 46 'hostResolverInfo', 'onHostResolverInfoChanged'); |
47 this.addNetInfoPollableDataHelper('socketPoolInfo', | 47 this.addNetInfoPollableDataHelper( |
48 'onSocketPoolInfoChanged'); | 48 'socketPoolInfo', 'onSocketPoolInfoChanged'); |
49 this.addNetInfoPollableDataHelper('spdySessionInfo', | 49 this.addNetInfoPollableDataHelper( |
50 'onSpdySessionInfoChanged'); | 50 'spdySessionInfo', 'onSpdySessionInfoChanged'); |
51 this.addNetInfoPollableDataHelper('spdyStatus', 'onSpdyStatusChanged'); | 51 this.addNetInfoPollableDataHelper('spdyStatus', 'onSpdyStatusChanged'); |
52 this.addNetInfoPollableDataHelper('altSvcMappings', | 52 this.addNetInfoPollableDataHelper( |
53 'onAltSvcMappingsChanged'); | 53 'altSvcMappings', 'onAltSvcMappingsChanged'); |
54 this.addNetInfoPollableDataHelper('quicInfo', 'onQuicInfoChanged'); | 54 this.addNetInfoPollableDataHelper('quicInfo', 'onQuicInfoChanged'); |
55 this.addNetInfoPollableDataHelper('sdchInfo', 'onSdchInfoChanged'); | 55 this.addNetInfoPollableDataHelper('sdchInfo', 'onSdchInfoChanged'); |
56 this.addNetInfoPollableDataHelper('httpCacheInfo', | 56 this.addNetInfoPollableDataHelper( |
57 'onHttpCacheInfoChanged'); | 57 'httpCacheInfo', 'onHttpCacheInfoChanged'); |
58 | 58 |
59 // Add other PollableDataHelpers. | 59 // Add other PollableDataHelpers. |
60 this.pollableDataHelpers_.sessionNetworkStats = | 60 this.pollableDataHelpers_.sessionNetworkStats = new PollableDataHelper( |
61 new PollableDataHelper('onSessionNetworkStatsChanged', | 61 'onSessionNetworkStatsChanged', |
62 this.sendGetSessionNetworkStats.bind(this)); | 62 this.sendGetSessionNetworkStats.bind(this)); |
63 this.pollableDataHelpers_.historicNetworkStats = | 63 this.pollableDataHelpers_.historicNetworkStats = new PollableDataHelper( |
64 new PollableDataHelper('onHistoricNetworkStatsChanged', | 64 'onHistoricNetworkStatsChanged', |
65 this.sendGetHistoricNetworkStats.bind(this)); | 65 this.sendGetHistoricNetworkStats.bind(this)); |
66 if (cr.isWindows) { | 66 if (cr.isWindows) { |
67 this.pollableDataHelpers_.serviceProviders = | 67 this.pollableDataHelpers_.serviceProviders = new PollableDataHelper( |
68 new PollableDataHelper('onServiceProvidersChanged', | 68 'onServiceProvidersChanged', this.sendGetServiceProviders.bind(this)); |
69 this.sendGetServiceProviders.bind(this)); | |
70 } | 69 } |
71 this.pollableDataHelpers_.prerenderInfo = | 70 this.pollableDataHelpers_.prerenderInfo = new PollableDataHelper( |
72 new PollableDataHelper('onPrerenderInfoChanged', | 71 'onPrerenderInfoChanged', this.sendGetPrerenderInfo.bind(this)); |
73 this.sendGetPrerenderInfo.bind(this)); | 72 this.pollableDataHelpers_.extensionInfo = new PollableDataHelper( |
74 this.pollableDataHelpers_.extensionInfo = | 73 'onExtensionInfoChanged', this.sendGetExtensionInfo.bind(this)); |
75 new PollableDataHelper('onExtensionInfoChanged', | 74 this.pollableDataHelpers_.dataReductionProxyInfo = new PollableDataHelper( |
76 this.sendGetExtensionInfo.bind(this)); | 75 'onDataReductionProxyInfoChanged', |
77 this.pollableDataHelpers_.dataReductionProxyInfo = | 76 this.sendGetDataReductionProxyInfo.bind(this)); |
78 new PollableDataHelper('onDataReductionProxyInfoChanged', | |
79 this.sendGetDataReductionProxyInfo.bind(this)); | |
80 | 77 |
81 // Setting this to true will cause messages from the browser to be ignored, | 78 // Setting this to true will cause messages from the browser to be ignored, |
82 // and no messages will be sent to the browser, either. Intended for use | 79 // and no messages will be sent to the browser, either. Intended for use |
83 // when viewing log files. | 80 // when viewing log files. |
84 this.disabled_ = false; | 81 this.disabled_ = false; |
85 | 82 |
86 // Interval id returned by window.setInterval for polling timer. | 83 // Interval id returned by window.setInterval for polling timer. |
87 this.pollIntervalId_ = null; | 84 this.pollIntervalId_ = null; |
88 } | 85 } |
89 | 86 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 * views) every |intervalMs|. Subsequent calls override previous calls | 118 * views) every |intervalMs|. Subsequent calls override previous calls |
122 * to this function. If |intervalMs| is 0, stops polling. | 119 * to this function. If |intervalMs| is 0, stops polling. |
123 */ | 120 */ |
124 setPollInterval: function(intervalMs) { | 121 setPollInterval: function(intervalMs) { |
125 if (this.pollIntervalId_ !== null) { | 122 if (this.pollIntervalId_ !== null) { |
126 window.clearInterval(this.pollIntervalId_); | 123 window.clearInterval(this.pollIntervalId_); |
127 this.pollIntervalId_ = null; | 124 this.pollIntervalId_ = null; |
128 } | 125 } |
129 | 126 |
130 if (intervalMs > 0) { | 127 if (intervalMs > 0) { |
131 this.pollIntervalId_ = | 128 this.pollIntervalId_ = window.setInterval( |
132 window.setInterval(this.checkForUpdatedInfo.bind(this, false), | 129 this.checkForUpdatedInfo.bind(this, false), intervalMs); |
133 intervalMs); | |
134 } | 130 } |
135 }, | 131 }, |
136 | 132 |
137 sendGetNetInfo: function(netInfoSource) { | 133 sendGetNetInfo: function(netInfoSource) { |
138 // If don't have constants yet, don't do anything yet. | 134 // If don't have constants yet, don't do anything yet. |
139 if (NetInfoSources) | 135 if (NetInfoSources) |
140 this.send('getNetInfo', [NetInfoSources[netInfoSource]]); | 136 this.send('getNetInfo', [NetInfoSources[netInfoSource]]); |
141 }, | 137 }, |
142 | 138 |
143 sendReloadProxySettings: function() { | 139 sendReloadProxySettings: function() { |
(...skipping 18 matching lines...) Expand all Loading... |
162 }, | 158 }, |
163 | 159 |
164 sendStartConnectionTests: function(url) { | 160 sendStartConnectionTests: function(url) { |
165 this.send('startConnectionTests', [url]); | 161 this.send('startConnectionTests', [url]); |
166 }, | 162 }, |
167 | 163 |
168 sendHSTSQuery: function(domain) { | 164 sendHSTSQuery: function(domain) { |
169 this.send('hstsQuery', [domain]); | 165 this.send('hstsQuery', [domain]); |
170 }, | 166 }, |
171 | 167 |
172 sendHSTSAdd: function(domain, sts_include_subdomains, | 168 sendHSTSAdd: function( |
173 pkp_include_subdomains, pins) { | 169 domain, sts_include_subdomains, pkp_include_subdomains, pins) { |
174 this.send('hstsAdd', [domain, sts_include_subdomains, | 170 this.send( |
175 pkp_include_subdomains, pins]); | 171 'hstsAdd', |
| 172 [domain, sts_include_subdomains, pkp_include_subdomains, pins]); |
176 }, | 173 }, |
177 | 174 |
178 sendHSTSDelete: function(domain) { | 175 sendHSTSDelete: function(domain) { |
179 this.send('hstsDelete', [domain]); | 176 this.send('hstsDelete', [domain]); |
180 }, | 177 }, |
181 | 178 |
182 sendGetSessionNetworkStats: function() { | 179 sendGetSessionNetworkStats: function() { |
183 this.send('getSessionNetworkStats'); | 180 this.send('getSessionNetworkStats'); |
184 }, | 181 }, |
185 | 182 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 //-------------------------------------------------------------------------- | 229 //-------------------------------------------------------------------------- |
233 | 230 |
234 receive: function(command, params) { | 231 receive: function(command, params) { |
235 // Does nothing if disabled. | 232 // Does nothing if disabled. |
236 if (this.disabled_) | 233 if (this.disabled_) |
237 return; | 234 return; |
238 | 235 |
239 // If no constants have been received, and params does not contain the | 236 // If no constants have been received, and params does not contain the |
240 // constants, delay handling the data. | 237 // constants, delay handling the data. |
241 if (Constants == null && command != 'receivedConstants') { | 238 if (Constants == null && command != 'receivedConstants') { |
242 this.earlyReceivedData_.push({ command: command, params: params }); | 239 this.earlyReceivedData_.push({command: command, params: params}); |
243 return; | 240 return; |
244 } | 241 } |
245 | 242 |
246 this[command](params); | 243 this[command](params); |
247 | 244 |
248 // Handle any data that was received early in the order it was received, | 245 // Handle any data that was received early in the order it was received, |
249 // once the constants have been processed. | 246 // once the constants have been processed. |
250 if (this.earlyReceivedData_ != null) { | 247 if (this.earlyReceivedData_ != null) { |
251 for (var i = 0; i < this.earlyReceivedData_.length; i++) { | 248 for (var i = 0; i < this.earlyReceivedData_.length; i++) { |
252 var command = this.earlyReceivedData_[i]; | 249 var command = this.earlyReceivedData_[i]; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 * (decides between the manual/automatic modes of the | 377 * (decides between the manual/automatic modes of the |
381 * fetched settings). | 378 * fetched settings). |
382 * | 379 * |
383 * Each of these two configurations is formatted as a string, and may be | 380 * Each of these two configurations is formatted as a string, and may be |
384 * omitted if not yet initialized. | 381 * omitted if not yet initialized. |
385 * | 382 * |
386 * If |ignoreWhenUnchanged| is true, data is only sent when it changes. | 383 * If |ignoreWhenUnchanged| is true, data is only sent when it changes. |
387 * If it's false, data is sent whenever it's received from the browser. | 384 * If it's false, data is sent whenever it's received from the browser. |
388 */ | 385 */ |
389 addProxySettingsObserver: function(observer, ignoreWhenUnchanged) { | 386 addProxySettingsObserver: function(observer, ignoreWhenUnchanged) { |
390 this.pollableDataHelpers_.proxySettings.addObserver(observer, | 387 this.pollableDataHelpers_.proxySettings.addObserver( |
391 ignoreWhenUnchanged); | 388 observer, ignoreWhenUnchanged); |
392 }, | 389 }, |
393 | 390 |
394 /** | 391 /** |
395 * Adds a listener of the proxy settings. |observer| will be called back | 392 * Adds a listener of the proxy settings. |observer| will be called back |
396 * when data is received, through: | 393 * when data is received, through: |
397 * | 394 * |
398 * observer.onBadProxiesChanged(badProxies) | 395 * observer.onBadProxiesChanged(badProxies) |
399 * | 396 * |
400 * |badProxies| is an array, where each entry has the property: | 397 * |badProxies| is an array, where each entry has the property: |
401 * badProxies[i].proxy_uri: String identify the proxy. | 398 * badProxies[i].proxy_uri: String identify the proxy. |
402 * badProxies[i].bad_until: The time when the proxy stops being considered | 399 * badProxies[i].bad_until: The time when the proxy stops being considered |
403 * bad. Note the time is in time ticks. | 400 * bad. Note the time is in time ticks. |
404 */ | 401 */ |
405 addBadProxiesObserver: function(observer, ignoreWhenUnchanged) { | 402 addBadProxiesObserver: function(observer, ignoreWhenUnchanged) { |
406 this.pollableDataHelpers_.badProxies.addObserver(observer, | 403 this.pollableDataHelpers_.badProxies.addObserver( |
407 ignoreWhenUnchanged); | 404 observer, ignoreWhenUnchanged); |
408 }, | 405 }, |
409 | 406 |
410 /** | 407 /** |
411 * Adds a listener of the host resolver info. |observer| will be called back | 408 * Adds a listener of the host resolver info. |observer| will be called back |
412 * when data is received, through: | 409 * when data is received, through: |
413 * | 410 * |
414 * observer.onHostResolverInfoChanged(hostResolverInfo) | 411 * observer.onHostResolverInfoChanged(hostResolverInfo) |
415 */ | 412 */ |
416 addHostResolverInfoObserver: function(observer, ignoreWhenUnchanged) { | 413 addHostResolverInfoObserver: function(observer, ignoreWhenUnchanged) { |
417 this.pollableDataHelpers_.hostResolverInfo.addObserver( | 414 this.pollableDataHelpers_.hostResolverInfo.addObserver( |
418 observer, ignoreWhenUnchanged); | 415 observer, ignoreWhenUnchanged); |
419 }, | 416 }, |
420 | 417 |
421 /** | 418 /** |
422 * Adds a listener of the socket pool. |observer| will be called back | 419 * Adds a listener of the socket pool. |observer| will be called back |
423 * when data is received, through: | 420 * when data is received, through: |
424 * | 421 * |
425 * observer.onSocketPoolInfoChanged(socketPoolInfo) | 422 * observer.onSocketPoolInfoChanged(socketPoolInfo) |
426 */ | 423 */ |
427 addSocketPoolInfoObserver: function(observer, ignoreWhenUnchanged) { | 424 addSocketPoolInfoObserver: function(observer, ignoreWhenUnchanged) { |
428 this.pollableDataHelpers_.socketPoolInfo.addObserver(observer, | 425 this.pollableDataHelpers_.socketPoolInfo.addObserver( |
429 ignoreWhenUnchanged); | 426 observer, ignoreWhenUnchanged); |
430 }, | 427 }, |
431 | 428 |
432 /** | 429 /** |
433 * Adds a listener of the network session. |observer| will be called back | 430 * Adds a listener of the network session. |observer| will be called back |
434 * when data is received, through: | 431 * when data is received, through: |
435 * | 432 * |
436 * observer.onSessionNetworkStatsChanged(sessionNetworkStats) | 433 * observer.onSessionNetworkStatsChanged(sessionNetworkStats) |
437 */ | 434 */ |
438 addSessionNetworkStatsObserver: function(observer, ignoreWhenUnchanged) { | 435 addSessionNetworkStatsObserver: function(observer, ignoreWhenUnchanged) { |
439 this.pollableDataHelpers_.sessionNetworkStats.addObserver( | 436 this.pollableDataHelpers_.sessionNetworkStats.addObserver( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 observer, ignoreWhenUnchanged); | 470 observer, ignoreWhenUnchanged); |
474 }, | 471 }, |
475 | 472 |
476 /** | 473 /** |
477 * Adds a listener of the SPDY status. |observer| will be called back | 474 * Adds a listener of the SPDY status. |observer| will be called back |
478 * when data is received, through: | 475 * when data is received, through: |
479 * | 476 * |
480 * observer.onSpdyStatusChanged(spdyStatus) | 477 * observer.onSpdyStatusChanged(spdyStatus) |
481 */ | 478 */ |
482 addSpdyStatusObserver: function(observer, ignoreWhenUnchanged) { | 479 addSpdyStatusObserver: function(observer, ignoreWhenUnchanged) { |
483 this.pollableDataHelpers_.spdyStatus.addObserver(observer, | 480 this.pollableDataHelpers_.spdyStatus.addObserver( |
484 ignoreWhenUnchanged); | 481 observer, ignoreWhenUnchanged); |
485 }, | 482 }, |
486 | 483 |
487 /** | 484 /** |
488 * Adds a listener of the altSvcMappings. |observer| will be | 485 * Adds a listener of the altSvcMappings. |observer| will be |
489 * called back when data is received, through: | 486 * called back when data is received, through: |
490 * | 487 * |
491 * observer.onAltSvcMappingsChanged(altSvcMappings) | 488 * observer.onAltSvcMappingsChanged(altSvcMappings) |
492 */ | 489 */ |
493 addAltSvcMappingsObserver: function(observer, ignoreWhenUnchanged) { | 490 addAltSvcMappingsObserver: function(observer, ignoreWhenUnchanged) { |
494 this.pollableDataHelpers_.altSvcMappings.addObserver( | 491 this.pollableDataHelpers_.altSvcMappings.addObserver( |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 helper.removeObserver(this); | 787 helper.removeObserver(this); |
791 --this.observingCount_; | 788 --this.observingCount_; |
792 this.updatedData_[name] = data; | 789 this.updatedData_[name] = data; |
793 if (this.observingCount_ == 0) | 790 if (this.observingCount_ == 0) |
794 this.callback_(this.updatedData_); | 791 this.callback_(this.updatedData_); |
795 } | 792 } |
796 }; | 793 }; |
797 | 794 |
798 return BrowserBridge; | 795 return BrowserBridge; |
799 })(); | 796 })(); |
OLD | NEW |