| 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" |
| 11 #include "platform/geometry/DoubleRect.h" | 11 #include "platform/geometry/DoubleRect.h" |
| 12 #include "platform/scheduler/CancellableTaskFactory.h" | |
| 13 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebFloatPoint.h" | 13 #include "public/platform/WebFloatPoint.h" |
| 15 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
| 16 #include "public/platform/WebViewScheduler.h" | 15 #include "public/platform/WebViewScheduler.h" |
| 17 #include "web/DevToolsEmulator.h" | 16 #include "web/DevToolsEmulator.h" |
| 18 #include "web/WebLocalFrameImpl.h" | 17 #include "web/WebLocalFrameImpl.h" |
| 19 #include "web/WebViewImpl.h" | 18 #include "web/WebViewImpl.h" |
| 20 | 19 |
| 21 namespace blink { | 20 namespace blink { |
| 22 | 21 |
| 23 namespace EmulationAgentState { | 22 namespace EmulationAgentState { |
| 24 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; | 23 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; |
| 25 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; | 24 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; |
| 26 static const char emulatedMedia[] = "emulatedMedia"; | 25 static const char emulatedMedia[] = "emulatedMedia"; |
| 27 static const char forcedViewportEnabled[] = "forcedViewportEnabled"; | 26 static const char forcedViewportEnabled[] = "forcedViewportEnabled"; |
| 28 static const char forcedViewportX[] = "forcedViewportX"; | 27 static const char forcedViewportX[] = "forcedViewportX"; |
| 29 static const char forcedViewportY[] = "forcedViewportY"; | 28 static const char forcedViewportY[] = "forcedViewportY"; |
| 30 static const char forcedViewportScale[] = "forcedViewportScale"; | 29 static const char forcedViewportScale[] = "forcedViewportScale"; |
| 31 } | 30 } |
| 32 | 31 |
| 33 InspectorEmulationAgent* InspectorEmulationAgent::create( | 32 InspectorEmulationAgent* InspectorEmulationAgent::create( |
| 34 WebLocalFrameImpl* webLocalFrameImpl, | 33 WebLocalFrameImpl* webLocalFrameImpl, |
| 35 Client* client) { | 34 Client* client) { |
| 36 return new InspectorEmulationAgent(webLocalFrameImpl, client); | 35 return new InspectorEmulationAgent(webLocalFrameImpl, client); |
| 37 } | 36 } |
| 38 | 37 |
| 39 InspectorEmulationAgent::InspectorEmulationAgent( | 38 InspectorEmulationAgent::InspectorEmulationAgent( |
| 40 WebLocalFrameImpl* webLocalFrameImpl, | 39 WebLocalFrameImpl* webLocalFrameImpl, |
| 41 Client* client) | 40 Client* client) |
| 42 : m_webLocalFrameImpl(webLocalFrameImpl), | 41 : m_webLocalFrameImpl(webLocalFrameImpl), m_client(client) {} |
| 43 m_client(client), | |
| 44 m_virtualTimeBudgetExpiredTask(CancellableTaskFactory::create( | |
| 45 this, | |
| 46 &InspectorEmulationAgent::virtualTimeBudgetExpired)) {} | |
| 47 | 42 |
| 48 InspectorEmulationAgent::~InspectorEmulationAgent() {} | 43 InspectorEmulationAgent::~InspectorEmulationAgent() {} |
| 49 | 44 |
| 50 WebViewImpl* InspectorEmulationAgent::webViewImpl() { | 45 WebViewImpl* InspectorEmulationAgent::webViewImpl() { |
| 51 return m_webLocalFrameImpl->viewImpl(); | 46 return m_webLocalFrameImpl->viewImpl(); |
| 52 } | 47 } |
| 53 | 48 |
| 54 void InspectorEmulationAgent::restore() { | 49 void InspectorEmulationAgent::restore() { |
| 55 setScriptExecutionDisabled(m_state->booleanProperty( | 50 setScriptExecutionDisabled(m_state->booleanProperty( |
| 56 EmulationAgentState::scriptExecutionDisabled, false)); | 51 EmulationAgentState::scriptExecutionDisabled, false)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 PauseIfNetworkFetchesPending == policy) { | 146 PauseIfNetworkFetchesPending == policy) { |
| 152 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 147 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 153 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); | 148 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); |
| 154 } | 149 } |
| 155 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); | 150 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| 156 | 151 |
| 157 if (budget.isJust()) { | 152 if (budget.isJust()) { |
| 158 WebTaskRunner* taskRunner = | 153 WebTaskRunner* taskRunner = |
| 159 Platform::current()->currentThread()->getWebTaskRunner(); | 154 Platform::current()->currentThread()->getWebTaskRunner(); |
| 160 long long delayMillis = static_cast<long long>(budget.fromJust()); | 155 long long delayMillis = static_cast<long long>(budget.fromJust()); |
| 161 taskRunner->postDelayedTask( | 156 m_virtualTimeBudgetExpiredTaskHandle = |
| 162 BLINK_FROM_HERE, m_virtualTimeBudgetExpiredTask->cancelAndCreate(), | 157 taskRunner->postDelayedCancellableTask( |
| 163 delayMillis); | 158 BLINK_FROM_HERE, |
| 159 WTF::bind(&InspectorEmulationAgent::virtualTimeBudgetExpired, |
| 160 wrapWeakPersistent(this)), |
| 161 delayMillis); |
| 164 } | 162 } |
| 165 return Response::OK(); | 163 return Response::OK(); |
| 166 } | 164 } |
| 167 | 165 |
| 168 void InspectorEmulationAgent::virtualTimeBudgetExpired() { | 166 void InspectorEmulationAgent::virtualTimeBudgetExpired() { |
| 169 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( | 167 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( |
| 170 WebViewScheduler::VirtualTimePolicy::PAUSE); | 168 WebViewScheduler::VirtualTimePolicy::PAUSE); |
| 171 frontend()->virtualTimeBudgetExpired(); | 169 frontend()->virtualTimeBudgetExpired(); |
| 172 } | 170 } |
| 173 | 171 |
| 174 DEFINE_TRACE(InspectorEmulationAgent) { | 172 DEFINE_TRACE(InspectorEmulationAgent) { |
| 175 visitor->trace(m_webLocalFrameImpl); | 173 visitor->trace(m_webLocalFrameImpl); |
| 176 InspectorBaseAgent::trace(visitor); | 174 InspectorBaseAgent::trace(visitor); |
| 177 } | 175 } |
| 178 | 176 |
| 179 } // namespace blink | 177 } // namespace blink |
| OLD | NEW |