Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: Source/devtools/front_end/emulation/OverridesSupport.js

Issue 1186083003: [DevTools] Move network throttling to network panel. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merged in device mode Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/emulation/OverridesUI.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 this.settings.overrideGeolocation = WebInspector.settings.createSetting("ove rrideGeolocation", false); 60 this.settings.overrideGeolocation = WebInspector.settings.createSetting("ove rrideGeolocation", false);
61 this.settings.geolocationOverride = WebInspector.settings.createSetting("geo locationOverride", ""); 61 this.settings.geolocationOverride = WebInspector.settings.createSetting("geo locationOverride", "");
62 62
63 this.settings.overrideDeviceOrientation = WebInspector.settings.createSettin g("overrideDeviceOrientation", false); 63 this.settings.overrideDeviceOrientation = WebInspector.settings.createSettin g("overrideDeviceOrientation", false);
64 this.settings.deviceOrientationOverride = WebInspector.settings.createSettin g("deviceOrientationOverride", ""); 64 this.settings.deviceOrientationOverride = WebInspector.settings.createSettin g("deviceOrientationOverride", "");
65 65
66 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("overri deCSSMedia", false); 66 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("overri deCSSMedia", false);
67 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("emulat edCSSMedia", "print"); 67 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("emulat edCSSMedia", "print");
68 68
69 this.settings.networkConditions = WebInspector.settings.createSetting("netwo rkConditions", {throughput: WebInspector.OverridesSupport.NetworkThroughputUnlim itedValue, latency: 0});
70
71 this.settings.javaScriptDisabled = WebInspector.moduleSetting("javaScriptDis abled"); 69 this.settings.javaScriptDisabled = WebInspector.moduleSetting("javaScriptDis abled");
72 } 70 }
73 71
74 WebInspector.OverridesSupport.Events = { 72 WebInspector.OverridesSupport.Events = {
75 OverridesWarningUpdated: "OverridesWarningUpdated", 73 OverridesWarningUpdated: "OverridesWarningUpdated",
76 EmulationStateChanged: "EmulationStateChanged" 74 EmulationStateChanged: "EmulationStateChanged"
77 } 75 }
78 76
79 WebInspector.OverridesSupport.MaxDeviceSize = 9999; 77 WebInspector.OverridesSupport.MaxDeviceSize = 9999;
80 78
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 * @param {string} value 249 * @param {string} value
252 * @return {string} 250 * @return {string}
253 */ 251 */
254 WebInspector.OverridesSupport.deviceScaleFactorValidator = function(value) 252 WebInspector.OverridesSupport.deviceScaleFactorValidator = function(value)
255 { 253 {
256 if (!value || (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10)) 254 if (!value || (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10))
257 return ""; 255 return "";
258 return WebInspector.UIString("Value must be non-negative float"); 256 return WebInspector.UIString("Value must be non-negative float");
259 } 257 }
260 258
261 WebInspector.OverridesSupport.NetworkThroughputUnlimitedValue = -1;
262
263 /** @typedef {{id: string, title: string, throughput: number, latency: number}} */
264 WebInspector.OverridesSupport.NetworkConditionsPreset;
265
266 WebInspector.OverridesSupport._touchEventsScriptIdSymbol = Symbol("OverridesSupp ort.touchEventsScriptIdSymbol"); 259 WebInspector.OverridesSupport._touchEventsScriptIdSymbol = Symbol("OverridesSupp ort.touchEventsScriptIdSymbol");
267 260
268 WebInspector.OverridesSupport.prototype = { 261 WebInspector.OverridesSupport.prototype = {
269 /** 262 /**
270 * @return {boolean} 263 * @return {boolean}
271 */ 264 */
272 canEmulate: function() 265 canEmulate: function()
273 { 266 {
274 return !!this._target && this._targetCanEmulate; 267 return !!this._target && this._targetCanEmulate;
275 }, 268 },
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 this._deviceMetricsChangedListenerMuted = true; 377 this._deviceMetricsChangedListenerMuted = true;
385 this._userAgentChangedListenerMuted = true; 378 this._userAgentChangedListenerMuted = true;
386 this.settings.userAgent.set(""); 379 this.settings.userAgent.set("");
387 this.settings.emulateResolution.set(false); 380 this.settings.emulateResolution.set(false);
388 this.settings.deviceScaleFactor.set(0); 381 this.settings.deviceScaleFactor.set(0);
389 this.settings.emulateTouch.set(false); 382 this.settings.emulateTouch.set(false);
390 this.settings.emulateMobile.set(false); 383 this.settings.emulateMobile.set(false);
391 this.settings.overrideDeviceOrientation.set(false); 384 this.settings.overrideDeviceOrientation.set(false);
392 this.settings.overrideGeolocation.set(false); 385 this.settings.overrideGeolocation.set(false);
393 this.settings.overrideCSSMedia.set(false); 386 this.settings.overrideCSSMedia.set(false);
394 this.settings.networkConditions.set({throughput: WebInspector.OverridesS upport.NetworkThroughputUnlimitedValue, latency: 0});
395 delete this._deviceMetricsChangedListenerMuted; 387 delete this._deviceMetricsChangedListenerMuted;
396 delete this._userAgentChangedListenerMuted; 388 delete this._userAgentChangedListenerMuted;
397 389
398 if (this._initialized) { 390 if (this._initialized) {
399 this._deviceMetricsChanged(); 391 this._deviceMetricsChanged();
400 this._userAgentChanged(); 392 this._userAgentChanged();
401 } 393 }
402 }, 394 },
403 395
404 /** 396 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); 439 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this);
448 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); 440 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this);
449 441
450 this.settings._emulationEnabled.addChangeListener(this._emulateTouchEven tsChanged, this); 442 this.settings._emulationEnabled.addChangeListener(this._emulateTouchEven tsChanged, this);
451 this.settings.emulateTouch.addChangeListener(this._emulateTouchEventsCha nged, this); 443 this.settings.emulateTouch.addChangeListener(this._emulateTouchEventsCha nged, this);
452 444
453 this.settings._emulationEnabled.addChangeListener(this._cssMediaChanged, this); 445 this.settings._emulationEnabled.addChangeListener(this._cssMediaChanged, this);
454 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); 446 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this);
455 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); 447 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this);
456 448
457 this.settings._emulationEnabled.addChangeListener(this._networkCondition sChanged, this);
458 this.settings.networkConditions.addChangeListener(this._networkCondition sChanged, this);
459
460 this.settings.javaScriptDisabled.addChangeListener(this._javaScriptDisab ledChanged, this); 449 this.settings.javaScriptDisabled.addChangeListener(this._javaScriptDisab ledChanged, this);
461 this._javaScriptDisabledChanged(); 450 this._javaScriptDisabledChanged();
462 451
463 this.settings._emulationEnabled.addChangeListener(this._showRulersChange d, this); 452 this.settings._emulationEnabled.addChangeListener(this._showRulersChange d, this);
464 WebInspector.moduleSetting("showMetricsRulers").addChangeListener(this._ showRulersChanged, this); 453 WebInspector.moduleSetting("showMetricsRulers").addChangeListener(this._ showRulersChanged, this);
465 this._showRulersChanged(); 454 this._showRulersChanged();
466 455
467 if (this.emulationEnabled()) { 456 if (this.emulationEnabled()) {
468 if (this.settings.overrideDeviceOrientation.get()) 457 if (this.settings.overrideDeviceOrientation.get())
469 this._deviceOrientationChanged(); 458 this._deviceOrientationChanged();
470 459
471 if (this.settings.overrideGeolocation.get()) 460 if (this.settings.overrideGeolocation.get())
472 this._geolocationPositionChanged(); 461 this._geolocationPositionChanged();
473 462
474 if (this.settings.emulateTouch.get()) 463 if (this.settings.emulateTouch.get())
475 this._emulateTouchEventsChanged(); 464 this._emulateTouchEventsChanged();
476 465
477 if (this.settings.overrideCSSMedia.get()) 466 if (this.settings.overrideCSSMedia.get())
478 this._cssMediaChanged(); 467 this._cssMediaChanged();
479 468
480 this._deviceMetricsChanged(); 469 this._deviceMetricsChanged();
481 if (this.settings.emulateResolution.get()) 470 if (this.settings.emulateResolution.get())
482 this._target.emulationAgent().resetScrollAndPageScaleFactor(); 471 this._target.emulationAgent().resetScrollAndPageScaleFactor();
483 472
484 this._userAgentChanged(); 473 this._userAgentChanged();
485
486 if (this.networkThroughputIsLimited())
487 this._networkConditionsChanged();
488 } 474 }
489 }, 475 },
490 476
491 _userAgentChanged: function() 477 _userAgentChanged: function()
492 { 478 {
493 if (this._userAgentChangedListenerMuted) 479 if (this._userAgentChangedListenerMuted)
494 return; 480 return;
495 var userAgent = this.emulationEnabled() ? this.settings.userAgent.get() : ""; 481 var userAgent = this.emulationEnabled() ? this.settings.userAgent.get() : "";
496 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); 482 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent);
497 if (this._userAgent !== userAgent) 483 if (this._userAgent !== userAgent)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 692
707 _cssMediaChanged: function() 693 _cssMediaChanged: function()
708 { 694 {
709 var enabled = this.emulationEnabled() && this.settings.overrideCSSMedia. get(); 695 var enabled = this.emulationEnabled() && this.settings.overrideCSSMedia. get();
710 this._target.emulationAgent().setEmulatedMedia(enabled ? this.settings.e mulatedCSSMedia.get() : ""); 696 this._target.emulationAgent().setEmulatedMedia(enabled ? this.settings.e mulatedCSSMedia.get() : "");
711 var cssModel = WebInspector.CSSStyleModel.fromTarget(this._target); 697 var cssModel = WebInspector.CSSStyleModel.fromTarget(this._target);
712 if (cssModel) 698 if (cssModel)
713 cssModel.mediaQueryResultChanged(); 699 cssModel.mediaQueryResultChanged();
714 }, 700 },
715 701
716 _networkConditionsChanged: function()
717 {
718 if (!this.emulationEnabled() || !this.networkThroughputIsLimited()) {
719 WebInspector.multitargetNetworkManager.emulateNetworkConditions(fals e, 0, 0);
720 } else {
721 var conditions = this.settings.networkConditions.get();
722 var throughput = conditions.throughput;
723 var latency = conditions.latency;
724 var offline = !throughput && !latency;
725 WebInspector.multitargetNetworkManager.emulateNetworkConditions(offl ine, latency, throughput);
726 }
727 },
728
729 _javaScriptDisabledChanged: function() 702 _javaScriptDisabledChanged: function()
730 { 703 {
731 this._target.emulationAgent().setScriptExecutionDisabled(this.settings.j avaScriptDisabled.get()); 704 this._target.emulationAgent().setScriptExecutionDisabled(this.settings.j avaScriptDisabled.get());
732 }, 705 },
733 706
734 _pageResizerActive: function() 707 _pageResizerActive: function()
735 { 708 {
736 return this._pageResizer && this.emulationEnabled(); 709 return this._pageResizer && this.emulationEnabled();
737 }, 710 },
738 711
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 }, 766 },
794 767
795 swapDimensions: function() 768 swapDimensions: function()
796 { 769 {
797 var width = WebInspector.overridesSupport.settings.deviceWidth.get(); 770 var width = WebInspector.overridesSupport.settings.deviceWidth.get();
798 var height = WebInspector.overridesSupport.settings.deviceHeight.get(); 771 var height = WebInspector.overridesSupport.settings.deviceHeight.get();
799 WebInspector.overridesSupport.settings.deviceWidth.set(height); 772 WebInspector.overridesSupport.settings.deviceWidth.set(height);
800 WebInspector.overridesSupport.settings.deviceHeight.set(width); 773 WebInspector.overridesSupport.settings.deviceHeight.set(width);
801 }, 774 },
802 775
803 /**
804 * @return {boolean}
805 */
806 networkThroughputIsLimited: function()
807 {
808 var conditions = this.settings.networkConditions.get();
809 return conditions.throughput !== WebInspector.OverridesSupport.NetworkTh roughputUnlimitedValue;
810 },
811
812 __proto__: WebInspector.Object.prototype 776 __proto__: WebInspector.Object.prototype
813 } 777 }
814 778
815 779
816 /** 780 /**
817 * @type {!WebInspector.OverridesSupport} 781 * @type {!WebInspector.OverridesSupport}
818 */ 782 */
819 WebInspector.overridesSupport; 783 WebInspector.overridesSupport;
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/emulation/OverridesUI.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698