| Index: Source/devtools/front_end/sdk/NetworkManager.js
|
| diff --git a/Source/devtools/front_end/sdk/NetworkManager.js b/Source/devtools/front_end/sdk/NetworkManager.js
|
| index 6f3fcbe1083ecf86f9c89f7e046df661a51783cb..f23e4766967ec3fc120e9a0cd4fa7c7e2b08ec03 100644
|
| --- a/Source/devtools/front_end/sdk/NetworkManager.js
|
| +++ b/Source/devtools/front_end/sdk/NetworkManager.js
|
| @@ -44,6 +44,7 @@ WebInspector.NetworkManager = function(target)
|
| this._networkAgent.setCacheDisabled(true);
|
| if (WebInspector.moduleSetting("monitoringXHREnabled").get())
|
| this._networkAgent.setMonitoringXHREnabled(true);
|
| + this._initNetworkConditions();
|
| this._networkAgent.enable();
|
|
|
| WebInspector.moduleSetting("cacheDisabled").addChangeListener(this._cacheDisabledSettingChanged, this);
|
| @@ -67,6 +68,9 @@ WebInspector.NetworkManager._MIMETypes = {
|
| "text/vtt": {"texttrack": true},
|
| }
|
|
|
| +/** @typedef {{throughput: number, latency: number}} */
|
| +WebInspector.NetworkManager.Conditions;
|
| +
|
| WebInspector.NetworkManager.prototype = {
|
| /**
|
| * @param {string} url
|
| @@ -101,6 +105,46 @@ WebInspector.NetworkManager.prototype = {
|
| this._networkAgent.clearBrowserCookies();
|
| },
|
|
|
| + _initNetworkConditions: function()
|
| + {
|
| + this._networkAgent.canEmulateNetworkConditions(callback.bind(this));
|
| +
|
| + /**
|
| + * @this {WebInspector.NetworkManager}
|
| + */
|
| + function callback(error, canEmulate)
|
| + {
|
| + if (error || !canEmulate)
|
| + return;
|
| + WebInspector.moduleSetting("networkConditions").addChangeListener(this._networkConditionsSettingChanged, this);
|
| + var conditions = WebInspector.moduleSetting("networkConditions").get();
|
| + if (conditions.throughput < 0)
|
| + return;
|
| + this._updateNetworkConditions(conditions);
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * @param {!WebInspector.NetworkManager.Conditions} conditions
|
| + */
|
| + _updateNetworkConditions: function(conditions)
|
| + {
|
| + if (conditions.throughput < 0) {
|
| + this._networkAgent.emulateNetworkConditions(false, 0, 0, 0);
|
| + } else {
|
| + var offline = !conditions.throughput && !conditions.latency;
|
| + this._networkAgent.emulateNetworkConditions(!!offline, conditions.latency, conditions.throughput, conditions.throughput);
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * @param {!WebInspector.Event} event
|
| + */
|
| + _networkConditionsSettingChanged: function(event)
|
| + {
|
| + this._updateNetworkConditions(/** @type {!WebInspector.NetworkManager.Conditions} */ (event.data));
|
| + },
|
| +
|
| __proto__: WebInspector.SDKModel.prototype
|
| }
|
|
|
| @@ -596,10 +640,6 @@ WebInspector.MultitargetNetworkManager.prototype = {
|
| networkAgent.setExtraHTTPHeaders(this._extraHeaders);
|
| if (typeof this._userAgent !== "undefined")
|
| networkAgent.setUserAgentOverride(this._userAgent);
|
| - if (this._networkConditions) {
|
| - networkAgent.emulateNetworkConditions(this._networkConditions.offline, this._networkConditions.latency,
|
| - this._networkConditions.throughput, this._networkConditions.throughput);
|
| - }
|
| },
|
|
|
| /**
|
| @@ -629,20 +669,6 @@ WebInspector.MultitargetNetworkManager.prototype = {
|
| this._userAgent = userAgent;
|
| for (var target of WebInspector.targetManager.targets())
|
| target.networkAgent().setUserAgentOverride(this._userAgent);
|
| - },
|
| -
|
| - /**
|
| - * @param {boolean} offline
|
| - * @param {number} latency
|
| - * @param {number} throughput
|
| - */
|
| - emulateNetworkConditions: function(offline, latency, throughput)
|
| - {
|
| - this._networkConditions = { offline: offline, latency: latency, throughput: throughput };
|
| - for (var target of WebInspector.targetManager.targets()) {
|
| - target.networkAgent().emulateNetworkConditions(this._networkConditions.offline, this._networkConditions.latency,
|
| - this._networkConditions.throughput, this._networkConditions.throughput);
|
| - }
|
| }
|
| }
|
|
|
|
|