| Index: third_party/WebKit/Source/devtools/front_end/mobile_throttling/NetworkThrottlingSelector.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/mobile_throttling/NetworkThrottlingSelector.js b/third_party/WebKit/Source/devtools/front_end/mobile_throttling/NetworkThrottlingSelector.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3539db4d22b75062b4944f1aa91bc20cf00e30d7
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/devtools/front_end/mobile_throttling/NetworkThrottlingSelector.js
|
| @@ -0,0 +1,65 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +MobileThrottling.NetworkThrottlingSelector = class {
|
| + /**
|
| + * @param {function(!Array<!MobileThrottling.NetworkThrottlingConditionsGroup>):!Array<?SDK.NetworkManager.Conditions>} populateCallback
|
| + * @param {function(number)} selectCallback
|
| + * @param {!Common.Setting<!Array<!SDK.NetworkManager.Conditions>>} customNetworkConditionsSetting
|
| + */
|
| + constructor(populateCallback, selectCallback, customNetworkConditionsSetting) {
|
| + this._populateCallback = populateCallback;
|
| + this._selectCallback = selectCallback;
|
| + this._customNetworkConditionsSetting = customNetworkConditionsSetting;
|
| + this._customNetworkConditionsSetting.addChangeListener(this._populateOptions, this);
|
| + SDK.multitargetNetworkManager.addEventListener(
|
| + SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._networkConditionsChanged, this);
|
| + /** @type {!Array<?SDK.NetworkManager.Conditions>} */
|
| + this._options;
|
| + this._populateOptions();
|
| + }
|
| +
|
| + revealAndUpdate() {
|
| + Common.Revealer.reveal(this._customNetworkConditionsSetting);
|
| + this._networkConditionsChanged();
|
| + }
|
| +
|
| + /**
|
| + * @param {!SDK.NetworkManager.Conditions} conditions
|
| + */
|
| + optionSelected(conditions) {
|
| + SDK.multitargetNetworkManager.setNetworkConditions(conditions);
|
| + }
|
| +
|
| + _populateOptions() {
|
| + var disabledGroup = {title: Common.UIString('Disabled'), items: [SDK.NetworkManager.NoThrottlingConditions]};
|
| + var presetsGroup = {title: Common.UIString('Presets'), items: MobileThrottling.networkPresets};
|
| + var customGroup = {title: Common.UIString('Custom'), items: this._customNetworkConditionsSetting.get()};
|
| + this._options = this._populateCallback([disabledGroup, presetsGroup, customGroup]);
|
| + if (!this._networkConditionsChanged()) {
|
| + for (var i = this._options.length - 1; i >= 0; i--) {
|
| + if (this._options[i]) {
|
| + this.optionSelected(/** @type {!SDK.NetworkManager.Conditions} */ (this._options[i]));
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * @return {boolean} returns false if selected condition no longer exists
|
| + */
|
| + _networkConditionsChanged() {
|
| + var value = SDK.multitargetNetworkManager.networkConditions();
|
| + for (var index = 0; index < this._options.length; ++index) {
|
| + var option = this._options[index];
|
| + if (option && option.download === value.download && option.upload === value.upload &&
|
| + option.latency === value.latency && option.title === value.title) {
|
| + this._selectCallback(index);
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +};
|
|
|