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

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

Issue 319143002: DevTools: introduce WebInspector.Throttler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/scripts/frontend_modules.json » ('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 24 matching lines...) Expand all
35 * @param {boolean} responsiveDesignAvailable 35 * @param {boolean} responsiveDesignAvailable
36 */ 36 */
37 WebInspector.OverridesSupport = function(responsiveDesignAvailable) 37 WebInspector.OverridesSupport = function(responsiveDesignAvailable)
38 { 38 {
39 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this); 39 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this);
40 this._overrideDeviceResolution = false; 40 this._overrideDeviceResolution = false;
41 this._emulateViewportEnabled = false; 41 this._emulateViewportEnabled = false;
42 this._userAgent = ""; 42 this._userAgent = "";
43 this._pageResizer = null; 43 this._pageResizer = null;
44 this._initialized = false; 44 this._initialized = false;
45 this._deviceMetricsThrottler = new WebInspector.Throttler(0);
45 WebInspector.targetManager.observeTargets(this); 46 WebInspector.targetManager.observeTargets(this);
46 this._responsiveDesignAvailable = responsiveDesignAvailable; 47 this._responsiveDesignAvailable = responsiveDesignAvailable;
47 } 48 }
48 49
49 WebInspector.OverridesSupport.Events = { 50 WebInspector.OverridesSupport.Events = {
50 OverridesWarningUpdated: "OverridesWarningUpdated", 51 OverridesWarningUpdated: "OverridesWarningUpdated",
51 HasActiveOverridesChanged: "HasActiveOverridesChanged", 52 HasActiveOverridesChanged: "HasActiveOverridesChanged",
52 } 53 }
53 54
54 /** 55 /**
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 _deviceMetricsChanged: function() 579 _deviceMetricsChanged: function()
579 { 580 {
580 this._showRulersChanged(); 581 this._showRulersChanged();
581 582
582 if (this._deviceMetricsChangedListenerMuted) 583 if (this._deviceMetricsChangedListenerMuted)
583 return; 584 return;
584 var responsiveDesignAvailableAndDisabled = this._responsiveDesignAvailab le && (!WebInspector.settings.responsiveDesignMode.get() || !this._pageResizer); 585 var responsiveDesignAvailableAndDisabled = this._responsiveDesignAvailab le && (!WebInspector.settings.responsiveDesignMode.get() || !this._pageResizer);
585 var overrideDeviceResolution = this.settings.overrideDeviceResolution.ge t(); 586 var overrideDeviceResolution = this.settings.overrideDeviceResolution.ge t();
586 var emulationEnabled = overrideDeviceResolution || this.settings.emulate Viewport.get(); 587 var emulationEnabled = overrideDeviceResolution || this.settings.emulate Viewport.get();
587 if (responsiveDesignAvailableAndDisabled || !emulationEnabled) { 588 if (responsiveDesignAvailableAndDisabled || !emulationEnabled) {
588 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this)); 589 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this, new Func tion()));
vsevik 2014/06/06 16:14:45 I think we use function() {} usually.
lushnikov 2014/06/06 16:38:15 Not relevant any more.
589 if (this._pageResizer && !emulationEnabled) 590 if (this._pageResizer && !emulationEnabled)
590 this._pageResizer.update(0, 0, 0); 591 this._pageResizer.update(0, 0, 0);
591 this.maybeHasActiveOverridesChanged(); 592 this.maybeHasActiveOverridesChanged();
592 return; 593 return;
593 } 594 }
594 595
595 var dipWidth = overrideDeviceResolution ? this.settings.deviceWidth.get( ) : 0; 596 var dipWidth = overrideDeviceResolution ? this.settings.deviceWidth.get( ) : 0;
596 var dipHeight = overrideDeviceResolution ? this.settings.deviceHeight.ge t() : 0; 597 var dipHeight = overrideDeviceResolution ? this.settings.deviceHeight.ge t() : 0;
597 598
598 // Disable override without checks. 599 // Disable override without checks.
599 if (this.isInspectingDevice()) 600 if (this.isInspectingDevice())
600 return; 601 return;
601 602
602 var overrideWidth = dipWidth; 603 var overrideWidth = dipWidth;
603 var overrideHeight = dipHeight; 604 var overrideHeight = dipHeight;
604 if (this._pageResizer) { 605 if (this._pageResizer) {
605 var available = this._pageResizer.availableDipSize(); 606 var available = this._pageResizer.availableDipSize();
606 if (available.width >= dipWidth && available.height >= dipHeight) { 607 if (available.width >= dipWidth && available.height >= dipHeight) {
607 this._pageResizer.update(dipWidth, dipHeight, 0); 608 this._pageResizer.update(dipWidth, dipHeight, 0);
608 // When we have enough space, no page size override is required. This will speed things up and remove lag. 609 // When we have enough space, no page size override is required. This will speed things up and remove lag.
609 overrideWidth = 0; 610 overrideWidth = 0;
610 overrideHeight = 0; 611 overrideHeight = 0;
611 } else { 612 } else {
612 this._pageResizer.update(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0); 613 this._pageResizer.update(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0);
613 } 614 }
614 } 615 }
615 616
616 // Do not emulate resolution more often than 10Hz.
617 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1;
618 if (overrideWidth || overrideHeight) 617 if (overrideWidth || overrideHeight)
619 setTimeout(setDeviceMetricsOverride.bind(this), 100); 618 this._deviceMetricsThrottler.schedule(setDeviceMetricsOverride.bind( this));
620 else 619 else
621 setDeviceMetricsOverride.call(this); 620 setDeviceMetricsOverride.call(this, new Function());
622 621
623 /** 622 /**
623 * @param {function()} finishCallback
624 * @this {WebInspector.OverridesSupport} 624 * @this {WebInspector.OverridesSupport}
625 */ 625 */
626 function setDeviceMetricsOverride() 626 function setDeviceMetricsOverride(finishCallback)
627 { 627 {
628 // Drop heavy intermediate commands.
629 this._setDeviceMetricsTimers--;
630 var isExpensive = overrideWidth || overrideHeight;
631 if (isExpensive && this._setDeviceMetricsTimers) {
632 var commandThreshold = 100;
633 var time = window.performance.now();
634 if (time - this._lastExpensivePageAgentCommandTime < commandThre shold)
635 return;
636 this._lastExpensivePageAgentCommandTime = time;
637 }
638
639 PageAgent.setDeviceMetricsOverride( 628 PageAgent.setDeviceMetricsOverride(
640 overrideWidth, overrideHeight, this.settings.deviceScaleFactor.g et(), 629 overrideWidth, overrideHeight, this.settings.deviceScaleFactor.g et(),
641 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(), 630 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(),
642 this.settings.deviceTextAutosizing.get(), this._fontScaleFactor( overrideWidth || dipWidth, overrideHeight || dipHeight), 631 this.settings.deviceTextAutosizing.get(), this._fontScaleFactor( overrideWidth || dipWidth, overrideHeight || dipHeight),
643 apiCallback.bind(this)); 632 apiCallback.bind(this, finishCallback));
644 } 633 }
645 634
646 this.maybeHasActiveOverridesChanged(); 635 this.maybeHasActiveOverridesChanged();
647 636
648 /** 637 /**
638 * @param {function()} finishCallback
649 * @param {?Protocol.Error} error 639 * @param {?Protocol.Error} error
650 * @this {WebInspector.OverridesSupport} 640 * @this {WebInspector.OverridesSupport}
651 */ 641 */
652 function apiCallback(error) 642 function apiCallback(finishCallback, error)
653 { 643 {
654 if (error) { 644 if (error) {
655 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page.")); 645 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page."));
656 this._deviceMetricsOverrideAppliedForTest(); 646 this._deviceMetricsOverrideAppliedForTest();
647 finishCallback();
657 return; 648 return;
658 } 649 }
659 650
660 var overrideDeviceResolution = this.settings.overrideDeviceResolutio n.get(); 651 var overrideDeviceResolution = this.settings.overrideDeviceResolutio n.get();
661 var viewportEnabled = this.settings.emulateViewport.get(); 652 var viewportEnabled = this.settings.emulateViewport.get();
662 if (this._overrideDeviceResolution !== overrideDeviceResolution || t his._emulateViewportEnabled !== viewportEnabled) 653 if (this._overrideDeviceResolution !== overrideDeviceResolution || t his._emulateViewportEnabled !== viewportEnabled)
663 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y ou might need to reload the page for proper user agent spoofing and viewport ren dering.")); 654 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Y ou might need to reload the page for proper user agent spoofing and viewport ren dering."));
664 this._overrideDeviceResolution = overrideDeviceResolution; 655 this._overrideDeviceResolution = overrideDeviceResolution;
665 this._emulateViewportEnabled = viewportEnabled; 656 this._emulateViewportEnabled = viewportEnabled;
666 this._deviceMetricsOverrideAppliedForTest(); 657 this._deviceMetricsOverrideAppliedForTest();
658 finishCallback();
667 } 659 }
668 }, 660 },
669 661
670 _deviceMetricsOverrideAppliedForTest: function() 662 _deviceMetricsOverrideAppliedForTest: function()
671 { 663 {
672 // Used for sniffing in tests. 664 // Used for sniffing in tests.
673 }, 665 },
674 666
675 _geolocationPositionChanged: function() 667 _geolocationPositionChanged: function()
676 { 668 {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 }, 948 },
957 949
958 __proto__: WebInspector.Object.prototype 950 __proto__: WebInspector.Object.prototype
959 } 951 }
960 952
961 953
962 /** 954 /**
963 * @type {!WebInspector.OverridesSupport} 955 * @type {!WebInspector.OverridesSupport}
964 */ 956 */
965 WebInspector.overridesSupport; 957 WebInspector.overridesSupport;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/scripts/frontend_modules.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698