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

Side by Side Diff: Source/core/inspector/InspectorPageAgent.cpp

Issue 1003243002: [DevTools] Cleanup after reversing emulation flow. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 5 years, 9 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/core/inspector/InspectorPageAgent.h ('k') | Source/devtools/protocol.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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 #include "wtf/Vector.h" 83 #include "wtf/Vector.h"
84 #include "wtf/text/Base64.h" 84 #include "wtf/text/Base64.h"
85 #include "wtf/text/TextEncoding.h" 85 #include "wtf/text/TextEncoding.h"
86 86
87 namespace blink { 87 namespace blink {
88 88
89 namespace PageAgentState { 89 namespace PageAgentState {
90 static const char pageAgentEnabled[] = "pageAgentEnabled"; 90 static const char pageAgentEnabled[] = "pageAgentEnabled";
91 static const char pageAgentScriptExecutionDisabled[] = "pageAgentScriptExecution Disabled"; 91 static const char pageAgentScriptExecutionDisabled[] = "pageAgentScriptExecution Disabled";
92 static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvalua teOnLoad"; 92 static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvalua teOnLoad";
93 static const char deviceMetricsOverrideEnabled[] = "deviceMetricsOverrideEnabled ";
94 static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride ";
95 static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverri de";
96 static const char pageAgentDeviceScaleFactorOverride[] = "pageAgentDeviceScaleFa ctorOverride";
97 static const char pageAgentEmulateMobile[] = "pageAgentEmulateMobile";
98 static const char pageAgentFitWindow[] = "pageAgentFitWindow";
99 static const char deviceScale[] = "deviceScale";
100 static const char deviceOffsetX[] = "deviceOffsetX";
101 static const char deviceOffsetY[] = "deviceOffsetY";
102 static const char pageAgentShowFPSCounter[] = "pageAgentShowFPSCounter"; 93 static const char pageAgentShowFPSCounter[] = "pageAgentShowFPSCounter";
103 static const char pageAgentContinuousPaintingEnabled[] = "pageAgentContinuousPai ntingEnabled"; 94 static const char pageAgentContinuousPaintingEnabled[] = "pageAgentContinuousPai ntingEnabled";
104 static const char pageAgentShowPaintRects[] = "pageAgentShowPaintRects"; 95 static const char pageAgentShowPaintRects[] = "pageAgentShowPaintRects";
105 static const char pageAgentShowDebugBorders[] = "pageAgentShowDebugBorders"; 96 static const char pageAgentShowDebugBorders[] = "pageAgentShowDebugBorders";
106 static const char pageAgentShowScrollBottleneckRects[] = "pageAgentShowScrollBot tleneckRects"; 97 static const char pageAgentShowScrollBottleneckRects[] = "pageAgentShowScrollBot tleneckRects";
107 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; 98 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled";
108 static const char pageAgentEmulatedMedia[] = "pageAgentEmulatedMedia"; 99 static const char pageAgentEmulatedMedia[] = "pageAgentEmulatedMedia";
109 static const char showSizeOnResize[] = "showSizeOnResize"; 100 static const char showSizeOnResize[] = "showSizeOnResize";
110 static const char showGridOnResize[] = "showGridOnResize"; 101 static const char showGridOnResize[] = "showGridOnResize";
111 static const char screencastEnabled[] = "screencastEnabled"; 102 static const char screencastEnabled[] = "screencastEnabled";
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 setShowDebugBorders(0, showDebugBorders); 420 setShowDebugBorders(0, showDebugBorders);
430 bool showFPSCounter = m_state->getBoolean(PageAgentState::pageAgentShowF PSCounter); 421 bool showFPSCounter = m_state->getBoolean(PageAgentState::pageAgentShowF PSCounter);
431 setShowFPSCounter(0, showFPSCounter); 422 setShowFPSCounter(0, showFPSCounter);
432 String emulatedMedia = m_state->getString(PageAgentState::pageAgentEmula tedMedia); 423 String emulatedMedia = m_state->getString(PageAgentState::pageAgentEmula tedMedia);
433 setEmulatedMedia(0, emulatedMedia); 424 setEmulatedMedia(0, emulatedMedia);
434 bool continuousPaintingEnabled = m_state->getBoolean(PageAgentState::pag eAgentContinuousPaintingEnabled); 425 bool continuousPaintingEnabled = m_state->getBoolean(PageAgentState::pag eAgentContinuousPaintingEnabled);
435 setContinuousPaintingEnabled(0, continuousPaintingEnabled); 426 setContinuousPaintingEnabled(0, continuousPaintingEnabled);
436 bool showScrollBottleneckRects = m_state->getBoolean(PageAgentState::pag eAgentShowScrollBottleneckRects); 427 bool showScrollBottleneckRects = m_state->getBoolean(PageAgentState::pag eAgentShowScrollBottleneckRects);
437 setShowScrollBottleneckRects(0, showScrollBottleneckRects); 428 setShowScrollBottleneckRects(0, showScrollBottleneckRects);
438 429
439 updateViewMetricsFromState();
440 updateTouchEventEmulationInPage(m_state->getBoolean(PageAgentState::touc hEventEmulationEnabled)); 430 updateTouchEventEmulationInPage(m_state->getBoolean(PageAgentState::touc hEventEmulationEnabled));
441 } 431 }
442 } 432 }
443 433
444 void InspectorPageAgent::enable(ErrorString*) 434 void InspectorPageAgent::enable(ErrorString*)
445 { 435 {
446 m_enabled = true; 436 m_enabled = true;
447 m_state->setBoolean(PageAgentState::pageAgentEnabled, true); 437 m_state->setBoolean(PageAgentState::pageAgentEnabled, true);
448 m_instrumentingAgents->setInspectorPageAgent(this); 438 m_instrumentingAgents->setInspectorPageAgent(this);
449 if (m_inspectorResourceContentLoader) 439 if (m_inspectorResourceContentLoader)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 setShowViewportSizeOnResize(0, false, 0); 471 setShowViewportSizeOnResize(0, false, 0);
482 setScriptExecutionDisabled(nullptr, false); 472 setScriptExecutionDisabled(nullptr, false);
483 stopScreencast(0); 473 stopScreencast(0);
484 474
485 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled)) { 475 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled)) {
486 updateTouchEventEmulationInPage(false); 476 updateTouchEventEmulationInPage(false);
487 m_state->setBoolean(PageAgentState::touchEventEmulationEnabled, false); 477 m_state->setBoolean(PageAgentState::touchEventEmulationEnabled, false);
488 } 478 }
489 479
490 finishReload(); 480 finishReload();
491
492 if (!deviceMetricsChanged(false, 0, 0, 0, false, false, 1, 0, 0))
493 return;
494
495 // When disabling the agent, reset the override values if necessary.
496 updateViewMetrics(false, 0, 0, 0, false, false, 1, 0, 0);
497 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0);
498 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0);
499 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, 0);
500 m_state->setBoolean(PageAgentState::pageAgentEmulateMobile, false);
501 m_state->setBoolean(PageAgentState::pageAgentFitWindow, false);
502 m_state->setDouble(PageAgentState::deviceScale, 1);
503 m_state->setDouble(PageAgentState::deviceOffsetX, 0);
504 m_state->setDouble(PageAgentState::deviceOffsetY, 0);
505 } 481 }
506 482
507 void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& s ource, String* identifier) 483 void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& s ource, String* identifier)
508 { 484 {
509 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad); 485 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad);
510 if (!scripts) { 486 if (!scripts) {
511 scripts = JSONObject::create(); 487 scripts = JSONObject::create();
512 m_state->setObject(PageAgentState::pageAgentScriptsToEvaluateOnLoad, scr ipts); 488 m_state->setObject(PageAgentState::pageAgentScriptsToEvaluateOnLoad, scr ipts);
513 } 489 }
514 // Assure we don't override existing ids -- m_lastScriptIdentifier could get out of sync WRT actual 490 // Assure we don't override existing ids -- m_lastScriptIdentifier could get out of sync WRT actual
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 return; 743 return;
768 744
769 Document* document = frame->document(); 745 Document* document = frame->document();
770 if (!document) { 746 if (!document) {
771 *errorString = "No Document instance to set HTML for"; 747 *errorString = "No Document instance to set HTML for";
772 return; 748 return;
773 } 749 }
774 DOMPatchSupport::patchDocument(*document, html); 750 DOMPatchSupport::patchDocument(*document, html);
775 } 751 }
776 752
777 void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, int width, int height, double deviceScaleFactor, bool mobile, bool fitWindow, const double* optionalScale, const double* optionalOffsetX, const double* optionalOffs etY)
778 {
779 const static long maxDimension = 10000000;
780 const static double maxScale = 10;
781
782 double scale = optionalScale ? *optionalScale : 1;
783 double offsetX = optionalOffsetX ? *optionalOffsetX : 0;
784 double offsetY = optionalOffsetY ? *optionalOffsetY : 0;
785
786 if (width < 0 || height < 0 || width > maxDimension || height > maxDimension ) {
787 *errorString = "Width and height values must be positive, not greater th an " + String::number(maxDimension);
788 return;
789 }
790
791 if (deviceScaleFactor < 0) {
792 *errorString = "deviceScaleFactor must be non-negative";
793 return;
794 }
795
796 if (scale <= 0 || scale > maxScale) {
797 *errorString = "scale must be positive, not greater than " + String::num ber(maxScale);
798 return;
799 }
800
801 Settings& settings = m_page->settings();
802 if (!settings.acceleratedCompositingEnabled()) {
803 if (errorString)
804 *errorString = "Compositing mode is not supported";
805 return;
806 }
807
808 if (!deviceMetricsChanged(true, width, height, deviceScaleFactor, mobile, fi tWindow, scale, offsetX, offsetY))
809 return;
810
811 m_state->setBoolean(PageAgentState::deviceMetricsOverrideEnabled, true);
812 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width);
813 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height);
814 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, devic eScaleFactor);
815 m_state->setBoolean(PageAgentState::pageAgentEmulateMobile, mobile);
816 m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow);
817 m_state->setDouble(PageAgentState::deviceScale, scale);
818 m_state->setDouble(PageAgentState::deviceOffsetX, offsetX);
819 m_state->setDouble(PageAgentState::deviceOffsetY, offsetY);
820 updateViewMetricsFromState();
821 }
822
823 void InspectorPageAgent::clearDeviceMetricsOverride(ErrorString*)
824 {
825 if (m_state->getBoolean(PageAgentState::deviceMetricsOverrideEnabled)) {
826 m_state->setBoolean(PageAgentState::deviceMetricsOverrideEnabled, false) ;
827 updateViewMetricsFromState();
828 }
829 }
830
831 void InspectorPageAgent::resetScrollAndPageScaleFactor(ErrorString*) 753 void InspectorPageAgent::resetScrollAndPageScaleFactor(ErrorString*)
832 { 754 {
833 m_client->resetScrollAndPageScaleFactor(); 755 m_client->resetScrollAndPageScaleFactor();
834 } 756 }
835 757
836 void InspectorPageAgent::setPageScaleFactor(ErrorString*, double pageScaleFactor ) 758 void InspectorPageAgent::setPageScaleFactor(ErrorString*, double pageScaleFactor )
837 { 759 {
838 m_client->setPageScaleFactor(static_cast<float>(pageScaleFactor)); 760 m_client->setPageScaleFactor(static_cast<float>(pageScaleFactor));
839 } 761 }
840 762
841 bool InspectorPageAgent::deviceMetricsChanged(bool enabled, int width, int heigh t, double deviceScaleFactor, bool mobile, bool fitWindow, double scale, double o ffsetX, double offsetY)
842 {
843 bool currentEnabled = m_state->getBoolean(PageAgentState::deviceMetricsOverr ideEnabled);
844 // These two always fit an int.
845 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride));
846 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAg entScreenHeightOverride));
847 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pageAge ntDeviceScaleFactorOverride, 0);
848 bool currentMobile = m_state->getBoolean(PageAgentState::pageAgentEmulateMob ile);
849 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWind ow);
850 double currentScale = m_state->getDouble(PageAgentState::deviceScale, 1);
851 double currentOffsetX = m_state->getDouble(PageAgentState::deviceOffsetX, 0) ;
852 double currentOffsetY = m_state->getDouble(PageAgentState::deviceOffsetY, 0) ;
853
854 return enabled != currentEnabled
855 || width != currentWidth
856 || height != currentHeight
857 || deviceScaleFactor != currentDeviceScaleFactor
858 || mobile != currentMobile
859 || fitWindow != currentFitWindow
860 || scale != currentScale
861 || offsetX != currentOffsetX
862 || offsetY != currentOffsetY;
863 }
864
865 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show) 763 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show)
866 { 764 {
867 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show); 765 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show);
868 m_client->setShowPaintRects(show); 766 m_client->setShowPaintRects(show);
869 767
870 if (!show && inspectedFrame() && inspectedFrame()->isMainFrame() && inspecte dFrame()->view()) 768 if (!show && inspectedFrame() && inspectedFrame()->isMainFrame() && inspecte dFrame()->view())
871 inspectedFrame()->view()->invalidate(); 769 inspectedFrame()->view()->invalidate();
872 } 770 }
873 771
874 void InspectorPageAgent::setShowDebugBorders(ErrorString* errorString, bool show ) 772 void InspectorPageAgent::setShowDebugBorders(ErrorString* errorString, bool show )
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 continue; 1129 continue;
1232 if (!childrenArray) { 1130 if (!childrenArray) {
1233 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create(); 1131 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create();
1234 result->setChildFrames(childrenArray); 1132 result->setChildFrames(childrenArray);
1235 } 1133 }
1236 childrenArray->addItem(buildObjectForFrameTree(toLocalFrame(child))); 1134 childrenArray->addItem(buildObjectForFrameTree(toLocalFrame(child)));
1237 } 1135 }
1238 return result; 1136 return result;
1239 } 1137 }
1240 1138
1241 void InspectorPageAgent::updateViewMetricsFromState()
1242 {
1243 bool enabled = m_state->getBoolean(PageAgentState::deviceMetricsOverrideEnab led);
1244 int width = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScree nWidthOverride));
1245 int height = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScre enHeightOverride));
1246 bool mobile = m_state->getBoolean(PageAgentState::pageAgentEmulateMobile);
1247 double deviceScaleFactor = m_state->getDouble(PageAgentState::pageAgentDevic eScaleFactorOverride);
1248 bool fitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWindow);
1249 double scale = m_state->getDouble(PageAgentState::deviceScale, 1);
1250 double offsetX = m_state->getDouble(PageAgentState::deviceOffsetX, 0);
1251 double offsetY = m_state->getDouble(PageAgentState::deviceOffsetY, 0);
1252 updateViewMetrics(enabled, width, height, deviceScaleFactor, mobile, fitWind ow, scale, offsetX, offsetY);
1253 }
1254
1255 void InspectorPageAgent::updateViewMetrics(bool enabled, int width, int height, double deviceScaleFactor, bool mobile, bool fitWindow, double scale, double offs etX, double offsetY)
1256 {
1257 if (enabled && !m_page->settings().acceleratedCompositingEnabled())
1258 return;
1259 if (!inspectedFrame()->isMainFrame())
1260 return;
1261
1262 if (enabled)
1263 m_client->setDeviceMetricsOverride(width, height, static_cast<float>(dev iceScaleFactor), mobile, fitWindow, static_cast<float>(scale), static_cast<float >(offsetX), static_cast<float>(offsetY));
1264 else
1265 m_client->clearDeviceMetricsOverride();
1266 }
1267
1268 void InspectorPageAgent::updateTouchEventEmulationInPage(bool enabled) 1139 void InspectorPageAgent::updateTouchEventEmulationInPage(bool enabled)
1269 { 1140 {
1270 m_client->setTouchEventEmulationEnabled(enabled); 1141 m_client->setTouchEventEmulationEnabled(enabled);
1271 } 1142 }
1272 1143
1273 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled, co nst String* configuration) 1144 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled, co nst String* configuration)
1274 { 1145 {
1275 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed) 1146 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed)
1276 return; 1147 return;
1277 1148
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 visitor->trace(m_page); 1210 visitor->trace(m_page);
1340 visitor->trace(m_injectedScriptManager); 1211 visitor->trace(m_injectedScriptManager);
1341 visitor->trace(m_debuggerAgent); 1212 visitor->trace(m_debuggerAgent);
1342 visitor->trace(m_cssAgent); 1213 visitor->trace(m_cssAgent);
1343 visitor->trace(m_overlay); 1214 visitor->trace(m_overlay);
1344 visitor->trace(m_inspectorResourceContentLoader); 1215 visitor->trace(m_inspectorResourceContentLoader);
1345 InspectorBaseAgent::trace(visitor); 1216 InspectorBaseAgent::trace(visitor);
1346 } 1217 }
1347 1218
1348 } // namespace blink 1219 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/devtools/protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698