| 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 WebInspector.NetworkManager.OfflineConditions, | 44 WebInspector.NetworkManager.OfflineConditions, |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 /** | 193 /** |
| 190 * @param {!WebInspector.ContextMenu} contextMenu | 194 * @param {!WebInspector.ContextMenu} contextMenu |
| 191 */ | 195 */ |
| 192 function appendItems(contextMenu) | 196 function appendItems(contextMenu) |
| 193 { | 197 { |
| 194 for (var index = 0; index < options.length; ++index) { | 198 for (var index = 0; index < options.length; ++index) { |
| 195 var conditions = options[index]; | 199 var conditions = options[index]; |
| 196 if (!conditions) | 200 if (!conditions) |
| 197 contextMenu.appendSeparator(); | 201 contextMenu.appendSeparator(); |
| 198 else | 202 else |
| 199 contextMenu.appendCheckboxItem(WebInspector.NetworkConditionsSel
ector._conditionsTitle(conditions).text, selector.optionSelected.bind(selector,
conditions), selectedIndex === index); | 203 contextMenu.appendCheckboxItem(WebInspector.NetworkConditionsSel
ector._conditionsTitle(conditions, true).text, selector.optionSelected.bind(sele
ctor, conditions), selectedIndex === index); |
| 200 } | 204 } |
| 201 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), selector.rev
ealAndUpdate.bind(selector)); | 205 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), selector.rev
ealAndUpdate.bind(selector)); |
| 202 } | 206 } |
| 203 | 207 |
| 204 /** | 208 /** |
| 205 * @param {!Array.<!WebInspector.NetworkConditionsGroup>} groups | 209 * @param {!Array.<!WebInspector.NetworkConditionsGroup>} groups |
| 206 * @return {!Array<?WebInspector.NetworkManager.Conditions>} | 210 * @return {!Array<?WebInspector.NetworkManager.Conditions>} |
| 207 */ | 211 */ |
| 208 function populate(groups) | 212 function populate(groups) |
| 209 { | 213 { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 WebInspector.multitargetNetworkManager.setNetworkConditions(WebInspe
ctor.NetworkManager.NoThrottlingConditions); | 460 WebInspector.multitargetNetworkManager.setNetworkConditions(WebInspe
ctor.NetworkManager.NoThrottlingConditions); |
| 457 return true; | 461 return true; |
| 458 } | 462 } |
| 459 if (actionId === "components.network-offline") { | 463 if (actionId === "components.network-offline") { |
| 460 WebInspector.multitargetNetworkManager.setNetworkConditions(WebInspe
ctor.NetworkManager.OfflineConditions); | 464 WebInspector.multitargetNetworkManager.setNetworkConditions(WebInspe
ctor.NetworkManager.OfflineConditions); |
| 461 return true; | 465 return true; |
| 462 } | 466 } |
| 463 return false; | 467 return false; |
| 464 } | 468 } |
| 465 } | 469 } |
| OLD | NEW |