| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @constructor | 6 * @constructor |
| 7 * @param {function(!Array<!WebInspector.NetworkConditionsGroup>):!Array<?WebIns
pector.NetworkManager.Conditions>} populateCallback | 7 * @param {function(!Array<!WebInspector.NetworkConditionsGroup>):!Array<?WebIns
pector.NetworkManager.Conditions>} populateCallback |
| 8 * @param {function(number)} selectCallback | 8 * @param {function(number)} selectCallback |
| 9 */ | 9 */ |
| 10 WebInspector.NetworkConditionsSelector = function(populateCallback, selectCallba
ck) | 10 WebInspector.NetworkConditionsSelector = function(populateCallback, selectCallba
ck) |
| 11 { | 11 { |
| 12 this._populateCallback = populateCallback; | 12 this._populateCallback = populateCallback; |
| 13 this._selectCallback = selectCallback; | 13 this._selectCallback = selectCallback; |
| 14 this._customSetting = WebInspector.moduleSetting("customNetworkConditions"); | 14 this._customSetting = WebInspector.moduleSetting("customNetworkConditions"); |
| 15 this._customSetting.addChangeListener(this._populateOptions, this); | 15 this._customSetting.addChangeListener(this._populateOptions, this); |
| 16 this._manager = WebInspector.multitargetNetworkManager; | 16 this._manager = WebInspector.multitargetNetworkManager; |
| 17 this._manager.addEventListener(WebInspector.MultitargetNetworkManager.Events
.ConditionsChanged, this._conditionsChanged, this); | 17 this._manager.addEventListener(WebInspector.MultitargetNetworkManager.Events
.ConditionsChanged, this._conditionsChanged, this); |
| 18 this._populateOptions(); | 18 this._populateOptions(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** @typedef {!{title: string, items: !Array<!WebInspector.NetworkManager.Condit
ions>}} */ | 21 /** @typedef {!{title: string, items: !Array<!WebInspector.NetworkManager.Condit
ions>}} */ |
| 22 WebInspector.NetworkConditionsGroup; | 22 WebInspector.NetworkConditionsGroup; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * @param {number} throughput | 25 * @param {number} throughput |
| 26 * @param {boolean=} plainText |
| 26 * @return {string} | 27 * @return {string} |
| 27 */ | 28 */ |
| 28 WebInspector.NetworkConditionsSelector._throughputText = function(throughput) | 29 WebInspector.NetworkConditionsSelector._throughputText = function(throughput, pl
ainText) |
| 29 { | 30 { |
| 30 if (throughput < 0) | 31 if (throughput < 0) |
| 31 return ""; | 32 return ""; |
| 32 var throughputInKbps = throughput / (1024 / 8); | 33 var throughputInKbps = throughput / (1024 / 8); |
| 34 var delimiter = plainText ? "" : " "; |
| 33 if (throughputInKbps < 1024) | 35 if (throughputInKbps < 1024) |
| 34 return WebInspector.UIString("%d kb/s", throughputInKbps); | 36 return WebInspector.UIString("%d%skb/s", throughputInKbps, delimiter); |
| 35 if (throughputInKbps < 1024 * 10) | 37 if (throughputInKbps < 1024 * 10) |
| 36 return WebInspector.UIString("%.1f Mb/s", throughputInKbps / 1024); | 38 return WebInspector.UIString("%.1f%sMb/s", throughputInKbps / 1024, deli
miter); |
| 37 return WebInspector.UIString("%d Mb/s", (throughputInKbps / 1024) | 0); | 39 return WebInspector.UIString("%d%sMb/s", (throughputInKbps / 1024) | 0, deli
miter); |
| 38 } | 40 } |
| 39 | 41 |
| 40 /** @type {!Array.<!WebInspector.NetworkManager.Conditions>} */ | 42 /** @type {!Array.<!WebInspector.NetworkManager.Conditions>} */ |
| 41 WebInspector.NetworkConditionsSelector._presets = [ | 43 WebInspector.NetworkConditionsSelector._presets = [ |
| 42 {title: "Offline", download: 0 * 1024 / 8, upload: 0 * 1024 / 8, latency: 0}
, | 44 {title: "Offline", download: 0 * 1024 / 8, upload: 0 * 1024 / 8, latency: 0}
, |
| 43 {title: "GPRS", download: 50 * 1024 / 8, upload: 20 * 1024 / 8, latency: 500
}, | 45 {title: "GPRS", download: 50 * 1024 / 8, upload: 20 * 1024 / 8, latency: 500
}, |
| 44 {title: "Regular 2G", download: 250 * 1024 / 8, upload: 50 * 1024 / 8, laten
cy: 300}, | 46 {title: "Regular 2G", download: 250 * 1024 / 8, upload: 50 * 1024 / 8, laten
cy: 300}, |
| 45 {title: "Good 2G", download: 450 * 1024 / 8, upload: 150 * 1024 / 8, latency
: 150}, | 47 {title: "Good 2G", download: 450 * 1024 / 8, upload: 150 * 1024 / 8, latency
: 150}, |
| 46 {title: "Regular 3G", download: 750 * 1024 / 8, upload: 250 * 1024 / 8, late
ncy: 100}, | 48 {title: "Regular 3G", download: 750 * 1024 / 8, upload: 250 * 1024 / 8, late
ncy: 100}, |
| 47 {title: "Good 3G", download: 1.5 * 1024 * 1024 / 8, upload: 750 * 1024 / 8,
latency: 40}, | 49 {title: "Good 3G", download: 1.5 * 1024 * 1024 / 8, upload: 750 * 1024 / 8,
latency: 40}, |
| 48 {title: "Regular 4G", download: 4 * 1024 * 1024 / 8, upload: 3 * 1024 * 1024
/ 8, latency: 20}, | 50 {title: "Regular 4G", download: 4 * 1024 * 1024 / 8, upload: 3 * 1024 * 1024
/ 8, latency: 20}, |
| 49 {title: "DSL", download: 2 * 1024 * 1024 / 8, upload: 1 * 1024 * 1024 / 8, l
atency: 5}, | 51 {title: "DSL", download: 2 * 1024 * 1024 / 8, upload: 1 * 1024 * 1024 / 8, l
atency: 5}, |
| 50 {title: "WiFi", download: 30 * 1024 * 1024 / 8, upload: 15 * 1024 * 1024 / 8
, latency: 2} | 52 {title: "WiFi", download: 30 * 1024 * 1024 / 8, upload: 15 * 1024 * 1024 / 8
, latency: 2} |
| 51 ]; | 53 ]; |
| 52 | 54 |
| 53 /** | 55 /** |
| 54 * @param {!WebInspector.NetworkManager.Conditions} conditions | 56 * @param {!WebInspector.NetworkManager.Conditions} conditions |
| 57 * @param {boolean=} plainText |
| 55 * @return {!{text: string, title: string}} | 58 * @return {!{text: string, title: string}} |
| 56 */ | 59 */ |
| 57 WebInspector.NetworkConditionsSelector._conditionsTitle = function(conditions) | 60 WebInspector.NetworkConditionsSelector._conditionsTitle = function(conditions, p
lainText) |
| 58 { | 61 { |
| 59 var downloadInKbps = conditions.download / (1024 / 8); | 62 var downloadInKbps = conditions.download / (1024 / 8); |
| 60 var uploadInKbps = conditions.upload / (1024 / 8); | 63 var uploadInKbps = conditions.upload / (1024 / 8); |
| 61 var isThrottling = (downloadInKbps >= 0) || (uploadInKbps >= 0) || (conditio
ns.latency > 0); | 64 var isThrottling = (downloadInKbps >= 0) || (uploadInKbps >= 0) || (conditio
ns.latency > 0); |
| 62 var conditionTitle = WebInspector.UIString(conditions.title); | 65 var conditionTitle = WebInspector.UIString(conditions.title); |
| 63 if (!isThrottling) | 66 if (!isThrottling) |
| 64 return {text: conditionTitle, title: conditionTitle}; | 67 return {text: conditionTitle, title: conditionTitle}; |
| 65 | 68 |
| 66 var downloadText = WebInspector.NetworkConditionsSelector._throughputText(co
nditions.download); | 69 var downloadText = WebInspector.NetworkConditionsSelector._throughputText(co
nditions.download, plainText); |
| 67 var uploadText = WebInspector.NetworkConditionsSelector._throughputText(cond
itions.upload); | 70 var uploadText = WebInspector.NetworkConditionsSelector._throughputText(cond
itions.upload, plainText); |
| 68 var title = WebInspector.UIString("%s (%s\u2b07 %s\u2b06 %dms RTT)", conditi
onTitle, downloadText, uploadText, conditions.latency); | 71 var pattern = plainText ? "%s (%dms, %s, %s)" : "%s (%dms RTT, %s\u2b07, %s\
u2b06)"; |
| 72 var title = WebInspector.UIString(pattern, conditionTitle, conditions.latenc
y, downloadText, uploadText); |
| 69 return {text: title, title: WebInspector.UIString("Maximum download throughp
ut: %s.\r\nMaximum upload throughput: %s.\r\nMinimum round-trip time: %dms.", do
wnloadText, uploadText, conditions.latency)}; | 73 return {text: title, title: WebInspector.UIString("Maximum download throughp
ut: %s.\r\nMaximum upload throughput: %s.\r\nMinimum round-trip time: %dms.", do
wnloadText, uploadText, conditions.latency)}; |
| 70 } | 74 } |
| 71 | 75 |
| 72 WebInspector.NetworkConditionsSelector.prototype = { | 76 WebInspector.NetworkConditionsSelector.prototype = { |
| 73 _populateOptions: function() | 77 _populateOptions: function() |
| 74 { | 78 { |
| 75 var customGroup = {title: WebInspector.UIString("Custom"), items: this._
customSetting.get()}; | 79 var customGroup = {title: WebInspector.UIString("Custom"), items: this._
customSetting.get()}; |
| 76 var presetsGroup = {title: WebInspector.UIString("Presets"), items: WebI
nspector.NetworkConditionsSelector._presets}; | 80 var presetsGroup = {title: WebInspector.UIString("Presets"), items: WebI
nspector.NetworkConditionsSelector._presets}; |
| 77 var disabledGroup = {title: WebInspector.UIString("Disabled"), items: [W
ebInspector.NetworkManager.NoThrottlingConditions]}; | 81 var disabledGroup = {title: WebInspector.UIString("Disabled"), items: [W
ebInspector.NetworkManager.NoThrottlingConditions]}; |
| 78 this._options = this._populateCallback([customGroup, presetsGroup, disab
ledGroup]); | 82 this._options = this._populateCallback([customGroup, presetsGroup, disab
ledGroup]); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 /** | 182 /** |
| 179 * @param {!WebInspector.ContextMenu} contextMenu | 183 * @param {!WebInspector.ContextMenu} contextMenu |
| 180 */ | 184 */ |
| 181 function appendItems(contextMenu) | 185 function appendItems(contextMenu) |
| 182 { | 186 { |
| 183 for (var index = 0; index < options.length; ++index) { | 187 for (var index = 0; index < options.length; ++index) { |
| 184 var conditions = options[index]; | 188 var conditions = options[index]; |
| 185 if (!conditions) | 189 if (!conditions) |
| 186 contextMenu.appendSeparator(); | 190 contextMenu.appendSeparator(); |
| 187 else | 191 else |
| 188 contextMenu.appendCheckboxItem(WebInspector.NetworkConditionsSel
ector._conditionsTitle(conditions).text, selector.optionSelected.bind(selector,
conditions), selectedIndex === index); | 192 contextMenu.appendCheckboxItem(WebInspector.NetworkConditionsSel
ector._conditionsTitle(conditions, true).text, selector.optionSelected.bind(sele
ctor, conditions), selectedIndex === index); |
| 189 } | 193 } |
| 190 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), selector.rev
ealAndUpdate.bind(selector)); | 194 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), selector.rev
ealAndUpdate.bind(selector)); |
| 191 } | 195 } |
| 192 | 196 |
| 193 /** | 197 /** |
| 194 * @param {!Array.<!WebInspector.NetworkConditionsGroup>} groups | 198 * @param {!Array.<!WebInspector.NetworkConditionsGroup>} groups |
| 195 * @return {!Array<?WebInspector.NetworkManager.Conditions>} | 199 * @return {!Array<?WebInspector.NetworkManager.Conditions>} |
| 196 */ | 200 */ |
| 197 function populate(groups) | 201 function populate(groups) |
| 198 { | 202 { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 */ | 420 */ |
| 417 function latencyValidator(item, index, input) | 421 function latencyValidator(item, index, input) |
| 418 { | 422 { |
| 419 var value = input.value.trim(); | 423 var value = input.value.trim(); |
| 420 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 10
00000); | 424 return !value || (/^[\d]+$/.test(value) && value >= 0 && value <= 10
00000); |
| 421 } | 425 } |
| 422 }, | 426 }, |
| 423 | 427 |
| 424 __proto__: WebInspector.VBox.prototype | 428 __proto__: WebInspector.VBox.prototype |
| 425 } | 429 } |
| OLD | NEW |