OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 return new WebInspector.OverridesSupport.DeviceOrientation(alpha, beta, gamm a); | 253 return new WebInspector.OverridesSupport.DeviceOrientation(alpha, beta, gamm a); |
254 } | 254 } |
255 | 255 |
256 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride = function() | 256 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride = function() |
257 { | 257 { |
258 PageAgent.clearDeviceOrientationOverride(); | 258 PageAgent.clearDeviceOrientationOverride(); |
259 } | 259 } |
260 | 260 |
261 /** | 261 /** |
262 * @param {string} value | 262 * @param {string} value |
263 * @return {!string} | |
263 */ | 264 */ |
264 WebInspector.OverridesSupport.integerInputValidator = function(value) | 265 WebInspector.OverridesSupport.integerInputValidator = function(value) |
265 { | 266 { |
266 if (/^[\d]+$/.test(value) && value >= 0 && value <= 10000) | 267 if (/^[\d]+$/.test(value) && value >= 0 && value <= 10000) |
267 return ""; | 268 return ""; |
268 return WebInspector.UIString("Value must be non-negative integer"); | 269 return WebInspector.UIString("Value must be non-negative integer"); |
269 } | 270 } |
270 | 271 |
271 /** | 272 /** |
272 * @param {string} value | 273 * @param {string} value |
274 * @return {!string} | |
273 */ | 275 */ |
274 WebInspector.OverridesSupport.doubleInputValidator = function(value) | 276 WebInspector.OverridesSupport.doubleInputValidator = function(value) |
275 { | 277 { |
276 if (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10000) | 278 if (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10000) |
277 return ""; | 279 return ""; |
278 return WebInspector.UIString("Value must be non-negative float"); | 280 return WebInspector.UIString("Value must be non-negative float"); |
279 } | 281 } |
280 | 282 |
283 /** | |
284 * @param {string} value | |
285 * @return {!string} | |
286 */ | |
287 WebInspector.OverridesSupport.networkDomainsValidator = function(value) | |
288 { | |
289 function test(s) | |
290 { | |
291 return /^[\w\-]+(\.[\w\-]+)*$/.test(s.trim()); | |
292 } | |
293 | |
294 if (!value.trim()) | |
295 return ""; | |
296 return value.split(",").every(test) ? "" : WebInspector.UIString("Value must be a comma-separated list of domains"); | |
297 } | |
298 | |
281 // Third element lists device metrics separated by 'x': | 299 // Third element lists device metrics separated by 'x': |
282 // - screen width, | 300 // - screen width, |
283 // - screen height, | 301 // - screen height, |
284 // - device scale factor, | 302 // - device scale factor, |
285 WebInspector.OverridesSupport._phones = [ | 303 WebInspector.OverridesSupport._phones = [ |
286 ["Apple iPhone 3GS", | 304 ["Apple iPhone 3GS", |
287 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWeb Kit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", | 305 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWeb Kit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", |
288 "320x480x1"], | 306 "320x480x1"], |
289 ["Apple iPhone 4", | 307 ["Apple iPhone 4", |
290 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWeb Kit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", | 308 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWeb Kit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 ["iPhone \u2014 iOS 6", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/853 6.25"], | 455 ["iPhone \u2014 iOS 6", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/853 6.25"], |
438 ["MeeGo \u2014 Nokia N9", "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 ( KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"], | 456 ["MeeGo \u2014 Nokia N9", "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 ( KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"], |
439 ["Opera 18 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) Appl eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12 84.68"], | 457 ["Opera 18 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) Appl eWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.12 84.68"], |
440 ["Opera 18 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.1284.68"], | 458 ["Opera 18 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.1284.68"], |
441 ["Opera 12 \u2014 Mac", "Opera/9.80 (Macintosh; Intel Mac OS X 10.9.1) Prest o/2.12.388 Version/12.16"], | 459 ["Opera 12 \u2014 Mac", "Opera/9.80 (Macintosh; Intel Mac OS X 10.9.1) Prest o/2.12.388 Version/12.16"], |
442 ["Opera 12 \u2014 Windows", "Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Ver sion/12.16"], | 460 ["Opera 12 \u2014 Windows", "Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Ver sion/12.16"], |
443 ["Silk \u2014 Kindle Fire (Desktop view)", "Mozilla/5.0 (Linux; U; en-us; KF THWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true"], | 461 ["Silk \u2014 Kindle Fire (Desktop view)", "Mozilla/5.0 (Linux; U; en-us; KF THWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true"], |
444 ["Silk \u2014 Kindle Fire (Mobile view)", "Mozilla/5.0 (Linux; U; Android 4. 2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"], | 462 ["Silk \u2014 Kindle Fire (Mobile view)", "Mozilla/5.0 (Linux; U; Android 4. 2.2; en-us; KFTHWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Mobile Safari/535.19 Silk-Accelerated=true"], |
445 ]; | 463 ]; |
446 | 464 |
465 WebInspector.OverridesSupport._networkThroughputPresets = [ | |
466 ["Offline", 0], | |
467 ["5 Kbps", 5 * 1024 / 8], | |
468 ["10 Kbps (GSM)", 10 * 1024 / 8], | |
469 ["20 Kbps", 20 * 1024 / 8], | |
470 ["40 Kbps (GPRS)", 40 * 1024 / 8], | |
471 ["80 Kbps", 80 * 1024 / 8], | |
472 ["160 Kbps (EDGE)", 160 * 1024 / 8], | |
473 ["320 Kbps", 320 * 1024 / 8], | |
474 ["640 Kbps (3G)", 640 * 1024 / 8], | |
475 ["1 Mbps", 1024 * 1024 / 8], | |
476 ["2 Mbps (802.11b)", 2048 * 1024 / 8] | |
vsevik
2014/06/11 14:53:20
AFAIK 802.11b actually supports up to 5.5 / 11 Mbp
dgozman
2014/06/11 14:59:02
As discussed offline, this is a real throughput es
| |
477 ]; | |
478 | |
447 WebInspector.OverridesSupport.prototype = { | 479 WebInspector.OverridesSupport.prototype = { |
448 /** | 480 /** |
449 * @return {boolean} | 481 * @return {boolean} |
450 */ | 482 */ |
451 responsiveDesignAvailable: function() | 483 responsiveDesignAvailable: function() |
452 { | 484 { |
453 return this._responsiveDesignAvailable; | 485 return this._responsiveDesignAvailable; |
454 }, | 486 }, |
455 | 487 |
456 /** | 488 /** |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); | 583 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); |
552 | 584 |
553 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); | 585 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); |
554 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); | 586 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); |
555 | 587 |
556 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); | 588 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); |
557 | 589 |
558 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); | 590 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); |
559 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); | 591 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); |
560 | 592 |
593 this.settings.emulateNetworkConditions.addChangeListener(this._networkCo nditionsChanged, this); | |
594 this.settings.networkConditionsDomains.addChangeListener(this._networkCo nditionsChanged, this); | |
595 this.settings.networkConditionsThroughput.addChangeListener(this._networ kConditionsChanged, this); | |
596 | |
561 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); | 597 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); |
562 | 598 |
563 if (this.settings.overrideDeviceOrientation.get()) | 599 if (this.settings.overrideDeviceOrientation.get()) |
564 this._deviceOrientationChanged(); | 600 this._deviceOrientationChanged(); |
565 | 601 |
566 if (this.settings.overrideGeolocation.get()) | 602 if (this.settings.overrideGeolocation.get()) |
567 this._geolocationPositionChanged(); | 603 this._geolocationPositionChanged(); |
568 | 604 |
569 if (this.settings.emulateTouchEvents.get()) | 605 if (this.settings.emulateTouchEvents.get()) |
570 this._emulateTouchEventsChanged(); | 606 this._emulateTouchEventsChanged(); |
571 | 607 |
572 if (this.settings.overrideCSSMedia.get()) | 608 if (this.settings.overrideCSSMedia.get()) |
573 this._cssMediaChanged(); | 609 this._cssMediaChanged(); |
574 | 610 |
575 if (this.settings.overrideDeviceResolution.get() || this.settings.emulat eViewport.get()) | 611 if (this.settings.overrideDeviceResolution.get() || this.settings.emulat eViewport.get()) |
576 this._deviceMetricsChanged(); | 612 this._deviceMetricsChanged(); |
577 | 613 |
578 if (this.settings.overrideUserAgent.get()) | 614 if (this.settings.overrideUserAgent.get()) |
579 this._userAgentChanged(); | 615 this._userAgentChanged(); |
580 | 616 |
617 if (this.settings.emulateNetworkConditions.get()) | |
618 this._networkConditionsChanged(); | |
619 | |
581 this._showRulersChanged(); | 620 this._showRulersChanged(); |
582 }, | 621 }, |
583 | 622 |
584 _userAgentChanged: function() | 623 _userAgentChanged: function() |
585 { | 624 { |
586 if (this._userAgentChangedListenerMuted) | 625 if (this._userAgentChangedListenerMuted) |
587 return; | 626 return; |
588 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; | 627 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; |
589 NetworkAgent.setUserAgentOverride(userAgent); | 628 NetworkAgent.setUserAgentOverride(userAgent); |
590 if (this._userAgent !== userAgent) | 629 if (this._userAgent !== userAgent) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) | 792 if (this.isInspectingDevice() && this.settings.overrideCSSMedia.get()) |
754 return; | 793 return; |
755 | 794 |
756 PageAgent.setEmulatedMedia(this.settings.overrideCSSMedia.get() ? this.s ettings.emulatedCSSMedia.get() : ""); | 795 PageAgent.setEmulatedMedia(this.settings.overrideCSSMedia.get() ? this.s ettings.emulatedCSSMedia.get() : ""); |
757 var targets = WebInspector.targetManager.targets(); | 796 var targets = WebInspector.targetManager.targets(); |
758 for (var i = 0; i < targets.length; ++i) | 797 for (var i = 0; i < targets.length; ++i) |
759 targets[i].cssModel.mediaQueryResultChanged(); | 798 targets[i].cssModel.mediaQueryResultChanged(); |
760 this.maybeHasActiveOverridesChanged(); | 799 this.maybeHasActiveOverridesChanged(); |
761 }, | 800 }, |
762 | 801 |
802 _networkConditionsChanged: function() | |
803 { | |
804 if (!this.settings.emulateNetworkConditions.get()) { | |
805 NetworkAgent.emulateNetworkConditions([], 0, false); | |
806 } else { | |
807 var domainsString = this.settings.networkConditionsDomains.get().tri m(); | |
808 var domains = domainsString ? domainsString.split(",").map(function (s) { return s.trim(); }) : []; | |
809 var throughput = this.settings.networkConditionsThroughput.get(); | |
810 var offline = !throughput; | |
811 NetworkAgent.emulateNetworkConditions(domains, throughput, offline); | |
812 } | |
813 this.maybeHasActiveOverridesChanged(); | |
814 }, | |
815 | |
763 /** | 816 /** |
764 * @return {boolean} | 817 * @return {boolean} |
765 */ | 818 */ |
766 showMetricsRulers: function() | 819 showMetricsRulers: function() |
767 { | 820 { |
768 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceResolution.get(); | 821 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceResolution.get(); |
769 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; | 822 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; |
770 }, | 823 }, |
771 | 824 |
772 _showRulersChanged: function() | 825 _showRulersChanged: function() |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); | 910 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); |
858 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); | 911 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); |
859 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); | 912 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); |
860 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); | 913 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); |
861 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); | 914 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); |
862 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); | 915 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); |
863 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); | 916 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); |
864 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); | 917 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); |
865 this.settings.emulatedDevice = WebInspector.settings.createSetting("emul atedDevice", "Google Nexus 5"); | 918 this.settings.emulatedDevice = WebInspector.settings.createSetting("emul atedDevice", "Google Nexus 5"); |
866 | 919 |
920 this.settings.emulateNetworkConditions = WebInspector.settings.createSet ting("emulateNetworkConditions", false); | |
921 this.settings.networkConditionsDomains = WebInspector.settings.createSet ting("networkConditionsDomains", ""); | |
922 this.settings.networkConditionsThroughput = WebInspector.settings.create Setting("networkConditionsThroughput", 0); | |
923 | |
867 this.maybeHasActiveOverridesChanged(); | 924 this.maybeHasActiveOverridesChanged(); |
868 | 925 |
869 if (this._applyInitialOverridesOnTargetAdded) { | 926 if (this._applyInitialOverridesOnTargetAdded) { |
870 delete this._applyInitialOverridesOnTargetAdded; | 927 delete this._applyInitialOverridesOnTargetAdded; |
871 this.applyInitialOverrides(); | 928 this.applyInitialOverrides(); |
872 } | 929 } |
873 }, | 930 }, |
874 | 931 |
875 swapDimensions: function() | 932 swapDimensions: function() |
876 { | 933 { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 | 1138 |
1082 overrideUserAgentSetting.addChangeListener(overrideUserAgentChanged); | 1139 overrideUserAgentSetting.addChangeListener(overrideUserAgentChanged); |
1083 function overrideUserAgentChanged() | 1140 function overrideUserAgentChanged() |
1084 { | 1141 { |
1085 otherUserAgentElement.readOnly = !overrideUserAgentSetting.get() || (userAgentSelectElement.options[userAgentSelectElement.selectedIndex].value !== "Other"); | 1142 otherUserAgentElement.readOnly = !overrideUserAgentSetting.get() || (userAgentSelectElement.options[userAgentSelectElement.selectedIndex].value !== "Other"); |
1086 } | 1143 } |
1087 | 1144 |
1088 return { select: userAgentSelectElement, input: otherUserAgentElement }; | 1145 return { select: userAgentSelectElement, input: otherUserAgentElement }; |
1089 }, | 1146 }, |
1090 | 1147 |
1148 /** | |
1149 * @param {!Document} document | |
1150 * @return {!Element} | |
1151 */ | |
1152 createNetworkThroughputSelect: function(document) | |
1153 { | |
1154 var throughputSetting = WebInspector.overridesSupport.settings.networkCo nditionsThroughput; | |
1155 var emulateNetworkSetting = WebInspector.overridesSupport.settings.emula teNetworkConditions; | |
1156 var throughputSelectElement = document.createElement("select"); | |
1157 var presets = WebInspector.OverridesSupport._networkThroughputPresets; | |
1158 for (var i = 0; i < presets.length; ++i) | |
1159 throughputSelectElement.add(new Option(presets[i][0], presets[i][1]) ); | |
1160 throughputSelectElement.selectedIndex = 0; | |
1161 | |
1162 settingChanged(); | |
1163 throughputSetting.addChangeListener(settingChanged); | |
1164 throughputSelectElement.addEventListener("change", throughputSelected, f alse); | |
1165 | |
1166 function throughputSelected() | |
1167 { | |
1168 var value = Number(throughputSelectElement.options[throughputSelectE lement.selectedIndex].value); | |
1169 throughputSetting.removeChangeListener(settingChanged); | |
1170 throughputSetting.set(value); | |
1171 throughputSetting.addChangeListener(settingChanged); | |
1172 emulateNetworkSetting.set(true); | |
1173 } | |
1174 | |
1175 function settingChanged() | |
1176 { | |
1177 var value = String(throughputSetting.get()); | |
1178 var options = throughputSelectElement.options; | |
1179 var selectionRestored = false; | |
1180 for (var i = 0; i < options.length; ++i) { | |
1181 if (options[i].value === value) { | |
1182 throughputSelectElement.selectedIndex = i; | |
1183 selectionRestored = true; | |
1184 break; | |
1185 } | |
1186 } | |
1187 if (!selectionRestored) | |
1188 throughputSelectElement.selectedIndex = options.length - 1; | |
1189 } | |
1190 | |
1191 return throughputSelectElement; | |
1192 }, | |
1193 | |
1091 __proto__: WebInspector.Object.prototype | 1194 __proto__: WebInspector.Object.prototype |
1092 } | 1195 } |
1093 | 1196 |
1094 | 1197 |
1095 /** | 1198 /** |
1096 * @type {!WebInspector.OverridesSupport} | 1199 * @type {!WebInspector.OverridesSupport} |
1097 */ | 1200 */ |
1098 WebInspector.overridesSupport; | 1201 WebInspector.overridesSupport; |
OLD | NEW |