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 "public/platform/Platform.h" | |
13 #include "public/platform/WebThread.h" | |
12 #include "public/platform/WebViewScheduler.h" | 14 #include "public/platform/WebViewScheduler.h" |
13 #include "web/DevToolsEmulator.h" | 15 #include "web/DevToolsEmulator.h" |
14 #include "web/WebLocalFrameImpl.h" | 16 #include "web/WebLocalFrameImpl.h" |
15 #include "web/WebViewImpl.h" | 17 #include "web/WebViewImpl.h" |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 namespace EmulationAgentState { | 21 namespace EmulationAgentState { |
20 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; | 22 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; |
21 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; | 23 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; |
22 static const char emulatedMedia[] = "emulatedMedia"; | 24 static const char emulatedMedia[] = "emulatedMedia"; |
23 } | 25 } |
24 | 26 |
25 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) | 27 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) |
26 { | 28 { |
27 return new InspectorEmulationAgent(webLocalFrameImpl, client); | 29 return new InspectorEmulationAgent(webLocalFrameImpl, client); |
28 } | 30 } |
29 | 31 |
30 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) | 32 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) |
31 : m_webLocalFrameImpl(webLocalFrameImpl) | 33 : m_webLocalFrameImpl(webLocalFrameImpl) |
34 , m_virtualTimeEnabled(false) | |
32 , m_client(client) | 35 , m_client(client) |
33 { | 36 { |
34 } | 37 } |
35 | 38 |
36 InspectorEmulationAgent::~InspectorEmulationAgent() | 39 InspectorEmulationAgent::~InspectorEmulationAgent() |
37 { | 40 { |
38 } | 41 } |
39 | 42 |
40 WebViewImpl* InspectorEmulationAgent::webViewImpl() | 43 WebViewImpl* InspectorEmulationAgent::webViewImpl() |
41 { | 44 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 { | 89 { |
87 m_state->setString(EmulationAgentState::emulatedMedia, media); | 90 m_state->setString(EmulationAgentState::emulatedMedia, media); |
88 webViewImpl()->page()->settings().setMediaTypeOverride(media); | 91 webViewImpl()->page()->settings().setMediaTypeOverride(media); |
89 } | 92 } |
90 | 93 |
91 void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, double throttli ngRate) | 94 void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, double throttli ngRate) |
92 { | 95 { |
93 m_client->setCPUThrottlingRate(throttlingRate); | 96 m_client->setCPUThrottlingRate(throttlingRate); |
94 } | 97 } |
95 | 98 |
96 void InspectorEmulationAgent::setVirtualTimePolicy(ErrorString*, const String& i n_policy) | 99 void InspectorEmulationAgent::setVirtualTimePolicy(ErrorString*, const String& i n_policy, const Maybe<double>& in_virtualTimeBudgetSeconds) |
97 { | 100 { |
98 if (protocol::Emulation::VirtualTimePolicyEnum::Advance == in_policy) { | 101 if (protocol::Emulation::VirtualTimePolicyEnum::Advance == in_policy) { |
99 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); | |
100 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::ADVANCE); | 102 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::ADVANCE); |
101 } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == in_policy) { | 103 } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == in_policy) { |
102 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); | |
103 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::PAUSE); | 104 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::PAUSE); |
104 } else if (protocol::Emulation::VirtualTimePolicyEnum::PauseIfNetworkFetches Pending == in_policy) { | 105 } else if (protocol::Emulation::VirtualTimePolicyEnum::PauseIfNetworkFetches Pending == in_policy) { |
106 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::DETERMINISTIC_LOADING); | |
107 } | |
108 if (!m_virtualTimeEnabled) { | |
105 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); | 109 m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
106 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSc heduler::VirtualTimePolicy::DETERMINISTIC_LOADING); | 110 m_virtualTimeEnabled = true; |
dgozman
2016/08/01 16:03:31
Should we instead make enableVirtualTime() idempot
alex clarke (OOO till 29th)
2016/08/01 16:45:24
Actually it is idempotent already. We can remove t
| |
111 } | |
112 | |
113 if (in_virtualTimeBudgetSeconds.isJust()) { | |
dgozman
2016/08/01 16:03:31
What happens if client calls setVirtualTimePolicy
alex clarke (OOO till 29th)
2016/08/01 16:45:23
Canceling the previous timer seems like the best a
| |
114 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWeb TaskRunner(); | |
115 long long delayMillis = static_cast<long long>(in_virtualTimeBudgetSecon ds.fromJust() * 1000.0); | |
dgozman
2016/08/01 16:03:31
Let's make it milliseconds in protocol.
alex clarke (OOO till 29th)
2016/08/01 16:45:24
Done.
| |
116 taskRunner->postDelayedTask(BLINK_FROM_HERE, WTF::bind(&InspectorEmulati onAgent::virtualTimeBudgetExpired, wrapPersistent(this)), delayMillis); | |
dgozman
2016/08/01 16:03:31
Can we use weak pointer here? If client detaches b
alex clarke (OOO till 29th)
2016/08/01 16:45:23
Good point. Using CancellableTaskFactory here doe
| |
107 } | 117 } |
108 } | 118 } |
109 | 119 |
120 void InspectorEmulationAgent::virtualTimeBudgetExpired() | |
121 { | |
122 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewSchedu ler::VirtualTimePolicy::PAUSE); | |
123 frontend()->virtualTimeBudgetExpired(); | |
124 } | |
125 | |
110 DEFINE_TRACE(InspectorEmulationAgent) | 126 DEFINE_TRACE(InspectorEmulationAgent) |
111 { | 127 { |
112 visitor->trace(m_webLocalFrameImpl); | 128 visitor->trace(m_webLocalFrameImpl); |
113 InspectorBaseAgent::trace(visitor); | 129 InspectorBaseAgent::trace(visitor); |
114 } | 130 } |
115 | 131 |
116 } // namespace blink | 132 } // namespace blink |
OLD | NEW |