| 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 #include "web/InspectorEmulationAgent.h" | 5 #include "web/InspectorEmulationAgent.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameHost.h" | 7 #include "core/frame/FrameHost.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/page/Page.h" | 10 #include "core/page/Page.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 this, | 45 this, |
| 46 &InspectorEmulationAgent::virtualTimeBudgetExpired)) {} | 46 &InspectorEmulationAgent::virtualTimeBudgetExpired)) {} |
| 47 | 47 |
| 48 InspectorEmulationAgent::~InspectorEmulationAgent() {} | 48 InspectorEmulationAgent::~InspectorEmulationAgent() {} |
| 49 | 49 |
| 50 WebViewImpl* InspectorEmulationAgent::webViewImpl() { | 50 WebViewImpl* InspectorEmulationAgent::webViewImpl() { |
| 51 return m_webLocalFrameImpl->viewImpl(); | 51 return m_webLocalFrameImpl->viewImpl(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void InspectorEmulationAgent::restore() { | 54 void InspectorEmulationAgent::restore() { |
| 55 ErrorString error; | 55 setScriptExecutionDisabled(m_state->booleanProperty( |
| 56 setScriptExecutionDisabled( | 56 EmulationAgentState::scriptExecutionDisabled, false)); |
| 57 &error, m_state->booleanProperty( | |
| 58 EmulationAgentState::scriptExecutionDisabled, false)); | |
| 59 setTouchEmulationEnabled( | 57 setTouchEmulationEnabled( |
| 60 &error, m_state->booleanProperty( | 58 m_state->booleanProperty(EmulationAgentState::touchEventEmulationEnabled, |
| 61 EmulationAgentState::touchEventEmulationEnabled, false), | 59 false), |
| 62 protocol::Maybe<String>()); | 60 protocol::Maybe<String>()); |
| 63 String emulatedMedia; | 61 String emulatedMedia; |
| 64 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); | 62 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); |
| 65 setEmulatedMedia(&error, emulatedMedia); | 63 setEmulatedMedia(emulatedMedia); |
| 66 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, | 64 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, |
| 67 false)) { | 65 false)) { |
| 68 forceViewport( | 66 forceViewport( |
| 69 &error, | 67 |
| 70 m_state->doubleProperty(EmulationAgentState::forcedViewportX, 0), | 68 m_state->doubleProperty(EmulationAgentState::forcedViewportX, 0), |
| 71 m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0), | 69 m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0), |
| 72 m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1)); | 70 m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1)); |
| 73 } | 71 } |
| 74 } | 72 } |
| 75 | 73 |
| 76 void InspectorEmulationAgent::disable(ErrorString*) { | 74 Response InspectorEmulationAgent::disable() { |
| 77 ErrorString error; | 75 setScriptExecutionDisabled(false); |
| 78 setScriptExecutionDisabled(&error, false); | 76 setTouchEmulationEnabled(false, Maybe<String>()); |
| 79 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); | 77 setEmulatedMedia(String()); |
| 80 setEmulatedMedia(&error, String()); | 78 setCPUThrottlingRate(1); |
| 81 setCPUThrottlingRate(&error, 1); | 79 resetViewport(); |
| 82 resetViewport(&error); | 80 return Response::OK(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 void InspectorEmulationAgent::forceViewport(ErrorString* error, | 83 Response InspectorEmulationAgent::forceViewport(double x, |
| 86 double x, | 84 double y, |
| 87 double y, | 85 double scale) { |
| 88 double scale) { | 86 if (x < 0 || y < 0) |
| 89 if (x < 0 || y < 0) { | 87 return Response::Error("Coordinates must be non-negative"); |
| 90 *error = "Coordinates must be non-negative"; | |
| 91 return; | |
| 92 } | |
| 93 | 88 |
| 94 if (scale <= 0) { | 89 if (scale <= 0) |
| 95 *error = "Scale must be positive"; | 90 return Response::Error("Scale must be positive"); |
| 96 return; | |
| 97 } | |
| 98 | 91 |
| 99 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, true); | 92 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, true); |
| 100 m_state->setDouble(EmulationAgentState::forcedViewportX, x); | 93 m_state->setDouble(EmulationAgentState::forcedViewportX, x); |
| 101 m_state->setDouble(EmulationAgentState::forcedViewportY, y); | 94 m_state->setDouble(EmulationAgentState::forcedViewportY, y); |
| 102 m_state->setDouble(EmulationAgentState::forcedViewportScale, scale); | 95 m_state->setDouble(EmulationAgentState::forcedViewportScale, scale); |
| 103 | 96 |
| 104 webViewImpl()->devToolsEmulator()->forceViewport(WebFloatPoint(x, y), scale); | 97 webViewImpl()->devToolsEmulator()->forceViewport(WebFloatPoint(x, y), scale); |
| 98 return Response::OK(); |
| 105 } | 99 } |
| 106 | 100 |
| 107 void InspectorEmulationAgent::resetViewport(ErrorString*) { | 101 Response InspectorEmulationAgent::resetViewport() { |
| 108 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false); | 102 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false); |
| 109 webViewImpl()->devToolsEmulator()->resetViewport(); | 103 webViewImpl()->devToolsEmulator()->resetViewport(); |
| 104 return Response::OK(); |
| 110 } | 105 } |
| 111 | 106 |
| 112 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) { | 107 Response InspectorEmulationAgent::resetPageScaleFactor() { |
| 113 webViewImpl()->resetScaleStateImmediately(); | 108 webViewImpl()->resetScaleStateImmediately(); |
| 109 return Response::OK(); |
| 114 } | 110 } |
| 115 | 111 |
| 116 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, | 112 Response InspectorEmulationAgent::setPageScaleFactor(double pageScaleFactor) { |
| 117 double pageScaleFactor) { | |
| 118 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); | 113 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); |
| 114 return Response::OK(); |
| 119 } | 115 } |
| 120 | 116 |
| 121 void InspectorEmulationAgent::setScriptExecutionDisabled(ErrorString*, | 117 Response InspectorEmulationAgent::setScriptExecutionDisabled(bool value) { |
| 122 bool value) { | |
| 123 m_state->setBoolean(EmulationAgentState::scriptExecutionDisabled, value); | 118 m_state->setBoolean(EmulationAgentState::scriptExecutionDisabled, value); |
| 124 webViewImpl()->devToolsEmulator()->setScriptExecutionDisabled(value); | 119 webViewImpl()->devToolsEmulator()->setScriptExecutionDisabled(value); |
| 120 return Response::OK(); |
| 125 } | 121 } |
| 126 | 122 |
| 127 void InspectorEmulationAgent::setTouchEmulationEnabled( | 123 Response InspectorEmulationAgent::setTouchEmulationEnabled( |
| 128 ErrorString*, | |
| 129 bool enabled, | 124 bool enabled, |
| 130 const Maybe<String>& configuration) { | 125 Maybe<String> configuration) { |
| 131 m_state->setBoolean(EmulationAgentState::touchEventEmulationEnabled, enabled); | 126 m_state->setBoolean(EmulationAgentState::touchEventEmulationEnabled, enabled); |
| 132 webViewImpl()->devToolsEmulator()->setTouchEventEmulationEnabled(enabled); | 127 webViewImpl()->devToolsEmulator()->setTouchEventEmulationEnabled(enabled); |
| 128 return Response::OK(); |
| 133 } | 129 } |
| 134 | 130 |
| 135 void InspectorEmulationAgent::setEmulatedMedia(ErrorString*, | 131 Response InspectorEmulationAgent::setEmulatedMedia(const String& media) { |
| 136 const String& media) { | |
| 137 m_state->setString(EmulationAgentState::emulatedMedia, media); | 132 m_state->setString(EmulationAgentState::emulatedMedia, media); |
| 138 webViewImpl()->page()->settings().setMediaTypeOverride(media); | 133 webViewImpl()->page()->settings().setMediaTypeOverride(media); |
| 134 return Response::OK(); |
| 139 } | 135 } |
| 140 | 136 |
| 141 void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, | 137 Response InspectorEmulationAgent::setCPUThrottlingRate(double throttlingRate) { |
| 142 double throttlingRate) { | |
| 143 m_client->setCPUThrottlingRate(throttlingRate); | 138 m_client->setCPUThrottlingRate(throttlingRate); |
| 139 return Response::OK(); |
| 144 } | 140 } |
| 145 | 141 |
| 146 void InspectorEmulationAgent::setVirtualTimePolicy( | 142 Response InspectorEmulationAgent::setVirtualTimePolicy(const String& policy, |
| 147 ErrorString*, | 143 Maybe<int> budget) { |
| 148 const String& in_policy, | 144 if (protocol::Emulation::VirtualTimePolicyEnum::Advance == policy) { |
| 149 const Maybe<int>& in_budget) { | |
| 150 if (protocol::Emulation::VirtualTimePolicyEnum::Advance == in_policy) { | |
| 151 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 145 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 152 WebViewScheduler::VirtualTimePolicy::ADVANCE); | 146 WebViewScheduler::VirtualTimePolicy::ADVANCE); |
| 153 } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == in_policy) { | 147 } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == policy) { |
| 154 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 148 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 155 WebViewScheduler::VirtualTimePolicy::PAUSE); | 149 WebViewScheduler::VirtualTimePolicy::PAUSE); |
| 156 } else if (protocol::Emulation::VirtualTimePolicyEnum:: | 150 } else if (protocol::Emulation::VirtualTimePolicyEnum:: |
| 157 PauseIfNetworkFetchesPending == in_policy) { | 151 PauseIfNetworkFetchesPending == policy) { |
| 158 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 152 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 159 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); | 153 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); |
| 160 } | 154 } |
| 161 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); | 155 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| 162 | 156 |
| 163 if (in_budget.isJust()) { | 157 if (budget.isJust()) { |
| 164 WebTaskRunner* taskRunner = | 158 WebTaskRunner* taskRunner = |
| 165 Platform::current()->currentThread()->getWebTaskRunner(); | 159 Platform::current()->currentThread()->getWebTaskRunner(); |
| 166 long long delayMillis = static_cast<long long>(in_budget.fromJust()); | 160 long long delayMillis = static_cast<long long>(budget.fromJust()); |
| 167 taskRunner->postDelayedTask( | 161 taskRunner->postDelayedTask( |
| 168 BLINK_FROM_HERE, m_virtualTimeBudgetExpiredTask->cancelAndCreate(), | 162 BLINK_FROM_HERE, m_virtualTimeBudgetExpiredTask->cancelAndCreate(), |
| 169 delayMillis); | 163 delayMillis); |
| 170 } | 164 } |
| 165 return Response::OK(); |
| 171 } | 166 } |
| 172 | 167 |
| 173 void InspectorEmulationAgent::virtualTimeBudgetExpired() { | 168 void InspectorEmulationAgent::virtualTimeBudgetExpired() { |
| 174 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 169 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 175 WebViewScheduler::VirtualTimePolicy::PAUSE); | 170 WebViewScheduler::VirtualTimePolicy::PAUSE); |
| 176 frontend()->virtualTimeBudgetExpired(); | 171 frontend()->virtualTimeBudgetExpired(); |
| 177 } | 172 } |
| 178 | 173 |
| 179 DEFINE_TRACE(InspectorEmulationAgent) { | 174 DEFINE_TRACE(InspectorEmulationAgent) { |
| 180 visitor->trace(m_webLocalFrameImpl); | 175 visitor->trace(m_webLocalFrameImpl); |
| 181 InspectorBaseAgent::trace(visitor); | 176 InspectorBaseAgent::trace(visitor); |
| 182 } | 177 } |
| 183 | 178 |
| 184 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |