| 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 /** | 5 /** |
| 6 * This class provides a "bridge" for communicating between the javascript and | 6 * This class provides a "bridge" for communicating between the javascript and |
| 7 * the browser. | 7 * the browser. |
| 8 */ | 8 */ |
| 9 var BrowserBridge = (function() { | 9 var BrowserBridge = (function() { |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Delay in milliseconds between updates of certain browser information. | 13 * Delay in milliseconds between updates of certain browser information. |
| 14 */ | 14 */ |
| 15 var POLL_INTERVAL_MS = 5000; | 15 var POLL_INTERVAL_MS = 5000; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @constructor | 18 * @constructor |
| 19 */ | 19 */ |
| 20 function BrowserBridge() { | 20 function BrowserBridge() { |
| 21 assertFirstConstructorCall(BrowserBridge); | 21 assertFirstConstructorCall(BrowserBridge); |
| 22 | 22 |
| 23 // List of observers for various bits of browser state. | 23 // List of observers for various bits of browser state. |
| 24 this.connectionTestsObservers_ = []; | 24 this.connectionTestsObservers_ = []; |
| 25 this.hstsObservers_ = []; | 25 this.hstsObservers_ = []; |
| 26 this.httpThrottlingObservers_ = []; | 26 this.httpThrottlingObservers_ = []; |
| 27 this.constantsObservers_ = []; | 27 this.constantsObservers_ = []; |
| 28 this.crosONCFileParseObservers_ = []; | 28 this.crosONCFileParseObservers_ = []; |
| 29 this.setNetworkDebugModeObservers_ = []; |
| 29 | 30 |
| 30 this.pollableDataHelpers_ = {}; | 31 this.pollableDataHelpers_ = {}; |
| 31 this.pollableDataHelpers_.proxySettings = | 32 this.pollableDataHelpers_.proxySettings = |
| 32 new PollableDataHelper('onProxySettingsChanged', | 33 new PollableDataHelper('onProxySettingsChanged', |
| 33 this.sendGetProxySettings.bind(this)); | 34 this.sendGetProxySettings.bind(this)); |
| 34 this.pollableDataHelpers_.badProxies = | 35 this.pollableDataHelpers_.badProxies = |
| 35 new PollableDataHelper('onBadProxiesChanged', | 36 new PollableDataHelper('onBadProxiesChanged', |
| 36 this.sendGetBadProxies.bind(this)); | 37 this.sendGetBadProxies.bind(this)); |
| 37 this.pollableDataHelpers_.httpCacheInfo = | 38 this.pollableDataHelpers_.httpCacheInfo = |
| 38 new PollableDataHelper('onHttpCacheInfoChanged', | 39 new PollableDataHelper('onHttpCacheInfoChanged', |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 }, | 227 }, |
| 227 | 228 |
| 228 getSystemLog: function(log_key, cellId) { | 229 getSystemLog: function(log_key, cellId) { |
| 229 this.send('getSystemLog', [log_key, cellId]); | 230 this.send('getSystemLog', [log_key, cellId]); |
| 230 }, | 231 }, |
| 231 | 232 |
| 232 importONCFile: function(fileContent, passcode) { | 233 importONCFile: function(fileContent, passcode) { |
| 233 this.send('importONCFile', [fileContent, passcode]); | 234 this.send('importONCFile', [fileContent, passcode]); |
| 234 }, | 235 }, |
| 235 | 236 |
| 237 setNetworkDebugMode: function(subsystem) { |
| 238 this.send('setNetworkDebugMode', [subsystem]); |
| 239 }, |
| 240 |
| 236 sendGetHttpPipeliningStatus: function() { | 241 sendGetHttpPipeliningStatus: function() { |
| 237 this.send('getHttpPipeliningStatus'); | 242 this.send('getHttpPipeliningStatus'); |
| 238 }, | 243 }, |
| 239 | 244 |
| 240 //-------------------------------------------------------------------------- | 245 //-------------------------------------------------------------------------- |
| 241 // Messages received from the browser. | 246 // Messages received from the browser. |
| 242 //-------------------------------------------------------------------------- | 247 //-------------------------------------------------------------------------- |
| 243 | 248 |
| 244 receive: function(command, params) { | 249 receive: function(command, params) { |
| 245 // Does nothing if disabled. | 250 // Does nothing if disabled. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 receivedHSTSResult: function(info) { | 323 receivedHSTSResult: function(info) { |
| 319 for (var i = 0; i < this.hstsObservers_.length; i++) | 324 for (var i = 0; i < this.hstsObservers_.length; i++) |
| 320 this.hstsObservers_[i].onHSTSQueryResult(info); | 325 this.hstsObservers_[i].onHSTSQueryResult(info); |
| 321 }, | 326 }, |
| 322 | 327 |
| 323 receivedONCFileParse: function(error) { | 328 receivedONCFileParse: function(error) { |
| 324 for (var i = 0; i < this.crosONCFileParseObservers_.length; i++) | 329 for (var i = 0; i < this.crosONCFileParseObservers_.length; i++) |
| 325 this.crosONCFileParseObservers_[i].onONCFileParse(error); | 330 this.crosONCFileParseObservers_[i].onONCFileParse(error); |
| 326 }, | 331 }, |
| 327 | 332 |
| 333 receivedSetNetworkDebugMode: function(status) { |
| 334 for (var i = 0; i < this.setNetworkDebugModeObservers_.length; i++) |
| 335 this.setNetworkDebugModeObservers_[i].onSetNetworkDebugMode(status); |
| 336 }, |
| 337 |
| 328 receivedHttpCacheInfo: function(info) { | 338 receivedHttpCacheInfo: function(info) { |
| 329 this.pollableDataHelpers_.httpCacheInfo.update(info); | 339 this.pollableDataHelpers_.httpCacheInfo.update(info); |
| 330 }, | 340 }, |
| 331 | 341 |
| 332 receivedHttpThrottlingEnabledPrefChanged: function(enabled) { | 342 receivedHttpThrottlingEnabledPrefChanged: function(enabled) { |
| 333 for (var i = 0; i < this.httpThrottlingObservers_.length; i++) { | 343 for (var i = 0; i < this.httpThrottlingObservers_.length; i++) { |
| 334 this.httpThrottlingObservers_[i].onHttpThrottlingEnabledPrefChanged( | 344 this.httpThrottlingObservers_[i].onHttpThrottlingEnabledPrefChanged( |
| 335 enabled); | 345 enabled); |
| 336 } | 346 } |
| 337 }, | 347 }, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 * Adds a listener for ONC file parse status. The observer will be called | 524 * Adds a listener for ONC file parse status. The observer will be called |
| 515 * back with: | 525 * back with: |
| 516 * | 526 * |
| 517 * observer.onONCFileParse(error); | 527 * observer.onONCFileParse(error); |
| 518 */ | 528 */ |
| 519 addCrosONCFileParseObserver: function(observer) { | 529 addCrosONCFileParseObserver: function(observer) { |
| 520 this.crosONCFileParseObservers_.push(observer); | 530 this.crosONCFileParseObservers_.push(observer); |
| 521 }, | 531 }, |
| 522 | 532 |
| 523 /** | 533 /** |
| 534 * Adds a listener for network debugging mode status. The observer |
| 535 * will be called back with: |
| 536 * |
| 537 * observer.onSetNetworkDebugMode(status); |
| 538 */ |
| 539 addSetNetworkDebugModeObserver: function(observer) { |
| 540 this.setNetworkDebugModeObservers_.push(observer); |
| 541 }, |
| 542 |
| 543 /** |
| 524 * Adds a listener for HTTP throttling-related events. |observer| will be | 544 * Adds a listener for HTTP throttling-related events. |observer| will be |
| 525 * called back when HTTP throttling is enabled/disabled, through: | 545 * called back when HTTP throttling is enabled/disabled, through: |
| 526 * | 546 * |
| 527 * observer.onHttpThrottlingEnabledPrefChanged(enabled); | 547 * observer.onHttpThrottlingEnabledPrefChanged(enabled); |
| 528 */ | 548 */ |
| 529 addHttpThrottlingObserver: function(observer) { | 549 addHttpThrottlingObserver: function(observer) { |
| 530 this.httpThrottlingObservers_.push(observer); | 550 this.httpThrottlingObservers_.push(observer); |
| 531 }, | 551 }, |
| 532 | 552 |
| 533 /** | 553 /** |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 helper.removeObserver(this); | 735 helper.removeObserver(this); |
| 716 --this.observingCount_; | 736 --this.observingCount_; |
| 717 this.updatedData_[name] = data; | 737 this.updatedData_[name] = data; |
| 718 if (this.observingCount_ == 0) | 738 if (this.observingCount_ == 0) |
| 719 this.callback_(this.updatedData_); | 739 this.callback_(this.updatedData_); |
| 720 } | 740 } |
| 721 }; | 741 }; |
| 722 | 742 |
| 723 return BrowserBridge; | 743 return BrowserBridge; |
| 724 })(); | 744 })(); |
| OLD | NEW |